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.
Files changed (244) hide show
  1. package/package.json +3 -22
  2. package/src/cli/ask.mjs +42 -0
  3. package/src/cli/ask.test.mjs +40 -0
  4. package/src/cli/branch-sync.mjs +126 -0
  5. package/src/cli/branch-sync.test.mjs +428 -0
  6. package/src/cli/budget-guard.mjs +74 -5
  7. package/src/cli/budget-guard.test.mjs +185 -2
  8. package/src/cli/budget-report.mjs +85 -0
  9. package/src/cli/budget-report.test.mjs +173 -0
  10. package/src/cli/budget.mjs +8 -5
  11. package/src/cli/check-commands.mjs +123 -11
  12. package/src/cli/check-commands.test.mjs +360 -6
  13. package/src/cli/check-feature-switches.test.mjs +110 -0
  14. package/src/cli/check-full.test.mjs +152 -0
  15. package/src/cli/check-verdict.mjs +46 -0
  16. package/src/cli/check-verdict.test.mjs +32 -0
  17. package/src/cli/check.mjs +137 -4
  18. package/src/cli/check.test.mjs +45 -0
  19. package/src/cli/checkpoint.mjs +143 -0
  20. package/src/cli/checkpoint.test.mjs +146 -0
  21. package/src/cli/child-run.mjs +7 -2
  22. package/src/cli/child-run.test.mjs +17 -2
  23. package/src/cli/ci-failures.mjs +304 -0
  24. package/src/cli/ci-failures.test.mjs +615 -0
  25. package/src/cli/ci-preview.mjs +62 -0
  26. package/src/cli/ci-preview.test.mjs +85 -0
  27. package/src/cli/ci-state.mjs +25 -29
  28. package/src/cli/ci-state.test.mjs +174 -2
  29. package/src/cli/ci-template.test.mjs +86 -0
  30. package/src/cli/claude-core.test.mjs +37 -0
  31. package/src/cli/codex-implement.mjs +580 -47
  32. package/src/cli/codex-implement.test.mjs +1946 -29
  33. package/src/cli/codex-limit.mjs +85 -0
  34. package/src/cli/codex-limit.test.mjs +179 -0
  35. package/src/cli/codex-reset.mjs +78 -0
  36. package/src/cli/codex-reset.test.mjs +192 -0
  37. package/src/cli/codex-verify.mjs +230 -0
  38. package/src/cli/codex-verify.test.mjs +402 -0
  39. package/src/cli/comment-watch.mjs +391 -0
  40. package/src/cli/comment-watch.test.mjs +392 -0
  41. package/src/cli/commit-guard.mjs +219 -0
  42. package/src/cli/commit-guard.test.mjs +809 -0
  43. package/src/cli/context-budgets.mjs +47 -0
  44. package/src/cli/context-budgets.test.mjs +96 -0
  45. package/src/cli/context-watch.mjs +116 -0
  46. package/src/cli/context-watch.test.mjs +395 -0
  47. package/src/cli/contract-history.mjs +1 -1
  48. package/src/cli/controller-guard.mjs +38 -0
  49. package/src/cli/controller-guard.test.mjs +66 -2
  50. package/src/cli/cost-stop.mjs +5 -1
  51. package/src/cli/cost-stop.test.mjs +26 -0
  52. package/src/cli/diff-shape.mjs +162 -0
  53. package/src/cli/diff-shape.test.mjs +200 -0
  54. package/src/cli/direct-lane.mjs +32 -19
  55. package/src/cli/direct-lane.test.mjs +21 -3
  56. package/src/cli/dispatch-guard.mjs +11 -0
  57. package/src/cli/dispatch-guard.test.mjs +145 -10
  58. package/src/cli/dispatch-reminder.mjs +23 -10
  59. package/src/cli/dispatch-reminder.test.mjs +63 -11
  60. package/src/cli/dispatch-route.mjs +54 -0
  61. package/src/cli/dispatch-route.test.mjs +101 -0
  62. package/src/cli/dispatch-slot.mjs +2 -2
  63. package/src/cli/dispatch-slot.test.mjs +18 -19
  64. package/src/cli/dispatch.test.mjs +3 -3
  65. package/src/cli/e2e-affected.mjs +15 -0
  66. package/src/cli/e2e-affected.test.mjs +73 -0
  67. package/src/cli/fleet.mjs +180 -0
  68. package/src/cli/fleet.test.mjs +213 -0
  69. package/src/cli/gate-slot.mjs +2 -1
  70. package/src/cli/gh-merge-command.mjs +96 -31
  71. package/src/cli/gh-merge-command.test.mjs +74 -0
  72. package/src/cli/gh-run.mjs +64 -3
  73. package/src/cli/gh-run.test.mjs +66 -1
  74. package/src/cli/git-hooks.test.mjs +25 -3
  75. package/src/cli/git-read.mjs +2 -1
  76. package/src/cli/integrate-tree.mjs +47 -0
  77. package/src/cli/integrate.mjs +143 -40
  78. package/src/cli/integrate.test.mjs +347 -1
  79. package/src/cli/integration-lane.mjs +62 -0
  80. package/src/cli/integration-lane.test.mjs +213 -0
  81. package/src/cli/ledger.mjs +4 -2
  82. package/src/cli/ledger.test.mjs +12 -3
  83. package/src/cli/legs.mjs +53 -0
  84. package/src/cli/legs.test.mjs +70 -0
  85. package/src/cli/lint-changed.mjs +59 -10
  86. package/src/cli/lint-changed.test.mjs +112 -1
  87. package/src/cli/locked-tests.mjs +134 -0
  88. package/src/cli/locked-tests.test.mjs +188 -0
  89. package/src/cli/merge-guard.mjs +234 -62
  90. package/src/cli/merge-guard.test.mjs +768 -39
  91. package/src/cli/metrics.mjs +53 -0
  92. package/src/cli/metrics.test.mjs +73 -0
  93. package/src/cli/milestone.mjs +297 -0
  94. package/src/cli/milestone.test.mjs +294 -0
  95. package/src/cli/mutate.mjs +203 -0
  96. package/src/cli/mutate.test.mjs +134 -0
  97. package/src/cli/output-redaction.mjs +26 -0
  98. package/src/cli/output-redaction.test.mjs +117 -0
  99. package/src/cli/overview.mjs +131 -0
  100. package/src/cli/overview.test.mjs +137 -0
  101. package/src/cli/pause.mjs +93 -0
  102. package/src/cli/pause.test.mjs +109 -0
  103. package/src/cli/plan-check.mjs +84 -12
  104. package/src/cli/plan-check.test.mjs +152 -2
  105. package/src/cli/plan-stop.mjs +7 -4
  106. package/src/cli/plan-stop.test.mjs +87 -0
  107. package/src/cli/platform-risk.mjs +46 -0
  108. package/src/cli/platform-risk.test.mjs +38 -0
  109. package/src/cli/plugin-skills.test.mjs +25 -0
  110. package/src/cli/pr-guard.mjs +128 -0
  111. package/src/cli/pr-guard.test.mjs +154 -0
  112. package/src/cli/promotion-branch.mjs +2 -0
  113. package/src/cli/qc.mjs +160 -27
  114. package/src/cli/qc.test.mjs +93 -0
  115. package/src/cli/report-stop.mjs +5 -0
  116. package/src/cli/report-stop.test.mjs +23 -1
  117. package/src/cli/retry-failed.mjs +3 -1
  118. package/src/cli/review-gate.mjs +24 -6
  119. package/src/cli/review-gate.test.mjs +116 -0
  120. package/src/cli/review-promotion.mjs +107 -0
  121. package/src/cli/review-promotion.test.mjs +251 -0
  122. package/src/cli/role-budget.mjs +50 -0
  123. package/src/cli/role-budget.test.mjs +91 -0
  124. package/src/cli/run-log.mjs +73 -0
  125. package/src/cli/run-log.test.mjs +121 -0
  126. package/src/cli/secret-patterns.mjs +16 -0
  127. package/src/cli/secret-patterns.test.mjs +73 -0
  128. package/src/cli/setup-block.mjs +24 -0
  129. package/src/cli/setup-block.test.mjs +96 -0
  130. package/src/cli/setup-checks.mjs +65 -0
  131. package/src/cli/setup-checks.test.mjs +158 -0
  132. package/src/cli/setup-compaction.mjs +55 -0
  133. package/src/cli/setup-compaction.test.mjs +115 -0
  134. package/src/cli/setup-skills.mjs +65 -0
  135. package/src/cli/setup-skills.test.mjs +171 -0
  136. package/src/cli/setup.mjs +107 -0
  137. package/src/cli/setup.test.mjs +275 -0
  138. package/src/cli/skill-length.test.mjs +8 -0
  139. package/src/cli/spawn-command.mjs +47 -0
  140. package/src/cli/spawn-command.test.mjs +64 -0
  141. package/src/cli/task-gate-review.test.mjs +21 -2
  142. package/src/cli/task-gate.mjs +25 -12
  143. package/src/cli/task-gate.test.mjs +43 -5
  144. package/src/cli/tokens.mjs +46 -3
  145. package/src/cli/tokens.test.mjs +103 -3
  146. package/src/cli/tools.mjs +49 -0
  147. package/src/cli/tools.test.mjs +89 -0
  148. package/src/cli/transcript-usage.mjs +27 -0
  149. package/src/cli/transcript-usage.test.mjs +34 -0
  150. package/src/cli/user-config-package.mjs +1 -1
  151. package/src/cli/user-config-toml.mjs +63 -7
  152. package/src/cli/user-config.mjs +39 -7
  153. package/src/cli/user-config.test.mjs +238 -5
  154. package/src/cli/watch-arm.mjs +39 -0
  155. package/src/cli/watch-arm.test.mjs +87 -0
  156. package/src/cli/watch.mjs +80 -35
  157. package/src/cli/watch.test.mjs +233 -27
  158. package/src/cli/work-order-guard.mjs +2 -1
  159. package/src/cli/workflow-hooks.test.mjs +18 -4
  160. package/src/cli/workflow-settings.mjs +44 -8
  161. package/src/cli/workflow-settings.test.mjs +124 -1
  162. package/src/cli/worktree.mjs +14 -1
  163. package/src/cli/worktree.test.mjs +20 -1
  164. package/src/config.mjs +174 -7
  165. package/src/config.test.mjs +327 -5
  166. package/src/consumer-package.mjs +31 -0
  167. package/src/consumer-package.test.mjs +54 -0
  168. package/src/descriptions.mjs +2 -0
  169. package/src/eslint/index.mjs +12 -0
  170. package/src/eslint/jsx.mjs +20 -0
  171. package/src/eslint/preset.mjs +26 -2
  172. package/src/eslint/preset.test.mjs +104 -2
  173. package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
  174. package/src/eslint/rules/no-literal-color.mjs +94 -0
  175. package/src/eslint/rules/no-static-inline-style.mjs +41 -0
  176. package/src/eslint/rules/one-component-per-file.mjs +70 -0
  177. package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
  178. package/src/eslint/rules/timeless-comment.mjs +92 -0
  179. package/src/eslint/rules.test.mjs +189 -0
  180. package/src/eslint/ui-regressions.test.mjs +39 -0
  181. package/src/gates/contract-operations.mjs +3 -3
  182. package/src/gates/contract-operations.test.mjs +28 -0
  183. package/src/gates/feature-switches.mjs +19 -0
  184. package/src/gates/feature-switches.test.mjs +55 -0
  185. package/src/gates/plain-language.mjs +396 -0
  186. package/src/gates/plain-language.test.mjs +210 -0
  187. package/src/gates/runtime-imports.test.mjs +114 -0
  188. package/src/gates/saga-key.test.mjs +1 -1
  189. package/src/global-skills.mjs +9 -0
  190. package/src/global-skills.test.mjs +53 -0
  191. package/src/plugin.test.mjs +3 -2
  192. package/src/ui/class-sites.mjs +38 -6
  193. package/src/ui/codemod.mjs +4 -1
  194. package/src/ui/codemod.test.mjs +52 -0
  195. package/src/ui/components.mjs +5 -3
  196. package/src/ui/components.test.mjs +8 -0
  197. package/src/ui/dupes.test.mjs +18 -0
  198. package/templates/docs/enforcement.md +12 -2
  199. package/templates/docs/ui.md +33 -0
  200. package/templates/githooks/pre-commit +1 -0
  201. package/templates/githooks/pre-push +11 -2
  202. package/templates/github/workflows/ci.yml +57 -3
  203. package/user-config/claude/CLAUDE.core.md +28 -0
  204. package/user-config/claude/settings.shared.json +41 -1
  205. package/src/cli/screens-discovery.mjs +0 -60
  206. package/src/cli/screens.mjs +0 -84
  207. package/src/cli/stack.mjs +0 -14
  208. package/src/cli/throwaway-db.mjs +0 -127
  209. package/src/cli/throwaway-db.test.mjs +0 -83
  210. package/src/screens/auth-context.test.mjs +0 -41
  211. package/src/screens/auth-run.test.mjs +0 -147
  212. package/src/screens/auth.mjs +0 -223
  213. package/src/screens/auth.test.mjs +0 -76
  214. package/src/screens/capture-idle.test.mjs +0 -27
  215. package/src/screens/capture.browser-test.mjs +0 -73
  216. package/src/screens/capture.mjs +0 -175
  217. package/src/screens/capture.test.mjs +0 -28
  218. package/src/screens/catalog.browser-test.mjs +0 -32
  219. package/src/screens/catalog.mjs +0 -72
  220. package/src/screens/catalog.test.mjs +0 -36
  221. package/src/screens/chrome.mjs +0 -21
  222. package/src/screens/compare.mjs +0 -40
  223. package/src/screens/compare.test.mjs +0 -30
  224. package/src/screens/discovery.browser-test.mjs +0 -29
  225. package/src/screens/discovery.mjs +0 -158
  226. package/src/screens/discovery.test.mjs +0 -27
  227. package/src/screens/inventory.mjs +0 -69
  228. package/src/screens/inventory.test.mjs +0 -10
  229. package/src/screens/map.mjs +0 -63
  230. package/src/screens/map.test.mjs +0 -35
  231. package/src/screens/open.browser-test.mjs +0 -50
  232. package/src/screens/regions.mjs +0 -137
  233. package/src/screens/regions.test.mjs +0 -38
  234. package/src/screens/session-files.mjs +0 -39
  235. package/src/screens/session-files.test.mjs +0 -39
  236. package/src/screens/setup.browser-test.mjs +0 -49
  237. package/src/screens/setup.mjs +0 -78
  238. package/src/screens/stack-auth.browser-test.mjs +0 -30
  239. package/src/screens/stack-auth.mjs +0 -106
  240. package/src/screens/stack-auth.test.mjs +0 -65
  241. package/src/screens/write-guard.mjs +0 -26
  242. package/src/stack/stack.mjs +0 -131
  243. package/src/stack/stack.test.mjs +0 -40
  244. package/src/stack/supervisor.mjs +0 -30
