feat: isNewerMajor + store write-refusal backstop (F5 SLICE-2, INV-16, #14)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-10 22:59:04 -07:00
parent a6b16f0d9c
commit 746071a585
4 changed files with 41 additions and 1 deletions
+17
View File
@@ -107,3 +107,20 @@ describe("CoauthorStore", () => {
expect(store.consumeSelfWrite(p)).toBe(false);
});
});
describe("newer-major write refusal (F5 SLICE-2, INV-16 backstop)", () => {
it("update REFUSES to write a sidecar from a newer major, leaving bytes untouched", () => {
const store = new CoauthorStore(root);
const p = store.sidecarPath("docs/v2.md");
fs.mkdirSync(path.dirname(p), { recursive: true });
const v2 = { ...emptyArtifact("docs/v2.md"), schemaVersion: 2 };
fs.writeFileSync(p, serializeArtifact(v2), "utf8");
const before = fs.readFileSync(p, "utf8");
expect(() =>
store.update("docs/v2.md", (a) => {
a.threads = [];
}),
).toThrow(/INV-16/);
expect(fs.readFileSync(p, "utf8")).toBe(before);
});
});