architecture-harness 0.25.0 → 0.26.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/package.json +3 -22
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/branch-sync.mjs +126 -0
- package/src/cli/branch-sync.test.mjs +428 -0
- package/src/cli/budget-guard.mjs +74 -5
- package/src/cli/budget-guard.test.mjs +185 -2
- package/src/cli/budget-report.mjs +85 -0
- package/src/cli/budget-report.test.mjs +173 -0
- package/src/cli/budget.mjs +8 -5
- package/src/cli/check-commands.mjs +123 -11
- package/src/cli/check-commands.test.mjs +360 -6
- package/src/cli/check-feature-switches.test.mjs +110 -0
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check-verdict.mjs +46 -0
- package/src/cli/check-verdict.test.mjs +32 -0
- package/src/cli/check.mjs +137 -4
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/checkpoint.mjs +143 -0
- package/src/cli/checkpoint.test.mjs +146 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +304 -0
- package/src/cli/ci-failures.test.mjs +615 -0
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +25 -29
- package/src/cli/ci-state.test.mjs +174 -2
- package/src/cli/ci-template.test.mjs +86 -0
- package/src/cli/claude-core.test.mjs +37 -0
- package/src/cli/codex-implement.mjs +580 -47
- package/src/cli/codex-implement.test.mjs +1946 -29
- package/src/cli/codex-limit.mjs +85 -0
- package/src/cli/codex-limit.test.mjs +179 -0
- package/src/cli/codex-reset.mjs +78 -0
- package/src/cli/codex-reset.test.mjs +192 -0
- package/src/cli/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +219 -0
- package/src/cli/commit-guard.test.mjs +809 -0
- package/src/cli/context-budgets.mjs +47 -0
- package/src/cli/context-budgets.test.mjs +96 -0
- package/src/cli/context-watch.mjs +116 -0
- package/src/cli/context-watch.test.mjs +395 -0
- package/src/cli/contract-history.mjs +1 -1
- package/src/cli/controller-guard.mjs +38 -0
- package/src/cli/controller-guard.test.mjs +66 -2
- package/src/cli/cost-stop.mjs +5 -1
- package/src/cli/cost-stop.test.mjs +26 -0
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/direct-lane.mjs +32 -19
- package/src/cli/direct-lane.test.mjs +21 -3
- package/src/cli/dispatch-guard.mjs +11 -0
- package/src/cli/dispatch-guard.test.mjs +145 -10
- package/src/cli/dispatch-reminder.mjs +23 -10
- package/src/cli/dispatch-reminder.test.mjs +63 -11
- package/src/cli/dispatch-route.mjs +54 -0
- package/src/cli/dispatch-route.test.mjs +101 -0
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/e2e-affected.mjs +15 -0
- package/src/cli/e2e-affected.test.mjs +73 -0
- package/src/cli/fleet.mjs +180 -0
- package/src/cli/fleet.test.mjs +213 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +96 -31
- package/src/cli/gh-merge-command.test.mjs +74 -0
- package/src/cli/gh-run.mjs +64 -3
- package/src/cli/gh-run.test.mjs +66 -1
- package/src/cli/git-hooks.test.mjs +25 -3
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +143 -40
- package/src/cli/integrate.test.mjs +347 -1
- package/src/cli/integration-lane.mjs +62 -0
- package/src/cli/integration-lane.test.mjs +213 -0
- package/src/cli/ledger.mjs +4 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +70 -0
- package/src/cli/lint-changed.mjs +59 -10
- package/src/cli/lint-changed.test.mjs +112 -1
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +234 -62
- package/src/cli/merge-guard.test.mjs +768 -39
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/output-redaction.mjs +26 -0
- package/src/cli/output-redaction.test.mjs +117 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/pause.mjs +93 -0
- package/src/cli/pause.test.mjs +109 -0
- package/src/cli/plan-check.mjs +84 -12
- package/src/cli/plan-check.test.mjs +152 -2
- package/src/cli/plan-stop.mjs +7 -4
- package/src/cli/plan-stop.test.mjs +87 -0
- package/src/cli/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/plugin-skills.test.mjs +25 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/promotion-branch.mjs +2 -0
- package/src/cli/qc.mjs +160 -27
- package/src/cli/qc.test.mjs +93 -0
- package/src/cli/report-stop.mjs +5 -0
- package/src/cli/report-stop.test.mjs +23 -1
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/review-gate.mjs +24 -6
- package/src/cli/review-gate.test.mjs +116 -0
- package/src/cli/review-promotion.mjs +107 -0
- package/src/cli/review-promotion.test.mjs +251 -0
- package/src/cli/role-budget.mjs +50 -0
- package/src/cli/role-budget.test.mjs +91 -0
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/secret-patterns.mjs +16 -0
- package/src/cli/secret-patterns.test.mjs +73 -0
- package/src/cli/setup-block.mjs +24 -0
- package/src/cli/setup-block.test.mjs +96 -0
- package/src/cli/setup-checks.mjs +65 -0
- package/src/cli/setup-checks.test.mjs +158 -0
- package/src/cli/setup-compaction.mjs +55 -0
- package/src/cli/setup-compaction.test.mjs +115 -0
- package/src/cli/setup-skills.mjs +65 -0
- package/src/cli/setup-skills.test.mjs +171 -0
- package/src/cli/setup.mjs +107 -0
- package/src/cli/setup.test.mjs +275 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/spawn-command.mjs +47 -0
- package/src/cli/spawn-command.test.mjs +64 -0
- package/src/cli/task-gate-review.test.mjs +21 -2
- package/src/cli/task-gate.mjs +25 -12
- package/src/cli/task-gate.test.mjs +43 -5
- package/src/cli/tokens.mjs +46 -3
- package/src/cli/tokens.test.mjs +103 -3
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/transcript-usage.mjs +27 -0
- package/src/cli/transcript-usage.test.mjs +34 -0
- package/src/cli/user-config-package.mjs +1 -1
- package/src/cli/user-config-toml.mjs +63 -7
- package/src/cli/user-config.mjs +39 -7
- package/src/cli/user-config.test.mjs +238 -5
- package/src/cli/watch-arm.mjs +39 -0
- package/src/cli/watch-arm.test.mjs +87 -0
- package/src/cli/watch.mjs +80 -35
- package/src/cli/watch.test.mjs +233 -27
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +18 -4
- package/src/cli/workflow-settings.mjs +44 -8
- package/src/cli/workflow-settings.test.mjs +124 -1
- package/src/cli/worktree.mjs +14 -1
- package/src/cli/worktree.test.mjs +20 -1
- package/src/config.mjs +174 -7
- package/src/config.test.mjs +327 -5
- package/src/consumer-package.mjs +31 -0
- package/src/consumer-package.test.mjs +54 -0
- package/src/descriptions.mjs +2 -0
- package/src/eslint/index.mjs +12 -0
- package/src/eslint/jsx.mjs +20 -0
- package/src/eslint/preset.mjs +26 -2
- package/src/eslint/preset.test.mjs +104 -2
- package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
- package/src/eslint/rules/no-literal-color.mjs +94 -0
- package/src/eslint/rules/no-static-inline-style.mjs +41 -0
- package/src/eslint/rules/one-component-per-file.mjs +70 -0
- package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +189 -0
- package/src/eslint/ui-regressions.test.mjs +39 -0
- package/src/gates/contract-operations.mjs +3 -3
- package/src/gates/contract-operations.test.mjs +28 -0
- package/src/gates/feature-switches.mjs +19 -0
- package/src/gates/feature-switches.test.mjs +55 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/gates/runtime-imports.test.mjs +114 -0
- package/src/gates/saga-key.test.mjs +1 -1
- package/src/global-skills.mjs +9 -0
- package/src/global-skills.test.mjs +53 -0
- package/src/plugin.test.mjs +3 -2
- package/src/ui/class-sites.mjs +38 -6
- package/src/ui/codemod.mjs +4 -1
- package/src/ui/codemod.test.mjs +52 -0
- package/src/ui/components.mjs +5 -3
- package/src/ui/components.test.mjs +8 -0
- package/src/ui/dupes.test.mjs +18 -0
- package/templates/docs/enforcement.md +12 -2
- package/templates/docs/ui.md +33 -0
- package/templates/githooks/pre-commit +1 -0
- package/templates/githooks/pre-push +11 -2
- package/templates/github/workflows/ci.yml +57 -3
- package/user-config/claude/CLAUDE.core.md +28 -0
- package/user-config/claude/settings.shared.json +41 -1
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -84
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -127
- package/src/cli/throwaway-db.test.mjs +0 -83
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -175
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -40
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -137
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -78
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -106
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -40
- package/src/stack/supervisor.mjs +0 -30
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, utimesSync, writeFileSync } from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { checkpointPathOf, checkpointProblem, decide, readCheckpoint } from "./checkpoint.mjs";
|
|
8
|
+
|
|
9
|
+
const text = "## Goal\nKeep my tasks\n## Rules\nKeep constraints\n## Tasks\n- Open: build\n## Next\nBuild it\n";
|
|
10
|
+
function workspace(t) {
|
|
11
|
+
const root = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-checkpoint-")));
|
|
12
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
13
|
+
execFileSync("git", ["init", "-q", root]);
|
|
14
|
+
const file = checkpointPathOf(root, "session-1");
|
|
15
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
16
|
+
return { root, file };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
test("checkpoint path belongs to the common Git directory and contains the session safely", (t) => {
|
|
20
|
+
const { root, file } = workspace(t);
|
|
21
|
+
assert.equal(file, path.join(root, ".git", "qc", "checkpoints", "session-1.md"));
|
|
22
|
+
assert.equal(path.dirname(checkpointPathOf(root, "../../escape")), path.dirname(file));
|
|
23
|
+
const linked = path.join(root, "linked");
|
|
24
|
+
execFileSync("git", ["-c", "user.name=qc", "-c", "user.email=qc@example.com", "-c", "commit.gpgsign=false", "commit", "--allow-empty", "-qm", "init"], { cwd: root });
|
|
25
|
+
execFileSync("git", ["worktree", "add", "-qb", "linked", linked], { cwd: root });
|
|
26
|
+
assert.equal(checkpointPathOf(linked, "session-1"), file);
|
|
27
|
+
assert.notEqual(checkpointPathOf(root, "session-2"), file);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("shape requires exact headings and at most 60 nonblank lines", () => {
|
|
31
|
+
assert.equal(checkpointProblem(text), null);
|
|
32
|
+
for (const heading of ["Goal", "Rules", "Tasks", "Next"]) {
|
|
33
|
+
assert.match(checkpointProblem(text.replace(`## ${heading}`, `### ${heading}`)), /heading/);
|
|
34
|
+
}
|
|
35
|
+
assert.equal(checkpointProblem(text + "\n".repeat(90)), null);
|
|
36
|
+
assert.equal(checkpointProblem(text + "task\n".repeat(52)), null);
|
|
37
|
+
assert.match(checkpointProblem(text + "task\n".repeat(53)), /60/);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("reader reports missing files, invalid shape, and age from modification time", (t) => {
|
|
41
|
+
const { file } = workspace(t);
|
|
42
|
+
assert.match(readCheckpoint(file).problem, /missing/);
|
|
43
|
+
writeFileSync(file, "## Goal\n");
|
|
44
|
+
assert.match(readCheckpoint(file).problem, /heading/);
|
|
45
|
+
writeFileSync(file, text);
|
|
46
|
+
const now = Date.now();
|
|
47
|
+
utimesSync(file, new Date(now - 31 * 60_000), new Date(now - 31 * 60_000));
|
|
48
|
+
assert.match(readCheckpoint(file, { now }).problem, /older/);
|
|
49
|
+
assert.equal(readCheckpoint(file, { now, maxAgeMinutes: 0 }).problem, null);
|
|
50
|
+
assert.equal(readCheckpoint(file, { now, maxAgeMinutes: 32 }).text, text);
|
|
51
|
+
assert.match(readCheckpoint(path.dirname(file)).problem, /read/);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("SessionStart names the absolute checkpoint path even with dispatch off", (t) => {
|
|
55
|
+
const { root, file } = workspace(t);
|
|
56
|
+
writeFileSync(path.join(root, "qc.config.json"), "{}");
|
|
57
|
+
const call = { cwd: root, session_id: "session-1", hook_event_name: "SessionStart", source: "startup" };
|
|
58
|
+
const output = decide(call).hookSpecificOutput;
|
|
59
|
+
assert.equal(output.hookEventName, "SessionStart");
|
|
60
|
+
assert.ok(output.additionalContext.includes(file));
|
|
61
|
+
for (const heading of ["## Goal", "## Rules", "## Tasks", "## Next"]) assert.ok(output.additionalContext.includes(heading));
|
|
62
|
+
assert.match(output.additionalContext, /write/i);
|
|
63
|
+
assert.match(output.additionalContext, /60 non-blank lines/);
|
|
64
|
+
assert.equal(decide({ ...call, agent_id: "worker" }), null);
|
|
65
|
+
assert.equal(decide({ ...call, hook_event_name: "PreToolUse" }), null);
|
|
66
|
+
assert.equal(decide({ ...call, cwd: os.tmpdir() }), null);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("compact and resume restore the checkpoint as the source of truth", (t) => {
|
|
70
|
+
const { root, file } = workspace(t);
|
|
71
|
+
writeFileSync(path.join(root, "qc.config.json"), "{}");
|
|
72
|
+
writeFileSync(file, text);
|
|
73
|
+
const call = { cwd: root, session_id: "session-1", hook_event_name: "SessionStart" };
|
|
74
|
+
for (const source of ["compact", "resume"]) {
|
|
75
|
+
const output = decide({ ...call, source }).hookSpecificOutput.additionalContext;
|
|
76
|
+
assert.ok(output.includes(file));
|
|
77
|
+
assert.match(output, /source of truth for open work/);
|
|
78
|
+
assert.ok(output.includes(text.trim()));
|
|
79
|
+
}
|
|
80
|
+
assert.ok(!decide({ ...call, source: "startup" }).hookSpecificOutput.additionalContext.includes("Keep my tasks"));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("restoration keeps 60 non-blank lines with blank separators", (t) => {
|
|
84
|
+
const { root, file } = workspace(t);
|
|
85
|
+
writeFileSync(path.join(root, "qc.config.json"), "{}");
|
|
86
|
+
const full = text.replace("## Next", "step\n".repeat(52) + "## Next");
|
|
87
|
+
assert.equal(checkpointProblem(full), null);
|
|
88
|
+
writeFileSync(file, full.replaceAll("\n", "\n\n"));
|
|
89
|
+
const note = decide({ cwd: root, session_id: "session-1", hook_event_name: "SessionStart", source: "compact" }).hookSpecificOutput.additionalContext;
|
|
90
|
+
assert.ok(note.endsWith("Build it"));
|
|
91
|
+
assert.doesNotMatch(note, /capped/);
|
|
92
|
+
assert.match(note, /open work\.\n## Goal\n/);
|
|
93
|
+
assert.equal(note.split(/\r?\n/).length, 61);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("restoration caps lines and characters and reports read errors without blocking", (t) => {
|
|
97
|
+
const { root, file } = workspace(t);
|
|
98
|
+
writeFileSync(path.join(root, "qc.config.json"), "{}");
|
|
99
|
+
const call = { cwd: root, session_id: "session-1", hook_event_name: "SessionStart", source: "compact" };
|
|
100
|
+
writeFileSync(file, Array.from({ length: 90 }, (_, n) => `line-${n}`).join("\n"));
|
|
101
|
+
let note = decide(call).hookSpecificOutput.additionalContext;
|
|
102
|
+
assert.ok(note.split(/\r?\n/).length <= 60);
|
|
103
|
+
assert.match(note, /line-57/);
|
|
104
|
+
assert.doesNotMatch(note, /line-58/);
|
|
105
|
+
assert.match(note, /60 lines.*4,000 characters/);
|
|
106
|
+
writeFileSync(file, "x".repeat(9000));
|
|
107
|
+
note = decide(call).hookSpecificOutput.additionalContext;
|
|
108
|
+
assert.ok(note.length <= 4000);
|
|
109
|
+
assert.match(note, /60 lines.*4,000 characters/);
|
|
110
|
+
rmSync(file);
|
|
111
|
+
mkdirSync(file);
|
|
112
|
+
note = decide(call).hookSpecificOutput.additionalContext;
|
|
113
|
+
assert.match(note, /cannot read/);
|
|
114
|
+
assert.ok(note.includes(file));
|
|
115
|
+
assert.equal(decide(call).hookSpecificOutput.permissionDecision, undefined);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("checkpoint has exactly one SessionStart hook", () => {
|
|
119
|
+
const hooks = JSON.parse(readFileSync(new URL("../../../../hooks/hooks.json", import.meta.url), "utf8"));
|
|
120
|
+
const entries = hooks.hooks.SessionStart.flatMap((entry) => entry.hooks).filter((hook) => hook.command.includes("/checkpoint.mjs"));
|
|
121
|
+
assert.equal(entries.length, 1);
|
|
122
|
+
assert.match(hooks.description, /checkpoint/i);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("both orchestrator skills use the session checkpoint and its fixed headings", () => {
|
|
126
|
+
for (const skill of ["codex", "swarm"]) {
|
|
127
|
+
const source = readFileSync(new URL(`../../../../skills/${skill}/SKILL.md`, import.meta.url), "utf8");
|
|
128
|
+
assert.ok(source.includes("<git common dir>/qc/checkpoints/<session_id>.md"), skill);
|
|
129
|
+
for (const heading of ["## Goal", "## Rules", "## Tasks", "## Next"]) assert.ok(source.includes(heading), `${skill}: ${heading}`);
|
|
130
|
+
assert.doesNotMatch(source, /`checkpoint\.md` in the scratchpad/);
|
|
131
|
+
assert.match(source, /60 non-blank lines/);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("the reference and Codex skill document the prompt rule caps and filters", () => {
|
|
136
|
+
for (const file of ["docs/reference.md", "skills/codex/SKILL.md"]) {
|
|
137
|
+
const source = readFileSync(new URL(`../../../../${file}`, import.meta.url), "utf8");
|
|
138
|
+
assert.match(source, /20 `Rule:` lines/);
|
|
139
|
+
assert.match(source, /2,000 characters/);
|
|
140
|
+
assert.match(source, /duplicates after trimming/);
|
|
141
|
+
assert.match(source, /starts with `none:`/);
|
|
142
|
+
}
|
|
143
|
+
const reference = readFileSync(new URL("../../../../docs/reference.md", import.meta.url), "utf8");
|
|
144
|
+
assert.match(reference, /60 non-blank lines/);
|
|
145
|
+
assert.match(reference, /60 lines.*4,000 characters/);
|
|
146
|
+
});
|
package/src/cli/child-run.mjs
CHANGED
|
@@ -3,9 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* One shell command line from argv words, quoted for the shell that `runInShell` starts on `platform`.
|
|
8
|
+
* @throws on Windows when a word holds a line break, because cmd.exe ends the command there
|
|
9
|
+
*/
|
|
10
|
+
export function commandLine(words, platform = process.platform) {
|
|
8
11
|
const args = words[0] === "--" ? words.slice(1) : words;
|
|
12
|
+
if (platform !== "win32") return args.map((arg) => (/^[\w@%+=:,./-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", "'\\''")}'`)).join(" ");
|
|
13
|
+
if (args.some((arg) => /[\r\n]/.test(arg))) throw new Error("cmd.exe cannot pass an argument with a line break; put the commands in a script file and run that file");
|
|
9
14
|
return args.map((arg) => (/^$|[\s"]/.test(arg) ? `"${arg.replaceAll('"', '\\"')}"` : arg)).join(" ");
|
|
10
15
|
}
|
|
11
16
|
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { strict as assert } from "node:assert";
|
|
2
|
+
import { mkdtempSync, readFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
2
5
|
import { test } from "node:test";
|
|
3
6
|
import { commandLine, runInShell, splitAtDashes } from "./child-run.mjs";
|
|
4
7
|
|
|
5
|
-
test("
|
|
6
|
-
|
|
8
|
+
test("each word is quoted for the shell of the platform, and a leading -- is dropped", () => {
|
|
9
|
+
const words = ["--", "pnpm", "vitest", "run", "a b.test.ts", 'say "hi"'];
|
|
10
|
+
assert.equal(commandLine(words, "win32"), 'pnpm vitest run "a b.test.ts" "say \\"hi\\""');
|
|
11
|
+
assert.equal(commandLine(words, "linux"), `pnpm vitest run 'a b.test.ts' 'say "hi"'`);
|
|
12
|
+
assert.equal(commandLine(["bash", "-c", "echo $HOME\necho it's", ""], "linux"), `bash -c 'echo $HOME\necho it'\\''s' ''`);
|
|
13
|
+
assert.throws(() => commandLine(["bash", "-c", "a\nb"], "win32"), /line break/);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("the shell hands each word to the command unchanged", async () => {
|
|
17
|
+
const word = process.platform === "win32" ? `one 'two' $HOME \`x\` "q"` : `line one\nline 'two' $HOME \`x\` "q"`;
|
|
18
|
+
const out = path.join(mkdtempSync(path.join(tmpdir(), "child-run-")), "word.txt");
|
|
19
|
+
const script = `require("node:fs").writeFileSync(process.argv[2], process.argv[1])`;
|
|
20
|
+
assert.equal(await runInShell(commandLine([process.execPath, "-e", script, word, out])), 0);
|
|
21
|
+
assert.equal(readFileSync(out, "utf8"), word);
|
|
7
22
|
});
|
|
8
23
|
|
|
9
24
|
test("argv splits at its first --", () => {
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
// Pipeline: record CI failures and apply the branch's lessons at workflow boundaries.
|
|
2
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
3
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { appendRecord, ledgerFileOf, readLedger, shaMatches } from "./ledger.mjs";
|
|
6
|
+
import { runGhResult } from "./gh-run.mjs";
|
|
7
|
+
import { holdRefusal } from "./pause.mjs";
|
|
8
|
+
import { askIssue } from "./ask.mjs";
|
|
9
|
+
import { load } from "../config.mjs";
|
|
10
|
+
import { isAncestor, originOf, repoOfSpelling } from "./git-read.mjs";
|
|
11
|
+
|
|
12
|
+
const sameHead = (a, b) => a === b || shaMatches(a, b);
|
|
13
|
+
const recordsOf = (root) => {
|
|
14
|
+
const file = ledgerFileOf(root);
|
|
15
|
+
return file ? readLedger(file) : [];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function openFailures(root, branch, repository = originOf(root)) {
|
|
19
|
+
const records = recordsOf(root);
|
|
20
|
+
const origin = originOf(root);
|
|
21
|
+
const resolved = new Set(records.filter((r) => r.type === "ci-resolution" && r.branch === branch).flatMap((r) => r.ids));
|
|
22
|
+
return records.filter((r) => r.type === "ci-failure" && r.branch === branch && (r.repository ?? origin) === repository && !resolved.has(r.id));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function testFile(location) {
|
|
26
|
+
const file = location.replace(/:\d+(?::\d+)?$/, "").replaceAll("\\", "/").replace(/^file:\/\//, "").replace(/^\/([A-Za-z]:\/)/, "$1").replace(/\/{2,}/g, "/");
|
|
27
|
+
return file.replace(/^(?:[A-Za-z]:\/a\/([^/]+)\/(?:\1\/)?|(?:\/home\/runner\/work|\/Users\/runner\/work|\/__w)\/[^/]+\/[^/]+\/)/, "");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function parseFailedLog(log) {
|
|
31
|
+
const jobs = new Map();
|
|
32
|
+
for (const raw of log.split(/\r?\n/)) {
|
|
33
|
+
const fields = raw.split("\t");
|
|
34
|
+
const job = fields.length >= 3 ? fields[0] : "CI job";
|
|
35
|
+
const line = (fields.length >= 3 ? fields.slice(2).join("\t") : raw).replace(/^\S+Z\s+/, "");
|
|
36
|
+
if (!jobs.has(job)) jobs.set(job, []);
|
|
37
|
+
jobs.get(job).push(line);
|
|
38
|
+
}
|
|
39
|
+
const failures = [];
|
|
40
|
+
for (const [job, lines] of jobs) {
|
|
41
|
+
const os = /(?:windows|ubuntu|macos)-[\w.]+/i.exec(job)?.[0] ?? "unknown";
|
|
42
|
+
const start = failures.length;
|
|
43
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
44
|
+
const location = /^\s*test at (.+:\d+(?::\d+)?)\s*$/.exec(lines[i]);
|
|
45
|
+
const match = /^\s*[✖×] (.+?) \([\d.]+m?s\)\s*$/.exec(lines[i + 1] ?? "");
|
|
46
|
+
if (!location || !match) continue;
|
|
47
|
+
const error = lines.slice(i + 2).find((line) => line.trim())?.trim() ?? match[1];
|
|
48
|
+
failures.push({ job, os, test: match[1], file: testFile(location[1]), error });
|
|
49
|
+
}
|
|
50
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
51
|
+
const match = /^\s*not ok \d+ - (.+)/.exec(lines[i]);
|
|
52
|
+
if (!match) continue;
|
|
53
|
+
const details = [];
|
|
54
|
+
for (let j = i + 1; j < lines.length && !/^\s*(?:not ok|ok) \d+ - /.test(lines[j]); j += 1) details.push(lines[j]);
|
|
55
|
+
const block = details.join("\n");
|
|
56
|
+
if (/failureType:\s*['"]?subtestsFailed/.test(block)) continue;
|
|
57
|
+
const location = /^\s*location:\s*['"]?(.*?)['"]?\s*$/m.exec(block)?.[1];
|
|
58
|
+
const errorAt = details.findIndex((line) => /^\s*error:/.test(line));
|
|
59
|
+
const value = errorAt < 0 ? null : details[errorAt].replace(/^\s*error:\s*/, "");
|
|
60
|
+
const error = (value && /^[|>][-+]?\s*$/.test(value)
|
|
61
|
+
? details.slice(errorAt + 1).find((line) => line.trim())?.trim()
|
|
62
|
+
: value?.replace(/^['"]|['"]$/g, "")) ?? lines.find((line) => /error|Error|failed/i.test(line)) ?? match[1];
|
|
63
|
+
failures.push({ job, os, test: match[1].replace(/\s+#.*$/, ""), file: location ? testFile(location) : null, error });
|
|
64
|
+
}
|
|
65
|
+
if (failures.length === start && lines.some((line) => line.trim())) {
|
|
66
|
+
failures.push({ job, os, test: job, file: null, error: lines.find((line) => /error|Error|failed/i.test(line)) ?? lines.find((line) => line.trim()) });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return failures;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function readGh(args, root) {
|
|
73
|
+
const result = runGhResult(args, { cwd: root, timeoutMs: 20_000 });
|
|
74
|
+
if (result.status !== 0) throw new Error(result.stderr?.trim() || result.error?.message || `exit ${result.status}`);
|
|
75
|
+
return result.stdout;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function recordRun(root, { id, branch, head, repository }, { gh = (args) => readGh(args, root), warn = console.error, repo } = {}) {
|
|
79
|
+
const file = ledgerFileOf(root);
|
|
80
|
+
if (!file) return [];
|
|
81
|
+
repository = repoOfSpelling(repository ?? repo ?? originOf(root) ?? "");
|
|
82
|
+
let log;
|
|
83
|
+
try {
|
|
84
|
+
log = gh(["run", "view", String(id), "--log-failed", ...(repo ? ["-R", repo] : [])]);
|
|
85
|
+
if (log === null) throw new Error("no answer");
|
|
86
|
+
} catch (error) {
|
|
87
|
+
warn(`ci-failures: gh failed: ${String(error.message).split(/\r?\n/)[0]}`);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const records = recordsOf(root);
|
|
91
|
+
const added = [];
|
|
92
|
+
for (const failure of parseFailedLog(log)) {
|
|
93
|
+
const key = JSON.stringify([repository, String(id), branch, head, failure.job, failure.file, failure.test]);
|
|
94
|
+
if (records.some((r) => r.type === "ci-failure" && r.id === key)) continue;
|
|
95
|
+
const record = { type: "ci-failure", id: key, run: String(id), repository, branch, head, ...failure };
|
|
96
|
+
appendRecord(file, record);
|
|
97
|
+
added.push(record);
|
|
98
|
+
}
|
|
99
|
+
const failures = openFailures(root, branch, repository);
|
|
100
|
+
const heads = failureHeads(root, branch, { repository }, failures);
|
|
101
|
+
let streakHeads = [];
|
|
102
|
+
const repeated = failures.find((failure) => {
|
|
103
|
+
if (failure.run !== String(id) || !sameHead(failure.head, head)) return false;
|
|
104
|
+
streakHeads = trailingFailureHeads(heads, failure);
|
|
105
|
+
return streakHeads.length >= 3;
|
|
106
|
+
});
|
|
107
|
+
if (repository && repository === originOf(root) && repeated) {
|
|
108
|
+
try {
|
|
109
|
+
const prs = JSON.parse(gh(["api", `repos/${repository}/commits/${head}/pulls`]));
|
|
110
|
+
const reference = /\b(?:refs|close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+(?:([\w.-]+\/[\w.-]+))?#([1-9]\d*)\b/gi;
|
|
111
|
+
const pr = prs.find((pr) => pr.state === "open" && pr.head?.repo?.full_name === repository && pr.head?.ref === branch);
|
|
112
|
+
const issue = [...(pr?.body ?? "").matchAll(reference)]
|
|
113
|
+
.find((match) => !match[1] || match[1].toLowerCase() === repository.toLowerCase())?.[2];
|
|
114
|
+
if (!issue) {
|
|
115
|
+
warn(`ci-failures: no linked issue in the PR for ${branch}; cannot ask about three failing heads`.replace(/[\r\n]+/g, " "));
|
|
116
|
+
} else {
|
|
117
|
+
const marker = `<!-- qc-ci-question:${Buffer.from(branch).toString("base64url")}:${head} -->`;
|
|
118
|
+
const pages = JSON.parse(gh(["api", `repos/${repository}/issues/${issue}/comments`, "--paginate", "--slurp"]));
|
|
119
|
+
if (!Array.isArray(pages) || !pages.every(Array.isArray)) throw new Error("cannot read issue comments");
|
|
120
|
+
const markers = streakHeads.map((sha) => `<!-- qc-ci-question:${Buffer.from(branch).toString("base64url")}:${sha} -->`);
|
|
121
|
+
if (!pages.flat().some((comment) => markers.some((marker) => comment.body?.includes(marker)))) {
|
|
122
|
+
askIssue(issue, `The CI test ${repeated.test} on branch ${branch} has failed on three heads in a row. How should we proceed?\n\n${marker}`, { cwd: root, repo: repository, gh });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
warn(`ci-failures: gh failed: ${String(error.message).split(/\r?\n/)[0]}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return added;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const identity = (r) => JSON.stringify([r.test, r.file, r.os]);
|
|
133
|
+
|
|
134
|
+
function failureHeads(root, branch, failure, failures = openFailures(root, branch, failure.repository ?? originOf(root))) {
|
|
135
|
+
const heads = new Map();
|
|
136
|
+
for (const record of failures) {
|
|
137
|
+
const head = [...heads.keys()].find((head) => sameHead(head, record.head)) ?? record.head;
|
|
138
|
+
if (!heads.has(head)) heads.set(head, new Set());
|
|
139
|
+
heads.get(head).add(identity(record));
|
|
140
|
+
}
|
|
141
|
+
return heads;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function trailingFailureHeads(heads, failure) {
|
|
145
|
+
const trailing = [];
|
|
146
|
+
for (const [head, tests] of [...heads].reverse()) {
|
|
147
|
+
if (!tests.has(identity(failure))) break;
|
|
148
|
+
trailing.push(head);
|
|
149
|
+
}
|
|
150
|
+
return trailing.reverse();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function repeatCount(root, branch, failure) {
|
|
154
|
+
return trailingFailureHeads(failureHeads(root, branch, failure), failure).length;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function section(text, name) {
|
|
158
|
+
const lines = text.split(/\r?\n/);
|
|
159
|
+
const start = lines.findIndex((line) => line.trim() === `## ${name}`);
|
|
160
|
+
if (start < 0) return "";
|
|
161
|
+
const end = lines.findIndex((line, i) => i > start && /^#{1,2}\s/.test(line));
|
|
162
|
+
return lines.slice(start + 1, end < 0 ? undefined : end).join("\n");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function ciBriefRefusal(root, branch, brief) {
|
|
166
|
+
const failures = openFailures(root, branch);
|
|
167
|
+
if (!failures.length) return null;
|
|
168
|
+
const body = section(brief, "CI failures");
|
|
169
|
+
const names = [...new Set(failures.map((r) => r.test))];
|
|
170
|
+
const missing = names.filter((name) => {
|
|
171
|
+
const start = body.indexOf(name);
|
|
172
|
+
if (start < 0) return true;
|
|
173
|
+
const end = Math.min(body.length, ...names.filter((other) => other !== name).map((other) => body.indexOf(other, start + name.length)).filter((i) => i >= 0));
|
|
174
|
+
const next = body.slice(start + name.length, end).split(/\n(?=#{1,3}\s)/)[0];
|
|
175
|
+
return !/^[ \t]*Cause:[ \t]*\S/m.test(next);
|
|
176
|
+
});
|
|
177
|
+
if (missing.length) return `The brief needs ## CI failures with each failed test and a Cause: line: ${missing.join(", ").replace(/[\r\n]+/g, " ")}`;
|
|
178
|
+
if (failures.some((r) => repeatCount(root, branch, r) >= 2)) {
|
|
179
|
+
const diagnosis = section(brief, "Diagnosis");
|
|
180
|
+
if (!/^[ \t]*Root cause:[ \t]*\S/im.test(diagnosis) || !/^[ \t]*Evidence:[ \t]*\S/im.test(diagnosis)) {
|
|
181
|
+
return "The brief needs ## Diagnosis with Root cause: and Evidence: from the log and the code after two failing heads.";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function resolveFailures(root, branch, head, run, repository = originOf(root)) {
|
|
188
|
+
const ids = openFailures(root, branch, repository).filter((r) => !sameHead(r.head, head)
|
|
189
|
+
&& (run === undefined || !/^\d+$/.test(r.run) || BigInt(run) > BigInt(r.run))).map((r) => r.id);
|
|
190
|
+
if (ids.length) appendRecord(ledgerFileOf(root), { type: "ci-resolution", repository, branch, head, run, ids });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function currentBranch(root) {
|
|
194
|
+
return execFileSync("git", ["branch", "--show-current"], { cwd: root, encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function resolvedFailures(root, branch, { merging = false } = {}) {
|
|
198
|
+
const records = recordsOf(root);
|
|
199
|
+
const resolved = new Set(records.filter((r) => r.type === "ci-resolution" && r.branch === branch).flatMap((r) => r.ids));
|
|
200
|
+
const repository = originOf(root);
|
|
201
|
+
const merged = merging || isAncestor(root, branch, load(root).worktree.base) === true;
|
|
202
|
+
return records.filter((r) => r.type === "ci-failure" && r.branch === branch && (r.repository ?? repository) === repository && (resolved.has(r.id) || merged));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function lessonRefusal(root, branch, text, failures = resolvedFailures(root, branch)) {
|
|
206
|
+
const missing = [...new Set(failures.map((r) => r.test))].filter((name) => {
|
|
207
|
+
const body = section(text ?? "", name);
|
|
208
|
+
return ["Symptom", "Cause", "Rule"].some((field) => !new RegExp(`^${field}:[ \\t]*\\S`, "m").test(body));
|
|
209
|
+
});
|
|
210
|
+
return missing.length ? `Merge guard: write a lesson with Symptom:, Cause:, and Rule: for: ${missing.join(", ").replace(/[\r\n]+/g, " ")}` : null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function lessonRules(root, lessons) {
|
|
214
|
+
let text;
|
|
215
|
+
try {
|
|
216
|
+
text = readFileSync(path.resolve(root, lessons.file), "utf8");
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (error.code === "ENOENT") return [];
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
const rules = [];
|
|
222
|
+
const seen = new Set();
|
|
223
|
+
let length = 0;
|
|
224
|
+
for (const line of text.split(/\r?\n/).reverse()) {
|
|
225
|
+
const rule = line.trim();
|
|
226
|
+
if (!/^Rule:\s*\S/.test(rule) || /^Rule:\s*none:/.test(rule) || seen.has(rule)) continue;
|
|
227
|
+
const size = rule.length + (rules.length ? 1 : 0);
|
|
228
|
+
if (rules.length === 20 || length + size > 2000) break;
|
|
229
|
+
rules.push(rule);
|
|
230
|
+
seen.add(rule);
|
|
231
|
+
length += size;
|
|
232
|
+
}
|
|
233
|
+
return rules;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function rerunFailures(root, branch, lessons, { run = (command, options) => spawnSync(command, { ...options, shell: true, stdio: "pipe", encoding: "utf8", maxBuffer: 64 * 1024 * 1024, windowsHide: true }), warn = console.error } = {}) {
|
|
237
|
+
const failures = openFailures(root, branch);
|
|
238
|
+
const files = [];
|
|
239
|
+
const skipped = [];
|
|
240
|
+
try {
|
|
241
|
+
for (const file of new Set(failures.map((r) => r.file).filter(Boolean).map(testFile))) {
|
|
242
|
+
let resolved;
|
|
243
|
+
try {
|
|
244
|
+
resolved = realpathSync(path.resolve(root, file));
|
|
245
|
+
} catch {
|
|
246
|
+
skipped.push(file);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const relative = path.relative(realpathSync(root), resolved);
|
|
250
|
+
if (!/^[\w./ @+-]+$/.test(file) || path.isAbsolute(file) || relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
251
|
+
skipped.push(file);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
files.push(file);
|
|
255
|
+
}
|
|
256
|
+
if (skipped.length) {
|
|
257
|
+
const line = `ci-failures: skip ${skipped.length} test file${skipped.length === 1 ? "" : "s"}: ${skipped.map((file) => JSON.stringify(file)).join(", ")}`;
|
|
258
|
+
warn(line.length <= 200 ? line : `${line.slice(0, 197)}...`);
|
|
259
|
+
}
|
|
260
|
+
if (!files.length) return 0;
|
|
261
|
+
const command = `${lessons.rerun} ${files.map((file) => `"${file}"`).join(" ")}`;
|
|
262
|
+
const result = run(command, { cwd: root });
|
|
263
|
+
if (result.status === 0) return 0;
|
|
264
|
+
const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`;
|
|
265
|
+
const names = [...output.matchAll(/^\s*(?:not ok \d+ - |[\u2716\u00d7] )(.+)/gmu)].map((match) => match[1]);
|
|
266
|
+
for (const name of [...new Set(names.length ? names : failures.filter((r) => r.file && files.includes(testFile(r.file))).map((r) => r.test))].slice(0, skipped.length ? 2 : 3)) {
|
|
267
|
+
warn(`ci-failures: ${String(name).replace(/[\r\n]+/g, " ")}`);
|
|
268
|
+
}
|
|
269
|
+
warn(`Run for full output: ${command}`);
|
|
270
|
+
return result.status ?? 1;
|
|
271
|
+
} catch (error) {
|
|
272
|
+
warn(`ci-failures: cannot rerun: ${String(error.message).split(/\r?\n/)[0]}`);
|
|
273
|
+
return 1;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function runCiFailures(root, argv, { gh = (args) => readGh(args, root), warn = console.error } = {}) {
|
|
278
|
+
if (argv[0] === "--rerun" && (argv.length === 1 || (argv.length === 3 && argv[1] === "--branch" && argv[2]))) {
|
|
279
|
+
try {
|
|
280
|
+
const branch = argv[2] ?? currentBranch(root);
|
|
281
|
+
const hold = branch ? holdRefusal(root, branch) : null;
|
|
282
|
+
if (hold) { warn(hold); return 5; }
|
|
283
|
+
return rerunFailures(root, branch, load(root).lessons, { warn });
|
|
284
|
+
} catch (error) {
|
|
285
|
+
warn(`ci-failures: ${String(error.message).split(/\r?\n/)[0]}`);
|
|
286
|
+
return 1;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (argv.length !== 2 || argv[0] !== "--run" || !/^\d+$/.test(argv[1])) {
|
|
290
|
+
warn("usage: qc ci-failures --run <id> | --rerun [--branch <branch>]");
|
|
291
|
+
return 1;
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
const run = JSON.parse(gh(["api", `repos/{owner}/{repo}/actions/runs/${argv[1]}`]));
|
|
295
|
+
const repository = repoOfSpelling(run.head_repository?.full_name ?? "");
|
|
296
|
+
if (!run.head_branch || !run.head_sha || !repository) throw new Error("run has no branch, head, or head repository");
|
|
297
|
+
if (run.conclusion === "success") resolveFailures(root, run.head_branch, run.head_sha, argv[1], repository);
|
|
298
|
+
else if (recordRun(root, { id: argv[1], branch: run.head_branch, head: run.head_sha, repository }, { gh, warn }) === null) return 1;
|
|
299
|
+
return 0;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
warn(`ci-failures: gh failed: ${String(error.message).split(/\r?\n/)[0]}`);
|
|
302
|
+
return 1;
|
|
303
|
+
}
|
|
304
|
+
}
|