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,171 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import { dropPersonalSkills } from "./setup-skills.mjs";
|
|
7
|
+
|
|
8
|
+
const pluginKey = "architecture@architecture-kit";
|
|
9
|
+
const name = "registering-work";
|
|
10
|
+
|
|
11
|
+
function fixture(t) {
|
|
12
|
+
const claudeDir = mkdtempSync(join(tmpdir(), "qc-setup-skills-"));
|
|
13
|
+
t.after(() => rmSync(claudeDir, { recursive: true, force: true }));
|
|
14
|
+
const installPath = join(claudeDir, "plugins", "cache", "architecture");
|
|
15
|
+
const folder = join(claudeDir, "skills", name);
|
|
16
|
+
const pluginFolder = join(installPath, "skills", name);
|
|
17
|
+
mkdirSync(folder, { recursive: true });
|
|
18
|
+
mkdirSync(pluginFolder, { recursive: true });
|
|
19
|
+
writeFileSync(join(folder, "SKILL.md"), "# Register work\n");
|
|
20
|
+
writeFileSync(join(pluginFolder, "SKILL.md"), "# Register work\n");
|
|
21
|
+
const registryPath = join(claudeDir, "plugins", "installed_plugins.json");
|
|
22
|
+
const entries = [{ scope: "user", installPath, version: "1.0.0" }];
|
|
23
|
+
writeFileSync(registryPath, JSON.stringify({ version: 2, plugins: { [pluginKey]: entries } }));
|
|
24
|
+
return {
|
|
25
|
+
claudeDir, folder, pluginFolder, registryPath, entries,
|
|
26
|
+
options: {
|
|
27
|
+
claudeDir,
|
|
28
|
+
settingsText: JSON.stringify({ enabledPlugins: { [pluginKey]: true } }),
|
|
29
|
+
names: [name],
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function assertKept(f, reason, options = f.options) {
|
|
35
|
+
assert.deepEqual(dropPersonalSkills(options), {
|
|
36
|
+
removed: [], kept: [{ name, reason }],
|
|
37
|
+
});
|
|
38
|
+
assert.equal(existsSync(f.folder), true);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
test("removes an identical personal skill after the plugin loads", (t) => {
|
|
42
|
+
const f = fixture(t);
|
|
43
|
+
assert.deepEqual(dropPersonalSkills(f.options), { removed: [f.folder], kept: [] });
|
|
44
|
+
assert.equal(existsSync(f.folder), false);
|
|
45
|
+
assert.equal(existsSync(join(f.pluginFolder, "SKILL.md")), true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("keeps a personal skill when the plugin is not enabled", (t) => {
|
|
49
|
+
const f = fixture(t);
|
|
50
|
+
rmSync(join(f.pluginFolder, "SKILL.md"));
|
|
51
|
+
assertKept(f, "the plugin is not enabled", { ...f.options, settingsText: "{}" });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("requires the enabled plugin setting to equal true", (t) => {
|
|
55
|
+
const f = fixture(t);
|
|
56
|
+
for (const enabled of [false, "true", 1]) {
|
|
57
|
+
assertKept(f, "the plugin is not enabled", {
|
|
58
|
+
...f.options, settingsText: JSON.stringify({ enabledPlugins: { [pluginKey]: enabled } }),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("treats invalid settings JSON as a disabled plugin", (t) => {
|
|
64
|
+
const f = fixture(t);
|
|
65
|
+
assertKept(f, "the plugin is not enabled", { ...f.options, settingsText: "not JSON" });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("keeps a personal skill when the plugin copy is missing", (t) => {
|
|
69
|
+
const f = fixture(t);
|
|
70
|
+
rmSync(join(f.pluginFolder, "SKILL.md"));
|
|
71
|
+
writeFileSync(join(f.folder, "notes.txt"), "Keep this file\n");
|
|
72
|
+
assertKept(f, "the plugin copy is not installed");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("treats a missing plugin registry as a missing installation", (t) => {
|
|
76
|
+
const f = fixture(t);
|
|
77
|
+
rmSync(f.registryPath);
|
|
78
|
+
assertKept(f, "the plugin copy is not installed");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("treats invalid plugin registry JSON as a missing installation", (t) => {
|
|
82
|
+
const f = fixture(t);
|
|
83
|
+
writeFileSync(f.registryPath, "not JSON");
|
|
84
|
+
assertKept(f, "the plugin copy is not installed");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("treats a plugin registry read error as a missing installation", (t) => {
|
|
88
|
+
const f = fixture(t);
|
|
89
|
+
rmSync(f.registryPath);
|
|
90
|
+
mkdirSync(f.registryPath);
|
|
91
|
+
assertKept(f, "the plugin copy is not installed");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("keeps a personal skill that differs before checking its other files", (t) => {
|
|
95
|
+
const f = fixture(t);
|
|
96
|
+
writeFileSync(join(f.folder, "SKILL.md"), "# Personal changes\n");
|
|
97
|
+
writeFileSync(join(f.folder, "notes.txt"), "Keep this file\n");
|
|
98
|
+
assertKept(f, "it differs from the plugin copy");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("compares bytes that decode to the same text", (t) => {
|
|
102
|
+
const f = fixture(t);
|
|
103
|
+
writeFileSync(join(f.folder, "SKILL.md"), Buffer.from([0x80]));
|
|
104
|
+
writeFileSync(join(f.pluginFolder, "SKILL.md"), Buffer.from([0x81]));
|
|
105
|
+
assertKept(f, "it differs from the plugin copy");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("keeps an identical personal skill with another file", (t) => {
|
|
109
|
+
const f = fixture(t);
|
|
110
|
+
writeFileSync(join(f.folder, "notes.txt"), "Keep this file\n");
|
|
111
|
+
assertKept(f, "it holds files besides SKILL.md");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("keeps an identical personal skill with another directory", (t) => {
|
|
115
|
+
const f = fixture(t);
|
|
116
|
+
mkdirSync(join(f.folder, "references"));
|
|
117
|
+
assertKept(f, "it holds files besides SKILL.md");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("a dry run lists the personal folder and leaves it on disk", (t) => {
|
|
121
|
+
const f = fixture(t);
|
|
122
|
+
assert.deepEqual(dropPersonalSkills({ ...f.options, dryRun: true }), {
|
|
123
|
+
removed: [f.folder], kept: [],
|
|
124
|
+
});
|
|
125
|
+
assert.equal(existsSync(join(f.folder, "SKILL.md")), true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("skips a name with no personal folder", (t) => {
|
|
129
|
+
const f = fixture(t);
|
|
130
|
+
assert.deepEqual(dropPersonalSkills({ ...f.options, names: ["absent-skill"] }), {
|
|
131
|
+
removed: [], kept: [],
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("skips a personal folder without SKILL.md", (t) => {
|
|
136
|
+
const f = fixture(t);
|
|
137
|
+
rmSync(join(f.folder, "SKILL.md"));
|
|
138
|
+
assert.deepEqual(dropPersonalSkills(f.options), { removed: [], kept: [] });
|
|
139
|
+
assert.equal(existsSync(f.folder), true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("finds a user installation after a project entry with a missing copy", (t) => {
|
|
143
|
+
const f = fixture(t);
|
|
144
|
+
writeFileSync(f.registryPath, JSON.stringify({
|
|
145
|
+
version: 2,
|
|
146
|
+
plugins: {
|
|
147
|
+
[pluginKey]: [
|
|
148
|
+
{ scope: "project", installPath: join(f.claudeDir, "missing"), version: "1.0.0" },
|
|
149
|
+
...f.entries,
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
}));
|
|
153
|
+
assert.deepEqual(dropPersonalSkills(f.options), { removed: [f.folder], kept: [] });
|
|
154
|
+
assert.equal(existsSync(f.folder), false);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("processes the supplied names in order", (t) => {
|
|
158
|
+
const f = fixture(t);
|
|
159
|
+
const second = "writing-plain-english";
|
|
160
|
+
const secondFolder = join(f.claudeDir, "skills", second);
|
|
161
|
+
const secondPluginFolder = join(f.entries[0].installPath, "skills", second);
|
|
162
|
+
mkdirSync(secondFolder, { recursive: true });
|
|
163
|
+
mkdirSync(secondPluginFolder, { recursive: true });
|
|
164
|
+
writeFileSync(join(secondFolder, "SKILL.md"), "# Plain English\n");
|
|
165
|
+
writeFileSync(join(secondPluginFolder, "SKILL.md"), "# Plain English\n");
|
|
166
|
+
assert.deepEqual(dropPersonalSkills({ ...f.options, names: [second, "absent-skill", name] }), {
|
|
167
|
+
removed: [secondFolder, f.folder], kept: [],
|
|
168
|
+
});
|
|
169
|
+
assert.equal(existsSync(secondFolder), false);
|
|
170
|
+
assert.equal(existsSync(f.folder), false);
|
|
171
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { GLOBAL_SKILLS } from "../global-skills.mjs";
|
|
6
|
+
import { applyBlock } from "./setup-block.mjs";
|
|
7
|
+
import { checkTools, personSteps } from "./setup-checks.mjs";
|
|
8
|
+
import { budgetsOf, compactClaude, compactCodex } from "./setup-compaction.mjs";
|
|
9
|
+
import { dropPersonalSkills } from "./setup-skills.mjs";
|
|
10
|
+
import { assertSafePath, backupFile, configPaths, kitUserConfigDir } from "./user-config.mjs";
|
|
11
|
+
|
|
12
|
+
/** Resource: read a safe file or use its default when it is absent. */
|
|
13
|
+
function read(file, fallback) {
|
|
14
|
+
assertSafePath(file);
|
|
15
|
+
try {
|
|
16
|
+
assertSafePath(realpathSync(file));
|
|
17
|
+
if (!statSync(file).isFile()) throw new Error(`Expected a regular file: ${file}`);
|
|
18
|
+
return readFileSync(file, "utf8");
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (error.code === "ENOENT" && fallback !== undefined) return fallback;
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Resource: validate personal copies of the kit's global skills. */
|
|
26
|
+
function skillNames(claudeDir) {
|
|
27
|
+
const root = path.join(claudeDir, "skills");
|
|
28
|
+
if (!existsSync(root)) return [];
|
|
29
|
+
const resolvedRoot = realpathSync(root);
|
|
30
|
+
return GLOBAL_SKILLS.filter((name) => existsSync(path.join(root, name))).map((name) => {
|
|
31
|
+
const folder = path.join(root, name);
|
|
32
|
+
const relative = path.relative(resolvedRoot, realpathSync(folder));
|
|
33
|
+
if (relative.startsWith(`..${path.sep}`) || relative === ".." || path.isAbsolute(relative)) {
|
|
34
|
+
throw new Error(`Skill folder leaves the skills directory: ${folder}`);
|
|
35
|
+
}
|
|
36
|
+
assertSafePath(folder);
|
|
37
|
+
const skill = path.join(folder, "SKILL.md");
|
|
38
|
+
if (existsSync(skill)) read(skill);
|
|
39
|
+
return name;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Pipeline: plan user setup, then apply changes after all checks pass. */
|
|
44
|
+
export async function runSetup(args, options = {}) {
|
|
45
|
+
const log = options.log ?? console.log;
|
|
46
|
+
try {
|
|
47
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: {
|
|
48
|
+
"dry-run": { type: "boolean" }, config: { type: "string" }, model: { type: "string", multiple: true },
|
|
49
|
+
} });
|
|
50
|
+
if (positionals.length) throw new Error("Usage: qc setup [--dry-run] [--config <file>] [--model <id>]...");
|
|
51
|
+
const home = options.home ?? os.homedir();
|
|
52
|
+
const paths = configPaths(home, options.env ?? process.env);
|
|
53
|
+
const claudeDir = path.dirname(paths.claude);
|
|
54
|
+
const codexDir = path.dirname(paths.codex);
|
|
55
|
+
const cwd = options.cwd ?? process.cwd();
|
|
56
|
+
const config = path.resolve(cwd, values.config ?? "qc.config.json");
|
|
57
|
+
const configText = read(config, null);
|
|
58
|
+
if (values.config && configText === null) console.error(`qc setup: config file not found: ${config}; skipping budgets.`);
|
|
59
|
+
const budgets = budgetsOf(configText);
|
|
60
|
+
const claude = compactClaude(read(paths.claude, "{}"), { models: values.model ?? [], window: budgets.orchestrator });
|
|
61
|
+
const codex = compactCodex(read(paths.codex, ""), budgets.codex);
|
|
62
|
+
const coreFile = path.join(claudeDir, "CLAUDE.md");
|
|
63
|
+
const template = path.join(options.kitDir ?? kitUserConfigDir(), "claude", "CLAUDE.core.md");
|
|
64
|
+
const core = applyBlock(read(coreFile, ""), read(template));
|
|
65
|
+
const plans = [
|
|
66
|
+
{ file: paths.claude, ...claude },
|
|
67
|
+
{ file: paths.codex, ...codex },
|
|
68
|
+
{ file: coreFile, text: core.text, changed: core.changed ? ["core"] : [] },
|
|
69
|
+
].filter((plan) => plan.changed.length);
|
|
70
|
+
const skillsOptions = { claudeDir, settingsText: claude.text, names: skillNames(claudeDir) };
|
|
71
|
+
const skills = dropPersonalSkills({ ...skillsOptions, dryRun: true });
|
|
72
|
+
const tools = checkTools(options.run);
|
|
73
|
+
const steps = personSteps({ tools, home, codexDir, run: options.run, exists: options.exists });
|
|
74
|
+
if (budgets.orchestrator !== null && !values.model?.length) {
|
|
75
|
+
steps.push("Run `qc setup --model <id>` to set the Claude compaction window");
|
|
76
|
+
}
|
|
77
|
+
for (const kept of skills.kept) steps.push(`Check ${path.join(claudeDir, "skills", kept.name)}: ${kept.reason}`);
|
|
78
|
+
|
|
79
|
+
if (!values["dry-run"]) {
|
|
80
|
+
const now = options.now ?? new Date();
|
|
81
|
+
for (const plan of plans) {
|
|
82
|
+
assertSafePath(plan.file);
|
|
83
|
+
if (existsSync(plan.file)) backupFile(plan.file, now);
|
|
84
|
+
}
|
|
85
|
+
for (const plan of plans) {
|
|
86
|
+
mkdirSync(path.dirname(plan.file), { recursive: true });
|
|
87
|
+
writeFileSync(plan.file, plan.text, { mode: 0o600 });
|
|
88
|
+
chmodSync(plan.file, 0o600);
|
|
89
|
+
}
|
|
90
|
+
dropPersonalSkills(skillsOptions);
|
|
91
|
+
}
|
|
92
|
+
const prefix = values["dry-run"] ? "Would change" : "Change";
|
|
93
|
+
for (const plan of plans) {
|
|
94
|
+
for (const key of plan.changed) log(`${prefix} ${plan.file}: ${key}`);
|
|
95
|
+
}
|
|
96
|
+
for (const folder of skills.removed) log(`${prefix} ${folder}: remove personal skill`);
|
|
97
|
+
if (!plans.length && !skills.removed.length) log("Setup matches.");
|
|
98
|
+
if (steps.length) {
|
|
99
|
+
log("Steps for a person:");
|
|
100
|
+
for (const step of steps) log(` - ${step}`);
|
|
101
|
+
}
|
|
102
|
+
return 0;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
log(`qc setup: ${error.message}`);
|
|
105
|
+
return 2;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
5
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, utimesSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { dirname, join, relative } from "node:path";
|
|
8
|
+
import test from "node:test";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { CORE_BEGIN, CORE_END } from "./setup-block.mjs";
|
|
11
|
+
import { runSetup } from "./setup.mjs";
|
|
12
|
+
|
|
13
|
+
function fixture(t) {
|
|
14
|
+
const root = mkdtempSync(join(tmpdir(), "qc-setup-"));
|
|
15
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
16
|
+
const home = join(root, "home");
|
|
17
|
+
const kitDir = join(root, "kit");
|
|
18
|
+
const cwd = join(root, "project");
|
|
19
|
+
const settings = join(home, ".claude", "settings.json");
|
|
20
|
+
const codex = join(home, ".codex", "config.toml");
|
|
21
|
+
const claude = join(home, ".claude", "CLAUDE.md");
|
|
22
|
+
const template = join(kitDir, "claude", "CLAUDE.core.md");
|
|
23
|
+
for (const folder of [dirname(settings), dirname(codex), dirname(template), cwd]) mkdirSync(folder, { recursive: true });
|
|
24
|
+
writeFileSync(settings, '{"theme":"dark"}');
|
|
25
|
+
writeFileSync(codex, 'model = "x"');
|
|
26
|
+
writeFileSync(template, "core rule\n");
|
|
27
|
+
const logs = [];
|
|
28
|
+
const options = {
|
|
29
|
+
home, env: {}, kitDir, now: new Date("2026-01-02T03:04:05Z"), log: (line) => logs.push(line), cwd,
|
|
30
|
+
run: () => ({ status: 0, stdout: "v22.0.0" }), exists: existsSync,
|
|
31
|
+
};
|
|
32
|
+
return { root, home, kitDir, cwd, settings, codex, claude, template, logs, options };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function snapshot(root) {
|
|
36
|
+
return Object.fromEntries(readdirSync(root, { recursive: true, withFileTypes: true })
|
|
37
|
+
.filter((entry) => entry.isFile())
|
|
38
|
+
.map((entry) => {
|
|
39
|
+
const file = join(entry.parentPath ?? entry.path, entry.name);
|
|
40
|
+
return [relative(root, file), { text: readFileSync(file, "utf8"), mtime: statSync(file).mtimeMs }];
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function budgets(f, value = { orchestrator: { compactAt: 200000 }, codex: { compactAt: 300000 } }, name = "custom.json") {
|
|
45
|
+
const file = join(f.cwd, name);
|
|
46
|
+
writeFileSync(file, JSON.stringify({ budgets: value }));
|
|
47
|
+
return file;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function personalSkill(f) {
|
|
51
|
+
const claudeDir = dirname(f.settings);
|
|
52
|
+
const installPath = join(claudeDir, "plugins", "cache", "architecture");
|
|
53
|
+
const folder = join(claudeDir, "skills", "registering-work");
|
|
54
|
+
const pluginFolder = join(installPath, "skills", "registering-work");
|
|
55
|
+
for (const dir of [folder, pluginFolder]) {
|
|
56
|
+
mkdirSync(dir, { recursive: true });
|
|
57
|
+
writeFileSync(join(dir, "SKILL.md"), "# Register work\n");
|
|
58
|
+
}
|
|
59
|
+
writeFileSync(join(claudeDir, "plugins", "installed_plugins.json"), JSON.stringify({
|
|
60
|
+
version: 2, plugins: { "architecture@architecture-kit": [{ scope: "user", installPath, version: "1.0.0" }] },
|
|
61
|
+
}));
|
|
62
|
+
writeFileSync(f.settings, JSON.stringify({ theme: "dark", enabledPlugins: { "architecture@architecture-kit": true } }));
|
|
63
|
+
return folder;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
test("sets up user files and logs each changed key", async (t) => {
|
|
67
|
+
const f = fixture(t);
|
|
68
|
+
const codexTime = statSync(f.codex).mtimeMs;
|
|
69
|
+
assert.equal(await runSetup([], f.options), 0);
|
|
70
|
+
assert.deepEqual(JSON.parse(readFileSync(f.settings, "utf8")), { theme: "dark", autoCompactEnabled: true });
|
|
71
|
+
assert.equal(readFileSync(f.claude, "utf8"), `${CORE_BEGIN}\ncore rule\n${CORE_END}\n`);
|
|
72
|
+
assert.equal(readFileSync(f.codex, "utf8"), 'model = "x"');
|
|
73
|
+
assert.equal(statSync(f.codex).mtimeMs, codexTime);
|
|
74
|
+
assert.ok(f.logs.includes(`Change ${f.settings}: autoCompactEnabled`));
|
|
75
|
+
assert.ok(f.logs.some((line) => line.startsWith(`Change ${f.claude}: `)));
|
|
76
|
+
assert.equal(f.logs.filter((line) => line.startsWith("Change ")).length, 2);
|
|
77
|
+
const backup = readdirSync(dirname(f.settings)).find((name) => name.startsWith("settings.json.bak-"));
|
|
78
|
+
assert.ok(backup);
|
|
79
|
+
assert.equal(readFileSync(join(dirname(f.settings), backup), "utf8"), '{"theme":"dark"}');
|
|
80
|
+
if (process.platform !== "win32") assert.equal(statSync(f.settings).mode & 0o777, 0o600);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("a second run preserves every file and creates no backup", async (t) => {
|
|
84
|
+
const f = fixture(t);
|
|
85
|
+
assert.equal(await runSetup([], f.options), 0);
|
|
86
|
+
for (const file of [f.settings, f.codex, f.claude]) utimesSync(file, 100, 100);
|
|
87
|
+
const before = snapshot(f.root);
|
|
88
|
+
f.logs.length = 0;
|
|
89
|
+
assert.equal(await runSetup([], { ...f.options, now: new Date("2026-01-03T03:04:05Z") }), 0);
|
|
90
|
+
assert.deepEqual(snapshot(f.root), before);
|
|
91
|
+
assert.equal(f.logs.some((line) => line.startsWith("Change ")), false);
|
|
92
|
+
assert.ok(f.logs.includes("Setup matches."));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("preserves text outside the markers when the template changes", async (t) => {
|
|
96
|
+
const f = fixture(t);
|
|
97
|
+
assert.equal(await runSetup([], f.options), 0);
|
|
98
|
+
writeFileSync(f.claude, `Personal rules\n${readFileSync(f.claude, "utf8")}More personal rules\n`);
|
|
99
|
+
writeFileSync(f.template, "changed core rule\n");
|
|
100
|
+
assert.equal(await runSetup([], f.options), 0);
|
|
101
|
+
assert.equal(readFileSync(f.claude, "utf8"), `Personal rules\n${CORE_BEGIN}\nchanged core rule\n${CORE_END}\nMore personal rules\n`);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("a dry run leaves all files and personal skills intact", async (t) => {
|
|
105
|
+
const f = fixture(t);
|
|
106
|
+
const folder = personalSkill(f);
|
|
107
|
+
const before = snapshot(f.root);
|
|
108
|
+
assert.equal(await runSetup(["--dry-run"], f.options), 0);
|
|
109
|
+
assert.deepEqual(snapshot(f.root), before);
|
|
110
|
+
assert.equal(existsSync(folder), true);
|
|
111
|
+
assert.ok(f.logs.some((line) => line.startsWith(`Would change ${f.settings}: `)));
|
|
112
|
+
assert.ok(f.logs.some((line) => line.startsWith(`Would change ${folder}: `)));
|
|
113
|
+
assert.equal(f.logs.some((line) => line.startsWith("Change ")), false);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("applies explicit budgets to each selected Claude model and Codex", async (t) => {
|
|
117
|
+
const f = fixture(t);
|
|
118
|
+
const config = budgets(f);
|
|
119
|
+
assert.equal(await runSetup(["--config", config, "--model", "claude-opus-5-5", "--model", "claude-sonnet-5"], f.options), 0);
|
|
120
|
+
const settings = JSON.parse(readFileSync(f.settings, "utf8"));
|
|
121
|
+
assert.equal(settings.modelSettings["claude-opus-5-5"].autoCompactWindow, 200000);
|
|
122
|
+
assert.equal(settings.modelSettings["claude-sonnet-5"].autoCompactWindow, 200000);
|
|
123
|
+
assert.match(readFileSync(f.codex, "utf8"), /^model_auto_compact_token_limit = 300000$/m);
|
|
124
|
+
assert.ok(f.logs.includes(`Change ${f.settings}: modelSettings.claude-opus-5-5.autoCompactWindow`));
|
|
125
|
+
assert.ok(f.logs.includes(`Change ${f.codex}: model_auto_compact_token_limit`));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("reads budgets from qc.config.json in the current directory", async (t) => {
|
|
129
|
+
const f = fixture(t);
|
|
130
|
+
budgets(f, undefined, "qc.config.json");
|
|
131
|
+
assert.equal(await runSetup(["--model", "claude-opus-5-5"], f.options), 0);
|
|
132
|
+
assert.equal(JSON.parse(readFileSync(f.settings, "utf8")).modelSettings["claude-opus-5-5"].autoCompactWindow, 200000);
|
|
133
|
+
assert.match(readFileSync(f.codex, "utf8"), /^model_auto_compact_token_limit = 300000$/m);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("lists a person step for budgets without a Claude model", async (t) => {
|
|
137
|
+
const f = fixture(t);
|
|
138
|
+
const config = budgets(f);
|
|
139
|
+
assert.equal(await runSetup(["--config", config], f.options), 0);
|
|
140
|
+
assert.equal(JSON.parse(readFileSync(f.settings, "utf8")).modelSettings, undefined);
|
|
141
|
+
assert.ok(f.logs.some((line) => line.startsWith(" - ") && line.includes("--model")));
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("invalid settings leave every file untouched", async (t) => {
|
|
145
|
+
const f = fixture(t);
|
|
146
|
+
writeFileSync(f.settings, "{invalid");
|
|
147
|
+
const before = snapshot(f.root);
|
|
148
|
+
assert.equal(await runSetup([], f.options), 2);
|
|
149
|
+
assert.deepEqual(snapshot(f.root), before);
|
|
150
|
+
assert.match(f.logs.at(-1), /^qc setup: /);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("invalid budgets leave every file untouched", async (t) => {
|
|
154
|
+
const f = fixture(t);
|
|
155
|
+
for (const value of [0, -1, 1.5, "200000"]) {
|
|
156
|
+
const config = budgets(f, { codex: { compactAt: value } });
|
|
157
|
+
const before = snapshot(f.root);
|
|
158
|
+
assert.equal(await runSetup(["--config", config], f.options), 2);
|
|
159
|
+
assert.deepEqual(snapshot(f.root), before);
|
|
160
|
+
assert.match(f.logs.at(-1), /^qc setup: .*compactAt/);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("a missing explicit config warns on stderr and skips budgets", async (t) => {
|
|
165
|
+
const f = fixture(t);
|
|
166
|
+
const warnings = [];
|
|
167
|
+
const config = join(f.cwd, "missing.json");
|
|
168
|
+
const warning = t.mock.method(console, "error", (line) => warnings.push(line));
|
|
169
|
+
assert.equal(await runSetup(["--config", config], f.options), 0);
|
|
170
|
+
warning.mock.restore();
|
|
171
|
+
assert.equal(readFileSync(f.codex, "utf8"), 'model = "x"');
|
|
172
|
+
assert.ok(warnings.some((line) => line.includes(config) && /missing|not found/i.test(line)));
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("setup ignores unrelated personal skills, including a folder containing auth", async (t) => {
|
|
176
|
+
const f = fixture(t);
|
|
177
|
+
mkdirSync(join(f.home, ".aws"));
|
|
178
|
+
writeFileSync(join(f.home, ".aws", "config"), "sso_session = work\n");
|
|
179
|
+
const folders = ["authoring-docs", "my-own"].map((name) => join(dirname(f.settings), "skills", name));
|
|
180
|
+
for (const folder of folders) {
|
|
181
|
+
mkdirSync(folder, { recursive: true });
|
|
182
|
+
writeFileSync(join(folder, "SKILL.md"), "personal rule\n");
|
|
183
|
+
}
|
|
184
|
+
assert.equal(await runSetup([], { ...f.options, exists: () => true }), 0);
|
|
185
|
+
assert.equal(f.logs.includes("Steps for a person:"), false);
|
|
186
|
+
for (const folder of folders) assert.equal(readFileSync(join(folder, "SKILL.md"), "utf8"), "personal rule\n");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("setup sets mode 0600 after writing an existing settings file", async (t) => {
|
|
190
|
+
const f = fixture(t);
|
|
191
|
+
const calls = [];
|
|
192
|
+
const chmod = fs.chmodSync;
|
|
193
|
+
const mocked = t.mock.method(fs, "chmodSync", (file, mode) => { calls.push({ file, mode }); chmod(file, mode); });
|
|
194
|
+
syncBuiltinESMExports();
|
|
195
|
+
try {
|
|
196
|
+
assert.equal(await runSetup([], f.options), 0);
|
|
197
|
+
assert.ok(calls.some(({ file, mode }) => file === f.settings && mode === 0o600));
|
|
198
|
+
if (process.platform !== "win32") assert.equal(statSync(f.settings).mode & 0o777, 0o600);
|
|
199
|
+
} finally {
|
|
200
|
+
mocked.mock.restore();
|
|
201
|
+
syncBuiltinESMExports();
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("removes a personal skill that matches its enabled plugin copy", async (t) => {
|
|
206
|
+
const f = fixture(t);
|
|
207
|
+
const folder = personalSkill(f);
|
|
208
|
+
assert.equal(await runSetup([], f.options), 0);
|
|
209
|
+
assert.equal(existsSync(folder), false);
|
|
210
|
+
assert.ok(f.logs.some((line) => line.startsWith(`Change ${folder}: `)));
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("names the kept skill folder in the step text", async (t) => {
|
|
214
|
+
const f = fixture(t);
|
|
215
|
+
const folder = personalSkill(f);
|
|
216
|
+
writeFileSync(join(folder, "SKILL.md"), "personal rule\n");
|
|
217
|
+
assert.equal(await runSetup([], f.options), 0);
|
|
218
|
+
assert.ok(f.logs.includes(` - Check ${folder}: it differs from the plugin copy`));
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("ends the log with each step for a person", async (t) => {
|
|
222
|
+
const f = fixture(t);
|
|
223
|
+
assert.equal(await runSetup([], f.options), 0);
|
|
224
|
+
const heading = f.logs.indexOf("Steps for a person:");
|
|
225
|
+
assert.ok(heading >= 0);
|
|
226
|
+
assert.deepEqual(f.logs.slice(heading + 1), [
|
|
227
|
+
" - Run `codex login`",
|
|
228
|
+
" - Set up the AWS SSO profile: run `aws configure sso`",
|
|
229
|
+
]);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("omits the person heading when all person steps are complete", async (t) => {
|
|
233
|
+
const f = fixture(t);
|
|
234
|
+
mkdirSync(join(f.home, ".aws"));
|
|
235
|
+
writeFileSync(join(f.home, ".aws", "config"), "sso_session = work\n");
|
|
236
|
+
assert.equal(await runSetup([], { ...f.options, exists: () => true }), 0);
|
|
237
|
+
assert.equal(f.logs.includes("Steps for a person:"), false);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test("a late planning error leaves files and skills untouched", async (t) => {
|
|
241
|
+
const f = fixture(t);
|
|
242
|
+
personalSkill(f);
|
|
243
|
+
const before = snapshot(f.root);
|
|
244
|
+
assert.equal(await runSetup([], { ...f.options, run: () => { throw new Error("tool check failed"); } }), 2);
|
|
245
|
+
assert.deepEqual(snapshot(f.root), before);
|
|
246
|
+
assert.equal(f.logs.at(-1), "qc setup: tool check failed");
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("invalid markers fail before any write", async (t) => {
|
|
250
|
+
const f = fixture(t);
|
|
251
|
+
writeFileSync(f.claude, `${CORE_BEGIN}\n`);
|
|
252
|
+
const before = snapshot(f.root);
|
|
253
|
+
assert.equal(await runSetup([], f.options), 2);
|
|
254
|
+
assert.deepEqual(snapshot(f.root), before);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("rejects credential paths before any write", async (t) => {
|
|
258
|
+
const f = fixture(t);
|
|
259
|
+
const file = join(f.cwd, "auth.json");
|
|
260
|
+
writeFileSync(file, "{}");
|
|
261
|
+
const before = snapshot(f.root);
|
|
262
|
+
assert.equal(await runSetup(["--config", file], f.options), 2);
|
|
263
|
+
assert.deepEqual(snapshot(f.root), before);
|
|
264
|
+
assert.match(f.logs.at(-1), /Refusing credential file/);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test("the CLI dispatches setup before loading the project config", (t) => {
|
|
268
|
+
const f = fixture(t);
|
|
269
|
+
writeFileSync(join(f.cwd, "qc.config.json"), "{invalid");
|
|
270
|
+
const result = spawnSync(process.execPath, [fileURLToPath(new URL("./qc.mjs", import.meta.url)), "setup", "--unknown"], {
|
|
271
|
+
cwd: f.cwd, encoding: "utf8", windowsHide: true,
|
|
272
|
+
});
|
|
273
|
+
assert.equal(result.status, 2);
|
|
274
|
+
assert.match(result.stdout, /^qc setup: Unknown option '--unknown'/);
|
|
275
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
test("skills/codex/SKILL.md has at most 100 non-blank lines", () => {
|
|
6
|
+
const lines = readFileSync(new URL("../../../../skills/codex/SKILL.md", import.meta.url), "utf8").split(/\r?\n/).filter((line) => line.trim());
|
|
7
|
+
assert.ok(lines.length <= 100, `codex skill has ${lines.length} non-blank lines`);
|
|
8
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// A pipeline that resolves Windows executables and runs shims with literal arguments.
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { statSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
const meta = /([()\][%!^"`<>&|;, *?])/g;
|
|
7
|
+
const escapeMeta = (value) => value.replace(meta, "^$1");
|
|
8
|
+
|
|
9
|
+
function quoteArgument(value) {
|
|
10
|
+
const quoted = '"' + String(value).replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1") + '"';
|
|
11
|
+
// Batch shims forward arguments through a second cmd.exe parse.
|
|
12
|
+
return escapeMeta(escapeMeta(quoted));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function resolveCommand(command, cwd, env) {
|
|
16
|
+
const get = (key) => env[Object.keys(env).findLast((name) => name.toUpperCase() === key)] ?? "";
|
|
17
|
+
const extensions = get("PATHEXT").split(";").filter(Boolean);
|
|
18
|
+
const suffixes = path.extname(command) ? [""] : (extensions.length ? extensions : [".COM", ".EXE", ".BAT", ".CMD"]);
|
|
19
|
+
const directories = /[\\/]/.test(command) ? [cwd] : [cwd, ...get("PATH").split(";").map((entry) => entry.replace(/^"|"$/g, ""))];
|
|
20
|
+
for (const directory of directories) {
|
|
21
|
+
for (const suffix of suffixes) {
|
|
22
|
+
const candidate = path.resolve(cwd, directory, command + suffix);
|
|
23
|
+
try {
|
|
24
|
+
if (statSync(candidate).isFile()) return candidate;
|
|
25
|
+
} catch {
|
|
26
|
+
// Missing candidates let the search continue through PATH.
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return command;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function spawnCommand(command, args = [], options = {}) {
|
|
34
|
+
const settings = { ...options, shell: false };
|
|
35
|
+
if (process.platform !== "win32") return spawn(command, args, settings);
|
|
36
|
+
const env = options.env ?? process.env;
|
|
37
|
+
const executable = resolveCommand(command, options.cwd ?? process.cwd(), env);
|
|
38
|
+
if (!/\.(cmd|bat)$/i.test(executable)) return spawn(executable, args, settings);
|
|
39
|
+
if (args.some((argument) => /[\r\n]/.test(String(argument)))) {
|
|
40
|
+
throw new Error(`Cannot run ${command}: a cmd.exe argument contains a line break`);
|
|
41
|
+
}
|
|
42
|
+
const line = [escapeMeta(executable), ...args.map(quoteArgument)].join(" ");
|
|
43
|
+
return spawn(process.env.ComSpec ?? "cmd.exe", ["/d", "/s", "/c", `"${line}"`], {
|
|
44
|
+
...settings,
|
|
45
|
+
windowsVerbatimArguments: true,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import { spawnCommand } from "./spawn-command.mjs";
|
|
7
|
+
|
|
8
|
+
for (const command of ["probe", "probe.CMD", "probe.BAT"]) {
|
|
9
|
+
test(`spawnCommand resolves ${command} and preserves literal shim arguments`, { skip: process.platform !== "win32" }, async () => {
|
|
10
|
+
const root = mkdtempSync(join(tmpdir(), "qc-spawn-"));
|
|
11
|
+
const bin = join(root, "bin space");
|
|
12
|
+
mkdirSync(bin);
|
|
13
|
+
writeFileSync(join(bin, "probe"), "#!/bin/sh\nexit 99\n");
|
|
14
|
+
writeFileSync(join(bin, "probe.CMD"), '@echo off\r\n@"' + process.execPath + '" "%~dp0probe.mjs" %*\r\n');
|
|
15
|
+
writeFileSync(join(bin, "probe.BAT"), '@echo off\r\n@"' + process.execPath + '" "%~dp0probe.mjs" %*\r\n');
|
|
16
|
+
writeFileSync(join(bin, "probe.mjs"), "console.log(JSON.stringify(process.argv.slice(2)))");
|
|
17
|
+
const args = ["with spaces", 'with"quote', "with&symbol", "^|<>()%!", "C:\\folder\\file", "ends with space\\", ""];
|
|
18
|
+
try {
|
|
19
|
+
const child = spawnCommand(command, args, {
|
|
20
|
+
cwd: root,
|
|
21
|
+
env: { ...Object.fromEntries(Object.entries(process.env).filter(([key]) => !["PATH", "PATHEXT"].includes(key.toUpperCase()))), Path: root, PATH: bin, Pathext: ".EXE", PATHEXT: ".EXE;.CMD" },
|
|
22
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
23
|
+
});
|
|
24
|
+
let output = "";
|
|
25
|
+
let errors = "";
|
|
26
|
+
child.stdout.on("data", (data) => { output += data; });
|
|
27
|
+
child.stderr.on("data", (data) => { errors += data; });
|
|
28
|
+
const code = await new Promise((resolve, reject) => {
|
|
29
|
+
child.on("error", reject);
|
|
30
|
+
child.on("close", resolve);
|
|
31
|
+
});
|
|
32
|
+
assert.equal(code, 0, errors);
|
|
33
|
+
assert.deepEqual(JSON.parse(output), args);
|
|
34
|
+
} finally {
|
|
35
|
+
rmSync(root, { recursive: true, force: true });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
test("spawnCommand forces shell off for native executables", async () => {
|
|
41
|
+
const child = spawnCommand(process.execPath, ["-e", "process.exit(process.argv[1] === '& literal' ? 0 : 1)", "& literal"], { shell: true, stdio: "ignore" });
|
|
42
|
+
const code = await new Promise((resolve, reject) => {
|
|
43
|
+
child.on("error", reject);
|
|
44
|
+
child.on("close", resolve);
|
|
45
|
+
});
|
|
46
|
+
assert.equal(code, 0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("spawnCommand rejects line breaks in batch arguments and names the command", { skip: process.platform !== "win32" }, () => {
|
|
50
|
+
const root = mkdtempSync(join(tmpdir(), "qc-spawn-newline-"));
|
|
51
|
+
try {
|
|
52
|
+
const shim = join(root, "probe.cmd");
|
|
53
|
+
writeFileSync(shim, "@exit /b 0\r\n");
|
|
54
|
+
for (const argument of ["first\nsecond", "first\rsecond", "first\r\nsecond"]) {
|
|
55
|
+
assert.throws(() => spawnCommand(shim, [argument], { stdio: "ignore" }), (error) => {
|
|
56
|
+
assert.ok(error.message.includes(shim));
|
|
57
|
+
assert.match(error.message, /line break/i);
|
|
58
|
+
return true;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
} finally {
|
|
62
|
+
rmSync(root, { recursive: true, force: true });
|
|
63
|
+
}
|
|
64
|
+
});
|