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
@@ -6,7 +6,47 @@
6
6
  "CLAUDE_CODE_DISABLE_BG_SHELL_PRESSURE_REAP": "1"
7
7
  },
8
8
  "permissions": {
9
- "defaultMode": "auto"
9
+ "defaultMode": "auto",
10
+ "allow": [
11
+ "Bash(powershell -Command \"Stop-Process -Id *)",
12
+ "Bash(powershell -NoProfile -Command \"Stop-Process -Id *)"
13
+ ],
14
+ "deny": [
15
+ "Read(**/.env)",
16
+ "Read(**/.env.local)",
17
+ "Read(**/.env.*.local)",
18
+ "Read(**/.env.production)",
19
+ "Read(**/*.pem)",
20
+ "Read(**/*.key)",
21
+ "Read(**/id_rsa*)",
22
+ "Read(**/id_ed25519*)",
23
+ "Read(~/.ssh/**)",
24
+ "Bash(git checkout*)",
25
+ "Bash(git -C * checkout*)",
26
+ "Bash(git switch*)",
27
+ "Bash(git -C * switch*)",
28
+ "Bash(git reset*)",
29
+ "Bash(git -C * reset*)",
30
+ "Bash(git stash*)",
31
+ "Bash(git -C * stash*)",
32
+ "Bash(git push --force*)",
33
+ "Bash(git push -f*)",
34
+ "Bash(git push --force-with-lease*)",
35
+ "Bash(git worktree prune*)",
36
+ "Bash(terraform apply*)"
37
+ ]
38
+ },
39
+ "autoMode": {
40
+ "environment": [
41
+ "**Local machine**: a single-user dev PC. The agent starts and stops its own local jobs (codex, node, vitest, flutter_tester, dart, adb, gradle, docker containers); stopping those is routine housekeeping",
42
+ "**Primary use of Claude Code**: software development",
43
+ "**Trusted repo**: Every git repository under `~/Documents/GitHub/`, with its worktrees under `.worktree/` and `.claude/worktrees/`",
44
+ "**Org-specific CLIs**: `qc` (architecture-kit: `qc worktree`, `qc codex-implement`, `qc throwaway-db`), `codex`, `gh`, `aws`, `flutter`, `dart`, `adb`"
45
+ ],
46
+ "allow": [
47
+ "$defaults",
48
+ "Stopping a local process on this PC by process ID (Stop-Process, taskkill, kill) when the user asked for it, or when the process is a stalled or orphaned job the agent or its subagents started (codex, node, vitest, flutter_tester, dart, adb, gradle). Check the process name first; never stop system processes, the user's editor, or the Claude Code process itself."
49
+ ]
10
50
  },
11
51
  "model": "opus",
