@juicesharp/rpiv-workflow 1.20.0 → 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/api.ts +1 -1
- package/audit-ctx.ts +103 -0
- package/audit-rows.ts +18 -0
- package/audit.ts +119 -164
- package/built-ins.ts +26 -6
- package/chain-state.ts +119 -68
- package/command-run.ts +35 -30
- package/command.ts +10 -4
- package/docs/workflow-authoring.md +34 -2
- package/events.ts +44 -4
- package/execution-host.ts +75 -0
- package/host.ts +137 -82
- package/internal-utils.ts +89 -3
- package/internal.ts +1 -0
- package/judge.ts +23 -11
- package/load/alias.ts +3 -3
- package/load/index.ts +15 -1
- package/load/issues.ts +2 -2
- package/load/legacy.ts +2 -2
- package/load/resolve-default.ts +3 -4
- package/load/skill-contract-phase.ts +1 -1
- package/loop-constructors.ts +19 -618
- package/loop-def.ts +60 -15
- package/loop-kinds.ts +319 -62
- package/loop-parallel.ts +250 -0
- package/loop-waves.ts +99 -0
- package/loop.ts +106 -80
- 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 +58 -33
- package/outcomes/collectors/index.ts +1 -0
- package/outcomes/collectors/text-scan.ts +47 -0
- package/outcomes/collectors/transcript-path.ts +2 -15
- package/outcomes/collectors/union.ts +2 -1
- package/outcomes/collectors/url.ts +2 -14
- package/outcomes/collectors/workspace-diff.ts +1 -1
- package/outcomes/git-commit.ts +57 -6
- package/output-spec.ts +1 -1
- package/output.ts +59 -1
- package/package.json +16 -6
- package/preview.ts +18 -18
- package/registration.ts +11 -4
- package/routing-dsl.ts +53 -41
- package/routing.ts +46 -0
- package/runner/chain-advance.ts +30 -17
- package/runner/errors.ts +7 -30
- package/runner/failure.ts +67 -13
- package/runner/input-validation.ts +8 -5
- package/runner/preflight.ts +17 -21
- package/runner/resume-entry.ts +23 -3
- package/runner/resume-loop.ts +50 -29
- package/runner/resume.ts +96 -10
- package/runner/run-context.ts +20 -16
- package/runner/run-stage.ts +125 -91
- package/runner/runner.ts +163 -69
- package/runner/script-stage.ts +23 -29
- package/schema-compat.ts +1 -2
- package/semaphore.ts +55 -0
- package/sessions/extraction.ts +103 -60
- package/sessions/halt-routing.ts +195 -0
- package/sessions/index.ts +2 -2
- package/sessions/locate.ts +60 -9
- package/sessions/reattach.ts +28 -20
- package/sessions/sessions.ts +103 -191
- package/sessions/spawn.ts +132 -119
- package/sessions/success-persist.ts +89 -0
- package/skill-contracts/composition.ts +8 -10
- package/skill-contracts/harvest.ts +3 -2
- package/skill-contracts/registry.ts +1 -1
- package/stage-def.ts +115 -47
- package/stage-errors.ts +84 -0
- package/stage-identity.ts +56 -0
- package/startup.ts +1 -0
- package/state/paths.ts +11 -3
- package/state/raw.ts +2 -3
- package/state/resolve.ts +3 -3
- package/state/state.ts +26 -3
- package/state/writes.ts +1 -1
- package/types.ts +97 -43
- package/validate/contract-compat.ts +16 -11
- package/validate/graph.ts +10 -1
- package/validate/issue.ts +20 -6
- package/validate/stage-rules.ts +139 -60
- package/validate-output.ts +27 -20
- package/validate-workflow.ts +5 -3
- package/validation-bounds.ts +35 -0
- package/load/cache.test.ts +0 -82
- package/load/shape-guards.test.ts +0 -77
- package/outcomes/collectors/directory-path.test.ts +0 -64
- package/outcomes/collectors/tool-call.test.ts +0 -112
- package/outcomes/collectors/transcript-path.test.ts +0 -70
- package/outcomes/collectors/union.test.ts +0 -113
- package/outcomes/collectors/url.test.ts +0 -67
- package/outcomes/collectors/workspace-diff.test.ts +0 -120
- package/outcomes/git-commit.test.ts +0 -240
- 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/header-write-failure.test.ts +0 -64
- package/runner/resume-loop.test.ts +0 -1410
- package/runner/resume-session.test.ts +0 -400
- package/runner/resume.test.ts +0 -1805
- package/sessions/locate.test.ts +0 -77
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import type { BranchEntry } from "../../transcript.js";
|
|
3
|
-
import { directoryPathCollector } from "./directory-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("directoryPathCollector", () => {
|
|
22
|
-
it("throws when dir is missing or empty", () => {
|
|
23
|
-
// @ts-expect-error — intentional misuse
|
|
24
|
-
expect(() => directoryPathCollector({})).toThrow(/dir.*required/);
|
|
25
|
-
expect(() => directoryPathCollector({ dir: "" })).toThrow(/dir.*required/);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("matches files under the directory with any extension when ext omitted", async () => {
|
|
29
|
-
const collector = directoryPathCollector({ dir: "docs/adr" });
|
|
30
|
-
const ctx = ctxOf([asst("Wrote docs/adr/0042-init.md and docs/adr/notes.txt")]);
|
|
31
|
-
const result = await collector.collect(ctx);
|
|
32
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({
|
|
33
|
-
kind: "fs",
|
|
34
|
-
path: "docs/adr/notes.txt",
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("narrows by extension when supplied", async () => {
|
|
39
|
-
const collector = directoryPathCollector({ dir: "docs/adr", ext: "md" });
|
|
40
|
-
const ctx = ctxOf([asst("Wrote docs/adr/0042-init.md and docs/adr/notes.txt")]);
|
|
41
|
-
const result = await collector.collect(ctx);
|
|
42
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({
|
|
43
|
-
kind: "fs",
|
|
44
|
-
path: "docs/adr/0042-init.md",
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("escapes regex metacharacters in dir (e.g. dots in subfolder names)", async () => {
|
|
49
|
-
const collector = directoryPathCollector({ dir: ".rpiv/artifacts/research.v2", ext: "md" });
|
|
50
|
-
const ctx = ctxOf([asst("Result: .rpiv/artifacts/research.v2/topic.md")]);
|
|
51
|
-
const result = await collector.collect(ctx);
|
|
52
|
-
expect(result.kind === "ok" && result.artifacts[0]?.handle).toEqual({
|
|
53
|
-
kind: "fs",
|
|
54
|
-
path: ".rpiv/artifacts/research.v2/topic.md",
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("fatals when nothing matches the directory", async () => {
|
|
59
|
-
const collector = directoryPathCollector({ dir: "docs/adr", ext: "md" });
|
|
60
|
-
const ctx = ctxOf([asst("Wrote elsewhere/file.md")]);
|
|
61
|
-
const result = await collector.collect(ctx);
|
|
62
|
-
expect(result.kind).toBe("fatal");
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,112 +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(/`match` is required/);
|
|
29
|
-
// @ts-expect-error — intentional misuse
|
|
30
|
-
expect(() => toolCallCollector({ match: () => true })).toThrow(/`toArtifact` is required/);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("emits one artifact per matching tool call in branch order", async () => {
|
|
34
|
-
const collector = toolCallCollector({
|
|
35
|
-
match: (tc) => tc.name === "write_file",
|
|
36
|
-
toArtifact: (tc) => ({ handle: fs(String(tc.input.path)), role: "written" }),
|
|
37
|
-
});
|
|
38
|
-
const ctx = ctxOf([
|
|
39
|
-
asstWithTools([
|
|
40
|
-
{ name: "write_file", input: { path: "a.ts" } },
|
|
41
|
-
{ name: "read_file", input: { path: "ignored.ts" } },
|
|
42
|
-
{ name: "write_file", input: { path: "b.ts" } },
|
|
43
|
-
]),
|
|
44
|
-
]);
|
|
45
|
-
const result = await collector.collect(ctx);
|
|
46
|
-
expect(result.kind).toBe("ok");
|
|
47
|
-
if (result.kind !== "ok") return;
|
|
48
|
-
expect(result.artifacts).toEqual([
|
|
49
|
-
{ handle: { kind: "fs", path: "a.ts" }, role: "written" },
|
|
50
|
-
{ handle: { kind: "fs", path: "b.ts" }, role: "written" },
|
|
51
|
-
]);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("returns ok+empty when nothing matches (runner decides whether to fatal)", async () => {
|
|
55
|
-
const collector = toolCallCollector({
|
|
56
|
-
match: (tc) => tc.name === "write_file",
|
|
57
|
-
toArtifact: (tc) => ({ handle: fs(String(tc.input.path)) }),
|
|
58
|
-
});
|
|
59
|
-
const ctx = ctxOf([asstWithTools([{ name: "read_file", input: { path: "x.ts" } }])]);
|
|
60
|
-
const result = await collector.collect(ctx);
|
|
61
|
-
expect(result.kind).toBe("ok");
|
|
62
|
-
if (result.kind !== "ok") return;
|
|
63
|
-
expect(result.artifacts).toEqual([]);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("toArtifact returning undefined skips the call", async () => {
|
|
67
|
-
const collector = toolCallCollector({
|
|
68
|
-
match: () => true,
|
|
69
|
-
toArtifact: (tc) => (tc.input.path ? { handle: fs(String(tc.input.path)) } : undefined),
|
|
70
|
-
});
|
|
71
|
-
const ctx = ctxOf([
|
|
72
|
-
asstWithTools([
|
|
73
|
-
{ name: "bash", input: { cmd: "ls" } }, // no path → skipped
|
|
74
|
-
{ name: "write_file", input: { path: "a.ts" } },
|
|
75
|
-
]),
|
|
76
|
-
]);
|
|
77
|
-
const result = await collector.collect(ctx);
|
|
78
|
-
expect(result.kind === "ok" && result.artifacts).toEqual([{ handle: { kind: "fs", path: "a.ts" } }]);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("respects branchOffset", async () => {
|
|
82
|
-
const collector = toolCallCollector({
|
|
83
|
-
match: (tc) => tc.name === "write_file",
|
|
84
|
-
toArtifact: (tc) => ({ handle: fs(String(tc.input.path)) }),
|
|
85
|
-
});
|
|
86
|
-
const branch = [
|
|
87
|
-
asstWithTools([{ name: "write_file", input: { path: "prior.ts" } }]),
|
|
88
|
-
asstWithTools([{ name: "write_file", input: { path: "current.ts" } }]),
|
|
89
|
-
];
|
|
90
|
-
const ctx = { ...ctxOf(branch), branchOffset: 1 };
|
|
91
|
-
const result = await collector.collect(ctx);
|
|
92
|
-
expect(result.kind === "ok" && result.artifacts).toEqual([{ handle: { kind: "fs", path: "current.ts" } }]);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("multi-tool match — one collector covers write_file + edit", async () => {
|
|
96
|
-
const collector = toolCallCollector({
|
|
97
|
-
match: (tc) => tc.name === "write_file" || tc.name === "edit",
|
|
98
|
-
toArtifact: (tc) => ({ handle: fs(String(tc.input.path ?? tc.input.target_file)) }),
|
|
99
|
-
});
|
|
100
|
-
const ctx = ctxOf([
|
|
101
|
-
asstWithTools([
|
|
102
|
-
{ name: "write_file", input: { path: "new.ts" } },
|
|
103
|
-
{ name: "edit", input: { target_file: "old.ts" } },
|
|
104
|
-
]),
|
|
105
|
-
]);
|
|
106
|
-
const result = await collector.collect(ctx);
|
|
107
|
-
expect(result.kind === "ok" && result.artifacts.map((a) => a.handle)).toEqual([
|
|
108
|
-
{ kind: "fs", path: "new.ts" },
|
|
109
|
-
{ kind: "fs", path: "old.ts" },
|
|
110
|
-
]);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
@@ -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,113 +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
|
-
|
|
60
|
-
// ------------------------------------------------------------------------
|
|
61
|
-
// Snapshot fanout (C4) — a snapshot-bearing collector inside a union must
|
|
62
|
-
// behave exactly as it would standalone.
|
|
63
|
-
// ------------------------------------------------------------------------
|
|
64
|
-
|
|
65
|
-
it("declares NO snapshot hook when no sub-collector snapshots", () => {
|
|
66
|
-
const union = unionCollectors(okCollector(["a.ts"]), okCollector(["b.ts"]));
|
|
67
|
-
expect(union.snapshot).toBeUndefined();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("captures every sub-collector's snapshot and threads snapshots[i] into sub-collector i (C4)", async () => {
|
|
71
|
-
const seen: unknown[] = [];
|
|
72
|
-
const snapshotting = (tag: string): ArtifactCollector => ({
|
|
73
|
-
snapshot: () => `${tag}-baseline`,
|
|
74
|
-
collect: (ctx) => {
|
|
75
|
-
seen.push(ctx.snapshot);
|
|
76
|
-
return { kind: "ok", artifacts: [{ handle: fs(`${tag}.ts`) }] };
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
const snapshotless: ArtifactCollector = {
|
|
80
|
-
collect: (ctx) => {
|
|
81
|
-
seen.push(ctx.snapshot);
|
|
82
|
-
return { kind: "ok", artifacts: [] };
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const union = unionCollectors(snapshotting("diff"), snapshotless, snapshotting("git"));
|
|
87
|
-
expect(union.snapshot).toBeTypeOf("function");
|
|
88
|
-
|
|
89
|
-
const captured = await union.snapshot!(ctxOf());
|
|
90
|
-
expect(captured).toEqual(["diff-baseline", undefined, "git-baseline"]);
|
|
91
|
-
|
|
92
|
-
const result = await union.collect({ ...ctxOf(), snapshot: captured });
|
|
93
|
-
expect(result.kind).toBe("ok");
|
|
94
|
-
// Each sub-collector saw ITS OWN snapshot, positionally.
|
|
95
|
-
expect(seen).toEqual(["diff-baseline", undefined, "git-baseline"]);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("degrades every sub-snapshot to undefined when the whole capture degraded (runner contract)", async () => {
|
|
99
|
-
const seen: unknown[] = [];
|
|
100
|
-
const snapshotting: ArtifactCollector = {
|
|
101
|
-
snapshot: () => "baseline",
|
|
102
|
-
collect: (ctx) => {
|
|
103
|
-
seen.push(ctx.snapshot);
|
|
104
|
-
return { kind: "ok", artifacts: [] };
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
const union = unionCollectors(snapshotting);
|
|
108
|
-
// captureStageSnapshot hands undefined when the capture threw.
|
|
109
|
-
const result = await union.collect({ ...ctxOf(), snapshot: undefined });
|
|
110
|
-
expect(result.kind).toBe("ok");
|
|
111
|
-
expect(seen).toEqual([undefined]);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
@@ -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,120 +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
|
-
|
|
108
|
-
it("fatal when git worked at snapshot time but fails after the stage — no fabricated 'no changes' (T10)", async () => {
|
|
109
|
-
initRepo(tmpDir);
|
|
110
|
-
const collector = workspaceDiffCollector();
|
|
111
|
-
const snapshot = await collector.snapshot?.(snapshotCtxOf(tmpDir));
|
|
112
|
-
expect(snapshot).toBeDefined();
|
|
113
|
-
// Simulate the environment breaking mid-stage: the repo (and cwd)
|
|
114
|
-
// vanish between snapshot and collect.
|
|
115
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
116
|
-
const result = await collector.collect(collectCtxOf(tmpDir, snapshot));
|
|
117
|
-
expect(result.kind).toBe("fatal");
|
|
118
|
-
expect(result.kind === "fatal" && result.message).toMatch(/worked at snapshot time but failed after/);
|
|
119
|
-
});
|
|
120
|
-
});
|