Skip to content

Commit 27d0dca

Browse files
authored
refactor: adopt Node 24 stdlib — AbortSignal.timeout, globSync, parseArgs, error causes (#1125)
Modernization batch: adopt Node 24 stdlib where it deletes code or removes a failure mode, one commit per item. - @types/node pinned to the ^24 line matching engines.node >=24, so Node-26-only APIs fail at compile instead of at deploy; the downgrade surfaced zero incompatible usages. - Six manual controller+timer+clearTimeout scaffolds around single fetches replaced with AbortSignal.timeout, preserving timeout error classification; the generic withTimeout helper and the telemetry Promise.race deadlines intentionally remain (tests require deadlines even when an injected fetch ignores its abort signal). - Five hand-rolled recursive directory walkers replaced with fs.globSync, with ordering, dot-path, closed/** exclusion, symlink, and read-failure behavior preserved and a new validate-all discovery-ordering fixture test. - Seven schema-complete leaf CLIs migrated to node:util parseArgs with exit codes, error messages, -- handling, and repeated options preserved (before/after transcript proof committed); the generic parsers in clawsweeper-args.ts and repair/lib.ts intentionally stay (strict:false unknown-option semantics are not drop-in compatible). - Eight rethrow-without-cause sites now preserve the originating error via cause; eight intentional sanitizer/AggregateError cases documented inline; the preserve-caught-error lint rule (alone, not its category) now guards the class. All gates green locally and in a Docker-backed Crabbox container on the reviewed head with committed receipt.
1 parent d8471a6 commit 27d0dca

39 files changed

Lines changed: 1093 additions & 239 deletions

‎dashboard/github-api.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,12 @@ export async function githubAppInstallationIdAsPlainError(appJwt, repo, env = {}
123123
}
124124

125125
export async function githubAppJson(path, appJwt, options: GithubAppJsonOptions = {}, env = {}) {
126-
const controller = new AbortController();
127-
const timeout = setTimeout(() => controller.abort("timeout"), GITHUB_APP_TIMEOUT_MS);
126+
const signal = AbortSignal.timeout(GITHUB_APP_TIMEOUT_MS);
128127
let response: Response;
129128
try {
130129
response = await fetch(githubApiUrl(env, path), {
131130
method: options.method || "GET",
132-
signal: controller.signal,
131+
signal,
133132
headers: {
134133
Accept: "application/vnd.github+json",
135134
"Content-Type": "application/json",
@@ -140,17 +139,15 @@ export async function githubAppJson(path, appJwt, options: GithubAppJsonOptions
140139
});
141140
} catch (error) {
142141
const timedOut =
143-
controller.signal.aborted ||
142+
signal.aborted ||
144143
(error instanceof Error && (error.name === "AbortError" || error.message === "timeout"));
145144
const requestError = new GitHubRequestError(
146145
`${options.errorLabel || "GitHub App"} ${timedOut ? "timed out" : "network failure"}`,
147146
undefined,
148147
timedOut,
149148
);
150-
if (!controller.signal.aborted) workerTransportErrors.set(requestError, error);
149+
if (!signal.aborted) workerTransportErrors.set(requestError, error);
151150
throw requestError;
152-
} finally {
153-
clearTimeout(timeout);
154151
}
155152
if (!response.ok) {
156153
const text = await response.text().catch(() => "");

‎dashboard/worker.ts‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,11 +2996,9 @@ async function sha256Text(value) {
29962996
}
29972997

29982998
async function githubTokenJson({ env = {}, token, path, method = "GET", body, errorLabel }) {
2999-
const controller = new AbortController();
3000-
const timeout = setTimeout(() => controller.abort("timeout"), GITHUB_TIMEOUT_MS);
30012999
const init: RequestInit = {
30023000
method,
3003-
signal: controller.signal,
3001+
signal: AbortSignal.timeout(GITHUB_TIMEOUT_MS),
30043002
headers: {
30053003
Accept: "application/vnd.github+json",
30063004
"Content-Type": "application/json",
@@ -3009,7 +3007,7 @@ async function githubTokenJson({ env = {}, token, path, method = "GET", body, er
30093007
},
30103008
};
30113009
if (body !== undefined) init.body = JSON.stringify(body);
3012-
const response = await fetch(githubApiUrl(env, path), init).finally(() => clearTimeout(timeout));
3010+
const response = await fetch(githubApiUrl(env, path), init);
30133011
if (!response.ok) {
30143012
const text = await response.text().catch(() => "");
30153013
throw new Error(
@@ -6995,36 +6993,32 @@ function createGithubJsonCache(env): GithubJsonReader {
69956993

69966994
async function githubJson(env, path) {
69976995
const token = await githubAuthToken(env);
6998-
const controller = new AbortController();
6999-
const timeout = setTimeout(() => controller.abort("timeout"), GITHUB_TIMEOUT_MS);
70006996
const response = await fetch(githubApiUrl(env, path), {
7001-
signal: controller.signal,
6997+
signal: AbortSignal.timeout(GITHUB_TIMEOUT_MS),
70026998
headers: {
70036999
Accept: "application/vnd.github+json",
70047000
"User-Agent": "openclaw-clawsweeper-status",
70057001
...(token ? { Authorization: `Bearer ${token}` } : {}),
70067002
},
7007-
}).finally(() => clearTimeout(timeout));
7003+
});
70087004
if (!response.ok) throw new Error(`GitHub ${response.status} for ${path}`);
70097005
return response.json();
70107006
}
70117007

70127008
async function githubGraphql(env, query, variables) {
70137009
const token = await githubAuthToken(env);
70147010
if (!token) throw new Error("GitHub auth is required for GraphQL");
7015-
const controller = new AbortController();
7016-
const timeout = setTimeout(() => controller.abort("timeout"), OPTIONAL_SECTION_TIMEOUT_MS);
70177011
const response = await fetch(githubApiUrl(env, "/graphql"), {
70187012
method: "POST",
7019-
signal: controller.signal,
7013+
signal: AbortSignal.timeout(OPTIONAL_SECTION_TIMEOUT_MS),
70207014
headers: {
70217015
Accept: "application/vnd.github+json",
70227016
"Content-Type": "application/json",
70237017
"User-Agent": "openclaw-clawsweeper-status",
70247018
Authorization: `Bearer ${token}`,
70257019
},
70267020
body: JSON.stringify({ query, variables }),
7027-
}).finally(() => clearTimeout(timeout));
7021+
});
70287022
if (!response.ok) throw new Error(`GitHub GraphQL ${response.status}`);
70297023
const payload = await response.json();
70307024
if (Array.isArray(payload.errors) && payload.errors.length) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Modernize stdlib batch proof
2+
3+
This proof covers the behavior-preserving Node standard-library migration in this batch. It keeps the current CLI contracts—including exit codes, custom error strings, ignored `--` delimiters, and repeated scalar/array options—while requiring all seven leaf parsers to use `node:util` `parseArgs` with complete schemas.
4+
5+
Run from the repository root:
6+
7+
```sh
8+
bash docs/proof/modernize-stdlib-batch/run-proof.sh origin/main
9+
```
10+
11+
The red check extracts each parser from `origin/main` and fails because none of the seven files has adopted the stdlib parser. The green check inspects the working tree and requires the stdlib import in every migrated CLI. The committed [red log](artifacts/adoption-red.log) and [green log](artifacts/adoption-green.log) retain those outcomes.
12+
13+
For behavioral equivalence, the harness extracts the old `scripts/e2e/automerge.mjs` with `git show`, supplies its repository-relative fixture imports, and runs the same argv matrix through old and new sources: help, an ignored `--` delimiter, a repeated scalar option, an unknown option, and a missing value. It records exit status, stdout, and the semantic error line (excluding source-location-only stack frames). The [before transcript](artifacts/cli-before.txt) and [after transcript](artifacts/cli-after.txt) are byte-identical; [their diff](artifacts/cli-transcript.diff) is empty.
14+
15+
The controlled proof is local, read-only apart from its own artifacts, and uses no credentials or network calls. It does not exercise the migrated commands' external GitHub, Worker, Git, or Docker operations. Fresh pushed-head container provenance belongs in the pull request's `pr-behavior-proof` section.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
adopted src/repair/action-ledger-cli.ts
2+
adopted src/repair/publish-main.ts
3+
adopted src/repair/collect-codex-debug.ts
4+
adopted scripts/exact-review-dead-letter-operator.mjs
5+
adopted scripts/hydrate-state.ts
6+
adopted scripts/e2e/automerge.mjs
7+
adopted scripts/e2e/automerge-container.mjs
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
missing src/repair/action-ledger-cli.ts
2+
missing src/repair/publish-main.ts
3+
missing src/repair/collect-codex-debug.ts
4+
missing scripts/exact-review-dead-letter-operator.mjs
5+
missing scripts/hydrate-state.ts
6+
missing scripts/e2e/automerge.mjs
7+
missing scripts/e2e/automerge-container.mjs
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
case=help
2+
argv= --help
3+
exit=0
4+
stdout<<EOF
5+
Usage:
6+
node scripts/e2e/automerge.mjs [options]
7+
8+
Description:
9+
Runs the production automerge planner, executor, publisher, applicator, and
10+
exact-head comment-router merger against stateful GitHub/Codex simulators and
11+
a real local Git remote.
12+
13+
Options:
14+
--scenario <name> Scenario to run; use all for the full suite
15+
(default: happy-path)
16+
--fixture <name> tiny, openclaw-shaped, or all (default: tiny)
17+
--expect <outcome> success or setup-identity-failure (default: success);
18+
failure proof supports the historical regression and
19+
openclaw-shaped happy-path
20+
--list-scenarios Print supported scenario names
21+
--list-fixtures Print supported target fixture names
22+
--candidate-root <dir> Built ClawSweeper checkout to validate (default: cwd)
23+
--output <dir> Failure and proof artifact root
24+
--keep Keep the temporary scenario workspace
25+
-h, --help Show this help
26+
27+
Outputs:
28+
<output>/<fixture>/<scenario>/summary.json and one stdout/stderr log per production step.
29+
Exit code 0 means all terminal-state and token-boundary assertions passed.
30+
31+
Examples:
32+
pnpm e2e:automerge
33+
pnpm e2e:automerge -- --scenario all --fixture all --output test-results/automerge
34+
pnpm e2e:automerge -- --scenario ci-regression-29623139111 --candidate-root ../clawsweeper-ci-regression --expect setup-identity-failure
35+
pnpm e2e:automerge -- --scenario happy-path --fixture openclaw-shaped --candidate-root ../clawsweeper-before-fix --expect setup-identity-failure
36+
EOF
37+
stderr_contract<<EOF
38+
EOF
39+
case=separator-help
40+
argv= -- --help
41+
exit=0
42+
stdout<<EOF
43+
Usage:
44+
node scripts/e2e/automerge.mjs [options]
45+
46+
Description:
47+
Runs the production automerge planner, executor, publisher, applicator, and
48+
exact-head comment-router merger against stateful GitHub/Codex simulators and
49+
a real local Git remote.
50+
51+
Options:
52+
--scenario <name> Scenario to run; use all for the full suite
53+
(default: happy-path)
54+
--fixture <name> tiny, openclaw-shaped, or all (default: tiny)
55+
--expect <outcome> success or setup-identity-failure (default: success);
56+
failure proof supports the historical regression and
57+
openclaw-shaped happy-path
58+
--list-scenarios Print supported scenario names
59+
--list-fixtures Print supported target fixture names
60+
--candidate-root <dir> Built ClawSweeper checkout to validate (default: cwd)
61+
--output <dir> Failure and proof artifact root
62+
--keep Keep the temporary scenario workspace
63+
-h, --help Show this help
64+
65+
Outputs:
66+
<output>/<fixture>/<scenario>/summary.json and one stdout/stderr log per production step.
67+
Exit code 0 means all terminal-state and token-boundary assertions passed.
68+
69+
Examples:
70+
pnpm e2e:automerge
71+
pnpm e2e:automerge -- --scenario all --fixture all --output test-results/automerge
72+
pnpm e2e:automerge -- --scenario ci-regression-29623139111 --candidate-root ../clawsweeper-ci-regression --expect setup-identity-failure
73+
pnpm e2e:automerge -- --scenario happy-path --fixture openclaw-shaped --candidate-root ../clawsweeper-before-fix --expect setup-identity-failure
74+
EOF
75+
stderr_contract<<EOF
76+
EOF
77+
case=repeated-help
78+
argv= --scenario first --scenario second --help
79+
exit=0
80+
stdout<<EOF
81+
Usage:
82+
node scripts/e2e/automerge.mjs [options]
83+
84+
Description:
85+
Runs the production automerge planner, executor, publisher, applicator, and
86+
exact-head comment-router merger against stateful GitHub/Codex simulators and
87+
a real local Git remote.
88+
89+
Options:
90+
--scenario <name> Scenario to run; use all for the full suite
91+
(default: happy-path)
92+
--fixture <name> tiny, openclaw-shaped, or all (default: tiny)
93+
--expect <outcome> success or setup-identity-failure (default: success);
94+
failure proof supports the historical regression and
95+
openclaw-shaped happy-path
96+
--list-scenarios Print supported scenario names
97+
--list-fixtures Print supported target fixture names
98+
--candidate-root <dir> Built ClawSweeper checkout to validate (default: cwd)
99+
--output <dir> Failure and proof artifact root
100+
--keep Keep the temporary scenario workspace
101+
-h, --help Show this help
102+
103+
Outputs:
104+
<output>/<fixture>/<scenario>/summary.json and one stdout/stderr log per production step.
105+
Exit code 0 means all terminal-state and token-boundary assertions passed.
106+
107+
Examples:
108+
pnpm e2e:automerge
109+
pnpm e2e:automerge -- --scenario all --fixture all --output test-results/automerge
110+
pnpm e2e:automerge -- --scenario ci-regression-29623139111 --candidate-root ../clawsweeper-ci-regression --expect setup-identity-failure
111+
pnpm e2e:automerge -- --scenario happy-path --fixture openclaw-shaped --candidate-root ../clawsweeper-before-fix --expect setup-identity-failure
112+
EOF
113+
stderr_contract<<EOF
114+
EOF
115+
case=unknown
116+
argv= --unknown
117+
exit=1
118+
stdout<<EOF
119+
EOF
120+
stderr_contract<<EOF
121+
Error: unknown option: --unknown; use --help for usage
122+
EOF
123+
case=missing-value
124+
argv= --scenario
125+
exit=1
126+
stdout<<EOF
127+
EOF
128+
stderr_contract<<EOF
129+
Error: --scenario requires a value
130+
EOF
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
case=help
2+
argv= --help
3+
exit=0
4+
stdout<<EOF
5+
Usage:
6+
node scripts/e2e/automerge.mjs [options]
7+
8+
Description:
9+
Runs the production automerge planner, executor, publisher, applicator, and
10+
exact-head comment-router merger against stateful GitHub/Codex simulators and
11+
a real local Git remote.
12+
13+
Options:
14+
--scenario <name> Scenario to run; use all for the full suite
15+
(default: happy-path)
16+
--fixture <name> tiny, openclaw-shaped, or all (default: tiny)
17+
--expect <outcome> success or setup-identity-failure (default: success);
18+
failure proof supports the historical regression and
19+
openclaw-shaped happy-path
20+
--list-scenarios Print supported scenario names
21+
--list-fixtures Print supported target fixture names
22+
--candidate-root <dir> Built ClawSweeper checkout to validate (default: cwd)
23+
--output <dir> Failure and proof artifact root
24+
--keep Keep the temporary scenario workspace
25+
-h, --help Show this help
26+
27+
Outputs:
28+
<output>/<fixture>/<scenario>/summary.json and one stdout/stderr log per production step.
29+
Exit code 0 means all terminal-state and token-boundary assertions passed.
30+
31+
Examples:
32+
pnpm e2e:automerge
33+
pnpm e2e:automerge -- --scenario all --fixture all --output test-results/automerge
34+
pnpm e2e:automerge -- --scenario ci-regression-29623139111 --candidate-root ../clawsweeper-ci-regression --expect setup-identity-failure
35+
pnpm e2e:automerge -- --scenario happy-path --fixture openclaw-shaped --candidate-root ../clawsweeper-before-fix --expect setup-identity-failure
36+
EOF
37+
stderr_contract<<EOF
38+
EOF
39+
case=separator-help
40+
argv= -- --help
41+
exit=0
42+
stdout<<EOF
43+
Usage:
44+
node scripts/e2e/automerge.mjs [options]
45+
46+
Description:
47+
Runs the production automerge planner, executor, publisher, applicator, and
48+
exact-head comment-router merger against stateful GitHub/Codex simulators and
49+
a real local Git remote.
50+
51+
Options:
52+
--scenario <name> Scenario to run; use all for the full suite
53+
(default: happy-path)
54+
--fixture <name> tiny, openclaw-shaped, or all (default: tiny)
55+
--expect <outcome> success or setup-identity-failure (default: success);
56+
failure proof supports the historical regression and
57+
openclaw-shaped happy-path
58+
--list-scenarios Print supported scenario names
59+
--list-fixtures Print supported target fixture names
60+
--candidate-root <dir> Built ClawSweeper checkout to validate (default: cwd)
61+
--output <dir> Failure and proof artifact root
62+
--keep Keep the temporary scenario workspace
63+
-h, --help Show this help
64+
65+
Outputs:
66+
<output>/<fixture>/<scenario>/summary.json and one stdout/stderr log per production step.
67+
Exit code 0 means all terminal-state and token-boundary assertions passed.
68+
69+
Examples:
70+
pnpm e2e:automerge
71+
pnpm e2e:automerge -- --scenario all --fixture all --output test-results/automerge
72+
pnpm e2e:automerge -- --scenario ci-regression-29623139111 --candidate-root ../clawsweeper-ci-regression --expect setup-identity-failure
73+
pnpm e2e:automerge -- --scenario happy-path --fixture openclaw-shaped --candidate-root ../clawsweeper-before-fix --expect setup-identity-failure
74+
EOF
75+
stderr_contract<<EOF
76+
EOF
77+
case=repeated-help
78+
argv= --scenario first --scenario second --help
79+
exit=0
80+
stdout<<EOF
81+
Usage:
82+
node scripts/e2e/automerge.mjs [options]
83+
84+
Description:
85+
Runs the production automerge planner, executor, publisher, applicator, and
86+
exact-head comment-router merger against stateful GitHub/Codex simulators and
87+
a real local Git remote.
88+
89+
Options:
90+
--scenario <name> Scenario to run; use all for the full suite
91+
(default: happy-path)
92+
--fixture <name> tiny, openclaw-shaped, or all (default: tiny)
93+
--expect <outcome> success or setup-identity-failure (default: success);
94+
failure proof supports the historical regression and
95+
openclaw-shaped happy-path
96+
--list-scenarios Print supported scenario names
97+
--list-fixtures Print supported target fixture names
98+
--candidate-root <dir> Built ClawSweeper checkout to validate (default: cwd)
99+
--output <dir> Failure and proof artifact root
100+
--keep Keep the temporary scenario workspace
101+
-h, --help Show this help
102+
103+
Outputs:
104+
<output>/<fixture>/<scenario>/summary.json and one stdout/stderr log per production step.
105+
Exit code 0 means all terminal-state and token-boundary assertions passed.
106+
107+
Examples:
108+
pnpm e2e:automerge
109+
pnpm e2e:automerge -- --scenario all --fixture all --output test-results/automerge
110+
pnpm e2e:automerge -- --scenario ci-regression-29623139111 --candidate-root ../clawsweeper-ci-regression --expect setup-identity-failure
111+
pnpm e2e:automerge -- --scenario happy-path --fixture openclaw-shaped --candidate-root ../clawsweeper-before-fix --expect setup-identity-failure
112+
EOF
113+
stderr_contract<<EOF
114+
EOF
115+
case=unknown
116+
argv= --unknown
117+
exit=1
118+
stdout<<EOF
119+
EOF
120+
stderr_contract<<EOF
121+
Error: unknown option: --unknown; use --help for usage
122+
EOF
123+
case=missing-value
124+
argv= --scenario
125+
exit=1
126+
stdout<<EOF
127+
EOF
128+
stderr_contract<<EOF
129+
Error: --scenario requires a value
130+
EOF

‎docs/proof/modernize-stdlib-batch/artifacts/cli-transcript.diff‎

Whitespace-only changes.

0 commit comments

Comments
 (0)