12
52
  "skillOverrides": {
@@ -1,60 +0,0 @@
1
- import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import path from "node:path";
3
- import { discover, pairStates, catalogCoverage, scaffoldEntry } from "../screens/discovery.mjs";
4
- import { targetSession } from "../screens/stack-auth.mjs";
5
-
6
- /** Trigger: discovery artifacts drive pairing, coverage, and catalog scaffolds. */
7
- export async function runDiscovery(command, map, values, { chromium, say }) {
8
- const out = path.resolve(values.out ?? ".");
9
- mkdirSync(out, { recursive: true });
10
- const read = name => JSON.parse(readFileSync(path.join(out, `discovered-${name}.json`), "utf8"));
11
- if (command === "discover") {
12
- const target = map.targets[values.target];
13
- if (!target) throw new Error("Choose --target from the map");
14
- const timeout = Number(values.timeout ?? 15000);
15
- const depth = Number(values.depth ?? 4);
16
- const maxStates = Number(values["max-states"] ?? 500);
17
- if (!Number.isInteger(depth) || depth < 0 || !Number.isInteger(maxStates) || maxStates < 1) throw new Error("Invalid depth or state bound");
18
- const session = await targetSession(chromium, target, { timeout, signInTimeout: Number(values["sign-in-timeout"] ?? 180000), targetName: values.target, say });
19
- try {
20
- const routes = [...new Map(map.screens.flatMap(screen => screen.targets[values.target]?.path ? [screen.targets[values.target].path] : []).map(route => [route, route])).values()];
21
- const result = await discover(session, { ...target, routes: target.routes ?? routes }, { out, targetName: values.target, widths: map.widths, depth, timeout, maxStates, allowWrites: values["allow-writes"], say });
22
- say(JSON.stringify({ target: result.target, states: result.states.length, counts: result.counts, errors: result.errors.length, unresolvedRoutes: result.unresolvedRoutes, blockedRequests: result.blockedRequests, complete: result.complete }));
23
- return result.complete ? 0 : 1;
24
- } finally { await session.close(); }
25
- }
26
- if (command === "pair") {
27
- const names = values.targets?.split(",");
28
- if (names?.length !== 2) throw new Error("pair requires --targets <legacy,mono>");
29
- const pairs = pairStates(read(names[0]).states, read(names[1]).states);
30
- const result = { targets: names, pairs, counts: Object.fromEntries(["paired", "legacy-only", "mono-only"].map(kind => [kind, pairs.filter(item => item.kind === kind).length])) };
31
- writeFileSync(path.join(out, "pairs.json"), JSON.stringify(result, null, 2));
32
- say(JSON.stringify(result.counts));
33
- return 0;
34
- }
35
- const names = values.target ? [values.target] : readdirSync(out).filter(name => /^discovered-.+\.json$/.test(name)).map(name => name.slice(11, -5));
36
- if (!names.length) throw new Error("No discoveries found");
37
- if (command === "coverage") {
38
- const rows = names.map(name => {
39
- const discovered = read(name);
40
- return { target: name, complete: discovered.complete, ...catalogCoverage(discovered.states, map.screens, map.excluded, name) };
41
- });
42
- writeFileSync(path.join(out, "coverage.json"), JSON.stringify(rows, null, 2));
43
- for (const row of rows) say(JSON.stringify({ target: row.target, complete: row.complete, covered: row.covered, total: row.total, missing: row.missing.length }));
44
- return rows.some(row => !row.complete || row.missing.length) ? 1 : 0;
45
- }
46
- const directory = path.resolve(values["catalog-out"] ?? path.join(out, "catalog"));
47
- mkdirSync(directory, { recursive: true });
48
- let written = 0;
49
- for (const name of names) {
50
- const family = map.targets[name]?.family ?? name.split("-")[0];
51
- for (const state of read(name).states) {
52
- const file = path.join(directory, `${name}-${state.id}.ts`);
53
- if (existsSync(file)) continue;
54
- writeFileSync(file, scaffoldEntry(state, family), { flag: "wx" });
55
- written++;
56
- }
57
- }
58
- say(JSON.stringify({ directory, written }));
59
- return 0;
60
- }
@@ -1,84 +0,0 @@
1
- import path from "node:path";
2
- import { parseArgs } from "node:util";
3
- import { loadMap } from "../screens/map.mjs";
4
- import { captureScreens } from "../screens/capture.mjs";
5
- import { authStatus, targetSession } from "../screens/stack-auth.mjs";
6
- import { applyCatalog, openScreen } from "../screens/catalog.mjs";
7
- import { runDiscovery } from "./screens-discovery.mjs";
8
- import { setupLocal } from "../screens/setup.mjs";
9
- import { installWriteGuard } from "../screens/write-guard.mjs";
10
-
11
- export const USAGE = `qc screens [run [names...]|list|open <name>|auth status|auth <target> --headed|setup]
12
- qc screens discover|pair|coverage|scaffold --map <json> --out <dir>
13
- --map <json> [--targets <left,right>] [--target <name>] [--out <dir>]
14
- [--only <names>] [--changed <target>] [--height <pixels>]
15
- [--timeout <milliseconds>] [--sign-in-timeout <milliseconds>]
16
- [--depth <levels>] [--max-states <count>] [--allow-writes] [--catalog-out <dir>]
17
-
18
- Chrome must be installed. Sessions stay in ~/.qc/screens.
19
- Catalog modules live outside the kit. open waits until you close its window.`;
20
-
21
- /** Trigger: screen commands share the same catalog, sessions, and map. */
22
- export async function runScreens(argv, { say = console.error, sessionFactory = targetSession } = {}) {
23
- let values, positionals;
24
- const command = argv[0]?.startsWith("--") || !argv.length ? "run" : argv.shift();
25
- const authTarget = command === "auth" ? argv.shift() : undefined;
26
- const authCommand = command === "auth" && authTarget === "status";
27
- try {
28
- ({ values, positionals } = parseArgs({ args: argv, allowPositionals: true, strict: true, options: { map: { type: "string" }, targets: { type: "string" }, target: { type: "string" }, out: { type: "string" }, only: { type: "string" }, changed: { type: "string" }, height: { type: "string" }, timeout: { type: "string" }, "sign-in-timeout": { type: "string" }, depth: { type: "string" }, "max-states": { type: "string" }, "allow-writes": { type: "boolean" }, "catalog-out": { type: "string" }, headed: { type: "boolean" }, help: { type: "boolean" } } }));
29
- if (values.help) { say(USAGE); return 0; }
30
- if (!values.map) throw new Error("--map is required");
31
- for (const field of ["height", "timeout", "sign-in-timeout"]) if (values[field] !== undefined && (!Number.isInteger(Number(values[field])) || Number(values[field]) < 1)) throw new Error(`--${field} must be a positive integer`);
32
- const selectedTargets = values.targets?.split(",") ?? (values.target ? [values.target] : command === "auth" && !authCommand && authTarget ? [authTarget] : command === "list" ? [] : undefined);
33
- const map = await applyCatalog(loadMap(path.resolve(values.map), { targets: selectedTargets }), path.resolve(values.map));
34
- if (command === "list") {
35
- for (const item of map.screens) say(`${item.name}\t${Object.keys(item.targets).join(", ")}`);
36
- return 0;
37
- }
38
- const { chromium } = await import("playwright");
39
- if (command === "setup") {
40
- const target = map.targets[values.target];
41
- if (!target) throw new Error("Choose --target from the map");
42
- say(JSON.stringify(await setupLocal(target, values.target, { chromium, timeout: Number(values.timeout ?? 15000), signInTimeout: Number(values["sign-in-timeout"] ?? 180000), say })));
43
- return 0;
44
- }
45
- if (["discover", "pair", "coverage", "scaffold"].includes(command)) return await runDiscovery(command, map, values, { chromium, say });
46
- const timeout = Number(values.timeout ?? 15000);
47
- const signInTimeout = Number(values["sign-in-timeout"] ?? 180000);
48
- if (authCommand) {
49
- const targets = values.target ? { [values.target]: map.targets[values.target] } : map.targets;
50
- if (Object.values(targets).some(target => !target)) throw new Error("Unknown target");
51
- for (const row of await authStatus(chromium, targets, { timeout })) say(JSON.stringify(row));
52
- return 0;
53
- }
54
- if (command === "auth") {
55
- const target = map.targets[authTarget];
56
- if (!target || !values.headed) throw new Error("Choose auth <target> --headed from the map");
57
- const session = await targetSession(chromium, target, { timeout, signInTimeout, say, targetName: authTarget, allowInteractive: true, headed: true });
58
- await session.close();
59
- say(`${authTarget}: signed in`);
60
- return 0;
61
- }
62
- if (command === "open") {
63
- const target = map.targets[values.target];
64
- const item = map.screens.find(item => item.name === positionals[0]);
65
- const route = item?.targets[values.target];
66
- if (!target || !route) throw new Error("Choose a screen name and --target from the map");
67
- const allowWrites = values["allow-writes"] === true;
68
- const session = await sessionFactory(chromium, target, { timeout, signInTimeout, say, targetName: values.target, headed: true, allowWrites });
69
- try {
70
- await installWriteGuard(session.context, target, { allowWrites });
71
- await session.page.setViewportSize({ width: map.widths[0], height: Number(values.height ?? 900) });
72
- if (route.open) await openScreen(session.page, target, route, { targetName: values.target, screenName: item.name, out: path.resolve(values.out ?? "."), timeout });
73
- else await session.page.goto(new URL(route.path, target.baseUrl).href, { timeout });
74
- await new Promise(resolve => session.page.once("close", resolve));
75
- } finally { await session.close().catch(() => {}); }
76
- return 0;
77
- }
78
- if (command !== "run") throw new Error(`Unknown screens command ${command}`);
79
- if (!values.targets || !values.out) throw new Error("--targets and --out are required");
80
- const report = await captureScreens(map, { targets: values.targets.split(",").map(name => name.trim()), out: path.resolve(values.out), only: positionals.length ? positionals.join(",") : values.only, changed: values.changed, height: Number(values.height ?? 900), timeout, signInTimeout, allowWrites: values["allow-writes"] === true }, { chromium, say });
81
- for (const row of report) say(JSON.stringify(row));
82
- return report.some(row => row.error) ? 1 : 0;
83
- } catch (error) { say(error.exitCode === 4 ? error.message : `qc screens: ${error.message}`); return error.exitCode === 4 ? 4 : 1; }
84
- }
package/src/cli/stack.mjs DELETED
@@ -1,14 +0,0 @@
1
- import { parseArgs } from "node:util";
2
- import { stackAction } from "../stack/stack.mjs";
3
-
4
- /** Trigger: a repository plugin owns each stack's lifecycle. */
5
- export async function runStack(argv, { say = console.log } = {}) {
6
- try {
7
- const [action, ...rest] = argv;
8
- const { values, positionals } = parseArgs({ args: rest, allowPositionals: true, options: { timeout: { type: "string", default: "120000" } } });
9
- const timeout = Number(values.timeout);
10
- if (!Number.isInteger(timeout) || timeout < 1) throw new Error("--timeout must be a positive integer");
11
- for (const row of await stackAction(action, positionals, { timeout })) say(JSON.stringify(row));
12
- return 0;
13
- } catch (error) { say(`qc stack: ${error.message}`); return 1; }
14
- }
@@ -1,127 +0,0 @@
1
- // `qc throwaway-db -- <command>`: run a command on a database of its own, in a container on a free port.
2
- // It never takes a port the local stack owns, and it removes the container once the command exits.
3
-
4
- import { spawnSync } from "node:child_process";
5
- import { randomBytes } from "node:crypto";
6
- import net from "node:net";
7
- import { parseArgs } from "node:util";
8
- import { merge } from "../config.mjs";
9
- import { commandLine, runInShell, splitAtDashes } from "./child-run.mjs";
10
-
11
- export const USAGE = `qc throwaway-db — run a command on a database of its own
12
-
13
- qc throwaway-db [--port <n>|auto] -- <command...>
14
- start a postgres container on a free port (auto by default), wait until it is ready, run the
15
- command with the variables of throwawayDb.env filled in, and remove the container after.
16
-
17
- qc.config.json "throwawayDb": image, user, database, env (each value may hold {url},
18
- {host}, {port}, {user}, {password}, {database}), avoidPorts, and readySeconds. The password is random for each run.`;
19
-
20
- export const throwawayDefaults = {
21
- image: "postgres:17-alpine",
22
- user: "postgres",
23
- database: "app",
24
- env: { DATABASE_URL: "{url}" },
25
- avoidPorts: [5432],
26
- readySeconds: 60,
27
- };
28
-
29
- const HOST = "127.0.0.1";
30
- const PORT_TRIES = 10;
31
-
32
- function listenOnZero() {
33
- return new Promise((resolve, reject) => {
34
- const server = net.createServer();
35
- server.unref();
36
- server.on("error", reject);
37
- server.listen(0, HOST, () => {
38
- const { port } = server.address();
39
- server.close(() => resolve(port));
40
- });
41
- });
42
- }
43
-
44
- /** A port the OS calls free, never one of `avoid`. */
45
- export async function freePort(avoid = [], open = listenOnZero) {
46
- for (let tries = 0; tries < PORT_TRIES; tries += 1) {
47
- const port = await open();
48
- if (!avoid.includes(port)) return port;
49
- }
50
- throw new Error(`no free port outside ${avoid.join(", ")} after ${PORT_TRIES} tries`);
51
- }
52
-
53
- /** Each variable of the template, with `{name}` replaced by its value; an unknown name stays as written. */
54
- export function fillEnv(template, values) {
55
- return Object.fromEntries(
56
- Object.entries(template).map(([name, value]) => [name, String(value).replace(/\{(\w+)\}/g, (whole, key) => (key in values ? String(values[key]) : whole))]),
57
- );
58
- }
59
-
60
- /** The `docker run` arguments: a detached container that removes itself, published on the loopback address only. */
61
- export function dockerRunArgs(settings, name, port, password) {
62
- return [
63
- "run", "--detach", "--rm", "--name", name, "--publish", `${HOST}:${port}:5432`,
64
- "--env", `POSTGRES_USER=${settings.user}`, "--env", `POSTGRES_PASSWORD=${password}`, "--env", `POSTGRES_DB=${settings.database}`,
65
- settings.image,
66
- ];
67
- }
68
-
69
- function dockerSync(args) {
70
- const result = spawnSync("docker", args, { encoding: "utf8", windowsHide: true });
71
- return { code: result.status ?? 1, err: (result.stderr ?? "").trim() || (result.error?.message ?? "") };
72
- }
73
-
74
- /** `qc throwaway-db`. @returns the command's exit code, 1 when the database did not start, or 2 on a usage error */
75
- export async function runThrowawayDb(config, argv, deps = {}) {
76
- const {
77
- docker = dockerSync,
78
- run = runInShell,
79
- open = listenOnZero,
80
- sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
81
- now = Date.now,
82
- env = process.env,
83
- say = (line) => console.error(line),
84
- name = `qc-throwaway-${randomBytes(4).toString("hex")}`,
85
- password = randomBytes(16).toString("hex"),
86
- } = deps;
87
- const merged = merge(throwawayDefaults, config.throwawayDb ?? {});
88
- const settings = { ...merged, avoidPorts: [...new Set([5432, ...merged.avoidPorts])] };
89
- const { flags, command } = splitAtDashes(argv);
90
- let port;
91
- try {
92
- const { values } = parseArgs({ args: flags, options: { port: { type: "string" } }, strict: true });
93
- if (command.length === 0) throw new Error("name the command after --");
94
- const asked = values.port ?? "auto";
95
- if (asked === "auto") port = await freePort(settings.avoidPorts, open);
96
- else {
97
- port = Number(asked);
98
- if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`--port must be auto or a port number, got ${asked}`);
99
- if (settings.avoidPorts.includes(port)) throw new Error(`port ${port} is in throwawayDb.avoidPorts; use --port auto`);
100
- }
101
- } catch (error) {
102
- say(`qc throwaway-db: ${error.message}\n\n${USAGE}`);
103
- return 2;
104
- }
105
- say(`qc throwaway-db: starting ${name} on port ${port}`);
106
- const started = docker(dockerRunArgs(settings, name, port, password));
107
- if (started.code !== 0) {
108
- say(`qc throwaway-db: docker run failed: ${started.err}`);
109
- return 1;
110
- }
111
- try {
112
- const deadline = now() + settings.readySeconds * 1000;
113
- while (docker(["exec", name, "pg_isready", "-h", HOST, "-U", settings.user, "-d", settings.database]).code !== 0) {
114
- if (now() >= deadline) {
115
- say(`qc throwaway-db: ${name} was not ready after ${settings.readySeconds} s`);
116
- return 1;
117
- }
118
- await sleep(1000);
119
- }
120
- const url = `postgres://${encodeURIComponent(settings.user)}:${encodeURIComponent(password)}@${HOST}:${port}/${settings.database}`;
121
- const values = { url, host: HOST, port, user: settings.user, password, database: settings.database };
122
- return await run(commandLine(command), { ...env, ...fillEnv(settings.env, values) });
123
- } finally {
124
- say(`qc throwaway-db: removing ${name}`);
125
- if (docker(["rm", "--force", name]).code !== 0) say(`qc throwaway-db: remove it by hand: docker rm --force ${name}`);
126
- }
127
- }
@@ -1,83 +0,0 @@
1
- import { strict as assert } from "node:assert";
2
- import { randomBytes } from "node:crypto";
3
- import { test } from "node:test";
4
- import { dockerRunArgs, fillEnv, freePort, runThrowawayDb, throwawayDefaults } from "./throwaway-db.mjs";
5
-
6
- test("a free port skips each port to avoid", async () => {
7
- const ports = [5432, 55001];
8
- assert.equal(await freePort([5432], async () => ports.shift()), 55001);
9
- });
10
-
11
- test("the OS hands out a real free port that is never 5432", async () => {
12
- const port = await freePort([5432]);
13
- assert.ok(Number.isInteger(port) && port > 0 && port !== 5432);
14
- });
15
-
16
- test("the env template fills the url, the port, and the rest, and keeps a literal", () => {
17
- const env = fillEnv({ DATABASE_URL: "{url}", PGPORT: "{port}", LIVE: "1" }, { url: "postgres://u:p@127.0.0.1:55001/app", port: 55001 });
18
- assert.deepEqual(env, { DATABASE_URL: "postgres://u:p@127.0.0.1:55001/app", PGPORT: "55001", LIVE: "1" });
19
- });
20
-
21
- test("the container publishes only on the loopback address", () => {
22
- const args = dockerRunArgs(throwawayDefaults, "qc-throwaway-1", 55001, generated);
23
- assert.ok(args.includes("127.0.0.1:55001:5432"));
24
- assert.equal(args.at(-1), throwawayDefaults.image);
25
- });
26
-
27
- const generated = randomBytes(8).toString("hex");
28
-
29
- /** A docker that answers each call, and records it. */
30
- function fakeDocker(calls, { readyAfter = 1, runCode = 0 } = {}) {
31
- let checks = 0;
32
- return (args) => {
33
- calls.push(args.slice(0, 2).join(" "));
34
- if (args[0] === "run") return { code: runCode, err: runCode === 0 ? "" : "no daemon" };
35
- if (args[0] === "exec") return { code: (checks += 1) > readyAfter ? 0 : 1, err: "" };
36
- return { code: 0, err: "" };
37
- };
38
- }
39
-
40
- test("the command runs on its own database on a free port, and the container is removed after it", async () => {
41
- const calls = [];
42
- let seen = null;
43
- const code = await runThrowawayDb({ throwawayDb: { env: { LIVE_DB: "1" } } }, ["--", "pnpm", "vitest", "run", "a.test.ts"], {
44
- docker: fakeDocker(calls),
45
- open: async () => 55002,
46
- sleep: async () => {},
47
- run: async (command, env) => {
48
- seen = { command, env };
49
- return 5;
50
- },
51
- env: {},
52
- say: () => {},
53
- name: "qc-throwaway-test",
54
- password: generated,
55
- });
56
- assert.equal(code, 5);
57
- assert.equal(seen.command, "pnpm vitest run a.test.ts");
58
- assert.equal(seen.env.DATABASE_URL, `postgres://postgres:${encodeURIComponent(generated)}@127.0.0.1:55002/app`);
59
- assert.equal(seen.env.LIVE_DB, "1");
60
- assert.deepEqual(calls, ["run --detach", "exec qc-throwaway-test", "exec qc-throwaway-test", "rm --force"]);
61
- });
62
-
63
- test("an explicit port to avoid is refused, and a docker that cannot start removes nothing", async () => {
64
- const deps = { docker: fakeDocker([]), open: async () => 55003, sleep: async () => {}, run: async () => 0, env: {}, say: () => {} };
65
- assert.equal(await runThrowawayDb({}, ["--port", "5432", "--", "x"], deps), 2);
66
- const calls = [];
67
- assert.equal(await runThrowawayDb({}, ["--", "x"], { ...deps, docker: fakeDocker(calls, { runCode: 1 }) }), 1);
68
- assert.deepEqual(calls, ["run --detach"]);
69
- });
70
-
71
- test("port 5432 stays avoided when the config lists other ports to avoid", async () => {
72
- const deps = { docker: fakeDocker([]), open: async () => 55003, sleep: async () => {}, run: async () => 0, env: {}, say: () => {} };
73
- const config = { throwawayDb: { avoidPorts: [5433] } };
74
- assert.equal(await runThrowawayDb(config, ["--port", "5432", "--", "x"], deps), 2);
75
- assert.equal(await runThrowawayDb(config, ["--port", "5433", "--", "x"], deps), 2);
76
- const opened = [5432, 5433, 55003];
77
- let next = 0;
78
- const ports = [];
79
- const run = async () => 0;
80
- const docker = (args) => { if (args[0] === "run") ports.push(args[args.indexOf("--publish") + 1]); return { code: 0, err: "" }; };
81
- await runThrowawayDb(config, ["--", "x"], { ...deps, docker, run, open: async () => opened[next++] });
82
- assert.deepEqual(ports, ["127.0.0.1:55003:5432"]);
83
- });
@@ -1,41 +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 { browserSession, seedSession } from "./auth.mjs";
7
-
8
- for (const method of ["profile", "state", "headed", "seed"]) {
9
- test(`${method} context blocks service workers`, async t => {
10
- const root = mkdtempSync(path.join(os.tmpdir(), "qc-context-"));
11
- t.after(() => rmSync(root, { recursive: true, force: true }));
12
- t.mock.method(os, "homedir", () => root);
13
- const directory = path.join(root, ".qc", "screens");
14
- mkdirSync(path.join(directory, "state"), { recursive: true });
15
- const emptyState = { cookies: [], origins: [] };
16
- if (method === "state") writeFileSync(path.join(directory, "state", "tenant.test.json"), JSON.stringify(emptyState));
17
- if (method === "seed") writeFileSync(path.join(directory, "local-4567.json"), JSON.stringify(emptyState));
18
- const source = path.join(root, "chrome");
19
- if (method === "profile") {
20
- mkdirSync(source);
21
- writeFileSync(path.join(source, "Local State"), JSON.stringify({ profile: { last_used: "Default" } }));
22
- }
23
- const target = { baseUrl: "http://localhost:4567", auth: { domain: "tenant.test", signedIn: "main" } };
24
- const context = {
25
- close: async () => {}, route: async () => {}, storageState: async () => emptyState,
26
- newPage: async () => ({ goto: async () => {}, url: () => target.baseUrl, locator: () => ({ first: () => ({ waitFor: async () => {} }) }) }),
27
- };
28
- const factories = [];
29
- const chromium = {
30
- launchPersistentContext: async (_directory, options) => { factories.push(["persistent", options]); return context; },
31
- launch: async () => ({ close: async () => {}, newContext: async options => { factories.push(["new", options]); return context; } }),
32
- };
33
- const session = await (method === "seed"
34
- ? seedSession(chromium, target, { savedOnly: true })
35
- : browserSession(chromium, target, { chromeProfile: source, allowInteractive: method !== "state", say: () => {} }));
36
- await session.close();
37
- assert.equal(factories.length, 1);
38
- assert.equal(factories[0][0], method === "profile" ? "persistent" : "new");
39
- assert.equal(factories[0][1].serviceWorkers, "block");
40
- });
41
- }
@@ -1,147 +0,0 @@
1
- import test from "node:test";
2
- import assert from "node:assert/strict";
3
- import http from "node:http";
4
- import { randomUUID } from "node:crypto";
5
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, readdirSync, rmSync } from "node:fs";
6
- import os from "node:os";
7
- import path from "node:path";
8
- import { chromium } from "playwright";
9
- import { browserSession, seedSession } from "./auth.mjs";
10
- import { runScreens } from "../cli/screens.mjs";
11
- import { captureScreens } from "./capture.mjs";
12
- import { chromeMissing } from "./chrome.mjs";
13
-
14
- const noChrome = await chromeMissing(chromium);
15
-
16
- async function fixture(t) {
17
- const root = mkdtempSync(path.join(os.tmpdir(), "qc-auth-run-"));
18
- t.mock.method(os, "homedir", () => root);
19
- const requests = [];
20
- const server = http.createServer((req, res) => {
21
- requests.push(req.url);
22
- res.setHeader("content-type", "text/html");
23
- if (req.url.startsWith("/bff/login") && req.headers.cookie?.includes("sso=yes")) {
24
- res.writeHead(302, { "set-cookie": "app=yes; Path=/; HttpOnly", location: "/projects" }).end();
25
- } else if (req.url === "/projects" && req.headers.cookie?.includes("app=yes")) res.end('<main id="signed">Projects</main>');
26
- else res.end('<input id="user"><input id="pass" type="password"><button id="submit">Login</button>');
27
- });
28
- await new Promise(resolve => server.listen(0, "127.0.0.1", resolve));
29
- t.after(async () => { await new Promise(resolve => server.close(resolve)); rmSync(root, { recursive: true, force: true }); });
30
- const baseUrl = `http://127.0.0.1:${server.address().port}`;
31
- const target = { baseUrl, auth: { mode: "browser-session", domain: "fixture.auth0.test", path: "/projects", signedIn: "#signed" } };
32
- const state = path.join(root, ".qc/screens/state/fixture.auth0.test.json");
33
- mkdirSync(path.dirname(state), { recursive: true });
34
- const save = cookies => writeFileSync(state, JSON.stringify({ cookies: cookies.map(name => ({ name, value: "yes", domain: "127.0.0.1", path: "/", expires: -1, httpOnly: true, secure: false, sameSite: "Lax" })), origins: [] }));
35
- return { root, requests, target, state, save };
36
- }
37
-
38
- test("expired application state refreshes once through the login path and persists the renewed cookie", { skip: noChrome }, async t => {
39
- const f = await fixture(t);
40
- f.save(["sso"]);
41
- const session = await browserSession(chromium, f.target, { targetName: "new-local", timeout: 3000, allowInteractive: false });
42
- await session.close();
43
- assert.equal(f.requests.filter(p => p.startsWith("/bff/login")).length, 1);
44
- assert.ok(JSON.parse(readFileSync(f.state)).cookies.some(c => c.name === "app"));
45
- });
46
-
47
- test("seed errors name the target and failing field without exposing browser diagnostics or credentials", { skip: noChrome }, async t => {
48
- const f = await fixture(t);
49
- const target = { ...f.target, auth: { ...f.target.auth, mode: "seed-login", path: "/login", userSelector: "#user", passwordSelector: "#missing", submitSelector: "#submit" } };
50
- await assert.rejects(seedSession(chromium, target, { targetName: "old-local", credentials: { user: "test", password: randomUUID() }, timeout: 3000 }), error => {
51
- assert.equal(error.message, "old-local: seed sign-in failed at the password field");
52
- return true;
53
- });
54
- });
55
-
56
- test("run stops with code four and one human instruction without capturing or retrying", { skip: noChrome }, async t => {
57
- const f = await fixture(t);
58
- f.save([]);
59
- const map = path.join(f.root, "map.json");
60
- writeFileSync(map, JSON.stringify({ widths: [200], targets: { "new-local": f.target, other: f.target }, screens: [{ name: "projects", targets: { "new-local": { path: "/projects" }, other: { path: "/projects" } } }] }));
61
- const lines = [];
62
- const code = await runScreens(["run", "projects", "--map", map, "--targets", "new-local,other", "--out", path.join(f.root, "out"), "--timeout", "3000", "--sign-in-timeout", "100"], { say: line => lines.push(line) });
63
- assert.equal(code, 4);
64
- assert.deepEqual(lines, ["new-local: needs a person to sign in (run qc screens auth new-local --headed)"]);
65
- assert.equal(f.requests.filter(p => p.startsWith("/bff/login")).length, 1);
66
- });
67
-
68
- test("capture checks each target once before navigating any screen and closes earlier sessions on failure", async t => {
69
- const f = await fixture(t);
70
- const events = [];
71
- await assert.rejects(captureScreens({ widths: [200], targets: { first: f.target, second: f.target }, screens: [{ name: "projects", targets: { first: { path: "/projects" }, second: { path: "/projects" } } }] }, { targets: ["first", "second"], out: path.join(f.root, "out") }, {
72
- sessionFactory: async (_chromium, _target, options) => {
73
- events.push(options.targetName);
74
- assert.equal(options.allowInteractive, false);
75
- if (options.targetName === "second") throw new Error("second failed");
76
- return { context: { route: async () => {} }, page: { setViewportSize: async () => { throw new Error("capture before preflight"); } }, close: async () => events.push("closed") };
77
- },
78
- }), /second failed/);
79
- assert.deepEqual(events, ["first", "second", "closed"]);
80
- });
81
-
82
-
83
- // A headed browser needs a display, which a Linux CI runner lacks.
84
- test("headed auth accepts the named target and saves a valid session", { skip: noChrome || (process.platform === "linux" && !process.env.DISPLAY) }, async t => {
85
- const f = await fixture(t);
86
- f.save(["app"]);
87
- const map = path.join(f.root, "map.json");
88
- writeFileSync(map, JSON.stringify({ widths: [200], targets: { "new-local": f.target, other: f.target }, screens: [{ name: "projects", targets: { "new-local": { path: "/projects" }, other: { path: "/projects" } } }] }));
89
- const lines = [];
90
- assert.equal(await runScreens(["auth", "new-local", "--headed", "--map", map, "--timeout", "3000"], { say: line => lines.push(line) }), 0);
91
- assert.deepEqual(lines, ["new-local: signed in"]);
92
- assert.ok(JSON.parse(readFileSync(f.state)).cookies.some(c => c.name === "app"));
93
- });
94
-
95
- test("parallel sessions preserve the shared saved state and write a complete refresh ledger", { skip: noChrome }, async t => {
96
- const f = await fixture(t);
97
- f.save(["sso"]);
98
- const { targetSession } = await import("./stack-auth.mjs");
99
- const sessions = await Promise.all(Array.from({ length: 3 }, () => targetSession(chromium, f.target, { targetName: "new-local", timeout: 3000, allowInteractive: false })));
100
- await Promise.all(sessions.map(s => s.close()));
101
- assert.equal(f.requests.filter(p => p.startsWith("/bff/login")).length, 1);
102
- assert.ok(JSON.parse(readFileSync(f.state)).cookies.some(c => c.name === "app"));
103
- const files = readdirSync(path.join(f.root, ".qc/screens"));
104
- const ledger = files.filter(name => /^session-.*\.json$/.test(name));
105
- assert.equal(ledger.length, 1);
106
- const record = JSON.parse(readFileSync(path.join(f.root, ".qc/screens", ledger[0])));
107
- assert.equal(record.target.baseUrl, f.target.baseUrl);
108
- assert.ok(Number.isFinite(Date.parse(record.lastRefreshed)));
109
- assert.equal(files.some(name => name.endsWith(".lock") || name.endsWith(".tmp")), false);
110
- assert.deepEqual(readdirSync(path.dirname(f.state)), ["fixture.auth0.test.json"]);
111
- });
112
-
113
- test("a browser launch failure names the target and method without asking for human sign-in", async t => {
114
- const f = await fixture(t);
115
- f.save([]);
116
- await assert.rejects(browserSession({ launch: async () => { throw new Error("private browser diagnostics"); } }, f.target, { targetName: "new-local", allowInteractive: false }), error => {
117
- assert.equal(error.message, "new-local: browser-session sign-in failed at the browser");
118
- assert.equal(error.exitCode, undefined);
119
- return true;
120
- });
121
- });
122
-
123
- test("--allow-writes reaches the capture write guard as well as the session", async t => {
124
- const f = await fixture(t);
125
- const verdicts = [];
126
- const report = await captureScreens({ widths: [200], targets: { first: f.target, second: f.target }, screens: [{ name: "projects", targets: { first: { path: "/projects" }, second: { path: "/projects" } } }] }, { targets: ["first", "second"], out: path.join(f.root, "out"), allowWrites: true }, {
127
- say: () => {},
128
- sessionFactory: async (_chromium, _target, options) => {
129
- assert.equal(options.allowWrites, true);
130
- const context = { route: async (_pattern, handler) => {
131
- await handler({ request: () => ({ method: () => "POST", url: () => `${f.target.baseUrl}/api/items` }), fallback: async () => verdicts.push("allowed"), abort: async () => verdicts.push("blocked") });
132
- } };
133
- return { context, page: { setViewportSize: async () => { throw new Error("stop after the guard"); } }, close: async () => {} };
134
- },
135
- });
136
- assert.equal(report[0].error.message, "stop after the guard");
137
- assert.deepEqual(verdicts, ["allowed", "allowed"]);
138
- });
139
-
140
- test("a cached target also passes preflight before a changed-target capture", async t => {
141
- const f = await fixture(t);
142
- const names = [];
143
- await assert.rejects(captureScreens({ widths: [200], targets: { first: f.target, second: f.target }, screens: [{ name: "projects", targets: { first: { path: "/projects" }, second: { path: "/projects" } } }] }, { targets: ["first", "second"], changed: "second", out: path.join(f.root, "out") }, {
144
- sessionFactory: async (_chromium, _target, options) => { names.push(options.targetName); throw new Error("preflight failed"); },
145
- }), /preflight failed/);
146
- assert.deepEqual(names, ["first"]);
147
- });