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.
- package/package.json +8 -3
- package/src/cli/check.mjs +61 -0
- package/src/cli/child-run.mjs +39 -0
- package/src/cli/child-run.test.mjs +16 -0
- package/src/cli/ci-template.test.mjs +28 -0
- package/src/cli/codex-implement.mjs +72 -3
- package/src/cli/codex-implement.test.mjs +141 -4
- package/src/cli/dispatch-guard.mjs +24 -1
- package/src/cli/dispatch-guard.test.mjs +30 -0
- package/src/cli/dispatch-reminder.mjs +4 -4
- package/src/cli/dispatch-reminder.test.mjs +3 -3
- package/src/cli/dispatch-slot.mjs +12 -0
- package/src/cli/gate-slot.mjs +151 -0
- package/src/cli/gate-slot.test.mjs +90 -0
- package/src/cli/integrate.mjs +122 -0
- package/src/cli/integrate.test.mjs +94 -0
- package/src/cli/ledger.mjs +25 -3
- package/src/cli/ledger.test.mjs +9 -0
- package/src/cli/merge-guard.mjs +13 -3
- package/src/cli/merge-guard.test.mjs +24 -1
- package/src/cli/migrations.mjs +127 -0
- package/src/cli/migrations.test.mjs +94 -0
- package/src/cli/plugin-agents.test.mjs +35 -8
- package/src/cli/qc.mjs +44 -0
- package/src/cli/report-stop.mjs +3 -0
- package/src/cli/report-stop.test.mjs +8 -0
- package/src/cli/retry-failed.mjs +80 -0
- package/src/cli/retry-failed.test.mjs +51 -0
- package/src/cli/review-gate.mjs +16 -7
- package/src/cli/slot-guard.mjs +43 -0
- package/src/cli/slot-guard.test.mjs +28 -0
- package/src/cli/task-gate-review.test.mjs +10 -0
- package/src/cli/task-gate.mjs +39 -7
- package/src/cli/task-gate.test.mjs +45 -0
- package/src/cli/throwaway-db.mjs +127 -0
- package/src/cli/throwaway-db.test.mjs +83 -0
- package/src/cli/ui-reuse-hint.mjs +89 -0
- package/src/cli/ui-reuse-hint.test.mjs +60 -0
- package/src/cli/ui.mjs +181 -0
- package/src/cli/ui.test.mjs +137 -0
- package/src/cli/watch.mjs +211 -0
- package/src/cli/watch.test.mjs +246 -0
- package/src/config.mjs +27 -2
- package/src/descriptions.mjs +3 -0
- package/src/gates/contract-keys.mjs +33 -0
- package/src/gates/contract-keys.test.mjs +38 -0
- package/src/gates/migration-numbers.mjs +1 -1
- package/src/gates/migration-numbers.test.mjs +1 -0
- package/src/gates/ui-catalog.mjs +45 -0
- package/src/gates/ui-catalog.test.mjs +48 -0
- package/src/gates/ui-dupes.mjs +36 -0
- package/src/gates/ui-dupes.test.mjs +29 -0
- package/src/ui/catalog.mjs +87 -0
- package/src/ui/catalog.test.mjs +54 -0
- package/src/ui/class-sites.mjs +151 -0
- package/src/ui/class-sites.test.mjs +41 -0
- package/src/ui/codemod.mjs +138 -0
- package/src/ui/codemod.test.mjs +140 -0
- package/src/ui/components.mjs +176 -0
- package/src/ui/components.test.mjs +87 -0
- package/src/ui/dupes.mjs +141 -0
- package/src/ui/dupes.test.mjs +85 -0
- package/src/ui/find.mjs +45 -0
- package/src/ui/find.test.mjs +48 -0
- package/src/ui/options.mjs +40 -0
- package/src/ui/scan.mjs +78 -0
- package/src/ui/typescript.mjs +29 -0
- package/templates/github/workflows/ci.yml +54 -0
package/src/ui/scan.mjs
ADDED
|
@@ -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
|