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:
@@ -2,6 +2,7 @@ import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
SCHEMA_VERSION,
|
||||
emptyArtifact,
|
||||
isNewerMajor,
|
||||
serializeArtifact,
|
||||
type Artifact,
|
||||
} from "../src/model";
|
||||
@@ -103,6 +104,13 @@ describe("cross-rung identity (F5 SLICE-2)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("isNewerMajor (F5 SLICE-2, INV-16)", () => {
|
||||
it("is false for v1 and true for a newer major", () => {
|
||||
expect(isNewerMajor(emptyArtifact("d.md"))).toBe(false);
|
||||
expect(isNewerMajor({ schemaVersion: 2 })).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("unknown-field preservation (F5 SLICE-2, INV-15)", () => {
|
||||
it("a rewrite preserves unknown fields at every level, after known keys, sorted", () => {
|
||||
const foreign = {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user