architecture-harness 0.23.0 → 0.23.1

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 (38) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +18 -5
  3. package/src/cli/bash-command-guard.mjs +44 -5
  4. package/src/cli/bash-command-guard.test.mjs +35 -1
  5. package/src/cli/check-commands.mjs +82 -0
  6. package/src/cli/check-commands.test.mjs +190 -0
  7. package/src/cli/check.mjs +34 -13
  8. package/src/cli/ci-template.test.mjs +12 -0
  9. package/src/cli/cli.test.mjs +11 -0
  10. package/src/cli/commit-msg.mjs +5 -2
  11. package/src/cli/commit-msg.test.mjs +12 -0
  12. package/src/cli/generated-file-guard.mjs +10 -1
  13. package/src/cli/generated-file-guard.test.mjs +10 -0
  14. package/src/cli/post-edit-gate.test.mjs +9 -2
  15. package/src/cli/pr-check.mjs +15 -2
  16. package/src/cli/pr-check.test.mjs +19 -9
  17. package/src/cli/qc.mjs +15 -4
  18. package/src/cli/shell-command.mjs +3 -1
  19. package/src/cli/stop-gate.test.mjs +17 -0
  20. package/src/cli/work-order-guard.mjs +2 -2
  21. package/src/config.mjs +15 -0
  22. package/src/config.test.mjs +33 -1
  23. package/src/eslint/rules/no-raw-fetch.mjs +42 -2
  24. package/src/eslint/rules.test.mjs +15 -0
  25. package/src/gates/audit-append-only.mjs +18 -4
  26. package/src/gates/audit-append-only.test.mjs +19 -0
  27. package/src/gates/tenant-predicate.mjs +147 -7
  28. package/src/gates/tenant-predicate.test.mjs +55 -0
  29. package/src/gates/tenant-tables.mjs +5 -2
  30. package/src/gates/tenant-tables.test.mjs +8 -0
  31. package/src/gates/threshold-ratchet.mjs +12 -9
  32. package/src/gates/threshold-ratchet.test.mjs +16 -0
  33. package/src/plugin.test.mjs +28 -0
  34. package/src/screens/auth-run.test.mjs +20 -17
  35. package/src/screens/capture-idle.test.mjs +2 -1
  36. package/src/screens/catalog.test.mjs +3 -3
  37. package/src/screens/chrome.mjs +21 -0
  38. package/templates/github/workflows/ci.yml +13 -5
@@ -14,10 +14,147 @@ import { scrub } from "./scrub.mjs";
14
14
  const DEFAULT_TENANT_COLUMN = "tenant_id";
15
15
  const DEFAULT_TENANT_IDENTIFIER = "tenantId";
16
16
 
17
- // Naming the column is not scoping by it: a select list mentioning the tenant
18
- // column reads every tenant's rows just as happily. The predicate is what counts.
19
- function scopedPattern(column) {
20
- return new RegExp(`\\b${escape(column)}\\s*=`);
17
+ // Naming the column is not scoping by it: a select list or a `set` clause that names the tenant
18
+ // column reaches every tenant's rows just as happily. Only a condition in a `where` clause, or in
19
+ // the `on` clause of a join, counts. The condition compares the column with a value, or with the
20
+ // tenant column of another row as a correlated subquery does, but never with itself. No top-level
21
+ // `or` sits beside it. A comment in the SQL is no condition.
22
+ function equalsTenant(condition, column) {
23
+ const equals = topLevelEquals(condition);
24
+ if (equals === -1) return false;
25
+ const side = new RegExp(`^(?:(\\w+)\\.)?${escape(column)}$`);
26
+ const left = side.exec(condition.slice(0, equals).trim());
27
+ const right = side.exec(condition.slice(equals + 1).trim());
28
+ // Either side may hold the column, as in `$1 = tenant_id`.
29
+ if (!left || !right) return Boolean(left || right);
30
+ // Two rows of one tenant: both sides name their row, and the rows differ.
31
+ return Boolean(left[1] && right[1] && left[1] !== right[1]);
32
+ }
33
+
34
+ /** The index of the first `=` outside parentheses that is no part of `<=`, `>=`, `!=`, `:=` or `==`, or -1. */
35
+ function topLevelEquals(condition) {
36
+ let depth = 0;
37
+ for (let i = 0; i < condition.length; i += 1) {
38
+ if (condition[i] === "(") depth += 1;
39
+ else if (condition[i] === ")") depth -= 1;
40
+ else if (depth === 0 && condition[i] === "=" && !"<>!:=".includes(condition[i - 1] ?? " ") && condition[i + 1] !== "=") return i;
41
+ }
42
+ return -1;
43
+ }
44
+ // A word that ends a `where` or `on` clause at its own depth.
45
+ const CLAUSE_END =
46
+ /^(?:where|on|group\s+by|order\s+by|limit|offset|returning|having|window|union|intersect|except|for\s+(?:update|share)|(?:(?:inner|left|right|full|cross)\s+(?:outer\s+)?)?join)\b/i;
47
+
48
+ /** The index of the last `}` of the `${` that opens at `from`. */
49
+ function interpolationEnd(sql, from) {
50
+ let depth = 1;
51
+ let i = from + 2;
52
+ while (i < sql.length && depth > 0) {
53
+ if (sql[i] === "{") depth += 1;
54
+ else if (sql[i] === "}") depth -= 1;
55
+ i += 1;
56
+ }
57
+ return i - 1;
58
+ }
59
+
60
+ /** The SQL with each interpolation and each string literal as one opaque value, and each comment gone. */
61
+ function plainSql(sql) {
62
+ let out = "";
63
+ for (let i = 0; i < sql.length; i += 1) {
64
+ if (sql.startsWith("${", i)) {
65
+ i = interpolationEnd(sql, i);
66
+ out += "$x";
67
+ } else if (sql[i] === "'") {
68
+ // A quote inside the literal is doubled, and a `${}` inside it is code with quotes of its own.
69
+ for (i += 1; i < sql.length && !(sql[i] === "'" && sql[i + 1] !== "'"); i += 1) {
70
+ if (sql.startsWith("${", i)) i = interpolationEnd(sql, i);
71
+ else if (sql[i] === "'") i += 1;
72
+ }
73
+ out += "$s";
74
+ } else if (sql.startsWith("--", i)) {
75
+ while (i < sql.length && sql[i] !== "\n") i += 1;
76
+ out += " ";
77
+ } else if (sql.startsWith("/*", i)) {
78
+ const end = sql.indexOf("*/", i + 2);
79
+ i = end === -1 ? sql.length : end + 1;
80
+ out += " ";
81
+ } else {
82
+ out += sql[i];
83
+ }
84
+ }
85
+ return out;
86
+ }
87
+
88
+ /** The parts of a condition between each top-level `word`, or the whole condition when it has none. */
89
+ function splitTopLevel(condition, word) {
90
+ const parts = [];
91
+ const pattern = new RegExp(`^${word}\\b`, "i");
92
+ let depth = 0;
93
+ let start = 0;
94
+ for (let i = 0; i < condition.length; i += 1) {
95
+ if (condition[i] === "(") depth += 1;
96
+ else if (condition[i] === ")") depth -= 1;
97
+ else if (depth === 0 && /\W/.test(condition[i - 1] ?? " ") && pattern.test(condition.slice(i))) {
98
+ parts.push(condition.slice(start, i));
99
+ start = i + word.length;
100
+ }
101
+ }
102
+ parts.push(condition.slice(start));
103
+ return parts.map((part) => part.trim());
104
+ }
105
+
106
+ /** A condition without the parentheses that wrap all of it. */
107
+ function unwrap(condition) {
108
+ let text = condition.trim();
109
+ while (text.startsWith("(") && text.endsWith(")")) {
110
+ let depth = 0;
111
+ let closesAtEnd = true;
112
+ for (let i = 0; i < text.length - 1; i += 1) {
113
+ if (text[i] === "(") depth += 1;
114
+ else if (text[i] === ")") depth -= 1;
115
+ if (depth === 0) {
116
+ closesAtEnd = false;
117
+ break;
118
+ }
119
+ }
120
+ if (!closesAtEnd) break;
121
+ text = text.slice(1, -1).trim();
122
+ }
123
+ return text;
124
+ }
125
+
126
+ /** True when every row the condition admits has the tenant column equal to one value. */
127
+ function conditionScopes(condition, column) {
128
+ const text = unwrap(condition);
129
+ if (splitTopLevel(text, "or").length > 1) return false;
130
+ const conjuncts = splitTopLevel(text, "and");
131
+ if (conjuncts.length > 1) return conjuncts.some((conjunct) => conditionScopes(conjunct, column));
132
+ return equalsTenant(text, column);
133
+ }
134
+
135
+ /** Each `where` clause, and each `on` clause of a join, with the text up to its end. */
136
+ function conditionClauses(sql) {
137
+ const clauses = [];
138
+ const keyword = /\b(where|on)\b(?!\s+conflict\b)/gi;
139
+ for (let match = keyword.exec(sql); match !== null; match = keyword.exec(sql)) {
140
+ let depth = 0;
141
+ let end = sql.length;
142
+ for (let i = match.index + match[0].length; i < sql.length; i += 1) {
143
+ if (sql[i] === "(") depth += 1;
144
+ else if (sql[i] === ")") {
145
+ if (depth === 0) {
146
+ end = i;
147
+ break;
148
+ }
149
+ depth -= 1;
150
+ } else if (depth === 0 && /\W/.test(sql[i - 1]) && CLAUSE_END.test(sql.slice(i))) {
151
+ end = i;
152
+ break;
153
+ }
154
+ }
155
+ clauses.push(sql.slice(match.index + match[0].length, end));
156
+ }
157
+ return clauses;
21
158
  }
22
159
  // Nine of eleven features write their generic helpers with the table name as a
23
160
  // runtime value — `from ${table}`. Matching only literal names skipped those
@@ -28,9 +165,12 @@ const DYNAMIC_TABLE = /\b(?:from|join|into|update)\s+\$\{/;
28
165
 
29
166
  /** True when the statement actually filters or writes the tenant, not merely names it. */
30
167
  function scopedBy(sql, column) {
31
- if (scopedPattern(column).test(sql)) return true;
32
- const inserted = /insert\s+into\s+(?:\w+|\$\{[^}]*\})\s*\(([^)]*)\)/i.exec(sql);
33
- return inserted ? new RegExp(`\\b${escape(column)}\\b`).test(inserted[1]) : false;
168
+ const plain = plainSql(sql);
169
+ const inserted = /insert\s+into\s+(?:\w+|\$x)\s*\(([^)]*)\)/i.exec(plain);
170
+ if (inserted && new RegExp(`\\b${escape(column)}\\b`).test(inserted[1])) return true;
171
+ // Each side of a set operation reads rows of its own, so each side carries the tenant.
172
+ const operands = ["union", "intersect", "except"].reduce((parts, word) => parts.flatMap((part) => splitTopLevel(part, word)), [plain]);
173
+ return operands.every((operand) => conditionClauses(operand).some((clause) => conditionScopes(clause, column)));
34
174
  }
35
175
 
36
176
  /** A statement that reads only a bound name touches no table and needs no predicate. */
@@ -28,6 +28,61 @@ test("an update that does not carry the tenant is a finding", () => {
28
28
  assert.equal(problems.length, 1);
29
29
  });
30
30
 
31
+ test("a tenant in the set clause of an update is not a predicate: the row may belong to any tenant", () => {
32
+ assert.equal(checkTenantPredicate(one("update projects set tenant_id = $1 where id = $2"), owned).length, 1);
33
+ });
34
+
35
+ test("a tenant beside a top-level or admits every tenant's rows, and is a finding", () => {
36
+ assert.equal(checkTenantPredicate(one("select id from projects where id = $1 or tenant_id = $2"), owned).length, 1);
37
+ assert.equal(checkTenantPredicate(one("select id from projects where tenant_id = $1 or true"), owned).length, 1);
38
+ assert.equal(checkTenantPredicate(one("select id from projects where (tenant_id = $1 or id = $2) and code = $3"), owned).length, 1);
39
+ });
40
+
41
+ test("an or nested inside a conjunct beside the tenant passes", () => {
42
+ const sql = "select id from projects where tenant_id = $1 and (status = $2 or status = $3)";
43
+ assert.deepEqual(checkTenantPredicate(one(sql), owned), []);
44
+ });
45
+
46
+ test("a tenant column compared with itself is a finding", () => {
47
+ assert.equal(checkTenantPredicate(one("select id from projects where tenant_id = tenant_id"), owned).length, 1);
48
+ assert.equal(checkTenantPredicate(one("select id from projects p where p.tenant_id = p.tenant_id"), owned).length, 1);
49
+ });
50
+
51
+ test("a string literal is one value: an or or a comment marker inside it changes nothing", () => {
52
+ const count = (sql) => checkTenantPredicate(one(sql), owned).length;
53
+ assert.equal(count("select * from projects where tenant_id = $1 and status <> 'draft or review'"), 0);
54
+ assert.equal(count("select * from projects where note = 'a -- b' and tenant_id = $1"), 0);
55
+ assert.equal(count("select * from projects where note = 'it''s' and tenant_id = $1"), 0);
56
+ assert.equal(count("select * from projects where tenant_id = $1 and note = '/*' or true or note = '*/'"), 1);
57
+ });
58
+
59
+ test("each side of a union, intersect or except carries the tenant", () => {
60
+ const count = (sql) => checkTenantPredicate(one(sql), owned).length;
61
+ assert.equal(count("select id from projects where tenant_id = $1 union select id from projects"), 1);
62
+ assert.equal(count("select id from projects where tenant_id = $1 except select id from projects"), 1);
63
+ assert.equal(count("select id from projects where tenant_id = $1 union all select id from projects where tenant_id = $1"), 0);
64
+ });
65
+
66
+ test("the tenant column may stand on either side of the equals sign", () => {
67
+ assert.equal(checkTenantPredicate(one("select * from projects where $1 = tenant_id"), owned).length, 0);
68
+ assert.equal(checkTenantPredicate(one("select * from projects where tenant_id <= $1"), owned).length, 1);
69
+ });
70
+
71
+ test("a correlated subquery that matches the tenant of the outer row passes", () => {
72
+ const sql = "exists (select 1 from projects v where v.tenant_id = outer_row.tenant_id and v.id = outer_row.project_id)";
73
+ assert.deepEqual(checkTenantPredicate(one(sql), owned), []);
74
+ });
75
+
76
+ test("a tenant inside an sql comment is no predicate", () => {
77
+ assert.equal(checkTenantPredicate(one("delete from projects where id = $1 -- tenant_id = $2"), owned).length, 1);
78
+ assert.equal(checkTenantPredicate(one("delete from projects where id = $1 /* and tenant_id = $2 */"), owned).length, 1);
79
+ });
80
+
81
+ test("an interpolated tenant value passes, and an interpolation cannot hide an or", () => {
82
+ assert.deepEqual(checkTenantPredicate(one("select id from projects where tenant_id = ${tenantId}"), owned), []);
83
+ assert.equal(checkTenantPredicate(one("select id from projects where tenant_id = ${f(\"a\")} or id = $2"), owned).length, 1);
84
+ });
85
+
31
86
  test("a statement reading only a common table expression needs no predicate", () => {
32
87
  const bound = new Set(["projects"]);
33
88
  assert.deepEqual(checkTenantPredicate(one("select id from projects", bound), owned), []);
@@ -34,14 +34,17 @@ function block(source, open) {
34
34
  */
35
35
  export function tenantScopedTables(source, options = {}) {
36
36
  const factory = escape(options.tableFactory ?? DEFAULT_TABLE_FACTORY);
37
- const tablePattern = new RegExp(`${factory}\\(\\s*"([a-z_][a-z0-9_]*)"\\s*,\\s*\\{`, "g");
37
+ // Either quote, and the columns as an object or as drizzle's callback, `(t) => ({ ... })`. A table this
38
+ // misses gets no policy and no finding, so the forms it reads are wide on purpose.
39
+ const callback = `(?:(?:\\(\\s*\\w*\\s*\\)|\\w+)\\s*=>\\s*\\(?\\s*)?`;
40
+ const tablePattern = new RegExp(`\\b${factory}\\(\\s*(["'\`])([a-z_][a-z0-9_]*)\\1\\s*,\\s*${callback}\\{`, "g");
38
41
  const column = new RegExp(`\\b${escape(options.column ?? DEFAULT_COLUMN)}\\b`);
39
42
 
40
43
  const found = new Set();
41
44
  let match = tablePattern.exec(source);
42
45
  while (match !== null) {
43
46
  const body = block(source, match.index + match[0].length - 1);
44
- if (column.test(body)) found.add(match[1]);
47
+ if (column.test(body)) found.add(match[2]);
45
48
  match = tablePattern.exec(source);
46
49
  }
47
50
  return [...found].sort();
@@ -31,6 +31,14 @@ test("a nested object inside a column definition does not end the table early",
31
31
  assert.deepEqual(tenantScopedTables(source), ["photos"]);
32
32
  });
33
33
 
34
+ test("a single-quoted name and drizzle's callback form are listed too", () => {
35
+ const source = `export const b = pgTable('b', { tenantId: uuid() });
36
+ export const c = pgTable("c", (t) => ({ tenantId: t.uuid() }));
37
+ export const d = pgTable(\`d\`, t => ({ tenantId: t.uuid() }));
38
+ export const e = myPgTable("e", { tenantId: uuid() });`;
39
+ assert.deepEqual(tenantScopedTables(source), ["b", "c", "d"]);
40
+ });
41
+
34
42
  test("a source with no table yields nothing", () => {
35
43
  assert.deepEqual(tenantScopedTables("export const queries = {};"), []);
36
44
  });
@@ -23,15 +23,18 @@ export function checkThresholdRatchet(before, after, adrs, { registry }) {
23
23
  };
24
24
  for (const [key, entry] of Object.entries(after)) {
25
25
  const was = before[key];
26
- // The comparator in force before the change is the policy the change answers to.
27
- if (typeof was?.value !== "number" || typeof entry?.value !== "number") continue;
28
- if (!loosened(was.comparator, was.value, entry.value)) continue;
29
- if (citedByAdr(key)) continue;
30
- problems.push({
31
- path: registry,
32
- rule: "loosened-threshold",
33
- detail: `'${key}' moves from ${was.value} to ${entry.value}, and a ${was.comparator} that moves this way loosens; a changed ADR must name '${key}'`,
34
- });
26
+ if (typeof was?.value !== "number" || citedByAdr(key)) continue;
27
+ // A limit with no number, or one that now points the other way, no longer holds the old line.
28
+ let detail = null;
29
+ if (typeof entry?.value !== "number") {
30
+ detail = `'${key}' (${was.comparator} ${was.value}) no longer has a number, so it limits nothing`;
31
+ } else if (entry.comparator !== was.comparator) {
32
+ detail = `'${key}' changes from ${was.comparator} ${was.value} to ${entry.comparator} ${entry.value}, which is no longer the same limit`;
33
+ } else if (loosened(was.comparator, was.value, entry.value)) {
34
+ // The comparator in force before the change is the policy the change answers to.
35
+ detail = `'${key}' moves from ${was.value} to ${entry.value}, and a ${was.comparator} that moves this way loosens`;
36
+ }
37
+ if (detail) problems.push({ path: registry, rule: "loosened-threshold", detail: `${detail}; a changed ADR must name '${key}'` });
35
38
  }
36
39
  // Dropping a limit is the widest loosening of all, so it answers to the same rule.
37
40
  for (const [key, was] of Object.entries(before)) {
@@ -58,3 +58,19 @@ test("the comparator in force at the base judges the change", () => {
58
58
  const after = { ...base, filelength: { value: 550, comparator: "min" } };
59
59
  assert.equal(check(after).length, 1);
60
60
  });
61
+
62
+ test("a comparator that flips at the same value fails, since the limit now points the other way", () => {
63
+ const problems = check({ ...base, filelength: { value: 500, comparator: "min" } });
64
+ assert.equal(problems.length, 1);
65
+ assert.match(problems[0].detail, /from max 500 to min 500/);
66
+ });
67
+
68
+ test("a value that is no longer a number fails, as a removal does, unless a changed ADR names it", () => {
69
+ for (const value of [null, "500", undefined]) {
70
+ const problems = check(moved("filelength", value));
71
+ assert.equal(problems.length, 1, String(value));
72
+ assert.match(problems[0].detail, /no longer has a number/);
73
+ }
74
+ const adrs = [{ path: "docs/decisions/0033-files.md", text: "We drop `filelength`." }];
75
+ assert.deepEqual(check(moved("filelength", null), adrs), []);
76
+ });
@@ -0,0 +1,28 @@
1
+ import { strict as assert } from "node:assert";
2
+ import { readdirSync, readFileSync } from "node:fs";
3
+ import { test } from "node:test";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const PLUGIN = fileURLToPath(new URL("../../../", import.meta.url));
7
+ const EDIT_TOOLS = ["Write", "Edit", "MultiEdit", "NotebookEdit"];
8
+
9
+ test("every skill applies only where qc.config.json exists, in its description and in its body", () => {
10
+ const skills = readdirSync(`${PLUGIN}skills`);
11
+ assert.ok(skills.length > 0);
12
+ for (const skill of skills) {
13
+ const text = readFileSync(`${PLUGIN}skills/${skill}/SKILL.md`, "utf8");
14
+ const description = /^description: (.+)$/m.exec(text)?.[1] ?? "";
15
+ assert.match(description, /only in a repository with a `qc\.config\.json`/, skill);
16
+ assert.match(text, /This skill applies only to a repository with a `qc\.config\.json` at its root/, skill);
17
+ }
18
+ });
19
+
20
+ test("each guard that keeps an edit inside its paths runs on every edit tool", () => {
21
+ const { hooks } = JSON.parse(readFileSync(`${PLUGIN}hooks/hooks.json`, "utf8"));
22
+ for (const guard of ["pre-edit-guard.sh", "controller-guard.mjs", "slot-guard.mjs"]) {
23
+ const entry = hooks.PreToolUse.find((group) => group.hooks.some((hook) => hook.command.includes(guard)));
24
+ assert.ok(entry, guard);
25
+ const tools = entry.matcher.split("|");
26
+ for (const tool of EDIT_TOOLS) assert.ok(tools.includes(tool), `${guard} misses ${tool}`);
27
+ }
28
+ });
@@ -9,6 +9,9 @@ import { chromium } from "playwright";
9
9
  import { browserSession, seedSession } from "./auth.mjs";
10
10
  import { runScreens } from "../cli/screens.mjs";
11
11
  import { captureScreens } from "./capture.mjs";
12
+ import { chromeMissing } from "./chrome.mjs";
13
+
14
+ const noChrome = await chromeMissing(chromium);
12
15
 
13
16
  async function fixture(t) {
14
17
  const root = mkdtempSync(path.join(os.tmpdir(), "qc-auth-run-"));
@@ -32,33 +35,33 @@ async function fixture(t) {
32
35
  return { root, requests, target, state, save };
33
36
  }
34
37
 
35
- test("expired application state refreshes once through the login path and persists the renewed cookie", async t => {
38
+ test("expired application state refreshes once through the login path and persists the renewed cookie", { skip: noChrome }, async t => {
36
39
  const f = await fixture(t);
37
40
  f.save(["sso"]);
38
- const session = await browserSession(chromium, f.target, { targetName: "mono-local", timeout: 3000, allowInteractive: false });
41
+ const session = await browserSession(chromium, f.target, { targetName: "new-local", timeout: 3000, allowInteractive: false });
39
42
  await session.close();
40
43
  assert.equal(f.requests.filter(p => p.startsWith("/bff/login")).length, 1);
41
44
  assert.ok(JSON.parse(readFileSync(f.state)).cookies.some(c => c.name === "app"));
42
45
  });
43
46
 
44
- test("seed errors name the target and failing field without exposing browser diagnostics or credentials", async t => {
47
+ test("seed errors name the target and failing field without exposing browser diagnostics or credentials", { skip: noChrome }, async t => {
45
48
  const f = await fixture(t);
46
49
  const target = { ...f.target, auth: { ...f.target.auth, mode: "seed-login", path: "/login", userSelector: "#user", passwordSelector: "#missing", submitSelector: "#submit" } };
47
- await assert.rejects(seedSession(chromium, target, { targetName: "legacy-local", credentials: { user: "test", password: randomUUID() }, timeout: 3000 }), error => {
48
- assert.equal(error.message, "legacy-local: seed sign-in failed at the password field");
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");
49
52
  return true;
50
53
  });
51
54
  });
52
55
 
53
- test("run stops with code four and one human instruction without capturing or retrying", async t => {
56
+ test("run stops with code four and one human instruction without capturing or retrying", { skip: noChrome }, async t => {
54
57
  const f = await fixture(t);
55
58
  f.save([]);
56
59
  const map = path.join(f.root, "map.json");
57
- writeFileSync(map, JSON.stringify({ widths: [200], targets: { "mono-local": f.target, other: f.target }, screens: [{ name: "projects", targets: { "mono-local": { path: "/projects" }, other: { path: "/projects" } } }] }));
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" } } }] }));
58
61
  const lines = [];
59
- const code = await runScreens(["run", "projects", "--map", map, "--targets", "mono-local,other", "--out", path.join(f.root, "out"), "--timeout", "3000", "--sign-in-timeout", "100"], { say: line => lines.push(line) });
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) });
60
63
  assert.equal(code, 4);
61
- assert.deepEqual(lines, ["mono-local: needs a person to sign in (run qc screens auth mono-local --headed)"]);
64
+ assert.deepEqual(lines, ["new-local: needs a person to sign in (run qc screens auth new-local --headed)"]);
62
65
  assert.equal(f.requests.filter(p => p.startsWith("/bff/login")).length, 1);
63
66
  });
64
67
 
@@ -78,22 +81,22 @@ test("capture checks each target once before navigating any screen and closes ea
78
81
 
79
82
 
80
83
  // A headed browser needs a display, which a Linux CI runner lacks.
81
- test("headed auth accepts the named target and saves a valid session", { skip: process.platform === "linux" && !process.env.DISPLAY }, async t => {
84
+ test("headed auth accepts the named target and saves a valid session", { skip: noChrome || (process.platform === "linux" && !process.env.DISPLAY) }, async t => {
82
85
  const f = await fixture(t);
83
86
  f.save(["app"]);
84
87
  const map = path.join(f.root, "map.json");
85
- writeFileSync(map, JSON.stringify({ widths: [200], targets: { "mono-local": f.target, other: f.target }, screens: [{ name: "projects", targets: { "mono-local": { path: "/projects" }, other: { path: "/projects" } } }] }));
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" } } }] }));
86
89
  const lines = [];
87
- assert.equal(await runScreens(["auth", "mono-local", "--headed", "--map", map, "--timeout", "3000"], { say: line => lines.push(line) }), 0);
88
- assert.deepEqual(lines, ["mono-local: signed in"]);
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"]);
89
92
  assert.ok(JSON.parse(readFileSync(f.state)).cookies.some(c => c.name === "app"));
90
93
  });
91
94
 
92
- test("parallel sessions preserve the shared saved state and write a complete refresh ledger", async t => {
95
+ test("parallel sessions preserve the shared saved state and write a complete refresh ledger", { skip: noChrome }, async t => {
93
96
  const f = await fixture(t);
94
97
  f.save(["sso"]);
95
98
  const { targetSession } = await import("./stack-auth.mjs");
96
- const sessions = await Promise.all(Array.from({ length: 3 }, () => targetSession(chromium, f.target, { targetName: "mono-local", timeout: 3000, allowInteractive: false })));
99
+ const sessions = await Promise.all(Array.from({ length: 3 }, () => targetSession(chromium, f.target, { targetName: "new-local", timeout: 3000, allowInteractive: false })));
97
100
  await Promise.all(sessions.map(s => s.close()));
98
101
  assert.equal(f.requests.filter(p => p.startsWith("/bff/login")).length, 1);
99
102
  assert.ok(JSON.parse(readFileSync(f.state)).cookies.some(c => c.name === "app"));
@@ -110,8 +113,8 @@ test("parallel sessions preserve the shared saved state and write a complete ref
110
113
  test("a browser launch failure names the target and method without asking for human sign-in", async t => {
111
114
  const f = await fixture(t);
112
115
  f.save([]);
113
- await assert.rejects(browserSession({ launch: async () => { throw new Error("private browser diagnostics"); } }, f.target, { targetName: "mono-local", allowInteractive: false }), error => {
114
- assert.equal(error.message, "mono-local: browser-session sign-in failed at the browser");
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");
115
118
  assert.equal(error.exitCode, undefined);
116
119
  return true;
117
120
  });
@@ -6,8 +6,9 @@ import os from "node:os";
6
6
  import path from "node:path";
7
7
  import { chromium } from "playwright";
8
8
  import { capturePage } from "./capture.mjs";
9
+ import { chromeMissing } from "./chrome.mjs";
9
10
 
10
- test("an entry with idle false captures a page that polls forever", async t => {
11
+ test("an entry with idle false captures a page that polls forever", { skip: await chromeMissing(chromium) }, async t => {
11
12
  const root = mkdtempSync(path.join(os.tmpdir(), "qc-capture-idle-"));
12
13
  const server = http.createServer((req, res) => {
13
14
  if (req.url === "/poll") return res.end("ok");
@@ -29,8 +29,8 @@ test("catalog entries carry the idle option for each app family", async () => {
29
29
  const root = mkdtempSync(path.join(os.tmpdir(), "qc-catalog-"));
30
30
  try {
31
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: { "legacy-local": { family: "legacy" }, "mono-local": { family: "mono" } }, screens: [] }, path.join(root, "map.json"));
33
- assert.equal(map.screens[0].targets["legacy-local"].idle, false);
34
- assert.equal(map.screens[0].targets["mono-local"].idle, undefined);
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
35
  } finally { rmSync(root, { recursive: true, force: true }); }
36
36
  });
@@ -0,0 +1,21 @@
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
+ }
@@ -38,11 +38,19 @@ jobs:
38
38
  - if: github.event_name == 'pull_request'
39
39
  run: npx qc prose --base "origin/$GITHUB_BASE_REF" --pr-body-event
40
40
 
41
- # Uncomment each as the repository grows the thing it checks.
42
- # - run: pnpm typecheck
43
- # - run: pnpm lint
44
- # - run: pnpm dup:check
45
- # - run: pnpm test
41
+ # Typecheck and lint as the stop gate runs them: a root script wins, else the installed tool.
42
+ # CI is the one check an agent cannot skip, so each step is on, and without its tool it says it skipped.
43
+ - run: |
44
+ if node -e "process.exit(require('./package.json').scripts?.typecheck ? 0 : 1)"; then pnpm run typecheck
45
+ elif [ -x node_modules/.bin/tsc ]; then pnpm exec tsc -b --pretty false
46
+ else echo "::notice::typecheck skipped: no typecheck script and no tsc"
47
+ fi
48
+ - run: |
49
+ if node -e "process.exit(require('./package.json').scripts?.lint ? 0 : 1)"; then pnpm run lint
50
+ elif [ -x node_modules/.bin/eslint ]; then pnpm exec eslint . --max-warnings 0
51
+ else echo "::notice::lint skipped: no lint script and no eslint"
52
+ fi
53
+ - run: pnpm run --if-present dup:check
46
54
 
47
55
  # Unit tests in eight hosted shards. A self-hosted runner that goes offline leaves a job queued;
48
56
  # `qc watch --pr` reports a check queued for over 15 minutes. A repository with no test:unit script skips it.