@juicesharp/rpiv-workflow 1.19.1 → 2.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/README.md +81 -8
- package/api.ts +18 -703
- package/audit-ctx.ts +103 -0
- package/audit-rows.ts +154 -0
- package/audit.ts +158 -190
- package/built-ins.ts +40 -45
- package/chain-state.ts +220 -0
- package/command-run.ts +64 -31
- package/command.ts +123 -21
- package/docs/workflow-authoring.md +356 -63
- package/{lifecycle.ts → events.ts} +161 -37
- package/execution-host.ts +75 -0
- package/host.ts +149 -64
- package/index.ts +25 -81
- package/internal-utils.ts +171 -71
- package/internal.ts +22 -1
- package/judge.ts +241 -0
- package/layers.ts +10 -15
- package/load/alias.ts +6 -12
- package/load/cache.ts +9 -6
- package/load/index.ts +27 -106
- package/load/issues.ts +31 -0
- package/load/legacy.ts +102 -0
- package/load/merge.ts +2 -2
- package/load/resolve-default.ts +3 -4
- package/load/shape-guards.ts +3 -6
- package/load/skill-contract-phase.ts +94 -0
- package/loop-constructors.ts +24 -0
- package/loop-def.ts +285 -0
- package/loop-kinds.ts +750 -0
- package/loop-parallel.ts +250 -0
- package/loop-waves.ts +99 -0
- package/loop.ts +330 -0
- package/loops/constructors.ts +334 -0
- package/loops/derivations.ts +65 -0
- package/loops/introspection.ts +184 -0
- package/loops/panel.ts +196 -0
- package/loops/verify.ts +99 -0
- package/messages.ts +249 -156
- package/outcomes/collectors/directory-path.ts +7 -3
- package/outcomes/collectors/index.ts +1 -0
- package/outcomes/collectors/require-opt.ts +11 -0
- package/outcomes/collectors/text-scan.ts +47 -0
- package/outcomes/collectors/tool-call.ts +8 -3
- package/outcomes/collectors/transcript-path.ts +4 -18
- package/outcomes/collectors/union.ts +30 -10
- package/outcomes/collectors/url.ts +9 -14
- package/outcomes/collectors/workspace-diff.ts +21 -14
- package/outcomes/exec.ts +17 -0
- package/outcomes/git-commit.ts +190 -100
- package/outcomes/index.ts +1 -0
- package/outcomes/parsers/json-body.ts +2 -2
- package/outcomes/side-effect.ts +3 -3
- package/output-spec.ts +36 -10
- package/output.ts +98 -20
- package/package.json +27 -11
- package/predicates.ts +11 -8
- package/preview.ts +81 -21
- package/registration.ts +117 -36
- package/routing-dsl.ts +322 -0
- package/routing.ts +48 -2
- package/runner/by-name.ts +2 -1
- package/runner/by-run-id.ts +2 -1
- package/runner/chain-advance.ts +84 -56
- package/runner/errors.ts +10 -0
- package/runner/failure.ts +163 -0
- package/runner/index.ts +7 -13
- package/runner/input-validation.ts +16 -23
- package/runner/preflight.ts +169 -0
- package/runner/resolve-stage.ts +68 -0
- package/runner/resume-entry.ts +121 -0
- package/runner/resume-loop.ts +131 -0
- package/runner/resume.ts +368 -262
- package/runner/run-context.ts +165 -0
- package/runner/run-stage.ts +490 -0
- package/runner/runner.ts +202 -449
- package/runner/script-stage.ts +104 -112
- package/schema-compat.ts +12 -1
- package/semaphore.ts +55 -0
- package/sessions/extraction.ts +146 -81
- package/sessions/halt-routing.ts +195 -0
- package/sessions/index.ts +3 -1
- package/sessions/locate.ts +141 -0
- package/sessions/reattach.ts +71 -0
- package/sessions/sessions.ts +114 -199
- package/sessions/spawn.ts +132 -119
- package/sessions/success-persist.ts +89 -0
- package/skill-contract.ts +22 -25
- package/skill-contracts/composition.ts +86 -37
- package/skill-contracts/{registries.ts → extension-points.ts} +45 -12
- package/skill-contracts/harvest.ts +4 -4
- package/skill-contracts/index.ts +15 -8
- package/skill-contracts/registry.ts +33 -50
- package/stage-def.ts +595 -0
- package/stage-errors.ts +84 -0
- package/stage-identity.ts +56 -0
- package/startup.ts +4 -1
- package/state/index.ts +8 -1
- package/state/names.ts +91 -65
- package/state/paths.ts +20 -0
- package/state/raw.ts +77 -0
- package/state/reads.ts +103 -85
- package/state/resolve.ts +73 -0
- package/state/state.ts +135 -15
- package/state/writes.ts +29 -12
- package/transcript.ts +24 -0
- package/triggers.ts +11 -3
- package/types.ts +290 -78
- package/validate/contract-compat.ts +198 -0
- package/validate/graph.ts +134 -0
- package/validate/issue.ts +328 -0
- package/validate/stage-rules.ts +499 -0
- package/validate-output.ts +82 -7
- package/validate-workflow.ts +57 -759
- package/validation-bounds.ts +35 -0
- package/control-flow.ts +0 -135
- package/fanout.ts +0 -102
- package/iterate.ts +0 -155
- package/load/cache.test.ts +0 -82
- package/load/shape-guards.test.ts +0 -74
- package/outcomes/collectors/directory-path.test.ts +0 -64
- package/outcomes/collectors/tool-call.test.ts +0 -110
- package/outcomes/collectors/transcript-path.test.ts +0 -70
- package/outcomes/collectors/union.test.ts +0 -59
- package/outcomes/collectors/url.test.ts +0 -67
- package/outcomes/collectors/workspace-diff.test.ts +0 -107
- package/outcomes/git-commit.test.ts +0 -194
- package/outcomes/parsers/json-body.test.ts +0 -80
- package/runner/by-name.test.ts +0 -95
- package/runner/by-run-id.test.ts +0 -115
- package/runner/resume-fanout.test.ts +0 -331
- package/runner/resume-fanout.ts +0 -136
- package/runner/resume-iterate.test.ts +0 -444
- package/runner/resume-iterate.ts +0 -111
- package/runner/resume.test.ts +0 -1130
- package/runner/stage-lifecycle.ts +0 -500
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { fs } from "../../handle.js";
|
|
3
|
-
import type { BranchEntry } from "../../transcript.js";
|
|
4
|
-
import { toolCallCollector } from "./tool-call.js";
|
|
5
|
-
|
|
6
|
-
const asstWithTools = (parts: Array<{ name: string; input: Record<string, unknown> }>): BranchEntry => ({
|
|
7
|
-
type: "message",
|
|
8
|
-
message: {
|
|
9
|
-
role: "assistant",
|
|
10
|
-
content: parts.map((p) => ({ type: "tool_use", name: p.name, input: p.input })),
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const ctxOf = (branch: BranchEntry[]) => ({
|
|
15
|
-
cwd: "/tmp",
|
|
16
|
-
runId: "test",
|
|
17
|
-
stageIndex: 0,
|
|
18
|
-
state: {} as never,
|
|
19
|
-
branch,
|
|
20
|
-
branchOffset: undefined,
|
|
21
|
-
snapshot: undefined,
|
|
22
|
-
skill: "test",
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe("toolCallCollector", () => {
|
|
26
|
-
it("throws when match or toArtifact are missing", () => {
|
|
27
|
-
// @ts-expect-error — intentional misuse
|
|
28
|
-
expect(() => toolCallCollector({})).toThrow(/required functions/);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("emits one artifact per matching tool call in branch order", async () => {
|
|
32
|
-
const collector = toolCallCollector({
|
|
33
|
-
match: (tc) => tc.name === "write_file",
|
|
34
|
-
toArtifact: (tc) => ({ handle: fs(String(tc.input.path)), role: "written" }),
|
|
35
|
-
});
|
|
36
|
-
const ctx = ctxOf([
|
|
37
|
-
asstWithTools([
|
|
38
|
-
{ name: "write_file", input: { path: "a.ts" } },
|
|
39
|
-
{ name: "read_file", input: { path: "ignored.ts" } },
|
|
40
|
-
{ name: "write_file", input: { path: "b.ts" } },
|
|
41
|
-
]),
|
|
42
|
-
]);
|
|
43
|
-
const result = await collector.collect(ctx);
|
|
44
|
-
expect(result.kind).toBe("ok");
|
|
45
|
-
if (result.kind !== "ok") return;
|
|
46
|
-
expect(result.artifacts).toEqual([
|
|
47
|
-
{ handle: { kind: "fs", path: "a.ts" }, role: "written" },
|
|
48
|
-
{ handle: { kind: "fs", path: "b.ts" }, role: "written" },
|
|
49
|
-
]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("returns ok+empty when nothing matches (runner decides whether to fatal)", async () => {
|
|
53
|
-
const collector = toolCallCollector({
|
|
54
|
-
match: (tc) => tc.name === "write_file",
|
|
55
|
-
toArtifact: (tc) => ({ handle: fs(String(tc.input.path)) }),
|
|
56
|
-
});
|
|
57
|
-
const ctx = ctxOf([asstWithTools([{ name: "read_file", input: { path: "x.ts" } }])]);
|
|
58
|
-
const result = await collector.collect(ctx);
|
|
59
|
-
expect(result.kind).toBe("ok");
|
|
60
|
-
if (result.kind !== "ok") return;
|
|
61
|
-
expect(result.artifacts).toEqual([]);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("toArtifact returning undefined skips the call", async () => {
|
|
65
|
-
const collector = toolCallCollector({
|
|
66
|
-
match: () => true,
|
|
67
|
-
toArtifact: (tc) => (tc.input.path ? { handle: fs(String(tc.input.path)) } : undefined),
|
|
68
|
-
});
|
|
69
|
-
const ctx = ctxOf([
|
|
70
|
-
asstWithTools([
|
|
71
|
-
{ name: "bash", input: { cmd: "ls" } }, // no path → skipped
|
|
72
|
-
{ name: "write_file", input: { path: "a.ts" } },
|
|
73
|
-
]),
|
|
74
|
-
]);
|
|
75
|
-
const result = await collector.collect(ctx);
|
|
76
|
-
expect(result.kind === "ok" && result.artifacts).toEqual([{ handle: { kind: "fs", path: "a.ts" } }]);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("respects branchOffset", async () => {
|
|
80
|
-
const collector = toolCallCollector({
|
|
81
|
-
match: (tc) => tc.name === "write_file",
|
|
82
|
-
toArtifact: (tc) => ({ handle: fs(String(tc.input.path)) }),
|
|
83
|
-
});
|
|
84
|
-
const branch = [
|
|
85
|
-
asstWithTools([{ name: "write_file", input: { path: "prior.ts" } }]),
|
|
86
|
-
asstWithTools([{ name: "write_file", input: { path: "current.ts" } }]),
|
|
87
|
-
];
|
|
88
|
-
const ctx = { ...ctxOf(branch), branchOffset: 1 };
|
|
89
|
-
const result = await collector.collect(ctx);
|
|
90
|
-
expect(result.kind === "ok" && result.artifacts).toEqual([{ handle: { kind: "fs", path: "current.ts" } }]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("multi-tool match — one collector covers write_file + edit", async () => {
|
|
94
|
-
const collector = toolCallCollector({
|
|
95
|
-
match: (tc) => tc.name === "write_file" || tc.name === "edit",
|
|
96
|
-
toArtifact: (tc) => ({ handle: fs(String(tc.input.path ?? tc.input.target_file)) }),
|
|
97
|
-
});
|
|
98
|
-
const ctx = ctxOf([
|
|
99
|
-
asstWithTools([
|
|
100
|
-
{ name: "write_file", input: { path: "new.ts" } },
|
|
101
|
-
{ name: "edit", input: { target_file: "old.ts" } },
|
|
102
|
-
]),
|
|
103
|
-
]);
|
|
104
|
-
const result = await collector.collect(ctx);
|
|
105
|
-
expect(result.kind === "ok" && result.artifacts.map((a) => a.handle)).toEqual([
|
|
106
|
-
{ kind: "fs", path: "new.ts" },
|
|
107
|
-
{ kind: "fs", path: "old.ts" },
|
|
108
|
-
]);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import type { BranchEntry } from "../../transcript.js";
|
|
3
|
-
import { transcriptPathCollector } from "./transcript-path.js";
|
|
4
|
-
|
|
5
|
-
const asst = (text: string): BranchEntry => ({
|
|
6
|
-
type: "message",
|
|
7
|
-
message: { role: "assistant", content: [{ type: "text", text }] },
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const ctxOf = (branch: BranchEntry[]) => ({
|
|
11
|
-
cwd: "/tmp",
|
|
12
|
-
runId: "test",
|
|
13
|
-
stageIndex: 0,
|
|
14
|
-
state: {} as never,
|
|
15
|
-
branch,
|
|
16
|
-
branchOffset: undefined,
|
|
17
|
-
snapshot: undefined,
|
|
18
|
-
skill: "test",
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("transcriptPathCollector", () => {
|
|
22
|
-
it("throws at construction when pattern is missing", () => {
|
|
23
|
-
// @ts-expect-error — intentional misuse
|
|
24
|
-
expect(() => transcriptPathCollector({})).toThrow(/pattern.*required/);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("emits one fs artifact for the last regex match in assistant text", async () => {
|
|
28
|
-
const collector = transcriptPathCollector({ pattern: /docs\/adr\/[\w-]+\.md/g });
|
|
29
|
-
const ctx = ctxOf([asst("Wrote docs/adr/0001-init.md, see docs/adr/0002-types.md")]);
|
|
30
|
-
const result = await collector.collect(ctx);
|
|
31
|
-
expect(result.kind).toBe("ok");
|
|
32
|
-
if (result.kind !== "ok") return;
|
|
33
|
-
expect(result.artifacts).toEqual([{ handle: { kind: "fs", path: "docs/adr/0002-types.md" }, role: "primary" }]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("fatals when no match is found (produces contract)", async () => {
|
|
37
|
-
const collector = transcriptPathCollector({ pattern: /docs\/adr\/[\w-]+\.md/g });
|
|
38
|
-
const ctx = ctxOf([asst("nothing here")]);
|
|
39
|
-
const result = await collector.collect(ctx);
|
|
40
|
-
expect(result.kind).toBe("fatal");
|
|
41
|
-
if (result.kind !== "fatal") return;
|
|
42
|
-
expect(result.message).toMatch(/finished without producing a path matching/);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("scans reverse — returns the match from the latest assistant message", async () => {
|
|
46
|
-
const collector = transcriptPathCollector({ pattern: /docs\/[\w-]+\.md/g });
|
|
47
|
-
const ctx = ctxOf([asst("first: docs/old.md"), asst("final: docs/new.md")]);
|
|
48
|
-
const result = await collector.collect(ctx);
|
|
49
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({ kind: "fs", path: "docs/new.md" });
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("respects branchOffset (continue-policy: skips prior-stage prefix)", async () => {
|
|
53
|
-
const collector = transcriptPathCollector({ pattern: /docs\/[\w-]+\.md/g });
|
|
54
|
-
const branch = [asst("prior: docs/old.md"), asst("current: docs/new.md")];
|
|
55
|
-
const ctx = { ...ctxOf(branch), branchOffset: 1 };
|
|
56
|
-
const result = await collector.collect(ctx);
|
|
57
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({ kind: "fs", path: "docs/new.md" });
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("ignores user messages and non-message entries", async () => {
|
|
61
|
-
const collector = transcriptPathCollector({ pattern: /docs\/[\w-]+\.md/g });
|
|
62
|
-
const ctx = ctxOf([
|
|
63
|
-
{ type: "message", message: { role: "user", content: [{ type: "text", text: "see docs/from-user.md" }] } },
|
|
64
|
-
{ type: "thinking_level_change" },
|
|
65
|
-
asst("agent: docs/from-agent.md"),
|
|
66
|
-
]);
|
|
67
|
-
const result = await collector.collect(ctx);
|
|
68
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({ kind: "fs", path: "docs/from-agent.md" });
|
|
69
|
-
});
|
|
70
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { fs } from "../../handle.js";
|
|
3
|
-
import type { ArtifactCollector } from "../../output-spec.js";
|
|
4
|
-
import { unionCollectors } from "./union.js";
|
|
5
|
-
|
|
6
|
-
const ctxOf = () => ({
|
|
7
|
-
cwd: "/tmp",
|
|
8
|
-
runId: "test",
|
|
9
|
-
stageIndex: 0,
|
|
10
|
-
state: {} as never,
|
|
11
|
-
branch: [],
|
|
12
|
-
branchOffset: undefined,
|
|
13
|
-
snapshot: undefined,
|
|
14
|
-
skill: "test",
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const okCollector = (paths: string[]): ArtifactCollector => ({
|
|
18
|
-
collect: () => ({ kind: "ok", artifacts: paths.map((p) => ({ handle: fs(p) })) }),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const fatalCollector = (msg: string): ArtifactCollector => ({
|
|
22
|
-
collect: () => ({ kind: "fatal", message: msg }),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe("unionCollectors", () => {
|
|
26
|
-
it("throws when constructed with zero collectors", () => {
|
|
27
|
-
expect(() => unionCollectors()).toThrow(/at least one collector/);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("concatenates artifacts in collector order", async () => {
|
|
31
|
-
const union = unionCollectors(okCollector(["a.ts", "b.ts"]), okCollector(["c.ts"]));
|
|
32
|
-
const result = await union.collect(ctxOf());
|
|
33
|
-
expect(
|
|
34
|
-
result.kind === "ok" && result.artifacts.map((a) => (a.handle.kind === "fs" ? a.handle.path : "")),
|
|
35
|
-
).toEqual(["a.ts", "b.ts", "c.ts"]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("returns ok+empty when every sub-collector yielded ok+empty", async () => {
|
|
39
|
-
const union = unionCollectors(okCollector([]), okCollector([]));
|
|
40
|
-
const result = await union.collect(ctxOf());
|
|
41
|
-
expect(result.kind === "ok" && result.artifacts).toEqual([]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("returns ok when at least one sub-collector succeeds (even if others fatal)", async () => {
|
|
45
|
-
const union = unionCollectors(fatalCollector("transcript: no match"), okCollector(["b.ts"]));
|
|
46
|
-
const result = await union.collect(ctxOf());
|
|
47
|
-
expect(
|
|
48
|
-
result.kind === "ok" && result.artifacts.map((a) => (a.handle.kind === "fs" ? a.handle.path : "")),
|
|
49
|
-
).toEqual(["b.ts"]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("returns fatal carrying the LAST fatal message when every sub-collector fataled", async () => {
|
|
53
|
-
const union = unionCollectors(fatalCollector("first failure"), fatalCollector("second failure"));
|
|
54
|
-
const result = await union.collect(ctxOf());
|
|
55
|
-
expect(result.kind).toBe("fatal");
|
|
56
|
-
if (result.kind !== "fatal") return;
|
|
57
|
-
expect(result.message).toBe("second failure");
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import type { BranchEntry } from "../../transcript.js";
|
|
3
|
-
import { urlCollector } from "./url.js";
|
|
4
|
-
|
|
5
|
-
const asst = (text: string): BranchEntry => ({
|
|
6
|
-
type: "message",
|
|
7
|
-
message: { role: "assistant", content: [{ type: "text", text }] },
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const ctxOf = (branch: BranchEntry[]) => ({
|
|
11
|
-
cwd: "/tmp",
|
|
12
|
-
runId: "test",
|
|
13
|
-
stageIndex: 0,
|
|
14
|
-
state: {} as never,
|
|
15
|
-
branch,
|
|
16
|
-
branchOffset: undefined,
|
|
17
|
-
snapshot: undefined,
|
|
18
|
-
skill: "test",
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("urlCollector", () => {
|
|
22
|
-
it("emits a url() handle for an https URL in assistant text", async () => {
|
|
23
|
-
const collector = urlCollector();
|
|
24
|
-
const ctx = ctxOf([asst("Opened https://github.com/owner/repo/pull/42 for review.")]);
|
|
25
|
-
const result = await collector.collect(ctx);
|
|
26
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({
|
|
27
|
-
kind: "url",
|
|
28
|
-
href: "https://github.com/owner/repo/pull/42",
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("trims trailing prose punctuation (.,;:!?))", async () => {
|
|
33
|
-
const collector = urlCollector();
|
|
34
|
-
const ctx = ctxOf([asst("See https://example.com/page.")]);
|
|
35
|
-
const result = await collector.collect(ctx);
|
|
36
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({
|
|
37
|
-
kind: "url",
|
|
38
|
-
href: "https://example.com/page",
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("returns the last URL when multiple appear", async () => {
|
|
43
|
-
const collector = urlCollector();
|
|
44
|
-
const ctx = ctxOf([asst("first: https://a.com second: https://b.com")]);
|
|
45
|
-
const result = await collector.collect(ctx);
|
|
46
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({ kind: "url", href: "https://b.com" });
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("fatals when no URL is found", async () => {
|
|
50
|
-
const collector = urlCollector();
|
|
51
|
-
const ctx = ctxOf([asst("no link here")]);
|
|
52
|
-
const result = await collector.collect(ctx);
|
|
53
|
-
expect(result.kind).toBe("fatal");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("accepts a narrower pattern (e.g. only linear.app URLs)", async () => {
|
|
57
|
-
const collector = urlCollector({ pattern: /https:\/\/linear\.app\/[^\s)]+/g });
|
|
58
|
-
const ctx = ctxOf([
|
|
59
|
-
asst("Filed https://github.com/owner/r/issues/1 and https://linear.app/team/issue/ENG-42 — see linear."),
|
|
60
|
-
]);
|
|
61
|
-
const result = await collector.collect(ctx);
|
|
62
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({
|
|
63
|
-
kind: "url",
|
|
64
|
-
href: "https://linear.app/team/issue/ENG-42",
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { execSync } from "node:child_process";
|
|
2
|
-
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
6
|
-
import type { CollectCtx, SnapshotCtx } from "../../output-spec.js";
|
|
7
|
-
import { type WorkspaceDiffSnapshot, workspaceDiffCollector } from "./workspace-diff.js";
|
|
8
|
-
|
|
9
|
-
const hasGit = (() => {
|
|
10
|
-
try {
|
|
11
|
-
execSync("git --version", { stdio: "ignore" });
|
|
12
|
-
return true;
|
|
13
|
-
} catch {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
})();
|
|
17
|
-
|
|
18
|
-
const initRepo = (cwd: string): void => {
|
|
19
|
-
execSync("git init -q", { cwd });
|
|
20
|
-
execSync("git config user.email test@example.com", { cwd });
|
|
21
|
-
execSync("git config user.name Test", { cwd });
|
|
22
|
-
execSync("git commit --allow-empty -q -m initial", { cwd });
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const snapshotCtxOf = (cwd: string): SnapshotCtx => ({
|
|
26
|
-
cwd,
|
|
27
|
-
runId: "test",
|
|
28
|
-
stageIndex: 0,
|
|
29
|
-
state: {} as never,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const collectCtxOf = (
|
|
33
|
-
cwd: string,
|
|
34
|
-
snapshot: WorkspaceDiffSnapshot | undefined,
|
|
35
|
-
): CollectCtx<WorkspaceDiffSnapshot | undefined> => ({
|
|
36
|
-
...snapshotCtxOf(cwd),
|
|
37
|
-
branch: [],
|
|
38
|
-
branchOffset: undefined,
|
|
39
|
-
snapshot,
|
|
40
|
-
skill: "test",
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe.runIf(hasGit)("workspaceDiffCollector", () => {
|
|
44
|
-
let tmpDir: string;
|
|
45
|
-
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
tmpDir = mkdtempSync(join(tmpdir(), "rpiv-wd-"));
|
|
48
|
-
});
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("emits one fs artifact per file written during the stage", async () => {
|
|
54
|
-
initRepo(tmpDir);
|
|
55
|
-
const collector = workspaceDiffCollector();
|
|
56
|
-
const snapshot = await collector.snapshot?.(snapshotCtxOf(tmpDir));
|
|
57
|
-
// Write two files post-snapshot.
|
|
58
|
-
writeFileSync(join(tmpDir, "a.txt"), "hello");
|
|
59
|
-
writeFileSync(join(tmpDir, "b.txt"), "world");
|
|
60
|
-
|
|
61
|
-
const result = await collector.collect(collectCtxOf(tmpDir, snapshot));
|
|
62
|
-
expect(result.kind).toBe("ok");
|
|
63
|
-
if (result.kind !== "ok") return;
|
|
64
|
-
const paths = result.artifacts.map((a) => (a.handle.kind === "fs" ? a.handle.path : "")).sort();
|
|
65
|
-
expect(paths).toEqual(["a.txt", "b.txt"]);
|
|
66
|
-
// Every artifact's role and meta hint come from the collector, not the user.
|
|
67
|
-
expect(result.artifacts[0]?.role).toBe("changed");
|
|
68
|
-
expect(result.artifacts[0]?.meta?.gitStatus).toBe("??");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("skips files whose status was unchanged from snapshot (untouched files don't count)", async () => {
|
|
72
|
-
initRepo(tmpDir);
|
|
73
|
-
// Pre-snapshot file — already untracked.
|
|
74
|
-
writeFileSync(join(tmpDir, "preexisting.txt"), "x");
|
|
75
|
-
const collector = workspaceDiffCollector();
|
|
76
|
-
const snapshot = await collector.snapshot?.(snapshotCtxOf(tmpDir));
|
|
77
|
-
|
|
78
|
-
// Write a NEW file during the "stage."
|
|
79
|
-
writeFileSync(join(tmpDir, "new.txt"), "y");
|
|
80
|
-
|
|
81
|
-
const result = await collector.collect(collectCtxOf(tmpDir, snapshot));
|
|
82
|
-
expect(
|
|
83
|
-
result.kind === "ok" && result.artifacts.map((a) => (a.handle.kind === "fs" ? a.handle.path : "")),
|
|
84
|
-
).toEqual(["new.txt"]);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("applies the optional filter", async () => {
|
|
88
|
-
initRepo(tmpDir);
|
|
89
|
-
const collector = workspaceDiffCollector({ filter: (p) => p.endsWith(".md") });
|
|
90
|
-
const snapshot = await collector.snapshot?.(snapshotCtxOf(tmpDir));
|
|
91
|
-
writeFileSync(join(tmpDir, "a.txt"), "x");
|
|
92
|
-
writeFileSync(join(tmpDir, "b.md"), "y");
|
|
93
|
-
|
|
94
|
-
const result = await collector.collect(collectCtxOf(tmpDir, snapshot));
|
|
95
|
-
expect(
|
|
96
|
-
result.kind === "ok" && result.artifacts.map((a) => (a.handle.kind === "fs" ? a.handle.path : "")),
|
|
97
|
-
).toEqual(["b.md"]);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("fail-soft: cwd is not a git repo → snapshot undefined → collect returns empty", async () => {
|
|
101
|
-
const collector = workspaceDiffCollector();
|
|
102
|
-
const snapshot = await collector.snapshot?.(snapshotCtxOf(tmpDir));
|
|
103
|
-
expect(snapshot).toBeUndefined();
|
|
104
|
-
const result = await collector.collect(collectCtxOf(tmpDir, snapshot));
|
|
105
|
-
expect(result.kind === "ok" && result.artifacts).toEqual([]);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the git-commit outcome — covers the collector + parser pair
|
|
3
|
-
* on the success path, when git isn't on PATH, and when the working
|
|
4
|
-
* tree isn't a git repo.
|
|
5
|
-
*
|
|
6
|
-
* The outcome is fail-soft by contract: every git error path collapses
|
|
7
|
-
* to a `noOp: true` payload so the workflow keeps moving. These tests
|
|
8
|
-
* pin that contract — a regression that converts a failure into a throw
|
|
9
|
-
* would surface here as an unhandled rejection.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { execSync } from "node:child_process";
|
|
13
|
-
import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
14
|
-
import { tmpdir } from "node:os";
|
|
15
|
-
import { join } from "node:path";
|
|
16
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
17
|
-
import type { CollectCtx, ParseCtx, SnapshotCtx } from "../output.js";
|
|
18
|
-
import {
|
|
19
|
-
type GitHeadSnapshot,
|
|
20
|
-
gitCommitCollector,
|
|
21
|
-
gitCommitOutcome,
|
|
22
|
-
gitCommitParser,
|
|
23
|
-
gitHeadSnapshot,
|
|
24
|
-
} from "./git-commit.js";
|
|
25
|
-
|
|
26
|
-
const hasGit = (() => {
|
|
27
|
-
try {
|
|
28
|
-
execSync("git --version", { stdio: "ignore" });
|
|
29
|
-
return true;
|
|
30
|
-
} catch {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
})();
|
|
34
|
-
|
|
35
|
-
const initRepo = (cwd: string): void => {
|
|
36
|
-
execSync("git init -q", { cwd });
|
|
37
|
-
execSync("git config user.email test@example.com", { cwd });
|
|
38
|
-
execSync("git config user.name Test", { cwd });
|
|
39
|
-
execSync("git commit --allow-empty -q -m initial", { cwd });
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const snapshotCtx = (cwd: string): SnapshotCtx => ({
|
|
43
|
-
cwd,
|
|
44
|
-
runId: "test-run",
|
|
45
|
-
stageIndex: 0,
|
|
46
|
-
state: {
|
|
47
|
-
originalInput: "",
|
|
48
|
-
primaryArtifact: undefined,
|
|
49
|
-
output: undefined,
|
|
50
|
-
named: {},
|
|
51
|
-
stagesCompleted: 0,
|
|
52
|
-
lastAllocatedStageNumber: 0,
|
|
53
|
-
telemetry: {
|
|
54
|
-
backwardJumps: 0,
|
|
55
|
-
droppedRoutingRows: [],
|
|
56
|
-
},
|
|
57
|
-
termination: {
|
|
58
|
-
success: false,
|
|
59
|
-
error: undefined,
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const collectCtx = (cwd: string, snapshot: GitHeadSnapshot | undefined): CollectCtx<GitHeadSnapshot | undefined> => ({
|
|
65
|
-
...snapshotCtx(cwd),
|
|
66
|
-
branch: [],
|
|
67
|
-
branchOffset: undefined,
|
|
68
|
-
snapshot,
|
|
69
|
-
skill: "commit",
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Run the full outcome (collector → parser) end-to-end, returning the
|
|
74
|
-
* commit data the parser produced. Mirrors what `produceAndValidateOutput`
|
|
75
|
-
* does in the runner.
|
|
76
|
-
*/
|
|
77
|
-
const runOutcome = async (cwd: string, snapshot: GitHeadSnapshot | undefined) => {
|
|
78
|
-
const ctx = collectCtx(cwd, snapshot);
|
|
79
|
-
const collected = await gitCommitOutcome.collector.collect(ctx);
|
|
80
|
-
if (collected.kind === "fatal") return collected;
|
|
81
|
-
const parseCtx: ParseCtx<GitHeadSnapshot | undefined> = { ...ctx, artifacts: collected.artifacts };
|
|
82
|
-
return gitCommitOutcome.parser!.parse(parseCtx);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
describe.runIf(hasGit)("gitHeadSnapshot", () => {
|
|
86
|
-
let tmpDir: string;
|
|
87
|
-
|
|
88
|
-
beforeEach(() => {
|
|
89
|
-
tmpDir = mkdtempSync(join(tmpdir(), "rpiv-git-snap-"));
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
afterEach(() => {
|
|
93
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("returns the current HEAD SHA in a real repo", async () => {
|
|
97
|
-
initRepo(tmpDir);
|
|
98
|
-
const snap = await gitHeadSnapshot(snapshotCtx(tmpDir));
|
|
99
|
-
expect(snap?.baselineSha).toMatch(/^[0-9a-f]{40}$/);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("returns undefined when cwd is not a git repo (no throw)", async () => {
|
|
103
|
-
const snap = await gitHeadSnapshot(snapshotCtx(tmpDir));
|
|
104
|
-
expect(snap).toBeUndefined();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("returns undefined when cwd does not exist (no throw)", async () => {
|
|
108
|
-
const snap = await gitHeadSnapshot(snapshotCtx(join(tmpDir, "does-not-exist")));
|
|
109
|
-
expect(snap).toBeUndefined();
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe.runIf(hasGit)("gitCommitOutcome end-to-end", () => {
|
|
114
|
-
let tmpDir: string;
|
|
115
|
-
|
|
116
|
-
beforeEach(() => {
|
|
117
|
-
tmpDir = mkdtempSync(join(tmpdir(), "rpiv-git-ext-"));
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
afterEach(() => {
|
|
121
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("emits a real commit payload when HEAD moved between snapshot and collect", async () => {
|
|
125
|
-
initRepo(tmpDir);
|
|
126
|
-
const snap = await gitHeadSnapshot(snapshotCtx(tmpDir));
|
|
127
|
-
expect(snap?.baselineSha).toMatch(/^[0-9a-f]{40}$/);
|
|
128
|
-
|
|
129
|
-
writeFileSync(join(tmpDir, "a.txt"), "hello\n");
|
|
130
|
-
execSync("git add a.txt", { cwd: tmpDir });
|
|
131
|
-
execSync('git commit -q -m "add a"', { cwd: tmpDir });
|
|
132
|
-
|
|
133
|
-
const result = await runOutcome(tmpDir, snap);
|
|
134
|
-
expect(result.kind).toBe("ok");
|
|
135
|
-
if (result.kind !== "ok") return;
|
|
136
|
-
expect(result.payload.kind).toBe("git-commit");
|
|
137
|
-
const data = result.payload.data;
|
|
138
|
-
expect(data.sha).toMatch(/^[0-9a-f]{40}$/);
|
|
139
|
-
expect(data.prevSha).toBe(snap?.baselineSha);
|
|
140
|
-
expect(data.subject).toBe("add a");
|
|
141
|
-
expect(data.filesChanged).toBe(1);
|
|
142
|
-
expect(data.noOp).toBeUndefined();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("emits noOp payload when HEAD did not move", async () => {
|
|
146
|
-
initRepo(tmpDir);
|
|
147
|
-
const snap = await gitHeadSnapshot(snapshotCtx(tmpDir));
|
|
148
|
-
const result = await runOutcome(tmpDir, snap);
|
|
149
|
-
expect(result.kind).toBe("ok");
|
|
150
|
-
if (result.kind !== "ok") return;
|
|
151
|
-
expect(result.payload.data.noOp).toBe(true);
|
|
152
|
-
expect(result.payload.data.prevSha).toBe(snap?.baselineSha);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("emits noOp payload when snapshot is undefined (snapshot failure upstream)", async () => {
|
|
156
|
-
const result = await runOutcome(tmpDir, undefined);
|
|
157
|
-
expect(result.kind).toBe("ok");
|
|
158
|
-
if (result.kind !== "ok") return;
|
|
159
|
-
expect(result.payload.data.noOp).toBe(true);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("emits noOp payload when cwd is not a git repo (collectCommitData returns null)", async () => {
|
|
163
|
-
// Synthesize a snapshot with a fake baseline; collect runs in a non-repo cwd.
|
|
164
|
-
const result = await runOutcome(tmpDir, { baselineSha: "deadbeef" });
|
|
165
|
-
expect(result.kind).toBe("ok");
|
|
166
|
-
if (result.kind !== "ok") return;
|
|
167
|
-
expect(result.payload.data.noOp).toBe(true);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
describe("gitCommitCollector always emits one artifact (the commit handle)", () => {
|
|
172
|
-
let tmpDir: string;
|
|
173
|
-
|
|
174
|
-
beforeEach(() => {
|
|
175
|
-
tmpDir = mkdtempSync(join(tmpdir(), "rpiv-git-res-"));
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
afterEach(() => {
|
|
179
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("emits role:'commit' opaque handle with the post-stage SHA (or empty when unavailable)", async () => {
|
|
183
|
-
const collected = await gitCommitCollector.collect(collectCtx(tmpDir, { baselineSha: "abc" }));
|
|
184
|
-
expect(collected.kind).toBe("ok");
|
|
185
|
-
if (collected.kind !== "ok") return;
|
|
186
|
-
expect(collected.artifacts).toHaveLength(1);
|
|
187
|
-
expect(collected.artifacts[0]?.role).toBe("commit");
|
|
188
|
-
expect(collected.artifacts[0]?.handle.kind).toBe("opaque");
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// Suppress unused-import lint when this file runs without git on PATH.
|
|
193
|
-
void existsSync;
|
|
194
|
-
void gitCommitParser;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { fs as fsHandle, opaque } from "../../handle.js";
|
|
6
|
-
import type { ParseCtx } from "../../output-spec.js";
|
|
7
|
-
import { jsonBodyParser } from "./json-body.js";
|
|
8
|
-
|
|
9
|
-
const ctxOf = (cwd: string, artifacts: ParseCtx["artifacts"]): ParseCtx => ({
|
|
10
|
-
cwd,
|
|
11
|
-
runId: "test",
|
|
12
|
-
stageIndex: 0,
|
|
13
|
-
state: {} as never,
|
|
14
|
-
branch: [],
|
|
15
|
-
branchOffset: undefined,
|
|
16
|
-
snapshot: undefined,
|
|
17
|
-
skill: "test",
|
|
18
|
-
artifacts,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("jsonBodyParser", () => {
|
|
22
|
-
let tmpDir: string;
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
tmpDir = mkdtempSync(join(tmpdir(), "rpiv-jsonbody-"));
|
|
26
|
-
});
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("parses the primary fs artifact's body and emits kind:'json'", async () => {
|
|
32
|
-
writeFileSync(join(tmpDir, "out.json"), JSON.stringify({ ok: true, count: 3 }));
|
|
33
|
-
const ctx = ctxOf(tmpDir, [{ handle: fsHandle("out.json") }]);
|
|
34
|
-
const result = await jsonBodyParser.parse(ctx);
|
|
35
|
-
expect(result.kind).toBe("ok");
|
|
36
|
-
if (result.kind !== "ok") return;
|
|
37
|
-
expect(result.payload.kind).toBe("json");
|
|
38
|
-
expect(result.payload.data).toEqual({ ok: true, count: 3 });
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("accepts absolute paths unchanged", async () => {
|
|
42
|
-
writeFileSync(join(tmpDir, "abs.json"), JSON.stringify({ x: 1 }));
|
|
43
|
-
const ctx = ctxOf(tmpDir, [{ handle: fsHandle(join(tmpDir, "abs.json")) }]);
|
|
44
|
-
const result = await jsonBodyParser.parse(ctx);
|
|
45
|
-
expect(result.kind === "ok" && result.payload.data).toEqual({ x: 1 });
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("fatals when the primary artifact isn't an fs handle", async () => {
|
|
49
|
-
const ctx = ctxOf(tmpDir, [{ handle: opaque("not-fs") }]);
|
|
50
|
-
const result = await jsonBodyParser.parse(ctx);
|
|
51
|
-
expect(result.kind).toBe("fatal");
|
|
52
|
-
if (result.kind !== "fatal") return;
|
|
53
|
-
expect(result.message).toMatch(/requires an fs artifact/);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("fatals when no artifacts are present", async () => {
|
|
57
|
-
const ctx = ctxOf(tmpDir, []);
|
|
58
|
-
const result = await jsonBodyParser.parse(ctx);
|
|
59
|
-
expect(result.kind).toBe("fatal");
|
|
60
|
-
if (result.kind !== "fatal") return;
|
|
61
|
-
expect(result.message).toMatch(/got none/);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("fatals when the file doesn't exist", async () => {
|
|
65
|
-
const ctx = ctxOf(tmpDir, [{ handle: fsHandle("missing.json") }]);
|
|
66
|
-
const result = await jsonBodyParser.parse(ctx);
|
|
67
|
-
expect(result.kind).toBe("fatal");
|
|
68
|
-
if (result.kind !== "fatal") return;
|
|
69
|
-
expect(result.message).toMatch(/does not exist on disk/);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("fatals on malformed JSON", async () => {
|
|
73
|
-
writeFileSync(join(tmpDir, "bad.json"), "{not json");
|
|
74
|
-
const ctx = ctxOf(tmpDir, [{ handle: fsHandle("bad.json") }]);
|
|
75
|
-
const result = await jsonBodyParser.parse(ctx);
|
|
76
|
-
expect(result.kind).toBe("fatal");
|
|
77
|
-
if (result.kind !== "fatal") return;
|
|
78
|
-
expect(result.message).toMatch(/failed to parse JSON/);
|
|
79
|
-
});
|
|
80
|
-
});
|