lynkeus 0.2.0 → 0.3.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/lib/cases/ahead.d.ts +31 -0
- package/lib/cases/ahead.js +90 -0
- package/lib/cases/fixtures.d.ts +12 -0
- package/lib/cases/fixtures.js +32 -0
- package/lib/cases/flakes.d.ts +28 -0
- package/lib/cases/flakes.js +61 -0
- package/lib/cases/format.d.ts +5 -0
- package/lib/cases/format.js +30 -4
- package/lib/cases/portClaim.d.ts +10 -0
- package/lib/cases/portClaim.js +55 -0
- package/lib/cases/runfile.d.ts +24 -0
- package/lib/cases/runfile.js +108 -0
- package/lib/cases/runner.d.ts +80 -3
- package/lib/cases/runner.js +387 -40
- package/lib/cases/templates.d.ts +2 -2
- package/lib/cases/templates.js +14 -4
- package/lib/cases/traces.d.ts +58 -0
- package/lib/cases/traces.js +250 -0
- package/lib/cli.js +27 -6
- package/lib/commands/cases.js +360 -37
- package/lib/commands/check.d.ts +6 -0
- package/lib/commands/check.js +8 -3
- package/lib/commands/drive.js +32 -8
- package/lib/commands/headless.js +12 -2
- package/lib/commands/init.d.ts +6 -0
- package/lib/commands/init.js +78 -21
- package/lib/commands/report.d.ts +97 -0
- package/lib/commands/report.js +228 -0
- package/lib/config.d.ts +10 -1
- package/lib/device/agentVersion.d.ts +7 -0
- package/lib/device/agentVersion.js +12 -0
- package/lib/device/devices.d.ts +5 -0
- package/lib/device/devices.js +27 -0
- package/lib/flow/runner.js +33 -1
- package/lib/flow/types.d.ts +2 -1
- package/lib/knowledge/contrast.d.ts +45 -0
- package/lib/knowledge/contrast.js +114 -0
- package/lib/knowledge/errors.js +1 -1
- package/lib/knowledge/lint.d.ts +2 -0
- package/lib/knowledge/lint.js +13 -3
- package/lib/registry.d.ts +5 -0
- package/lib/targets.d.ts +10 -1
- package/lib/targets.js +16 -3
- package/package.json +10 -6
- package/src/cases/ahead.ts +111 -0
- package/src/cases/fixtures.ts +37 -0
- package/src/cases/flakes.ts +67 -0
- package/src/cases/format.ts +31 -6
- package/src/cases/portClaim.ts +52 -0
- package/src/cases/runfile.ts +119 -0
- package/src/cases/runner.ts +446 -46
- package/src/cases/templates.ts +14 -4
- package/src/cases/traces.ts +298 -0
- package/src/cli.ts +28 -6
- package/src/commands/cases.ts +375 -37
- package/src/commands/check.ts +11 -4
- package/src/commands/drive.ts +31 -8
- package/src/commands/headless.ts +12 -2
- package/src/commands/init.ts +84 -20
- package/src/commands/report.ts +272 -0
- package/src/config.ts +6 -2
- package/src/device/agentVersion.ts +15 -0
- package/src/device/devices.ts +28 -0
- package/src/flow/runner.ts +35 -1
- package/src/flow/types.ts +2 -2
- package/src/knowledge/contrast.ts +135 -0
- package/src/knowledge/errors.ts +1 -1
- package/src/knowledge/lint.ts +15 -4
- package/src/registry.ts +2 -0
- package/src/targets.ts +17 -3
- package/lib/__tests__/args.test.d.ts +0 -1
- package/lib/__tests__/args.test.js +0 -69
- package/lib/__tests__/check.test.d.ts +0 -1
- package/lib/__tests__/check.test.js +0 -60
- package/lib/__tests__/init.test.d.ts +0 -1
- package/lib/__tests__/init.test.js +0 -42
- package/lib/__tests__/record.test.d.ts +0 -1
- package/lib/__tests__/record.test.js +0 -44
- package/lib/__tests__/snapshot.test.d.ts +0 -1
- package/lib/__tests__/snapshot.test.js +0 -47
- package/lib/__tests__/targets.test.d.ts +0 -1
- package/lib/__tests__/targets.test.js +0 -127
- package/lib/cases/__tests__/format.test.d.ts +0 -1
- package/lib/cases/__tests__/format.test.js +0 -61
- package/lib/cases/__tests__/runner.test.d.ts +0 -1
- package/lib/cases/__tests__/runner.test.js +0 -188
- package/lib/knowledge/__tests__/edges.test.d.ts +0 -1
- package/lib/knowledge/__tests__/edges.test.js +0 -25
- package/lib/knowledge/__tests__/events.test.d.ts +0 -1
- package/lib/knowledge/__tests__/events.test.js +0 -39
- package/lib/knowledge/__tests__/extract.test.d.ts +0 -1
- package/lib/knowledge/__tests__/extract.test.js +0 -69
- package/lib/knowledge/__tests__/frontier.test.d.ts +0 -1
- package/lib/knowledge/__tests__/frontier.test.js +0 -57
- package/lib/knowledge/__tests__/funnels.test.d.ts +0 -1
- package/lib/knowledge/__tests__/funnels.test.js +0 -40
- package/lib/knowledge/__tests__/lint.test.d.ts +0 -1
- package/lib/knowledge/__tests__/lint.test.js +0 -53
- package/lib/knowledge/__tests__/perf.test.d.ts +0 -1
- package/lib/knowledge/__tests__/perf.test.js +0 -34
- package/lib/knowledge/__tests__/plan.test.d.ts +0 -1
- package/lib/knowledge/__tests__/plan.test.js +0 -35
- package/lib/knowledge/__tests__/query.test.d.ts +0 -1
- package/lib/knowledge/__tests__/query.test.js +0 -55
- package/lib/knowledge/__tests__/screens.test.d.ts +0 -1
- package/lib/knowledge/__tests__/screens.test.js +0 -30
- package/lib/knowledge/__tests__/why.test.d.ts +0 -1
- package/lib/knowledge/__tests__/why.test.js +0 -28
- package/src/__tests__/args.test.ts +0 -82
- package/src/__tests__/check.test.ts +0 -71
- package/src/__tests__/init.test.ts +0 -52
- package/src/__tests__/record.test.ts +0 -49
- package/src/__tests__/snapshot.test.ts +0 -51
- package/src/__tests__/targets.test.ts +0 -132
- package/src/cases/__tests__/format.test.ts +0 -76
- package/src/cases/__tests__/runner.test.ts +0 -230
- package/src/knowledge/__tests__/edges.test.ts +0 -34
- package/src/knowledge/__tests__/events.test.ts +0 -45
- package/src/knowledge/__tests__/extract.test.ts +0 -88
- package/src/knowledge/__tests__/frontier.test.ts +0 -77
- package/src/knowledge/__tests__/funnels.test.ts +0 -58
- package/src/knowledge/__tests__/lint.test.ts +0 -66
- package/src/knowledge/__tests__/perf.test.ts +0 -41
- package/src/knowledge/__tests__/plan.test.ts +0 -52
- package/src/knowledge/__tests__/query.test.ts +0 -74
- package/src/knowledge/__tests__/screens.test.ts +0 -37
- package/src/knowledge/__tests__/why.test.ts +0 -40
package/src/commands/cases.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { type ChildProcess, spawn } from 'node:child_process';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
|
|
5
6
|
import { Fixtures } from '../cases/fixtures.js';
|
|
6
7
|
import { readCases } from '../cases/format.js';
|
|
7
|
-
import
|
|
8
|
+
import type { Case } from '../cases/format.js';
|
|
9
|
+
import { type CasesConfig, type CaseReport, missingFixtures, type Prepared, preparable, runCase } from '../cases/runner.js';
|
|
8
10
|
import { CONFIG, EXAMPLE_CASE, FIXTURES, FORMAT } from '../cases/templates.js';
|
|
9
|
-
import {
|
|
11
|
+
import { claimPorts } from '../cases/portClaim.js';
|
|
12
|
+
import { configFile, portFromEnv } from '../config.js';
|
|
10
13
|
import { readJson, writeJson } from '../files.js';
|
|
14
|
+
import { Ahead, InMemory, type Store } from '../cases/ahead.js';
|
|
15
|
+
import { Flakes } from '../cases/flakes.js';
|
|
16
|
+
import { RunFile } from '../cases/runfile.js';
|
|
11
17
|
import { eventsFile } from '../knowledge/events.js';
|
|
12
|
-
import { define } from '../registry.js';
|
|
18
|
+
import { type Base, define } from '../registry.js';
|
|
19
|
+
import { describeChanges, pushRun, service } from './report.js';
|
|
20
|
+
import { TraceSink } from '../cases/traces.js';
|
|
13
21
|
|
|
14
22
|
const startHost = async (root: string, err: (line: string) => void): Promise<ChildProcess> => {
|
|
15
23
|
// Its own process group: the host starts a test runner of its own, and stopping one without the other leaves an app dialing in.
|
|
@@ -47,11 +55,30 @@ const stopGroup = (pid: number) => {
|
|
|
47
55
|
} catch {}
|
|
48
56
|
};
|
|
49
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Stops a host and waits until it is gone. The next case's host dials the same port, and a host still on
|
|
60
|
+
* its way out dials it too: whichever reaches the driver first is the one the case talks to.
|
|
61
|
+
*/
|
|
62
|
+
const stopHost = async (host: ChildProcess): Promise<void> => {
|
|
63
|
+
if (!host.pid || host.exitCode !== null || host.signalCode !== null) return;
|
|
64
|
+
const gone = new Promise<void>((resolve) => host.once('exit', () => resolve()));
|
|
65
|
+
host.stdin?.end();
|
|
66
|
+
stopGroup(host.pid);
|
|
67
|
+
const late = setTimeout(() => {
|
|
68
|
+
try {
|
|
69
|
+
process.kill(-host.pid!, 'SIGKILL');
|
|
70
|
+
} catch {}
|
|
71
|
+
}, 2000);
|
|
72
|
+
await gone;
|
|
73
|
+
clearTimeout(late);
|
|
74
|
+
};
|
|
75
|
+
|
|
50
76
|
const describe = (report: CaseReport): string => {
|
|
51
|
-
const counts = { passed: 0, failed: 0, skipped: 0 };
|
|
77
|
+
const counts = { passed: 0, failed: 0, skipped: 0, unsupported: 0 };
|
|
52
78
|
for (const s of report.steps) counts[s.status] += 1;
|
|
79
|
+
const headline = { passed: '✅ PASSED', failed: '❌ FAILED', unsupported: '🚫 NOT ON THIS HOST' }[report.result];
|
|
53
80
|
const lines = [
|
|
54
|
-
`${
|
|
81
|
+
`${headline} ✅ ${counts.passed}${counts.failed ? ` ❌ ${counts.failed}` : ''}${counts.unsupported ? ` 🚫 ${counts.unsupported}` : ''}${counts.skipped ? ` ⏭️ ${counts.skipped}` : ''} — ${(report.ms / 1000).toFixed(1)}s`,
|
|
55
82
|
];
|
|
56
83
|
if (report.evidence?.screen) lines.push('— screen at the failure:', ...report.evidence.screen.split('\n').map((l) => ` ${l}`));
|
|
57
84
|
if (report.evidence?.requests?.length) lines.push('— requests:', ...report.evidence.requests.map((l) => ` ${l}`));
|
|
@@ -59,6 +86,98 @@ const describe = (report: CaseReport): string => {
|
|
|
59
86
|
return lines.join('\n');
|
|
60
87
|
};
|
|
61
88
|
|
|
89
|
+
/** The share of the machine's CPU that sat idle over the next 300 ms. */
|
|
90
|
+
const idleShare = async (): Promise<number> => {
|
|
91
|
+
const total = () =>
|
|
92
|
+
os.cpus().reduce(
|
|
93
|
+
(sum, cpu) => {
|
|
94
|
+
const t = cpu.times;
|
|
95
|
+
return { idle: sum.idle + t.idle, all: sum.all + t.idle + t.user + t.sys + t.nice + t.irq };
|
|
96
|
+
},
|
|
97
|
+
{ idle: 0, all: 0 },
|
|
98
|
+
);
|
|
99
|
+
const before = total();
|
|
100
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
101
|
+
const after = total();
|
|
102
|
+
return after.all > before.all ? (after.idle - before.idle) / (after.all - before.all) : 1;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** The case files named, or every case under the cases directory; a sentence when there are none. */
|
|
106
|
+
const caseFiles = (args: string[], home: string, casesDir: string | undefined): string[] | string => {
|
|
107
|
+
const dir = path.resolve(home, casesDir ?? 'cases');
|
|
108
|
+
const files = args.length
|
|
109
|
+
? args.map((f) => path.resolve(f))
|
|
110
|
+
: fs.existsSync(dir)
|
|
111
|
+
? fs
|
|
112
|
+
.readdirSync(dir)
|
|
113
|
+
.filter((f) => f.endsWith('.md') && !/^(README|FORMAT|CATALOG)\.md$/i.test(f) && !f.startsWith('.'))
|
|
114
|
+
.sort()
|
|
115
|
+
.map((f) => path.join(dir, f))
|
|
116
|
+
: [];
|
|
117
|
+
return files.length > 0 ? files : `no cases under ${path.relative(home, dir) || '.'}; \`lynkeus case init\` writes one`;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
type PrepareOptions = { base: Base; config: CasesConfig; store: Store; open: () => Fixtures; limit: number; idle: number; jobs: number };
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Runs the setups of `cases` ahead of them, in order, `jobs` at a time: never more than `limit` waiting
|
|
124
|
+
* to be taken, and only while the machine has `idle` of its CPU to spare. A case that started first is skipped.
|
|
125
|
+
*/
|
|
126
|
+
const prepareAhead = async (cases: Case[], o: PrepareOptions): Promise<{ made: number; skipped: number }> => {
|
|
127
|
+
let next = 0;
|
|
128
|
+
let made = 0;
|
|
129
|
+
let skipped = 0;
|
|
130
|
+
// Far enough ahead, or the machine busy: a setup made then only takes the CPU from the cases
|
|
131
|
+
// running now, and the suite gains nothing from having it early.
|
|
132
|
+
const room = async (): Promise<boolean> => {
|
|
133
|
+
if (o.store.waiting() < o.limit) return (await idleShare()) >= o.idle;
|
|
134
|
+
// A timer, not a bare check: the jobs that take the waiting setups may run in this same process,
|
|
135
|
+
// and a loop that never yields to the event loop would keep them from ever taking one.
|
|
136
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
137
|
+
return false;
|
|
138
|
+
};
|
|
139
|
+
const worker = async () => {
|
|
140
|
+
const fixtures = o.open();
|
|
141
|
+
await fixtures.ahead();
|
|
142
|
+
try {
|
|
143
|
+
for (let c = cases[next++]; c; c = cases[next++]) {
|
|
144
|
+
while (!o.store.started(c) && !(await room()));
|
|
145
|
+
if (o.store.started(c)) {
|
|
146
|
+
skipped++;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const done = c;
|
|
150
|
+
await runCase(done, { base: o.base, config: o.config, fixtures, setupOnly: { keep: (p) => o.store.keep(done, p) } });
|
|
151
|
+
made++;
|
|
152
|
+
}
|
|
153
|
+
} finally {
|
|
154
|
+
fixtures.close();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
await Promise.all(Array.from({ length: Math.max(1, o.jobs) }, worker));
|
|
158
|
+
return { made, skipped };
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/** A host for one case, started by the project's own command: `{port}` is where it dials the driver. */
|
|
162
|
+
const spawnHost = (command: string, port: number, job: number, cwd: string): ChildProcess =>
|
|
163
|
+
spawn('/bin/sh', ['-c', command.replaceAll('{port}', String(port)).replaceAll('{job}', String(job))], {
|
|
164
|
+
cwd,
|
|
165
|
+
env: process.env,
|
|
166
|
+
// stdin stays open for the host's life: a host that serves until its stdin closes stops with the case.
|
|
167
|
+
stdio: ['pipe', 'ignore', 'ignore'],
|
|
168
|
+
detached: true,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
/** A run that could not be uploaded still ran: the failure is said, not raised. */
|
|
172
|
+
const pushed = async (dir: string, to: Exclude<ReturnType<typeof service>, string>, project: string) => {
|
|
173
|
+
try {
|
|
174
|
+
const run = await pushRun(dir, { ...to, project });
|
|
175
|
+
return [`report: ${run.url}${run.refused.length ? ` (not kept on this plan: ${run.refused.join(', ')})` : ''}`, ...describeChanges(run.changes)].join('\n');
|
|
176
|
+
} catch (error) {
|
|
177
|
+
return `the report was not uploaded: ${(error as Error).message}`;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
62
181
|
export const caseCommands = [
|
|
63
182
|
define({
|
|
64
183
|
name: 'case run',
|
|
@@ -70,8 +189,33 @@ export const caseCommands = [
|
|
|
70
189
|
flags: {
|
|
71
190
|
host: { type: 'boolean', help: 'start `headless start` for the run and stop it after' },
|
|
72
191
|
once: { type: 'boolean', help: 'no second chance for a case that fails' },
|
|
192
|
+
continue: { type: 'boolean', help: "keep running a case's steps after one fails (a failed setup still stops it)" },
|
|
193
|
+
seen: { type: 'string', help: 'write <dir>/<case id>.json with the screens each passing case went through, for a coverage map', value: 'dir' },
|
|
73
194
|
report: { type: 'string', help: 'append one JSON line per case', value: 'file' },
|
|
74
195
|
events: { type: 'string', help: 'keep what the app told its analytics, per case, as <dir>/<case id>/events.jsonl', value: 'dir' },
|
|
196
|
+
out: { type: 'string', help: 'write the run as a directory a report can read: run.json and cases.jsonl, a line per attempt', value: 'dir' },
|
|
197
|
+
screenshots: { type: 'boolean', help: 'with --out: a frame of the screen after every step of the app' },
|
|
198
|
+
video: { type: 'boolean', help: 'with --out: film each case, where the host films (the step says at what second it began)' },
|
|
199
|
+
traces: {
|
|
200
|
+
type: 'boolean',
|
|
201
|
+
help: 'listen for the backend’s OpenTelemetry traces (OTLP over HTTP) and keep, under each step, what the backend did for it; point the backend’s OTEL_EXPORTER_OTLP_ENDPOINT at http://localhost:<traces-port>',
|
|
202
|
+
},
|
|
203
|
+
'traces-port': { type: 'number', help: 'where --traces listens', default: 4318, value: 'port' },
|
|
204
|
+
push: { type: 'boolean', help: 'with --out: upload the run to the reports service when it ends and print the report’s address' },
|
|
205
|
+
project: { type: 'string', help: 'with --push: the project the run is filed under (default: the app’s folder name)', value: 'name' },
|
|
206
|
+
'video-fps': { type: 'number', help: 'frames per second of the film', default: 30, value: 'n' },
|
|
207
|
+
flakes: { type: 'string', help: 'the ledger of how each case did across runs (default .lynkeus/flakes.json)', value: 'file' },
|
|
208
|
+
prepared: { type: 'string', help: 'where `case prepare` leaves setups made ahead; a case found there skips its setup', value: 'dir' },
|
|
209
|
+
jobs: { type: 'number', help: 'cases at once, each on its own host (needs --ports)', value: 'n', default: 1 },
|
|
210
|
+
ports: { type: 'string', help: 'the driver port of each job, comma-separated: where its host dials in', value: 'list' },
|
|
211
|
+
'host-command': {
|
|
212
|
+
type: 'string',
|
|
213
|
+
help: 'starts a fresh host for every case and stops it after; {port} is where the host dials, {job} the job',
|
|
214
|
+
value: 'command',
|
|
215
|
+
},
|
|
216
|
+
'in-order': { type: 'boolean', help: 'with --jobs: take the cases in the order given, not the longest first' },
|
|
217
|
+
ahead: { type: 'number', help: 'make up to this many setups ahead of their cases while others run (0: none)', value: 'n', default: 0 },
|
|
218
|
+
idle: { type: 'number', help: 'with --ahead: start a setup only while this share of the CPU is idle', value: 'share', default: 0.25 },
|
|
75
219
|
'dry-run': { type: 'boolean', help: 'parse and list the steps without running them' },
|
|
76
220
|
},
|
|
77
221
|
needs: 'nothing',
|
|
@@ -80,23 +224,56 @@ export const caseCommands = [
|
|
|
80
224
|
run: async (ctx) => {
|
|
81
225
|
const config = ctx.config.cases ?? {};
|
|
82
226
|
const home = config.base ?? ctx.root;
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
? ctx.args.map((f) => path.resolve(f))
|
|
86
|
-
: fs.existsSync(dir)
|
|
87
|
-
? fs
|
|
88
|
-
.readdirSync(dir)
|
|
89
|
-
.filter((f) => f.endsWith('.md') && !/^(README|FORMAT|CATALOG)\.md$/i.test(f) && !f.startsWith('.'))
|
|
90
|
-
.sort()
|
|
91
|
-
.map((f) => path.join(dir, f))
|
|
92
|
-
: [];
|
|
93
|
-
if (files.length === 0) return { text: `no cases under ${path.relative(ctx.root, dir) || '.'}; \`lynkeus case init\` writes one`, code: 1 };
|
|
227
|
+
const files = caseFiles(ctx.args, home, config.dir);
|
|
228
|
+
if (typeof files === 'string') return { text: files, code: 1 };
|
|
94
229
|
const cases = files.flatMap(readCases);
|
|
95
230
|
const dry = !!ctx.flags['dry-run'];
|
|
96
|
-
const
|
|
231
|
+
const seenDir = typeof ctx.flags.seen === 'string' && !dry ? path.resolve(ctx.flags.seen) : undefined;
|
|
232
|
+
const out = typeof ctx.flags.out === 'string' && !dry ? new RunFile(path.resolve(ctx.flags.out), ctx.root) : undefined;
|
|
233
|
+
if ((ctx.flags.screenshots || ctx.flags.video) && !out)
|
|
234
|
+
return { text: '--screenshots and --video keep what they take in the run directory: add --out <dir>', code: 2 };
|
|
235
|
+
// Checked before the run, so a missing key does not surface only after every case has run.
|
|
236
|
+
const reportsTo = ctx.flags.push && out ? service() : undefined;
|
|
237
|
+
if (ctx.flags.push && !out) return { text: '--push uploads the run directory: add --out <dir>', code: 2 };
|
|
238
|
+
if (typeof reportsTo === 'string') return { text: reportsTo, code: 2 };
|
|
239
|
+
const evidenceOf = (id: string, attempt: number) =>
|
|
240
|
+
out && (ctx.flags.screenshots || ctx.flags.video)
|
|
241
|
+
? {
|
|
242
|
+
dir: out.evidenceDir(id, attempt),
|
|
243
|
+
screenshots: !!ctx.flags.screenshots,
|
|
244
|
+
...(ctx.flags.video ? { video: { fps: Number(ctx.flags['video-fps'] ?? 30) } } : {}),
|
|
245
|
+
}
|
|
246
|
+
: undefined;
|
|
247
|
+
const ledger = dry ? undefined : new Flakes(path.resolve(ctx.root, typeof ctx.flags.flakes === 'string' ? ctx.flags.flakes : '.lynkeus/flakes.json'));
|
|
248
|
+
// A run file files each event under its step, so it needs them collected.
|
|
249
|
+
const events = typeof ctx.flags.events === 'string' || out !== undefined;
|
|
250
|
+
const claimed = dry
|
|
251
|
+
? undefined
|
|
252
|
+
: claimPorts(
|
|
253
|
+
typeof ctx.flags.ports === 'string'
|
|
254
|
+
? ctx.flags.ports
|
|
255
|
+
.split(',')
|
|
256
|
+
.map(Number)
|
|
257
|
+
.filter(Number.isInteger)
|
|
258
|
+
.slice(0, Math.max(1, Number(ctx.flags.jobs ?? 1)))
|
|
259
|
+
: [portFromEnv(ctx.config) ?? 8123],
|
|
260
|
+
);
|
|
261
|
+
if (claimed && 'refused' in claimed) return { text: claimed.refused, code: 1 };
|
|
97
262
|
const host = ctx.flags.host && !dry ? await startHost(ctx.root, ctx.err) : undefined;
|
|
98
263
|
const fixtures = config.fixtures && !dry ? new Fixtures(config.fixtures, home) : undefined;
|
|
264
|
+
const traces = ctx.flags.traces && !dry ? new TraceSink(Number(ctx.flags['traces-port'] ?? 4318)) : undefined;
|
|
265
|
+
if (traces) {
|
|
266
|
+
try {
|
|
267
|
+
await traces.start();
|
|
268
|
+
} catch (error) {
|
|
269
|
+
fixtures?.close();
|
|
270
|
+
return { text: `--traces could not listen on port ${traces.port}: ${(error as Error).message}`, code: 2 };
|
|
271
|
+
}
|
|
272
|
+
ctx.err(`backend traces: listening on http://localhost:${traces.port} (the backend's OTEL_EXPORTER_OTLP_ENDPOINT)`);
|
|
273
|
+
}
|
|
99
274
|
const stop = () => {
|
|
275
|
+
traces?.close();
|
|
276
|
+
claimed?.release();
|
|
100
277
|
fixtures?.close();
|
|
101
278
|
if (host?.pid) stopGroup(host.pid);
|
|
102
279
|
};
|
|
@@ -108,32 +285,193 @@ export const caseCommands = [
|
|
|
108
285
|
process.once('SIGTERM', interrupted);
|
|
109
286
|
const reports: (CaseReport & { retried?: boolean })[] = [];
|
|
110
287
|
try {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
report = { ...(await runCase(c, { base: ctx, config, fixtures, events, log: ctx.err })), retried: true };
|
|
118
|
-
ctx.err(describe(report));
|
|
119
|
-
}
|
|
120
|
-
if (events && report.events) {
|
|
121
|
-
const out = path.resolve(ctx.flags.events as string, c.id);
|
|
122
|
-
fs.mkdirSync(out, { recursive: true });
|
|
123
|
-
fs.writeFileSync(eventsFile(out), report.events.map((e) => `${JSON.stringify(e)}\n`).join(''));
|
|
124
|
-
}
|
|
125
|
-
reports.push(report);
|
|
126
|
-
if (ctx.flags.report) fs.appendFileSync(path.resolve(ctx.flags.report as string), `${JSON.stringify(report)}\n`);
|
|
288
|
+
// A case that names a fixture the server does not have fails halfway, after it has changed the backend. Better not to start.
|
|
289
|
+
const described = await fixtures?.describe();
|
|
290
|
+
if (described?.down) return { text: `the fixtures server cannot serve: ${described.down}`, code: 1 };
|
|
291
|
+
if (described) {
|
|
292
|
+
const missing = cases.flatMap((c) => missingFixtures(c, config, described.commands).map((name) => `${c.id}: no fixture ${name}`));
|
|
293
|
+
if (missing.length > 0) return { text: [...missing, `the fixtures command answers: ${described.commands.join(', ')}`].join('\n'), code: 1 };
|
|
127
294
|
}
|
|
295
|
+
const jobs = Math.max(1, Number(ctx.flags.jobs ?? 1));
|
|
296
|
+
const ports = typeof ctx.flags.ports === 'string' ? ctx.flags.ports.split(',').map(Number) : [];
|
|
297
|
+
const hostCommand = typeof ctx.flags['host-command'] === 'string' && !dry ? ctx.flags['host-command'] : undefined;
|
|
298
|
+
if ((jobs > 1 || hostCommand) && (ports.length < jobs || ports.some((p) => !Number.isInteger(p)) || !ctx.forPort))
|
|
299
|
+
return { text: `--jobs and --host-command need a driver port per job: --ports with ${jobs}`, code: 2 };
|
|
300
|
+
// Several jobs finish together only if the longest cases start first: one left for the end runs alone
|
|
301
|
+
// while the other jobs wait. A case the ledger has not timed goes first too, as it may be long.
|
|
302
|
+
if (jobs > 1 && ledger && !ctx.flags['in-order']) {
|
|
303
|
+
const took = (id: string) => ledger.lastMs(id) ?? Number.POSITIVE_INFINITY;
|
|
304
|
+
cases.sort((a, b) => took(b.id) - took(a.id));
|
|
305
|
+
}
|
|
306
|
+
const limit = Number(ctx.flags.ahead ?? 0);
|
|
307
|
+
const store: Store | undefined =
|
|
308
|
+
typeof ctx.flags.prepared === 'string' && !dry ? new Ahead(path.resolve(ctx.flags.prepared)) : limit > 0 && fixtures ? new InMemory() : undefined;
|
|
309
|
+
const declared = config.fixtures;
|
|
310
|
+
// The setups of the cases to come, made while these run, in the order the jobs will take them.
|
|
311
|
+
const preparing =
|
|
312
|
+
limit > 0 && declared && store && !dry
|
|
313
|
+
? prepareAhead(
|
|
314
|
+
cases.filter((c) => preparable(c, config)),
|
|
315
|
+
{
|
|
316
|
+
base: ctx,
|
|
317
|
+
config,
|
|
318
|
+
store,
|
|
319
|
+
open: () => new Fixtures(declared, home),
|
|
320
|
+
limit,
|
|
321
|
+
idle: Number(ctx.flags.idle ?? 0.25),
|
|
322
|
+
jobs: 1,
|
|
323
|
+
},
|
|
324
|
+
)
|
|
325
|
+
: undefined;
|
|
326
|
+
let next = 0;
|
|
327
|
+
const job = async (index: number) => {
|
|
328
|
+
// Each job keeps its own connection to the fixtures server, warm from one case to the next.
|
|
329
|
+
const own = index === 0 ? fixtures : declared && !dry ? new Fixtures(declared, home) : undefined;
|
|
330
|
+
const port = ports[index];
|
|
331
|
+
try {
|
|
332
|
+
for (let c = cases[next++]; c; c = cases[next++]) {
|
|
333
|
+
const lines: string[] = [];
|
|
334
|
+
// With several jobs a case's lines are held and printed together, not interleaved.
|
|
335
|
+
const log = jobs > 1 ? (line: string) => lines.push(line) : ctx.err;
|
|
336
|
+
log(`▶ ${c.id}${c.title ? ` — ${c.title}` : ''}`);
|
|
337
|
+
store?.start(c);
|
|
338
|
+
const attempt = async (n: number, prepared?: Prepared) => {
|
|
339
|
+
const host = hostCommand && port !== undefined ? spawnHost(hostCommand, port, index, ctx.root) : undefined;
|
|
340
|
+
const scoped = port !== undefined && ctx.forPort ? ctx.forPort(port) : { base: ctx as Base, stop: async () => undefined };
|
|
341
|
+
const startedAt = new Date();
|
|
342
|
+
try {
|
|
343
|
+
// A host just started is still drawing its first screens; with the setup made ahead nothing
|
|
344
|
+
// else gives it that moment before the first press.
|
|
345
|
+
if (host)
|
|
346
|
+
await scoped.base
|
|
347
|
+
.device()
|
|
348
|
+
.then((d) => d.idle({ quietMs: 300, timeoutMs: 5000 }))
|
|
349
|
+
.catch(() => undefined);
|
|
350
|
+
const report = await runCase(c, {
|
|
351
|
+
base: scoped.base,
|
|
352
|
+
config,
|
|
353
|
+
fixtures: own,
|
|
354
|
+
dry,
|
|
355
|
+
events,
|
|
356
|
+
evidence: evidenceOf(c.id, n),
|
|
357
|
+
log,
|
|
358
|
+
prepared,
|
|
359
|
+
continue: !!ctx.flags.continue,
|
|
360
|
+
routes: seenDir ? (host ? 'fresh' : true) : false,
|
|
361
|
+
traces,
|
|
362
|
+
});
|
|
363
|
+
if (seenDir && report.result === 'passed' && report.routes?.length) {
|
|
364
|
+
fs.mkdirSync(seenDir, { recursive: true });
|
|
365
|
+
fs.writeFileSync(path.join(seenDir, `${c.id}.json`), `${JSON.stringify({ id: c.id, routes: report.routes }, null, 2)}\n`);
|
|
366
|
+
}
|
|
367
|
+
return { report, startedAt, hello: (await scoped.base.device().catch(() => undefined))?.server.hello ?? undefined };
|
|
368
|
+
} finally {
|
|
369
|
+
if (host) await stopHost(host);
|
|
370
|
+
await scoped.stop();
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
let {
|
|
374
|
+
report,
|
|
375
|
+
startedAt,
|
|
376
|
+
hello,
|
|
377
|
+
}: { report: CaseReport & { retried?: boolean }; startedAt: Date; hello?: { platform?: string; native?: boolean } } = await attempt(
|
|
378
|
+
1,
|
|
379
|
+
store?.take(c),
|
|
380
|
+
);
|
|
381
|
+
seen ??= hello;
|
|
382
|
+
log(describe(report));
|
|
383
|
+
out?.add(c, { report, attempt: 1, startedAt });
|
|
384
|
+
if (report.result === 'failed' && !ctx.flags.once && !dry) {
|
|
385
|
+
log(` retrying ${c.id} once`);
|
|
386
|
+
const again = await attempt(2);
|
|
387
|
+
report = { ...again.report, retried: true };
|
|
388
|
+
startedAt = again.startedAt;
|
|
389
|
+
log(describe(report));
|
|
390
|
+
out?.add(c, { report, attempt: 2, startedAt });
|
|
391
|
+
}
|
|
392
|
+
if (jobs > 1) ctx.err(lines.join('\n'));
|
|
393
|
+
ledger?.note(report);
|
|
394
|
+
if (typeof ctx.flags.events === 'string' && report.events) {
|
|
395
|
+
const dir = path.resolve(ctx.flags.events as string, c.id);
|
|
396
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
397
|
+
fs.writeFileSync(eventsFile(dir), report.events.map((e) => `${JSON.stringify(e)}\n`).join(''));
|
|
398
|
+
}
|
|
399
|
+
reports.push(report);
|
|
400
|
+
if (ctx.flags.report) fs.appendFileSync(path.resolve(ctx.flags.report as string), `${JSON.stringify(report)}\n`);
|
|
401
|
+
}
|
|
402
|
+
} finally {
|
|
403
|
+
if (own !== fixtures) own?.close();
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
let seen: { platform?: string; native?: boolean } | undefined;
|
|
407
|
+
await Promise.all(Array.from({ length: jobs }, (_, i) => job(i)));
|
|
408
|
+
await preparing;
|
|
409
|
+
if (out) out.finish({ platform: seen?.platform, native: seen?.native });
|
|
128
410
|
} finally {
|
|
129
411
|
stop();
|
|
130
412
|
}
|
|
131
|
-
const
|
|
413
|
+
const count = (result: CaseReport['result']) => reports.filter((r) => r.result === result).length;
|
|
414
|
+
const unsupported = count('unsupported');
|
|
132
415
|
const summary = [
|
|
133
|
-
...reports.map(
|
|
134
|
-
|
|
416
|
+
...reports.map(
|
|
417
|
+
(r) => `${{ passed: '✅', failed: '❌', unsupported: '🚫' }[r.result]} ${r.id}${r.retried && r.result === 'passed' ? ' ⚠ passed on retry' : ''}`,
|
|
418
|
+
),
|
|
419
|
+
`${count('passed')}/${reports.length} passed${unsupported ? `, ${unsupported} cannot run on this host` : ''}`,
|
|
420
|
+
...(ledger ? ledger.flaky(reports.map((r) => r.id)) : []),
|
|
421
|
+
...(reportsTo && out
|
|
422
|
+
? [
|
|
423
|
+
await pushed(
|
|
424
|
+
path.resolve(ctx.flags.out as string),
|
|
425
|
+
reportsTo,
|
|
426
|
+
typeof ctx.flags.project === 'string' ? ctx.flags.project : path.basename(ctx.root),
|
|
427
|
+
),
|
|
428
|
+
]
|
|
429
|
+
: []),
|
|
135
430
|
].join('\n');
|
|
136
|
-
|
|
431
|
+
ledger?.save();
|
|
432
|
+
// A case this host cannot run is not a failure of the app; only a failed case fails the run.
|
|
433
|
+
return { text: summary, json: reports, code: count('failed') === 0 ? 0 : 1 };
|
|
434
|
+
},
|
|
435
|
+
}),
|
|
436
|
+
define({
|
|
437
|
+
name: 'case prepare',
|
|
438
|
+
group: 'runs',
|
|
439
|
+
summary: 'Run the setup of cases ahead of them, so each starts at its first step',
|
|
440
|
+
details:
|
|
441
|
+
'For a suite that starts `case run --prepared <dir>` once per case: start this first, with the same cases in the order they will run, and leave it running. It runs every setup made only of the project fixtures and leaves what each produced in <dir>; a case that starts before its setup is ready runs its own, and this skips it. It asks the fixtures server for a lower priority (`lynkeus.ahead`), so it takes what the running cases leave of the machine.',
|
|
442
|
+
positionals: [{ name: 'files', help: 'case files, in the order they will run (default: every .md under cases.dir)', rest: true }],
|
|
443
|
+
flags: {
|
|
444
|
+
prepared: { type: 'string', help: 'where to leave the setups (emptied first)', value: 'dir', default: '.lynkeus/prepared' },
|
|
445
|
+
jobs: { type: 'number', help: 'setups made at once', value: 'n', default: 1 },
|
|
446
|
+
ahead: { type: 'number', help: 'setups kept ready and not yet taken, at most', value: 'n', default: 4 },
|
|
447
|
+
idle: { type: 'number', help: 'start a setup only while at least this share of the CPU is idle (0 to 1)', value: 'share', default: 0.25 },
|
|
448
|
+
},
|
|
449
|
+
needs: 'nothing',
|
|
450
|
+
session: false,
|
|
451
|
+
mcp: false,
|
|
452
|
+
run: async (ctx) => {
|
|
453
|
+
const config = ctx.config.cases ?? {};
|
|
454
|
+
if (!config.fixtures) return { text: 'the project declares no fixtures (cases.fixtures in lynkeus.config.json): nothing to prepare', code: 1 };
|
|
455
|
+
const declared = config.fixtures;
|
|
456
|
+
const home = config.base ?? ctx.root;
|
|
457
|
+
const files = caseFiles(ctx.args, home, config.dir);
|
|
458
|
+
if (typeof files === 'string') return { text: files, code: 1 };
|
|
459
|
+
const cases = files.flatMap(readCases).filter((c) => preparable(c, config));
|
|
460
|
+
const probe = new Fixtures(declared, home);
|
|
461
|
+
const described = await probe.describe().finally(() => probe.close());
|
|
462
|
+
if (described?.down) return { text: `the fixtures server cannot serve: ${described.down}`, code: 1 };
|
|
463
|
+
const store = new Ahead(path.resolve(ctx.root, String(ctx.flags.prepared ?? '.lynkeus/prepared')));
|
|
464
|
+
store.clear();
|
|
465
|
+
const { made, skipped } = await prepareAhead(cases, {
|
|
466
|
+
base: ctx,
|
|
467
|
+
config,
|
|
468
|
+
store,
|
|
469
|
+
open: () => new Fixtures(declared, home),
|
|
470
|
+
limit: Math.max(1, Number(ctx.flags.ahead ?? 4)),
|
|
471
|
+
idle: Number(ctx.flags.idle ?? 0.25),
|
|
472
|
+
jobs: Number(ctx.flags.jobs ?? 1),
|
|
473
|
+
});
|
|
474
|
+
return { text: `${made} setups made ahead, ${skipped} cases had started first`, json: { made, skipped } };
|
|
137
475
|
},
|
|
138
476
|
}),
|
|
139
477
|
define({
|
package/src/commands/check.ts
CHANGED
|
@@ -55,15 +55,22 @@ export const diffGraphs = (base: ScreenGraph, head: ScreenGraph): GraphDiff => {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
/** Lint findings per route, as `lynkeus lint --save` writes them. */
|
|
58
|
-
export type LintBaseline = Record<string, { rule: string; testId?: string; message: string }[]>;
|
|
58
|
+
export type LintBaseline = Record<string, { rule: string; testId?: string; subject?: string; message: string }[]>;
|
|
59
59
|
|
|
60
60
|
type LintedFinding = { finding: Finding; testId?: string };
|
|
61
61
|
|
|
62
|
-
const key = (rule: string, testId: string | undefined,
|
|
62
|
+
const key = (rule: string, testId: string | undefined, what: string) => `${rule}|${testId ?? ''}|${what}`;
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* A finding is known by its rule and what it is about, not by what was measured: a target that went from
|
|
66
|
+
* 32 to 30 points is the finding the baseline already has. A baseline saved before findings named their
|
|
67
|
+
* subject has only the message to go by.
|
|
68
|
+
*/
|
|
64
69
|
export const newFindings = (baseline: LintBaseline, route: string, findings: LintedFinding[]): LintedFinding[] => {
|
|
65
|
-
const seen = new Set((baseline[route] ?? []).map((b) => key(b.rule, b.testId, b.message)));
|
|
66
|
-
return findings.filter(
|
|
70
|
+
const seen = new Set((baseline[route] ?? []).map((b) => key(b.rule, b.testId, b.subject ?? b.message)));
|
|
71
|
+
return findings.filter(
|
|
72
|
+
(f) => !seen.has(key(f.finding.rule, f.testId, f.finding.subject ?? f.finding.message)) && !seen.has(key(f.finding.rule, f.testId, f.finding.message)),
|
|
73
|
+
);
|
|
67
74
|
};
|
|
68
75
|
|
|
69
76
|
export const describeGraphDiff = (d: GraphDiff): string => {
|
package/src/commands/drive.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
|
|
5
|
+
import { PNG } from 'pngjs';
|
|
6
|
+
|
|
4
7
|
import { lynkeusDir } from '../config.js';
|
|
5
8
|
import { describeScreen, describeTrace } from '../device/driver.js';
|
|
6
9
|
import { readJson, writeJson } from '../files.js';
|
|
10
|
+
import { lintContrast } from '../knowledge/contrast.js';
|
|
7
11
|
import { describeFindings, lintScreen } from '../knowledge/lint.js';
|
|
8
12
|
import { describePerf, summarize, visitsFrom } from '../knowledge/perf.js';
|
|
9
13
|
import * as screens from '../knowledge/screens.js';
|
|
10
14
|
import { screenTree } from '../knowledge/tree.js';
|
|
11
15
|
import { define } from '../registry.js';
|
|
12
16
|
import { whyFor } from '../runtime.js';
|
|
13
|
-
import { expectedOf, isRoute, parseTarget, scopedTarget, TARGET_HELP } from '../targets.js';
|
|
17
|
+
import { expectedOf, isRoute, parseTarget, routeOf, scopedTarget, TARGET_HELP } from '../targets.js';
|
|
14
18
|
import { type LintBaseline, newFindings } from './check.js';
|
|
15
19
|
|
|
16
20
|
const SCOPE_FLAGS = {
|
|
@@ -165,7 +169,7 @@ export const driveCommands = [
|
|
|
165
169
|
mcpOmit: ['nth'],
|
|
166
170
|
group: 'drive',
|
|
167
171
|
summary: 'Until a route or element appears (or leaves), or a number of ms',
|
|
168
|
-
positionals: [{ name: 'what', help: `Route | ${TARGET_HELP} | 800 (ms)`, required: true }],
|
|
172
|
+
positionals: [{ name: 'what', help: `Route | route:index | ${TARGET_HELP} | 800 (ms)`, required: true }],
|
|
169
173
|
flags: {
|
|
170
174
|
...SCOPE_FLAGS,
|
|
171
175
|
gone: { type: 'boolean', help: 'until it leaves the screen' },
|
|
@@ -181,7 +185,7 @@ export const driveCommands = [
|
|
|
181
185
|
}
|
|
182
186
|
return {
|
|
183
187
|
json: await (await ctx.device()).waitFor({
|
|
184
|
-
...(isRoute(raw) ? { route: raw } : { target: scopedTarget(raw, ctx.flags) }),
|
|
188
|
+
...(isRoute(raw) ? { route: routeOf(raw) } : { target: scopedTarget(raw, ctx.flags) }),
|
|
185
189
|
gone: ctx.flags.gone ? true : undefined,
|
|
186
190
|
scroll: ctx.flags.scroll ? true : undefined,
|
|
187
191
|
timeoutMs: ctx.flags.timeout as number,
|
|
@@ -206,7 +210,7 @@ export const driveCommands = [
|
|
|
206
210
|
name: 'see',
|
|
207
211
|
group: 'drive',
|
|
208
212
|
summary: 'Assert a route or element is on screen now (exit 1 if not)',
|
|
209
|
-
positionals: [{ name: 'what', help: `Route | ${TARGET_HELP}`, required: true }],
|
|
213
|
+
positionals: [{ name: 'what', help: `Route | route:index | ${TARGET_HELP}`, required: true }],
|
|
210
214
|
flags: {
|
|
211
215
|
absent: { type: 'boolean', help: 'assert it is not there' },
|
|
212
216
|
within: { type: 'number', help: 'allow it this long to appear', default: 0, value: 'ms' },
|
|
@@ -217,7 +221,7 @@ export const driveCommands = [
|
|
|
217
221
|
const device = await ctx.device();
|
|
218
222
|
try {
|
|
219
223
|
const result = await device.waitFor({
|
|
220
|
-
...(isRoute(raw) ? { route: raw } : { target: parseTarget(raw) }),
|
|
224
|
+
...(isRoute(raw) ? { route: routeOf(raw) } : { target: parseTarget(raw) }),
|
|
221
225
|
gone: ctx.flags.absent ? true : undefined,
|
|
222
226
|
timeoutMs: Math.max(1, ctx.flags.within as number),
|
|
223
227
|
});
|
|
@@ -341,9 +345,10 @@ export const driveCommands = [
|
|
|
341
345
|
define({
|
|
342
346
|
name: 'lint',
|
|
343
347
|
group: 'drive',
|
|
344
|
-
summary: 'Unlabeled controls, small targets, untranslated keys, covered or clipped elements',
|
|
348
|
+
summary: 'Unlabeled controls, small targets, low-contrast text, untranslated keys, covered or clipped elements',
|
|
345
349
|
flags: {
|
|
346
350
|
strict: { type: 'boolean', help: 'exit 1 on any warning' },
|
|
351
|
+
'no-contrast': { type: 'boolean', help: 'skip the contrast of text against its background (it takes a screenshot)' },
|
|
347
352
|
save: { type: 'string', help: "keep this screen's findings in a baseline file", value: 'file' },
|
|
348
353
|
baseline: { type: 'string', help: 'print only what is new against a baseline file', value: 'file' },
|
|
349
354
|
},
|
|
@@ -353,20 +358,38 @@ export const driveCommands = [
|
|
|
353
358
|
const { lint, lintBaseline } = ctx.config;
|
|
354
359
|
let findings = lintScreen(screen, { i18nKeyPatterns: lint?.i18nKeyPatterns?.map((p) => new RegExp(p, 'i')), minTouchTarget: lint?.minTouchTarget });
|
|
355
360
|
const route = screen.route ?? '?';
|
|
361
|
+
const notes: string[] = [];
|
|
362
|
+
if (lint?.contrast !== false && !ctx.flags['no-contrast']) {
|
|
363
|
+
// Contrast is read off the pixels, so it needs a host that can take a picture of the screen.
|
|
364
|
+
const file = path.join(os.tmpdir(), `lynkeus-lint-${process.pid}-${Date.now()}.png`);
|
|
365
|
+
try {
|
|
366
|
+
await (await ctx.device()).screenshot(file);
|
|
367
|
+
const picture = PNG.sync.read(fs.readFileSync(file));
|
|
368
|
+
const contrast = lint?.contrast;
|
|
369
|
+
findings = [
|
|
370
|
+
...findings,
|
|
371
|
+
...lintContrast(screen, picture, { normal: contrast?.normal, large: contrast?.large, ignore: contrast?.ignore?.map((p) => new RegExp(p)) }),
|
|
372
|
+
];
|
|
373
|
+
} catch {
|
|
374
|
+
notes.push('contrast not measured: this host takes no screenshots');
|
|
375
|
+
} finally {
|
|
376
|
+
fs.rmSync(file, { force: true });
|
|
377
|
+
}
|
|
378
|
+
}
|
|
356
379
|
const withIds = findings.map((finding) => ({ finding, testId: screen.elements[finding.element]?.testId }));
|
|
357
380
|
const lines: string[] = [];
|
|
358
381
|
const save = ctx.flags.save as string | undefined;
|
|
359
382
|
const baselineFile = (ctx.flags.baseline as string | undefined) ?? lintBaseline;
|
|
360
383
|
if (save) {
|
|
361
384
|
const baseline = fs.existsSync(save) ? readJson<LintBaseline>(save) : {};
|
|
362
|
-
baseline[route] = withIds.map((f) => ({ rule: f.finding.rule, testId: f.testId, message: f.finding.message }));
|
|
385
|
+
baseline[route] = withIds.map((f) => ({ rule: f.finding.rule, testId: f.testId, subject: f.finding.subject, message: f.finding.message }));
|
|
363
386
|
writeJson(save, baseline);
|
|
364
387
|
lines.push(`saved ${findings.length} finding(s) for ${route} → ${save}`);
|
|
365
388
|
} else if (baselineFile && fs.existsSync(baselineFile)) {
|
|
366
389
|
findings = newFindings(readJson<LintBaseline>(baselineFile), route, withIds).map((f) => f.finding);
|
|
367
390
|
lines.push(findings.length ? `${findings.length} new against ${baselineFile}:` : `nothing new on ${route} against ${baselineFile}`);
|
|
368
391
|
}
|
|
369
|
-
lines.push(describeFindings(findings, screen.route));
|
|
392
|
+
lines.push(describeFindings(findings, screen.route), ...notes);
|
|
370
393
|
return { text: lines.join('\n'), json: findings, code: ctx.flags.strict && findings.some((f) => f.severity === 'warn') ? 1 : 0 };
|
|
371
394
|
},
|
|
372
395
|
}),
|
package/src/commands/headless.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type LynkeusConfig, lynkeusDir, portFromEnv } from '../config.js';
|
|
|
6
6
|
import { describeExplanations, explainError } from '../knowledge/errors.js';
|
|
7
7
|
import { type Ctx, define } from '../registry.js';
|
|
8
8
|
import { doctor } from './doctor.js';
|
|
9
|
-
import { init } from './init.js';
|
|
9
|
+
import { init, mountAgent } from './init.js';
|
|
10
10
|
|
|
11
11
|
const ENTRY_FLAG = { entry: { type: 'string' as const, help: 'the headless entry (or `entry` in lynkeus.config.json)', value: 'file' } };
|
|
12
12
|
const entryOf = (ctx: Ctx) => (ctx.flags.entry as string | undefined) ?? ctx.config.entry ?? 'qa/headless.tsx';
|
|
@@ -32,6 +32,16 @@ hostApp(() => <entry.App />, { ${options.join(', ')} });
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
export const headlessCommands = [
|
|
35
|
+
define({
|
|
36
|
+
name: 'init',
|
|
37
|
+
group: 'drive',
|
|
38
|
+
summary: "Mount the agent from the app's entry: React Native or Expo (Expo Router gets an entry of its own)",
|
|
39
|
+
needs: 'nothing',
|
|
40
|
+
run: async (ctx) => {
|
|
41
|
+
const lines = mountAgent(ctx.root);
|
|
42
|
+
return { text: lines.join('\n'), json: lines };
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
35
45
|
define({
|
|
36
46
|
name: 'headless start',
|
|
37
47
|
group: 'headless',
|
|
@@ -121,7 +131,7 @@ export const headlessCommands = [
|
|
|
121
131
|
if (ctx.flags.explain) {
|
|
122
132
|
const found = explainError(ctx.flags.explain as string);
|
|
123
133
|
return {
|
|
124
|
-
text: found.length ? describeExplanations(found).trim() : 'nothing in the
|
|
134
|
+
text: found.length ? describeExplanations(found).trim() : 'nothing in the catalog matches; paste the first line of the error, not the stack.',
|
|
125
135
|
json: found,
|
|
126
136
|
};
|
|
127
137
|
}
|