@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
package/test/ports.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Fake providers of Benny's three ports, in memory: they offer each port the way an owner's plugin would, implement
|
|
2
|
+
// every action of its contract, and write down what they were asked, so the tests can say what Benny did.
|
|
3
|
+
|
|
4
|
+
import { action } from "@niwa-labs/core";
|
|
5
|
+
import type { ActionRef } from "@niwa-labs/core";
|
|
6
|
+
import { plugin } from "@niwa-labs/plugin";
|
|
7
|
+
import type { Plugin } from "@niwa-labs/plugin";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
BENNY_CHANNEL,
|
|
11
|
+
BENNY_CONTROL,
|
|
12
|
+
BENNY_TRACKER,
|
|
13
|
+
bennyChannelNotify,
|
|
14
|
+
bennyChannelReply,
|
|
15
|
+
bennyControlBringUp,
|
|
16
|
+
bennyControlCapabilities,
|
|
17
|
+
bennyControlCleanup,
|
|
18
|
+
bennyControlDrive,
|
|
19
|
+
bennyControlInspect,
|
|
20
|
+
bennyControlRecord,
|
|
21
|
+
bennyControlScreenshot,
|
|
22
|
+
bennyTrackerComment,
|
|
23
|
+
bennyTrackerCreate,
|
|
24
|
+
bennyTrackerFind,
|
|
25
|
+
bennyTrackerLinkPr,
|
|
26
|
+
} from "../src/ports.ts";
|
|
27
|
+
|
|
28
|
+
/** One call a provider answered. */
|
|
29
|
+
export interface PortCall {
|
|
30
|
+
action: string;
|
|
31
|
+
input: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The fake providers, and what they were asked. */
|
|
35
|
+
export interface FakePorts {
|
|
36
|
+
plugins: Plugin[];
|
|
37
|
+
calls: PortCall[];
|
|
38
|
+
/** The issues of the fake tracker, by id. */
|
|
39
|
+
issues: Map<string, { id: string; url: string; title: string; state: "open" | "closed"; sources: string[]; prs: string[]; notes: string[] }>;
|
|
40
|
+
/** The calls of an action, by its name. */
|
|
41
|
+
of(name: string): PortCall[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Providers that offer the three ports; `omit` leaves one out, as a host that lacks it would. */
|
|
45
|
+
export function fakePorts(omit: ReadonlyArray<"tracker" | "channel" | "control"> = []): FakePorts {
|
|
46
|
+
const calls: PortCall[] = [];
|
|
47
|
+
const issues: FakePorts["issues"] = new Map();
|
|
48
|
+
const record = <I>(name: string, input: I): I => {
|
|
49
|
+
calls.push({ action: name, input });
|
|
50
|
+
return input;
|
|
51
|
+
};
|
|
52
|
+
const made: Plugin[] = [];
|
|
53
|
+
if (!omit.includes("tracker")) {
|
|
54
|
+
made.push(
|
|
55
|
+
plugin("fake-tracker", (api) => {
|
|
56
|
+
api.offer(BENNY_TRACKER, { description: "an in-memory issue tracker" });
|
|
57
|
+
api.action(
|
|
58
|
+
action(bennyTrackerFind, {
|
|
59
|
+
recovery: "repeat",
|
|
60
|
+
effect: "read",
|
|
61
|
+
world: "niwa",
|
|
62
|
+
run: (input) => {
|
|
63
|
+
record("benny.tracker.find", input);
|
|
64
|
+
const found = [...issues.values()].filter((one) => (input.state === "any" || one.state === input.state) && (one.title.includes(input.text) || (input.source !== undefined && one.sources.includes(input.source))));
|
|
65
|
+
return { items: found.map(({ id, url, title, state, sources }) => ({ id, url, title, state, sources })) };
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
api.action(
|
|
70
|
+
action(bennyTrackerCreate, {
|
|
71
|
+
recovery: "do-not-repeat",
|
|
72
|
+
effect: "write",
|
|
73
|
+
world: "niwa",
|
|
74
|
+
run: (input) => {
|
|
75
|
+
record("benny.tracker.create", input);
|
|
76
|
+
const id = `ISSUE-${String(issues.size + 1)}`;
|
|
77
|
+
issues.set(id, { id, url: `https://tracker.example/issue/${id}`, title: input.title, state: "open", sources: [input.source], prs: [], notes: [] });
|
|
78
|
+
return { id, url: `https://tracker.example/issue/${id}` };
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
api.action(
|
|
83
|
+
action(bennyTrackerComment, {
|
|
84
|
+
recovery: "do-not-repeat",
|
|
85
|
+
effect: "write",
|
|
86
|
+
world: "niwa",
|
|
87
|
+
run: (input) => {
|
|
88
|
+
record("benny.tracker.comment", input);
|
|
89
|
+
const issue = issues.get(input.id);
|
|
90
|
+
if (issue === undefined) throw new Error(`no issue ${input.id}`);
|
|
91
|
+
issue.notes.push(input.note);
|
|
92
|
+
if (input.source !== undefined) issue.sources.push(input.source);
|
|
93
|
+
return { ok: true as const };
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
api.action(
|
|
98
|
+
action(bennyTrackerLinkPr, {
|
|
99
|
+
recovery: "do-not-repeat",
|
|
100
|
+
effect: "write",
|
|
101
|
+
world: "niwa",
|
|
102
|
+
run: (input) => {
|
|
103
|
+
record("benny.tracker.link-pr", input);
|
|
104
|
+
const issue = issues.get(input.id);
|
|
105
|
+
if (issue === undefined) throw new Error(`no issue ${input.id}`);
|
|
106
|
+
issue.prs.push(input.pr);
|
|
107
|
+
return { ok: true as const };
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
if (!omit.includes("channel")) {
|
|
115
|
+
made.push(
|
|
116
|
+
plugin("fake-channel", (api) => {
|
|
117
|
+
api.offer(BENNY_CHANNEL, { description: "an in-memory report channel" });
|
|
118
|
+
let posted = 0;
|
|
119
|
+
api.action(
|
|
120
|
+
action(bennyChannelReply, {
|
|
121
|
+
recovery: "do-not-repeat",
|
|
122
|
+
effect: "write",
|
|
123
|
+
world: "niwa",
|
|
124
|
+
run: (input) => {
|
|
125
|
+
record("benny.channel.reply", input);
|
|
126
|
+
posted += 1;
|
|
127
|
+
return { id: `msg-${String(posted)}` };
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
api.action(
|
|
132
|
+
action(bennyChannelNotify, {
|
|
133
|
+
recovery: "do-not-repeat",
|
|
134
|
+
effect: "write",
|
|
135
|
+
world: "niwa",
|
|
136
|
+
run: (input) => {
|
|
137
|
+
record("benny.channel.notify", input);
|
|
138
|
+
posted += 1;
|
|
139
|
+
return { id: `msg-${String(posted)}` };
|
|
140
|
+
},
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
if (!omit.includes("control")) {
|
|
147
|
+
made.push(
|
|
148
|
+
plugin("fake-control", (api) => {
|
|
149
|
+
api.offer(BENNY_CONTROL, { description: "an in-memory product control" });
|
|
150
|
+
const stage = <I, O, In>(ref: ActionRef<I, O, In>, effect: "read" | "write", run: (input: I) => O) =>
|
|
151
|
+
api.action(
|
|
152
|
+
action(ref, {
|
|
153
|
+
recovery: effect === "read" ? "repeat" : "do-not-repeat",
|
|
154
|
+
effect,
|
|
155
|
+
world: "local",
|
|
156
|
+
run: (input) => {
|
|
157
|
+
record(ref.name, input);
|
|
158
|
+
return run(input);
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
stage(bennyControlCapabilities, "read", () => ({ features: ["readme"], missing: [] }));
|
|
163
|
+
stage(bennyControlBringUp, "write", () => ({ session: "app-1", markers: ["app:fixture"], confirmed: "the window title names the fixture" }));
|
|
164
|
+
stage(bennyControlDrive, "write", () => ({ observed: "the page shows payroll" }));
|
|
165
|
+
stage(bennyControlInspect, "read", () => ({ state: "heading: payroll" }));
|
|
166
|
+
stage(bennyControlScreenshot, "write", (input) => ({ path: input.path, marker: "app:fixture" }));
|
|
167
|
+
stage(bennyControlRecord, "write", (input) => ({ path: input.path }));
|
|
168
|
+
stage(bennyControlCleanup, "write", () => ({ stopped: ["app-1"], retained: [] }));
|
|
169
|
+
}),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
return { plugins: made, calls, issues, of: (name) => calls.filter((one) => one.action === name) };
|
|
173
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The roles: the author writes only in a box, and a verdict counts only from a seat that did not write the code.
|
|
2
|
+
|
|
3
|
+
import { expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import { Roles } from "../src/roles.ts";
|
|
6
|
+
import { ROLES } from "./support.ts";
|
|
7
|
+
|
|
8
|
+
test("an author without a box is refused", () => {
|
|
9
|
+
const parsed = Roles.safeParse({ ...ROLES, author: { harness: "author" } });
|
|
10
|
+
expect(parsed.success).toBe(false);
|
|
11
|
+
expect(Roles.safeParse({ ...ROLES, author: { harness: "author", box: false } }).error?.issues[0]?.message).toContain("box: true");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("a verifier on the author's harness is refused", () => {
|
|
15
|
+
const parsed = Roles.safeParse({ ...ROLES, verifier: { harness: "author" } });
|
|
16
|
+
expect(parsed.error?.issues[0]?.message).toContain("did not write the code");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("the roles of the tests are a definition", () => {
|
|
20
|
+
expect(Roles.parse(ROLES).author.box).toBe(true);
|
|
21
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// pstack's entry and playbooks come in as candidates: shown, not installed, not run. The suite runs its scenarios
|
|
2
|
+
// on the set under trial, each built-in started by its version, and promotes the candidates in one action; a set
|
|
3
|
+
// whose scenario fails is not promoted.
|
|
4
|
+
|
|
5
|
+
import { afterEach, expect, test } from "bun:test";
|
|
6
|
+
|
|
7
|
+
import { AccessGranted, runIdOfPrincipal } from "@niwa-labs/core";
|
|
8
|
+
import { PrMerged } from "@niwa-labs/forge/records";
|
|
9
|
+
import { eventually } from "@niwa-labs/testing";
|
|
10
|
+
|
|
11
|
+
import { UNGATED, gatedOf } from "../src/catalog.ts";
|
|
12
|
+
import { builtins, defaultAnswers, pstackHost, recordsOf, registeredAll, syncErrors } from "./support.ts";
|
|
13
|
+
import type { Answers, PstackHost } from "./support.ts";
|
|
14
|
+
|
|
15
|
+
const hosts: PstackHost[] = [];
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
for (const one of hosts.splice(0)) await one.close();
|
|
18
|
+
}, 30_000);
|
|
19
|
+
|
|
20
|
+
async function served(change: (answers: Answers) => Answers = (answers) => answers): Promise<PstackHost> {
|
|
21
|
+
const made = await pstackHost();
|
|
22
|
+
made.harnesses.answers = change(defaultAnswers(made));
|
|
23
|
+
hosts.push(made);
|
|
24
|
+
await registeredAll(made.host, gatedOf(true).length + UNGATED.length);
|
|
25
|
+
return made;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A merge on the forge, as the forge module records one. */
|
|
29
|
+
const merge = (made: PstackHost, number: number, version: number) =>
|
|
30
|
+
made.host.emit(PrMerged, {
|
|
31
|
+
pr: { repo: { host: made.fixture.repo.host, path: made.fixture.repo.path, projectId: 42 }, number },
|
|
32
|
+
base: "main",
|
|
33
|
+
head: "a".repeat(40),
|
|
34
|
+
source: { kind: "observed", version },
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/** The runs of a built-in that were asked for. */
|
|
38
|
+
const runsOf = async (made: PstackHost, name: string) => {
|
|
39
|
+
const id = (await builtins(made.host))[name]?.id;
|
|
40
|
+
return (await recordsOf(made.host, "workflow.run.requested")).filter((one) => (one.data as { workflow?: string }).workflow === id);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const versionsOf = async (made: PstackHost, id: string) =>
|
|
44
|
+
((await made.host.call("workflow.get" as never, { id } as never)) as { versions: Array<{ version: string; candidate?: boolean }> }).versions;
|
|
45
|
+
|
|
46
|
+
const startSuite = async (made: PstackHost) => {
|
|
47
|
+
const suite = (await builtins(made.host))["suite"];
|
|
48
|
+
return (await made.host.call("workflow.start" as never, { id: suite?.id, args: made.fixture, wait: true, timeoutMs: 120_000 } as never)) as {
|
|
49
|
+
run: string;
|
|
50
|
+
outcome?: { status: string; result?: any };
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
test("a first install shows the entry and the playbooks as candidates and runs none of them", async () => {
|
|
55
|
+
const made = await served();
|
|
56
|
+
const all = await builtins(made.host);
|
|
57
|
+
for (const { name } of gatedOf(true)) {
|
|
58
|
+
expect((await versionsOf(made, all[name]?.id ?? "")).map((one) => one.candidate)).toEqual([true]);
|
|
59
|
+
await expect(made.host.call("workflow.start" as never, { id: all[name]?.id, args: {} } as never)).rejects.toThrow("candidate");
|
|
60
|
+
}
|
|
61
|
+
expect((await versionsOf(made, all["suite"]?.id ?? "")).map((one) => one.candidate)).toEqual([undefined]);
|
|
62
|
+
expect((await made.host.call("workflow.installation.list" as never, {} as never)) as { items: unknown[] }).toEqual({ items: [] });
|
|
63
|
+
|
|
64
|
+
// A merge on the forge starts no cleanup before a version of it was accepted.
|
|
65
|
+
await merge(made, 99, 1);
|
|
66
|
+
await Bun.sleep(1000);
|
|
67
|
+
expect(await runsOf(made, "worktree-cleanup")).toEqual([]);
|
|
68
|
+
}, 60_000);
|
|
69
|
+
|
|
70
|
+
test("the suite tries the set by its versions and promotes the candidates in one action", async () => {
|
|
71
|
+
const made = await served();
|
|
72
|
+
const all = await builtins(made.host);
|
|
73
|
+
const ran = await startSuite(made);
|
|
74
|
+
if (ran.outcome?.status !== "done") console.log(JSON.stringify(ran), (await syncErrors(made.host, "")).join("\n"));
|
|
75
|
+
expect(ran.outcome?.status).toBe("done");
|
|
76
|
+
const failed = (ran.outcome?.result.rows as Array<{ passed: boolean }>).filter((one) => !one.passed);
|
|
77
|
+
if (failed.length > 0) console.log((await syncErrors(made.host, "")).join("\n"));
|
|
78
|
+
expect(failed).toEqual([]);
|
|
79
|
+
expect(ran.outcome?.result.status).toBe("promoted");
|
|
80
|
+
// The sync is gated, so the suite tried it: it carried a reworded upstream across and assembled the texts.
|
|
81
|
+
expect((ran.outcome?.result.rows as Array<{ builtin: string; passed: boolean }>).filter((one) => one.builtin === "upstream-sync")).toEqual([expect.objectContaining({ passed: true })]);
|
|
82
|
+
|
|
83
|
+
const promoted = await recordsOf(made.host, "workflow.builtin.promoted");
|
|
84
|
+
expect(promoted).toHaveLength(1);
|
|
85
|
+
const data = promoted[0]?.data as { run: string; versions: Array<{ workflow: string; version: string }> };
|
|
86
|
+
expect(data.run).toBe(ran.run);
|
|
87
|
+
expect(data.versions.map((one) => one.workflow).sort()).toEqual(gatedOf(true).map(({ name }) => all[name]?.id ?? "").sort());
|
|
88
|
+
|
|
89
|
+
const trials = (await recordsOf(made.host, "workflow.builtin.trial")).map((row) => row.data as {
|
|
90
|
+
run: string;
|
|
91
|
+
entries: Array<{ workflow: string; version: string; candidate?: true }>;
|
|
92
|
+
});
|
|
93
|
+
const trial = trials.find((one) => one.run === ran.run);
|
|
94
|
+
expect(trial?.entries.filter((one) => one.candidate).map(({ workflow, version }) => ({ workflow, version }))).toEqual(data.versions);
|
|
95
|
+
|
|
96
|
+
const requested = (await recordsOf(made.host, "workflow.run.requested")).map((row) => row.data as {
|
|
97
|
+
run: string; workflow: string; version: string;
|
|
98
|
+
});
|
|
99
|
+
// workflow.start binds its child to the caller through the grant. RunRequested.parent is used by flow calls.
|
|
100
|
+
const parents = new Map<string, string>();
|
|
101
|
+
for (const row of await recordsOf(made.host, AccessGranted.name)) {
|
|
102
|
+
const { principal, parent } = AccessGranted.schema.parse(row.data);
|
|
103
|
+
if (principal.kind === "run" && parent?.principal.kind === "run") {
|
|
104
|
+
parents.set(runIdOfPrincipal(principal.id), runIdOfPrincipal(parent.principal.id));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const pinned = (name: string) => trial?.entries.find((one) => one.workflow === all[name]?.id);
|
|
108
|
+
const entryRuns = requested.filter((one) => parents.get(one.run) === ran.run && one.workflow === all["entry"]?.id);
|
|
109
|
+
expect(entryRuns).toEqual([expect.objectContaining({ version: pinned("entry")?.version })]);
|
|
110
|
+
const [entryRun] = entryRuns;
|
|
111
|
+
expect(requested.filter((one) => parents.get(one.run) === entryRun?.run)).toEqual([
|
|
112
|
+
expect.objectContaining({ workflow: all["investigation"]?.id, version: pinned("investigation")?.version }),
|
|
113
|
+
]);
|
|
114
|
+
|
|
115
|
+
// GitLab only conditions on the source SHA. All reviewed pairs stay open.
|
|
116
|
+
const merged = [...made.project.mrs.values()].filter((mr) => mr.state === "merged").map((mr) => mr.iid);
|
|
117
|
+
const open = [...made.project.mrs.values()].filter((mr) => mr.state === "opened").map((mr) => mr.iid);
|
|
118
|
+
expect(merged).toHaveLength(0);
|
|
119
|
+
expect(made.gitlab.seen("PUT", /\/merge$/)).toHaveLength(0);
|
|
120
|
+
expect(open).toHaveLength(11);
|
|
121
|
+
expect(made.project.mrs.get(4)?.description).toStartWith("## Why");
|
|
122
|
+
|
|
123
|
+
// Promoted: a merge on the forge starts the cleanup.
|
|
124
|
+
const previousCleanups = (await runsOf(made, "worktree-cleanup")).length;
|
|
125
|
+
await merge(made, 99, 1);
|
|
126
|
+
await eventually(async () => (await runsOf(made, "worktree-cleanup")).length === previousCleanups + 1, 20_000, "the cleanup did not start on the merge");
|
|
127
|
+
|
|
128
|
+
// Promoted: the entry starts by its id, and runs the accepted investigation.
|
|
129
|
+
const entry = (await made.host.call("workflow.start" as never, {
|
|
130
|
+
id: all["entry"]?.id,
|
|
131
|
+
args: { request: "Where is the description?", repo: made.fixture.repo, worktrees: made.fixture.worktrees },
|
|
132
|
+
wait: true,
|
|
133
|
+
timeoutMs: 60_000,
|
|
134
|
+
} as never)) as { outcome?: { status: string; result?: any } };
|
|
135
|
+
expect(entry.outcome).toMatchObject({ status: "done", result: { status: "ran", playbook: "investigation", result: { status: "answered" } } });
|
|
136
|
+
await expect(made.host.call("workflow.start" as never, {
|
|
137
|
+
id: all["entry"]?.id,
|
|
138
|
+
args: { request: "Where is the description?", repo: made.fixture.repo, worktrees: made.fixture.worktrees, pins: { investigation: data.versions.find((one) => one.workflow === all["investigation"]?.id)?.version } },
|
|
139
|
+
} as never)).rejects.toThrow("pins");
|
|
140
|
+
expect((await startSuite(made)).outcome).toMatchObject({ status: "done", result: { status: "nothing" } });
|
|
141
|
+
|
|
142
|
+
}, 240_000);
|
|
143
|
+
|
|
144
|
+
test("a set with a failing scenario is not promoted, and the candidates stay candidates", async () => {
|
|
145
|
+
const made = await served((answers) => ({ ...answers, "investigation:trace": () => ({ summary: "No idea.", sources: [] }) }));
|
|
146
|
+
const all = await builtins(made.host);
|
|
147
|
+
const ran = await startSuite(made);
|
|
148
|
+
expect(ran.outcome?.result.status).toBe("failed");
|
|
149
|
+
const failed = (ran.outcome?.result.rows as Array<{ builtin: string; passed: boolean; why?: string }>).filter((one) => !one.passed);
|
|
150
|
+
expect(failed.map((one) => one.builtin)).toEqual(["investigation"]);
|
|
151
|
+
expect(failed[0]?.why).toContain("no source");
|
|
152
|
+
expect(await recordsOf(made.host, "workflow.builtin.promoted")).toEqual([]);
|
|
153
|
+
expect((await versionsOf(made, all["entry"]?.id ?? "")).map((one) => one.candidate)).toEqual([true]);
|
|
154
|
+
}, 240_000);
|
|
155
|
+
|
|
156
|
+
test("the entry holds its rights over the repository as the four target templates", async () => {
|
|
157
|
+
const made = await served();
|
|
158
|
+
const all = await builtins(made.host);
|
|
159
|
+
const registered = (await recordsOf(made.host, "workflow.registered")).map((one) => one.data as { workflow: string; uses: string[] });
|
|
160
|
+
const uses = registered.find((one) => one.workflow === all["entry"]?.id)?.uses ?? [];
|
|
161
|
+
expect(uses.filter((one) => one.startsWith("forge.pr.merge") || one.startsWith("forge.pr.ensure") || one.startsWith("proc.run") || one.startsWith("git.*"))).toEqual([
|
|
162
|
+
"forge.pr.merge@{repo.host}/{repo.path}/pr/*",
|
|
163
|
+
"forge.pr.ensure@{repo.host}/{repo.path}/pr/*",
|
|
164
|
+
"proc.run@{worktrees}/*",
|
|
165
|
+
"git.*@{repo.local}",
|
|
166
|
+
]);
|
|
167
|
+
}, 60_000);
|