architecture-harness 0.21.2 → 0.22.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 (68) hide show
  1. package/package.json +8 -3
  2. package/src/cli/check.mjs +61 -0
  3. package/src/cli/child-run.mjs +39 -0
  4. package/src/cli/child-run.test.mjs +16 -0
  5. package/src/cli/ci-template.test.mjs +28 -0
  6. package/src/cli/codex-implement.mjs +72 -3
  7. package/src/cli/codex-implement.test.mjs +141 -4
  8. package/src/cli/dispatch-guard.mjs +24 -1
  9. package/src/cli/dispatch-guard.test.mjs +30 -0
  10. package/src/cli/dispatch-reminder.mjs +4 -4
  11. package/src/cli/dispatch-reminder.test.mjs +3 -3
  12. package/src/cli/dispatch-slot.mjs +12 -0
  13. package/src/cli/gate-slot.mjs +151 -0
  14. package/src/cli/gate-slot.test.mjs +90 -0
  15. package/src/cli/integrate.mjs +122 -0
  16. package/src/cli/integrate.test.mjs +94 -0
  17. package/src/cli/ledger.mjs +25 -3
  18. package/src/cli/ledger.test.mjs +9 -0
  19. package/src/cli/merge-guard.mjs +13 -3
  20. package/src/cli/merge-guard.test.mjs +24 -1
  21. package/src/cli/migrations.mjs +127 -0
  22. package/src/cli/migrations.test.mjs +94 -0
  23. package/src/cli/plugin-agents.test.mjs +35 -8
  24. package/src/cli/qc.mjs +44 -0
  25. package/src/cli/report-stop.mjs +3 -0
  26. package/src/cli/report-stop.test.mjs +8 -0
  27. package/src/cli/retry-failed.mjs +80 -0
  28. package/src/cli/retry-failed.test.mjs +51 -0
  29. package/src/cli/review-gate.mjs +16 -7
  30. package/src/cli/slot-guard.mjs +43 -0
  31. package/src/cli/slot-guard.test.mjs +28 -0
  32. package/src/cli/task-gate-review.test.mjs +10 -0
  33. package/src/cli/task-gate.mjs +39 -7
  34. package/src/cli/task-gate.test.mjs +45 -0
  35. package/src/cli/throwaway-db.mjs +127 -0
  36. package/src/cli/throwaway-db.test.mjs +83 -0
  37. package/src/cli/ui-reuse-hint.mjs +89 -0
  38. package/src/cli/ui-reuse-hint.test.mjs +60 -0
  39. package/src/cli/ui.mjs +181 -0
  40. package/src/cli/ui.test.mjs +137 -0
  41. package/src/cli/watch.mjs +211 -0
  42. package/src/cli/watch.test.mjs +246 -0
  43. package/src/config.mjs +27 -2
  44. package/src/descriptions.mjs +3 -0
  45. package/src/gates/contract-keys.mjs +33 -0
  46. package/src/gates/contract-keys.test.mjs +38 -0
  47. package/src/gates/migration-numbers.mjs +1 -1
  48. package/src/gates/migration-numbers.test.mjs +1 -0
  49. package/src/gates/ui-catalog.mjs +45 -0
  50. package/src/gates/ui-catalog.test.mjs +48 -0
  51. package/src/gates/ui-dupes.mjs +36 -0
  52. package/src/gates/ui-dupes.test.mjs +29 -0
  53. package/src/ui/catalog.mjs +87 -0
  54. package/src/ui/catalog.test.mjs +54 -0
  55. package/src/ui/class-sites.mjs +151 -0
  56. package/src/ui/class-sites.test.mjs +41 -0
  57. package/src/ui/codemod.mjs +138 -0
  58. package/src/ui/codemod.test.mjs +140 -0
  59. package/src/ui/components.mjs +176 -0
  60. package/src/ui/components.test.mjs +87 -0
  61. package/src/ui/dupes.mjs +141 -0
  62. package/src/ui/dupes.test.mjs +85 -0
  63. package/src/ui/find.mjs +45 -0
  64. package/src/ui/find.test.mjs +48 -0
  65. package/src/ui/options.mjs +40 -0
  66. package/src/ui/scan.mjs +78 -0
  67. package/src/ui/typescript.mjs +29 -0
  68. package/templates/github/workflows/ci.yml +54 -0
