Skip to content

Commit 3f01013

Browse files
committed
test(workflow): cover path and profile identity guards
1 parent 94ac40d commit 3f01013

2 files changed

Lines changed: 71 additions & 4 deletions

File tree

src/workflow-files.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from "node:assert/strict";
2-
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
2+
import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
55
import {
@@ -71,6 +71,31 @@ import { hashSource } from "./workflow-script.js";
7171
/must be inside/,
7272
);
7373

74+
if (process.platform !== "win32") {
75+
const outside = await mkdtemp(join(tmpdir(), "wf-files-outside-"));
76+
try {
77+
const outsideScript = join(outside, "escape.js");
78+
await writeFile(
79+
outsideScript,
80+
"export const meta = { name: 'escape', description: 'd' }\nreturn 4\n",
81+
);
82+
await symlink(
83+
outsideScript,
84+
join(dir, ".devspace", "workflows", "escape.js"),
85+
);
86+
await assert.rejects(
87+
() =>
88+
readProjectWorkflowScriptFile({
89+
scriptPath: "escape.js",
90+
workspaceRoot: dir,
91+
}),
92+
/resolves outside/,
93+
);
94+
} finally {
95+
await rm(outside, { recursive: true, force: true });
96+
}
97+
}
98+
7499
await mkdir(join(dir, "workflows"), { recursive: true });
75100
await writeFile(
76101
join(dir, "workflows", "legacy.js"),

src/workflow-replay.test.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ function call(
2020
};
2121
}
2222

23-
function identity(prompt = "prompt") {
23+
function identity(
24+
prompt = "prompt",
25+
profile: { name: string | null; fingerprint: string | null } = {
26+
name: null,
27+
fingerprint: null,
28+
},
29+
) {
2430
return {
2531
prompt,
26-
profileName: null,
27-
profileFingerprint: null,
32+
profileName: profile.name,
33+
profileFingerprint: profile.fingerprint,
2834
provider: "codex" as const,
2935
model: null,
3036
effort: null,
@@ -33,6 +39,42 @@ function identity(prompt = "prompt") {
3339
};
3440
}
3541

42+
{
43+
const replay = createWorkflowReplay([
44+
call({
45+
callIndex: 0,
46+
cacheKey: "profile",
47+
profileName: "reviewer",
48+
profileFingerprint: "fp-1",
49+
}),
50+
]);
51+
const miss = replay.decide(
52+
0,
53+
"profile-name-changed",
54+
identity("prompt", { name: "implementer", fingerprint: "fp-1" }),
55+
).miss;
56+
assert.equal(miss?.reason, "identity_changed");
57+
assert.deepEqual(miss?.changedFields, ["profileName"]);
58+
}
59+
60+
{
61+
const replay = createWorkflowReplay([
62+
call({
63+
callIndex: 0,
64+
cacheKey: "profile",
65+
profileName: "reviewer",
66+
profileFingerprint: "fp-1",
67+
}),
68+
]);
69+
const miss = replay.decide(
70+
0,
71+
"profile-fingerprint-changed",
72+
identity("prompt", { name: "reviewer", fingerprint: "fp-2" }),
73+
).miss;
74+
assert.equal(miss?.reason, "identity_changed");
75+
assert.deepEqual(miss?.changedFields, ["profileFingerprint"]);
76+
}
77+
3678
{
3779
const replay = createWorkflowReplay([
3880
call({ callIndex: 0, cacheKey: "k0", returnValueJson: JSON.stringify("a") }),

0 commit comments

Comments
 (0)