thing-contract-ts: seq, version and segment checked on the encode door of the leaf (integer and bound) where a caller hands a number in
The factory and key builders took a non-integer through the decode leaf; the encode leaf refuses it. Deep chain bound corrected to 83 Box levels. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8425526548
commit
b8ad36a189
4 changed files with 9 additions and 6 deletions
|
|
@ -5,11 +5,11 @@
|
|||
import { segment, seq, version } from "./domain.js";
|
||||
|
||||
export function surfaceKey(providerId: string, label: string): string {
|
||||
return `thing:surface:${providerId}.${segment.decode(label)}`;
|
||||
return `thing:surface:${providerId}.${segment.encode(label)}`;
|
||||
}
|
||||
|
||||
export function compositionKey(publisher: string, name: string, versionNumber: number | bigint): string {
|
||||
return `thing:composition:${publisher}.${segment.decode(name)}.v${version.decode(versionNumber)}`;
|
||||
return `thing:composition:${publisher}.${segment.encode(name)}.v${version.encode(versionNumber)}`;
|
||||
}
|
||||
|
||||
export function invocationKey(invocationId: string): string {
|
||||
|
|
@ -17,9 +17,9 @@ export function invocationKey(invocationId: string): string {
|
|||
}
|
||||
|
||||
export function resultKey(invocationId: string, position: number): string {
|
||||
return `thing:result:${invocationId}.${seq.decode(position)}`;
|
||||
return `thing:result:${invocationId}.${seq.encode(position)}`;
|
||||
}
|
||||
|
||||
export function assetCatalogKey(providerId: string, catalogId: string): string {
|
||||
return `thing:asset_catalog:${providerId}.${segment.decode(catalogId)}`;
|
||||
return `thing:asset_catalog:${providerId}.${segment.encode(catalogId)}`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export class CommandResult {
|
|||
private constructor(key: typeof door, invocationId: string, position: number, outcome: Outcome) {
|
||||
if (key !== door) throw new Error("a CommandResult is built by its factories");
|
||||
this.invocationId = invocationId;
|
||||
this.seq = seq.decode(position);
|
||||
this.seq = seq.encode(position);
|
||||
this.outcome = outcome;
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ const admits = (levels: number): boolean => {
|
|||
test("the deepest Box chain the bound admits round-trips on the default stack, and one more is refused", () => {
|
||||
let deepest = 1;
|
||||
while (admits(deepest + 1)) deepest++;
|
||||
assert.equal(deepest, 84, "the bound admits 84 Box levels above the leaf");
|
||||
assert.equal(deepest, 83, "the bound admits 83 Box levels above the text leaf, 84 nodes deep");
|
||||
assert.ok(!admits(deepest + 1));
|
||||
|
||||
const value = chain(deepest);
|
||||
|
|
|
|||
|
|
@ -38,6 +38,9 @@ test("a result key refuses a seq below 1 and a composition key a version below 0
|
|||
assert.throws(() => resultKey("x", 0), /Seq must be at least 1/);
|
||||
assert.throws(() => compositionKey("pub", "card", -1), /Version must be at least 0/);
|
||||
assert.equal(compositionKey("pub", "card", 0), "thing:composition:pub.card.v0");
|
||||
assert.throws(() => compositionKey("pub", "card", 1.5), /int64/);
|
||||
assert.throws(() => resultKey("x", 1.5), /int32/);
|
||||
assert.throws(() => resultKey("x", 2 ** 31), /int32/);
|
||||
});
|
||||
|
||||
test("keys are injective over their field sets", () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue