@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.
Files changed (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +260 -2
  3. package/package.json +28 -4
  4. package/scripts/upstream-map.ts +90 -0
  5. package/src/author.ts +57 -0
  6. package/src/binding.ts +32 -0
  7. package/src/catalog.ts +86 -0
  8. package/src/composition.ts +66 -0
  9. package/src/index.ts +50 -0
  10. package/src/mapping/analyze.ts +223 -0
  11. package/src/mapping/assemble.ts +96 -0
  12. package/src/mapping/diff.ts +139 -0
  13. package/src/mapping/format.ts +67 -0
  14. package/src/mapping/git.ts +69 -0
  15. package/src/mapping/index.ts +18 -0
  16. package/src/mapping/maintain.ts +36 -0
  17. package/src/mapping/schema.ts +50 -0
  18. package/src/mapping/sources.ts +108 -0
  19. package/src/mapping/tool.ts +77 -0
  20. package/src/mapping/verify.ts +130 -0
  21. package/src/plugin.ts +136 -0
  22. package/src/policy.ts +115 -0
  23. package/src/ports.ts +184 -0
  24. package/src/pr-binding.ts +88 -0
  25. package/src/records.ts +61 -0
  26. package/src/roles.ts +49 -0
  27. package/src/trunk.ts +59 -0
  28. package/src/upstream-actions.ts +135 -0
  29. package/src/upstream-records.ts +71 -0
  30. package/src/upstream.ts +151 -0
  31. package/src/workflows/adapted.md +780 -0
  32. package/src/workflows/authoring-a-skill.ts +52 -0
  33. package/src/workflows/autonomous-run.ts +56 -0
  34. package/src/workflows/autopilot-full.ts +90 -0
  35. package/src/workflows/autopilot-stack.ts +125 -0
  36. package/src/workflows/babysit.ts +124 -0
  37. package/src/workflows/benny-reproduce.ts +122 -0
  38. package/src/workflows/benny-triage.ts +89 -0
  39. package/src/workflows/bug-fix.ts +54 -0
  40. package/src/workflows/entry.ts +130 -0
  41. package/src/workflows/eval.ts +63 -0
  42. package/src/workflows/feature.ts +54 -0
  43. package/src/workflows/hillclimb.ts +78 -0
  44. package/src/workflows/investigation.ts +41 -0
  45. package/src/workflows/lib/catalog.ts +45 -0
  46. package/src/workflows/lib/change.ts +70 -0
  47. package/src/workflows/lib/forensics.ts +37 -0
  48. package/src/workflows/lib/git.ts +30 -0
  49. package/src/workflows/lib/go.ts +58 -0
  50. package/src/workflows/lib/inputs.ts +34 -0
  51. package/src/workflows/lib/lane.ts +170 -0
  52. package/src/workflows/lib/measure.ts +34 -0
  53. package/src/workflows/lib/plan.ts +24 -0
  54. package/src/workflows/lib/script.ts +79 -0
  55. package/src/workflows/lib/ship.ts +110 -0
  56. package/src/workflows/lib/texts.ts +18 -0
  57. package/src/workflows/lib/trunk.ts +91 -0
  58. package/src/workflows/multi-phase-plan.ts +83 -0
  59. package/src/workflows/opening-a-pr.ts +62 -0
  60. package/src/workflows/pause-safely.ts +50 -0
  61. package/src/workflows/perf-issue.ts +87 -0
  62. package/src/workflows/prototype.ts +76 -0
  63. package/src/workflows/refactoring.ts +54 -0
  64. package/src/workflows/runtime-forensics.ts +26 -0
  65. package/src/workflows/scenarios.ts +380 -0
  66. package/src/workflows/session-pickup.ts +57 -0
  67. package/src/workflows/shipping.ts +63 -0
  68. package/src/workflows/suite.ts +129 -0
  69. package/src/workflows/texts/authoring-a-skill.json +5 -0
  70. package/src/workflows/texts/autonomous-run.json +5 -0
  71. package/src/workflows/texts/autopilot-full.json +5 -0
  72. package/src/workflows/texts/autopilot-stack.json +5 -0
  73. package/src/workflows/texts/babysit.json +5 -0
  74. package/src/workflows/texts/benny-reproduce.json +5 -0
  75. package/src/workflows/texts/benny-triage.json +5 -0
  76. package/src/workflows/texts/bug-fix.json +5 -0
  77. package/src/workflows/texts/bugbot-triage.json +5 -0
  78. package/src/workflows/texts/eval.json +5 -0
  79. package/src/workflows/texts/feature.json +5 -0
  80. package/src/workflows/texts/hillclimb.json +5 -0
  81. package/src/workflows/texts/investigation.json +5 -0
  82. package/src/workflows/texts/multi-phase-plan.json +5 -0
  83. package/src/workflows/texts/opening-a-pr.json +5 -0
  84. package/src/workflows/texts/pause-safely.json +5 -0
  85. package/src/workflows/texts/perf-issue.json +5 -0
  86. package/src/workflows/texts/prototype.json +5 -0
  87. package/src/workflows/texts/refactoring.json +5 -0
  88. package/src/workflows/texts/runtime-forensics.json +5 -0
  89. package/src/workflows/texts/session-pickup.json +5 -0
  90. package/src/workflows/texts/trace-forensics.json +5 -0
  91. package/src/workflows/texts/visual-parity.json +5 -0
  92. package/src/workflows/texts/worker.json +5 -0
  93. package/src/workflows/trace-forensics.ts +27 -0
  94. package/src/workflows/upstream-sync.ts +182 -0
  95. package/src/workflows/visual-parity.ts +52 -0
  96. package/src/workflows/worktree-cleanup.ts +57 -0
  97. package/test/author.test.ts +61 -0
  98. package/test/benny.test.ts +138 -0
  99. package/test/binding.test.ts +54 -0
  100. package/test/catalog-helpers.test.ts +49 -0
  101. package/test/closure.test.ts +45 -0
  102. package/test/composition.test.ts +23 -0
  103. package/test/eval.test.ts +23 -0
  104. package/test/lanes.test.ts +334 -0
  105. package/test/mapping-diff.test.ts +64 -0
  106. package/test/mapping-support.ts +110 -0
  107. package/test/mapping-texts.test.ts +106 -0
  108. package/test/mapping.test.ts +276 -0
  109. package/test/package-layout.ts +68 -0
  110. package/test/policy.test.ts +98 -0
  111. package/test/ports.test.ts +45 -0
  112. package/test/ports.ts +173 -0
  113. package/test/roles.test.ts +21 -0
  114. package/test/suite.test.ts +167 -0
  115. package/test/support.ts +541 -0
  116. package/test/texts.test.ts +174 -0
  117. package/test/tool.test.ts +48 -0
  118. package/test/trunk-helpers.test.ts +149 -0
  119. package/test/trunk.test.ts +24 -0
  120. package/test/upstream-sync.test.ts +246 -0
  121. package/test/upstream.test.ts +106 -0
  122. package/test/worktree-cleanup.test.ts +107 -0
  123. package/tsconfig.json +7 -0
  124. package/upstream/LICENSE +21 -0
  125. package/upstream/SOURCE.json +5 -0
  126. package/upstream/benny/FOR_AGENTS.md +89 -0
  127. package/upstream/benny/README.md +23 -0
  128. package/upstream/benny/skills/reproduce-and-fix-issues/SKILL.md +310 -0
  129. package/upstream/benny/skills/reproduce-and-fix-issues/references/control-adapter.md +169 -0
  130. package/upstream/benny/skills/reproduce-and-fix-issues/references/feature-map.example.md +205 -0
  131. package/upstream/benny/skills/reproduce-and-fix-issues/references/verify-existing-fix.md +93 -0
  132. package/upstream/benny/skills/setup-benny/SKILL.md +265 -0
  133. package/upstream/benny/skills/triage-issue-reports/SKILL.md +240 -0
  134. package/upstream/benny/skills/triage-issue-reports/references/routing.example.md +61 -0
  135. package/upstream/benny/templates/configuration.example.yaml +84 -0
  136. package/upstream/benny/templates/reproduce-automation-prompt.md +33 -0
  137. package/upstream/benny/templates/triage-automation-prompt.md +39 -0
  138. package/upstream/mapping.json +699 -0
  139. package/upstream/poteto-mode/SKILL.md +110 -0
  140. package/upstream/poteto-mode/playbooks/authoring-a-skill.md +12 -0
  141. package/upstream/poteto-mode/playbooks/autonomous-run.md +13 -0
  142. package/upstream/poteto-mode/playbooks/autopilot-full.md +25 -0
  143. package/upstream/poteto-mode/playbooks/autopilot-stack.md +8 -0
  144. package/upstream/poteto-mode/playbooks/babysit.md +10 -0
  145. package/upstream/poteto-mode/playbooks/bug-fix.md +15 -0
  146. package/upstream/poteto-mode/playbooks/eval.md +25 -0
  147. package/upstream/poteto-mode/playbooks/feature.md +21 -0
  148. package/upstream/poteto-mode/playbooks/hillclimb.md +21 -0
  149. package/upstream/poteto-mode/playbooks/investigation.md +14 -0
  150. package/upstream/poteto-mode/playbooks/multi-phase-plan.md +11 -0
  151. package/upstream/poteto-mode/playbooks/opening-a-pr.md +9 -0
  152. package/upstream/poteto-mode/playbooks/pause-safely.md +10 -0
  153. package/upstream/poteto-mode/playbooks/perf-issue.md +25 -0
  154. package/upstream/poteto-mode/playbooks/prototype.md +14 -0
  155. package/upstream/poteto-mode/playbooks/refactoring.md +16 -0
  156. package/upstream/poteto-mode/playbooks/runtime-forensics.md +11 -0
  157. package/upstream/poteto-mode/playbooks/session-pickup.md +11 -0
  158. package/upstream/poteto-mode/playbooks/shipping.md +12 -0
  159. package/upstream/poteto-mode/playbooks/trace-forensics.md +14 -0
  160. package/upstream/poteto-mode/playbooks/visual-parity.md +11 -0
  161. package/upstream/poteto-mode/playbooks/worktree-cleanup.md +12 -0
  162. package/upstream/poteto-mode/references/bugbot-triage.md +142 -0
  163. package/upstream/poteto-mode/worker.md +11 -0
@@ -0,0 +1,334 @@
1
+ // Lanes, the go and landing on a host with the promoted set: the author is boxed to its worktree, a verdict the
2
+ // author gives itself does not count, a merge result that is not green keeps a pull request from landing, and the
3
+ // owner's go is bound to the revision of the plan it was given on.
4
+
5
+ import { afterEach, expect, test } from "bun:test";
6
+
7
+ import { deny, grant, principalOf } from "@niwa-labs/core";
8
+ import { sessionStart } from "@niwa-labs/sessions/records";
9
+ import { connect, plugin } from "@niwa-labs/testing";
10
+
11
+ import { UNGATED, gatedOf, scriptOf } from "../src/catalog.ts";
12
+ import { goDigest, goSubject } from "../src/policy.ts";
13
+ import { pstackPrBind } from "../src/pr-binding.ts";
14
+ import { pstackAuthorOptions } from "../src/records.ts";
15
+ import { FORGE_HOST, builtins, claimAsked, defaultAnswers, pstackHost, recordsOf, registeredAll } from "./support.ts";
16
+ import type { Answers, PstackHost, PstackHostOptions } from "./support.ts";
17
+
18
+ const hosts: PstackHost[] = [];
19
+ afterEach(async () => {
20
+ for (const one of hosts.splice(0)) await one.close();
21
+ }, 30_000);
22
+
23
+ /** A host whose set was tried and promoted by the suite, answering as `change` says from then on. */
24
+ async function promoted(options: PstackHostOptions = {}, change: (answers: Answers) => Answers = (answers) => answers): Promise<PstackHost> {
25
+ const made = await pstackHost(options);
26
+ hosts.push(made);
27
+ made.harnesses.answers = defaultAnswers(made);
28
+ await registeredAll(made.host, gatedOf(true).length + UNGATED.length);
29
+ const all = await builtins(made.host);
30
+ const suite = (await made.host.call("workflow.start" as never, { id: all["suite"]?.id, args: made.fixture, wait: true, timeoutMs: 120_000 } as never)) as { outcome?: { result?: { status: string } } };
31
+ if (suite.outcome?.result?.status !== "promoted") throw new Error(`the suite did not promote: ${JSON.stringify(suite).slice(0, 2000)}`);
32
+ made.harnesses.answers = change(defaultAnswers(made));
33
+ return made;
34
+ }
35
+
36
+ /** Run a promoted built-in to its end and answer its result. */
37
+ async function run(made: PstackHost, name: string, args: Record<string, unknown>): Promise<any> {
38
+ const all = await builtins(made.host);
39
+ const ended = (await made.host.call("workflow.start" as never, { id: all[name]?.id, args: { ...made.fixture, task: "Do it.", ...args }, wait: true, timeoutMs: 120_000 } as never)) as {
40
+ state: string;
41
+ outcome?: { status: string; result?: unknown };
42
+ reason?: string;
43
+ };
44
+ if (ended.outcome?.status !== "done") throw new Error(`${name} did not finish: ${JSON.stringify(ended).slice(0, 2000)}`);
45
+ return ended.outcome.result;
46
+ }
47
+
48
+ /** Plan two independent pull requests without asking, and give the go on them as the owner. */
49
+ async function plannedWithGo(made: PstackHost, of: string): Promise<{ plan: { of: string; rev: number }; nodes: Array<{ id: string }> }> {
50
+ const planned = await run(made, "multi-phase-plan", { plan: of, ask: false });
51
+ const change = `${made.fixture.repo.host}/${made.fixture.repo.path}`;
52
+ for (const node of planned.nodes as Array<{ id: string }>) {
53
+ await made.asOwner("evidence.attest", { subject: goSubject(planned.plan, node.id), claim: { kind: "verdict", name: "go", outcome: "pass", sha: goDigest(planned.plan, node.id, change) } });
54
+ }
55
+ return planned;
56
+ }
57
+
58
+ test("the author is started boxed to its own worktree and the forge, and a place elsewhere starts nothing", async () => {
59
+ const made = await promoted();
60
+ const authors = [...made.harnesses.sessions.values()].filter((one) => one.harness === "author");
61
+ expect(authors.length).toBeGreaterThan(0);
62
+ expect(authors.map((one) => one.box)).toContainEqual({ allow: ["project", { net: FORGE_HOST }] });
63
+ const tools = ["harness.list", "session.start@author", "session.ask", "session.end"];
64
+ for (const one of authors) {
65
+ expect(one.cwd?.startsWith(`${made.worktrees}/`)).toBe(true);
66
+ expect(one.box).toMatchObject({ allow: expect.arrayContaining(["project"]) });
67
+ expect(one.ended).toBe(true);
68
+ if (one.visible !== undefined) expect(one.visible).toEqual(tools);
69
+ expect(one.caller).toMatchObject({ kind: "client", principal: { kind: "run" } });
70
+ }
71
+ const attempts = made.harnesses.of("hillclimb:attempt");
72
+ expect(attempts).toHaveLength(2);
73
+ const ref = attempts[0]?.ref;
74
+ expect(ref).toBeDefined();
75
+ expect(attempts.map((call) => call.ref)).toEqual([ref, ref]);
76
+ expect(made.harnesses.lookup(ref ?? "")[1]).toMatchObject({ ended: true, visible: tools });
77
+
78
+ const before = made.harnesses.sessions.size;
79
+ await expect(made.host.call(pstackAuthorOptions, { place: made.repo })).rejects.toThrow("is not one of niwa's worktrees");
80
+ expect(made.harnesses.sessions.size).toBe(before);
81
+ }, 240_000);
82
+
83
+ test("checked author settings add only the forge network the caller can grant", async () => {
84
+ const made = await pstackHost({ benny: false });
85
+ hosts.push(made);
86
+ const { path } = await made.host.call("git.worktree.create" as never, { repo: made.repo, description: "author grant" } as never) as { path: string };
87
+ for (const [label, rule, allow] of [
88
+ ["local", [], ["project"]],
89
+ ["publish", [`box.net@${FORGE_HOST}`], ["project", { net: FORGE_HOST }]],
90
+ ] as const) {
91
+ const token = made.host.issueToken(principalOf("client", label), { grant: grant([pstackAuthorOptions.name, ...rule]) });
92
+ const client = await connect({ home: made.home, id: label, token });
93
+ try {
94
+ expect(await client.call(pstackAuthorOptions, { place: path })).toEqual({ harness: "author", cwd: path, box: { allow: [...allow] } });
95
+ expect(made.harnesses.sessions.size).toBe(0);
96
+ } finally {
97
+ await client.close();
98
+ }
99
+ }
100
+ }, 30_000);
101
+
102
+ test("the fake session preserves mixed visible action rules", async () => {
103
+ const made = await pstackHost({ benny: false });
104
+ hosts.push(made);
105
+ const actions = ["harness.list", { do: "session.ask", ask: true as const }];
106
+ const { ref } = await made.host.call(sessionStart, { harness: "author", prompt: "", visible: { actions } });
107
+ expect(made.harnesses.lookup(ref)[1].visible).toEqual(actions);
108
+ }, 30_000);
109
+
110
+ test("a verdict the author attests itself does not verify its pull request", async () => {
111
+ const made = await promoted({}, (answers) => ({
112
+ ...answers,
113
+ // The verifier finds nothing to attest; the author attests the live verdict as itself.
114
+ "*:verify-live": () => ({ outcome: "pass", evidence: "looked" }),
115
+ "*:build": async (call) => {
116
+ const built = (await answers["*:build"]?.(call)) as { sha: string; summary: string };
117
+ return built;
118
+ },
119
+ }));
120
+ const planned = await run(made, "multi-phase-plan", { plan: "own-verdict", ask: false });
121
+ // The author's session attests a live pass on whatever it is asked to verify once its pull request exists.
122
+ made.harnesses.answers["*:verify-gates"] = async (call) => {
123
+ const asked = claimAsked(call.prompt);
124
+ const author = [...made.harnesses.sessions.entries()].find(([, one]) => one.harness === "author" && one.cwd === call.cwd)?.[0];
125
+ await made.attestAs(author?.split(" ")[1] ?? "", asked.subject, { kind: "verdict", name: "live", outcome: "pass", sha: asked.sha });
126
+ await made.attestAs(call.ref?.split(" ")[1] ?? "", asked.subject, { kind: "verdict", name: "gates", outcome: "pass", sha: asked.sha });
127
+ return { outcome: "pass", evidence: "the gates passed" };
128
+ };
129
+ const stacked = await run(made, "autopilot-stack", { plan: planned.plan.of });
130
+ expect(stacked.nodes.map((one: { verified: boolean }) => one.verified)).toEqual([false, false]);
131
+ const attested = (await recordsOf(made.host, "evidence.attested")).map((one) => one.data as { claim: { name?: string }; author: { harness?: string } });
132
+ expect(attested.some((one) => one.claim.name === "live" && one.author.harness === "author")).toBe(true);
133
+ }, 240_000);
134
+
135
+ test("a merge result that is not green keeps a verified pull request with the go from landing", async () => {
136
+ const made = await promoted();
137
+ made.ci.mergeResult = "failed";
138
+ const planned = await plannedWithGo(made, "red-merge-result");
139
+ const done = await run(made, "autopilot-full", { plan: planned.plan.of });
140
+ for (const node of done.nodes as Array<{ verified: boolean; go: boolean; landed: { outcome: string; missing: Array<{ name: string }> } }>) {
141
+ expect(node).toMatchObject({ verified: true, go: true, landed: { outcome: "refused" } });
142
+ expect(node.landed.missing.map((one) => one.name)).toEqual(["merge-result"]);
143
+ }
144
+ const prs = new Set((done.nodes as Array<{ pr: number }>).map((one) => one.pr));
145
+ expect([...made.project.mrs.values()].filter((mr) => prs.has(mr.iid)).map((mr) => mr.state)).toEqual(["opened", "opened"]);
146
+ }, 240_000);
147
+
148
+ test("the owner's go is asked once, attested per node, and does not cover a revised plan", async () => {
149
+ const made = await promoted();
150
+ const all = await builtins(made.host);
151
+ const { run: started } = (await made.host.call("workflow.start" as never, { id: all["multi-phase-plan"]?.id, args: { ...made.fixture, task: "Do it.", plan: "with-go" } } as never)) as { run: string };
152
+ await made.answer(["yes"]);
153
+ const ended = (await made.host.call("workflow.wait" as never, { run: started, timeoutMs: 60_000 } as never)) as { outcome?: { result?: any } };
154
+ const planned = ended.outcome?.result as { go: boolean; plan: { of: string; rev: number }; nodes: Array<{ id: string }> };
155
+ expect(planned.go).toBe(true);
156
+ const goes = (await recordsOf(made.host, "evidence.attested")).map((one) => one.data as { subject: string; claim: { name: string; sha: string } }).filter((one) => one.claim.name === "go" && one.subject.includes("with-go"));
157
+ const change = `${made.fixture.repo.host}/${made.fixture.repo.path}`;
158
+ expect(goes.map((one) => [one.subject, one.claim.sha])).toEqual(planned.nodes.map((node) => [goSubject(planned.plan, node.id), goDigest(planned.plan, node.id, change)]));
159
+
160
+ // A revision of the plan: the go of revision 1 covers nothing of it, and nothing lands.
161
+ await made.host.call("plan.set" as never, { of: "with-go", goal: "Deliver the task, revised", items: planned.nodes.map((node) => ({ id: node.id, text: `${node.id}, revised`, state: "open" })) } as never);
162
+ const done = await run(made, "autopilot-full", { plan: "with-go" });
163
+ expect(done.nodes.map((one: { go: boolean; landed?: unknown }) => [one.go, one.landed])).toEqual([
164
+ [false, undefined],
165
+ [false, undefined],
166
+ ]);
167
+ }, 240_000);
168
+
169
+ /** A merge-result claim of a pull request's selected merge result, as the fake forge has it. */
170
+ function mergeResultClaim(made: PstackHost, number: number, sha: string) {
171
+ const pipeline = [...made.project.pipelines].reverse().find((one) => one.ref === `refs/merge-requests/${String(number)}/merge`);
172
+ const parents = pipeline === undefined ? undefined : made.project.commits.get(pipeline.sha);
173
+ if (pipeline === undefined || parents?.[0] === undefined) throw new Error(`no merge result of ${String(number)}`);
174
+ return { kind: "ci", at: "merge-result", sourceSha: sha, targetSha: parents[0], mergeSha: pipeline.sha, pipeline: pipeline.id, pipelineKind: "merge-result" };
175
+ }
176
+
177
+ test("a merge result a verifier attests does not stand in for the red one the forge reports", async () => {
178
+ const made = await promoted();
179
+ made.ci.mergeResult = "failed";
180
+ const planned = await plannedWithGo(made, "forged-merge-result");
181
+ // The verifiers, who are not the authors, also attest a green merge result of the pair the forge selected.
182
+ const verify = made.harnesses.answers["*:verify-gates"];
183
+ made.harnesses.answers["*:verify-gates"] = async (call) => {
184
+ const asked = claimAsked(call.prompt);
185
+ const number = Number(asked.subject.slice(asked.subject.lastIndexOf("/") + 1));
186
+ await made.attestAs(call.ref?.split(" ")[1] ?? "", asked.subject, mergeResultClaim(made, number, asked.sha));
187
+ return await verify?.(call);
188
+ };
189
+ const done = await run(made, "autopilot-full", { plan: planned.plan.of });
190
+ for (const node of done.nodes as Array<{ verified: boolean; landed: { outcome: string; missing: Array<{ name: string }> } }>) {
191
+ expect(node).toMatchObject({ verified: true, landed: { outcome: "refused" } });
192
+ expect(node.landed.missing.map((one) => one.name)).toEqual(["merge-result"]);
193
+ }
194
+ }, 240_000);
195
+
196
+ test("a head the forge reports red after it was verified green does not land", async () => {
197
+ const made = await promoted();
198
+ const planned = await run(made, "multi-phase-plan", { plan: "red-later", ask: false });
199
+ const stacked = await run(made, "autopilot-stack", { plan: planned.plan.of });
200
+ const change = `${made.fixture.repo.host}/${made.fixture.repo.path}`;
201
+ for (const node of planned.nodes as Array<{ id: string }>) {
202
+ await made.asOwner("evidence.attest", { subject: goSubject(planned.plan, node.id), claim: { kind: "verdict", name: "go", outcome: "pass", sha: goDigest(planned.plan, node.id, change) } });
203
+ }
204
+ const [bottom] = stacked.nodes as Array<{ node: string; pr: number; head: string; author: unknown }>;
205
+ if (bottom === undefined) throw new Error("nothing was stacked");
206
+ // The head's pipeline runs again, and fails: the green one attested when it was verified is not the latest.
207
+ made.gitlab.pipeline(made.project, { sha: bottom.head, ref: `refs/merge-requests/${String(bottom.pr)}/head`, status: "failed", source: "merge_request_event" });
208
+ const shipped = await run(made, "shipping", { plan: planned.plan.of, prs: [{ number: bottom.pr, nodes: [bottom.node], author: bottom.author }] });
209
+ expect(shipped.status).toBe("stopped");
210
+ expect(shipped.prs[0].missing.map((one: { name: string }) => one.name)).toEqual(["head-ci"]);
211
+ expect(made.project.mrs.get(bottom.pr)?.state).toBe("opened");
212
+ }, 240_000);
213
+
214
+ test("standalone shipping binds the author, MR and live target and refuses before merge", async () => {
215
+ const made = await pstackHost({ onlyBuiltins: ["multi-phase-plan", "autopilot-stack", "shipping"] });
216
+ hosts.push(made);
217
+ made.harnesses.answers = defaultAnswers(made);
218
+ await registeredAll(made.host, 3);
219
+ const planned = await plannedWithGo(made, "standalone");
220
+ const stacked = await run(made, "autopilot-stack", { plan: planned.plan.of });
221
+ const [bottom] = stacked.nodes as Array<{ node: string; pr: number; head: string; author: { kind: "session"; id: string; harness: string } }>;
222
+ if (!bottom) throw new Error("no PR built");
223
+ const repo = { host: made.fixture.repo.host, path: made.fixture.repo.path };
224
+ const key = { repo, number: bottom.pr, head: bottom.head };
225
+ const receipt = await made.host.call("pstack.pr.binding" as never, key as never) as { binding?: { author: unknown; run: string } };
226
+ expect(receipt.binding?.author).toEqual(bottom.author);
227
+ const rows = await recordsOf(made.host, "pstack.pr.bound");
228
+ expect(await made.host.call("pstack.pr.binding" as never, { ...key, before: rows[0]?.seq } as never)).toEqual({});
229
+ const bound = rows[0]!.data as { run: string; worktree: object };
230
+ await expect(made.host.call("pstack.pr.bind" as never, { ...key, author: bottom.author, worktree: bound.worktree } as never))
231
+ .rejects.toThrow("only a registered pstack authoring lane");
232
+
233
+ const ship = async (author?: typeof bottom.author) => {
234
+ const shipped = await run(made, "shipping", { plan: planned.plan.of, prs: [{ number: bottom.pr, nodes: [bottom.node], author }] });
235
+ expect(shipped.status).toBe("stopped");
236
+ return shipped.prs[0].missing.map((one: { name: string }) => one.name);
237
+ };
238
+ const subject = `${repo.host}/${repo.path}/pr/${bottom.pr}`;
239
+ for (const name of ["gates", "live"]) {
240
+ await made.attestAs(bottom.author.id, subject, { kind: "verdict", name, outcome: "pass", sha: bottom.head });
241
+ }
242
+ expect(await ship({ ...bottom.author, id: "another-session" })).toEqual(["author"]);
243
+ expect(await ship()).toEqual(["land"]);
244
+
245
+ const previous = made.project.branches.get("main")!;
246
+ made.project.branches.set("main", bottom.head);
247
+ expect(await ship()).toEqual(["merge-result"]);
248
+ made.project.branches.set("main", previous);
249
+ const own = made.project.pipelines.find(one => one.ref === `refs/merge-requests/${bottom.pr}/merge`)!;
250
+ own.status = "failed";
251
+ made.gitlab.mr(made.project, { iid: 987, source_branch: "other", sha: bottom.head });
252
+ made.gitlab.pipeline(made.project, { ref: "refs/merge-requests/987/merge", sha: own.sha, status: "success", source: "merge_request_event" });
253
+ expect(await ship()).toEqual(["merge-result"]);
254
+ const mr = made.project.mrs.get(bottom.pr)!;
255
+ mr.sha = previous;
256
+ expect(await ship()).toEqual(["author"]);
257
+ expect(made.gitlab.seen("PUT", /\/merge$/)).toHaveLength(0);
258
+ }, 150_000);
259
+
260
+ /** Both verification seats report the author's own evidence in this fixture. */
261
+ function attestAsAuthor(made: PstackHost): void {
262
+ for (const name of ["gates", "live"]) {
263
+ made.harnesses.answers[`*:verify-${name}`] = async call => {
264
+ const asked = claimAsked(call.prompt);
265
+ const author = [...made.harnesses.sessions.entries()].find(([, one]) => one.harness === "author" && one.cwd === call.cwd);
266
+ if (!author) throw new Error("no author for this checkout");
267
+ await made.attestAs(author[0].split(" ")[1]!, asked.subject, { kind: "verdict", name, outcome: "pass", sha: asked.sha });
268
+ return { outcome: "pass", evidence: "only the author's verdict" };
269
+ };
270
+ }
271
+ }
272
+
273
+ test("the author's own verdicts on a bound head cannot satisfy standalone shipping", async () => {
274
+ const made = await pstackHost({ onlyBuiltins: ["multi-phase-plan", "autopilot-stack", "shipping"] });
275
+ hosts.push(made);
276
+ made.harnesses.answers = defaultAnswers(made);
277
+ attestAsAuthor(made);
278
+ await registeredAll(made.host, 3);
279
+ const planned = await plannedWithGo(made, "self-verdict");
280
+ const stacked = await run(made, "autopilot-stack", { plan: planned.plan.of });
281
+ const [bottom] = stacked.nodes;
282
+ expect(bottom.verified).toBe(false);
283
+ const prs = [{ number: bottom.pr, nodes: [bottom.node] }];
284
+ const shipped = await run(made, "shipping", { plan: planned.plan.of, prs });
285
+ expect(shipped.prs[0].missing.map((one: { name: string }) => one.name)).toEqual(["gates", "live"]);
286
+ const forged = await run(made, "shipping", { plan: planned.plan.of, prs: [{ ...prs[0], author: { ...bottom.author, id: "another-session" } }] });
287
+ expect(forged.prs[0].missing.map((one: { name: string }) => one.name)).toEqual(["author"]);
288
+ expect(made.gitlab.seen("PUT", /\/merge$/)).toHaveLength(0);
289
+ }, 150_000);
290
+
291
+ test("a resumed registered lane binds the open PR and its next head under the stable run", async () => {
292
+ let interrupt = true;
293
+ const made = await pstackHost({
294
+ onlyBuiltins: ["multi-phase-plan", "autopilot-stack", "shipping"],
295
+ plugins: [plugin("interrupt-receipt", api => api.guard(pstackPrBind, () => interrupt ? deny("fixture interruption after PR opened") : undefined))],
296
+ });
297
+ hosts.push(made);
298
+ made.harnesses.answers = defaultAnswers(made);
299
+ attestAsAuthor(made);
300
+ await registeredAll(made.host, 3);
301
+ const planned = await plannedWithGo(made, "resume-receipt");
302
+ const flows = await builtins(made.host);
303
+ const args = { ...made.fixture, task: "Do it.", plan: planned.plan.of };
304
+ const started = await made.host.call("workflow.start" as never, { id: flows["autopilot-stack"]!.id, args, wait: true, timeoutMs: 8_000 } as never) as { run: string };
305
+ expect(made.project.mrs.size).toBe(1);
306
+ const opened = [...made.project.mrs.values()][0]!;
307
+ expect(await recordsOf(made.host, "pstack.pr.bound")).toHaveLength(0);
308
+ interrupt = false;
309
+ const from = `label:node-${planned.nodes[0]!.id}-pr-bind`;
310
+ await made.asOwner("workflow.resume", { run: started.run, from });
311
+ const result = await made.host.call("workflow.wait" as never, { run: started.run, timeoutMs: 8_000 } as never) as { outcome?: { status: string; result: { nodes: Array<{ node: string; pr: number; head: string; author: unknown }> } } };
312
+ expect(result.outcome?.status).toBe("done");
313
+ const nodes = result.outcome!.result.nodes;
314
+ expect(nodes.map(one => one.pr)).toEqual([opened.iid, opened.iid + 1]);
315
+ expect(nodes[1]!.head).not.toBe(opened.sha);
316
+ expect(made.gitlab.seen("POST", /\/merge_requests$/)).toHaveLength(2);
317
+ const { host, path } = made.fixture.repo;
318
+ for (const node of nodes) {
319
+ expect(await made.host.call("pstack.pr.binding" as never, { repo: { host, path }, number: node.pr, head: node.head } as never))
320
+ .toMatchObject({ binding: { run: started.run, author: node.author } });
321
+ }
322
+ const last = nodes[1]!;
323
+ const shipped = await run(made, "shipping", { plan: planned.plan.of, prs: [{ number: last.pr, nodes: [last.node] }] });
324
+ expect(shipped.prs[0].missing.map((one: { name: string }) => one.name)).toEqual(["gates", "live"]);
325
+
326
+ // The unarchived source has the same code, name and grants. Its inherited origin must not authorize it.
327
+ await made.asOwner("workflow.revise", { run: started.run, file: scriptOf("autopilot-stack"), from });
328
+ const revised = await made.host.call("workflow.wait" as never, { run: started.run, timeoutMs: 8_000 } as never) as { outcome?: { status: string }; reason?: string };
329
+ expect(revised).toMatchObject({ state: "paused", reason: `step ${from}: failed` });
330
+ const failures = await recordsOf(made.host, "niwa.step.outcome");
331
+ expect(failures.some(row => JSON.stringify(row.data).includes("only a registered pstack authoring lane can bind a pull request"))).toBe(true);
332
+ expect(await recordsOf(made.host, "pstack.pr.bound")).toHaveLength(2);
333
+ expect(made.gitlab.seen("POST", /\/merge_requests$/)).toHaveLength(2);
334
+ }, 60_000);
@@ -0,0 +1,64 @@
1
+ // Carrying a range of characters from an old text to a new one: what stayed where it was, what was touched, what is gone.
2
+
3
+ import { expect, test } from "bun:test";
4
+
5
+ import { carry, diffText } from "../src/mapping/diff.ts";
6
+
7
+ const OLD = "# Title\n\nFirst paragraph.\n\nSecond paragraph.\n\nThird paragraph.\n";
8
+
9
+ const at = (text: string, needle: string): [number, number] => {
10
+ const start = text.indexOf(needle);
11
+ if (start < 0) throw new Error(`${needle} not in text`);
12
+ return [start, start + needle.length];
13
+ };
14
+
15
+ test("equal texts carry every range to itself", () => {
16
+ const segments = diffText(OLD, OLD);
17
+ expect(carry(segments, at(OLD, "Second paragraph."))).toEqual({ status: "unchanged", range: at(OLD, "Second paragraph.") });
18
+ });
19
+
20
+ test("text added before a range shifts it and leaves it unchanged", () => {
21
+ const next = `Intro.\n\n${OLD}`;
22
+ expect(carry(diffText(OLD, next), at(OLD, "Second paragraph."))).toEqual({ status: "unchanged", range: at(next, "Second paragraph.") });
23
+ });
24
+
25
+ test("a line rewritten inside a range touches the range, and the new range is the rewritten block", () => {
26
+ const next = OLD.replace("Second paragraph.", "Second, rewritten paragraph.");
27
+ const moved = carry(diffText(OLD, next), at(OLD, "Second paragraph."));
28
+ expect(moved.status).toBe("touched");
29
+ if (moved.status === "gone") throw new Error("not gone");
30
+ expect(next.slice(...moved.range)).toContain("rewritten");
31
+ });
32
+
33
+ test("a change on one line leaves a range on another part of that line unchanged", () => {
34
+ const old = "alpha beta gamma\n";
35
+ const next = "alpha BETA gamma\n";
36
+ const diff = diffText(old, next);
37
+ expect(carry(diff, at(old, "alpha"))).toEqual({ status: "unchanged", range: [0, 5] });
38
+ expect(carry(diff, at(old, "gamma"))).toEqual({ status: "unchanged", range: at(next, "gamma") });
39
+ expect(carry(diff, at(old, "beta")).status).toBe("touched");
40
+ });
41
+
42
+ test("a range whose text was removed is gone, and one that lost only a part is touched", () => {
43
+ const next = OLD.replace("Second paragraph.\n\n", "");
44
+ const diff = diffText(OLD, next);
45
+ expect(carry(diff, at(OLD, "Second paragraph."))).toEqual({ status: "gone" });
46
+ const partial = carry(diff, [OLD.indexOf("First"), OLD.indexOf("Second") + 6]);
47
+ expect(partial.status).toBe("touched");
48
+ });
49
+
50
+ test("an insertion inside a range touches it", () => {
51
+ const next = OLD.replace("First paragraph.\n\n", "First paragraph.\n\nInserted.\n\n");
52
+ expect(carry(diffText(OLD, next), [OLD.indexOf("First"), OLD.indexOf("Third") + 5]).status).toBe("touched");
53
+ });
54
+
55
+ test("a text that became empty takes every range with it", () => {
56
+ expect(carry(diffText("abc\n", ""), [0, 3])).toEqual({ status: "gone" });
57
+ });
58
+
59
+ test("offsets count UTF-16 code units, as string indexes do", () => {
60
+ const old = "one\n\ntwo — dash\n\nthree\n";
61
+ const next = `zero\n\n${old}`;
62
+ const range = at(old, "three");
63
+ expect(carry(diffText(old, next), range)).toEqual({ status: "unchanged", range: at(next, "three") });
64
+ });
@@ -0,0 +1,110 @@
1
+ // What the mapping tests share: an upstream checkout and its snapshot, a repository of ours, and entries written
2
+ // against the commits they were made at.
3
+
4
+ import { mkdirSync, rmSync, writeFileSync } from "node:fs";
5
+ import { dirname, join } from "node:path";
6
+
7
+ import { tempDir } from "@niwa-labs/testing";
8
+
9
+ import { OursTexts, UpstreamTexts } from "../src/mapping/index.ts";
10
+ import type { Entry, Mapping, Span } from "../src/mapping/index.ts";
11
+ import { refreshUpstream } from "../src/upstream.ts";
12
+
13
+ const ENV = { GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_NOSYSTEM: "1", GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t.invalid", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t.invalid" };
14
+
15
+ export function git(dir: string, ...args: string[]): string {
16
+ const ran = Bun.spawnSync(["git", "-C", dir, ...args], { stdout: "pipe", stderr: "pipe", env: { ...process.env, ...ENV } });
17
+ if (ran.exitCode !== 0) throw new Error(`git ${args.join(" ")}: ${ran.stderr.toString()}`);
18
+ return ran.stdout.toString().trim();
19
+ }
20
+
21
+ /** Write files into a checkout and commit them: the new commit. A file whose text is null is removed. */
22
+ export function commitFiles(dir: string, files: Record<string, string | null>, message = "change"): string {
23
+ for (const [file, text] of Object.entries(files)) {
24
+ if (text === null) rmSync(join(dir, file), { force: true });
25
+ else {
26
+ mkdirSync(dirname(join(dir, file)), { recursive: true });
27
+ writeFileSync(join(dir, file), text);
28
+ }
29
+ }
30
+ git(dir, "add", "-A");
31
+ git(dir, "commit", "-q", "-m", message);
32
+ return git(dir, "rev-parse", "HEAD");
33
+ }
34
+
35
+ /** The first upstream files: an operator skill, the worker rules, a playbook. */
36
+ export const UPSTREAM_FILES: Record<string, string> = {
37
+ LICENSE: "MIT License\n",
38
+ "skills/poteto-mode/SKILL.md": "# Mode\n\nAlpha block.\n\nBeta block.\n",
39
+ "skills/poteto-mode/worker.md": "Work for the operator.\n",
40
+ "skills/poteto-mode/playbooks/bug-fix.md": "### Bug fix\n\nReproduce it.\n\nFix the cause.\n",
41
+ };
42
+
43
+ /** Our first files: some code and a text of our own. */
44
+ export const OURS_FILES: Record<string, string> = {
45
+ "src/brief.ts": "export const brief = 1;\n// the assembler\nexport const other = 2;\n",
46
+ "src/adapted.md": "Own words.\n",
47
+ };
48
+
49
+ /** The offsets of a needle in a text. */
50
+ export function at(text: string, needle: string): Span {
51
+ const start = text.indexOf(needle);
52
+ if (start < 0) throw new Error(`${JSON.stringify(needle)} is not in the text`);
53
+ return [start, start + needle.length];
54
+ }
55
+
56
+ /** An upstream checkout with its snapshot, and a repository of ours. */
57
+ export class World {
58
+ constructor(
59
+ readonly upstreamDir: string,
60
+ readonly snapshot: string,
61
+ readonly oursDir: string,
62
+ public upstreamCommit: string,
63
+ public oursCommit: string,
64
+ ) {}
65
+
66
+ static async make(): Promise<World> {
67
+ const upstreamDir = await tempDir("upstream");
68
+ git(upstreamDir, "init", "-q", "-b", "main");
69
+ const upstreamCommit = commitFiles(upstreamDir, UPSTREAM_FILES, "upstream");
70
+ const snapshot = join(await tempDir("snapshot"), "upstream");
71
+ refreshUpstream(upstreamDir, { upstream: snapshot });
72
+ const oursDir = await tempDir("ours");
73
+ git(oursDir, "init", "-q", "-b", "main");
74
+ const oursCommit = commitFiles(oursDir, OURS_FILES, "ours");
75
+ return new World(upstreamDir, snapshot, oursDir, upstreamCommit, oursCommit);
76
+ }
77
+
78
+ /** Change the upstream files, commit them, and take a new snapshot. */
79
+ evolveUpstream(files: Record<string, string | null>): string {
80
+ this.upstreamCommit = commitFiles(this.upstreamDir, files, "upstream change");
81
+ refreshUpstream(this.upstreamDir, { upstream: this.snapshot });
82
+ return this.upstreamCommit;
83
+ }
84
+
85
+ /** Change our files and commit them. */
86
+ evolveOurs(files: Record<string, string | null>): string {
87
+ return commitFiles(this.oursDir, files, "ours change");
88
+ }
89
+
90
+ upstream(checkout = true): UpstreamTexts {
91
+ return new UpstreamTexts(this.snapshot, checkout ? this.upstreamDir : undefined);
92
+ }
93
+
94
+ ours(head = "HEAD"): OursTexts {
95
+ return new OursTexts(this.oursDir, head);
96
+ }
97
+
98
+ /** An entry for a needle of an upstream file at a commit (this world's upstream commit by default). */
99
+ entry(id: string, kind: Entry["kind"], upstream: { file: string; text: string; needle: string; commit?: string }, ours: Array<{ file: string; text: string; needle: string; commit?: string }> = [], note?: string): Entry {
100
+ return {
101
+ id,
102
+ kind,
103
+ upstream: { commit: upstream.commit ?? this.upstreamCommit, file: upstream.file, range: at(upstream.text, upstream.needle) as [number, number] },
104
+ ours: ours.map((one) => ({ commit: one.commit ?? this.oursCommit, file: one.file, range: at(one.text, one.needle) as [number, number] })),
105
+ ...(note === undefined ? {} : { note }),
106
+ };
107
+ }
108
+ }
109
+
110
+ export const mapping = (...entries: Entry[]): Mapping => ({ entries });
@@ -0,0 +1,106 @@
1
+ // The texts the scripts import are held to the map: they equal upstream except exactly where an adapted or a dropped
2
+ // entry says so.
3
+
4
+ import { expect, test } from "bun:test";
5
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
6
+ import { join } from "node:path";
7
+
8
+ import { tempDir } from "@niwa-labs/testing";
9
+
10
+ import { analyze, assemble, jsonOf, parseMapping, verifyTextsIn, writeTexts } from "../src/mapping/index.ts";
11
+ import type { Entry } from "../src/mapping/index.ts";
12
+ import { OURS_FILES, UPSTREAM_FILES, World, mapping } from "./mapping-support.ts";
13
+
14
+ const BUG_FIX = "poteto-mode/playbooks/bug-fix.md";
15
+ const BUG_TEXT = UPSTREAM_FILES["skills/poteto-mode/playbooks/bug-fix.md"] as string;
16
+ const WORKER = "poteto-mode/worker.md";
17
+ const WORKER_TEXT = UPSTREAM_FILES["skills/poteto-mode/worker.md"] as string;
18
+ const SKILL = "poteto-mode/SKILL.md";
19
+ const SKILL_TEXT = UPSTREAM_FILES["skills/poteto-mode/SKILL.md"] as string;
20
+ const BRIEF = OURS_FILES["src/brief.ts"] as string;
21
+ const OWN = OURS_FILES["src/adapted.md"] as string;
22
+
23
+ /** The map of the playbook in two blocks and the worker rules in one, each as `kind` says. */
24
+ function mapOf(w: World, kinds: { head?: Entry["kind"]; fix?: Entry["kind"]; worker?: Entry["kind"] } = {}) {
25
+ const carried = [{ file: "src/brief.ts", text: BRIEF, needle: "// the assembler" }];
26
+ const own = [{ file: "src/adapted.md", text: OWN, needle: "Own words." }];
27
+ const make = (id: string, file: string, text: string, needle: string, kind: Entry["kind"]) => w.entry(id, kind, { file, text, needle }, kind === "dropped" ? [] : kind === "adapted" ? own : carried, kind === "dropped" ? "not taken" : undefined);
28
+ return mapping(
29
+ make("head", BUG_FIX, BUG_TEXT, "### Bug fix\n\nReproduce it.\n\n", kinds.head ?? "prompt"),
30
+ make("fix", BUG_FIX, BUG_TEXT, "Fix the cause.\n", kinds.fix ?? "prompt"),
31
+ make("worker", WORKER, WORKER_TEXT, "Work for the operator.\n", kinds.worker ?? "prompt"),
32
+ // The operator's skill goes into the worker text too: here none of it does.
33
+ make("skill", SKILL, SKILL_TEXT, SKILL_TEXT, "dropped"),
34
+ );
35
+ }
36
+
37
+ /** The texts folder the map assembles, written as the package writes it. */
38
+ async function written(w: World, map: ReturnType<typeof mapOf>): Promise<string> {
39
+ const dir = join(await tempDir("texts"), "texts");
40
+ writeTexts(assemble(map, w.upstream(false), w.ours()), dir);
41
+ return dir;
42
+ }
43
+
44
+ const problemsOf = (w: World, map: ReturnType<typeof mapOf>, dir: string) => verifyTextsIn(map, w.upstream(false), w.ours(), dir).map((one) => `${one.entry ?? "-"}: ${one.message}`);
45
+
46
+ test("texts that are what the map assembles have no problem, with a dropped block out and an adapted one in", async () => {
47
+ const w = await World.make();
48
+ const map = mapOf(w, { head: "adapted", fix: "dropped" });
49
+ const dir = await written(w, map);
50
+ expect(readFileSync(join(dir, "bug-fix.json"), "utf8")).toContain("Own words.");
51
+ expect(problemsOf(w, map, dir)).toEqual([]);
52
+ expect(analyze(map, w.upstream(false), w.ours()).problems).toEqual([]);
53
+ });
54
+
55
+ test("a text edited by hand is a problem that says where it parts from the map", async () => {
56
+ const w = await World.make();
57
+ const map = mapOf(w);
58
+ const dir = await written(w, map);
59
+ const file = join(dir, "bug-fix.json");
60
+ const text = JSON.parse(readFileSync(file, "utf8")) as { name: string; title: string; text: string };
61
+ writeFileSync(file, jsonOf({ ...text, text: text.text.replace("Reproduce it.", "Reproduce it twice.") }));
62
+ const found = problemsOf(w, map, dir);
63
+ expect(found).toHaveLength(1);
64
+ expect(found[0]).toContain("text bug-fix: it is not what the map says: they part at character");
65
+ expect(found[0]).toContain("Reproduce it twice.");
66
+ });
67
+
68
+ test("a block left out as code, in a file that goes into a text, is a problem", async () => {
69
+ const w = await World.make();
70
+ const map = mapOf(w, { fix: "code" });
71
+ const dir = await written(w, map);
72
+ expect(problemsOf(w, map, dir)).toEqual([expect.stringContaining("fix: text bug-fix: poteto-mode/playbooks/bug-fix.md goes into this text, and its block is left out as code")]);
73
+ });
74
+
75
+ test("upstream text that no entry accounts for may be left out unrecorded, and is a problem", async () => {
76
+ const w = await World.make();
77
+ const full = mapOf(w);
78
+ const map = mapping(...full.entries.filter((one) => one.id !== "fix"));
79
+ const dir = await written(w, map);
80
+ const found = problemsOf(w, map, dir);
81
+ expect(found).toEqual([expect.stringMatching(/is in no entry, so the text may leave it out unrecorded/)]);
82
+ });
83
+
84
+ test("a text with no file, a file of no text, and a wrong name or title are problems", async () => {
85
+ const w = await World.make();
86
+ const map = mapOf(w);
87
+ const dir = await written(w, map);
88
+ const file = join(dir, "bug-fix.json");
89
+ const text = JSON.parse(readFileSync(file, "utf8")) as { name: string; title: string; text: string };
90
+ writeFileSync(file, jsonOf({ ...text, title: "Something else" }));
91
+ writeFileSync(join(dir, "stray.json"), jsonOf({ name: "stray", title: "Stray", text: "x" }));
92
+ const found = problemsOf(w, map, dir);
93
+ expect(found).toEqual([expect.stringContaining("its title is \"Something else\""), expect.stringContaining("text stray: a text of no spec")]);
94
+ const empty = join(await tempDir("empty"), "texts");
95
+ mkdirSync(empty);
96
+ expect(problemsOf(w, map, empty)).toEqual([expect.stringContaining("text bug-fix: the map puts blocks into it, and it has no file"), expect.stringContaining("text worker: the map puts blocks into it, and it has no file")]);
97
+ });
98
+
99
+ test("an entry still at an older upstream commit is said, not compared", async () => {
100
+ const w = await World.make();
101
+ const map = mapOf(w);
102
+ const dir = await written(w, map);
103
+ w.evolveUpstream({ "skills/poteto-mode/worker.md": `${WORKER_TEXT}More.\n` });
104
+ const found = verifyTextsIn(parseMapping(JSON.stringify(map)), w.upstream(), w.ours(), dir).map((one) => one.message);
105
+ expect(found.some((one) => one.includes("is recorded at upstream commit"))).toBe(true);
106
+ });