@@ -1,26 +0,0 @@
1
- import { requireLocalhost } from "./map.mjs";
2
-
3
- const mutationName = /save|delete|submit|send|complete|upload|confirm|保存|削除|登録|送信|確定|竣工|アップロード|完了|取消|解除/i;
4
-
5
- /** Branch: all navigation shares one list of mutation controls. */
6
- export function safeControl(control) {
7
- return control.type !== "submit" && !mutationName.test(control.text ?? control.name ?? "");
8
- }
9
-
10
- /** Branch: only explicit local opt-in and Auth0 sign-in permit writes. */
11
- export function permitsRequest(method, value, target, allowWrites = false) {
12
- const url = new URL(value);
13
- if (["GET", "HEAD", "OPTIONS"].includes(method)) return ["http:", "https:"].includes(url.protocol);
14
- if (target.auth?.domain === url.hostname && url.protocol === "https:" && /^\/(?:u\/login(?:\/|$)|oauth\/token$|usernamepassword\/login$|co\/authenticate$)/.test(url.pathname)) return true;
15
- if (!allowWrites) return false;
16
- try { requireLocalhost(target.baseUrl); requireLocalhost(url.href); return true; } catch { return false; }
17
- }
18
-
19
- /** Resource: the browser aborts requests before they reach a write endpoint. */
20
- export async function installWriteGuard(context, target, { allowWrites = false, onBlocked = () => {} } = {}) {
21
- await context.route("**/*", async route => {
22
- const request = route.request();
23
- if (permitsRequest(request.method(), request.url(), target, allowWrites)) await route.fallback();
24
- else { onBlocked(); await route.abort("blockedbyclient"); }
25
- });
26
- }
@@ -1,131 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync, openSync, closeSync } from "node:fs";
2
- import { spawn, execFile } from "node:child_process";
3
- import { promisify } from "node:util";
4
- import { randomUUID } from "node:crypto";
5
- import os from "node:os";
6
- import path from "node:path";
7
- import net from "node:net";
8
- import { fileURLToPath } from "node:url";
9
- import { requireLocalhost } from "../screens/map.mjs";
10
-
11
- export const stackRoot = () => path.join(os.homedir(), ".qc", "stacks");
12
- export const readRegistry = () => JSON.parse(readFileSync(path.join(os.homedir(), ".qc", "stacks.json"), "utf8"));
13
- export const healthUrls = manifest => typeof manifest.health === "string" ? [manifest.health] : Object.values(manifest.health ?? {});
14
-
15
- /** Record: plugins declare local resources before the lifecycle starts. */
16
- export function validateManifest(manifest) {
17
- if (!/^[a-z0-9][a-z0-9_-]*$/i.test(manifest.name ?? "")) throw new Error("Invalid stack name");
18
- for (const [name, port] of Object.entries(manifest.ports ?? {})) {
19
- if (!Number.isInteger(port) || port < 1024 || port > 65535) throw new Error(`Invalid port ${name}`);
20
- }
21
- for (const key of ["up", "down"]) if (typeof manifest[key] !== "string" || !manifest[key]) throw new Error(`Stack requires ${key}`);
22
- if (!healthUrls(manifest).length) throw new Error("Stack requires health URLs");
23
- for (const url of healthUrls(manifest)) requireLocalhost(url);
24
- if (!["form", "auth0-session"].includes(manifest.login?.kind)) throw new Error("Stack login requires form or auth0-session");
25
- if (manifest.login.kind === "form") requireLocalhost(new URL(manifest.login.url, healthUrls(manifest)[0]).href);
26
- return manifest;
27
- }
28
-
29
- /** Resource: resolve a registered repository without copying its environment. */
30
- export function loadStack(name, registry = readRegistry()) {
31
- const repo = registry[name];
32
- if (typeof repo !== "string") throw new Error(`Unknown stack ${name}`);
33
- const manifest = validateManifest(JSON.parse(readFileSync(path.join(repo, "qc.stack.json"), "utf8")));
34
- if (manifest.name !== name) throw new Error(`Stack name differs from registry: ${name}`);
35
- return { repo: path.resolve(repo), manifest };
36
- }
37
-
38
- const pause = ms => new Promise(resolve => setTimeout(resolve, ms));
39
- const alive = pid => { try { process.kill(pid, 0); return true; } catch { return false; } };
40
-
41
- async function portBusy(port) {
42
- for (const host of ["127.0.0.1", "::1"]) {
43
- const server = net.createServer();
44
- const busy = await new Promise((resolve, reject) => {
45
- server.once("error", error => error.code === "EADDRINUSE" || error.code === "EACCES" ? resolve(true) : reject(error));
46
- server.listen({ port, host, exclusive: true }, () => server.close(() => resolve(false)));
47
- });
48
- if (busy) return true;
49
- }
50
- return false;
51
- }
52
-
53
- /** Branch: health requires a successful response from every declared endpoint. */
54
- export async function healthy(manifest) {
55
- const checks = await Promise.all(healthUrls(manifest).map(async url => {
56
- try { return (await fetch(url, { signal: AbortSignal.timeout(2000), redirect: "manual" })).ok; } catch { return false; }
57
- }));
58
- return checks.every(Boolean);
59
- }
60
-
61
- /** Resource: commands inherit the repository environment and have a fixed bound. */
62
- export function pluginCommand(command, repo, { timeout = 30000, env = process.env, stdio = "ignore" } = {}) {
63
- return new Promise((resolve, reject) => {
64
- const child = spawn(command, { cwd: repo, shell: true, windowsHide: true, env, stdio });
65
- const timer = setTimeout(async () => { await stopTree(child.pid); reject(new Error("Stack command timed out")); }, timeout);
66
- child.once("error", error => { clearTimeout(timer); reject(error); });
67
- child.once("exit", code => { clearTimeout(timer); code === 0 ? resolve() : reject(new Error(`Stack command exited ${code}`)); });
68
- });
69
- }
70
-
71
- /** Resource: stop only the process tree created by the supervisor. */
72
- export async function stopTree(pid) {
73
- if (!pid || !alive(pid)) return;
74
- if (process.platform === "win32") await promisify(execFile)("taskkill", ["/PID", String(pid), "/T", "/F"], { windowsHide: true }).catch(() => {});
75
- else { try { process.kill(-pid, "SIGTERM"); } catch { try { process.kill(pid, "SIGTERM"); } catch {} } }
76
- }
77
-
78
- /** Pipeline: persist ownership, wait for health, and compensate failed starts. */
79
- export async function stackAction(action, names = [], { registry = readRegistry(), stateRoot = stackRoot(), timeout = 120000 } = {}) {
80
- if (!["up", "down", "status"].includes(action)) throw new Error("Choose stack up, down, or status");
81
- mkdirSync(stateRoot, { recursive: true, mode: 0o700 });
82
- const rows = [];
83
- const entries = (names.length ? names : Object.keys(registry)).map(name => ({ name, ...loadStack(name, registry) }));
84
- for (const { name, repo, manifest } of entries) {
85
- const file = path.join(stateRoot, `${name}.json`);
86
- let state = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : null;
87
- let running = Boolean(state?.pid && alive(state.pid) && existsSync(`${file}.${state.token}.live`));
88
- if (action === "up" && !running) {
89
- for (const port of Object.values(manifest.ports ?? {})) if (await portBusy(port)) throw new Error(`Stack ${name}: port ${port} is in use`);
90
- const token = randomUUID();
91
- state = { repo, manifest, token, startedAt: new Date().toISOString() };
92
- writeFileSync(file, JSON.stringify(state), { mode: 0o600 });
93
- const log = openSync(path.join(stateRoot, `${name}.log`), "a", 0o600);
94
- const worker = spawn(process.execPath, [fileURLToPath(new URL("./supervisor.mjs", import.meta.url)), file], { detached: true, windowsHide: true, stdio: ["ignore", log, log] });
95
- closeSync(log);
96
- await new Promise((resolve, reject) => { worker.once("spawn", resolve); worker.once("error", reject); });
97
- worker.unref();
98
- const deadline = Date.now() + timeout;
99
- try {
100
- while (true) {
101
- state = JSON.parse(readFileSync(file, "utf8"));
102
- if (state.error) throw new Error(`Stack ${name}: ${state.error}`);
103
- if (state.pid && alive(state.pid) && await healthy(manifest)) break;
104
- if (Date.now() >= deadline) throw new Error(`Stack ${name}: health timed out`);
105
- await pause(200);
106
- }
107
- } catch (error) {
108
- writeFileSync(`${file}.${token}.stop`, "stop");
109
- await pause(500);
110
- throw error;
111
- }
112
- running = true;
113
- }
114
- if (action === "down" && running) {
115
- writeFileSync(`${file}.${state.token}.stop`, "stop");
116
- const deadline = Date.now() + timeout;
117
- while (alive(state.pid) && existsSync(`${file}.${state.token}.live`)) {
118
- if (Date.now() > deadline) throw new Error(`Stack ${name}: down timed out`);
119
- await pause(100);
120
- }
121
- rmSync(file, { force: true });
122
- running = false;
123
- }
124
- let pluginHealthy = true;
125
- if (action === "status" && running && manifest.status) {
126
- try { await pluginCommand(manifest.status, repo, { timeout: Math.min(timeout, 15000) }); } catch { pluginHealthy = false; }
127
- }
128
- rows.push({ name, running, healthy: running && pluginHealthy && await healthy(manifest), baseUrl: healthUrls(manifest)[0], startedAt: state?.startedAt ?? null });
129
- }
130
- return rows;
131
- }
@@ -1,40 +0,0 @@
1
- import test from "node:test";
2
- import assert from "node:assert/strict";
3
- import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import net from "node:net";
7
- import { stackAction, validateManifest } from "./stack.mjs";
8
-
9
- test("stack up waits for health, status observes it, and down stops its process", async () => {
10
- const root = mkdtempSync(path.join(os.tmpdir(), "qc-stack-"));
11
- const probe = net.createServer();
12
- await new Promise(resolve => probe.listen(0, "127.0.0.1", resolve));
13
- const port = probe.address().port;
14
- await new Promise(resolve => probe.close(resolve));
15
- const manifest = { name: "fixture", up: "node server.cjs", down: "node -e \"process.exit(0)\"", status: "node -e \"process.exit(0)\"", ports: { web: port }, health: [`http://127.0.0.1:${port}`], login: { kind: "form", url: "/login" } };
16
- writeFileSync(path.join(root, "qc.stack.json"), JSON.stringify(manifest));
17
- writeFileSync(path.join(root, "server.cjs"), `require('node:http').createServer((q,s)=>s.end('ok')).listen(${port},'127.0.0.1')`);
18
- try {
19
- const options = { registry: { fixture: root }, stateRoot: path.join(root, "state"), timeout: 8000 };
20
- assert.equal((await stackAction("up", ["fixture"], options))[0].healthy, true);
21
- assert.equal((await stackAction("status", ["fixture"], options))[0].healthy, true);
22
- const other = path.join(root, "other");
23
- mkdirSync(other);
24
- writeFileSync(path.join(other, "qc.stack.json"), JSON.stringify({ ...manifest, name: "other" }));
25
- await assert.rejects(stackAction("up", ["fixture", "other"], { ...options, registry: { fixture: root, other } }), /Stack other: port .* is in use/);
26
- assert.equal((await stackAction("down", ["fixture"], options))[0].running, false);
27
- await new Promise(resolve => probe.listen(port, "127.0.0.1", resolve));
28
- await assert.rejects(stackAction("up", ["fixture"], options), /in use/);
29
- await new Promise(resolve => probe.close(resolve));
30
- } finally { if (probe.listening) await new Promise(resolve => probe.close(resolve)); rmSync(root, { recursive: true, force: true }); }
31
- });
32
- test("stack accepts a database on port 5432", () => {
33
- const manifest = { name: "x", up: "node app", down: "node stop", ports: { db: 5432 }, health: ["http://localhost:3000"], login: { kind: "auth0-session" } };
34
- assert.equal(validateManifest(manifest).ports.db, 5432);
35
- });
36
- test("stack refuses remote health URLs", () => {
37
- const manifest = { name: "x", up: "node app", down: "node stop", ports: { db: 5433 }, health: ["http://localhost:3000"], login: { kind: "auth0-session" } };
38
- manifest.health = ["https://cloud.example"];
39
- assert.throws(() => validateManifest(manifest), /localhost/);
40
- });
@@ -1,30 +0,0 @@
1
- import { existsSync, readFileSync, writeFileSync, rmSync } from "node:fs";
2
- import { spawn } from "node:child_process";
3
- import { pluginCommand, stopTree } from "./stack.mjs";
4
-
5
- const file = process.argv[2];
6
- const state = JSON.parse(readFileSync(file, "utf8"));
7
- const live = `${file}.${state.token}.live`;
8
- const stop = `${file}.${state.token}.stop`;
9
- state.pid = process.pid;
10
- writeFileSync(file, JSON.stringify(state), { mode: 0o600 });
11
- writeFileSync(live, state.token, { mode: 0o600 });
12
- const child = spawn(state.manifest.up, { cwd: state.repo, shell: true, detached: process.platform !== "win32", windowsHide: true, stdio: "inherit" });
13
- child.on("error", () => { state.error = "Cannot start plugin command"; writeFileSync(file, JSON.stringify(state)); });
14
- child.on("exit", code => { if (code) { state.error = `Plugin exited ${code}`; writeFileSync(file, JSON.stringify(state)); } });
15
- let refreshing = false;
16
- const timer = setInterval(async () => {
17
- if (existsSync(stop)) {
18
- clearInterval(timer);
19
- try { await pluginCommand(state.manifest.down, state.repo); }
20
- finally { await stopTree(child.pid); rmSync(live, { force: true }); rmSync(stop, { force: true }); process.exit(0); }
21
- }
22
- if (!refreshing && state.manifest.login.kind === "auth0-session") {
23
- refreshing = true;
24
- try {
25
- const { refreshStackSessions } = await import("../screens/stack-auth.mjs");
26
- await refreshStackSessions(state.manifest.name);
27
- } catch { /* The refresh ledger delays a failed session until its next due time. */ }
28
- finally { refreshing = false; }
29
- }
30
- }, 1000);