forgedock 1.56.0 → 1.58.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/bin/config-schema.mjs +1 -1
- package/bin/engine/outcome-codes.mjs +2 -1
- package/bin/engine/phases.mjs +4 -3
- package/bin/engine-cli.mjs +48 -12
- package/bin/forgedock.mjs +52 -3
- package/bin/gc.mjs +43 -6
- package/bin/help-text.mjs +4 -2
- package/bin/lean/batch-health.mjs +5 -1
- package/bin/lean/batch-health.test.mjs +7 -1
- package/bin/lean/batch.mjs +7 -2
- package/bin/lean/batch.test.mjs +45 -0
- package/bin/lean/conformance.e2e.test.mjs +3 -2
- package/bin/lean/conformance.mjs +118 -20
- package/bin/lean/conformance.test.mjs +172 -3
- package/bin/lean/decisions.mjs +98 -1
- package/bin/lean/decisions.test.mjs +30 -1
- package/bin/lean/depcache.mjs +124 -13
- package/bin/lean/depcache.test.mjs +121 -3
- package/bin/lean/design-gate.mjs +144 -0
- package/bin/lean/design-gate.test.mjs +169 -0
- package/bin/lean/effects-cap.test.mjs +17 -0
- package/bin/lean/effects.mjs +58 -13
- package/bin/lean/heavy.mjs +25 -8
- package/bin/lean/hostload.test.mjs +28 -0
- package/bin/lean/intake.mjs +97 -0
- package/bin/lean/intake.test.mjs +105 -0
- package/bin/lean/interfaces.mjs +181 -0
- package/bin/lean/interfaces.test.mjs +192 -0
- package/bin/lean/issuewatch-install.mjs +52 -12
- package/bin/lean/issuewatch-install.test.mjs +50 -0
- package/bin/lean/issuewatch-parity.mjs +16 -3
- package/bin/lean/issuewatch-parity.test.mjs +32 -0
- package/bin/lean/issuewatch-reconcile.mjs +29 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +21 -0
- package/bin/lean/issuewatch.mjs +34 -3
- package/bin/lean/issuewatch.test.mjs +49 -1
- package/bin/lean/lanecheck.test.mjs +15 -4
- package/bin/lean/lean.mjs +110 -24
- package/bin/lean/lean.test.mjs +183 -4
- package/bin/lean/orchestrate-blocked.test.mjs +18 -2
- package/bin/lean/orchestrate-owned.test.mjs +14 -5
- package/bin/lean/orchestrate.mjs +26 -4
- package/bin/lean/orphan-pr.mjs +3 -2
- package/bin/lean/orphan-pr.test.mjs +8 -1
- package/bin/lean/pagegate.mjs +35 -12
- package/bin/lean/pagegate.test.mjs +39 -1
- package/bin/lean/preflight.mjs +35 -1
- package/bin/lean/preflight.test.mjs +27 -1
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/reap.test.mjs +39 -0
- package/bin/lean/recovery.test.mjs +28 -3
- package/bin/lean/release-config.mjs +169 -0
- package/bin/lean/release-config.test.mjs +132 -0
- package/bin/lean/release-control.mjs +171 -0
- package/bin/lean/release-control.test.mjs +167 -0
- package/bin/lean/release-deploy.mjs +209 -0
- package/bin/lean/release-deploy.test.mjs +217 -0
- package/bin/lean/release-fence.mjs +50 -0
- package/bin/lean/release-fence.test.mjs +105 -0
- package/bin/lean/release-flakes.mjs +139 -0
- package/bin/lean/release-flakes.test.mjs +116 -0
- package/bin/lean/release-gates.mjs +230 -0
- package/bin/lean/release-gates.test.mjs +146 -0
- package/bin/lean/release-ledger.mjs +176 -0
- package/bin/lean/release-ledger.test.mjs +226 -0
- package/bin/lean/release-minutes.mjs +102 -0
- package/bin/lean/release-minutes.test.mjs +107 -0
- package/bin/lean/release-nightly.mjs +75 -0
- package/bin/lean/release-nightly.test.mjs +48 -0
- package/bin/lean/release-postmerge.mjs +8 -2
- package/bin/lean/release-review.e2e.test.mjs +1 -0
- package/bin/lean/release-review.mjs +54 -7
- package/bin/lean/release-review.test.mjs +76 -7
- package/bin/lean/release-status.mjs +300 -0
- package/bin/lean/release-status.test.mjs +220 -0
- package/bin/lean/release-unitmap.mjs +35 -0
- package/bin/lean/release-unitmap.test.mjs +41 -0
- package/bin/lean/release-verify.mjs +221 -0
- package/bin/lean/release-verify.test.mjs +176 -0
- package/bin/lean/release.mjs +244 -22
- package/bin/lean/release.test.mjs +44 -0
- package/bin/lean/render.mjs +3 -1
- package/bin/lean/run-issue-placement.test.mjs +82 -0
- package/bin/lean/sandbox-remote.mjs +16 -0
- package/bin/lean/schedd.mjs +1 -1
- package/bin/lean/seam.mjs +115 -0
- package/bin/lean/seam.test.mjs +118 -0
- package/bin/lean/selftest-journey.mjs +40 -2
- package/bin/lean/selftest-journey.test.mjs +43 -3
- package/bin/lean/statuscomment.mjs +168 -0
- package/bin/lean/statuscomment.test.mjs +133 -0
- package/bin/lean/ui-quality.mjs +57 -0
- package/bin/lean/ui-quality.test.mjs +55 -0
- package/bin/lean/visual-gate.test.mjs +63 -0
- package/bin/pool/agent.mjs +16 -2
- package/bin/pool/router.mjs +5 -1
- package/bin/review-staging.mjs +5 -3
- package/bin/stats/card.mjs +117 -0
- package/bin/stats/card.test.mjs +109 -0
- package/bin/stats/conformance-outcomes.test.mjs +2 -1
- package/bin/stats/depth.mjs +1 -1
- package/bin/stats/gh-retry.test.mjs +152 -0
- package/bin/stats/github-source.mjs +147 -14
- package/bin/stats/index.mjs +35 -2
- package/bin/stats/stats.test.mjs +31 -3
- package/bin/vendor/js-yaml/LICENSE +21 -0
- package/bin/vendor/js-yaml/PIN.md +7 -0
- package/bin/vendor/js-yaml/js-yaml.mjs +3851 -0
- package/commands/design-render-critique-loop.md +2 -0
- package/commands/design.md +2 -0
- package/commands/issue.md +1 -1
- package/commands/milestone.md +1 -1
- package/commands/review-pr-agents/frontend.md +1 -0
- package/commands/review-pr-staging.md +5 -0
- package/docs/CONFIG.md +95 -2
- package/docs/ISSUE-WATCH.md +7 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +10 -0
- package/docs/design/visual-gate.md +25 -0
- package/docs/eval/adversarial-bench.md +2 -2
- package/docs/eval/corpus/adversarial-v1.json +3 -3
- package/docs/site/start-a-new-project.md +7 -0
- package/docs/spec/forge-protocol-v1.md +31 -0
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/scripts/acceptance-red-green.sh +15 -1
- package/scripts/acceptance-red-green.test.sh +12 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +4 -1
- package/scripts/bootstrap-create.mjs +8 -2
- package/scripts/ci-local/scoping.mjs +19 -0
- package/scripts/ci-local.test.sh +16 -3
- package/scripts/fixtures/ci-local/gha-dorny/.github/workflows/ci.yml +4 -0
- package/scripts/plan-validate-live.mjs +9 -6
- package/scripts/review-prepare.sh +7 -1
- package/scripts/review-roster.sh +5 -2
- package/scripts/review-roster.test.sh +9 -0
- package/scripts/visual-gate.mjs +64 -0
- package/templates/bootstrap/technical-spike.md +17 -0
- package/templates/contracts/seam-check.mjs +236 -0
|
@@ -4,28 +4,65 @@
|
|
|
4
4
|
* `forgedock issue-watch install` (#5465): run one watch as a supervised unit, like `forgedock-schedd` (pool/install/install-schedd.sh).
|
|
5
5
|
* systemd user unit with `Restart=on-failure` (a finished watch exits 0 and stays down) plus a watchdog timer that runs
|
|
6
6
|
* `issue-watch watchdog` to alert on a dead heartbeat; launchd agent with `KeepAlive.SuccessfulExit=false` on macOS. No LLM calls.
|
|
7
|
+
* #5529: the unit carries the lane environment (PATH with claude first, TMPDIR, TOKENBATON_*, no CLAUDE_CONFIG_DIR) and reads the
|
|
8
|
+
* computeshare token when it starts; the token value is never written into the unit.
|
|
7
9
|
*/
|
|
8
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
9
11
|
import { spawnSync } from "node:child_process";
|
|
10
12
|
import { homedir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { resolveOnPath } from "./issuewatch-parity.mjs";
|
|
15
|
+
import { isShim } from "./rotator.mjs";
|
|
12
16
|
|
|
13
17
|
const safe = (s) => String(s).replace(/[^\w.-]/g, "_");
|
|
14
18
|
const quote = (s) => (/[\s"\\]/.test(s) ? `"${s.replace(/(["\\])/g, "\\$1")}"` : s);
|
|
15
19
|
|
|
16
20
|
export const watchUnitName = (name) => `forgedock-issue-watch-${safe(name)}`;
|
|
17
21
|
|
|
22
|
+
/** The router's token *file path* (never its value): `forgedock_token_file` of the computeshare router config, else its sibling `forgedock.token`. */
|
|
23
|
+
export function routerTokenFile({ env = process.env, home = homedir(), read = (p) => readFileSync(p, "utf8") } = {}) {
|
|
24
|
+
const conf = env.COMPUTESHARE_CONFIG || join(home, ".config", "computeshare", "router.json");
|
|
25
|
+
try { const p = JSON.parse(read(conf))?.forgedock_token_file; if (typeof p === "string" && p) return p; } catch { /* no router config: the sibling path */ }
|
|
26
|
+
return join(dirname(conf), "forgedock.token");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* #5529: the lane environment a supervised watch needs (systemd and launchd start it with almost none, so its lanes failed
|
|
31
|
+
* `Failed to find executable claude`): PATH with the tokenbaton shim and the resolved `claude` dirs first, then the installer's PATH;
|
|
32
|
+
* TMPDIR; TOKENBATON_HOME / TOKENBATON_SWITCH_AT when set. `tokenFile` is where the computeshare token is read at start (a path only).
|
|
33
|
+
* @returns {{vars: Record<string,string>, unset: string[], tokenFile: string, claude: string|null}}
|
|
34
|
+
*/
|
|
35
|
+
export function resolveLaneEnv({ env = process.env, home = homedir(), exists = existsSync } = {}) {
|
|
36
|
+
const claude = resolveOnPath("claude", env.PATH);
|
|
37
|
+
const shims = [env.TOKENBATON_HOME && join(env.TOKENBATON_HOME, "shim"), join(home, ".tokenbaton", "shim")].filter((d) => d && exists(join(d, "claude")));
|
|
38
|
+
const dirs = [...(claude && isShim(claude) ? [dirname(claude)] : []), ...shims, ...(claude ? [dirname(claude)] : []), ...String(env.PATH ?? "").split(":"), "/usr/local/bin", "/usr/bin", "/bin"];
|
|
39
|
+
const vars = { PATH: [...new Set(dirs.filter(Boolean))].join(":"), TMPDIR: env.TMPDIR || "/tmp" };
|
|
40
|
+
for (const k of ["TOKENBATON_HOME", "TOKENBATON_SWITCH_AT"]) if (env[k]) vars[k] = env[k];
|
|
41
|
+
return { vars, unset: ["CLAUDE_CONFIG_DIR"], tokenFile: routerTokenFile({ env, home }), claude };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const shq = (s) => "'" + String(s).replace(/'/g, "'\\''") + "'";
|
|
45
|
+
/** sh run at unit start: COMPUTESHARE_TOKEN from the keychain (pool/install/install-router.sh), else the router token file, then exec the watch. */
|
|
46
|
+
export const tokenStartScript = (tokenFile) =>
|
|
47
|
+
't="${COMPUTESHARE_TOKEN:-}"; [ -n "$t" ] || t=$(secret-tool lookup service forgedock account COMPUTESHARE_TOKEN 2>/dev/null) || t=; ' +
|
|
48
|
+
'[ -n "$t" ] || t=$(cat ' + shq(tokenFile) + ' 2>/dev/null) || t=; [ -n "$t" ] && export COMPUTESHARE_TOKEN="$t"; exec "$@"';
|
|
49
|
+
/** One systemd word in double quotes; `$` and `%` are doubled so systemd passes them through verbatim. */
|
|
50
|
+
const sdArg = (s) => '"' + String(s).replace(/(["\\])/g, "\\$1").replace(/[$%]/g, (c) => c + c) + '"';
|
|
51
|
+
|
|
18
52
|
/** The argv after `forgedock.mjs` that runs the watch. */
|
|
19
53
|
const runArgs = ({ name, repo, interval }) => ["issue-watch", "run", "--name", name, ...(repo ? ["--repo", repo] : []), ...(interval ? ["--interval", String(interval)] : [])];
|
|
20
54
|
|
|
21
|
-
export function renderSystemdUnit({ node, cli, name, repo, interval, cwd }) {
|
|
55
|
+
export function renderSystemdUnit({ node, cli, name, repo, interval, cwd, laneEnv = null }) {
|
|
56
|
+
const argv = [node, cli, ...runArgs({ name, repo, interval })].map(quote).join(" ");
|
|
57
|
+
const env = laneEnv ? [...Object.entries(laneEnv.vars).map(([k, v]) => `Environment=${sdArg(`${k}=${v}`)}`), `UnsetEnvironment=${laneEnv.unset.join(" ")}`, ""].join("\n") : "";
|
|
58
|
+
const exec = laneEnv ? `/bin/sh -c ${sdArg(tokenStartScript(laneEnv.tokenFile))} forgedock-issue-watch ${argv}` : argv;
|
|
22
59
|
return `[Unit]
|
|
23
60
|
Description=forgedock issue-watch ${name}
|
|
24
61
|
StartLimitIntervalSec=0
|
|
25
62
|
|
|
26
63
|
[Service]
|
|
27
64
|
WorkingDirectory=${cwd}
|
|
28
|
-
ExecStart=${
|
|
65
|
+
${env}ExecStart=${exec}
|
|
29
66
|
Restart=on-failure
|
|
30
67
|
RestartSec=30
|
|
31
68
|
|
|
@@ -56,8 +93,11 @@ WantedBy=timers.target
|
|
|
56
93
|
return { service, timer };
|
|
57
94
|
}
|
|
58
95
|
|
|
59
|
-
export function renderLaunchdPlist({ node, cli, name, repo, interval, cwd }) {
|
|
60
|
-
const
|
|
96
|
+
export function renderLaunchdPlist({ node, cli, name, repo, interval, cwd, laneEnv = null }) {
|
|
97
|
+
const x = (a) => String(a).replace(/&/g, "&").replace(/</g, "<");
|
|
98
|
+
const args = [node, cli, ...runArgs({ name, repo, interval })].map((a) => ` <string>${x(a)}</string>`).join("\n");
|
|
99
|
+
// launchd agents run in the login session, so the lane reads the token from the keychain itself; no value here
|
|
100
|
+
const env = laneEnv ? ` <key>EnvironmentVariables</key><dict>${Object.entries(laneEnv.vars).map(([k, v]) => `<key>${x(k)}</key><string>${x(v)}</string>`).join("")}</dict>\n` : "";
|
|
61
101
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
62
102
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
63
103
|
<plist version="1.0"><dict>
|
|
@@ -66,21 +106,21 @@ export function renderLaunchdPlist({ node, cli, name, repo, interval, cwd }) {
|
|
|
66
106
|
${args}
|
|
67
107
|
</array>
|
|
68
108
|
<key>WorkingDirectory</key><string>${cwd}</string>
|
|
69
|
-
<key>RunAtLoad</key><true/>
|
|
109
|
+
${env} <key>RunAtLoad</key><true/>
|
|
70
110
|
<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>
|
|
71
111
|
<key>ThrottleInterval</key><integer>30</integer>
|
|
72
112
|
</dict></plist>
|
|
73
113
|
`;
|
|
74
114
|
}
|
|
75
115
|
|
|
76
|
-
/** Writes and starts the unit; `{files, platform}`. `run(cmd, args)` and `write(path, text)` are injectable. */
|
|
77
|
-
export function installWatchUnit({ name, repo, interval, cwd = process.cwd(), node = process.execPath, cli, platform = process.platform, home = homedir(), run = (c, a) => spawnSync(c, a, { stdio: "ignore" }), write = (p, t) => { mkdirSync(join(p, ".."), { recursive: true }); writeFileSync(p, t); } }) {
|
|
78
|
-
const o = { node, cli, name, repo, interval, cwd }, files = [];
|
|
116
|
+
/** Writes and starts the unit; `{files, platform, claude}`. `run(cmd, args)` and `write(path, text)` are injectable; `env` is the installer's environment. */
|
|
117
|
+
export function installWatchUnit({ name, repo, interval, cwd = process.cwd(), node = process.execPath, cli, platform = process.platform, home = homedir(), env = process.env, run = (c, a) => spawnSync(c, a, { stdio: "ignore" }), write = (p, t) => { mkdirSync(join(p, ".."), { recursive: true }); writeFileSync(p, t); } }) {
|
|
118
|
+
const laneEnv = resolveLaneEnv({ env, home }), o = { node, cli, name, repo, interval, cwd, laneEnv }, files = [];
|
|
79
119
|
if (platform === "darwin") {
|
|
80
120
|
const f = join(home, "Library", "LaunchAgents", `com.forgedock.issue-watch.${safe(name)}.plist`);
|
|
81
121
|
write(f, renderLaunchdPlist(o)); files.push(f);
|
|
82
122
|
run("launchctl", ["unload", f]); run("launchctl", ["load", "-w", f]);
|
|
83
|
-
return { files, platform };
|
|
123
|
+
return { files, platform, claude: laneEnv.claude };
|
|
84
124
|
}
|
|
85
125
|
if (platform !== "linux") throw new Error(`issue-watch install: unsupported platform ${platform} (systemd or launchd only)`);
|
|
86
126
|
const dir = join(home, ".config", "systemd", "user"), u = watchUnitName(name), w = renderWatchdog(o);
|
|
@@ -88,5 +128,5 @@ export function installWatchUnit({ name, repo, interval, cwd = process.cwd(), no
|
|
|
88
128
|
run("systemctl", ["--user", "daemon-reload"]);
|
|
89
129
|
run("systemctl", ["--user", "enable", "--now", `${u}.service`]);
|
|
90
130
|
run("systemctl", ["--user", "enable", "--now", `${u}-watchdog.timer`]);
|
|
91
|
-
return { files, platform };
|
|
131
|
+
return { files, platform, claude: laneEnv.claude };
|
|
92
132
|
}
|
|
@@ -29,3 +29,53 @@ test("#5465 installWatchUnit writes three systemd files and enables them; other
|
|
|
29
29
|
assert.ok(ran.some((l) => /enable --now forgedock-issue-watch-nomilestone\.service/.test(l)));
|
|
30
30
|
assert.throws(() => installWatchUnit({ ...o, platform: "win32" }), /unsupported platform/);
|
|
31
31
|
});
|
|
32
|
+
|
|
33
|
+
// #5529: the unit the real installer writes must let a lane find claude; nothing in the install/render path is replaced
|
|
34
|
+
import { mkdirSync, writeFileSync, readFileSync, chmodSync, symlinkSync } from "node:fs";
|
|
35
|
+
import { join } from "node:path";
|
|
36
|
+
import { execFileSync } from "node:child_process";
|
|
37
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
38
|
+
|
|
39
|
+
const exe = (p) => { mkdirSync(join(p, ".."), { recursive: true }); writeFileSync(p, "#!/bin/sh\nexit 0\n"); chmodSync(p, 0o755); return p; };
|
|
40
|
+
/** systemd unquoting of one double-quoted word (`\x` escapes, doubled `$`/`%`). */
|
|
41
|
+
const sdWord = (w) => w.replace(/\\(.)/g, "$1").replace(/\$\$/g, "$").replace(/%%/g, "%");
|
|
42
|
+
|
|
43
|
+
test("#5529 the installed unit's PATH resolves the staged claude shim and carries the lane environment without the token value", () => {
|
|
44
|
+
const root = tmpDir("iw5529-"), home = join(root, "home"), bin = join(root, "opt", "claude-bin"), tb = join(root, "tb");
|
|
45
|
+
const claude = exe(join(bin, "claude"));
|
|
46
|
+
const tokenFile = join(home, ".config", "computeshare", "forgedock.token");
|
|
47
|
+
mkdirSync(join(tokenFile, ".."), { recursive: true }); writeFileSync(tokenFile, "file-token-xyz\n");
|
|
48
|
+
const env = { PATH: `${bin}:/usr/bin:/bin`, TMPDIR: "/tmp", TOKENBATON_HOME: tb, TOKENBATON_SWITCH_AT: "90", COMPUTESHARE_TOKEN: "secret-value-123", CLAUDE_CONFIG_DIR: "/x/claude" };
|
|
49
|
+
const ran = [];
|
|
50
|
+
const r = installWatchUnit({ ...o, platform: "linux", home, env, run: (c, a) => ran.push([c, ...a].join(" ")) });
|
|
51
|
+
const unit = readFileSync(r.files[0], "utf8");
|
|
52
|
+
// the observable: a shell started with the unit's PATH finds claude (the systemd default /usr/local/bin:/usr/bin did not)
|
|
53
|
+
const envLine = (k) => { const m = new RegExp(`^Environment="${k}=((?:[^"\\\\]|\\\\.)*)"$`, "m").exec(unit); return m ? sdWord(m[1]) : null; };
|
|
54
|
+
const path = envLine("PATH");
|
|
55
|
+
assert.ok(path, "unit sets PATH");
|
|
56
|
+
assert.equal(execFileSync("/bin/sh", ["-c", "command -v claude"], { env: { PATH: path }, encoding: "utf8" }).trim(), claude);
|
|
57
|
+
assert.equal(path.split(":")[0], bin, "the resolved claude dir comes first");
|
|
58
|
+
assert.equal(envLine("TMPDIR"), "/tmp");
|
|
59
|
+
assert.equal(envLine("TOKENBATON_HOME"), tb);
|
|
60
|
+
assert.equal(envLine("TOKENBATON_SWITCH_AT"), "90");
|
|
61
|
+
assert.match(unit, /^UnsetEnvironment=CLAUDE_CONFIG_DIR$/m);
|
|
62
|
+
assert.doesNotMatch(unit, /secret-value-123|file-token-xyz/, "the token value is never written into the unit");
|
|
63
|
+
// the token is sourced when the unit starts: run the ExecStart wrapper with a PATH that has only cat (no secret-tool)
|
|
64
|
+
const m = /^ExecStart=\/bin\/sh -c "((?:[^"\\]|\\.)*)" forgedock-issue-watch (.*)$/m.exec(unit);
|
|
65
|
+
assert.ok(m, "ExecStart wraps the watch in a token-sourcing sh");
|
|
66
|
+
assert.match(m[2], /forgedock\.mjs issue-watch run --name nomilestone --repo o\/r$/);
|
|
67
|
+
const catOnly = join(root, "catbin"); mkdirSync(catOnly); symlinkSync(execFileSync("/bin/sh", ["-c", "command -v cat"], { encoding: "utf8" }).trim(), join(catOnly, "cat"));
|
|
68
|
+
const out = execFileSync("/bin/sh", ["-c", sdWord(m[1]), "forgedock-issue-watch", "/bin/sh", "-c", 'printf %s "$COMPUTESHARE_TOKEN"'], { env: { PATH: catOnly }, encoding: "utf8" });
|
|
69
|
+
assert.equal(out, "file-token-xyz");
|
|
70
|
+
assert.ok(ran.some((l) => /enable --now forgedock-issue-watch-nomilestone\.service/.test(l)));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("#5529 launchd plist carries the lane PATH/TMPDIR, never the token", () => {
|
|
74
|
+
const root = tmpDir("iw5529-"), bin = join(root, "b"); exe(join(bin, "claude"));
|
|
75
|
+
const written = {};
|
|
76
|
+
installWatchUnit({ ...o, platform: "darwin", home: join(root, "h"), env: { PATH: `${bin}:/usr/bin`, COMPUTESHARE_TOKEN: "secret-value-123" }, run: () => {}, write: (p, t) => { written[p] = t; } });
|
|
77
|
+
const p = Object.values(written)[0];
|
|
78
|
+
assert.match(p, new RegExp(`<key>EnvironmentVariables</key><dict><key>PATH</key><string>${bin}:`));
|
|
79
|
+
assert.match(p, /<key>TMPDIR<\/key><string>\/tmp<\/string>/);
|
|
80
|
+
assert.doesNotMatch(p, /secret-value-123/);
|
|
81
|
+
});
|
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
* the default skip labels, issues with an open closing PR, release awareness (pause while a `forgedock release` job runs)
|
|
6
6
|
* and the heartbeat liveness read by `issue-watch status` and doctor. No LLM calls; gh and the clock are injected.
|
|
7
7
|
*/
|
|
8
|
-
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
8
|
+
import { accessSync, constants, existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
9
9
|
import { writeAtomic } from "./batch.mjs";
|
|
10
|
-
import { join } from "node:path";
|
|
10
|
+
import { delimiter, join } from "node:path";
|
|
11
11
|
import { RELEASE_STEPS } from "./release.mjs";
|
|
12
12
|
|
|
13
|
+
/** Optional steps that leave no trace when unconfigured: once post-merge is done they are not the pending step (#5560). */
|
|
14
|
+
const OPTIONAL_NO_TRACE = ["deploy"];
|
|
15
|
+
|
|
13
16
|
export const DEFAULT_SKIP_LABELS = ["epic", "needs-human", "post-deploy", "workflow:merged", "awaiting-promotion", "host-task"];
|
|
14
17
|
/** A release job that has not written its end `status` for this long is taken as dead, not in flight. */
|
|
15
18
|
export const RELEASE_STALE_MS = 6 * 3600 * 1000;
|
|
@@ -48,7 +51,7 @@ export function releaseInFlight({ root, repo = null, now = Date.now(), staleMs =
|
|
|
48
51
|
if (!st || st.status || (repo && st.repo && st.repo !== repo)) continue;
|
|
49
52
|
let age; try { age = now - stat(f).mtimeMs; } catch { continue; }
|
|
50
53
|
if (age > staleMs) continue;
|
|
51
|
-
if (!best || age < best.ageMs) best = { id, step: RELEASE_STEPS.find((x) => !st.steps?.[x]?.done) ?? null, ageMs: age };
|
|
54
|
+
if (!best || age < best.ageMs) best = { id, step: RELEASE_STEPS.find((x) => !st.steps?.[x]?.done && !(OPTIONAL_NO_TRACE.includes(x) && st.steps?.["post-merge"]?.done)) ?? null, ageMs: age };
|
|
52
55
|
}
|
|
53
56
|
return best;
|
|
54
57
|
}
|
|
@@ -92,3 +95,13 @@ export async function alertDeadWatches({ root, now = Date.now(), emit }) {
|
|
|
92
95
|
}
|
|
93
96
|
return dead;
|
|
94
97
|
}
|
|
98
|
+
|
|
99
|
+
/** #5529: the first executable `name` on `PATH` (a PATH string), or null. `isExec` defaults to a real X_OK check. */
|
|
100
|
+
export function resolveOnPath(name, PATH, { isExec = (p) => { try { accessSync(p, constants.X_OK); return statSync(p).isFile(); } catch { return false; } } } = {}) {
|
|
101
|
+
for (const d of String(PATH ?? "").split(delimiter)) if (d && isExec(join(d, name))) return join(d, name);
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** #5529: one warning per watch whose running watcher recorded that it cannot resolve `claude` (status.json `claude: null`). */
|
|
106
|
+
export const watchEnvWarnings = (rows) => rows.filter((w) => w.status && "claude" in w.status && w.status.claude === null && !["done", "exited"].includes(w.live?.state))
|
|
107
|
+
.map((w) => `watch ${w.name} (${w.repo}): cannot resolve claude on the watcher PATH; its lanes fail 'Failed to find executable claude' (reinstall: forgedock issue-watch install --name ${w.name})`);
|
|
@@ -89,6 +89,12 @@ test("#5313 a release in flight pauses the watch (no claims), the next pass resu
|
|
|
89
89
|
assert.match(formatStatus(s, watch, io.now()), /state: exited \(single pass/);
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
+
test("#5560 releaseInFlight: an unconfigured (trace-less) deploy is not the pending step after post-merge", () => {
|
|
93
|
+
const env = tmpDir("iwp-"), root = join(env, "releases"), done = { done: true };
|
|
94
|
+
relDir(env, "r20261110-120000-1", { repo: "o/r", steps: { preflight: done, "host-preflight": done, "release-pr": done, review: done, fixes: done, "mark-ready": done, rehearsal: done, promotion: done, "post-merge": done } }, 60000);
|
|
95
|
+
assert.equal(releaseInFlight({ root, repo: "o/r", now: NOW }).step, null);
|
|
96
|
+
});
|
|
97
|
+
|
|
92
98
|
test("#5313 watchLiveness: a fresh heartbeat runs, an old one is dead, a finished watch is done", () => {
|
|
93
99
|
const beat = (ms) => new Date(NOW - ms).toISOString();
|
|
94
100
|
assert.equal(watchLiveness({ phase: "running", heartbeat: beat(1000), heartbeatEveryMs: 300000 }, NOW).state, "running");
|
|
@@ -150,3 +156,29 @@ test("#5465 a killed watch shows DEAD within 3 heartbeats and the watchdog alert
|
|
|
150
156
|
writeFileSync(join(dir, "status.json"), JSON.stringify({ ...state(), heartbeat: beat(1000), heartbeatEveryMs: 300000 }));
|
|
151
157
|
assert.equal((await alertDeadWatches({ root, now, emit })).length, 0);
|
|
152
158
|
});
|
|
159
|
+
|
|
160
|
+
// #5529: claude resolution of the running watcher and the status/doctor warning rows, on a real temp filesystem
|
|
161
|
+
import { chmodSync } from "node:fs";
|
|
162
|
+
import { resolveOnPath, watchEnvWarnings } from "./issuewatch-parity.mjs";
|
|
163
|
+
|
|
164
|
+
test("#5529 resolveOnPath finds an executable claude and ignores a non-executable one", () => {
|
|
165
|
+
const d = tmpDir("iw5529-"), a = join(d, "a"), b = join(d, "b");
|
|
166
|
+
mkdirSync(a); mkdirSync(b);
|
|
167
|
+
writeFileSync(join(a, "claude"), "x"); // not executable
|
|
168
|
+
writeFileSync(join(b, "claude"), "#!/bin/sh\n"); chmodSync(join(b, "claude"), 0o755);
|
|
169
|
+
assert.equal(resolveOnPath("claude", `${a}:${b}`), join(b, "claude"));
|
|
170
|
+
assert.equal(resolveOnPath("claude", a), null);
|
|
171
|
+
assert.equal(resolveOnPath("claude", undefined), null);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("#5529 watchEnvWarnings warns only for a live watcher that recorded it cannot resolve claude", () => {
|
|
175
|
+
const root = tmpDir("iw5529-"), beat = new Date(NOW).toISOString();
|
|
176
|
+
const put = (name, s) => { mkdirSync(join(root, "o__r", name), { recursive: true }); writeFileSync(join(root, "o__r", name, "status.json"), JSON.stringify({ name, repo: "o/r", phase: "running", heartbeat: beat, ...s })); };
|
|
177
|
+
put("bare", { claude: null });
|
|
178
|
+
put("ok", { claude: "/u/bin/claude" });
|
|
179
|
+
put("old", {}); // written before #5529: unknown, no warning
|
|
180
|
+
put("gone", { claude: null, phase: "exited" });
|
|
181
|
+
const lines = watchEnvWarnings(listWatches(root, NOW));
|
|
182
|
+
assert.equal(lines.length, 1);
|
|
183
|
+
assert.match(lines[0], /watch bare \(o\/r\): cannot resolve claude/);
|
|
184
|
+
});
|
|
@@ -26,7 +26,35 @@ export function classifyClaim(row) {
|
|
|
26
26
|
return code && classifyNeedsHuman(row) !== "human" && code !== "unclassified" ? { kind: "parked", code } : { kind: "needs-human", code };
|
|
27
27
|
}
|
|
28
28
|
if (outcome === "" || outcome === "pending" || outcome === "running") return { kind: "running", code: null };
|
|
29
|
-
|
|
29
|
+
// #5529: a lane that could not start its CLI (unit without the lane PATH) is environmental: retried once the watcher resolves it
|
|
30
|
+
const why = String(row.detail ?? row.reason ?? row.error ?? "");
|
|
31
|
+
return MISSING_EXECUTABLE.test(why) ? { kind: "stranded", code: outcome, reason: "missing-executable" } : { kind: "stranded", code: outcome };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** #5529: the lane's error text when its CLI was not on PATH ("Failed to find executable claude", spawn ENOENT, sh "not found"). */
|
|
35
|
+
export const MISSING_EXECUTABLE = /Failed to find executable|spawn \S+ ENOENT|command not found|claude: not found/i;
|
|
36
|
+
/** #5529: re-drives per stranded claim before it stays failed. */
|
|
37
|
+
export const REDRIVES = 2;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* #5529: a stranded claim is re-driven, not only counted: `redrive(n)` (requeue into the batch, or release the claim) at most `max`
|
|
41
|
+
* times per issue; a `missing-executable` one only once `resolved()` says the watcher can find the CLI again. A re-driven claim's
|
|
42
|
+
* outcome is cleared so `claimCounts` stops counting it. @returns {number[]} the issues re-driven.
|
|
43
|
+
*/
|
|
44
|
+
export function redriveStep({ state, now, resolved, redrive, max = REDRIVES }) {
|
|
45
|
+
state.redriven ??= {};
|
|
46
|
+
const out = [];
|
|
47
|
+
for (const [n, o] of Object.entries(state.outcomes ?? {})) {
|
|
48
|
+
if (o.kind !== "stranded") continue;
|
|
49
|
+
const r = state.redriven[n] ?? { count: 0 };
|
|
50
|
+
if (r.count >= max) continue;
|
|
51
|
+
if (o.reason === "missing-executable" && !resolved()) continue;
|
|
52
|
+
if (!redrive(Number(n), o)) continue;
|
|
53
|
+
state.redriven[n] = { count: r.count + 1, at: now, reason: o.reason ?? o.code };
|
|
54
|
+
delete state.outcomes[n];
|
|
55
|
+
out.push(Number(n));
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
30
58
|
}
|
|
31
59
|
|
|
32
60
|
/**
|
|
@@ -28,3 +28,24 @@ test("stuckClaims lists only old unmerged claims with the reason", () => {
|
|
|
28
28
|
assert.deepEqual(rows.map((r) => r.issue), [1]);
|
|
29
29
|
assert.match(formatStuck(rows), /#1 claimed 100h ago, no merged PR: running in its lane/);
|
|
30
30
|
});
|
|
31
|
+
|
|
32
|
+
test("#5529 classifyClaim marks a lane that could not find its CLI as missing-executable; other engine-errors unchanged", () => {
|
|
33
|
+
const row = { outcome: "engine-error", detail: "claude CLI exited with status 1. Output: Failed to find executable claude: No such file or directory" };
|
|
34
|
+
assert.deepEqual(classifyClaim(row), { kind: "stranded", code: "engine-error", reason: "missing-executable" });
|
|
35
|
+
assert.deepEqual(classifyClaim({ outcome: "engine-error", detail: "lane pid 4 exited without a result" }), { kind: "stranded", code: "engine-error" });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("#5529 redriveStep waits for claude on a missing-executable claim, re-drives others, and respects the budget", async () => {
|
|
39
|
+
const { redriveStep } = await import("./issuewatch-reconcile.mjs");
|
|
40
|
+
const state = { outcomes: { 1: { kind: "stranded", code: "engine-error", reason: "missing-executable" }, 2: { kind: "stranded", code: "engine-error" }, 3: { kind: "parked", code: "ci.red" } } };
|
|
41
|
+
const driven = [];
|
|
42
|
+
let ok = false;
|
|
43
|
+
assert.deepEqual(redriveStep({ state, now: 1, resolved: () => ok, redrive: (n) => (driven.push(n), true) }), [2]);
|
|
44
|
+
assert.equal(claimCounts({ ...state, inflight: [] }).stranded, 1);
|
|
45
|
+
ok = true;
|
|
46
|
+
assert.deepEqual(redriveStep({ state, now: 2, resolved: () => ok, redrive: (n) => (driven.push(n), true) }), [1]);
|
|
47
|
+
assert.equal(claimCounts({ ...state, inflight: [] }).stranded, 0);
|
|
48
|
+
for (let i = 0; i < 3; i++) { state.outcomes[2] = { kind: "stranded", code: "engine-error" }; redriveStep({ state, now: 3 + i, resolved: () => true, redrive: (n) => (driven.push(n), true) }); }
|
|
49
|
+
assert.equal(driven.filter((n) => n === 2).length, 2, "budget of 2 re-drives");
|
|
50
|
+
assert.equal(state.outcomes[3].kind, "parked");
|
|
51
|
+
});
|
package/bin/lean/issuewatch.mjs
CHANGED
|
@@ -22,12 +22,12 @@ import { releaseTick, formatDryRun } from "./issuewatch-release.mjs";
|
|
|
22
22
|
import { releaseRoot } from "./release.mjs";
|
|
23
23
|
import { loadPolicy } from "./decision-engine.mjs";
|
|
24
24
|
import { decisionContext, decisionsActive, decisionStep, decisionCounts, formatDecisionDryRun, claimsUsed } from "./issuewatch-decisions.mjs";
|
|
25
|
-
import { reconcileClaims, remediateStep, reclaimStep, claimCounts, stuckClaims, formatStuck } from "./issuewatch-reconcile.mjs";
|
|
25
|
+
import { reconcileClaims, remediateStep, reclaimStep, redriveStep, claimCounts, stuckClaims, formatStuck } from "./issuewatch-reconcile.mjs";
|
|
26
26
|
import { APP_SLUG } from "../init-repo.mjs";
|
|
27
27
|
import { noComments } from "./render.mjs";
|
|
28
28
|
import { listAssociations } from "./gh-assoc.mjs";
|
|
29
29
|
import { verifyMerge, verifyComment } from "./issuewatch-verify.mjs";
|
|
30
|
-
import { DEFAULT_SKIP_LABELS, isPullRequest, searchesPullRequests, skipLabelHit, closingPrIssues, releaseInFlight, watchLiveness, alertDeadWatches } from "./issuewatch-parity.mjs";
|
|
30
|
+
import { DEFAULT_SKIP_LABELS, isPullRequest, searchesPullRequests, skipLabelHit, closingPrIssues, releaseInFlight, watchLiveness, alertDeadWatches, resolveOnPath } from "./issuewatch-parity.mjs";
|
|
31
31
|
|
|
32
32
|
const WATCH_KEYS = ["milestone", "labels", "exclude_labels", "search", "title_regex", "since", "version", "lane", "max_issues", "max_inflight", "until", "mode", "parallel", "include_followups", "postdeploy_rollup", "threshold", "immediate", "max_release_issues", "theme_map", "tracker", "sweep_needs_human", "max_launches", "trust_app", "trust_app_labels", "skip_labels", "release_pause", "max_remediations"];
|
|
33
33
|
export const TRUSTED = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
@@ -362,6 +362,16 @@ export async function tick({ watch, repo, io, state, dir, branches = {}, default
|
|
|
362
362
|
if (watch.mode === "batch") {
|
|
363
363
|
await remediateStep({ watch, repo, io, state, handles, now, settle, fail });
|
|
364
364
|
await reclaimStep({ repo, io, state, trusted: (c) => TRUSTED.has(c?.authorAssociation), release: (n) => { releaseClaims(repoDir(repo, io.env), [n], watch.name); state.claimed = state.claimed.filter((x) => x !== n); delete state.lanes[n]; unsettle(state, n); } });
|
|
365
|
+
// #5529: stranded claims are re-driven (budgeted); a missing-executable one once this watcher, whose env its lanes inherit, finds claude
|
|
366
|
+
redriveStep({ state, now, resolved: () => resolveOnPath("claude", (io.env ?? process.env).PATH) !== null, redrive: (n) => {
|
|
367
|
+
if (state.batch) {
|
|
368
|
+
if (!io.batch?.requeue?.(state.batch, n, "issue-watch: re-drive stranded claim")) return false;
|
|
369
|
+
unsettle(state, n); if (!state.inflight.includes(n)) state.inflight.push(n);
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
releaseClaims(repoDir(repo, io.env), [n], watch.name); state.claimed = state.claimed.filter((x) => x !== n); delete state.lanes[n]; unsettle(state, n);
|
|
373
|
+
return true;
|
|
374
|
+
} });
|
|
365
375
|
}
|
|
366
376
|
for (const n of [...(state.pendingVerify ?? [])]) if (await closed(n)) await verify(n);
|
|
367
377
|
if (watch.mode === "batch" && state.batch && io.batch.reported(state.batch)) { state.inflight.forEach(fail); state.batch = null; }
|
|
@@ -497,7 +507,8 @@ export function formatStatus(s, watch, now = Date.now()) {
|
|
|
497
507
|
const left = watch.until ? `${Math.max(0, Math.round((Date.parse(watch.until) - now) / 60000))}m` : "forever";
|
|
498
508
|
const live = s.heartbeat || s.paused || s.phase === "exited" ? watchLiveness(s, now) : null;
|
|
499
509
|
return [`watch ${s.name} (${s.repo}) [${s.phase}, ${watch.mode}]`, ...(live ? [` state: ${live.state === "dead" ? "DEAD" : live.state}${["paused", "dead", "exited"].includes(live.state) ? ` (${live.reason})` : ""} last heartbeat: ${s.heartbeat ?? "never"}${live.ageMs != null ? ` (${Math.round(live.ageMs / 1000)}s ago)` : ""}`] : []), ` selector: ${sel}`,
|
|
500
|
-
|
|
510
|
+
...(s.claude === null ? [" WARNING: this watcher cannot resolve claude on its PATH; its lanes fail 'Failed to find executable claude' (reinstall: forgedock issue-watch install)"] : []), // #5529
|
|
511
|
+
` reconciled: ${Object.entries(claimCounts(s)).map(([k, v]) => `${k} ${v}`).join(" ")}${s.redriven && Object.keys(s.redriven).length ? ` re-driven ${Object.keys(s.redriven).length}` : ""}`,
|
|
501
512
|
` claims: ${s.claimed.length}/${watch.max_issues ?? "∞"} inflight: ${s.inflight.length} merged: ${s.merged.length} verified: ${s.verified.length} unverified: ${(s.unverified ?? []).length} closed unmerged: ${(s.closed ?? []).length} failed: ${s.failed.length}`, ` time remaining: ${left}`,
|
|
502
513
|
...(s.decisions ? [(({ decided, evidence, folded, external_kept: kept }) => ` needs-human decisions: decided ${decided} evidence-gathered ${evidence} folded ${folded} external-kept ${kept}`)(decisionCounts(s))] : []),
|
|
503
514
|
...(s.passError ? [` last pass failed: ${s.passError}`] : []), // #5425
|
|
@@ -554,7 +565,11 @@ export async function runWatch({ watch, repo, io, dir, branches, defaults, once
|
|
|
554
565
|
try {
|
|
555
566
|
do {
|
|
556
567
|
state.heartbeat = new Date(io.now()).toISOString(); state.heartbeatEveryMs = intervalMs; // #5313: liveness lives in the state, not a process grep
|
|
568
|
+
state.claude = resolveOnPath("claude", (io.env ?? process.env).PATH); // #5529: what this watcher's lanes inherit; status/doctor warn on null
|
|
557
569
|
let rel = null; try { rel = watch.release_pause && state.phase === "running" ? (io.releaseInFlight ?? releaseInFlight)({ root: releaseRoot(io.env), repo, now: io.now() }) : null; } catch { /* unreadable release state: not paused */ }
|
|
570
|
+
let gp = null; // #5555 (I18): GitHub truth, every host; only for a managed release repo, so defaults make no call
|
|
571
|
+
if (!rel && watch.release_pause && state.phase === "running") { try { gp = await githubIntake({ io, repo, cwd, state }); } catch (e) { state.pauseError = String(e?.message ?? e).slice(0, 200); } }
|
|
572
|
+
if (gp) { state.paused = { reason: gp.reason, source: gp.source, since: state.paused?.since ?? state.heartbeat }; writeAtomic(join(dir, "status.json"), JSON.stringify(state) + "\n"); if (once) break; await io.sleep(intervalMs); continue; }
|
|
558
573
|
if (rel) { // a release job holds staging: no claims, retries or decisions until it ends; the next pass resumes by itself
|
|
559
574
|
state.paused = { reason: `release ${rel.id} in flight${rel.step ? ` (${rel.step})` : ""}`, release: rel.id, since: state.paused?.since ?? state.heartbeat };
|
|
560
575
|
writeAtomic(join(dir, "status.json"), JSON.stringify(state) + "\n");
|
|
@@ -671,6 +686,22 @@ export function ghRunner(exec, warn = () => {}, { retries = GH_RETRIES, sleep =
|
|
|
671
686
|
};
|
|
672
687
|
}
|
|
673
688
|
|
|
689
|
+
/** #5555: `{reason, source}` when GitHub says intake is paused (null otherwise); auto-resumes a pause whose release ended. */
|
|
690
|
+
async function githubIntake({ io, repo, cwd, state }) {
|
|
691
|
+
const { readReleaseConfig } = await import("./release.mjs"), { githubPause, ghGet, setIntake } = await import("./intake.mjs");
|
|
692
|
+
let raw = ""; try { raw = readFileSync(join(cwd, "forge.yaml"), "utf8"); } catch { /* defaults */ }
|
|
693
|
+
const cfg = readReleaseConfig(raw);
|
|
694
|
+
if (!cfg.managed) return null;
|
|
695
|
+
const g = await githubPause({ get: ghGet(io.gh), repo, autoResume: !!cfg.intakeAutoResume });
|
|
696
|
+
state.pauseError = null;
|
|
697
|
+
if (g.resume) {
|
|
698
|
+
const api = io.api ?? (await import("./release.mjs")).realReleaseIo({ env: io.env, cwd }).api;
|
|
699
|
+
await setIntake({ io: { api }, repo, paused: false, by: "issue-watch", tracker: cfg.tracker ?? null, now: io.now() });
|
|
700
|
+
return null;
|
|
701
|
+
}
|
|
702
|
+
return g.paused ? g : null;
|
|
703
|
+
}
|
|
704
|
+
|
|
674
705
|
const flag = (argv, f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : null; };
|
|
675
706
|
|
|
676
707
|
/** `forgedock issue-watch run [--name w] [--repo o/r] [--once] [--interval s] | status [--name w] [--repo o/r]`; `--dry-run` writes nothing: mode release prints the would-cut set, per-issue/batch the would-claim/fold/skip plan (#5088) and the needs-human classification. */
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { test } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { mkdirSync, writeFileSync, existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { mkdirSync, writeFileSync, existsSync, readFileSync, chmodSync } from "node:fs";
|
|
6
6
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { unclaimedOrOwn, parseWatches, validateWatch, loadWatches, matchesSelectors, issueVersion, hasUnresolvedDefer, classifyIssue, laneFor, dagOrder, claimIssue, acquireLock, tick, runWatch, formatStatus, repoDir, watchDir, issueWatchFromCli, isOwnApp, selectorMiss, planClaims, ghFailureEffect, ghRunner, isTransientGhError } from "./issuewatch.mjs";
|
|
@@ -763,3 +763,51 @@ test("a needs-human issue a person cleared with a new comment is re-claimed; stu
|
|
|
763
763
|
await tick({ watch: w, repo: "o/r", io, state });
|
|
764
764
|
assert.ok(!state.outcomes?.[1]); // released, then re-selected is up to planClaims
|
|
765
765
|
});
|
|
766
|
+
|
|
767
|
+
// #5529: real tick/reconcile/redrive over a real batch state.json (openBatch) and the real claims.json registry; the
|
|
768
|
+
// orchestrate --requeue spawn and gh are the external seams (calls recorded); claude is resolved on a real temp PATH
|
|
769
|
+
const stageClaude = (d) => { mkdirSync(d, { recursive: true }); writeFileSync(join(d, "claude"), "#!/bin/sh\n"); chmodSync(join(d, "claude"), 0o755); return d; };
|
|
770
|
+
|
|
771
|
+
test("#5529 a missing-executable engine-error is requeued once claude resolves, not before; other stranded claims are re-driven within budget", async () => {
|
|
772
|
+
const dir = tmp(), root = tmp(), noClaude = tmp(), bin = join(tmp(), "bin");
|
|
773
|
+
const b = openBatch(root, "b1");
|
|
774
|
+
mkdirSync(b.dir, { recursive: true });
|
|
775
|
+
b.store.save({ order: [1, 2], results: { 1: { outcome: "engine-error", detail: "claude CLI exited with status 1. Output: Failed to find executable claude: No such file or directory" }, 2: { outcome: "engine-error", detail: "lane pid 9 exited without a result" } } });
|
|
776
|
+
const io = fakeIo(dir, []), requeued = [];
|
|
777
|
+
io.env.PATH = noClaude;
|
|
778
|
+
io.batch.results = (id) => openBatch(root, id).store.load()?.results ?? null;
|
|
779
|
+
io.batch.requeue = (id, n) => { requeued.push(n); const st = b.store.load(); delete st.results[n]; b.store.save(st); return true; }; // what orchestrate --requeue does to the row
|
|
780
|
+
for (const n of [1, 2]) assert.equal(claimIssue(repoDir("o/r", io.env), n, "w"), true);
|
|
781
|
+
const state = batchState({ claimed: [1, 2], inflight: [1, 2], lanes: { 1: "staging", 2: "staging" } });
|
|
782
|
+
const watch = W({ mode: "batch" });
|
|
783
|
+
await tick({ watch, repo: "o/r", io, state });
|
|
784
|
+
assert.deepEqual(requeued, [2], "claude still missing: only the generic stranded claim is re-driven");
|
|
785
|
+
assert.match(formatStatus(state, watch, io.now()), /stranded 1/);
|
|
786
|
+
await tick({ watch, repo: "o/r", io, state });
|
|
787
|
+
assert.deepEqual(requeued, [2], "still not resolvable: no requeue");
|
|
788
|
+
io.env.PATH = `${noClaude}:${stageClaude(bin)}`;
|
|
789
|
+
await tick({ watch, repo: "o/r", io, state });
|
|
790
|
+
assert.deepEqual(requeued, [2, 1]);
|
|
791
|
+
assert.ok(state.inflight.includes(1) && !state.failed.includes(1));
|
|
792
|
+
assert.match(formatStatus(state, watch, io.now()), /stranded 0.*re-driven 2/);
|
|
793
|
+
assert.equal(claimIssue(repoDir("o/r", io.env), 1, "other"), false, "the claim stays with this watch while it is requeued");
|
|
794
|
+
// budget: issue 2 keeps failing; it is requeued at most twice in total
|
|
795
|
+
for (let i = 0; i < 3; i++) { const st = b.store.load(); st.results[2] = { outcome: "engine-error", detail: "boom" }; b.store.save(st); await tick({ watch, repo: "o/r", io, state }); }
|
|
796
|
+
assert.equal(requeued.filter((n) => n === 2).length, 2);
|
|
797
|
+
assert.match(formatStatus(state, watch, io.now()), /stranded 1/);
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
test("#5529 the running watcher records whether it resolves claude and status warns when it cannot", async () => {
|
|
801
|
+
const dir = tmp(), bin = join(tmp(), "bin"), watch = W({ mode: "batch" });
|
|
802
|
+
const io = fakeIo(dir, []);
|
|
803
|
+
io.env.PATH = tmp();
|
|
804
|
+
const wd = watchDir("o/r", "w", io.env);
|
|
805
|
+
let state = await runWatch({ watch, repo: "o/r", io, dir: wd, once: true });
|
|
806
|
+
assert.equal(state.claude, null);
|
|
807
|
+
assert.equal(JSON.parse(readFileSync(join(wd, "status.json"), "utf8")).claude, null);
|
|
808
|
+
assert.match(formatStatus(state, watch, io.now()), /WARNING: this watcher cannot resolve claude/);
|
|
809
|
+
io.env.PATH = stageClaude(bin);
|
|
810
|
+
state = await runWatch({ watch, repo: "o/r", io, dir: wd, once: true });
|
|
811
|
+
assert.equal(state.claude, join(bin, "claude"));
|
|
812
|
+
assert.doesNotMatch(formatStatus(state, watch, io.now()), /cannot resolve claude/);
|
|
813
|
+
});
|
|
@@ -7,7 +7,7 @@ import { mkdirSync, writeFileSync, chmodSync } from "node:fs";
|
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
9
9
|
import { checkPoolAuth, checkPoolVersion, checkPathLoop, checkGhFields, availableFields, runLaneChecks, formatLaneChecks, UPGRADE_COMMAND } from "./lanecheck.mjs";
|
|
10
|
-
import { findShimLoops } from "./heavy.mjs";
|
|
10
|
+
import { findShimLoops, heavyShimScript } from "./heavy.mjs";
|
|
11
11
|
import { orchestrate, deferPolicy } from "./orchestrate.mjs";
|
|
12
12
|
import { providerLanes, isCloneFailure } from "./execution.mjs";
|
|
13
13
|
|
|
@@ -66,10 +66,21 @@ describe("pool_version", () => {
|
|
|
66
66
|
describe("path_loop", () => {
|
|
67
67
|
const wrapper = "#!/bin/sh\nexec \"$(command -v docker)\" \"$@\"\n";
|
|
68
68
|
const mk = () => { const d = tmpDir("lc-"); const w = join(d, "wrap"); mkdirSync(w); writeFileSync(join(w, "docker"), wrapper); chmodSync(join(w, "docker"), 0o755); return { d, w }; };
|
|
69
|
-
it("names the
|
|
69
|
+
it("names the shim dir when a heavy shim execs a pass-through wrapper", () => {
|
|
70
|
+
const { d, w } = mk(); const sh = join(d, "shim"); mkdirSync(sh);
|
|
71
|
+
writeFileSync(join(sh, "docker"), heavyShimScript("docker", join(w, "docker"))); chmodSync(join(sh, "docker"), 0o755);
|
|
72
|
+
const c = checkPathLoop({ env: { PATH: `${sh}:${w}` } });
|
|
73
|
+
assert.equal(c.ok, false); assert.equal(c.code, "preflight.path_loop"); assert.ok(c.detail.includes(sh));
|
|
74
|
+
});
|
|
75
|
+
it("#5592: a batch-level wrapper with no real binary behind it does not trip (no shim is written over it)", () => {
|
|
70
76
|
const { w } = mk();
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
assert.equal(checkPathLoop({ env: { PATH: w } }).ok, true);
|
|
78
|
+
});
|
|
79
|
+
it("#5592: a wrapper our own shim already covers (shim points at the real binary) passes", () => {
|
|
80
|
+
const { d, w } = mk(); const real = join(d, "real"), sh = join(d, "shim"); mkdirSync(real); mkdirSync(sh);
|
|
81
|
+
writeFileSync(join(real, "docker"), "#!/bin/sh\necho hi\n"); chmodSync(join(real, "docker"), 0o755);
|
|
82
|
+
writeFileSync(join(sh, "docker"), heavyShimScript("docker", join(real, "docker"))); chmodSync(join(sh, "docker"), 0o755);
|
|
83
|
+
assert.equal(checkPathLoop({ env: { PATH: `${sh}:${w}:${real}` } }).ok, true);
|
|
73
84
|
});
|
|
74
85
|
it("passes when a real binary is behind the wrapper", () => {
|
|
75
86
|
const { d, w } = mk(); const real = join(d, "real"); mkdirSync(real); writeFileSync(join(real, "docker"), "#!/bin/sh\necho hi\n"); chmodSync(join(real, "docker"), 0o755);
|