@mcoda/mswarm 0.1.135-codali.41 → 0.1.135-codali.47
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/dist/vendor/codali/cli/TerminalCommand.js +2 -2
- package/dist/vendor/codali/cli/tui/TerminalPresentation.js +1 -1
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts +1 -0
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -1
- package/dist/vendor/codali/config/OrchestrationConfig.js +3 -1
- package/dist/vendor/codali/docdex/DocdexClient.d.ts +11 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/vendor/codali/docdex/DocdexClient.js +55 -1
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts +5 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts.map +1 -1
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.js +63 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.js +2 -2
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.js +2 -2
- package/dist/vendor/codali/permissions/PermissionGate.d.ts +7 -0
- package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -1
- package/dist/vendor/codali/permissions/PermissionGate.js +27 -1
- package/dist/vendor/codali/providers/ClaudeCliProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ClaudeCliProvider.js +1 -0
- package/dist/vendor/codali/providers/CodexCliProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/CodexCliProvider.js +1 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +2 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ConfiguredProvider.js +29 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts +16 -2
- package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ModelServiceError.js +18 -1
- package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/OllamaRemoteProvider.js +1 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +4 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +4 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/AnswerEdits.d.ts +39 -0
- package/dist/vendor/codali/runtime/AnswerEdits.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/AnswerEdits.js +134 -0
- package/dist/vendor/codali/runtime/AnswerVerification.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/AnswerVerification.js +4 -2
- package/dist/vendor/codali/runtime/AuditGuards.d.ts +41 -0
- package/dist/vendor/codali/runtime/AuditGuards.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/AuditGuards.js +81 -0
- package/dist/vendor/codali/runtime/CompletionReport.d.ts +4 -2
- package/dist/vendor/codali/runtime/CompletionReport.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CompletionReport.js +8 -3
- package/dist/vendor/codali/runtime/ContextCompression.d.ts +5 -0
- package/dist/vendor/codali/runtime/ContextCompression.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ContextCompression.js +16 -4
- package/dist/vendor/codali/runtime/DeliveryDocs.d.ts +21 -0
- package/dist/vendor/codali/runtime/DeliveryDocs.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/DeliveryDocs.js +148 -0
- package/dist/vendor/codali/runtime/FigureCheck.d.ts +61 -2
- package/dist/vendor/codali/runtime/FigureCheck.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/FigureCheck.js +210 -14
- package/dist/vendor/codali/runtime/GatewayRequest.d.ts +13 -0
- package/dist/vendor/codali/runtime/GatewayRequest.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/GatewayRequest.js +54 -1
- package/dist/vendor/codali/runtime/InspectionConvergence.d.ts +4 -0
- package/dist/vendor/codali/runtime/InspectionConvergence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/InspectionConvergence.js +24 -1
- package/dist/vendor/codali/runtime/InteractionContract.d.ts +15 -0
- package/dist/vendor/codali/runtime/InteractionContract.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/InteractionContract.js +33 -0
- package/dist/vendor/codali/runtime/InteractionRouter.d.ts +3 -3
- package/dist/vendor/codali/runtime/InteractionRouter.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/InteractionRouter.js +1 -1
- package/dist/vendor/codali/runtime/NumericProvenance.d.ts +102 -0
- package/dist/vendor/codali/runtime/NumericProvenance.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/NumericProvenance.js +411 -0
- package/dist/vendor/codali/runtime/OutageWait.d.ts +46 -5
- package/dist/vendor/codali/runtime/OutageWait.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/OutageWait.js +81 -8
- package/dist/vendor/codali/runtime/ResearchEvidence.d.ts +14 -0
- package/dist/vendor/codali/runtime/ResearchEvidence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ResearchEvidence.js +139 -3
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts +22 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ReviewCoordinator.js +203 -25
- package/dist/vendor/codali/runtime/ReviewSource.d.ts +5 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ReviewSource.js +6 -1
- package/dist/vendor/codali/runtime/SessionController.d.ts +85 -10
- package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/SessionController.js +996 -176
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts +10 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/StructuralEvidence.js +10 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts +10 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/TaskReview.js +31 -3
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts +8 -0
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/VerificationCommand.js +114 -0
- package/dist/vendor/codali/runtime/WorkingStyle.d.ts +20 -0
- package/dist/vendor/codali/runtime/WorkingStyle.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkingStyle.js +71 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/vendor/codali/tools/ToolRegistry.js +30 -4
- package/dist/vendor/codali/tools/ToolTypes.d.ts +3 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -1
- package/dist/vendor/codali/tools/browser/BrowserTool.d.ts +23 -1
- package/dist/vendor/codali/tools/browser/BrowserTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/browser/BrowserTool.js +83 -4
- package/dist/vendor/codali/tools/browser/BrowserWorker.js +142 -2
- package/dist/vendor/codali/tools/browser/HttpFallback.d.ts +39 -0
- package/dist/vendor/codali/tools/browser/HttpFallback.d.ts.map +1 -0
- package/dist/vendor/codali/tools/browser/HttpFallback.js +240 -0
- package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts +16 -1
- package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/calculation/CalculatorTool.js +321 -26
- package/dist/vendor/codali/tools/deterministic/DeterministicTools.js +1 -1
- package/dist/vendor/codali/tools/deterministic/node-worker.cjs +10 -10
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts +2 -0
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/AsyncProcess.js +38 -5
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +29 -1
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +179 -9
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts +2 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/ShellTool.js +33 -3
- package/dist/vendor/codali/tools/verification/CodeRunTool.d.ts +19 -0
- package/dist/vendor/codali/tools/verification/CodeRunTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/verification/CodeRunTool.js +104 -0
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.js +21 -10
- package/dist/vendor/codali/tools/verification/VitestTool.d.ts +27 -0
- package/dist/vendor/codali/tools/verification/VitestTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/verification/VitestTool.js +232 -18
- package/dist/vendor/config/deterministic/node-worker.mjs +15 -2
- package/dist/vendor/config/skills/code-implementation/SKILL.md +1 -1
- package/dist/vendor/config/skills/planning/SKILL.md +1 -1
- package/dist/vendor/config/skills/testing-and-verification/SKILL.md +5 -5
- package/dist/vendor/config/skills/ui-ux-design/SKILL.md +1 -1
- package/dist/vendor/config/skills/webapp-testing/SKILL.md +4 -0
- package/dist/vendor/config/skills/webapp-testing/journey-driver.mjs +186 -0
- package/package.json +3 -3
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// journey-driver.mjs: drive headless Chrome over its debugging protocol.
|
|
2
|
+
// No dependencies; Node 22 or newer. Copy it into the project's test folder.
|
|
3
|
+
// It records every console error, uncaught exception, HTTP 4xx/5xx response
|
|
4
|
+
// and failed request; page.step() fails a step that produced one, or that
|
|
5
|
+
// leaves a visible form control without an accessible name.
|
|
6
|
+
// Page methods: goto, reload, step(name, run, { allow, labels }), click, type,
|
|
7
|
+
// text, waitForSelector, waitForText, waitFor (any expression), evaluate,
|
|
8
|
+
// screenshot, unlabelledControls, problems. A wait that fails reports what the
|
|
9
|
+
// page shows. In allow, list what the step expects: an HTTP status, or a RegExp
|
|
10
|
+
// for one entry: "STATUS METHOD URL" (a response, e.g. /^401 GET \S+\/api\/me$/),
|
|
11
|
+
// "network METHOD URL ERROR", "console TEXT" or "exception TEXT".
|
|
12
|
+
// Requests to public internet hosts (a CDN font in an offline sandbox)
|
|
13
|
+
// are reported as kind "external" in problems() and on the PASS line, but do
|
|
14
|
+
// not fail a step.
|
|
15
|
+
//
|
|
16
|
+
// Usage (one run_shell call; every role gets a reload-then-act step):
|
|
17
|
+
// import { launch, startServer } from './journey-driver.mjs';
|
|
18
|
+
// const server = await startServer('node', ['server/index.js'], { url: 'http://127.0.0.1:3000/health', env: { PORT: '3000' } });
|
|
19
|
+
// const page = await launch(); let failed = false;
|
|
20
|
+
// const step = (name, run, options) => page.step(name, run, options).catch(() => { failed = true; });
|
|
21
|
+
// try {
|
|
22
|
+
// await step('admin signs in', async () => { await page.goto('http://127.0.0.1:3000/');
|
|
23
|
+
// await page.type('#email', 'a@example.test'); await page.click('button[type=submit]'); await page.waitForText('Dashboard');
|
|
24
|
+
// }, { allow: [/^401 GET \S+\/api\/me$/] });
|
|
25
|
+
// await step('after a reload, admin creates a project', async () => { await page.reload();
|
|
26
|
+
// await page.type('#name', 'Apollo'); await page.click('#create'); await page.reload(); await page.waitForText('Apollo'); });
|
|
27
|
+
// } finally { await page.close(); server.kill(); }
|
|
28
|
+
// process.exit(failed ? 1 : 0);
|
|
29
|
+
import { spawn } from 'node:child_process';
|
|
30
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
31
|
+
import { tmpdir } from 'node:os';
|
|
32
|
+
import { join } from 'node:path';
|
|
33
|
+
|
|
34
|
+
export const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
35
|
+
|
|
36
|
+
/** Start the app and wait until `url` answers. Kill the returned process when done. */
|
|
37
|
+
export async function startServer(command, args, { url, env = {}, ms = 20000 } = {}) {
|
|
38
|
+
const proc = spawn(command, args, { stdio: 'inherit', env: { ...process.env, ...env } });
|
|
39
|
+
for (const end = Date.now() + ms; ;) {
|
|
40
|
+
try { await fetch(url); return proc; } catch {}
|
|
41
|
+
if (proc.exitCode !== null) throw new Error('Server exited before it answered');
|
|
42
|
+
if (Date.now() > end) { proc.kill(); throw new Error(`Server not reachable at ${url}`); }
|
|
43
|
+
await sleep(100);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Launch Chrome and return page controls. Every wait fails with a clear message. */
|
|
48
|
+
export async function launch({ chrome = process.env.CHROME_BIN } = {}) {
|
|
49
|
+
const dir = mkdtempSync(join(process.env.TMPDIR || tmpdir(), 'journey-'));
|
|
50
|
+
// Port 0: Chrome picks a free port and writes it to DevToolsActivePort, so
|
|
51
|
+
// two journeys on one machine never attach to each other's browser.
|
|
52
|
+
const flags = ['--headless=new', '--no-sandbox', '--disable-gpu', '--no-first-run',
|
|
53
|
+
'--remote-debugging-port=0', `--user-data-dir=${dir}`, 'about:blank'];
|
|
54
|
+
let proc;
|
|
55
|
+
for (const bin of [chrome, 'google-chrome', 'chromium', 'chromium-browser'].filter(Boolean)) {
|
|
56
|
+
const candidate = spawn(bin, flags, { stdio: 'ignore' });
|
|
57
|
+
if (await new Promise(r => { candidate.once('error', () => r(false)); setTimeout(() => r(true), 300); })) { proc = candidate; break; }
|
|
58
|
+
}
|
|
59
|
+
if (!proc) throw new Error('No Chrome or Chromium executable found');
|
|
60
|
+
let target;
|
|
61
|
+
for (let i = 0; i < 150 && !target; i++) {
|
|
62
|
+
try {
|
|
63
|
+
const port = Number(readFileSync(join(dir, 'DevToolsActivePort'), 'utf8').split('\n')[0]);
|
|
64
|
+
target = (await (await fetch(`http://127.0.0.1:${port}/json`)).json()).find(t => t.type === 'page');
|
|
65
|
+
} catch {}
|
|
66
|
+
if (!target) await sleep(100);
|
|
67
|
+
}
|
|
68
|
+
if (!target) { proc.kill(); throw new Error('Chrome did not open its debugging port'); }
|
|
69
|
+
const ws = new WebSocket(target.webSocketDebuggerUrl);
|
|
70
|
+
await new Promise((res, rej) => { ws.onopen = res; ws.onerror = () => rej(new Error('Debugging socket failed')); });
|
|
71
|
+
let id = 0;
|
|
72
|
+
const pending = new Map();
|
|
73
|
+
const problems = [], methods = new Map(), loads = [];
|
|
74
|
+
const appOrigins = new Set();
|
|
75
|
+
const originOf = url => { try { return new URL(url).origin; } catch { return undefined; } };
|
|
76
|
+
// Only public internet hosts are remote. The app's own origins (every page it
|
|
77
|
+
// served or the journey opened), loopback, private networks and single-label
|
|
78
|
+
// or local names (a compose service such as http://api:3000) are the app.
|
|
79
|
+
const localHost = host => /^(?:localhost|0\.0\.0\.0|127(?:\.\d+){3}|10(?:\.\d+){3}|192\.168(?:\.\d+){2}|172\.(?:1[6-9]|2\d|3[01])(?:\.\d+){2}|169\.254(?:\.\d+){2})$/.test(host)
|
|
80
|
+
|| /^\[(?:::1?|f[cd][0-9a-f]*:.*|fe80:.*)\]$/i.test(host) || !host.includes('.') || /\.(?:local|localhost|internal|lan|home\.arpa|test)$/i.test(host);
|
|
81
|
+
const remote = url => { try { const u = new URL(url);
|
|
82
|
+
return /^https?:$/.test(u.protocol) && !appOrigins.has(u.origin) && !localHost(u.hostname); } catch { return false; } };
|
|
83
|
+
const record = problem => problems.push({ ...problem,
|
|
84
|
+
...(problem.url && /^(?:http|network)$/.test(problem.kind) && remote(problem.url) ? { kind: 'external', was: problem.kind } : {}),
|
|
85
|
+
at: Date.now() });
|
|
86
|
+
const events = {
|
|
87
|
+
'Page.loadEventFired': () => loads.splice(0).forEach(r => r()),
|
|
88
|
+
'Page.frameNavigated': p => { const origin = !p.frame.parentId && originOf(p.frame.url); if (origin && origin !== 'null') appOrigins.add(origin); },
|
|
89
|
+
'Network.requestWillBeSent': p => methods.set(p.requestId, { method: p.request.method, url: p.request.url }),
|
|
90
|
+
'Network.responseReceived': p => { const { status, url } = p.response;
|
|
91
|
+
if (status >= 400 && !/\/favicon\.ico(?:$|\?)/.test(url)) record({ kind: 'http', status, method: methods.get(p.requestId)?.method ?? 'GET', url }); },
|
|
92
|
+
'Network.loadingFailed': p => { if (!p.canceled) record({ kind: 'network', ...methods.get(p.requestId), error: p.errorText }); },
|
|
93
|
+
'Runtime.consoleAPICalled': p => { if (p.type === 'error' || p.type === 'assert')
|
|
94
|
+
record({ kind: 'console', text: p.args.map(a => a.value ?? a.description ?? '').join(' ') }); },
|
|
95
|
+
'Runtime.exceptionThrown': p => record({ kind: 'exception', text: p.exceptionDetails.exception?.description || p.exceptionDetails.text }),
|
|
96
|
+
};
|
|
97
|
+
ws.onmessage = e => {
|
|
98
|
+
const m = JSON.parse(e.data), p = pending.get(m.id);
|
|
99
|
+
if (m.method) events[m.method]?.(m.params);
|
|
100
|
+
if (p) { pending.delete(m.id); m.error ? p.rej(new Error(m.error.message)) : p.res(m.result); }
|
|
101
|
+
};
|
|
102
|
+
const cdp = (method, params = {}) => new Promise((res, rej) => { pending.set(++id, { res, rej }); ws.send(JSON.stringify({ id, method, params })); });
|
|
103
|
+
await cdp('Page.enable'); await cdp('Runtime.enable'); await cdp('Network.enable');
|
|
104
|
+
// Resolves on the next load event, so a reload never sees the old page as loaded.
|
|
105
|
+
const load = async (what, start) => {
|
|
106
|
+
let timer;
|
|
107
|
+
const loaded = new Promise((res, rej) => { loads.push(res); timer = setTimeout(() => rej(new Error(`Timed out waiting for ${what}`)), 10000); });
|
|
108
|
+
loaded.catch(() => {});
|
|
109
|
+
try {
|
|
110
|
+
const result = await start();
|
|
111
|
+
if (result?.errorText) throw new Error(`${what} failed: ${result.errorText}`);
|
|
112
|
+
// A same-document navigation (a hash route) fires no load event.
|
|
113
|
+
if (result && 'frameId' in result && !result.loaderId) return;
|
|
114
|
+
await loaded;
|
|
115
|
+
} finally { clearTimeout(timer); }
|
|
116
|
+
};
|
|
117
|
+
const evaluate = async expression => {
|
|
118
|
+
const r = await cdp('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
|
|
119
|
+
if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description || r.exceptionDetails.text);
|
|
120
|
+
return r.result.value;
|
|
121
|
+
};
|
|
122
|
+
const waitFor = async (expression, what = expression, ms = 5000) => {
|
|
123
|
+
for (const end = Date.now() + ms; ;) {
|
|
124
|
+
const value = await evaluate(expression).catch(() => undefined);
|
|
125
|
+
if (value) return value;
|
|
126
|
+
if (Date.now() > end) throw new Error(`Timed out waiting for ${what}; page shows: ${String(await evaluate('document.body?.innerText ?? ""').catch(() => '')).slice(0, 300)}`);
|
|
127
|
+
await sleep(50);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const q = s => `document.querySelector(${JSON.stringify(s)})`;
|
|
131
|
+
// Visible inputs, selects and textareas with no label[for], wrapping label,
|
|
132
|
+
// aria-label, aria-labelledby or title. Returns a short selector for each.
|
|
133
|
+
const unlabelledControls = () => evaluate(`[...document.querySelectorAll('input, select, textarea')].filter(e =>
|
|
134
|
+
!['hidden', 'submit', 'button', 'reset', 'image'].includes(e.type) && e.getClientRects().length
|
|
135
|
+
&& ![...(e.labels ?? [])].some(l => l.innerText.trim()) && !e.getAttribute('aria-label')?.trim() && !e.title.trim()
|
|
136
|
+
&& !(e.getAttribute('aria-labelledby') ?? '').split(/\\s+/).some(i => document.getElementById(i)?.innerText.trim())
|
|
137
|
+
).map(e => e.tagName.toLowerCase() + (e.id ? '#' + e.id : e.name ? '[name=' + e.name + ']' : ''))`);
|
|
138
|
+
const describe = p => p.kind === 'http' ? `${p.method} ${p.url} returned ${p.status}`
|
|
139
|
+
: p.kind === 'network' ? `${p.method} ${p.url} failed: ${p.error}`
|
|
140
|
+
: p.kind === 'external' ? `${p.method} ${p.url} ${p.error ? 'failed: ' + p.error : 'returned ' + p.status}` : `${p.kind} error: ${p.text}`;
|
|
141
|
+
const entry = p => p.kind === 'http' ? `${p.status} ${p.method} ${p.url}` : p.kind === 'network' ? `network ${p.method} ${p.url} ${p.error}`
|
|
142
|
+
: p.kind === 'external' ? `external ${p.method} ${p.url} ${p.error ?? p.status}` : `${p.kind} ${p.text}`;
|
|
143
|
+
return {
|
|
144
|
+
cdp, evaluate, waitFor, unlabelledControls,
|
|
145
|
+
/** Everything recorded since launch: { kind: http|network|console|exception, ... }. */
|
|
146
|
+
problems: () => [...problems],
|
|
147
|
+
goto: url => { const origin = originOf(url); if (origin && origin !== 'null') appOrigins.add(origin); return load(`load of ${url}`, () => cdp('Page.navigate', { url })); },
|
|
148
|
+
/** Reload the current page (the session cookie stays), then wait for the load. */
|
|
149
|
+
reload: () => load('reload', () => cdp('Page.reload', { ignoreCache: true })),
|
|
150
|
+
/** Run one scenario step. It fails on a console error, uncaught exception,
|
|
151
|
+
* failed request or 4xx/5xx response during the step and on unlabelled
|
|
152
|
+
* controls. List what the step expects in allow (see the header). */
|
|
153
|
+
step: async (name, run, { allow = [], labels = true } = {}) => {
|
|
154
|
+
const start = problems.length;
|
|
155
|
+
const expected = p => p.kind === 'external' || allow.some(a => a instanceof RegExp ? a.test(entry(p)) : p.kind === 'http' && a === p.status);
|
|
156
|
+
const unexpected = () => problems.slice(start).filter(p => !expected(p)).map(describe).join('; ');
|
|
157
|
+
const external = () => problems.slice(start).filter(p => p.kind === 'external').map(describe);
|
|
158
|
+
try {
|
|
159
|
+
await run(); await sleep(300);
|
|
160
|
+
if (unexpected()) throw new Error(unexpected());
|
|
161
|
+
const unlabelled = labels ? await unlabelledControls() : [];
|
|
162
|
+
if (unlabelled.length) throw new Error(`form controls without a label: ${unlabelled.join(', ')}`);
|
|
163
|
+
console.log(`PASS ${name}${external().length ? ` (other origins not reached: ${external().join('; ')})` : ''}`);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
// A wait that timed out often hides the refused request behind it.
|
|
166
|
+
const seen = unexpected();
|
|
167
|
+
if (seen && !error.message.includes(seen)) error.message += `; during this step: ${seen}`;
|
|
168
|
+
console.log(`FAIL ${name}: ${error.message}`); throw error;
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
waitForSelector: (s, ms) => waitFor(`!!${q(s)}`, `selector ${s}`, ms),
|
|
172
|
+
waitForText: (t, ms) => waitFor(`!!document.body && document.body.innerText.includes(${JSON.stringify(t)})`, `text "${t}"`, ms),
|
|
173
|
+
click: async s => { await waitFor(`!!${q(s)}`, `selector ${s}`); await evaluate(`${q(s)}.click()`); },
|
|
174
|
+
// Sets the value the way a framework expects, then fires input and change.
|
|
175
|
+
type: async (s, text) => {
|
|
176
|
+
await waitFor(`!!${q(s)}`, `selector ${s}`);
|
|
177
|
+
await evaluate(`(() => { const e = ${q(s)}; e.focus();
|
|
178
|
+
const set = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e), 'value')?.set;
|
|
179
|
+
set ? set.call(e, ${JSON.stringify(text)}) : (e.value = ${JSON.stringify(text)});
|
|
180
|
+
e.dispatchEvent(new Event('input', { bubbles: true })); e.dispatchEvent(new Event('change', { bubbles: true })); })()`);
|
|
181
|
+
},
|
|
182
|
+
text: (s = 'body') => evaluate(`${q(s)}?.innerText ?? ''`),
|
|
183
|
+
screenshot: async () => Buffer.from((await cdp('Page.captureScreenshot', { format: 'png' })).data, 'base64'),
|
|
184
|
+
close: async () => { try { ws.close(); } catch {} proc.kill(); await sleep(150); rmSync(dir, { recursive: true, force: true }); },
|
|
185
|
+
};
|
|
186
|
+
}
|
package/package.json
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"url": "https://github.com/bekirdag/mcoda/issues"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@mcoda/db": "0.1.135-codali.
|
|
12
|
-
"@mcoda/shared": "0.1.135-codali.
|
|
11
|
+
"@mcoda/db": "0.1.135-codali.47",
|
|
12
|
+
"@mcoda/shared": "0.1.135-codali.47",
|
|
13
13
|
"@modelcontextprotocol/sdk": "1.30.0",
|
|
14
14
|
"ajv": "8.20.0",
|
|
15
15
|
"browser-use": "0.9.0",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
},
|
|
68
68
|
"type": "module",
|
|
69
69
|
"types": "dist/server.d.ts",
|
|
70
|
-
"version": "0.1.135-codali.
|
|
70
|
+
"version": "0.1.135-codali.47"
|
|
71
71
|
}
|