F4 SLICE-1: proposalModel helpers — add/remove + fenced-diff body (#12)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
type Proposal,
|
||||
} from "../src/model";
|
||||
import { CoauthorStore } from "../src/store";
|
||||
import { addProposal, proposalBody, removeProposal } from "../src/proposalModel";
|
||||
|
||||
const agent = {
|
||||
kind: "agent" as const,
|
||||
@@ -73,3 +74,34 @@ describe("CoauthorStore prune with proposals (spec §6.3)", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("proposalModel helpers (spec §6.4)", () => {
|
||||
const fp = { text: "old line one\nold line two", before: "", after: "", lineHint: 3 };
|
||||
|
||||
it("addProposal creates the anchor + pending record; removeProposal deletes by id", () => {
|
||||
const a = emptyArtifact("docs/x.md");
|
||||
const { proposalId, anchorId } = addProposal(a, fp, "new line", agent, {
|
||||
turnId: "turn-9", instruction: "shorten",
|
||||
});
|
||||
expect(a.anchors[anchorId].fingerprint).toEqual(fp);
|
||||
expect(a.proposals).toHaveLength(1);
|
||||
expect(a.proposals[0].id).toBe(proposalId);
|
||||
expect(a.proposals[0].replacement).toBe("new line");
|
||||
expect(a.proposals[0].turnId).toBe("turn-9");
|
||||
expect(a.proposals[0].instruction).toBe("shorten");
|
||||
expect(removeProposal(a, proposalId)).toBe(true);
|
||||
expect(a.proposals).toHaveLength(0);
|
||||
expect(removeProposal(a, proposalId)).toBe(false);
|
||||
});
|
||||
|
||||
it("proposalBody renders instruction + a fenced unified diff of old → new", () => {
|
||||
const a = emptyArtifact("docs/x.md");
|
||||
addProposal(a, fp, "new only line", agent, { instruction: "merge the lines" });
|
||||
const body = proposalBody(fp.text, a.proposals[0]);
|
||||
expect(body).toContain("**Claude proposes** — _merge the lines_");
|
||||
expect(body).toContain("```diff");
|
||||
expect(body).toContain("- old line one");
|
||||
expect(body).toContain("- old line two");
|
||||
expect(body).toContain("+ new only line");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user