@canaryai/cli 0.1.1-alpha.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/README.md +82 -0
- package/dist/fsevents-72LCIACT.node +0 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +916 -0
- package/dist/index.js.map +1 -0
- package/dist/runner/preload.d.ts +2 -0
- package/dist/runner/preload.js +1491 -0
- package/dist/runner/preload.js.map +1 -0
- package/dist/test.d.ts +1167 -0
- package/dist/test.js +149276 -0
- package/dist/test.js.map +1 -0
- package/package.json +57 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,916 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
11
|
+
import process7 from "process";
|
|
12
|
+
import path5 from "path";
|
|
13
|
+
import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "url";
|
|
14
|
+
|
|
15
|
+
// src/runner/common.ts
|
|
16
|
+
import { spawnSync } from "child_process";
|
|
17
|
+
import fs from "fs";
|
|
18
|
+
import path from "path";
|
|
19
|
+
import { createRequire } from "module";
|
|
20
|
+
import { pathToFileURL } from "url";
|
|
21
|
+
function makeRequire() {
|
|
22
|
+
try {
|
|
23
|
+
return createRequire(import.meta.url);
|
|
24
|
+
} catch {
|
|
25
|
+
try {
|
|
26
|
+
return createRequire(process.cwd());
|
|
27
|
+
} catch {
|
|
28
|
+
return typeof __require !== "undefined" ? __require : createRequire(".");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function resolveRunner(preloadPath2) {
|
|
33
|
+
const { bin, version } = pickNodeBinary();
|
|
34
|
+
const supportsImport = typeof version === "number" && version >= 18;
|
|
35
|
+
if (supportsImport && preloadPath2 && fs.existsSync(preloadPath2)) {
|
|
36
|
+
return { runnerBin: bin, preloadFlag: `--import=${pathToFileURL(preloadPath2).href}` };
|
|
37
|
+
}
|
|
38
|
+
if (preloadPath2) {
|
|
39
|
+
console.warn("[canary] Warning: no preload module found; instrumentation may be disabled.");
|
|
40
|
+
}
|
|
41
|
+
return { runnerBin: bin };
|
|
42
|
+
}
|
|
43
|
+
function pickNodeBinary() {
|
|
44
|
+
const candidates = collectNodeCandidates();
|
|
45
|
+
let best;
|
|
46
|
+
let fallback;
|
|
47
|
+
for (const bin of candidates) {
|
|
48
|
+
const version = getNodeMajor(bin);
|
|
49
|
+
if (!version) continue;
|
|
50
|
+
const current = { bin, version };
|
|
51
|
+
if (version >= 18 && !fallback) {
|
|
52
|
+
fallback = current;
|
|
53
|
+
}
|
|
54
|
+
if (!best || version > (best.version ?? 0)) {
|
|
55
|
+
best = current;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (fallback) return fallback;
|
|
59
|
+
if (best) return best;
|
|
60
|
+
return { bin: candidates[0] ?? "node" };
|
|
61
|
+
}
|
|
62
|
+
function collectNodeCandidates() {
|
|
63
|
+
const seen = /* @__PURE__ */ new Set();
|
|
64
|
+
const push = (value) => {
|
|
65
|
+
if (!value) return;
|
|
66
|
+
if (seen.has(value)) return;
|
|
67
|
+
seen.add(value);
|
|
68
|
+
};
|
|
69
|
+
const isBun = path.basename(process.execPath).includes("bun");
|
|
70
|
+
push(process.env.CANARY_NODE_BIN);
|
|
71
|
+
push(isBun ? void 0 : process.execPath);
|
|
72
|
+
push("node");
|
|
73
|
+
try {
|
|
74
|
+
const which = spawnSync("which", ["-a", "node"], { encoding: "utf-8" });
|
|
75
|
+
which.stdout?.toString().split("\n").map((line) => line.trim()).forEach((line) => push(line));
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
78
|
+
const nvmDir = process.env.NVM_DIR || (process.env.HOME ? path.join(process.env.HOME, ".nvm") : void 0);
|
|
79
|
+
if (nvmDir) {
|
|
80
|
+
const versionsDir = path.join(nvmDir, "versions", "node");
|
|
81
|
+
if (fs.existsSync(versionsDir)) {
|
|
82
|
+
try {
|
|
83
|
+
const versions = fs.readdirSync(versionsDir);
|
|
84
|
+
versions.sort((a, b) => a > b ? -1 : 1).forEach((v) => push(path.join(versionsDir, v, "bin", "node")));
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return Array.from(seen);
|
|
90
|
+
}
|
|
91
|
+
function getNodeMajor(bin) {
|
|
92
|
+
try {
|
|
93
|
+
const result = spawnSync(bin, ["-v"], { encoding: "utf-8" });
|
|
94
|
+
const output = (result.stdout || result.stderr || "").toString().trim();
|
|
95
|
+
const match = output.match(/^v(\d+)/);
|
|
96
|
+
if (match) return Number(match[1]);
|
|
97
|
+
} catch {
|
|
98
|
+
}
|
|
99
|
+
return void 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/run.ts
|
|
103
|
+
import { spawn } from "child_process";
|
|
104
|
+
import fs2 from "fs";
|
|
105
|
+
import os from "os";
|
|
106
|
+
import path2 from "path";
|
|
107
|
+
import { fileURLToPath } from "url";
|
|
108
|
+
async function run(request = {}) {
|
|
109
|
+
const cwd = request.projectRoot ?? process.cwd();
|
|
110
|
+
const stdio = request.stdio ?? "inherit";
|
|
111
|
+
const requireFn2 = makeRequire();
|
|
112
|
+
const playwrightCli = requireFn2.resolve("@playwright/test/cli");
|
|
113
|
+
const baseDir2 = path2.dirname(fileURLToPath(import.meta.url));
|
|
114
|
+
const preloadPath2 = path2.join(baseDir2, "runner", "preload.js");
|
|
115
|
+
const { runnerBin, preloadFlag } = resolveRunner(preloadPath2);
|
|
116
|
+
const { jsonReportPath, eventLogPath, artifactsDir } = prepareArtifactsDir(cwd);
|
|
117
|
+
const reporter = buildReporterArgs(request.reporter, jsonReportPath);
|
|
118
|
+
const args = buildArgs({
|
|
119
|
+
testDir: request.testDir,
|
|
120
|
+
configFile: request.configFile,
|
|
121
|
+
cliArgs: request.cliArgs,
|
|
122
|
+
reporter
|
|
123
|
+
});
|
|
124
|
+
const nodeOptions = process.env.NODE_OPTIONS && preloadFlag ? `${process.env.NODE_OPTIONS} ${preloadFlag}` : preloadFlag ?? process.env.NODE_OPTIONS;
|
|
125
|
+
const env = buildEnv({
|
|
126
|
+
base: process.env,
|
|
127
|
+
overrides: request.env,
|
|
128
|
+
healing: request.healing,
|
|
129
|
+
eventLogPath,
|
|
130
|
+
nodeOptions
|
|
131
|
+
});
|
|
132
|
+
const runResult = await spawnPlaywright({
|
|
133
|
+
bin: request.nodeBin ?? runnerBin,
|
|
134
|
+
args: [playwrightCli, ...args],
|
|
135
|
+
cwd,
|
|
136
|
+
env,
|
|
137
|
+
stdio,
|
|
138
|
+
timeoutMs: request.timeoutMs
|
|
139
|
+
});
|
|
140
|
+
const summary = summarize(jsonReportPath, eventLogPath, runResult.durationMs);
|
|
141
|
+
return {
|
|
142
|
+
ok: runResult.exitCode === 0,
|
|
143
|
+
exitCode: runResult.exitCode,
|
|
144
|
+
summary,
|
|
145
|
+
artifactsDir,
|
|
146
|
+
rawOutput: runResult.output,
|
|
147
|
+
error: runResult.error
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function buildArgs(opts) {
|
|
151
|
+
const args = ["test"];
|
|
152
|
+
if (opts.testDir) {
|
|
153
|
+
const dirs = Array.isArray(opts.testDir) ? opts.testDir : [opts.testDir];
|
|
154
|
+
args.push(...dirs);
|
|
155
|
+
}
|
|
156
|
+
if (opts.configFile) {
|
|
157
|
+
args.push("--config", opts.configFile);
|
|
158
|
+
}
|
|
159
|
+
args.push("--reporter", opts.reporter);
|
|
160
|
+
if (opts.cliArgs?.length) {
|
|
161
|
+
args.push(...opts.cliArgs);
|
|
162
|
+
}
|
|
163
|
+
return args;
|
|
164
|
+
}
|
|
165
|
+
function buildReporterArgs(requested, jsonReportPath) {
|
|
166
|
+
if (requested === "json") return `json=${jsonReportPath}`;
|
|
167
|
+
if (requested && requested !== "default") return requested;
|
|
168
|
+
return `list,json=${jsonReportPath}`;
|
|
169
|
+
}
|
|
170
|
+
function prepareArtifactsDir(cwd) {
|
|
171
|
+
const dir = fs2.mkdtempSync(path2.join(os.tmpdir(), "canary-run-"));
|
|
172
|
+
const jsonReportPath = path2.join(dir, "report.json");
|
|
173
|
+
const eventLogPath = path2.join(dir, "events-worker-0.jsonl");
|
|
174
|
+
const artifactsDir = path2.join(cwd, "test-results", "ai-healer");
|
|
175
|
+
return { jsonReportPath, eventLogPath, artifactsDir: dir };
|
|
176
|
+
}
|
|
177
|
+
function buildEnv(params) {
|
|
178
|
+
const healing = params.healing ?? {};
|
|
179
|
+
const env = {
|
|
180
|
+
...params.base,
|
|
181
|
+
CANARY_ENABLED: params.base.CANARY_ENABLED ?? "1",
|
|
182
|
+
CANARY_RUNNER: "canary",
|
|
183
|
+
CANARY_EVENT_LOG: params.eventLogPath,
|
|
184
|
+
...params.nodeOptions ? { NODE_OPTIONS: params.nodeOptions } : {},
|
|
185
|
+
...healing.apiKey ? { AI_API_KEY: healing.apiKey } : {},
|
|
186
|
+
...healing.provider ? { AI_PROVIDER: healing.provider } : {},
|
|
187
|
+
...healing.model ? { AI_MODEL: healing.model } : {},
|
|
188
|
+
...healing.timeoutMs ? { AI_TIMEOUT_MS: String(healing.timeoutMs) } : {},
|
|
189
|
+
...healing.maxActions ? { CANARY_MAX_ACTIONS: String(healing.maxActions) } : {},
|
|
190
|
+
...healing.vision ? { CANARY_VISION: "1" } : {},
|
|
191
|
+
...healing.dryRun ? { CANARY_DRY_RUN: "1" } : {},
|
|
192
|
+
...healing.warnOnly ? { CANARY_WARN_ONLY: "1" } : {},
|
|
193
|
+
...healing.debug ? { CANARY_DEBUG: "1" } : {},
|
|
194
|
+
...healing.readOnly ? { CANARY_READ_ONLY: "1" } : {},
|
|
195
|
+
...healing.allowEvaluate === false ? { CANARY_ALLOW_EVALUATE: "0" } : {},
|
|
196
|
+
...healing.allowRunCode ? { CANARY_ALLOW_RUN_CODE: "1" } : {},
|
|
197
|
+
...healing.maxPayloadBytes ? { CANARY_MAX_PAYLOAD_BYTES: String(healing.maxPayloadBytes) } : {},
|
|
198
|
+
...params.overrides
|
|
199
|
+
};
|
|
200
|
+
return env;
|
|
201
|
+
}
|
|
202
|
+
async function spawnPlaywright(opts) {
|
|
203
|
+
return new Promise((resolve) => {
|
|
204
|
+
const started = Date.now();
|
|
205
|
+
const child = spawn(opts.bin, opts.args, {
|
|
206
|
+
cwd: opts.cwd,
|
|
207
|
+
env: opts.env,
|
|
208
|
+
stdio: opts.stdio === "inherit" ? "inherit" : ["ignore", "pipe", "pipe"]
|
|
209
|
+
});
|
|
210
|
+
let timer;
|
|
211
|
+
let output = "";
|
|
212
|
+
let error;
|
|
213
|
+
if (opts.stdio === "pipe") {
|
|
214
|
+
child.stdout?.on("data", (chunk) => {
|
|
215
|
+
output += chunk.toString();
|
|
216
|
+
});
|
|
217
|
+
child.stderr?.on("data", (chunk) => {
|
|
218
|
+
output += chunk.toString();
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (opts.timeoutMs && opts.timeoutMs > 0) {
|
|
222
|
+
timer = setTimeout(() => {
|
|
223
|
+
error = new Error(`canary.run timed out after ${opts.timeoutMs}ms`);
|
|
224
|
+
child.kill("SIGKILL");
|
|
225
|
+
}, opts.timeoutMs);
|
|
226
|
+
}
|
|
227
|
+
child.on("close", (code) => {
|
|
228
|
+
if (timer) clearTimeout(timer);
|
|
229
|
+
resolve({ exitCode: code ?? 1, output: output || void 0, durationMs: Date.now() - started, error });
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function summarize(jsonReportPath, eventLogPath, durationMs) {
|
|
234
|
+
const base = {
|
|
235
|
+
total: 0,
|
|
236
|
+
passed: 0,
|
|
237
|
+
failed: 0,
|
|
238
|
+
flaky: 0,
|
|
239
|
+
skipped: 0,
|
|
240
|
+
durationMs
|
|
241
|
+
};
|
|
242
|
+
const jsonReport = readJsonReport(jsonReportPath);
|
|
243
|
+
if (jsonReport) {
|
|
244
|
+
const counts = countTests(jsonReport);
|
|
245
|
+
base.total = counts.total;
|
|
246
|
+
base.passed = counts.passed;
|
|
247
|
+
base.failed = counts.failed;
|
|
248
|
+
base.flaky = counts.flaky;
|
|
249
|
+
base.skipped = counts.skipped;
|
|
250
|
+
base.durationMs = jsonReport.duration ?? durationMs;
|
|
251
|
+
}
|
|
252
|
+
const healed = countHealed(eventLogPath);
|
|
253
|
+
if (healed) {
|
|
254
|
+
return { ...base, healed };
|
|
255
|
+
}
|
|
256
|
+
return base;
|
|
257
|
+
}
|
|
258
|
+
function readJsonReport(reportPath) {
|
|
259
|
+
try {
|
|
260
|
+
if (fs2.existsSync(reportPath)) {
|
|
261
|
+
const raw = fs2.readFileSync(reportPath, "utf-8");
|
|
262
|
+
return JSON.parse(raw);
|
|
263
|
+
}
|
|
264
|
+
} catch {
|
|
265
|
+
}
|
|
266
|
+
return void 0;
|
|
267
|
+
}
|
|
268
|
+
function countTests(report) {
|
|
269
|
+
let total = 0;
|
|
270
|
+
let passed = 0;
|
|
271
|
+
let failed = 0;
|
|
272
|
+
let flaky = 0;
|
|
273
|
+
let skipped = 0;
|
|
274
|
+
const visitSuite = (suite) => {
|
|
275
|
+
if (!suite) return;
|
|
276
|
+
suite.tests?.forEach((test) => {
|
|
277
|
+
total += 1;
|
|
278
|
+
const statuses = test.results.map((r) => r.status);
|
|
279
|
+
const hasFailed = statuses.includes("failed") || statuses.includes("interrupted");
|
|
280
|
+
const hasPassed = statuses.includes("passed");
|
|
281
|
+
const hasTimedOut = statuses.includes("timedOut");
|
|
282
|
+
const allSkipped = statuses.every((s) => s === "skipped");
|
|
283
|
+
if (allSkipped) {
|
|
284
|
+
skipped += 1;
|
|
285
|
+
} else if ((hasFailed || hasTimedOut) && hasPassed) {
|
|
286
|
+
flaky += 1;
|
|
287
|
+
} else if (hasFailed || hasTimedOut) {
|
|
288
|
+
failed += 1;
|
|
289
|
+
} else if (hasPassed && statuses.length > 1) {
|
|
290
|
+
flaky += 1;
|
|
291
|
+
} else if (hasPassed) {
|
|
292
|
+
passed += 1;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
suite.suites?.forEach(visitSuite);
|
|
296
|
+
};
|
|
297
|
+
report.suites?.forEach(visitSuite);
|
|
298
|
+
return { total, passed, failed, flaky, skipped };
|
|
299
|
+
}
|
|
300
|
+
function countHealed(eventLogPath) {
|
|
301
|
+
try {
|
|
302
|
+
if (!fs2.existsSync(eventLogPath)) return void 0;
|
|
303
|
+
const raw = fs2.readFileSync(eventLogPath, "utf-8").trim();
|
|
304
|
+
if (!raw) return void 0;
|
|
305
|
+
const lines = raw.split("\n");
|
|
306
|
+
let healed = 0;
|
|
307
|
+
for (const line of lines) {
|
|
308
|
+
try {
|
|
309
|
+
const event = JSON.parse(line);
|
|
310
|
+
if (event?.healed === true) healed += 1;
|
|
311
|
+
} catch {
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return healed;
|
|
315
|
+
} catch {
|
|
316
|
+
return void 0;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/local-run.ts
|
|
321
|
+
import process2 from "process";
|
|
322
|
+
|
|
323
|
+
// src/auth.ts
|
|
324
|
+
import fs3 from "fs/promises";
|
|
325
|
+
import os2 from "os";
|
|
326
|
+
import path3 from "path";
|
|
327
|
+
async function readStoredToken() {
|
|
328
|
+
try {
|
|
329
|
+
const filePath = path3.join(os2.homedir(), ".config", "canary-cli", "auth.json");
|
|
330
|
+
const content = await fs3.readFile(filePath, "utf8");
|
|
331
|
+
const parsed = JSON.parse(content);
|
|
332
|
+
return typeof parsed.token === "string" ? parsed.token : null;
|
|
333
|
+
} catch {
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/local-run.ts
|
|
339
|
+
function getArgValue(argv, key) {
|
|
340
|
+
const index = argv.indexOf(key);
|
|
341
|
+
if (index === -1) return void 0;
|
|
342
|
+
return argv[index + 1];
|
|
343
|
+
}
|
|
344
|
+
async function runLocalTest(argv) {
|
|
345
|
+
const apiUrl = getArgValue(argv, "--api-url") ?? process2.env.CANARY_API_URL ?? "https://api.trycanary.ai";
|
|
346
|
+
const token = getArgValue(argv, "--token") ?? process2.env.CANARY_API_TOKEN ?? await readStoredToken();
|
|
347
|
+
const title = getArgValue(argv, "--title");
|
|
348
|
+
const featureSpec = getArgValue(argv, "--feature");
|
|
349
|
+
const startUrl = getArgValue(argv, "--start-url");
|
|
350
|
+
const tunnelUrl = getArgValue(argv, "--tunnel-url");
|
|
351
|
+
if (!tunnelUrl && !startUrl) {
|
|
352
|
+
console.error("Missing --tunnel-url or --start-url");
|
|
353
|
+
process2.exit(1);
|
|
354
|
+
}
|
|
355
|
+
if (!token) {
|
|
356
|
+
console.error("Missing token. Run `canary login` first or set CANARY_API_TOKEN.");
|
|
357
|
+
process2.exit(1);
|
|
358
|
+
}
|
|
359
|
+
const result = await createLocalRun({
|
|
360
|
+
apiUrl,
|
|
361
|
+
token,
|
|
362
|
+
title,
|
|
363
|
+
featureSpec,
|
|
364
|
+
startUrl,
|
|
365
|
+
tunnelUrl
|
|
366
|
+
});
|
|
367
|
+
console.log(`Local test queued: ${result.runId}`);
|
|
368
|
+
if (result.watchUrl) {
|
|
369
|
+
console.log(`Watch: ${result.watchUrl}`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
async function createLocalRun(input) {
|
|
373
|
+
const body = {
|
|
374
|
+
title: input.title ?? null,
|
|
375
|
+
featureSpec: input.featureSpec ?? null,
|
|
376
|
+
startUrl: input.startUrl ?? null,
|
|
377
|
+
tunnelPublicUrl: input.tunnelUrl ?? null
|
|
378
|
+
};
|
|
379
|
+
const response = await fetch(`${input.apiUrl}/local-tests/runs`, {
|
|
380
|
+
method: "POST",
|
|
381
|
+
headers: {
|
|
382
|
+
"content-type": "application/json",
|
|
383
|
+
authorization: `Bearer ${input.token}`
|
|
384
|
+
},
|
|
385
|
+
body: JSON.stringify(body)
|
|
386
|
+
});
|
|
387
|
+
const json = await response.json();
|
|
388
|
+
if (!response.ok || !json.ok || !json.runId) {
|
|
389
|
+
throw new Error(json.error ?? response.statusText);
|
|
390
|
+
}
|
|
391
|
+
return { runId: json.runId, watchUrl: json.watchUrl };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/tunnel.ts
|
|
395
|
+
import { createHash } from "crypto";
|
|
396
|
+
import os3 from "os";
|
|
397
|
+
import process3 from "process";
|
|
398
|
+
function getArgValue2(argv, key) {
|
|
399
|
+
const index = argv.indexOf(key);
|
|
400
|
+
if (index === -1) return void 0;
|
|
401
|
+
return argv[index + 1];
|
|
402
|
+
}
|
|
403
|
+
function toWebSocketUrl(apiUrl) {
|
|
404
|
+
const url = new URL(apiUrl);
|
|
405
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
406
|
+
return url.toString();
|
|
407
|
+
}
|
|
408
|
+
function createFingerprint() {
|
|
409
|
+
const raw = `${os3.hostname()}-${os3.userInfo().username}-${process3.version}`;
|
|
410
|
+
return createHash("sha256").update(raw).digest("hex").slice(0, 16);
|
|
411
|
+
}
|
|
412
|
+
async function runTunnel(argv) {
|
|
413
|
+
const apiUrl = getArgValue2(argv, "--api-url") ?? process3.env.CANARY_API_URL ?? "https://api.trycanary.ai";
|
|
414
|
+
const token = getArgValue2(argv, "--token") ?? process3.env.CANARY_API_TOKEN ?? await readStoredToken();
|
|
415
|
+
const portRaw = getArgValue2(argv, "--port") ?? process3.env.CANARY_LOCAL_PORT;
|
|
416
|
+
if (!portRaw) {
|
|
417
|
+
console.error("Missing --port");
|
|
418
|
+
process3.exit(1);
|
|
419
|
+
}
|
|
420
|
+
const port = Number(portRaw);
|
|
421
|
+
if (Number.isNaN(port) || port <= 0) {
|
|
422
|
+
console.error("Invalid --port value");
|
|
423
|
+
process3.exit(1);
|
|
424
|
+
}
|
|
425
|
+
if (!token) {
|
|
426
|
+
console.error("Missing token. Run `canary login` first or set CANARY_API_TOKEN.");
|
|
427
|
+
process3.exit(1);
|
|
428
|
+
}
|
|
429
|
+
const data = await createTunnel({
|
|
430
|
+
apiUrl,
|
|
431
|
+
token,
|
|
432
|
+
port
|
|
433
|
+
});
|
|
434
|
+
const ws = connectTunnel({
|
|
435
|
+
apiUrl,
|
|
436
|
+
tunnelId: data.tunnelId,
|
|
437
|
+
token: data.token,
|
|
438
|
+
port
|
|
439
|
+
});
|
|
440
|
+
ws.onopen = () => {
|
|
441
|
+
console.log(`Tunnel connected: ${data.publicUrl ?? data.tunnelId}`);
|
|
442
|
+
if (data.publicUrl) {
|
|
443
|
+
console.log(`Public URL: ${data.publicUrl}`);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
await new Promise(() => void 0);
|
|
447
|
+
}
|
|
448
|
+
async function createTunnel(input) {
|
|
449
|
+
const response = await fetch(`${input.apiUrl}/local-tests/tunnels`, {
|
|
450
|
+
method: "POST",
|
|
451
|
+
headers: {
|
|
452
|
+
"content-type": "application/json",
|
|
453
|
+
authorization: `Bearer ${input.token}`
|
|
454
|
+
},
|
|
455
|
+
body: JSON.stringify({
|
|
456
|
+
requestedPort: input.port,
|
|
457
|
+
clientFingerprint: createFingerprint()
|
|
458
|
+
})
|
|
459
|
+
});
|
|
460
|
+
const data = await response.json();
|
|
461
|
+
if (!response.ok || !data.ok || !data.tunnelId || !data.token) {
|
|
462
|
+
throw new Error(data.error ?? response.statusText);
|
|
463
|
+
}
|
|
464
|
+
return { tunnelId: data.tunnelId, publicUrl: data.publicUrl, token: data.token };
|
|
465
|
+
}
|
|
466
|
+
function connectTunnel(input) {
|
|
467
|
+
const wsUrl = toWebSocketUrl(
|
|
468
|
+
`${input.apiUrl}/local-tests/tunnels/${input.tunnelId}/connect?token=${input.token}`
|
|
469
|
+
);
|
|
470
|
+
const ws = new WebSocket(wsUrl);
|
|
471
|
+
ws.onopen = () => {
|
|
472
|
+
input.onReady?.();
|
|
473
|
+
};
|
|
474
|
+
ws.onerror = (event) => {
|
|
475
|
+
console.error("Tunnel error", event);
|
|
476
|
+
};
|
|
477
|
+
ws.onclose = () => {
|
|
478
|
+
console.log("Tunnel closed");
|
|
479
|
+
};
|
|
480
|
+
ws.onmessage = async (event) => {
|
|
481
|
+
try {
|
|
482
|
+
const raw = typeof event.data === "string" ? event.data : Buffer.from(event.data).toString();
|
|
483
|
+
const payload = JSON.parse(raw);
|
|
484
|
+
if (payload.type === "http_request") {
|
|
485
|
+
const request = payload;
|
|
486
|
+
const targetUrl = `http://localhost:${input.port}${request.path.startsWith("/") ? request.path : `/${request.path}`}`;
|
|
487
|
+
const body = request.bodyBase64 ? Buffer.from(request.bodyBase64, "base64") : void 0;
|
|
488
|
+
const headers = { ...request.headers };
|
|
489
|
+
delete headers.host;
|
|
490
|
+
delete headers["content-length"];
|
|
491
|
+
try {
|
|
492
|
+
const res = await fetch(targetUrl, {
|
|
493
|
+
method: request.method,
|
|
494
|
+
headers,
|
|
495
|
+
body: body ?? void 0
|
|
496
|
+
});
|
|
497
|
+
const resBody = await res.arrayBuffer();
|
|
498
|
+
const responsePayload = {
|
|
499
|
+
type: "http_response",
|
|
500
|
+
id: request.id,
|
|
501
|
+
status: res.status,
|
|
502
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
503
|
+
bodyBase64: resBody.byteLength ? Buffer.from(resBody).toString("base64") : null
|
|
504
|
+
};
|
|
505
|
+
ws.send(JSON.stringify(responsePayload));
|
|
506
|
+
} catch (error) {
|
|
507
|
+
const responsePayload = {
|
|
508
|
+
type: "http_response",
|
|
509
|
+
id: request.id,
|
|
510
|
+
status: 502,
|
|
511
|
+
headers: { "content-type": "text/plain" },
|
|
512
|
+
bodyBase64: Buffer.from(`Tunnel error: ${String(error)}`).toString("base64")
|
|
513
|
+
};
|
|
514
|
+
ws.send(JSON.stringify(responsePayload));
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (payload.type === "health_ping") {
|
|
518
|
+
ws.send(JSON.stringify({ type: "health_pong" }));
|
|
519
|
+
}
|
|
520
|
+
} catch (error) {
|
|
521
|
+
console.error("Tunnel message error", error);
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
return ws;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// src/login.ts
|
|
528
|
+
import fs4 from "fs/promises";
|
|
529
|
+
import os4 from "os";
|
|
530
|
+
import path4 from "path";
|
|
531
|
+
import process4 from "process";
|
|
532
|
+
import { spawn as spawn2 } from "child_process";
|
|
533
|
+
var DEFAULT_APP_URL = "https://app.trycanary.ai";
|
|
534
|
+
function getArgValue3(argv, key) {
|
|
535
|
+
const index = argv.indexOf(key);
|
|
536
|
+
if (index === -1) return void 0;
|
|
537
|
+
return argv[index + 1];
|
|
538
|
+
}
|
|
539
|
+
function shouldOpenBrowser(argv) {
|
|
540
|
+
return !argv.includes("--no-open");
|
|
541
|
+
}
|
|
542
|
+
function openUrl(url) {
|
|
543
|
+
const platform = process4.platform;
|
|
544
|
+
if (platform === "darwin") {
|
|
545
|
+
spawn2("open", [url], { stdio: "ignore" });
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (platform === "win32") {
|
|
549
|
+
spawn2("cmd", ["/c", "start", "", url], { stdio: "ignore" });
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
spawn2("xdg-open", [url], { stdio: "ignore" });
|
|
553
|
+
}
|
|
554
|
+
async function writeToken(token) {
|
|
555
|
+
const dir = path4.join(os4.homedir(), ".config", "canary-cli");
|
|
556
|
+
const filePath = path4.join(dir, "auth.json");
|
|
557
|
+
await fs4.mkdir(dir, { recursive: true });
|
|
558
|
+
await fs4.writeFile(filePath, JSON.stringify({ token }, null, 2), "utf8");
|
|
559
|
+
return filePath;
|
|
560
|
+
}
|
|
561
|
+
async function runLogin(argv) {
|
|
562
|
+
const apiUrl = getArgValue3(argv, "--api-url") ?? process4.env.CANARY_API_URL ?? "https://api.trycanary.ai";
|
|
563
|
+
const appUrl = getArgValue3(argv, "--app-url") ?? process4.env.CANARY_APP_URL ?? DEFAULT_APP_URL;
|
|
564
|
+
const startRes = await fetch(`${apiUrl}/cli-login/start`, {
|
|
565
|
+
method: "POST",
|
|
566
|
+
headers: { "content-type": "application/json" },
|
|
567
|
+
body: JSON.stringify({ appUrl })
|
|
568
|
+
});
|
|
569
|
+
const startJson = await startRes.json();
|
|
570
|
+
if (!startRes.ok || !startJson.ok || !startJson.deviceCode || !startJson.userCode) {
|
|
571
|
+
console.error("Login start failed", startJson.error ?? startRes.statusText);
|
|
572
|
+
process4.exit(1);
|
|
573
|
+
}
|
|
574
|
+
console.log("Login required.");
|
|
575
|
+
console.log(`User code: ${startJson.userCode}`);
|
|
576
|
+
if (startJson.verificationUrl) {
|
|
577
|
+
console.log(`Open: ${startJson.verificationUrl}`);
|
|
578
|
+
if (shouldOpenBrowser(argv)) {
|
|
579
|
+
try {
|
|
580
|
+
openUrl(startJson.verificationUrl);
|
|
581
|
+
} catch {
|
|
582
|
+
console.log("Unable to open browser automatically. Please open the URL manually.");
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
const intervalMs = (startJson.intervalSeconds ?? 3) * 1e3;
|
|
587
|
+
const expiresAt = startJson.expiresAt ? new Date(startJson.expiresAt).getTime() : null;
|
|
588
|
+
while (true) {
|
|
589
|
+
if (expiresAt && Date.now() > expiresAt) {
|
|
590
|
+
console.error("Login code expired.");
|
|
591
|
+
process4.exit(1);
|
|
592
|
+
}
|
|
593
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
594
|
+
const pollRes = await fetch(`${apiUrl}/cli-login/poll`, {
|
|
595
|
+
method: "POST",
|
|
596
|
+
headers: { "content-type": "application/json" },
|
|
597
|
+
body: JSON.stringify({ deviceCode: startJson.deviceCode })
|
|
598
|
+
});
|
|
599
|
+
const pollJson = await pollRes.json();
|
|
600
|
+
if (!pollRes.ok || !pollJson.ok) {
|
|
601
|
+
console.error("Login poll failed", pollJson.error ?? pollRes.statusText);
|
|
602
|
+
process4.exit(1);
|
|
603
|
+
}
|
|
604
|
+
if (pollJson.status === "approved" && pollJson.accessToken) {
|
|
605
|
+
const filePath = await writeToken(pollJson.accessToken);
|
|
606
|
+
console.log(`Login successful. Token saved to ${filePath}`);
|
|
607
|
+
console.log("Set CANARY_API_TOKEN to use the CLI without re-login.");
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (pollJson.status === "rejected") {
|
|
611
|
+
console.error("Login rejected.");
|
|
612
|
+
process4.exit(1);
|
|
613
|
+
}
|
|
614
|
+
if (pollJson.status === "expired") {
|
|
615
|
+
console.error("Login expired.");
|
|
616
|
+
process4.exit(1);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// src/run-local.ts
|
|
622
|
+
import process5 from "process";
|
|
623
|
+
function getArgValue4(argv, key) {
|
|
624
|
+
const index = argv.indexOf(key);
|
|
625
|
+
if (index === -1) return void 0;
|
|
626
|
+
return argv[index + 1];
|
|
627
|
+
}
|
|
628
|
+
async function runLocalSession(argv) {
|
|
629
|
+
const apiUrl = getArgValue4(argv, "--api-url") ?? process5.env.CANARY_API_URL ?? "https://api.trycanary.ai";
|
|
630
|
+
const token = getArgValue4(argv, "--token") ?? process5.env.CANARY_API_TOKEN ?? await readStoredToken();
|
|
631
|
+
if (!token) {
|
|
632
|
+
console.error("Missing token. Run `canary login` first or set CANARY_API_TOKEN.");
|
|
633
|
+
process5.exit(1);
|
|
634
|
+
}
|
|
635
|
+
const portRaw = getArgValue4(argv, "--port") ?? process5.env.CANARY_LOCAL_PORT;
|
|
636
|
+
const tunnelUrl = getArgValue4(argv, "--tunnel-url");
|
|
637
|
+
const title = getArgValue4(argv, "--title");
|
|
638
|
+
const featureSpec = getArgValue4(argv, "--feature");
|
|
639
|
+
const startUrl = getArgValue4(argv, "--start-url");
|
|
640
|
+
if (!tunnelUrl && !portRaw) {
|
|
641
|
+
console.error("Missing --port or --tunnel-url");
|
|
642
|
+
process5.exit(1);
|
|
643
|
+
}
|
|
644
|
+
let publicUrl = tunnelUrl;
|
|
645
|
+
let ws = null;
|
|
646
|
+
if (!publicUrl && portRaw) {
|
|
647
|
+
const port = Number(portRaw);
|
|
648
|
+
if (Number.isNaN(port) || port <= 0) {
|
|
649
|
+
console.error("Invalid --port value");
|
|
650
|
+
process5.exit(1);
|
|
651
|
+
}
|
|
652
|
+
const tunnel = await createTunnel({ apiUrl, token, port });
|
|
653
|
+
publicUrl = tunnel.publicUrl;
|
|
654
|
+
ws = connectTunnel({
|
|
655
|
+
apiUrl,
|
|
656
|
+
tunnelId: tunnel.tunnelId,
|
|
657
|
+
token: tunnel.token,
|
|
658
|
+
port,
|
|
659
|
+
onReady: () => {
|
|
660
|
+
console.log(`Tunnel connected: ${publicUrl ?? tunnel.tunnelId}`);
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
if (!publicUrl) {
|
|
665
|
+
console.error("Failed to resolve tunnel URL");
|
|
666
|
+
process5.exit(1);
|
|
667
|
+
}
|
|
668
|
+
const run2 = await createLocalRun({
|
|
669
|
+
apiUrl,
|
|
670
|
+
token,
|
|
671
|
+
title,
|
|
672
|
+
featureSpec,
|
|
673
|
+
startUrl,
|
|
674
|
+
tunnelUrl: publicUrl
|
|
675
|
+
});
|
|
676
|
+
console.log(`Local test queued: ${run2.runId}`);
|
|
677
|
+
if (run2.watchUrl) {
|
|
678
|
+
console.log(`Watch: ${run2.watchUrl}`);
|
|
679
|
+
}
|
|
680
|
+
if (ws) {
|
|
681
|
+
console.log("Tunnel active. Press Ctrl+C to stop.");
|
|
682
|
+
process5.on("SIGINT", () => {
|
|
683
|
+
ws?.close();
|
|
684
|
+
process5.exit(0);
|
|
685
|
+
});
|
|
686
|
+
await new Promise(() => void 0);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// src/mcp.ts
|
|
691
|
+
import process6 from "process";
|
|
692
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
693
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
694
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
695
|
+
import { createParser } from "eventsource-parser";
|
|
696
|
+
var DEFAULT_API_URL = "https://api.trycanary.ai";
|
|
697
|
+
function resolveApiUrl(input) {
|
|
698
|
+
return input ?? process6.env.CANARY_API_URL ?? DEFAULT_API_URL;
|
|
699
|
+
}
|
|
700
|
+
async function resolveToken() {
|
|
701
|
+
const token = process6.env.CANARY_API_TOKEN ?? await readStoredToken();
|
|
702
|
+
if (!token) {
|
|
703
|
+
throw new Error("Missing token. Run `canary login` first or set CANARY_API_TOKEN.");
|
|
704
|
+
}
|
|
705
|
+
return token;
|
|
706
|
+
}
|
|
707
|
+
function toolText(text) {
|
|
708
|
+
return { content: [{ type: "text", text }] };
|
|
709
|
+
}
|
|
710
|
+
function toolJson(data) {
|
|
711
|
+
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
712
|
+
}
|
|
713
|
+
async function runMcp(argv) {
|
|
714
|
+
const server = new Server(
|
|
715
|
+
{ name: "canary-cli", version: "0.1.0" },
|
|
716
|
+
{ capabilities: { tools: {} } }
|
|
717
|
+
);
|
|
718
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
719
|
+
tools: [
|
|
720
|
+
{
|
|
721
|
+
name: "local_run_tests",
|
|
722
|
+
description: "Start an async local test run. A tunnel is opened automatically. Returns runId and watchUrl.",
|
|
723
|
+
inputSchema: {
|
|
724
|
+
type: "object",
|
|
725
|
+
properties: {
|
|
726
|
+
port: { type: "number" },
|
|
727
|
+
instructions: { type: "string" },
|
|
728
|
+
title: { type: "string" }
|
|
729
|
+
},
|
|
730
|
+
required: ["port", "instructions"]
|
|
731
|
+
}
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
name: "local_wait_for_results",
|
|
735
|
+
description: "Wait for a local test run to complete. Streams until completion and returns a compact report.",
|
|
736
|
+
inputSchema: {
|
|
737
|
+
type: "object",
|
|
738
|
+
properties: {
|
|
739
|
+
runId: { type: "string" }
|
|
740
|
+
},
|
|
741
|
+
required: ["runId"]
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
]
|
|
745
|
+
}));
|
|
746
|
+
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
747
|
+
const token = await resolveToken();
|
|
748
|
+
const tool = req.params.name;
|
|
749
|
+
if (tool === "local_run_tests") {
|
|
750
|
+
const input = req.params.arguments;
|
|
751
|
+
const apiUrl = resolveApiUrl();
|
|
752
|
+
const tunnel = await createTunnel({ apiUrl, token, port: input.port });
|
|
753
|
+
connectTunnel({
|
|
754
|
+
apiUrl,
|
|
755
|
+
tunnelId: tunnel.tunnelId,
|
|
756
|
+
token: tunnel.token,
|
|
757
|
+
port: input.port
|
|
758
|
+
});
|
|
759
|
+
const tunnelUrl = tunnel.publicUrl;
|
|
760
|
+
const run2 = await createLocalRun({
|
|
761
|
+
apiUrl,
|
|
762
|
+
token,
|
|
763
|
+
title: input.title ?? "Local MCP run",
|
|
764
|
+
featureSpec: input.instructions,
|
|
765
|
+
startUrl: null,
|
|
766
|
+
tunnelUrl
|
|
767
|
+
});
|
|
768
|
+
return toolJson({
|
|
769
|
+
runId: run2.runId,
|
|
770
|
+
watchUrl: run2.watchUrl,
|
|
771
|
+
tunnelUrl,
|
|
772
|
+
note: "Testing is asynchronous. Use local_wait_for_results with the runId to wait for completion."
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
if (tool === "local_wait_for_results") {
|
|
776
|
+
const input = req.params.arguments;
|
|
777
|
+
const apiUrl = resolveApiUrl();
|
|
778
|
+
const report = await waitForResult({ apiUrl, token, runId: input.runId });
|
|
779
|
+
return toolJson(report);
|
|
780
|
+
}
|
|
781
|
+
return toolText(`Unknown tool: ${tool}`);
|
|
782
|
+
});
|
|
783
|
+
const transport = new StdioServerTransport();
|
|
784
|
+
await server.connect(transport);
|
|
785
|
+
return new Promise(() => void 0);
|
|
786
|
+
}
|
|
787
|
+
async function waitForResult(input) {
|
|
788
|
+
await streamUntilComplete(input);
|
|
789
|
+
const response = await fetch(`${input.apiUrl}/local-tests/runs/${input.runId}`, {
|
|
790
|
+
credentials: "include",
|
|
791
|
+
headers: { authorization: `Bearer ${input.token}` }
|
|
792
|
+
});
|
|
793
|
+
const data = await response.json();
|
|
794
|
+
const run2 = data?.data?.run ?? data?.run ?? data?.data;
|
|
795
|
+
const summary = run2?.summaryJson;
|
|
796
|
+
return formatReport({ run: run2, summary });
|
|
797
|
+
}
|
|
798
|
+
async function streamUntilComplete(input) {
|
|
799
|
+
const response = await fetch(`${input.apiUrl}/local-tests/runs/${input.runId}/stream`, {
|
|
800
|
+
headers: { authorization: `Bearer ${input.token}` }
|
|
801
|
+
});
|
|
802
|
+
if (!response.body) return;
|
|
803
|
+
const reader = response.body.getReader();
|
|
804
|
+
const decoder = new TextDecoder();
|
|
805
|
+
const parser = createParser((event) => {
|
|
806
|
+
if (event.type !== "event") return;
|
|
807
|
+
if (event.event === "status") {
|
|
808
|
+
try {
|
|
809
|
+
const payload = JSON.parse(event.data);
|
|
810
|
+
if (payload?.status === "completed" || payload?.status === "failed") {
|
|
811
|
+
reader.cancel().catch(() => void 0);
|
|
812
|
+
}
|
|
813
|
+
} catch {
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (event.event === "complete" || event.event === "error") {
|
|
817
|
+
reader.cancel().catch(() => void 0);
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
while (true) {
|
|
821
|
+
const { done, value } = await reader.read();
|
|
822
|
+
if (done) break;
|
|
823
|
+
parser.feed(decoder.decode(value, { stream: true }));
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
function formatReport(input) {
|
|
827
|
+
if (!input.summary) {
|
|
828
|
+
return {
|
|
829
|
+
runId: input.run?.id,
|
|
830
|
+
status: input.run?.status ?? "unknown",
|
|
831
|
+
summary: "No final report available."
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
const tested = Array.isArray(input.summary.testedItems) ? input.summary.testedItems : [];
|
|
835
|
+
const status = input.summary.status ?? input.run?.status ?? "unknown";
|
|
836
|
+
const issues = status === "issues_found" ? input.summary.notes ? [input.summary.notes] : ["Issues reported."] : [];
|
|
837
|
+
return {
|
|
838
|
+
runId: input.run?.id,
|
|
839
|
+
status,
|
|
840
|
+
summary: input.summary.summary ?? "Run completed.",
|
|
841
|
+
testedItems: tested,
|
|
842
|
+
issues,
|
|
843
|
+
notes: input.summary.notes ?? null
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// src/index.ts
|
|
848
|
+
var canary = { run };
|
|
849
|
+
var baseDir = typeof __dirname !== "undefined" ? __dirname : path5.dirname(fileURLToPath2(import.meta.url));
|
|
850
|
+
var preloadPath = path5.join(baseDir, "runner", "preload.js");
|
|
851
|
+
var requireFn = makeRequire();
|
|
852
|
+
function runPlaywrightTests(args) {
|
|
853
|
+
const playwrightCli = requireFn.resolve("@playwright/test/cli");
|
|
854
|
+
const { runnerBin, preloadFlag } = resolveRunner(preloadPath);
|
|
855
|
+
const nodeOptions = process7.env.NODE_OPTIONS && preloadFlag ? `${process7.env.NODE_OPTIONS} ${preloadFlag}` : preloadFlag ?? process7.env.NODE_OPTIONS;
|
|
856
|
+
const env = {
|
|
857
|
+
...process7.env,
|
|
858
|
+
CANARY_ENABLED: process7.env.CANARY_ENABLED ?? "1",
|
|
859
|
+
CANARY_RUNNER: "canary",
|
|
860
|
+
...nodeOptions ? { NODE_OPTIONS: nodeOptions } : {}
|
|
861
|
+
};
|
|
862
|
+
const result = spawnSync2(runnerBin, [playwrightCli, "test", ...args], {
|
|
863
|
+
env,
|
|
864
|
+
stdio: "inherit",
|
|
865
|
+
cwd: process7.cwd()
|
|
866
|
+
});
|
|
867
|
+
if (result.error) {
|
|
868
|
+
console.error("canary failed to launch Playwright:", result.error);
|
|
869
|
+
process7.exit(1);
|
|
870
|
+
}
|
|
871
|
+
process7.exit(result.status ?? 1);
|
|
872
|
+
}
|
|
873
|
+
async function main(argv) {
|
|
874
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
875
|
+
console.log(
|
|
876
|
+
"canary: Playwright AI healer runner (scaffold).\nUsage: canary test [playwright options]\n canary local-run --tunnel-url <url> [options]\n canary tunnel --port <localPort> [options]\n canary run --port <localPort> [options]\n canary mcp\n canary login [--app-url https://app.trycanary.ai] [--api-url http://localhost:3000] [--no-open]\nPlan: see ai-healer-runner-plan.md"
|
|
877
|
+
);
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
const [command, ...rest] = argv;
|
|
881
|
+
if (!command || command === "test") {
|
|
882
|
+
runPlaywrightTests(rest);
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
if (command === "local-run") {
|
|
886
|
+
await runLocalTest(rest);
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
if (command === "run") {
|
|
890
|
+
await runLocalSession(rest);
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
if (command === "mcp") {
|
|
894
|
+
await runMcp(rest);
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
if (command === "tunnel") {
|
|
898
|
+
await runTunnel(rest);
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
if (command === "login") {
|
|
902
|
+
await runLogin(rest);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
console.log(`Unknown command "${command}". Try "canary test" or "--help".`);
|
|
906
|
+
process7.exit(1);
|
|
907
|
+
}
|
|
908
|
+
if (import.meta.url === pathToFileURL2(process7.argv[1]).href) {
|
|
909
|
+
void main(process7.argv.slice(2));
|
|
910
|
+
}
|
|
911
|
+
export {
|
|
912
|
+
canary,
|
|
913
|
+
main,
|
|
914
|
+
run
|
|
915
|
+
};
|
|
916
|
+
//# sourceMappingURL=index.js.map
|