lynkeus 0.3.0 → 0.5.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/coverage.d.ts +31 -0
- package/lib/cases/coverage.js +82 -0
- package/lib/cases/draft.d.ts +21 -0
- package/lib/cases/draft.js +53 -0
- package/lib/cases/fixtures.d.ts +11 -0
- package/lib/cases/fixtures.js +59 -8
- package/lib/cases/frames.d.ts +6 -0
- package/lib/cases/frames.js +28 -0
- package/lib/cases/nativeLogs.d.ts +14 -0
- package/lib/cases/nativeLogs.js +111 -0
- package/lib/cases/runDirs.d.ts +13 -0
- package/lib/cases/runDirs.js +48 -0
- package/lib/cases/runfile.d.ts +5 -1
- package/lib/cases/runfile.js +67 -4
- package/lib/cases/runner.d.ts +58 -1
- package/lib/cases/runner.js +322 -39
- package/lib/cases/templates.d.ts +2 -2
- package/lib/cases/templates.js +20 -2
- package/lib/cases/traces.js +4 -1
- package/lib/cli.js +27 -4
- package/lib/commands/cases.d.ts +8 -0
- package/lib/commands/cases.js +154 -25
- package/lib/commands/ci.d.ts +13 -0
- package/lib/commands/ci.js +184 -0
- package/lib/commands/coverage.d.ts +1 -0
- package/lib/commands/coverage.js +151 -0
- package/lib/commands/device.js +32 -2
- package/lib/commands/doctor.js +8 -2
- package/lib/commands/drive.js +3 -1
- package/lib/commands/fixtures.d.ts +7 -0
- package/lib/commands/fixtures.js +94 -0
- package/lib/commands/headless.d.ts +11 -0
- package/lib/commands/headless.js +189 -9
- package/lib/commands/init.d.ts +23 -0
- package/lib/commands/init.js +231 -26
- package/lib/commands/map.d.ts +2 -0
- package/lib/commands/map.js +18 -14
- package/lib/commands/os.js +43 -10
- package/lib/commands/report.d.ts +4 -0
- package/lib/commands/report.js +156 -20
- package/lib/config.d.ts +41 -0
- package/lib/config.js +30 -0
- package/lib/device/agentVersion.d.ts +7 -0
- package/lib/device/agentVersion.js +14 -0
- package/lib/device/devices.js +6 -0
- package/lib/device/driver.js +2 -2
- package/lib/knowledge/analyticsTraffic.d.ts +10 -0
- package/lib/knowledge/analyticsTraffic.js +109 -0
- package/lib/knowledge/errors.js +6 -0
- package/lib/knowledge/events.d.ts +2 -0
- package/lib/knowledge/why.d.ts +2 -0
- package/lib/knowledge/why.js +1 -1
- package/lib/mcp/server.js +45 -4
- package/lib/runtime.d.ts +9 -1
- package/lib/runtime.js +25 -3
- package/package.json +7 -4
- package/src/cases/coverage.ts +99 -0
- package/src/cases/draft.ts +75 -0
- package/src/cases/fixtures.ts +57 -8
- package/src/cases/frames.ts +30 -0
- package/src/cases/nativeLogs.ts +112 -0
- package/src/cases/runDirs.ts +48 -0
- package/src/cases/runfile.ts +64 -4
- package/src/cases/runner.ts +372 -42
- package/src/cases/templates.ts +20 -2
- package/src/cases/traces.ts +3 -1
- package/src/cli.ts +27 -4
- package/src/commands/cases.ts +165 -23
- package/src/commands/ci.ts +189 -0
- package/src/commands/coverage.ts +147 -0
- package/src/commands/device.ts +27 -2
- package/src/commands/doctor.ts +9 -2
- package/src/commands/drive.ts +3 -1
- package/src/commands/fixtures.ts +102 -0
- package/src/commands/headless.ts +197 -9
- package/src/commands/init.ts +270 -26
- package/src/commands/map.ts +20 -15
- package/src/commands/os.ts +38 -10
- package/src/commands/report.ts +162 -18
- package/src/config.ts +48 -0
- package/src/device/agentVersion.ts +17 -0
- package/src/device/devices.ts +5 -0
- package/src/device/driver.ts +2 -2
- package/src/knowledge/analyticsTraffic.ts +142 -0
- package/src/knowledge/errors.ts +6 -0
- package/src/knowledge/events.ts +2 -1
- package/src/knowledge/why.ts +3 -1
- package/src/mcp/server.ts +45 -4
- package/src/runtime.ts +24 -3
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { coverageOf, impactOf, readSeen } from '../cases/coverage.js';
|
|
4
|
+
import { draftCase } from '../cases/draft.js';
|
|
5
|
+
import { Fixtures } from '../cases/fixtures.js';
|
|
6
|
+
import { readCases } from '../cases/format.js';
|
|
7
|
+
import { edgesFile } from '../config.js';
|
|
8
|
+
import * as edges from '../knowledge/edges.js';
|
|
9
|
+
import { plan } from '../knowledge/plan.js';
|
|
10
|
+
import { screensAffectedBy } from '../knowledge/query.js';
|
|
11
|
+
import { define } from '../registry.js';
|
|
12
|
+
import { caseFiles } from './cases.js';
|
|
13
|
+
import { changedSources } from './map.js';
|
|
14
|
+
// The project's cases and what they cover, read the way `case run` reads them.
|
|
15
|
+
const coverageFor = (ctx, seenFlag) => {
|
|
16
|
+
const config = ctx.config.cases ?? {};
|
|
17
|
+
const home = config.base ?? ctx.root;
|
|
18
|
+
const files = caseFiles([], home, config.dir);
|
|
19
|
+
if (typeof files === 'string')
|
|
20
|
+
return files;
|
|
21
|
+
const cases = files.flatMap(readCases);
|
|
22
|
+
const seenDir = path.resolve(ctx.root, typeof seenFlag === 'string' ? seenFlag : '.lynkeus/seen');
|
|
23
|
+
return { cases, coverage: coverageOf(cases, Object.keys(ctx.graph().screens).sort(), readSeen(seenDir)) };
|
|
24
|
+
};
|
|
25
|
+
export const coverageCommands = [
|
|
26
|
+
define({
|
|
27
|
+
name: 'case coverage',
|
|
28
|
+
group: 'runs',
|
|
29
|
+
summary: 'Which of the app’s screens the cases touch, which none does, and which a case names that the app no longer has',
|
|
30
|
+
details: 'A screen counts as touched when a case goes to it (`app.nav`), waits for it (`app.wait`), checks it (`app.see: { route }`), or went through it on its last passing run (`case run --seen <dir>`, read from .lynkeus/seen unless --seen says where). The screens come from the route graph (`lynkeus map build`).',
|
|
31
|
+
flags: {
|
|
32
|
+
route: { type: 'string', help: 'only this screen: the cases that touch it', value: 'Route' },
|
|
33
|
+
seen: { type: 'string', help: 'where `case run --seen` kept the screens of passing cases (default .lynkeus/seen)', value: 'dir' },
|
|
34
|
+
},
|
|
35
|
+
needs: 'graph',
|
|
36
|
+
session: false,
|
|
37
|
+
mcp: 'core',
|
|
38
|
+
run: async (ctx) => {
|
|
39
|
+
const read = coverageFor(ctx, ctx.flags.seen);
|
|
40
|
+
if (typeof read === 'string')
|
|
41
|
+
return { text: read, code: 1 };
|
|
42
|
+
const { cases, coverage } = read;
|
|
43
|
+
if (typeof ctx.flags.route === 'string') {
|
|
44
|
+
const ids = coverage.byRoute[ctx.flags.route] ?? [];
|
|
45
|
+
return { text: `${ctx.flags.route}: ${ids.length ? ids.join(', ') : 'no case'}`, json: { route: ctx.flags.route, cases: ids } };
|
|
46
|
+
}
|
|
47
|
+
const pct = coverage.routes ? Math.round((100 * coverage.covered.length) / coverage.routes) : 0;
|
|
48
|
+
const top = Object.entries(coverage.byRoute)
|
|
49
|
+
.filter(([r]) => !coverage.unknown.includes(r))
|
|
50
|
+
.sort((a, b) => b[1].length - a[1].length)
|
|
51
|
+
.slice(0, 8);
|
|
52
|
+
const lines = [
|
|
53
|
+
`${coverage.covered.length} of ${coverage.routes} screens touched by a case (${pct}%), from ${cases.length} case${cases.length === 1 ? '' : 's'}`,
|
|
54
|
+
...(top.length ? ['most covered:', ...top.map(([r, ids]) => ` ${r.padEnd(34)} ${ids.length}`)] : []),
|
|
55
|
+
...(coverage.unknown.length
|
|
56
|
+
? ['named by a case, unknown to the app (renamed? a typo?):', ...coverage.unknown.map((r) => ` ${r} ← ${coverage.byRoute[r].join(', ')}`)]
|
|
57
|
+
: []),
|
|
58
|
+
`${coverage.uncovered.length} screen${coverage.uncovered.length === 1 ? '' : 's'} no case touches${coverage.uncovered.length ? ':' : ''}`,
|
|
59
|
+
...coverage.uncovered.slice(0, 30).map((r) => ` ${r}`),
|
|
60
|
+
...(coverage.uncovered.length > 30 ? [` … ${coverage.uncovered.length - 30} more (--json)`] : []),
|
|
61
|
+
];
|
|
62
|
+
return { text: lines.join('\n'), json: coverage };
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
define({
|
|
66
|
+
name: 'case impact',
|
|
67
|
+
group: 'runs',
|
|
68
|
+
summary: 'The cases a branch’s changes reach, to run only those, and the reached screens no case covers',
|
|
69
|
+
details: 'The screens the diff against --base touches or imports (as `map check` finds them), crossed with what each case covers (as `case coverage` finds it). --files prints one case file per line: `lynkeus case run $(lynkeus case impact --files)`.',
|
|
70
|
+
flags: {
|
|
71
|
+
base: { type: 'string', help: 'git ref to diff against', default: 'main', value: 'ref' },
|
|
72
|
+
depth: { type: 'number', help: 'how many imports away a change still reaches a screen', default: 4, value: 'n' },
|
|
73
|
+
seen: { type: 'string', help: 'where `case run --seen` kept the screens of passing cases (default .lynkeus/seen)', value: 'dir' },
|
|
74
|
+
files: { type: 'boolean', help: 'print only the case files, one per line' },
|
|
75
|
+
},
|
|
76
|
+
needs: 'graph',
|
|
77
|
+
session: false,
|
|
78
|
+
mcp: 'core',
|
|
79
|
+
run: async (ctx) => {
|
|
80
|
+
const read = coverageFor(ctx, ctx.flags.seen);
|
|
81
|
+
if (typeof read === 'string')
|
|
82
|
+
return { text: read, code: 1 };
|
|
83
|
+
const base = ctx.flags.base;
|
|
84
|
+
const changed = changedSources(ctx.root, base, ctx.err);
|
|
85
|
+
const affected = screensAffectedBy(ctx.graph(), changed, ctx.flags.depth);
|
|
86
|
+
const impact = impactOf(affected, read.coverage);
|
|
87
|
+
if (ctx.flags.files)
|
|
88
|
+
return { text: [...new Set(impact.cases.map((c) => c.file))].join('\n'), json: impact };
|
|
89
|
+
const lines = [
|
|
90
|
+
`${changed.length} source file${changed.length === 1 ? '' : 's'} changed against ${base}; they reach ${new Set(affected.map((a) => a.route)).size} screen(s)`,
|
|
91
|
+
...(impact.cases.length
|
|
92
|
+
? [`cases to run (${impact.cases.length}):`, ...impact.cases.map((c) => ` ${c.id.padEnd(46)} ${c.routes.join(', ')} (via ${c.via})`)]
|
|
93
|
+
: ['no case touches them']),
|
|
94
|
+
...(impact.untested.length ? [`reached, and touched by no case (${impact.untested.length}):`, ...impact.untested.map((r) => ` ${r}`)] : []),
|
|
95
|
+
];
|
|
96
|
+
return { text: lines.join('\n'), json: { base, changed, ...impact } };
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
define({
|
|
100
|
+
name: 'case new',
|
|
101
|
+
group: 'runs',
|
|
102
|
+
summary: 'Draft a case for a screen: the way there, the backend setup to pick from, and the checks left to write',
|
|
103
|
+
details: 'Prints a case to finish: the frontmatter with the questions a reader needs answered, the setup the project’s fixtures server offers (from `lynkeus.describe`, commented out: what state the case needs is the author’s call), the presses from --from (default `cases.start`) to the screen as `map plan` knows them, and the checks to write. --write saves it as <cases dir>/<id>.md, never over a file that is there.',
|
|
104
|
+
positionals: [{ name: 'id', help: 'the case id, which is also its file name', required: true }],
|
|
105
|
+
flags: {
|
|
106
|
+
to: { type: 'string', help: 'the screen the case is about', value: 'Route' },
|
|
107
|
+
from: { type: 'string', help: 'where it begins (default: cases.start in lynkeus.config.json)', value: 'Route' },
|
|
108
|
+
title: { type: 'string', help: 'what a person can do there, as the report will title it', value: 'text' },
|
|
109
|
+
write: { type: 'boolean', help: 'save it in the cases folder instead of printing it' },
|
|
110
|
+
},
|
|
111
|
+
needs: 'graph',
|
|
112
|
+
session: false,
|
|
113
|
+
mcp: 'core',
|
|
114
|
+
run: async (ctx) => {
|
|
115
|
+
const config = ctx.config.cases ?? {};
|
|
116
|
+
const id = ctx.args[0];
|
|
117
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/.test(id))
|
|
118
|
+
return { text: `${id}: an id is lower case letters, digits, dots, dashes and underscores`, code: 2 };
|
|
119
|
+
const to = ctx.flags.to;
|
|
120
|
+
const from = ctx.flags.from ?? config.start;
|
|
121
|
+
if (!to)
|
|
122
|
+
return { text: 'case new needs --to <Route>, the screen the case is about', code: 2 };
|
|
123
|
+
if (!from)
|
|
124
|
+
return { text: 'case new needs --from <Route>, or cases.start in lynkeus.config.json', code: 2 };
|
|
125
|
+
const graph = ctx.graph();
|
|
126
|
+
if (!graph.screens[to])
|
|
127
|
+
return { text: `${to}: the app has no such screen (lynkeus map routes lists them)`, code: 1 };
|
|
128
|
+
const server = config.fixtures ? new Fixtures(config.fixtures, config.base ?? ctx.root) : undefined;
|
|
129
|
+
const described = server ? await server.describe().finally(() => server.close()) : undefined;
|
|
130
|
+
const text = draftCase({
|
|
131
|
+
id,
|
|
132
|
+
title: ctx.flags.title,
|
|
133
|
+
from,
|
|
134
|
+
to,
|
|
135
|
+
path: plan(graph, from, to, edges.load(edgesFile(ctx.root))) ?? undefined,
|
|
136
|
+
fixtures: described?.details,
|
|
137
|
+
fixturesSilent: !!server && !described,
|
|
138
|
+
macros: Object.keys(config.macros ?? {}),
|
|
139
|
+
});
|
|
140
|
+
if (!ctx.flags.write)
|
|
141
|
+
return { text, json: { id, text } };
|
|
142
|
+
const dir = path.resolve(config.base ?? ctx.root, config.dir ?? 'cases');
|
|
143
|
+
const file = path.join(dir, `${id}.md`);
|
|
144
|
+
if (fs.existsSync(file))
|
|
145
|
+
return { text: `${path.relative(ctx.root, file)} is there already; pick another id or edit it`, code: 1 };
|
|
146
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
147
|
+
fs.writeFileSync(file, text);
|
|
148
|
+
return { text: `wrote ${path.relative(ctx.root, file)}`, json: { id, file } };
|
|
149
|
+
},
|
|
150
|
+
}),
|
|
151
|
+
];
|
package/lib/commands/device.js
CHANGED
|
@@ -76,8 +76,29 @@ export const simulatorArgv = (platform, deviceId, sub, args, appId) => {
|
|
|
76
76
|
{ bin: 'xcrun', args: ['simctl', 'launch', deviceId, app, '-AppleLanguages', `(${tag})`, '-AppleLocale', locale] },
|
|
77
77
|
];
|
|
78
78
|
}
|
|
79
|
+
case 'biometrics': {
|
|
80
|
+
// The simulator's Face ID / Touch ID enrollment, as Features ▸ Face ID ▸ Enrolled toggles it; which of the two
|
|
81
|
+
// the device has is its model's.
|
|
82
|
+
const [available] = args;
|
|
83
|
+
if (!available)
|
|
84
|
+
throw new Error('lynkeus os biometrics --available FaceID|TouchID|none on a simulator');
|
|
85
|
+
const enrolled = available === 'none' ? '0' : '1';
|
|
86
|
+
return [
|
|
87
|
+
{ bin: 'xcrun', args: ['simctl', 'spawn', deviceId, 'notifyutil', '-s', 'com.apple.BiometricKit.enrollmentChanged', enrolled] },
|
|
88
|
+
{ bin: 'xcrun', args: ['simctl', 'spawn', deviceId, 'notifyutil', '-p', 'com.apple.BiometricKit.enrollmentChanged'] },
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
case 'appstate': {
|
|
92
|
+
// Another app in front puts this one in the background; launching it again brings it back as it was.
|
|
93
|
+
const [state] = args;
|
|
94
|
+
if (state === 'background')
|
|
95
|
+
return [{ bin: 'xcrun', args: ['simctl', 'launch', deviceId, 'com.apple.Preferences'] }];
|
|
96
|
+
if (state === 'active')
|
|
97
|
+
return [{ bin: 'xcrun', args: ['simctl', 'launch', deviceId, needApp()] }];
|
|
98
|
+
throw new Error('lynkeus os appstate background|active on a simulator');
|
|
99
|
+
}
|
|
79
100
|
default:
|
|
80
|
-
throw new Error(`unknown os subcommand "${sub}"; one of permissions, push, appearance, location, language`);
|
|
101
|
+
throw new Error(`unknown os subcommand "${sub}"; one of permissions, push, appearance, location, language, appstate`);
|
|
81
102
|
}
|
|
82
103
|
}
|
|
83
104
|
const adb = (a) => ({ bin: 'adb', args: ['-s', deviceId, ...a] });
|
|
@@ -101,8 +122,17 @@ export const simulatorArgv = (platform, deviceId, sub, args, appId) => {
|
|
|
101
122
|
const [lat, lon] = where.split(',');
|
|
102
123
|
return [adb(['emu', 'geo', 'fix', lon, lat])];
|
|
103
124
|
}
|
|
125
|
+
case 'appstate': {
|
|
126
|
+
// Home sends the app to the background; its launcher intent brings the same task back, not a new one.
|
|
127
|
+
const [state] = args;
|
|
128
|
+
if (state === 'background')
|
|
129
|
+
return [adb(['shell', 'input', 'keyevent', 'KEYCODE_HOME'])];
|
|
130
|
+
if (state === 'active')
|
|
131
|
+
return [adb(['shell', 'monkey', '--pct-syskeys', '0', '-p', needApp(), '-c', 'android.intent.category.LAUNCHER', '1'])];
|
|
132
|
+
throw new Error('lynkeus os appstate background|active on an emulator or a phone');
|
|
133
|
+
}
|
|
104
134
|
default:
|
|
105
|
-
throw new Error(`"${sub}" is not available on Android through lynkeus; permissions, appearance and
|
|
135
|
+
throw new Error(`"${sub}" is not available on Android through lynkeus; permissions, appearance, location and appstate are`);
|
|
106
136
|
}
|
|
107
137
|
};
|
|
108
138
|
export const simulatorCommand = async (platform, deviceId, sub, args, appId) => {
|
package/lib/commands/doctor.js
CHANGED
|
@@ -73,6 +73,12 @@ const PATTERNS = [
|
|
|
73
73
|
{ re: /requireNativeComponent\s*(?:<[^>]*>)?\(\s*['"]([^'"]+)['"]/g, how: 'requireNativeComponent' },
|
|
74
74
|
{ re: /codegenNativeComponent\s*<[^>]*>\(\s*['"]([^'"]+)['"]/g, how: 'codegenNativeComponent' },
|
|
75
75
|
];
|
|
76
|
+
/**
|
|
77
|
+
* The text with its comments blanked, lines kept where they were: a mock or a native module named in a comment
|
|
78
|
+
* (the generated entry shows `jest.mock('some-native-package', …)` as an example) is neither. Only comments that
|
|
79
|
+
* own their line are taken, so a `//` inside a string (a URL) stays.
|
|
80
|
+
*/
|
|
81
|
+
const withoutComments = (text) => text.replace(/\/\*[\s\S]*?\*\//g, (block) => block.replace(/[^\n]/g, ' ')).replace(/^[ \t]*\/\/.*$/gm, '');
|
|
76
82
|
const scanNativeRefs = (root) => {
|
|
77
83
|
const files = [];
|
|
78
84
|
for (const d of SCAN_DIRS)
|
|
@@ -81,7 +87,7 @@ const scanNativeRefs = (root) => {
|
|
|
81
87
|
for (const file of files) {
|
|
82
88
|
let text;
|
|
83
89
|
try {
|
|
84
|
-
text = fs.readFileSync(file, 'utf8');
|
|
90
|
+
text = withoutComments(fs.readFileSync(file, 'utf8'));
|
|
85
91
|
}
|
|
86
92
|
catch {
|
|
87
93
|
continue;
|
|
@@ -104,7 +110,7 @@ const entryMocks = (root, entry) => {
|
|
|
104
110
|
const entryPath = path.join(root, entry);
|
|
105
111
|
let text = '';
|
|
106
112
|
try {
|
|
107
|
-
text = fs.readFileSync(entryPath, 'utf8');
|
|
113
|
+
text = withoutComments(fs.readFileSync(entryPath, 'utf8'));
|
|
108
114
|
}
|
|
109
115
|
catch {
|
|
110
116
|
return { specs, files };
|
package/lib/commands/drive.js
CHANGED
|
@@ -165,7 +165,7 @@ export const driveCommands = [
|
|
|
165
165
|
define({
|
|
166
166
|
name: 'wait',
|
|
167
167
|
mcp: 'core',
|
|
168
|
-
mcpOmit: ['nth'],
|
|
168
|
+
mcpOmit: ['nth', 'since'],
|
|
169
169
|
group: 'drive',
|
|
170
170
|
summary: 'Until a route or element appears (or leaves), or a number of ms',
|
|
171
171
|
positionals: [{ name: 'what', help: `Route | route:index | ${TARGET_HELP} | 800 (ms)`, required: true }],
|
|
@@ -174,6 +174,7 @@ export const driveCommands = [
|
|
|
174
174
|
gone: { type: 'boolean', help: 'until it leaves the screen' },
|
|
175
175
|
scroll: { type: 'boolean', help: 'scroll until it is in the window' },
|
|
176
176
|
timeout: { type: 'number', help: 'give up after', default: 10000, value: 'ms' },
|
|
177
|
+
since: { type: 'number', help: 'a trace mark: a route reached after it counts, even if already left', value: 'seq' },
|
|
177
178
|
},
|
|
178
179
|
needs: 'app',
|
|
179
180
|
run: async (ctx) => {
|
|
@@ -188,6 +189,7 @@ export const driveCommands = [
|
|
|
188
189
|
gone: ctx.flags.gone ? true : undefined,
|
|
189
190
|
scroll: ctx.flags.scroll ? true : undefined,
|
|
190
191
|
timeoutMs: ctx.flags.timeout,
|
|
192
|
+
since: ctx.flags.since,
|
|
191
193
|
}),
|
|
192
194
|
};
|
|
193
195
|
},
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Description } from '../cases/fixtures.js';
|
|
2
|
+
/** What a server keeps of the contract and what it leaves out, as lines a person can act on. */
|
|
3
|
+
export declare const checkDescription: (d: Description | undefined) => {
|
|
4
|
+
ok: boolean;
|
|
5
|
+
lines: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare const fixturesCommands: import("../registry.js").Command[];
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { FIXTURES_PROTOCOL } from 'lynkeus-protocol';
|
|
2
|
+
import { DESCRIBE, Fixtures, lastDescription, readDescription } from '../cases/fixtures.js';
|
|
3
|
+
import { define } from '../registry.js';
|
|
4
|
+
const paramsOf = (c) => Object.entries(c.params ?? {})
|
|
5
|
+
.map(([k, p]) => `${k}${p.required ? '' : '?'}${p.values ? `=${p.values.join('|')}` : p.type ? `:${p.type}` : ''}`)
|
|
6
|
+
.join(' ');
|
|
7
|
+
/** What a server keeps of the contract and what it leaves out, as lines a person can act on. */
|
|
8
|
+
export const checkDescription = (d) => {
|
|
9
|
+
if (!d)
|
|
10
|
+
return { ok: false, lines: ['✗ `lynkeus.describe` got no list of commands: answer {"commands": [...]} (docs/FIXTURES.md)'] };
|
|
11
|
+
const lines = [];
|
|
12
|
+
let ok = true;
|
|
13
|
+
if (d.down) {
|
|
14
|
+
ok = false;
|
|
15
|
+
lines.push(`✗ the server runs but cannot serve: ${d.down}`);
|
|
16
|
+
}
|
|
17
|
+
if (d.protocol !== undefined && d.protocol > FIXTURES_PROTOCOL) {
|
|
18
|
+
ok = false;
|
|
19
|
+
lines.push(`✗ it speaks fixtures protocol ${d.protocol}; this lynkeus knows ${FIXTURES_PROTOCOL}`);
|
|
20
|
+
}
|
|
21
|
+
const names = new Set();
|
|
22
|
+
for (const c of d.details) {
|
|
23
|
+
if (names.has(c.name)) {
|
|
24
|
+
ok = false;
|
|
25
|
+
lines.push(`✗ ${c.name} is listed twice`);
|
|
26
|
+
}
|
|
27
|
+
names.add(c.name);
|
|
28
|
+
}
|
|
29
|
+
const bare = d.details.filter((c) => !c.summary);
|
|
30
|
+
lines.push(`✓ ${d.commands.length} command${d.commands.length === 1 ? '' : 's'}`);
|
|
31
|
+
if (bare.length)
|
|
32
|
+
lines.push(`· ${bare.length} without a summary (${bare
|
|
33
|
+
.slice(0, 6)
|
|
34
|
+
.map((c) => c.name)
|
|
35
|
+
.join(', ')}${bare.length > 6 ? ', …' : ''}): a summary and params let authors and models pick a setup`);
|
|
36
|
+
return { ok, lines };
|
|
37
|
+
};
|
|
38
|
+
export const fixturesCommands = [
|
|
39
|
+
define({
|
|
40
|
+
name: 'fixtures describe',
|
|
41
|
+
group: 'runs',
|
|
42
|
+
summary: 'List what the project’s fixtures server can do: each command, what it makes or reads, its parameters',
|
|
43
|
+
details: 'Starts the command `cases.fixtures` names, asks `lynkeus.describe`, and prints each command with its summary and parameters, for whoever writes a case. A server that answers names only shows names. What it answered last (here or before a run) is kept in .lynkeus and shown for a day without starting it; --fresh asks again.',
|
|
44
|
+
flags: { fresh: { type: 'boolean', help: 'ask the server even when it described itself in the last day' } },
|
|
45
|
+
needs: 'nothing',
|
|
46
|
+
session: false,
|
|
47
|
+
mcp: 'core',
|
|
48
|
+
run: async (ctx) => {
|
|
49
|
+
const config = ctx.config.cases ?? {};
|
|
50
|
+
if (!config.fixtures)
|
|
51
|
+
return { text: 'the project declares no fixtures (cases.fixtures in lynkeus.config.json)', code: 1 };
|
|
52
|
+
const root = config.base ?? ctx.root;
|
|
53
|
+
const kept = ctx.flags.fresh ? undefined : lastDescription(root, config.fixtures.command);
|
|
54
|
+
const recent = kept && Date.now() - kept.at < 24 * 3600_000 ? kept : undefined;
|
|
55
|
+
let d = recent?.description;
|
|
56
|
+
if (!d) {
|
|
57
|
+
const server = new Fixtures(config.fixtures, root);
|
|
58
|
+
d = await server.describe().finally(() => server.close());
|
|
59
|
+
}
|
|
60
|
+
if (!d)
|
|
61
|
+
return { text: 'the fixtures server did not describe itself (it answers `lynkeus.describe` with {"commands": [...]})', code: 1 };
|
|
62
|
+
const text = d.details.map((c) => `${c.name}${c.params ? ` ${paramsOf(c)}` : ''}${c.summary ? `\n ${c.summary}` : ''}`).join('\n');
|
|
63
|
+
const age = recent ? `\n(as the server described itself ${Math.round((Date.now() - recent.at) / 60_000)} min ago; --fresh asks it again)` : '';
|
|
64
|
+
return { text: d.down ? `${text}\n(the server cannot serve now: ${d.down})` : `${text}${age}`, json: d };
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
define({
|
|
68
|
+
name: 'fixtures check',
|
|
69
|
+
group: 'runs',
|
|
70
|
+
summary: 'Tell whether the project’s fixtures server keeps the fixtures protocol',
|
|
71
|
+
details: 'Starts the server, asks `lynkeus.describe`, and checks the answer against the contract in docs/FIXTURES.md: a list of commands, no name twice, a protocol version this lynkeus knows, and whether it is up. It changes nothing in the backend.',
|
|
72
|
+
needs: 'nothing',
|
|
73
|
+
session: false,
|
|
74
|
+
mcp: 'core',
|
|
75
|
+
run: async (ctx) => {
|
|
76
|
+
const config = ctx.config.cases ?? {};
|
|
77
|
+
if (!config.fixtures)
|
|
78
|
+
return { text: 'the project declares no fixtures (cases.fixtures in lynkeus.config.json)', code: 1 };
|
|
79
|
+
const server = new Fixtures(config.fixtures, config.base ?? ctx.root);
|
|
80
|
+
// Its own call, not describe(): a server that never answers is told apart from one that answers wrong.
|
|
81
|
+
const answered = await server.call(DESCRIBE, {}).then((answer) => ({ answer }), (error) => ({ error: error.message }));
|
|
82
|
+
server.close();
|
|
83
|
+
if ('error' in answered)
|
|
84
|
+
return {
|
|
85
|
+
text: `✗ the fixtures server gave no answer to lynkeus.describe: ${answered.error}\n (is its backend up? the command is \`${config.fixtures.command}\`)`,
|
|
86
|
+
json: { ok: false, error: answered.error },
|
|
87
|
+
code: 1,
|
|
88
|
+
};
|
|
89
|
+
const d = readDescription(answered.answer);
|
|
90
|
+
const { ok, lines } = checkDescription(d);
|
|
91
|
+
return { text: lines.join('\n'), json: { ok, description: d }, code: ok ? 0 : 1 };
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
];
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A jest cache of its own for each API base. Babel inlines `process.env` into the code it transforms and jest
|
|
3
|
+
* keeps that output, so a host started with another API address kept calling the first one it was started with.
|
|
4
|
+
*/
|
|
5
|
+
export declare const cacheFor: (root: string, env: Record<string, string | undefined>, apiEnv?: string) => string;
|
|
6
|
+
/**
|
|
7
|
+
* What jest is told when the app has not said it itself, so an app with no jest set up runs headless as it is:
|
|
8
|
+
* the preset its framework needs (jest-expo for Expo, React Native's otherwise), and which packages under node_modules to transpile.
|
|
9
|
+
*/
|
|
10
|
+
/** The app's react folder, when lynkeus-headless would load another copy; undefined when they are one. */
|
|
11
|
+
export declare const duplicateReact: (root: string) => string | undefined;
|
|
1
12
|
export declare const headlessCommands: import("../registry.js").Command[];
|