Tests: pin the authority record shape checks and the dangling-link message
Mutation survivors of the authority reader (record count, schema id, type) and of the reader's dangling-link error text each get a test that fails when the rule breaks. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a23eb8219d
commit
f218c9e8f3
2 changed files with 38 additions and 1 deletions
|
|
@ -2143,7 +2143,10 @@ test("SingleFileMessagePackBackingStore refuses a dangling symlink at its path a
|
|||
await symlink(join(volume, "store.cc"), file);
|
||||
const store = new SingleFileMessagePackBackingStore(file);
|
||||
const envelope = { key: "k", type: "t", payload: Uint8Array.of(0x90), storedAt: "2026-09-30T00:00:00Z" };
|
||||
await assert.rejects(() => store.pullAll(), (error: NodeJS.ErrnoException) => error.code === "ENOENT");
|
||||
await assert.rejects(
|
||||
() => store.pullAll(),
|
||||
(error: NodeJS.ErrnoException) => error.code === "ENOENT" && error.message.includes("symbolic link") && error.message.includes(file),
|
||||
);
|
||||
await assert.rejects(() => store.push(envelope), (error: NodeJS.ErrnoException) => error.code === "ENOENT");
|
||||
await assert.rejects(() => store.pushAll([envelope], { soft: true }), (error: NodeJS.ErrnoException) => error.code === "ENOENT");
|
||||
assert.ok((await lstat(file)).isSymbolicLink());
|
||||
|
|
|
|||
|
|
@ -181,6 +181,40 @@ for (const file of ["expected.cc", "activation.cc"]) {
|
|||
});
|
||||
}
|
||||
|
||||
// What an authority file may hold once the one reader has accepted it: exactly one record, under the schema
|
||||
// id and the type the loader asked for. Each case edits the Rust-written store and changes one thing.
|
||||
function withStore(change: (store: unknown[][]) => void): (bytes: Buffer) => Buffer {
|
||||
return (bytes) => {
|
||||
const store = decode(bytes) as unknown[][];
|
||||
change(store);
|
||||
return Buffer.from(encode(store));
|
||||
};
|
||||
}
|
||||
|
||||
test("an authority file holding two records is refused", (context) => {
|
||||
const bundle = bundleWith(context, "web", "expected.cc", withStore((store) => {
|
||||
const second = [...(store[2]![0] as unknown[])];
|
||||
second[0] = "second";
|
||||
store[2]!.push(second);
|
||||
}));
|
||||
assert.throws(() => openAuthority(context, "web", { bundle }), /must contain exactly one record/);
|
||||
});
|
||||
|
||||
test("an authority file whose one record is under another schema id is refused", (context) => {
|
||||
const bundle = bundleWith(context, "web", "expected.cc", () => fixtureFile("web", "activation.cc"));
|
||||
assert.throws(
|
||||
() => openAuthority(context, "web", { bundle }),
|
||||
(error: Error) => /must contain exactly one .+ record/.test(error.message) && !error.message.includes("unexpected CultCache type"),
|
||||
);
|
||||
});
|
||||
|
||||
test("an authority record whose catalog names another type is refused, naming that type", (context) => {
|
||||
const bundle = bundleWith(context, "web", "expected.cc", withStore((store) => {
|
||||
(store[1]![0] as unknown[])[1] = "idunn.other_type";
|
||||
}));
|
||||
assert.throws(() => openAuthority(context, "web", { bundle }), /unexpected CultCache type idunn.other_type/);
|
||||
});
|
||||
|
||||
function presenceSlot(document: { payload: Uint8Array }, slot: number): unknown {
|
||||
return (decode(document.payload) as unknown[])[slot];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue