Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The endpoint MUST be same-origin with the card unless a client policy explicitly

The well-known suffix is intentionally `latch.json`; it is more precise than squatting on a generic metadata name. Deployments seeking formal interoperability should follow the registration process in RFC 8615. A path-local `latch.json` and an HTML `<link rel="latch" type="application/latch+json" href="...">` MAY be used on shared hosting where the origin root is unavailable.

`input` uses JSON Schema. The dependency-free reference runtime validates the documented subset in `validateInput`; providers remain responsible for enforcing their complete schema. Unknown protocol fields MUST be ignored unless they are required by a negotiated extension.
`input` uses JSON Schema. When its schema declares a type, it MUST include object; an omitted type remains allowed. The dependency-free reference runtime validates the documented subset in `validateInput`; providers remain responsible for enforcing their complete schema. Unknown protocol fields MUST be ignored unless they are required by a negotiated extension.

## 3. Envelope

Expand Down
8 changes: 5 additions & 3 deletions latch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ export function validateCard(card) {
errors.push(`${at} read capabilities must have no effects and no approval`);
}
if (capability.mode === "write" && capability.effects === "none") errors.push(`${at} write capability cannot have no effects`);
validateInput({}, capability.input || {}, `${at}.input`).forEach((error) => {
if (error.includes("must be object")) errors.push(`${at}.input must be an object schema`);
});
const declaredType = capability.input?.type;
if (declaredType !== undefined && !(Array.isArray(declaredType)
? declaredType.includes("object") : declaredType === "object")) {
errors.push(at + " (" + capability.id + ").input must be an object schema; declared type: " + JSON.stringify(declaredType));
}
});
}
if (errors.length) fail("invalid_card", "The LATCH card is invalid.", 422, { details: errors });
Expand Down
25 changes: 24 additions & 1 deletion test/latch.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
listen,
runDemoTrace,
sha256,
validateInput
validateInput,
validateCard
} from "../latch.mjs";

const ROOT = fileURLToPath(new URL("../", import.meta.url));
Expand Down Expand Up @@ -530,3 +531,25 @@ test("fifty concurrent identical commits create exactly one task and invalid inp
test.after(async () => {
await rm(TEMP, { recursive: true, force: true });
});

for (const type of ["string", "array", ["string", "number"]]) {
test("card refuses non-object input schema " + JSON.stringify(type), () => {
const card = createDemoProvider().card;
card.capabilities[0].input = { type };
assert.throws(() => validateCard(card), (error) => {
assert.equal(error.code, "invalid_card");
assert.equal(error.status, 422);
assert.ok(error.details.some((detail) =>
detail.includes("materials.list") && detail.includes(JSON.stringify(type))));
return true;
});
});
}

test("card keeps object, object unions and unspecified input types", () => {
for (const input of [{ type: "object" }, { type: ["object", "null"] }, {}]) {
const card = createDemoProvider().card;
card.capabilities[0].input = input;
assert.equal(validateCard(card), true);
}
});
Loading