architecture-harness 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -22
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/branch-sync.mjs +126 -0
- package/src/cli/branch-sync.test.mjs +428 -0
- package/src/cli/budget-guard.mjs +74 -5
- package/src/cli/budget-guard.test.mjs +185 -2
- package/src/cli/budget-report.mjs +85 -0
- package/src/cli/budget-report.test.mjs +173 -0
- package/src/cli/budget.mjs +8 -5
- package/src/cli/check-commands.mjs +123 -11
- package/src/cli/check-commands.test.mjs +360 -6
- package/src/cli/check-feature-switches.test.mjs +110 -0
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check-verdict.mjs +46 -0
- package/src/cli/check-verdict.test.mjs +32 -0
- package/src/cli/check.mjs +137 -4
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/checkpoint.mjs +143 -0
- package/src/cli/checkpoint.test.mjs +146 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +304 -0
- package/src/cli/ci-failures.test.mjs +615 -0
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +25 -29
- package/src/cli/ci-state.test.mjs +174 -2
- package/src/cli/ci-template.test.mjs +86 -0
- package/src/cli/claude-core.test.mjs +37 -0
- package/src/cli/codex-implement.mjs +580 -47
- package/src/cli/codex-implement.test.mjs +1946 -29
- package/src/cli/codex-limit.mjs +85 -0
- package/src/cli/codex-limit.test.mjs +179 -0
- package/src/cli/codex-reset.mjs +78 -0
- package/src/cli/codex-reset.test.mjs +192 -0
- package/src/cli/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +219 -0
- package/src/cli/commit-guard.test.mjs +809 -0
- package/src/cli/context-budgets.mjs +47 -0
- package/src/cli/context-budgets.test.mjs +96 -0
- package/src/cli/context-watch.mjs +116 -0
- package/src/cli/context-watch.test.mjs +395 -0
- package/src/cli/contract-history.mjs +1 -1
- package/src/cli/controller-guard.mjs +38 -0
- package/src/cli/controller-guard.test.mjs +66 -2
- package/src/cli/cost-stop.mjs +5 -1
- package/src/cli/cost-stop.test.mjs +26 -0
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/direct-lane.mjs +32 -19
- package/src/cli/direct-lane.test.mjs +21 -3
- package/src/cli/dispatch-guard.mjs +11 -0
- package/src/cli/dispatch-guard.test.mjs +145 -10
- package/src/cli/dispatch-reminder.mjs +23 -10
- package/src/cli/dispatch-reminder.test.mjs +63 -11
- package/src/cli/dispatch-route.mjs +54 -0
- package/src/cli/dispatch-route.test.mjs +101 -0
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/e2e-affected.mjs +15 -0
- package/src/cli/e2e-affected.test.mjs +73 -0
- package/src/cli/fleet.mjs +180 -0
- package/src/cli/fleet.test.mjs +213 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +96 -31
- package/src/cli/gh-merge-command.test.mjs +74 -0
- package/src/cli/gh-run.mjs +64 -3
- package/src/cli/gh-run.test.mjs +66 -1
- package/src/cli/git-hooks.test.mjs +25 -3
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +143 -40
- package/src/cli/integrate.test.mjs +347 -1
- package/src/cli/integration-lane.mjs +62 -0
- package/src/cli/integration-lane.test.mjs +213 -0
- package/src/cli/ledger.mjs +4 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +70 -0
- package/src/cli/lint-changed.mjs +59 -10
- package/src/cli/lint-changed.test.mjs +112 -1
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +234 -62
- package/src/cli/merge-guard.test.mjs +768 -39
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/output-redaction.mjs +26 -0
- package/src/cli/output-redaction.test.mjs +117 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/pause.mjs +93 -0
- package/src/cli/pause.test.mjs +109 -0
- package/src/cli/plan-check.mjs +84 -12
- package/src/cli/plan-check.test.mjs +152 -2
- package/src/cli/plan-stop.mjs +7 -4
- package/src/cli/plan-stop.test.mjs +87 -0
- package/src/cli/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/plugin-skills.test.mjs +25 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/promotion-branch.mjs +2 -0
- package/src/cli/qc.mjs +160 -27
- package/src/cli/qc.test.mjs +93 -0
- package/src/cli/report-stop.mjs +5 -0
- package/src/cli/report-stop.test.mjs +23 -1
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/review-gate.mjs +24 -6
- package/src/cli/review-gate.test.mjs +116 -0
- package/src/cli/review-promotion.mjs +107 -0
- package/src/cli/review-promotion.test.mjs +251 -0
- package/src/cli/role-budget.mjs +50 -0
- package/src/cli/role-budget.test.mjs +91 -0
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/secret-patterns.mjs +16 -0
- package/src/cli/secret-patterns.test.mjs +73 -0
- package/src/cli/setup-block.mjs +24 -0
- package/src/cli/setup-block.test.mjs +96 -0
- package/src/cli/setup-checks.mjs +65 -0
- package/src/cli/setup-checks.test.mjs +158 -0
- package/src/cli/setup-compaction.mjs +55 -0
- package/src/cli/setup-compaction.test.mjs +115 -0
- package/src/cli/setup-skills.mjs +65 -0
- package/src/cli/setup-skills.test.mjs +171 -0
- package/src/cli/setup.mjs +107 -0
- package/src/cli/setup.test.mjs +275 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/spawn-command.mjs +47 -0
- package/src/cli/spawn-command.test.mjs +64 -0
- package/src/cli/task-gate-review.test.mjs +21 -2
- package/src/cli/task-gate.mjs +25 -12
- package/src/cli/task-gate.test.mjs +43 -5
- package/src/cli/tokens.mjs +46 -3
- package/src/cli/tokens.test.mjs +103 -3
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/transcript-usage.mjs +27 -0
- package/src/cli/transcript-usage.test.mjs +34 -0
- package/src/cli/user-config-package.mjs +1 -1
- package/src/cli/user-config-toml.mjs +63 -7
- package/src/cli/user-config.mjs +39 -7
- package/src/cli/user-config.test.mjs +238 -5
- package/src/cli/watch-arm.mjs +39 -0
- package/src/cli/watch-arm.test.mjs +87 -0
- package/src/cli/watch.mjs +80 -35
- package/src/cli/watch.test.mjs +233 -27
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +18 -4
- package/src/cli/workflow-settings.mjs +44 -8
- package/src/cli/workflow-settings.test.mjs +124 -1
- package/src/cli/worktree.mjs +14 -1
- package/src/cli/worktree.test.mjs +20 -1
- package/src/config.mjs +174 -7
- package/src/config.test.mjs +327 -5
- package/src/consumer-package.mjs +31 -0
- package/src/consumer-package.test.mjs +54 -0
- package/src/descriptions.mjs +2 -0
- package/src/eslint/index.mjs +12 -0
- package/src/eslint/jsx.mjs +20 -0
- package/src/eslint/preset.mjs +26 -2
- package/src/eslint/preset.test.mjs +104 -2
- package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
- package/src/eslint/rules/no-literal-color.mjs +94 -0
- package/src/eslint/rules/no-static-inline-style.mjs +41 -0
- package/src/eslint/rules/one-component-per-file.mjs +70 -0
- package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +189 -0
- package/src/eslint/ui-regressions.test.mjs +39 -0
- package/src/gates/contract-operations.mjs +3 -3
- package/src/gates/contract-operations.test.mjs +28 -0
- package/src/gates/feature-switches.mjs +19 -0
- package/src/gates/feature-switches.test.mjs +55 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/gates/runtime-imports.test.mjs +114 -0
- package/src/gates/saga-key.test.mjs +1 -1
- package/src/global-skills.mjs +9 -0
- package/src/global-skills.test.mjs +53 -0
- package/src/plugin.test.mjs +3 -2
- package/src/ui/class-sites.mjs +38 -6
- package/src/ui/codemod.mjs +4 -1
- package/src/ui/codemod.test.mjs +52 -0
- package/src/ui/components.mjs +5 -3
- package/src/ui/components.test.mjs +8 -0
- package/src/ui/dupes.test.mjs +18 -0
- package/templates/docs/enforcement.md +12 -2
- package/templates/docs/ui.md +33 -0
- package/templates/githooks/pre-commit +1 -0
- package/templates/githooks/pre-push +11 -2
- package/templates/github/workflows/ci.yml +57 -3
- package/user-config/claude/CLAUDE.core.md +28 -0
- package/user-config/claude/settings.shared.json +41 -1
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -84
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -127
- package/src/cli/throwaway-db.test.mjs +0 -83
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -175
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -40
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -137
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -78
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -106
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -40
- package/src/stack/supervisor.mjs +0 -30
package/src/screens/catalog.mjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync, mkdirSync } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { privateRoot } from "./auth.mjs";
|
|
5
|
-
|
|
6
|
-
/** Record: catalog names are portable paths below the output directory. */
|
|
7
|
-
export function screen(entry) {
|
|
8
|
-
if (!/^[a-z0-9_-]+(?:\/[a-z0-9_-]+)*$/i.test(entry.name ?? "")) throw new Error("Invalid catalog screen name");
|
|
9
|
-
if (!entry.open || typeof entry.open !== "object") throw new Error(`Screen ${entry.name} requires open functions`);
|
|
10
|
-
return entry;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Resource: each area exports entries or an array of entries. */
|
|
14
|
-
export async function loadCatalog(directory) {
|
|
15
|
-
const entries = [];
|
|
16
|
-
const walk = async dir => {
|
|
17
|
-
for (const item of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
18
|
-
const file = path.join(dir, item.name);
|
|
19
|
-
if (item.isDirectory()) await walk(file);
|
|
20
|
-
else if (/\.(?:ts|mjs|js)$/.test(item.name) && !/\.d\.ts$/.test(item.name)) {
|
|
21
|
-
const module = await import(pathToFileURL(file).href);
|
|
22
|
-
for (const value of Object.values(module)) for (const entry of Array.isArray(value) ? value : [value]) {
|
|
23
|
-
if (entry?.name && entry?.open) entries.push(screen(entry));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
await walk(directory);
|
|
29
|
-
const names = new Set();
|
|
30
|
-
for (const entry of entries) {
|
|
31
|
-
if (names.has(entry.name)) throw new Error(`Duplicate catalog screen ${entry.name}`);
|
|
32
|
-
names.add(entry.name);
|
|
33
|
-
}
|
|
34
|
-
return entries;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Record: navigation receives fixture ids and names every fallible step. */
|
|
38
|
-
export function navigationContext(page, target, targetName, screenName, out) {
|
|
39
|
-
const file = path.join(privateRoot(), `fixtures-${targetName}.json`);
|
|
40
|
-
const fixtures = { ...(target.fixtures ?? {}), ...(existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {}) };
|
|
41
|
-
return { baseUrl: target.baseUrl, fixtures, target: targetName, async step(name, action) {
|
|
42
|
-
try { return await action(); }
|
|
43
|
-
catch (cause) {
|
|
44
|
-
if (cause.step) throw cause;
|
|
45
|
-
const screenshot = `${screenName}/failure-${targetName}-${name.replace(/[^a-z0-9_-]/gi, "_")}.png`;
|
|
46
|
-
mkdirSync(path.dirname(path.join(out, screenshot)), { recursive: true });
|
|
47
|
-
await page.screenshot({ path: path.join(out, screenshot) }).catch(() => {});
|
|
48
|
-
throw Object.assign(new Error(`Screen ${screenName}, target ${targetName}, step ${name} failed`), { screen: screenName, target: targetName, step: name, screenshot });
|
|
49
|
-
}
|
|
50
|
-
} };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Pipeline: bind shared app navigation to each cloud or local target. */
|
|
54
|
-
export async function applyCatalog(map, mapFile) {
|
|
55
|
-
if (!map.catalog) return map;
|
|
56
|
-
const entries = await loadCatalog(path.resolve(path.dirname(mapFile), map.catalog));
|
|
57
|
-
map.screens = entries.map(entry => ({ name: entry.name, signatures: entry.signatures, targets: Object.fromEntries(Object.entries(map.targets).flatMap(([name, target]) => {
|
|
58
|
-
const family = target.family ?? name.split("-")[0];
|
|
59
|
-
const key = entry.open[name] ? name : family;
|
|
60
|
-
if (!entry.open[key]) return [];
|
|
61
|
-
const original = map.screens.find(item => item.name === entry.name)?.targets[name] ?? {};
|
|
62
|
-
return [[name, { ...original, path: entry.paths?.[key] ?? original.path, ready: entry.ready?.[key] ?? original.ready, masks: entry.masks?.[key] ?? original.masks, exclude: entry.exclude?.[key] ?? original.exclude, idle: entry.idle?.[key] ?? original.idle, open: entry.open[key], navigationSource: String(entry.open[key]) }]];
|
|
63
|
-
})) }));
|
|
64
|
-
return map;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Pipeline: catalog functions use named steps and an explicit ready state. */
|
|
68
|
-
export async function openScreen(page, target, route, { targetName, screenName, out, timeout = 15000 }) {
|
|
69
|
-
const ctx = navigationContext(page, target, targetName, screenName, out);
|
|
70
|
-
await ctx.step("Open screen", () => route.open(page, ctx));
|
|
71
|
-
if (route.ready) await ctx.step("Ready", () => page.locator(route.ready).first().waitFor({ state: "visible", timeout }));
|
|
72
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { loadCatalog, screen, navigationContext, applyCatalog } from "./catalog.mjs";
|
|
7
|
-
|
|
8
|
-
test("catalog loads TypeScript areas and rejects duplicate names", async () => {
|
|
9
|
-
const root = mkdtempSync(path.join(os.tmpdir(), "qc-catalog-"));
|
|
10
|
-
try {
|
|
11
|
-
writeFileSync(path.join(root, "area.ts"), 'export const entry = {name:"photos/viewer",ready:{mono:"main"},open:{mono:async (page: any) => page.goto("/photos")}}');
|
|
12
|
-
assert.equal((await loadCatalog(root))[0].name, "photos/viewer");
|
|
13
|
-
writeFileSync(path.join(root, "other.ts"), 'export const entry = {name:"photos/viewer",open:{}}');
|
|
14
|
-
await assert.rejects(loadCatalog(root), /Duplicate/);
|
|
15
|
-
assert.throws(() => screen({ name: "../escape", open: {} }), /name/);
|
|
16
|
-
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test("failed named step retains its name and screenshot", async () => {
|
|
20
|
-
const calls = [];
|
|
21
|
-
const page = { screenshot: async options => { calls.push(options.path); } };
|
|
22
|
-
const ctx = navigationContext(page, { baseUrl: "http://localhost:3000", fixtures: { project: "p" } }, "target", "photos/viewer", ".");
|
|
23
|
-
await assert.rejects(ctx.step("Open viewer", async () => { throw new Error("missing button"); }), error => error.step === "Open viewer" && error.screen === "photos/viewer" && error.target === "target" && Boolean(error.screenshot));
|
|
24
|
-
assert.equal(ctx.fixtures.project, "p");
|
|
25
|
-
assert.equal(calls.length, 1);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test("catalog entries carry the idle option for each app family", async () => {
|
|
29
|
-
const root = mkdtempSync(path.join(os.tmpdir(), "qc-catalog-"));
|
|
30
|
-
try {
|
|
31
|
-
writeFileSync(path.join(root, "area.ts"), 'export const entry = {name:"drawings-pins",idle:{legacy:false},open:{legacy:async (page: any) => page.goto("/a"),mono:async (page: any) => page.goto("/b")}}');
|
|
32
|
-
const map = await applyCatalog({ catalog: root, targets: { "old-local": { family: "legacy" }, "new-local": { family: "mono" } }, screens: [] }, path.join(root, "map.json"));
|
|
33
|
-
assert.equal(map.screens[0].targets["old-local"].idle, false);
|
|
34
|
-
assert.equal(map.screens[0].targets["new-local"].idle, undefined);
|
|
35
|
-
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
36
|
-
});
|
package/src/screens/chrome.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// The screen commands launch Google Chrome as the `chrome` channel, and a machine may not have it.
|
|
2
|
-
|
|
3
|
-
const MISSING = /is not found at|Executable doesn't exist|not installed/i;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Why a test that launches Chrome cannot run here, or false when it can. `QC_REQUIRE_CHROME=1` makes a missing
|
|
7
|
-
* Chrome a failure, so CI never passes by skipping.
|
|
8
|
-
* @param {{launch: (options: object) => Promise<{close: () => Promise<void>}>}} chromium the Playwright browser type
|
|
9
|
-
* @returns {Promise<string | false>}
|
|
10
|
-
*/
|
|
11
|
-
export async function chromeMissing(chromium) {
|
|
12
|
-
if (process.env.QC_REQUIRE_CHROME === "1") return false;
|
|
13
|
-
try {
|
|
14
|
-
const browser = await chromium.launch({ channel: "chrome" });
|
|
15
|
-
await browser.close();
|
|
16
|
-
return false;
|
|
17
|
-
} catch (error) {
|
|
18
|
-
if (!MISSING.test(error?.message ?? "")) return false;
|
|
19
|
-
return "Google Chrome is not installed. Set QC_REQUIRE_CHROME=1 to fail instead of skip.";
|
|
20
|
-
}
|
|
21
|
-
}
|
package/src/screens/compare.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import pixelmatch from "pixelmatch";
|
|
2
|
-
import { PNG } from "pngjs";
|
|
3
|
-
|
|
4
|
-
/** Pipeline: normalize dimensions and paint changed pixels over the right image. */
|
|
5
|
-
export function compareImages(left, right) {
|
|
6
|
-
const width = Math.max(left.width, right.width);
|
|
7
|
-
const height = Math.max(left.height, right.height);
|
|
8
|
-
const padded = [left, right].map(source => {
|
|
9
|
-
const image = new PNG({ width, height });
|
|
10
|
-
PNG.bitblt(source, image, 0, 0, source.width, source.height, 0, 0);
|
|
11
|
-
return image;
|
|
12
|
-
});
|
|
13
|
-
const diff = new PNG({ width, height });
|
|
14
|
-
const diffPixels = pixelmatch(padded[0].data, padded[1].data, diff.data, width, height, { threshold: 0.1, includeAA: true, diffMask: true, diffColor: [255, 0, 0] });
|
|
15
|
-
const pair = new PNG({ width: width * 2, height });
|
|
16
|
-
PNG.bitblt(padded[0], pair, 0, 0, width, height, 0, 0);
|
|
17
|
-
PNG.bitblt(padded[1], pair, 0, 0, width, height, width, 0);
|
|
18
|
-
for (let y = 0; y < height; y++) {
|
|
19
|
-
for (let x = 0; x < width; x++) {
|
|
20
|
-
const offset = (y * width + x) * 4;
|
|
21
|
-
if (diff.data[offset + 3]) diff.data.copy(pair.data, (y * width * 2 + width + x) * 4, offset, offset + 4);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return { pair, diffPixels, totalPixels: width * height, diffPercent: Number((100 * diffPixels / (width * height)).toFixed(4)) };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Ledger: list the greatest visual differences first. */
|
|
28
|
-
export function sortReport(rows) {
|
|
29
|
-
return [...rows].sort((a, b) => b.diffPercent - a.diffPercent || a.screen.localeCompare(b.screen) || a.width - b.width);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const escapeHtml = value => String(value).replace(/[&<>"']/g, ch => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[ch]);
|
|
33
|
-
|
|
34
|
-
/** Fragment: a static gallery needs neither a server nor a script. */
|
|
35
|
-
export function gallery(rows) {
|
|
36
|
-
const failed = rows.filter(row => row.error).map(row => `<p>${escapeHtml(row.screen)}: ${escapeHtml(row.error.message)}${row.error.screenshot ? ` <a href="${escapeHtml(row.error.screenshot)}">Failure screenshot</a>` : ""}</p>`).join("");
|
|
37
|
-
if (failed) return gallery(rows.filter(row => !row.error)).replace("<h1>Screen pairs</h1>", `<h1>Screen pairs</h1>${failed}`);
|
|
38
|
-
const crops = rows.flatMap(row => [...(row.inventoryFindings ?? []), ...(row.regions ?? [])].filter(region => region.crop).map(region => `<figure><figcaption>${escapeHtml(row.screen)} @ ${row.width}px — ${escapeHtml(region.kind)} ${region.id}</figcaption><a href="${escapeHtml(region.crop)}"><img loading="lazy" src="${escapeHtml(region.crop)}" alt="${escapeHtml(region.kind)} region ${region.id}"></a></figure>`)).join("");
|
|
39
|
-
return `<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Screen pairs</title><style>body{font:16px system-ui;margin:24px;background:#fafafa;color:#222}img{max-width:100%;border:1px solid #ccc}figure{margin:24px 0}figcaption{margin:8px 0}</style><h1>Screen pairs</h1><p>Left: baseline. Right: comparison, with differences in red.</p>${crops}${rows.map(row => `<figure><figcaption>${escapeHtml(row.screen)} @ ${row.width}px: ${row.diffPercent}% (${escapeHtml(row.targets.join(" → "))})</figcaption><a href="${escapeHtml(row.pair)}"><img loading="lazy" src="${escapeHtml(row.pair)}" alt="${escapeHtml(row.screen)} pair at ${row.width} pixels"></a></figure>`).join("")}</html>`;
|
|
40
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { PNG } from "pngjs";
|
|
4
|
-
import { compareImages, sortReport } from "./compare.mjs";
|
|
5
|
-
|
|
6
|
-
test("diff counts pixels and marks the right image in red", () => {
|
|
7
|
-
const left = new PNG({ width: 2, height: 1 });
|
|
8
|
-
left.data.fill(255);
|
|
9
|
-
const right = PNG.sync.read(PNG.sync.write(left));
|
|
10
|
-
right.data[0] = 0;
|
|
11
|
-
right.data[1] = 0;
|
|
12
|
-
right.data[2] = 0;
|
|
13
|
-
const result = compareImages(left, right);
|
|
14
|
-
assert.equal(result.diffPercent, 50);
|
|
15
|
-
assert.equal(result.diffPixels, 1);
|
|
16
|
-
assert.equal(result.pair.width, 4);
|
|
17
|
-
assert.deepEqual([...result.pair.data.subarray(8, 12)], [255, 0, 0, 255]);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("report sorts greatest differences first with stable screen and width order", () => {
|
|
21
|
-
assert.deepEqual(sortReport([{ screen: "b", width: 390, diffPercent: 0 }, { screen: "a", width: 390, diffPercent: 20 }, { screen: "a", width: 2514, diffPercent: 20 }]).map(r => `${r.screen}@${r.width}`), ["a@390", "a@2514", "b@390"]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("different dimensions count the extra area", () => {
|
|
25
|
-
const left = new PNG({ width: 1, height: 1 });
|
|
26
|
-
const right = new PNG({ width: 2, height: 1 });
|
|
27
|
-
left.data.fill(255);
|
|
28
|
-
right.data.fill(255);
|
|
29
|
-
assert.equal(compareImages(left, right).diffPercent, 50);
|
|
30
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import http from "node:http";
|
|
4
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
5
|
-
import os from "node:os";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import { chromium } from "playwright";
|
|
8
|
-
import { discover } from "./discovery.mjs";
|
|
9
|
-
|
|
10
|
-
test("one SPA URL exposes five states; writes and an automatic POST stay blocked", async () => {
|
|
11
|
-
let writes = 0;
|
|
12
|
-
const server = http.createServer((request, response) => {
|
|
13
|
-
if (request.method === "POST") writes++;
|
|
14
|
-
response.setHeader("content-type", "text/html");
|
|
15
|
-
response.end(`<main><h1>Workspace</h1><button role="tab" aria-selected="false" onclick="this.setAttribute('aria-selected','true')">Photos</button><button role="tab" aria-selected="false" onclick="this.setAttribute('aria-selected','true')">Drawings</button><button onclick="document.querySelector('dialog').showModal()">Open dialog</button><button onclick="document.querySelector('[role=menu]').hidden=false">Open menu</button><button onclick="fetch('/write',{method:'POST'})">Save</button><dialog aria-label="Details">Details</dialog><div role="menu" aria-label="Actions" hidden>Actions</div></main><script>fetch('/automatic',{method:'POST'})</script>`);
|
|
16
|
-
});
|
|
17
|
-
await new Promise(resolve => server.listen(0, "127.0.0.1", resolve));
|
|
18
|
-
const browser = await chromium.launch({ channel: "chrome", headless: true });
|
|
19
|
-
const context = await browser.newContext({ serviceWorkers: "block" });
|
|
20
|
-
const out = mkdtempSync(path.join(os.tmpdir(), "qc-discover-"));
|
|
21
|
-
try {
|
|
22
|
-
const result = await discover({ context, page: await context.newPage() }, { baseUrl: `http://127.0.0.1:${server.address().port}`, routes: ["/"], auth: { signedIn: "main" } }, { out, targetName: "fixture", widths: [390], depth: 1, timeout: 3000 });
|
|
23
|
-
assert.equal(result.states.length, 5);
|
|
24
|
-
assert.equal(result.errors.length, 0);
|
|
25
|
-
assert.equal(result.states.some(state => state.path.some(step => step.name === "Save")), false);
|
|
26
|
-
assert.equal(writes, 0);
|
|
27
|
-
assert.ok(result.blockedRequests > 0);
|
|
28
|
-
} finally { await browser.close(); await new Promise(resolve => server.close(resolve)); rmSync(out, { recursive: true, force: true }); }
|
|
29
|
-
});
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { safeControl, installWriteGuard } from "./write-guard.mjs";
|
|
5
|
-
|
|
6
|
-
const normalized = text => String(text ?? "").normalize("NFKC").replace(/\s+/g, " ").trim().toLowerCase();
|
|
7
|
-
const hash = text => createHash("sha256").update(text).digest("hex").slice(0, 16);
|
|
8
|
-
|
|
9
|
-
/** Record: source route patterns resolve only known fixture parameters. */
|
|
10
|
-
export function sourceRoutes(source, fixtures = {}) {
|
|
11
|
-
const result = [];
|
|
12
|
-
const names = { projectId: "project", folderId: "folder", photoId: "photo", drawingId: "drawing", id: "project" };
|
|
13
|
-
for (const match of source.matchAll(/\bpath\s*[:=]\s*["'](\/[^"']*)["']/g)) {
|
|
14
|
-
const pattern = match[1];
|
|
15
|
-
let missing = false;
|
|
16
|
-
const route = pattern.replace(/:([a-zA-Z]\w*)\??/g, (_, name) => {
|
|
17
|
-
const value = fixtures[name] ?? fixtures[names[name]];
|
|
18
|
-
if (!value) missing = true;
|
|
19
|
-
return encodeURIComponent(value ?? "");
|
|
20
|
-
});
|
|
21
|
-
result.push({ pattern, path: missing || route.includes("*") ? null : route });
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Resource: route extraction reads application source without loading its modules. */
|
|
27
|
-
export function readSourceRoutes(roots = [], fixtures = {}) {
|
|
28
|
-
const routes = [];
|
|
29
|
-
const walk = root => {
|
|
30
|
-
for (const item of readdirSync(root, { withFileTypes: true })) {
|
|
31
|
-
if (/^(?:node_modules|\.git|dist|build|coverage|\.worktree|\.next)$/.test(item.name)) continue;
|
|
32
|
-
const file = path.join(root, item.name);
|
|
33
|
-
if (item.isDirectory()) walk(file);
|
|
34
|
-
else if (/\.[jt]sx?$/.test(item.name) && !/\.(?:test|spec)\./.test(item.name) && statSync(file).size < 2000000) routes.push(...sourceRoutes(readFileSync(file, "utf8"), fixtures));
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
for (const root of roots) walk(root);
|
|
38
|
-
return [...new Map(routes.map(route => [route.pattern, route])).values()];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const locatorFor = (page, step) => step.testId ? page.getByTestId(step.testId) : page.getByRole(step.role, { name: step.name, exact: true });
|
|
42
|
-
|
|
43
|
-
/** Record: a UI signature identifies state independently of its data rows. */
|
|
44
|
-
export async function stateSignature(page, pattern) {
|
|
45
|
-
const read = async selector => page.locator(selector).evaluateAll(nodes => nodes.filter(node => node.getBoundingClientRect().width && node.getBoundingClientRect().height).map(node => node.getAttribute("aria-label") || node.textContent.trim()).join(" | "));
|
|
46
|
-
const dialogs = page.getByRole("dialog");
|
|
47
|
-
const dialog = await dialogs.count() ? await dialogs.last().ariaSnapshot() : "";
|
|
48
|
-
return JSON.stringify({ route: pattern, dialog: dialog.split("\n")[0].replace(/^\s*-\s*/, ""), tab: await read('[role="tab"][aria-selected="true"]'), menu: await read('[role="menu"]'), heading: await read('main h1,main [role="heading"][aria-level="1"],h1'), expanded: await read('[aria-expanded="true"]') });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function candidates(page) {
|
|
52
|
-
const controls = page.locator('button,[role="button"],[role="tab"],[role="menuitem"],[role="combobox"],[role="switch"],summary');
|
|
53
|
-
const result = [];
|
|
54
|
-
for (const control of await controls.all()) {
|
|
55
|
-
if (!await control.isVisible() || !await control.isEnabled()) continue;
|
|
56
|
-
const data = await control.evaluate(element => ({ type: element.getAttribute("type") ?? (element.tagName === "BUTTON" && element.closest("form") ? "submit" : ""), text: `${element.textContent} ${element.getAttribute("aria-label") ?? ""}`, testId: element.getAttribute("data-testid"), role: element.getAttribute("role") ?? (element.tagName === "SUMMARY" ? "button" : "button") }));
|
|
57
|
-
if (!safeControl(data)) continue;
|
|
58
|
-
const snapshot = await control.ariaSnapshot().catch(() => "");
|
|
59
|
-
const first = snapshot.split("\n")[0].match(/^-\s+([\w]+)(?:\s+"(.*?)")?/);
|
|
60
|
-
const step = { role: first?.[1] ?? data.role, name: first?.[2] ?? "", ...(data.testId ? { testId: data.testId } : {}) };
|
|
61
|
-
if (!step.testId && !step.name) continue;
|
|
62
|
-
if (await locatorFor(page, step).count() !== 1) continue;
|
|
63
|
-
result.push(step);
|
|
64
|
-
}
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Pipeline: replay safe paths from every route and retain unique UI states. */
|
|
69
|
-
export async function discover(session, target, { out, targetName, widths = [2514, 390], depth = 4, timeout = 15000, allowWrites = false, maxStates = 500, say = () => {} } = {}) {
|
|
70
|
-
const { page, context } = session;
|
|
71
|
-
page.setDefaultTimeout(timeout);
|
|
72
|
-
const states = [], errors = [], unresolvedRoutes = [];
|
|
73
|
-
let blockedRequests = 0;
|
|
74
|
-
await installWriteGuard(context, target, { allowWrites, onBlocked: () => blockedRequests++ });
|
|
75
|
-
const discoveredRoutes = readSourceRoutes(target.sourceRoots, target.fixtures);
|
|
76
|
-
for (const route of discoveredRoutes) if (!route.path) unresolvedRoutes.push(route.pattern);
|
|
77
|
-
const starts = [...(target.routes ?? ["/"]).map(route => typeof route === "string" ? { path: route, pattern: route } : route), ...discoveredRoutes.filter(route => route.path)];
|
|
78
|
-
const origin = new URL(target.baseUrl).origin;
|
|
79
|
-
const seen = new Set();
|
|
80
|
-
const queuedRoutes = new Set();
|
|
81
|
-
const queue = [];
|
|
82
|
-
const addRoute = (route, width) => {
|
|
83
|
-
const key = `${width}:${route.path}`;
|
|
84
|
-
if (!queuedRoutes.has(key)) { queuedRoutes.add(key); queue.push({ route, width, path: [] }); }
|
|
85
|
-
};
|
|
86
|
-
for (const width of widths) for (const route of starts) addRoute(route, width);
|
|
87
|
-
mkdirSync(out, { recursive: true });
|
|
88
|
-
while (queue.length) {
|
|
89
|
-
if (states.length >= maxStates) { errors.push({ message: `State limit ${maxStates} reached; discovery is incomplete` }); break; }
|
|
90
|
-
const current = queue.shift();
|
|
91
|
-
try {
|
|
92
|
-
await page.setViewportSize({ width: current.width, height: 900 });
|
|
93
|
-
const response = await page.goto(new URL(current.route.path, target.baseUrl).href, { waitUntil: "domcontentloaded", timeout });
|
|
94
|
-
if (response?.status() >= 400) throw new Error(`HTTP ${response.status()}`);
|
|
95
|
-
for (const step of target.discoverySteps ?? []) {
|
|
96
|
-
const control = locatorFor(page, step);
|
|
97
|
-
if (await control.isVisible() && safeControl({ text: step.name })) await control.click({ timeout });
|
|
98
|
-
}
|
|
99
|
-
for (const step of current.path) await locatorFor(page, step).click({ timeout });
|
|
100
|
-
await page.waitForLoadState("networkidle", { timeout });
|
|
101
|
-
if (new URL(page.url()).origin !== origin) throw new Error("Discovery left the target origin");
|
|
102
|
-
await page.locator(target.auth.signedIn).first().waitFor({ state: "visible", timeout });
|
|
103
|
-
const actual = new URL(page.url());
|
|
104
|
-
const pattern = actual.pathname === new URL(current.route.path, target.baseUrl).pathname ? current.route.pattern : actual.pathname;
|
|
105
|
-
const signature = await stateSignature(page, pattern);
|
|
106
|
-
const key = `${current.width}:${signature}`;
|
|
107
|
-
if (seen.has(key)) continue;
|
|
108
|
-
seen.add(key);
|
|
109
|
-
const id = hash(key);
|
|
110
|
-
const thumbnail = `${targetName}-${id}.png`;
|
|
111
|
-
await page.screenshot({ path: path.join(out, thumbnail), animations: "disabled" });
|
|
112
|
-
const state = { id, signature, route: current.route.path, pattern, width: current.width, path: current.path, thumbnail };
|
|
113
|
-
states.push(state);
|
|
114
|
-
say(`Discovered ${targetName} ${current.width} ${pattern} ${id}`);
|
|
115
|
-
const links = await page.locator("a[href]").evaluateAll(nodes => nodes.map(node => node.href));
|
|
116
|
-
for (const href of links) {
|
|
117
|
-
const url = new URL(href);
|
|
118
|
-
if (url.origin === origin && !/logout|signout|delete|remove|complete/i.test(url.pathname)) addRoute({ path: url.pathname + url.search, pattern: url.pathname }, current.width);
|
|
119
|
-
}
|
|
120
|
-
if (current.path.length < depth) for (const step of await candidates(page)) queue.push({ ...current, path: [...current.path, step] });
|
|
121
|
-
} catch (error) { errors.push({ route: current.route.path, width: current.width, path: current.path, message: error.message }); }
|
|
122
|
-
}
|
|
123
|
-
const counts = Object.fromEntries([...new Set(states.map(state => state.pattern))].map(route => [route, states.filter(state => state.pattern === route).length]));
|
|
124
|
-
const result = { target: targetName, states, counts, errors, unresolvedRoutes, blockedRequests, complete: !errors.length && !unresolvedRoutes.length };
|
|
125
|
-
writeFileSync(path.join(out, `discovered-${targetName}.json`), JSON.stringify(result, null, 2));
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function pairingText(state) {
|
|
130
|
-
const value = JSON.parse(state.signature);
|
|
131
|
-
const text = normalized([value.dialog, value.tab, value.menu, value.heading, value.expanded].filter(Boolean).join(" | "));
|
|
132
|
-
return `${state.width}:${text || value.route}`;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Pipeline: match identical state text once, retaining both parity gaps. */
|
|
136
|
-
export function pairStates(legacy, mono) {
|
|
137
|
-
const available = new Set(mono);
|
|
138
|
-
const result = legacy.map(left => {
|
|
139
|
-
const right = [...available].find(right => pairingText(left) === pairingText(right));
|
|
140
|
-
if (right) { available.delete(right); return { kind: "paired", legacy: left, mono: right }; }
|
|
141
|
-
return { kind: "legacy-only", legacy: left };
|
|
142
|
-
});
|
|
143
|
-
return [...result, ...[...available].map(right => ({ kind: "mono-only", mono: right }))];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** Branch: every discovery needs a catalog signature or a written exclusion. */
|
|
147
|
-
export function catalogCoverage(states, entries, excluded = [], targetName) {
|
|
148
|
-
const signatures = entries.flatMap(entry => Array.isArray(entry.signatures) ? entry.signatures : entry.signatures?.[targetName] ?? entry.signatures?.[targetName?.split("-")[0]] ?? []);
|
|
149
|
-
const missing = states.filter(state => !signatures.some(signature => typeof signature === "string" ? signature === state.signature : signature.signature === state.signature && signature.width === state.width) && !excluded.some(item => item.signature === state.signature && (!item.target || item.target === targetName) && (!item.width || item.width === state.width) && item.reason?.trim()));
|
|
150
|
-
return { covered: states.length - missing.length, total: states.length, missing };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/** Fragment: scaffold selectors replay the recorded path through named steps. */
|
|
154
|
-
export function scaffoldEntry(state, family) {
|
|
155
|
-
const steps = state.path.map((step, index) => ` await ctx.step(${JSON.stringify(`${index + 1}. ${step.name || step.testId}`)}, () => ${step.testId ? `page.getByTestId(${JSON.stringify(step.testId)})` : `page.getByRole(${JSON.stringify(step.role)}, {name:${JSON.stringify(step.name)},exact:true})`}.click());`).join("\n");
|
|
156
|
-
const name = `discovered/${family}-${state.id ?? hash(state.signature)}`;
|
|
157
|
-
return `export const state${state.id ?? hash(state.signature)} = {\n name:${JSON.stringify(name)},\n signatures:{${JSON.stringify(family)}:[${JSON.stringify({ signature: state.signature, width: state.width })}]},\n open:{${JSON.stringify(family)}:async (page, ctx) => {\n await ctx.step("Navigate", () => page.goto(new URL(${JSON.stringify(state.route)},ctx.baseUrl).href));\n${steps}\n }}\n};\n`;
|
|
158
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { safeControl, permitsRequest } from "./write-guard.mjs";
|
|
4
|
-
import { pairStates, catalogCoverage, scaffoldEntry, sourceRoutes } from "./discovery.mjs";
|
|
5
|
-
|
|
6
|
-
test("write guard blocks mutations in English and Japanese and allows local opt-in", () => {
|
|
7
|
-
for (const name of ["Save", "Delete project", "送信", "保存", "確定", "竣工にする", "アップロード", "登録"]) assert.equal(safeControl({ text: name }), false);
|
|
8
|
-
assert.equal(safeControl({ text: "Photos" }), true);
|
|
9
|
-
assert.equal(permitsRequest("POST", "http://localhost/api", { baseUrl: "http://localhost" }), false);
|
|
10
|
-
assert.equal(permitsRequest("POST", "http://localhost/api", { baseUrl: "http://localhost" }, true), true);
|
|
11
|
-
assert.equal(permitsRequest("POST", "https://other.test/x", { baseUrl: "http://localhost" }, true), false);
|
|
12
|
-
assert.equal(permitsRequest("POST", "https://cloud.test/api", { baseUrl: "https://cloud.test" }, true), false);
|
|
13
|
-
assert.equal(permitsRequest("POST", "https://tenant.auth0.com/u/login", { baseUrl: "https://cloud.test", auth: { domain: "tenant.auth0.com" } }), true);
|
|
14
|
-
assert.equal(permitsRequest("POST", "https://tenant.auth0.com/api/users", { baseUrl: "https://cloud.test", auth: { domain: "tenant.auth0.com" } }), false);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test("pairing is one-to-one and coverage requires an entry or a reason", () => {
|
|
18
|
-
const state = title => ({ signature: JSON.stringify({ heading: title, tab: "", menu: "", dialog: "", route: "/" }), width: 390, route: "/", path: [] });
|
|
19
|
-
const old = [state("Projects"), state("Legacy")];
|
|
20
|
-
const next = [state("Projects"), state("Mono")];
|
|
21
|
-
const pairs = pairStates(old, next);
|
|
22
|
-
assert.deepEqual(pairs.map(item => item.kind), ["paired", "legacy-only", "mono-only"]);
|
|
23
|
-
assert.equal(catalogCoverage(old, [{ signatures: [old[0].signature] }], [{ signature: old[1].signature, reason: "Legacy settings" }]).missing.length, 0);
|
|
24
|
-
assert.equal(catalogCoverage(old, [], [{ signature: old[1].signature, reason: "" }]).missing.length, 2);
|
|
25
|
-
assert.match(scaffoldEntry({ ...old[0], path: [{ role: "tab", name: "Photos" }] }, "mono"), /getByRole\("tab"/);
|
|
26
|
-
assert.deepEqual(sourceRoutes('<Route path="/projects/:projectId"/><Route path="/login"/>', { project: "p" }).map(item => item.path), ["/projects/p", "/login"]);
|
|
27
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const normalize = value => String(value ?? "").normalize("NFKC").replace(/\s+/g, " ").trim().toLowerCase();
|
|
2
|
-
const key = item => `${item.role}:${normalize(item.name)}`;
|
|
3
|
-
const roles = new Set(["textbox", "searchbox", "combobox", "checkbox", "radio", "spinbutton", "slider", "switch", "button", "link", "tab", "menuitem", "menuitemcheckbox", "menuitemradio", "heading", "columnheader"]);
|
|
4
|
-
|
|
5
|
-
/** Pipeline: read accessible names from Playwright snapshots and attach field metadata in page order. */
|
|
6
|
-
export async function collectInventory(page, excludes = []) {
|
|
7
|
-
const selector = 'input,textarea,select,button,a[href],h1,h2,h3,h4,h5,h6,th,[role]';
|
|
8
|
-
const elements = page.locator(selector);
|
|
9
|
-
const inventory = [];
|
|
10
|
-
for (let index = 0; index < await elements.count(); index++) {
|
|
11
|
-
const element = elements.nth(index);
|
|
12
|
-
const metadata = await element.evaluate((node, omitted) => {
|
|
13
|
-
if (omitted.some(selector => node.closest(selector))) return null;
|
|
14
|
-
const style = getComputedStyle(node);
|
|
15
|
-
const rect = node.getBoundingClientRect();
|
|
16
|
-
if (!rect.width || !rect.height || style.visibility === "hidden" || style.display === "none") return null;
|
|
17
|
-
const type = node.tagName === "SELECT" ? "select" : node.getAttribute("type") ?? (node.tagName === "TEXTAREA" ? "textarea" : "");
|
|
18
|
-
if (type === "hidden") return null;
|
|
19
|
-
return { type, label: Array.from(node.labels ?? []).map(label => label.textContent.trim()).join(" "), placeholder: node.getAttribute("placeholder") ?? "", state: { disabled: node.matches(":disabled") || node.getAttribute("aria-disabled") === "true", required: node.required === true || node.getAttribute("aria-required") === "true", checked: "checked" in node ? node.checked : node.getAttribute("aria-checked"), selected: node.getAttribute("aria-selected"), value: node.tagName === "SELECT" ? node.selectedOptions[0]?.textContent?.trim() ?? "" : undefined }, box: { x: Math.max(0, rect.x), y: Math.max(0, rect.y), width: rect.width, height: rect.height } };
|
|
20
|
-
}, excludes);
|
|
21
|
-
if (!metadata) continue;
|
|
22
|
-
const snapshot = await element.ariaSnapshot();
|
|
23
|
-
const match = snapshot.match(/^- (\w+)(?: "((?:\\.|[^"\\])*)")?/);
|
|
24
|
-
if (!match || !roles.has(match[1])) continue;
|
|
25
|
-
let name = match[2] ?? "";
|
|
26
|
-
try { name = JSON.parse(`"${name}"`); } catch { /* Names from older Playwright snapshots can contain literal newlines. */ }
|
|
27
|
-
inventory.push({ role: match[1], name, ...metadata });
|
|
28
|
-
}
|
|
29
|
-
return inventory;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Pipeline: align role and normalized name, then reconcile moves, renames, types, and states. */
|
|
33
|
-
export function diffInventory(left, right) {
|
|
34
|
-
const rows = Array.from({ length: left.length + 1 }, () => new Uint32Array(right.length + 1));
|
|
35
|
-
for (let i = left.length - 1; i >= 0; i--) for (let j = right.length - 1; j >= 0; j--) rows[i][j] = key(left[i]) === key(right[j]) ? rows[i + 1][j + 1] + 1 : Math.max(rows[i + 1][j], rows[i][j + 1]);
|
|
36
|
-
const aligned = [], unmatchedLeft = [], unmatchedRight = [];
|
|
37
|
-
let i = 0, j = 0;
|
|
38
|
-
while (i < left.length || j < right.length) {
|
|
39
|
-
if (i < left.length && j < right.length && key(left[i]) === key(right[j])) aligned.push([i++, j++]);
|
|
40
|
-
else if (i < left.length && (j === right.length || rows[i + 1][j] >= rows[i][j + 1])) unmatchedLeft.push(i++);
|
|
41
|
-
else unmatchedRight.push(j++);
|
|
42
|
-
}
|
|
43
|
-
const findings = [];
|
|
44
|
-
const add = (kind, a, b) => findings.push({ id: findings.length + 1, kind, left: a === undefined ? null : left[a], right: b === undefined ? null : right[b], leftIndex: a ?? null, rightIndex: b ?? null });
|
|
45
|
-
for (const [a, b] of aligned) {
|
|
46
|
-
if (left[a].type !== right[b].type) add("type", a, b);
|
|
47
|
-
if (JSON.stringify(left[a].state) !== JSON.stringify(right[b].state)) add("state", a, b);
|
|
48
|
-
}
|
|
49
|
-
const used = new Set();
|
|
50
|
-
for (const a of unmatchedLeft) {
|
|
51
|
-
let b = unmatchedRight.find(b => !used.has(b) && key(left[a]) === key(right[b]));
|
|
52
|
-
if (b !== undefined) { used.add(b); add("moved", a, b); continue; }
|
|
53
|
-
b = unmatchedRight.find(b => !used.has(b) && normalize(left[a].name) === normalize(right[b].name));
|
|
54
|
-
if (b !== undefined) { used.add(b); add("type", a, b); continue; }
|
|
55
|
-
b = unmatchedRight.find(b => !used.has(b) && left[a].role === right[b].role && Math.abs(a - b) <= 1);
|
|
56
|
-
if (b !== undefined) { used.add(b); add("renamed", a, b); continue; }
|
|
57
|
-
add("missing", a, undefined);
|
|
58
|
-
}
|
|
59
|
-
for (const b of unmatchedRight) if (!used.has(b)) add("extra", undefined, b);
|
|
60
|
-
return findings;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Record: cover the visible part of either element with one crop. */
|
|
64
|
-
export function inventoryBox(finding, width, height) {
|
|
65
|
-
const boxes = [finding.left?.box, finding.right?.box].filter(Boolean);
|
|
66
|
-
const x = Math.min(width - 1, Math.max(0, Math.floor(Math.min(...boxes.map(box => box.x)))));
|
|
67
|
-
const y = Math.min(height - 1, Math.max(0, Math.floor(Math.min(...boxes.map(box => box.y)))));
|
|
68
|
-
return { x, y, width: Math.max(1, Math.min(width - x, Math.ceil(Math.max(...boxes.map(box => box.x + box.width))) - x)), height: Math.max(1, Math.min(height - y, Math.ceil(Math.max(...boxes.map(box => box.y + box.height))) - y)) };
|
|
69
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { diffInventory } from "./inventory.mjs";
|
|
4
|
-
const field = (name, role = "textbox", type = "text", state = {}) => ({ role, name, type, state, box: { x: 0, y: 0, width: 100, height: 30 } });
|
|
5
|
-
test("a removed field is missing", () => assert.equal(diffInventory([field("Email")], [])[0].kind, "missing"));
|
|
6
|
-
test("a renamed button is renamed", () => assert.equal(diffInventory([field("Continue", "button")], [field("Next", "button")])[0].kind, "renamed"));
|
|
7
|
-
test("swapped fields report a move", () => assert.ok(diffInventory([field("A"), field("B")], [field("B"), field("A")]).some(f => f.kind === "moved")));
|
|
8
|
-
test("a text input against a select reports type", () => assert.equal(diffInventory([field("Country")], [field("Country", "combobox", "select")])[0].kind, "type"));
|
|
9
|
-
test("a disabled field reports state", () => assert.equal(diffInventory([field("Email")], [field("Email", "textbox", "text", { disabled: true })])[0].kind, "state"));
|
|
10
|
-
test("identical inventories have no findings", () => assert.deepEqual(diffInventory([field("Email")], [field(" Email ")]), []));
|
package/src/screens/map.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { resolveStackTargets } from "./stack-auth.mjs";
|
|
4
|
-
|
|
5
|
-
const namePattern = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;
|
|
6
|
-
const text = (value) => typeof value === "string" && value.length > 0;
|
|
7
|
-
const requireValue = (condition, message) => { if (!condition) throw new Error(message); };
|
|
8
|
-
|
|
9
|
-
/** Branch: seed credentials belong only to a loopback origin. */
|
|
10
|
-
export function requireLocalhost(value) {
|
|
11
|
-
const url = new URL(value);
|
|
12
|
-
requireValue(["http:", "https:"].includes(url.protocol) && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname) && !url.username && !url.password, "seed-login requires localhost");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Record: validate the map before opening a browser or creating output files. */
|
|
16
|
-
export function parseMap(input) {
|
|
17
|
-
requireValue(input && typeof input === "object", "Expected a screen map");
|
|
18
|
-
requireValue(Array.isArray(input.widths) && input.widths.length > 0 && input.widths.every(w => Number.isInteger(w) && w > 0 && w <= 10000), "widths must contain positive integers up to 10000");
|
|
19
|
-
requireValue(input.targets && Object.keys(input.targets).length >= 2, "At least two targets are required");
|
|
20
|
-
for (const [name, target] of Object.entries(input.targets)) {
|
|
21
|
-
requireValue(namePattern.test(name) && name !== "pair", "Invalid target name");
|
|
22
|
-
const url = new URL(target.baseUrl);
|
|
23
|
-
requireValue(["http:", "https:"].includes(url.protocol) && !url.username && !url.password && url.port !== "5432", "Targets require HTTP URLs without credentials");
|
|
24
|
-
const auth = target.auth;
|
|
25
|
-
requireValue(auth && text(auth.signedIn), "auth.signedIn must identify a signed-in page");
|
|
26
|
-
if (auth.mode === "browser-session") {
|
|
27
|
-
requireValue(text(auth.domain) && /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/i.test(auth.domain), "Invalid Auth0 domain");
|
|
28
|
-
} else if (auth.mode === "form") {
|
|
29
|
-
requireLocalhost(target.baseUrl);
|
|
30
|
-
for (const field of ["userSelector", "passwordSelector", "submitSelector"]) requireValue(text(auth[field]), `form requires ${field}`);
|
|
31
|
-
} else {
|
|
32
|
-
requireValue(auth.mode === "seed-login", "Unknown auth mode");
|
|
33
|
-
requireLocalhost(target.baseUrl);
|
|
34
|
-
for (const field of ["seedFile", "userField", "passwordField", "userSelector", "passwordSelector", "submitSelector"]) requireValue(text(auth[field]), `seed-login requires ${field}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
requireValue(Array.isArray(input.screens) && input.screens.length > 0, "screens must be a nonempty array");
|
|
38
|
-
const names = new Set();
|
|
39
|
-
for (const screen of input.screens) {
|
|
40
|
-
requireValue(namePattern.test(screen.name) && !names.has(screen.name), "Invalid or duplicate screen name");
|
|
41
|
-
names.add(screen.name);
|
|
42
|
-
requireValue(screen.targets && Object.keys(screen.targets).length >= 2, "Each screen needs two targets");
|
|
43
|
-
for (const [name, route] of Object.entries(screen.targets)) {
|
|
44
|
-
requireValue(input.targets[name], `Unknown target ${name}`);
|
|
45
|
-
requireValue(text(route.path) && route.path.startsWith("/") && !route.path.startsWith("//") && !route.path.includes("\\"), "Screen paths must stay on the target origin");
|
|
46
|
-
requireValue(new URL(route.path, input.targets[name].baseUrl).origin === new URL(input.targets[name].baseUrl).origin, "Screen path changes origin");
|
|
47
|
-
if (route.masks !== undefined) requireValue(Array.isArray(route.masks) && route.masks.every(text), "masks must contain selectors");
|
|
48
|
-
if (route.clicks !== undefined) requireValue(Array.isArray(route.clicks) && route.clicks.every(step => text(step) || (step && text(step.selector) && typeof step.optional === "boolean")), "clicks must contain selectors or optional navigation steps");
|
|
49
|
-
if (route.ready !== undefined) requireValue(text(route.ready), "ready must be a selector");
|
|
50
|
-
if (route.idle !== undefined) requireValue(typeof route.idle === "boolean", "idle must be true or false");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return input;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Resource: resolve a seed file relative to its map. */
|
|
57
|
-
export function loadMap(file, { targets } = {}) {
|
|
58
|
-
const map = parseMap(resolveStackTargets(JSON.parse(readFileSync(file, "utf8")), targets));
|
|
59
|
-
if (map.catalog) map.catalog = path.resolve(path.dirname(file), map.catalog);
|
|
60
|
-
for (const target of Object.values(map.targets)) if (target.setup) target.setup = path.resolve(path.dirname(file), target.setup);
|
|
61
|
-
for (const target of Object.values(map.targets)) if (target.auth.mode === "seed-login") target.auth.seedFile = path.resolve(path.dirname(file), target.auth.seedFile);
|
|
62
|
-
return map;
|
|
63
|
-
}
|
package/src/screens/map.test.mjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { parseMap, requireLocalhost } from "./map.mjs";
|
|
4
|
-
|
|
5
|
-
const fixture = () => ({ widths: [2514, 390], targets: { old: { baseUrl: "https://old.example", auth: { mode: "browser-session", domain: "tenant.auth0.com", signedIn: "[data-user]" } }, next: { baseUrl: "http://localhost:5173", auth: { mode: "browser-session", domain: "tenant.auth0.com", signedIn: "[data-user]" } } }, screens: [{ name: "projects", targets: { old: { path: "/projects" }, next: { path: "/projects" } } }] });
|
|
6
|
-
|
|
7
|
-
test("map preserves widths and resolves target paths", () => {
|
|
8
|
-
const map = parseMap(fixture());
|
|
9
|
-
assert.deepEqual(map.widths, [2514, 390]);
|
|
10
|
-
assert.equal(map.screens[0].targets.old.path, "/projects");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("map rejects traversal, duplicate names, unknown targets, and invalid widths", () => {
|
|
14
|
-
for (const mutate of [m => m.screens[0].name = "../escape", m => m.screens.push(m.screens[0]), m => m.widths = [0], m => m.screens[0].targets.unknown = { path: "/" }, m => m.screens[0].targets.old.path = "https://evil.example", m => m.targets.old.auth.domain = "../tenant"]) {
|
|
15
|
-
const map = fixture();
|
|
16
|
-
mutate(map);
|
|
17
|
-
assert.throws(() => parseMap(map));
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("seed login accepts only exact loopback hosts", () => {
|
|
22
|
-
for (const url of ["http://localhost:3000", "http://127.0.0.1:3000", "http://[::1]:3000"]) assert.doesNotThrow(() => requireLocalhost(url));
|
|
23
|
-
for (const url of ["https://cloud.example", "http://localhost.evil", "http://127.0.0.2", "file:///tmp", "http://localhost@evil.example"]) assert.throws(() => requireLocalhost(url));
|
|
24
|
-
const map = fixture();
|
|
25
|
-
map.targets.old.auth = { mode: "seed-login", signedIn: "main", seedFile: "seed.json", userField: "username", passwordField: "password", userSelector: "#user", passwordSelector: "#password", submitSelector: "#login" };
|
|
26
|
-
assert.throws(() => parseMap(map), /localhost/);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("map accepts optional navigation for onboarding and rejects malformed steps", () => {
|
|
30
|
-
const map = fixture();
|
|
31
|
-
map.screens[0].targets.old.clicks = [{ selector: "[data-guide-skip]", optional: true }];
|
|
32
|
-
assert.doesNotThrow(() => parseMap(map));
|
|
33
|
-
map.screens[0].targets.old.clicks = [{ optional: true }];
|
|
34
|
-
assert.throws(() => parseMap(map));
|
|
35
|
-
});
|