@@ -0,0 +1,78 @@
1
+ // The I/O side of the UI tools: list the repository, read the component files, parse them, and write the
2
+ // catalog. A repository's codegen imports `writeCatalog` from `architecture-harness/ui/scan` so that its
3
+ // own codegen command writes the catalog, as it writes every other generated file.
4
+
5
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
6
+ import path from "node:path";
7
+ import { ignoresOf } from "../config.mjs";
8
+ import { globMatcher } from "../glob.mjs";
9
+ import { repoFiles } from "../cli/repo-files.mjs";
10
+ import { baselineOf, catalogEntries, renderCatalog } from "./catalog.mjs";
11
+ import { componentFileMatcher, expandBraces, uiOptions } from "./options.mjs";
12
+ import { loadTypeScript } from "./typescript.mjs";
13
+
14
+ /** What writes the catalog: this command, or a codegen that calls `writeCatalog`. */
15
+ export const CATALOG_COMMAND = "qc ui catalog";
16
+
17
+ const read = (file) => readFile(file, "utf8").catch(() => null);
18
+
19
+ export function requireTypeScript(root) {
20
+ const ts = loadTypeScript(root);
21
+ if (!ts) throw new Error("the UI tools read TSX with the TypeScript compiler API, and `typescript` resolves from neither this repository nor the harness; install it");
22
+ return ts;
23
+ }
24
+
25
+ /** Read each listed file. One the listing names but the disk no longer holds is skipped. */
26
+ export async function readFiles(root, rels) {
27
+ const files = [];
28
+ for (const rel of rels) {
29
+ const contents = await read(path.join(root, rel));
30
+ if (contents !== null) files.push({ path: rel, contents });
31
+ }
32
+ return files;
33
+ }
34
+
35
+ /** @param {string[]} [listed] the repository's files, when a caller already holds them */
36
+ export async function listFiles(config, listed) {
37
+ return listed ?? (await repoFiles(config.root, { ignores: ignoresOf(config) }));
38
+ }
39
+
40
+ /**
41
+ * Every exported component under the roots.
42
+ * @returns {Promise<{options: object, files: {path: string, contents: string}[], entries: object[], ts: object | null}>}
43
+ * `ts` is null when no component file exists, and then TypeScript was never loaded
44
+ */
45
+ export async function scanComponents(config, listed) {
46
+ const options = uiOptions(config);
47
+ const inRoots = componentFileMatcher(options);
48
+ const files = await readFiles(config.root, (await listFiles(config, listed)).filter(inRoots));
49
+ if (files.length === 0) return { options, files, entries: [], ts: null };
50
+ const ts = requireTypeScript(config.root);
51
+ return { options, files, entries: catalogEntries(ts, options, files, config.featureDir), ts };
52
+ }
53
+
54
+ /** The text the catalog file should hold, or null when there is no component. */
55
+ export const catalogText = (entries, options) => renderCatalog(entries, { layers: options.layers, command: CATALOG_COMMAND });
56
+
57
+ /** Write the catalog, or remove it when no component is left. @returns {Promise<{path: string, entries: number}>} */
58
+ export async function writeCatalog(config, listed) {
59
+ const { options, entries } = await scanComponents(config, listed);
60
+ const file = path.join(config.root, options.catalog);
61
+ const text = catalogText(entries, options);
62
+ if (text === null) {
63
+ await rm(file, { force: true });
64
+ } else {
65
+ await mkdir(path.dirname(file), { recursive: true });
66
+ await writeFile(file, text);
67
+ }
68
+ return { path: options.catalog, entries: entries.length };
69
+ }
70
+
71
+ export const writeCatalogBaseline = (config, entries, options) =>
72
+ writeFile(path.join(config.root, options.catalogBaseline), `${JSON.stringify(baselineOf(entries), null, 2)}\n`);
73
+
74
+ /** The files the codemod walks: the client globs, TypeScript and TSX only. */
75
+ export async function clientSourceFiles(config, listed) {
76
+ const matches = globMatcher((config.clientFiles ?? []).flatMap(expandBraces));
77
+ return readFiles(config.root, (await listFiles(config, listed)).filter((rel) => /\.tsx?$/.test(rel) && matches(rel)));
78
+ }
@@ -0,0 +1,29 @@
1
+ // A fragment: the TypeScript compiler API, loaded from the repository being judged, so the harness adds
2
+ // no runtime dependency. The kit's own copy is the fallback when the repository holds none.
3
+
4
+ import { createRequire } from "node:module";
5
+ import path from "node:path";
6
+
7
+ const cache = new Map();
8
+
9
+ /** @returns the `typescript` module, or null when neither the repository nor the kit resolves it. */
10
+ export function loadTypeScript(root = process.cwd()) {
11
+ if (cache.has(root)) return cache.get(root);
12
+ let found = null;
13
+ for (const from of [path.join(root, "noop.js"), import.meta.url]) {
14
+ try {
15
+ found = createRequire(from)("typescript");
16
+ break;
17
+ } catch {
18
+ // Try the next place to resolve it from.
19
+ }
20
+ }
21
+ cache.set(root, found);
22
+ return found;
23
+ }
24
+
25
+ /** The syntax tree of one `.ts` or `.tsx` source. */
26
+ export function parseSource(ts, name, text) {
27
+ const kind = name.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
28
+ return ts.createSourceFile(name, text, ts.ScriptTarget.Latest, true, kind);
29
+ }
@@ -43,3 +43,57 @@ jobs:
43
43
  # - run: pnpm lint
