@niwa-labs/pstack 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +260 -2
- package/package.json +28 -4
- package/scripts/upstream-map.ts +90 -0
- package/src/author.ts +57 -0
- package/src/binding.ts +32 -0
- package/src/catalog.ts +86 -0
- package/src/composition.ts +66 -0
- package/src/index.ts +50 -0
- package/src/mapping/analyze.ts +223 -0
- package/src/mapping/assemble.ts +96 -0
- package/src/mapping/diff.ts +139 -0
- package/src/mapping/format.ts +67 -0
- package/src/mapping/git.ts +69 -0
- package/src/mapping/index.ts +18 -0
- package/src/mapping/maintain.ts +36 -0
- package/src/mapping/schema.ts +50 -0
- package/src/mapping/sources.ts +108 -0
- package/src/mapping/tool.ts +77 -0
- package/src/mapping/verify.ts +130 -0
- package/src/plugin.ts +136 -0
- package/src/policy.ts +115 -0
- package/src/ports.ts +184 -0
- package/src/pr-binding.ts +88 -0
- package/src/records.ts +61 -0
- package/src/roles.ts +49 -0
- package/src/trunk.ts +59 -0
- package/src/upstream-actions.ts +135 -0
- package/src/upstream-records.ts +71 -0
- package/src/upstream.ts +151 -0
- package/src/workflows/adapted.md +780 -0
- package/src/workflows/authoring-a-skill.ts +52 -0
- package/src/workflows/autonomous-run.ts +56 -0
- package/src/workflows/autopilot-full.ts +90 -0
- package/src/workflows/autopilot-stack.ts +125 -0
- package/src/workflows/babysit.ts +124 -0
- package/src/workflows/benny-reproduce.ts +122 -0
- package/src/workflows/benny-triage.ts +89 -0
- package/src/workflows/bug-fix.ts +54 -0
- package/src/workflows/entry.ts +130 -0
- package/src/workflows/eval.ts +63 -0
- package/src/workflows/feature.ts +54 -0
- package/src/workflows/hillclimb.ts +78 -0
- package/src/workflows/investigation.ts +41 -0
- package/src/workflows/lib/catalog.ts +45 -0
- package/src/workflows/lib/change.ts +70 -0
- package/src/workflows/lib/forensics.ts +37 -0
- package/src/workflows/lib/git.ts +30 -0
- package/src/workflows/lib/go.ts +58 -0
- package/src/workflows/lib/inputs.ts +34 -0
- package/src/workflows/lib/lane.ts +170 -0
- package/src/workflows/lib/measure.ts +34 -0
- package/src/workflows/lib/plan.ts +24 -0
- package/src/workflows/lib/script.ts +79 -0
- package/src/workflows/lib/ship.ts +110 -0
- package/src/workflows/lib/texts.ts +18 -0
- package/src/workflows/lib/trunk.ts +91 -0
- package/src/workflows/multi-phase-plan.ts +83 -0
- package/src/workflows/opening-a-pr.ts +62 -0
- package/src/workflows/pause-safely.ts +50 -0
- package/src/workflows/perf-issue.ts +87 -0
- package/src/workflows/prototype.ts +76 -0
- package/src/workflows/refactoring.ts +54 -0
- package/src/workflows/runtime-forensics.ts +26 -0
- package/src/workflows/scenarios.ts +380 -0
- package/src/workflows/session-pickup.ts +57 -0
- package/src/workflows/shipping.ts +63 -0
- package/src/workflows/suite.ts +129 -0
- package/src/workflows/texts/authoring-a-skill.json +5 -0
- package/src/workflows/texts/autonomous-run.json +5 -0
- package/src/workflows/texts/autopilot-full.json +5 -0
- package/src/workflows/texts/autopilot-stack.json +5 -0
- package/src/workflows/texts/babysit.json +5 -0
- package/src/workflows/texts/benny-reproduce.json +5 -0
- package/src/workflows/texts/benny-triage.json +5 -0
- package/src/workflows/texts/bug-fix.json +5 -0
- package/src/workflows/texts/bugbot-triage.json +5 -0
- package/src/workflows/texts/eval.json +5 -0
- package/src/workflows/texts/feature.json +5 -0
- package/src/workflows/texts/hillclimb.json +5 -0
- package/src/workflows/texts/investigation.json +5 -0
- package/src/workflows/texts/multi-phase-plan.json +5 -0
- package/src/workflows/texts/opening-a-pr.json +5 -0
- package/src/workflows/texts/pause-safely.json +5 -0
- package/src/workflows/texts/perf-issue.json +5 -0
- package/src/workflows/texts/prototype.json +5 -0
- package/src/workflows/texts/refactoring.json +5 -0
- package/src/workflows/texts/runtime-forensics.json +5 -0
- package/src/workflows/texts/session-pickup.json +5 -0
- package/src/workflows/texts/trace-forensics.json +5 -0
- package/src/workflows/texts/visual-parity.json +5 -0
- package/src/workflows/texts/worker.json +5 -0
- package/src/workflows/trace-forensics.ts +27 -0
- package/src/workflows/upstream-sync.ts +182 -0
- package/src/workflows/visual-parity.ts +52 -0
- package/src/workflows/worktree-cleanup.ts +57 -0
- package/test/author.test.ts +61 -0
- package/test/benny.test.ts +138 -0
- package/test/binding.test.ts +54 -0
- package/test/catalog-helpers.test.ts +49 -0
- package/test/closure.test.ts +45 -0
- package/test/composition.test.ts +23 -0
- package/test/eval.test.ts +23 -0
- package/test/lanes.test.ts +334 -0
- package/test/mapping-diff.test.ts +64 -0
- package/test/mapping-support.ts +110 -0
- package/test/mapping-texts.test.ts +106 -0
- package/test/mapping.test.ts +276 -0
- package/test/package-layout.ts +68 -0
- package/test/policy.test.ts +98 -0
- package/test/ports.test.ts +45 -0
- package/test/ports.ts +173 -0
- package/test/roles.test.ts +21 -0
- package/test/suite.test.ts +167 -0
- package/test/support.ts +541 -0
- package/test/texts.test.ts +174 -0
- package/test/tool.test.ts +48 -0
- package/test/trunk-helpers.test.ts +149 -0
- package/test/trunk.test.ts +24 -0
- package/test/upstream-sync.test.ts +246 -0
- package/test/upstream.test.ts +106 -0
- package/test/worktree-cleanup.test.ts +107 -0
- package/tsconfig.json +7 -0
- package/upstream/LICENSE +21 -0
- package/upstream/SOURCE.json +5 -0
- package/upstream/benny/FOR_AGENTS.md +89 -0
- package/upstream/benny/README.md +23 -0
- package/upstream/benny/skills/reproduce-and-fix-issues/SKILL.md +310 -0
- package/upstream/benny/skills/reproduce-and-fix-issues/references/control-adapter.md +169 -0
- package/upstream/benny/skills/reproduce-and-fix-issues/references/feature-map.example.md +205 -0
- package/upstream/benny/skills/reproduce-and-fix-issues/references/verify-existing-fix.md +93 -0
- package/upstream/benny/skills/setup-benny/SKILL.md +265 -0
- package/upstream/benny/skills/triage-issue-reports/SKILL.md +240 -0
- package/upstream/benny/skills/triage-issue-reports/references/routing.example.md +61 -0
- package/upstream/benny/templates/configuration.example.yaml +84 -0
- package/upstream/benny/templates/reproduce-automation-prompt.md +33 -0
- package/upstream/benny/templates/triage-automation-prompt.md +39 -0
- package/upstream/mapping.json +699 -0
- package/upstream/poteto-mode/SKILL.md +110 -0
- package/upstream/poteto-mode/playbooks/authoring-a-skill.md +12 -0
- package/upstream/poteto-mode/playbooks/autonomous-run.md +13 -0
- package/upstream/poteto-mode/playbooks/autopilot-full.md +25 -0
- package/upstream/poteto-mode/playbooks/autopilot-stack.md +8 -0
- package/upstream/poteto-mode/playbooks/babysit.md +10 -0
- package/upstream/poteto-mode/playbooks/bug-fix.md +15 -0
- package/upstream/poteto-mode/playbooks/eval.md +25 -0
- package/upstream/poteto-mode/playbooks/feature.md +21 -0
- package/upstream/poteto-mode/playbooks/hillclimb.md +21 -0
- package/upstream/poteto-mode/playbooks/investigation.md +14 -0
- package/upstream/poteto-mode/playbooks/multi-phase-plan.md +11 -0
- package/upstream/poteto-mode/playbooks/opening-a-pr.md +9 -0
- package/upstream/poteto-mode/playbooks/pause-safely.md +10 -0
- package/upstream/poteto-mode/playbooks/perf-issue.md +25 -0
- package/upstream/poteto-mode/playbooks/prototype.md +14 -0
- package/upstream/poteto-mode/playbooks/refactoring.md +16 -0
- package/upstream/poteto-mode/playbooks/runtime-forensics.md +11 -0
- package/upstream/poteto-mode/playbooks/session-pickup.md +11 -0
- package/upstream/poteto-mode/playbooks/shipping.md +12 -0
- package/upstream/poteto-mode/playbooks/trace-forensics.md +14 -0
- package/upstream/poteto-mode/playbooks/visual-parity.md +11 -0
- package/upstream/poteto-mode/playbooks/worktree-cleanup.md +12 -0
- package/upstream/poteto-mode/references/bugbot-triage.md +142 -0
- package/upstream/poteto-mode/worker.md +11 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// The mapping tool: it validates the mapping, measures how much of the upstream text it covers, and follows each
|
|
2
|
+
// range from the commit it was recorded at to the current one on both sides, without concluding anything.
|
|
3
|
+
|
|
4
|
+
import { expect, test } from "bun:test";
|
|
5
|
+
|
|
6
|
+
import { accept, advance, analyze, assemble, formatMapping, formatReport, parseMapping } from "../src/mapping/index.ts";
|
|
7
|
+
import { OURS_FILES, UPSTREAM_FILES, World, at, git, mapping } from "./mapping-support.ts";
|
|
8
|
+
|
|
9
|
+
const SKILL = "skills/poteto-mode/SKILL.md";
|
|
10
|
+
const BUG_FIX = "skills/poteto-mode/playbooks/bug-fix.md";
|
|
11
|
+
const SKILL_TEXT = UPSTREAM_FILES[SKILL] as string;
|
|
12
|
+
const BUG_TEXT = UPSTREAM_FILES[BUG_FIX] as string;
|
|
13
|
+
const BRIEF = OURS_FILES["src/brief.ts"] as string;
|
|
14
|
+
|
|
15
|
+
/** Entries that cover the whole of SKILL.md, the worker rules and the bug-fix playbook, split in blocks. */
|
|
16
|
+
function covering(w: World) {
|
|
17
|
+
const brief = [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }];
|
|
18
|
+
const mine = (file: string, snapshot: string, text: string, id: string, needle: string, kind: "prompt" | "code" | "dropped" = "prompt") =>
|
|
19
|
+
w.entry(id, kind, { file: snapshot, text, needle }, kind === "dropped" ? [] : brief, kind === "dropped" ? "not taken" : undefined);
|
|
20
|
+
return [
|
|
21
|
+
mine("", "poteto-mode/SKILL.md", SKILL_TEXT, "skill.title", "# Mode\n\n", "dropped"),
|
|
22
|
+
mine("", "poteto-mode/SKILL.md", SKILL_TEXT, "skill.alpha", "Alpha block.\n\n"),
|
|
23
|
+
mine("", "poteto-mode/SKILL.md", SKILL_TEXT, "skill.beta", "Beta block.\n"),
|
|
24
|
+
mine("", "poteto-mode/worker.md", UPSTREAM_FILES["skills/poteto-mode/worker.md"] as string, "worker.all", "Work for the operator.\n"),
|
|
25
|
+
mine("", "poteto-mode/playbooks/bug-fix.md", BUG_TEXT, "bug-fix.head", "### Bug fix\n\nReproduce it.\n\n"),
|
|
26
|
+
mine("", "poteto-mode/playbooks/bug-fix.md", BUG_TEXT, "bug-fix.fix", "Fix the cause.\n", "code"),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
test("a sound mapping has no problems, and its coverage is a share of the upstream characters", async () => {
|
|
31
|
+
const w = await World.make();
|
|
32
|
+
const report = analyze(mapping(...covering(w)), w.upstream(false), w.ours());
|
|
33
|
+
expect(report.problems).toEqual([]);
|
|
34
|
+
expect(report.coverage.percent).toBe(100);
|
|
35
|
+
expect(report.coverage.files.map((one) => one.file)).toEqual(["poteto-mode/SKILL.md", "poteto-mode/playbooks/bug-fix.md", "poteto-mode/worker.md"]);
|
|
36
|
+
expect(report.unresolved).toBe(0);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("coverage is counted per file and in total, and the uncovered ranges are listed with their text", async () => {
|
|
40
|
+
const w = await World.make();
|
|
41
|
+
const entries = covering(w).filter((one) => one.id !== "skill.beta" && one.id !== "worker.all");
|
|
42
|
+
const report = analyze(mapping(...entries), w.upstream(false), w.ours());
|
|
43
|
+
const skill = report.coverage.files.find((one) => one.file === "poteto-mode/SKILL.md");
|
|
44
|
+
const worker = report.coverage.files.find((one) => one.file === "poteto-mode/worker.md");
|
|
45
|
+
expect(skill?.uncovered).toEqual([{ start: SKILL_TEXT.indexOf("Beta"), end: SKILL_TEXT.length, text: "Beta block.\n", added: false }]);
|
|
46
|
+
expect(skill?.percent).toBeCloseTo(((SKILL_TEXT.length - 12) / SKILL_TEXT.length) * 100, 6);
|
|
47
|
+
expect(worker?.percent).toBe(0);
|
|
48
|
+
expect(worker?.uncovered).toHaveLength(1);
|
|
49
|
+
const total = (UPSTREAM_FILES["skills/poteto-mode/worker.md"] as string).length + SKILL_TEXT.length + BUG_TEXT.length;
|
|
50
|
+
expect(report.coverage.size).toBe(total);
|
|
51
|
+
expect(report.coverage.covered).toBe(total - 12 - (UPSTREAM_FILES["skills/poteto-mode/worker.md"] as string).length);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("a dropped block counts as covered", async () => {
|
|
55
|
+
const w = await World.make();
|
|
56
|
+
const entry = w.entry("whole", "dropped", { file: "poteto-mode/worker.md", text: UPSTREAM_FILES["skills/poteto-mode/worker.md"] as string, needle: "Work for the operator.\n" }, [], "the operator is a person");
|
|
57
|
+
const report = analyze(mapping(entry), w.upstream(false), w.ours());
|
|
58
|
+
expect(report.coverage.files.find((one) => one.file === "poteto-mode/worker.md")?.percent).toBe(100);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("the license and the snapshot's own files are not upstream text", async () => {
|
|
62
|
+
const w = await World.make();
|
|
63
|
+
const report = analyze(mapping(), w.upstream(false), w.ours());
|
|
64
|
+
expect(report.coverage.files.map((one) => one.file)).not.toContain("LICENSE");
|
|
65
|
+
expect(report.coverage.files.map((one) => one.file)).not.toContain("SOURCE.json");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("two entries that cover the same upstream characters at one commit are refused", async () => {
|
|
69
|
+
const w = await World.make();
|
|
70
|
+
const [a, b] = covering(w).filter((one) => one.id.startsWith("bug-fix"));
|
|
71
|
+
const overlapping = { ...(b as NonNullable<typeof b>), upstream: { ...(b as NonNullable<typeof b>).upstream, range: [(a as NonNullable<typeof a>).upstream.range[1] - 3, (b as NonNullable<typeof b>).upstream.range[1]] as [number, number] } };
|
|
72
|
+
const report = analyze(mapping(a as NonNullable<typeof a>, overlapping), w.upstream(false), w.ours());
|
|
73
|
+
expect(report.problems.map((one) => one.message)).toEqual(["the upstream range overlaps the one of bug-fix.head"]);
|
|
74
|
+
expect(report.entries.map((one) => one.id)).toEqual(["bug-fix.head"]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("a range outside its file at its commit, a missing file and a repeated id are refused", async () => {
|
|
78
|
+
const w = await World.make();
|
|
79
|
+
const [first] = covering(w);
|
|
80
|
+
const base = first as NonNullable<typeof first>;
|
|
81
|
+
const beyond = { ...base, id: "beyond", upstream: { ...base.upstream, range: [0, 9999] as [number, number] } };
|
|
82
|
+
const nowhere = { ...base, id: "nowhere", upstream: { ...base.upstream, file: "poteto-mode/none.md" } };
|
|
83
|
+
const ours = { ...base, id: "ours", kind: "prompt" as const, ours: [{ commit: w.oursCommit, file: "src/brief.ts", range: [0, 9999] as [number, number] }] };
|
|
84
|
+
const again = { ...base };
|
|
85
|
+
const report = analyze(mapping(base, again, beyond, nowhere, ours), w.upstream(false), w.ours());
|
|
86
|
+
const said = report.problems.map((one) => `${one.entry}: ${one.message.split(" ").slice(0, 3).join(" ")}`);
|
|
87
|
+
expect(said).toContain(`${base.id}: the id is`);
|
|
88
|
+
expect(said).toContain("beyond: upstream range [0,");
|
|
89
|
+
expect(said).toContain("nowhere: poteto-mode/none.md is not");
|
|
90
|
+
expect(said).toContain("ours: our range [0,");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("a dropped entry needs a note and no range of ours, and any other kind needs a range of ours", async () => {
|
|
94
|
+
const w = await World.make();
|
|
95
|
+
const base = covering(w).find((one) => one.id === "skill.alpha") as ReturnType<typeof covering>[number];
|
|
96
|
+
const noNote = { ...base, id: "no-note", kind: "dropped" as const, ours: [], note: undefined };
|
|
97
|
+
const linked = { ...base, id: "linked", kind: "dropped" as const, note: "why" };
|
|
98
|
+
const unlinked = { ...base, id: "unlinked", kind: "code" as const, ours: [] };
|
|
99
|
+
const { note: _note, ...bare } = noNote;
|
|
100
|
+
const report = analyze(mapping(bare, linked, unlinked), w.upstream(false), w.ours());
|
|
101
|
+
expect(report.problems.map((one) => `${one.entry}: ${one.message}`)).toEqual([
|
|
102
|
+
"no-note: a dropped entry says why in its note",
|
|
103
|
+
"linked: a dropped entry has no range of ours",
|
|
104
|
+
"unlinked: a code entry links to the ranges of ours that carry it",
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("a range of ours that only shifted is unchanged, at its new position", async () => {
|
|
109
|
+
const w = await World.make();
|
|
110
|
+
const entry = w.entry("a", "code", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle: "Alpha block." }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
111
|
+
const later = w.evolveOurs({ "src/brief.ts": `// header\n${BRIEF}` });
|
|
112
|
+
const report = analyze(mapping(entry), w.upstream(false), w.ours());
|
|
113
|
+
const moved = report.entries[0]?.ours[0];
|
|
114
|
+
expect(moved?.status).toBe("unchanged");
|
|
115
|
+
expect(moved?.to).toEqual({ commit: later, file: "src/brief.ts", range: [...at(`// header\n${BRIEF}`, "// the assembler")] });
|
|
116
|
+
expect(report.entries[0]?.status).toBe("unchanged");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("a range of ours that was edited is touched, with its old and new text", async () => {
|
|
120
|
+
const w = await World.make();
|
|
121
|
+
const entry = w.entry("a", "code", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle: "Alpha block." }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
122
|
+
w.evolveOurs({ "src/brief.ts": BRIEF.replace("// the assembler", "// the new assembler") });
|
|
123
|
+
const report = analyze(mapping(entry), w.upstream(false), w.ours());
|
|
124
|
+
const moved = report.entries[0]?.ours[0];
|
|
125
|
+
expect(report.entries[0]?.status).toBe("touched");
|
|
126
|
+
expect(moved?.status).toBe("touched");
|
|
127
|
+
expect(moved?.old).toBe("// the assembler");
|
|
128
|
+
expect(moved?.new).toContain("new assembler");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("a file of ours that was renamed is followed, and one that was deleted is gone", async () => {
|
|
132
|
+
const w = await World.make();
|
|
133
|
+
const entry = (id: string, file: string, text: string) => w.entry(id, "adapted", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle: id === "r" ? "Alpha block." : "Beta block." }, [{ file, text, needle: "Own words." }]);
|
|
134
|
+
const entries = [entry("r", "src/adapted.md", OURS_FILES["src/adapted.md"] as string), w.entry("d", "code", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle: "Beta block." }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }])];
|
|
135
|
+
const head = w.evolveOurs({ "src/adapted.md": null, "src/renamed.md": OURS_FILES["src/adapted.md"] as string, "src/brief.ts": null });
|
|
136
|
+
const report = analyze(mapping(...entries), w.upstream(false), w.ours());
|
|
137
|
+
expect(report.entries.find((one) => one.id === "r")?.ours[0]?.to).toEqual({ commit: head, file: "src/renamed.md", range: [0, 10] });
|
|
138
|
+
expect(report.entries.find((one) => one.id === "d")?.status).toBe("gone");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("our side is measured against the working tree on request, and against HEAD otherwise", async () => {
|
|
142
|
+
const w = await World.make();
|
|
143
|
+
const entry = w.entry("a", "code", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle: "Alpha block." }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
144
|
+
const { writeFileSync } = await import("node:fs");
|
|
145
|
+
writeFileSync(`${w.oursDir}/src/brief.ts`, BRIEF.replace("// the assembler", "// edited"));
|
|
146
|
+
expect(analyze(mapping(entry), w.upstream(false), w.ours()).entries[0]?.status).toBe("unchanged");
|
|
147
|
+
expect(analyze(mapping(entry), w.upstream(false), w.ours("worktree")).entries[0]?.status).toBe("touched");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("a new upstream commit moves the upstream side: shifted, touched with both texts, and gone", async () => {
|
|
151
|
+
const w = await World.make();
|
|
152
|
+
const recorded = w.upstreamCommit;
|
|
153
|
+
const e = (id: string, file: string, text: string, needle: string) => w.entry(id, "prompt", { file, text, needle }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
154
|
+
const entries = [e("alpha", "poteto-mode/SKILL.md", SKILL_TEXT, "Alpha block.\n"), e("beta", "poteto-mode/SKILL.md", SKILL_TEXT, "Beta block.\n"), e("fix", "poteto-mode/playbooks/bug-fix.md", BUG_TEXT, "Fix the cause.\n")];
|
|
155
|
+
const next = w.evolveUpstream({ [SKILL]: SKILL_TEXT.replace("# Mode\n", "# Mode\n\nNew intro.\n").replace("Beta block.", "Beta block, reworded."), [BUG_FIX]: BUG_TEXT.replace("Fix the cause.\n", "") });
|
|
156
|
+
const report = analyze(mapping(...entries), w.upstream(), w.ours());
|
|
157
|
+
expect(report.upstream.commit).toBe(next);
|
|
158
|
+
const by = (id: string) => report.entries.find((one) => one.id === id);
|
|
159
|
+
expect(by("alpha")?.upstream.status).toBe("unchanged");
|
|
160
|
+
expect(by("alpha")?.upstream.from.commit).toBe(recorded);
|
|
161
|
+
expect(by("alpha")?.upstream.to?.commit).toBe(next);
|
|
162
|
+
expect(by("beta")?.upstream.status).toBe("touched");
|
|
163
|
+
expect(by("beta")?.upstream.old).toBe("Beta block.\n");
|
|
164
|
+
expect(by("beta")?.upstream.new).toBe("Beta block, reworded.\n");
|
|
165
|
+
expect(by("fix")?.status).toBe("gone");
|
|
166
|
+
expect(report.unresolved).toBe(2);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("text upstream added since the recorded commit is reported as new uncovered text", async () => {
|
|
170
|
+
const w = await World.make();
|
|
171
|
+
const e = (id: string, needle: string) => w.entry(id, "prompt", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
172
|
+
const map = mapping(e("alpha", "Alpha block.\n"), e("beta", "Beta block.\n"));
|
|
173
|
+
w.evolveUpstream({ [SKILL]: `${SKILL_TEXT}\nGamma block.\n` });
|
|
174
|
+
const skill = analyze(map, w.upstream(), w.ours()).coverage.files.find((one) => one.file === "poteto-mode/SKILL.md");
|
|
175
|
+
const added = skill?.uncovered.filter((one) => one.added).map((one) => one.text);
|
|
176
|
+
expect(added).toEqual(["\nGamma block.\n"]);
|
|
177
|
+
expect(skill?.uncovered.some((one) => !one.added && one.text.includes("# Mode"))).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("a range at an upstream commit needs the checkout it is read from", async () => {
|
|
181
|
+
const w = await World.make();
|
|
182
|
+
const e = w.entry("alpha", "prompt", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle: "Alpha block.\n" }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
183
|
+
w.evolveUpstream({ [SKILL]: `${SKILL_TEXT}\nGamma block.\n` });
|
|
184
|
+
expect(() => analyze(mapping(e), w.upstream(false), w.ours())).toThrow("give the upstream checkout");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("advance records the unchanged entries at the current commits and leaves the touched ones", async () => {
|
|
188
|
+
const w = await World.make();
|
|
189
|
+
const e = (id: string, needle: string) => w.entry(id, "prompt", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
190
|
+
const map = mapping(e("alpha", "Alpha block.\n"), e("beta", "Beta block.\n"));
|
|
191
|
+
const next = w.evolveUpstream({ [SKILL]: SKILL_TEXT.replace("Beta block.", "Beta, reworded.").replace("# Mode\n", "# Mode\n\nIntro.\n") });
|
|
192
|
+
const ours = w.evolveOurs({ "src/brief.ts": `// top\n${BRIEF}` });
|
|
193
|
+
const report = analyze(map, w.upstream(), w.ours());
|
|
194
|
+
const advanced = advance(map, report);
|
|
195
|
+
expect(advanced.entries[0]?.upstream.commit).toBe(next);
|
|
196
|
+
expect(advanced.entries[0]?.ours[0]?.commit).toBe(ours);
|
|
197
|
+
expect(advanced.entries[1]).toEqual(map.entries[1]);
|
|
198
|
+
// After it, the entry is read at the current commits: nothing to carry, nothing moved.
|
|
199
|
+
const after = analyze(advanced, w.upstream(), w.ours());
|
|
200
|
+
expect(after.entries.find((one) => one.id === "alpha")?.status).toBe("unchanged");
|
|
201
|
+
expect(after.entries.find((one) => one.id === "alpha")?.upstream.from.commit).toBe(next);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("accept records the named touched entry at its carried positions, and refuses a gone one", async () => {
|
|
205
|
+
const w = await World.make();
|
|
206
|
+
const e = (id: string, needle: string, file = "poteto-mode/SKILL.md", text = SKILL_TEXT) => w.entry(id, "prompt", { file, text, needle }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
207
|
+
const map = mapping(e("beta", "Beta block.\n"), e("fix", "Fix the cause.\n", "poteto-mode/playbooks/bug-fix.md", BUG_TEXT));
|
|
208
|
+
w.evolveUpstream({ [SKILL]: SKILL_TEXT.replace("Beta block.", "Beta, reworded."), [BUG_FIX]: BUG_TEXT.replace("Fix the cause.\n", "") });
|
|
209
|
+
const report = analyze(map, w.upstream(), w.ours());
|
|
210
|
+
const accepted = accept(map, report, ["beta"]);
|
|
211
|
+
expect(accepted.entries[0]?.upstream.commit).toBe(w.upstreamCommit);
|
|
212
|
+
expect(report.entries.find((one) => one.id === "beta")?.status).toBe("touched");
|
|
213
|
+
expect(analyze(accepted, w.upstream(), w.ours()).entries.find((one) => one.id === "beta")?.status).toBe("unchanged");
|
|
214
|
+
expect(() => accept(map, report, ["fix"])).toThrow("is gone");
|
|
215
|
+
expect(() => accept(map, report, ["nope"])).toThrow("is not an entry");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("the working tree cannot be recorded: the ranges of ours need a commit", async () => {
|
|
219
|
+
const w = await World.make();
|
|
220
|
+
const e = w.entry("alpha", "prompt", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle: "Alpha block.\n" }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
221
|
+
const map = mapping(e);
|
|
222
|
+
expect(() => advance(map, analyze(map, w.upstream(false), w.ours("worktree")))).toThrow("commit");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("texts are assembled from the blocks: prompt verbatim, adapted from our text, code and dropped left out", async () => {
|
|
226
|
+
const w = await World.make();
|
|
227
|
+
const own = OURS_FILES["src/adapted.md"] as string;
|
|
228
|
+
const blocks = [
|
|
229
|
+
w.entry("head", "prompt", { file: "poteto-mode/playbooks/bug-fix.md", text: BUG_TEXT, needle: "### Bug fix\n\n" }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]),
|
|
230
|
+
w.entry("step", "adapted", { file: "poteto-mode/playbooks/bug-fix.md", text: BUG_TEXT, needle: "Reproduce it.\n\n" }, [{ file: "src/adapted.md", text: own, needle: "Own words.\n" }]),
|
|
231
|
+
w.entry("fix", "code", { file: "poteto-mode/playbooks/bug-fix.md", text: BUG_TEXT, needle: "Fix the cause.\n" }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]),
|
|
232
|
+
w.entry("worker", "prompt", { file: "poteto-mode/worker.md", text: UPSTREAM_FILES["skills/poteto-mode/worker.md"] as string, needle: "Work for the operator.\n" }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]),
|
|
233
|
+
];
|
|
234
|
+
const made = assemble(mapping(...blocks), w.upstream(false), w.ours());
|
|
235
|
+
expect(made).toEqual([
|
|
236
|
+
{ name: "bug-fix", title: "Bug fix", text: "### Bug fix\n\nOwn words.\n" },
|
|
237
|
+
{ name: "worker", title: "Worker rules", text: "Work for the operator.\n" },
|
|
238
|
+
]);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("a text whose blocks are all prompt is its upstream file byte for byte, and an unmapped file has no text", async () => {
|
|
242
|
+
const w = await World.make();
|
|
243
|
+
const e = w.entry("all", "prompt", { file: "poteto-mode/playbooks/bug-fix.md", text: BUG_TEXT, needle: BUG_TEXT }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
244
|
+
const made = assemble(mapping(e), w.upstream(false), w.ours());
|
|
245
|
+
expect(made.map((one) => one.name)).toEqual(["bug-fix"]);
|
|
246
|
+
expect(made[0]?.text).toBe(BUG_TEXT);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("a block recorded at an older upstream commit is not assembled", async () => {
|
|
250
|
+
const w = await World.make();
|
|
251
|
+
const e = w.entry("alpha", "prompt", { file: "poteto-mode/playbooks/bug-fix.md", text: BUG_TEXT, needle: "Fix the cause.\n" }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
252
|
+
w.evolveUpstream({ [BUG_FIX]: `${BUG_TEXT}More.\n` });
|
|
253
|
+
expect(() => assemble(mapping(e), w.upstream(), w.ours())).toThrow("carry the entry to the snapshot");
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("the mapping is written an entry to a line, and read back as it was", async () => {
|
|
257
|
+
const w = await World.make();
|
|
258
|
+
const map = mapping(...covering(w));
|
|
259
|
+
const text = formatMapping(map);
|
|
260
|
+
expect(text.split("\n").filter((line) => line.includes('"id"'))).toHaveLength(map.entries.length);
|
|
261
|
+
expect(parseMapping(text)).toEqual(map);
|
|
262
|
+
expect(() => parseMapping('{"entries":[{"id":"x"}]}')).toThrow();
|
|
263
|
+
expect(() => parseMapping(JSON.stringify({ entries: [{ ...map.entries[0], upstream: { ...map.entries[0]?.upstream, range: [5, 5] } }] }))).toThrow();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test("the report says what is touched with the old and new text, and draws no conclusion", async () => {
|
|
267
|
+
const w = await World.make();
|
|
268
|
+
const e = w.entry("beta", "prompt", { file: "poteto-mode/SKILL.md", text: SKILL_TEXT, needle: "Beta block.\n" }, [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }]);
|
|
269
|
+
w.evolveUpstream({ [SKILL]: SKILL_TEXT.replace("Beta block.", "Beta, reworded.") });
|
|
270
|
+
const text = formatReport(analyze(mapping(e), w.upstream(), w.ours()));
|
|
271
|
+
expect(text).toContain("COVERAGE");
|
|
272
|
+
expect(text).toContain("touched beta (prompt)");
|
|
273
|
+
expect(text).toContain('old: "Beta block."');
|
|
274
|
+
expect(text).toContain('new: "Beta, reworded."');
|
|
275
|
+
expect(git(w.upstreamDir, "rev-parse", "HEAD")).toContain(w.upstreamCommit);
|
|
276
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// A tiny upstream checkout and a repository with a tiny pstack-shaped package folder that maps it, for the tests of the
|
|
2
|
+
// tool on a package folder and of the sync.
|
|
3
|
+
|
|
4
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
import { tempDir } from "@niwa-labs/testing";
|
|
8
|
+
|
|
9
|
+
import { formatMapping } from "../src/mapping/index.ts";
|
|
10
|
+
import type { Entry } from "../src/mapping/index.ts";
|
|
11
|
+
import { refreshUpstream } from "../src/upstream.ts";
|
|
12
|
+
import { commitFiles, git } from "./mapping-support.ts";
|
|
13
|
+
|
|
14
|
+
export const UPSTREAM_FILES_V1: Record<string, string> = {
|
|
15
|
+
LICENSE: "MIT License\n",
|
|
16
|
+
"skills/poteto-mode/SKILL.md": "# Mode\n\nAlpha block.\n",
|
|
17
|
+
"skills/poteto-mode/worker.md": "Work for the operator.\n",
|
|
18
|
+
"skills/poteto-mode/playbooks/bug-fix.md": "### Bug fix\n\nReproduce it.\n\nFix the cause.\n",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** The files of the snapshot, as the map names them, with their texts. */
|
|
22
|
+
export const SNAPSHOT_V1: Record<string, string> = {
|
|
23
|
+
"poteto-mode/SKILL.md": UPSTREAM_FILES_V1["skills/poteto-mode/SKILL.md"] as string,
|
|
24
|
+
"poteto-mode/worker.md": UPSTREAM_FILES_V1["skills/poteto-mode/worker.md"] as string,
|
|
25
|
+
"poteto-mode/playbooks/bug-fix.md": UPSTREAM_FILES_V1["skills/poteto-mode/playbooks/bug-fix.md"] as string,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** An upstream checkout, committed: its folder and the commit. */
|
|
29
|
+
export async function upstreamCheckout(files: Record<string, string> = UPSTREAM_FILES_V1): Promise<{ dir: string; commit: string }> {
|
|
30
|
+
const dir = await tempDir("upstream");
|
|
31
|
+
git(dir, "init", "-q", "-b", "main");
|
|
32
|
+
return { dir, commit: commitFiles(dir, files, "upstream") };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The entries that cover a snapshot whole: the skill is dropped, the rest goes into prompts, linked to `ours`. */
|
|
36
|
+
export function entriesFor(upstreamCommit: string, oursCommit: string, texts: Record<string, string> = SNAPSHOT_V1): Entry[] {
|
|
37
|
+
return Object.entries(texts).map(([file, text], index): Entry => {
|
|
38
|
+
const upstream = { commit: upstreamCommit, file, range: [0, text.length] as [number, number] };
|
|
39
|
+
return file.endsWith("SKILL.md")
|
|
40
|
+
? { id: `skill:${String(index)}`, upstream, ours: [], kind: "dropped", note: "Not taken: a skill of Cursor's." }
|
|
41
|
+
: { id: `${file.split("/").at(-1)?.replace(/\.md$/, "") ?? file}:01`, upstream, ours: [{ commit: oursCommit, file: "README.md", range: [0, 1] }], kind: "prompt" };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Put a package folder into the repository `root`: the snapshot of `checkout` at `commit` and a map that covers it, committed. */
|
|
46
|
+
export function seedPackage(root: string, checkout: string, commit: string, kinds: { worker?: Entry["kind"]; bugFix?: Entry["kind"] } = {}): { packageDir: string; oursCommit: string; entries: Entry[] } {
|
|
47
|
+
const oursCommit = git(root, "rev-parse", "HEAD");
|
|
48
|
+
const packageDir = join(root, "packages", "pstack");
|
|
49
|
+
mkdirSync(packageDir, { recursive: true });
|
|
50
|
+
refreshUpstream(checkout, { upstream: join(packageDir, "upstream"), commit });
|
|
51
|
+
const entries = entriesFor(commit, oursCommit).map((one) => {
|
|
52
|
+
const kind = one.upstream.file.endsWith("worker.md") ? kinds.worker : one.upstream.file.endsWith("bug-fix.md") ? kinds.bugFix : undefined;
|
|
53
|
+
return kind === undefined ? one : { ...one, kind };
|
|
54
|
+
});
|
|
55
|
+
writeFileSync(join(packageDir, "upstream", "mapping.json"), formatMapping({ entries }));
|
|
56
|
+
git(root, "add", "-A");
|
|
57
|
+
git(root, "commit", "-q", "-m", "snapshot and map");
|
|
58
|
+
return { packageDir, oursCommit, entries };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A repository whose package folder holds the snapshot of `checkout` at `commit` and a map that covers it. */
|
|
62
|
+
export async function packageRepo(checkout: string, commit: string): Promise<{ root: string; packageDir: string; oursCommit: string }> {
|
|
63
|
+
const root = await tempDir("repo");
|
|
64
|
+
git(root, "init", "-q", "-b", "main");
|
|
65
|
+
commitFiles(root, { "README.md": "The billing service.\n" }, "start");
|
|
66
|
+
const seeded = seedPackage(root, checkout, commit);
|
|
67
|
+
return { root, packageDir: seeded.packageDir, oursCommit: seeded.oursCommit };
|
|
68
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// The merge policy as data: what it asks evidence for, how a go is bound to the plan, and what clears a landing.
|
|
2
|
+
|
|
3
|
+
import { expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import { coverage } from "@niwa-labs/evidence";
|
|
6
|
+
import type { Attestation } from "@niwa-labs/evidence";
|
|
7
|
+
|
|
8
|
+
import { decide, goCovers, goDigest, goSubject, mayGiveGo, mergeRequirements } from "../src/policy.ts";
|
|
9
|
+
import type { Listed } from "../src/policy.ts";
|
|
10
|
+
|
|
11
|
+
const sha = (c: string) => c.repeat(40);
|
|
12
|
+
const author = { kind: "session", harness: "author", id: "native-1" } as const;
|
|
13
|
+
const verifier = { kind: "session", harness: "verifier", id: "native-2" } as const;
|
|
14
|
+
const subject = "gitlab.example.com/acme/billing/pr/7";
|
|
15
|
+
const plan = { of: "billing/q4", rev: 3 };
|
|
16
|
+
|
|
17
|
+
test("a go is bound to the plan's revision, the node and the change", () => {
|
|
18
|
+
const digest = goDigest(plan, "n1", "gitlab.example.com/acme/billing");
|
|
19
|
+
expect(digest).toMatch(/^[0-9a-f]{64}$/);
|
|
20
|
+
expect(goDigest({ ...plan, rev: 4 }, "n1", "gitlab.example.com/acme/billing")).not.toBe(digest);
|
|
21
|
+
expect(goDigest(plan, "n2", "gitlab.example.com/acme/billing")).not.toBe(digest);
|
|
22
|
+
expect(goDigest(plan, "n1", "gitlab.example.com/acme/payroll")).not.toBe(digest);
|
|
23
|
+
expect(goSubject(plan, "n1")).toBe("plan/billing%2Fq4/rev-3/n1");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const go = (id: string, by: Listed["author"], sha: string, outcome = "pass"): Listed => ({ id, author: by, claim: { kind: "verdict", name: "go", outcome, sha } });
|
|
27
|
+
|
|
28
|
+
test("a go counts only from the owner or a run, for the revision it was given on", () => {
|
|
29
|
+
const change = "gitlab.example.com/acme/billing";
|
|
30
|
+
const digest = goDigest(plan, "n1", change);
|
|
31
|
+
expect(goCovers([go("a", { kind: "client", id: "run:run-1" }, digest)], plan, "n1", change)).toEqual({ covered: true, by: ["a"] });
|
|
32
|
+
expect(goCovers([go("a", { kind: "owner" }, digest)], plan, "n1", change).covered).toBe(true);
|
|
33
|
+
// An author's own session cannot give itself a go.
|
|
34
|
+
expect(goCovers([go("a", author, digest)], plan, "n1", change)).toMatchObject({ covered: false, why: "not-the-owner" });
|
|
35
|
+
// A go of the revision before does not cover the revised plan.
|
|
36
|
+
expect(goCovers([go("a", { kind: "owner" }, goDigest({ ...plan, rev: 2 }, "n1", change))], plan, "n1", change)).toMatchObject({ covered: false, why: "none" });
|
|
37
|
+
// A go withdrawn later is withdrawn.
|
|
38
|
+
expect(goCovers([go("a", { kind: "owner" }, digest), go("b", { kind: "owner" }, digest, "fail")], plan, "n1", change)).toMatchObject({ covered: false, why: "withdrawn" });
|
|
39
|
+
expect(mayGiveGo({ kind: "client", id: "session:x" })).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/** The attestations the evidence module would hold, with ids in order. */
|
|
43
|
+
function attestations(...items: Array<{ author: Attestation["author"]; claim: Attestation["claim"] }>): Attestation[] {
|
|
44
|
+
return items.map((one, index) => ({ id: `e${String(index)}`, seq: index + 1, at: index, subject, ...one }));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const pair = { sha: sha("b"), pipeline: 12 };
|
|
48
|
+
const required = mergeRequirements({ subject, head: sha("a"), author, target: pair });
|
|
49
|
+
|
|
50
|
+
/** What the policy decides over these attestations, held to the evidence module's own coverage. */
|
|
51
|
+
const decideOver = (held: Attestation[]) => decide(required.map(({ name, requirement }) => ({ name, ...coverage(held, requirement as never) })));
|
|
52
|
+
|
|
53
|
+
const green = [
|
|
54
|
+
{ author: verifier, claim: { kind: "verdict", name: "gates", outcome: "pass", sha: sha("a") } },
|
|
55
|
+
{ author: verifier, claim: { kind: "verdict", name: "live", outcome: "pass", sha: sha("a") } },
|
|
56
|
+
{ author: { kind: "client", id: "run:r" }, claim: { kind: "ci", at: "head", sha: sha("a"), pipeline: 11 } },
|
|
57
|
+
{ author: { kind: "client", id: "run:r" }, claim: { kind: "ci", at: "merge-result", sourceSha: sha("a"), targetSha: sha("b"), mergeSha: sha("c"), pipeline: 12, pipelineKind: "merge-result" } },
|
|
58
|
+
] as const satisfies ReadonlyArray<{ author: Attestation["author"]; claim: Attestation["claim"] }>;
|
|
59
|
+
|
|
60
|
+
test("a pull request lands when every requirement is covered at its head", () => {
|
|
61
|
+
expect(decideOver(attestations(...green))).toEqual({ land: true });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("a verdict by the author of the patch does not count", () => {
|
|
65
|
+
const byAuthor = green.map((one) => (one.claim.kind === "verdict" && one.claim.name === "live" ? { ...one, author } : one));
|
|
66
|
+
expect(decideOver(attestations(...byAuthor))).toEqual({ land: false, missing: [{ name: "live", why: "excluded-author" }] });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("green CI alone never clears a landing", () => {
|
|
70
|
+
expect(decideOver(attestations(...green.filter((one) => one.claim.kind === "ci")))).toEqual({
|
|
71
|
+
land: false,
|
|
72
|
+
missing: [
|
|
73
|
+
{ name: "gates", why: "none" },
|
|
74
|
+
{ name: "live", why: "none" },
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("a merge result of a target that moved, or a head pipeline in its place, does not cover the pair", () => {
|
|
80
|
+
const moved = green.map((one) => (one.claim.kind === "ci" && one.claim.at === "merge-result" ? { ...one, claim: { ...one.claim, targetSha: sha("d") } } : one));
|
|
81
|
+
expect(decideOver(attestations(...moved))).toEqual({ land: false, missing: [{ name: "merge-result", why: "target-moved" }] });
|
|
82
|
+
// GitLab ran an ordinary pipeline of the head where the merge result was selected.
|
|
83
|
+
const headOnly = green
|
|
84
|
+
.filter((one) => !(one.claim.kind === "ci" && one.claim.at === "merge-result"))
|
|
85
|
+
.map((one) => (one.claim.kind === "ci" ? { ...one, claim: { ...one.claim, pipeline: 12 } } : one));
|
|
86
|
+
expect(decideOver(attestations(...headOnly))).toEqual({ land: false, missing: [{ name: "merge-result", why: "not-merge-result" }] });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("a verdict on an older head does not cover the new one, and red head CI is missing", () => {
|
|
90
|
+
const older = green.map((one) => (one.claim.kind === "verdict" && one.claim.name === "gates" ? { ...one, claim: { ...one.claim, sha: sha("e") } } : one));
|
|
91
|
+
expect(decideOver(attestations(...older))).toEqual({ land: false, missing: [{ name: "gates", why: "none" }] });
|
|
92
|
+
const noHead = green.filter((one) => !(one.claim.kind === "ci" && one.claim.at === "head"));
|
|
93
|
+
expect(decideOver(attestations(...noHead))).toEqual({ land: false, missing: [{ name: "head-ci", why: "none" }] });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("nothing checked is not a landing", () => {
|
|
97
|
+
expect(decide([])).toEqual({ land: false, missing: [{ name: "policy", why: "nothing was checked" }] });
|
|
98
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Benny's ports: pstack ships the contracts and no implementation. A host that lacks a port refuses to enable Benny and
|
|
2
|
+
// says which; a provider's actions are held to the contract they implement.
|
|
3
|
+
|
|
4
|
+
import { afterEach, expect, test } from "bun:test";
|
|
5
|
+
|
|
6
|
+
import { pstackHost } from "./support.ts";
|
|
7
|
+
import type { PstackHost } from "./support.ts";
|
|
8
|
+
|
|
9
|
+
const hosts: PstackHost[] = [];
|
|
10
|
+
afterEach(async () => {
|
|
11
|
+
for (const one of hosts.splice(0)) await one.close();
|
|
12
|
+
}, 30_000);
|
|
13
|
+
|
|
14
|
+
test("a host that lacks a port of Benny's refuses to enable him, and names every port it lacks", async () => {
|
|
15
|
+
await expect(pstackHost({ withoutPorts: ["tracker", "control"] })).rejects.toThrow(/issue tracker port \(benny\.tracker\.\*\)[\s\S]*product control port \(benny\.control\.\*\)/);
|
|
16
|
+
const error = await pstackHost({ withoutPorts: ["channel"] }).catch((caught: Error) => caught);
|
|
17
|
+
expect(error).toBeInstanceOf(Error);
|
|
18
|
+
expect((error as Error).message).toContain("report channel port (benny.channel.*)");
|
|
19
|
+
expect((error as Error).message).not.toContain("issue tracker");
|
|
20
|
+
expect((error as Error).message).toContain("before pstack");
|
|
21
|
+
expect((error as Error).message).toContain("Benny needs your plugins");
|
|
22
|
+
}, 60_000);
|
|
23
|
+
|
|
24
|
+
test("a host with no Benny needs no port", async () => {
|
|
25
|
+
const made = await pstackHost({ benny: false, withoutPorts: ["tracker", "channel", "control"] });
|
|
26
|
+
hosts.push(made);
|
|
27
|
+
expect(made.agents).toEqual([]);
|
|
28
|
+
// The suite's grant names the port actions, so they exist; with no Benny they only say so.
|
|
29
|
+
await expect(made.asOwner("benny.tracker.find", { text: "x" })).rejects.toThrow("Benny is not enabled");
|
|
30
|
+
}, 60_000);
|
|
31
|
+
|
|
32
|
+
test("a provider's actions are held to the contract: input and output are checked by the references", async () => {
|
|
33
|
+
const made = await pstackHost();
|
|
34
|
+
hosts.push(made);
|
|
35
|
+
const created = (await made.asOwner("benny.tracker.create", { title: "README names the wrong service", body: "Quoted.", source: "thread-1" })) as { id: string; url: string };
|
|
36
|
+
expect(created.id).toBe("ISSUE-1");
|
|
37
|
+
const found = (await made.asOwner("benny.tracker.find", { text: "wrong service" })) as { items: Array<{ id: string; state: string }> };
|
|
38
|
+
expect(found.items).toEqual([expect.objectContaining({ id: "ISSUE-1", state: "open" })]);
|
|
39
|
+
await expect(made.asOwner("benny.tracker.find", { text: "x", state: "pending" })).rejects.toThrow();
|
|
40
|
+
await expect(made.asOwner("benny.tracker.create", { title: "no source", body: "x" })).rejects.toThrow();
|
|
41
|
+
expect(await made.asOwner("benny.tracker.link-pr", { id: "ISSUE-1", pr: "gitlab.example.com/acme/billing/pr/7" })).toEqual({ ok: true });
|
|
42
|
+
expect(await made.asOwner("benny.channel.reply", { source: "thread-1", text: "A bug." })).toEqual({ id: "msg-1" });
|
|
43
|
+
expect(await made.asOwner("benny.control.capabilities", {})).toEqual({ features: ["readme"], missing: [] });
|
|
44
|
+
await expect(made.asOwner("benny.control.drive", { session: "app-1" })).rejects.toThrow();
|
|
45
|
+
}, 60_000);
|