44
44
  # - run: pnpm dup:check
45
45
  # - run: pnpm test
46
+
47
+ # Unit tests in eight hosted shards. A self-hosted runner that goes offline leaves a job queued;
48
+ # `qc watch --pr` reports a check queued for over 15 minutes. A repository with no test:unit script skips it.
49
+ unit:
50
+ runs-on: ubuntu-latest
51
+ strategy: { fail-fast: false, matrix: { shard: [1, 2, 3, 4, 5, 6, 7, 8] } }
52
+ steps:
53
+ - uses: actions/checkout@v5
54
+ - id: script
55
+ run: node -e "console.log('present=' + Boolean(require('./package.json').scripts?.['test:unit']))" >> "$GITHUB_OUTPUT"
56
+ - if: steps.script.outputs.present == 'true'
57
+ uses: actions/setup-node@v5
58
+ with: { node-version-file: package.json }
59
+ - if: steps.script.outputs.present == 'true'
60
+ run: corepack enable && pnpm install --frozen-lockfile
61
+ - if: steps.script.outputs.present == 'true'
62
+ run: pnpm test:unit --shard=${{ matrix.shard }}/${{ strategy.job-total }}
63
+
64
+ # Integration tests in two hosted shards. Add the services the tests need, such as a database.
65
+ integration:
66
+ runs-on: ubuntu-latest
67
+ strategy: { fail-fast: false, matrix: { shard: [1, 2] } }
68
+ steps:
69
+ - uses: actions/checkout@v5
70
+ - id: script
71
+ run: node -e "console.log('present=' + Boolean(require('./package.json').scripts?.['test:integration']))" >> "$GITHUB_OUTPUT"
72
+ - if: steps.script.outputs.present == 'true'
73
+ uses: actions/setup-node@v5
74
+ with: { node-version-file: package.json }
75
+ - if: steps.script.outputs.present == 'true'
76
+ run: corepack enable && pnpm install --frozen-lockfile
77
+ - if: steps.script.outputs.present == 'true'
78
+ run: pnpm test:integration --shard=${{ matrix.shard }}/${{ strategy.job-total }}
79
+
80
+ # Browser tests: the specs a pull request affects, by the repository's own e2e:affected script,
81
+ # and every spec on a push.
82
+ e2e:
83
+ runs-on: ubuntu-latest
84
+ steps:
85
+ - uses: actions/checkout@v5
86
+ with: { fetch-depth: 0 }
87
+ - id: script
88
+ run: node -e "const s = require('./package.json').scripts ?? {}; console.log('present=' + Boolean(s.e2e && s['e2e:affected']))" >> "$GITHUB_OUTPUT"
89
+ - if: steps.script.outputs.present == 'true'
90
+ uses: actions/setup-node@v5
91
+ with: { node-version-file: package.json }
92
+ - if: steps.script.outputs.present == 'true'
93
+ run: corepack enable && pnpm install --frozen-lockfile
94
+ - if: steps.script.outputs.present == 'true'
95
+ run: pnpm exec playwright install --with-deps
96
+ - if: steps.script.outputs.present == 'true' && github.event_name == 'pull_request'
97
+ run: pnpm e2e:affected "origin/$GITHUB_BASE_REF"
98
+ - if: steps.script.outputs.present == 'true' && github.event_name != 'pull_request'
99
+ run: pnpm e2e