@canaryai/cli 0.1.6 → 0.1.11
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 +52 -1
- package/dist/bin.js +1 -6
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-7OCVIDC7.js → chunk-DGUM43GV.js} +1 -2
- package/dist/{chunk-55MFLJD7.js → chunk-G2X3H7AM.js} +1 -3
- package/dist/{chunk-55MFLJD7.js.map → chunk-G2X3H7AM.js.map} +1 -1
- package/dist/chunk-HJ2JWIJ7.js +91 -0
- package/dist/chunk-HJ2JWIJ7.js.map +1 -0
- package/dist/{chunk-7AP5KRVU.js → chunk-ROTCL5WO.js} +1 -3
- package/dist/{chunk-7AP5KRVU.js.map → chunk-ROTCL5WO.js.map} +1 -1
- package/dist/{chunk-Z6I3ZXZL.js → chunk-VYBCH4ZP.js} +2 -3
- package/dist/{chunk-Z6I3ZXZL.js.map → chunk-VYBCH4ZP.js.map} +1 -1
- package/dist/feature-flag-PN5IFFQR.js +226 -0
- package/dist/feature-flag-PN5IFFQR.js.map +1 -0
- package/dist/index.js +1207 -8
- package/dist/index.js.map +1 -1
- package/dist/knobs-DAG7HD2F.js +286 -0
- package/dist/knobs-DAG7HD2F.js.map +1 -0
- package/dist/{local-browser-5LJ7UPOH.js → local-browser-VOBIUIGT.js} +4 -5
- package/dist/{local-browser-5LJ7UPOH.js.map → local-browser-VOBIUIGT.js.map} +1 -1
- package/dist/{mcp-P2B24MTM.js → mcp-I6FCGDDR.js} +5 -6
- package/dist/{mcp-P2B24MTM.js.map → mcp-I6FCGDDR.js.map} +1 -1
- package/dist/psql-A3BADRQN.js +124 -0
- package/dist/psql-A3BADRQN.js.map +1 -0
- package/dist/redis-N2DSDDQU.js +130 -0
- package/dist/redis-N2DSDDQU.js.map +1 -0
- package/dist/runner/preload.js +2 -3
- package/dist/runner/preload.js.map +1 -1
- package/dist/test.js +2 -3
- package/dist/test.js.map +1 -1
- package/package.json +3 -4
- package/dist/bin.d.ts +0 -2
- package/dist/chunk-UBYYNMML.js +0 -21
- package/dist/chunk-UBYYNMML.js.map +0 -1
- package/dist/chunk-YA43CE6P.js +0 -781
- package/dist/chunk-YA43CE6P.js.map +0 -1
- /package/dist/{chunk-7OCVIDC7.js.map → chunk-DGUM43GV.js.map} +0 -0
package/dist/chunk-YA43CE6P.js
DELETED
|
@@ -1,781 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
connectTunnel,
|
|
4
|
-
createLocalRun,
|
|
5
|
-
createTunnel,
|
|
6
|
-
runLocalTest,
|
|
7
|
-
runTunnel
|
|
8
|
-
} from "./chunk-Z6I3ZXZL.js";
|
|
9
|
-
import {
|
|
10
|
-
readStoredToken
|
|
11
|
-
} from "./chunk-UBYYNMML.js";
|
|
12
|
-
import {
|
|
13
|
-
__require
|
|
14
|
-
} from "./chunk-7OCVIDC7.js";
|
|
15
|
-
|
|
16
|
-
// src/index.ts
|
|
17
|
-
import { spawnSync as spawnSync2 } from "child_process";
|
|
18
|
-
import process5 from "process";
|
|
19
|
-
import path4 from "path";
|
|
20
|
-
import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "url";
|
|
21
|
-
|
|
22
|
-
// src/runner/common.ts
|
|
23
|
-
import { spawnSync } from "child_process";
|
|
24
|
-
import fs from "fs";
|
|
25
|
-
import path from "path";
|
|
26
|
-
import { createRequire } from "module";
|
|
27
|
-
import { pathToFileURL } from "url";
|
|
28
|
-
function makeRequire() {
|
|
29
|
-
try {
|
|
30
|
-
return createRequire(import.meta.url);
|
|
31
|
-
} catch {
|
|
32
|
-
try {
|
|
33
|
-
return createRequire(process.cwd());
|
|
34
|
-
} catch {
|
|
35
|
-
return typeof __require !== "undefined" ? __require : createRequire(".");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function resolveRunner(preloadPath2) {
|
|
40
|
-
const { bin, version } = pickNodeBinary();
|
|
41
|
-
const supportsImport = typeof version === "number" && version >= 18;
|
|
42
|
-
if (supportsImport && preloadPath2 && fs.existsSync(preloadPath2)) {
|
|
43
|
-
return { runnerBin: bin, preloadFlag: `--import=${pathToFileURL(preloadPath2).href}` };
|
|
44
|
-
}
|
|
45
|
-
if (preloadPath2) {
|
|
46
|
-
console.warn("[canary] Warning: no preload module found; instrumentation may be disabled.");
|
|
47
|
-
}
|
|
48
|
-
return { runnerBin: bin };
|
|
49
|
-
}
|
|
50
|
-
function pickNodeBinary() {
|
|
51
|
-
const candidates = collectNodeCandidates();
|
|
52
|
-
let best;
|
|
53
|
-
let fallback;
|
|
54
|
-
for (const bin of candidates) {
|
|
55
|
-
const version = getNodeMajor(bin);
|
|
56
|
-
if (!version) continue;
|
|
57
|
-
const current = { bin, version };
|
|
58
|
-
if (version >= 18 && !fallback) {
|
|
59
|
-
fallback = current;
|
|
60
|
-
}
|
|
61
|
-
if (!best || version > (best.version ?? 0)) {
|
|
62
|
-
best = current;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (fallback) return fallback;
|
|
66
|
-
if (best) return best;
|
|
67
|
-
return { bin: candidates[0] ?? "node" };
|
|
68
|
-
}
|
|
69
|
-
function collectNodeCandidates() {
|
|
70
|
-
const seen = /* @__PURE__ */ new Set();
|
|
71
|
-
const push = (value) => {
|
|
72
|
-
if (!value) return;
|
|
73
|
-
if (seen.has(value)) return;
|
|
74
|
-
seen.add(value);
|
|
75
|
-
};
|
|
76
|
-
const isBun = path.basename(process.execPath).includes("bun");
|
|
77
|
-
push(process.env.CANARY_NODE_BIN);
|
|
78
|
-
push(isBun ? void 0 : process.execPath);
|
|
79
|
-
push("node");
|
|
80
|
-
try {
|
|
81
|
-
const which = spawnSync("which", ["-a", "node"], { encoding: "utf-8" });
|
|
82
|
-
which.stdout?.toString().split("\n").map((line) => line.trim()).forEach((line) => push(line));
|
|
83
|
-
} catch {
|
|
84
|
-
}
|
|
85
|
-
const nvmDir = process.env.NVM_DIR || (process.env.HOME ? path.join(process.env.HOME, ".nvm") : void 0);
|
|
86
|
-
if (nvmDir) {
|
|
87
|
-
const versionsDir = path.join(nvmDir, "versions", "node");
|
|
88
|
-
if (fs.existsSync(versionsDir)) {
|
|
89
|
-
try {
|
|
90
|
-
const versions = fs.readdirSync(versionsDir);
|
|
91
|
-
versions.sort((a, b) => a > b ? -1 : 1).forEach((v) => push(path.join(versionsDir, v, "bin", "node")));
|
|
92
|
-
} catch {
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return Array.from(seen);
|
|
97
|
-
}
|
|
98
|
-
function getNodeMajor(bin) {
|
|
99
|
-
try {
|
|
100
|
-
const result = spawnSync(bin, ["-v"], { encoding: "utf-8" });
|
|
101
|
-
const output = (result.stdout || result.stderr || "").toString().trim();
|
|
102
|
-
const match = output.match(/^v(\d+)/);
|
|
103
|
-
if (match) return Number(match[1]);
|
|
104
|
-
} catch {
|
|
105
|
-
}
|
|
106
|
-
return void 0;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// src/run.ts
|
|
110
|
-
import { spawn } from "child_process";
|
|
111
|
-
import fs2 from "fs";
|
|
112
|
-
import os from "os";
|
|
113
|
-
import path2 from "path";
|
|
114
|
-
import { fileURLToPath } from "url";
|
|
115
|
-
async function run(request = {}) {
|
|
116
|
-
const cwd = request.projectRoot ?? process.cwd();
|
|
117
|
-
const stdio = request.stdio ?? "inherit";
|
|
118
|
-
const requireFn2 = makeRequire();
|
|
119
|
-
const playwrightCli = requireFn2.resolve("@playwright/test/cli");
|
|
120
|
-
const baseDir2 = path2.dirname(fileURLToPath(import.meta.url));
|
|
121
|
-
const preloadPath2 = path2.join(baseDir2, "runner", "preload.js");
|
|
122
|
-
const { runnerBin, preloadFlag } = resolveRunner(preloadPath2);
|
|
123
|
-
const { jsonReportPath, eventLogPath, artifactsDir } = prepareArtifactsDir(cwd);
|
|
124
|
-
const reporter = buildReporterArgs(request.reporter, jsonReportPath);
|
|
125
|
-
const args = buildArgs({
|
|
126
|
-
testDir: request.testDir,
|
|
127
|
-
configFile: request.configFile,
|
|
128
|
-
cliArgs: request.cliArgs,
|
|
129
|
-
reporter
|
|
130
|
-
});
|
|
131
|
-
const nodeOptions = process.env.NODE_OPTIONS && preloadFlag ? `${process.env.NODE_OPTIONS} ${preloadFlag}` : preloadFlag ?? process.env.NODE_OPTIONS;
|
|
132
|
-
const env = buildEnv({
|
|
133
|
-
base: process.env,
|
|
134
|
-
overrides: request.env,
|
|
135
|
-
healing: request.healing,
|
|
136
|
-
eventLogPath,
|
|
137
|
-
nodeOptions
|
|
138
|
-
});
|
|
139
|
-
const runResult = await spawnPlaywright({
|
|
140
|
-
bin: request.nodeBin ?? runnerBin,
|
|
141
|
-
args: [playwrightCli, ...args],
|
|
142
|
-
cwd,
|
|
143
|
-
env,
|
|
144
|
-
stdio,
|
|
145
|
-
timeoutMs: request.timeoutMs
|
|
146
|
-
});
|
|
147
|
-
const summary = summarize(jsonReportPath, eventLogPath, runResult.durationMs);
|
|
148
|
-
return {
|
|
149
|
-
ok: runResult.exitCode === 0,
|
|
150
|
-
exitCode: runResult.exitCode,
|
|
151
|
-
summary,
|
|
152
|
-
artifactsDir,
|
|
153
|
-
rawOutput: runResult.output,
|
|
154
|
-
error: runResult.error
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
function buildArgs(opts) {
|
|
158
|
-
const args = ["test"];
|
|
159
|
-
if (opts.testDir) {
|
|
160
|
-
const dirs = Array.isArray(opts.testDir) ? opts.testDir : [opts.testDir];
|
|
161
|
-
args.push(...dirs);
|
|
162
|
-
}
|
|
163
|
-
if (opts.configFile) {
|
|
164
|
-
args.push("--config", opts.configFile);
|
|
165
|
-
}
|
|
166
|
-
args.push("--reporter", opts.reporter);
|
|
167
|
-
if (opts.cliArgs?.length) {
|
|
168
|
-
args.push(...opts.cliArgs);
|
|
169
|
-
}
|
|
170
|
-
return args;
|
|
171
|
-
}
|
|
172
|
-
function buildReporterArgs(requested, jsonReportPath) {
|
|
173
|
-
if (requested === "json") return `json=${jsonReportPath}`;
|
|
174
|
-
if (requested && requested !== "default") return requested;
|
|
175
|
-
return `list,json=${jsonReportPath}`;
|
|
176
|
-
}
|
|
177
|
-
function prepareArtifactsDir(cwd) {
|
|
178
|
-
const dir = fs2.mkdtempSync(path2.join(os.tmpdir(), "canary-run-"));
|
|
179
|
-
const jsonReportPath = path2.join(dir, "report.json");
|
|
180
|
-
const eventLogPath = path2.join(dir, "events-worker-0.jsonl");
|
|
181
|
-
const artifactsDir = path2.join(cwd, "test-results", "ai-healer");
|
|
182
|
-
return { jsonReportPath, eventLogPath, artifactsDir: dir };
|
|
183
|
-
}
|
|
184
|
-
function buildEnv(params) {
|
|
185
|
-
const healing = params.healing ?? {};
|
|
186
|
-
const env = {
|
|
187
|
-
...params.base,
|
|
188
|
-
CANARY_ENABLED: params.base.CANARY_ENABLED ?? "1",
|
|
189
|
-
CANARY_RUNNER: "canary",
|
|
190
|
-
CANARY_EVENT_LOG: params.eventLogPath,
|
|
191
|
-
...params.nodeOptions ? { NODE_OPTIONS: params.nodeOptions } : {},
|
|
192
|
-
...healing.apiKey ? { AI_API_KEY: healing.apiKey } : {},
|
|
193
|
-
...healing.provider ? { AI_PROVIDER: healing.provider } : {},
|
|
194
|
-
...healing.model ? { AI_MODEL: healing.model } : {},
|
|
195
|
-
...healing.timeoutMs ? { AI_TIMEOUT_MS: String(healing.timeoutMs) } : {},
|
|
196
|
-
...healing.maxActions ? { CANARY_MAX_ACTIONS: String(healing.maxActions) } : {},
|
|
197
|
-
...healing.vision ? { CANARY_VISION: "1" } : {},
|
|
198
|
-
...healing.dryRun ? { CANARY_DRY_RUN: "1" } : {},
|
|
199
|
-
...healing.warnOnly ? { CANARY_WARN_ONLY: "1" } : {},
|
|
200
|
-
...healing.debug ? { CANARY_DEBUG: "1" } : {},
|
|
201
|
-
...healing.readOnly ? { CANARY_READ_ONLY: "1" } : {},
|
|
202
|
-
...healing.allowEvaluate === false ? { CANARY_ALLOW_EVALUATE: "0" } : {},
|
|
203
|
-
...healing.allowRunCode ? { CANARY_ALLOW_RUN_CODE: "1" } : {},
|
|
204
|
-
...healing.maxPayloadBytes ? { CANARY_MAX_PAYLOAD_BYTES: String(healing.maxPayloadBytes) } : {},
|
|
205
|
-
...params.overrides
|
|
206
|
-
};
|
|
207
|
-
return env;
|
|
208
|
-
}
|
|
209
|
-
async function spawnPlaywright(opts) {
|
|
210
|
-
return new Promise((resolve) => {
|
|
211
|
-
const started = Date.now();
|
|
212
|
-
const child = spawn(opts.bin, opts.args, {
|
|
213
|
-
cwd: opts.cwd,
|
|
214
|
-
env: opts.env,
|
|
215
|
-
stdio: opts.stdio === "inherit" ? "inherit" : ["ignore", "pipe", "pipe"]
|
|
216
|
-
});
|
|
217
|
-
let timer;
|
|
218
|
-
let output = "";
|
|
219
|
-
let error;
|
|
220
|
-
if (opts.stdio === "pipe") {
|
|
221
|
-
child.stdout?.on("data", (chunk) => {
|
|
222
|
-
output += chunk.toString();
|
|
223
|
-
});
|
|
224
|
-
child.stderr?.on("data", (chunk) => {
|
|
225
|
-
output += chunk.toString();
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
if (opts.timeoutMs && opts.timeoutMs > 0) {
|
|
229
|
-
timer = setTimeout(() => {
|
|
230
|
-
error = new Error(`canary.run timed out after ${opts.timeoutMs}ms`);
|
|
231
|
-
child.kill("SIGKILL");
|
|
232
|
-
}, opts.timeoutMs);
|
|
233
|
-
}
|
|
234
|
-
child.on("close", (code) => {
|
|
235
|
-
if (timer) clearTimeout(timer);
|
|
236
|
-
resolve({ exitCode: code ?? 1, output: output || void 0, durationMs: Date.now() - started, error });
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
function summarize(jsonReportPath, eventLogPath, durationMs) {
|
|
241
|
-
const base = {
|
|
242
|
-
total: 0,
|
|
243
|
-
passed: 0,
|
|
244
|
-
failed: 0,
|
|
245
|
-
flaky: 0,
|
|
246
|
-
skipped: 0,
|
|
247
|
-
durationMs
|
|
248
|
-
};
|
|
249
|
-
const jsonReport = readJsonReport(jsonReportPath);
|
|
250
|
-
if (jsonReport) {
|
|
251
|
-
const counts = countTests(jsonReport);
|
|
252
|
-
base.total = counts.total;
|
|
253
|
-
base.passed = counts.passed;
|
|
254
|
-
base.failed = counts.failed;
|
|
255
|
-
base.flaky = counts.flaky;
|
|
256
|
-
base.skipped = counts.skipped;
|
|
257
|
-
base.durationMs = jsonReport.duration ?? durationMs;
|
|
258
|
-
}
|
|
259
|
-
const healed = countHealed(eventLogPath);
|
|
260
|
-
if (healed) {
|
|
261
|
-
return { ...base, healed };
|
|
262
|
-
}
|
|
263
|
-
return base;
|
|
264
|
-
}
|
|
265
|
-
function readJsonReport(reportPath) {
|
|
266
|
-
try {
|
|
267
|
-
if (fs2.existsSync(reportPath)) {
|
|
268
|
-
const raw = fs2.readFileSync(reportPath, "utf-8");
|
|
269
|
-
return JSON.parse(raw);
|
|
270
|
-
}
|
|
271
|
-
} catch {
|
|
272
|
-
}
|
|
273
|
-
return void 0;
|
|
274
|
-
}
|
|
275
|
-
function countTests(report) {
|
|
276
|
-
let total = 0;
|
|
277
|
-
let passed = 0;
|
|
278
|
-
let failed = 0;
|
|
279
|
-
let flaky = 0;
|
|
280
|
-
let skipped = 0;
|
|
281
|
-
const visitSuite = (suite) => {
|
|
282
|
-
if (!suite) return;
|
|
283
|
-
suite.tests?.forEach((test) => {
|
|
284
|
-
total += 1;
|
|
285
|
-
const statuses = test.results.map((r) => r.status);
|
|
286
|
-
const hasFailed = statuses.includes("failed") || statuses.includes("interrupted");
|
|
287
|
-
const hasPassed = statuses.includes("passed");
|
|
288
|
-
const hasTimedOut = statuses.includes("timedOut");
|
|
289
|
-
const allSkipped = statuses.every((s) => s === "skipped");
|
|
290
|
-
if (allSkipped) {
|
|
291
|
-
skipped += 1;
|
|
292
|
-
} else if ((hasFailed || hasTimedOut) && hasPassed) {
|
|
293
|
-
flaky += 1;
|
|
294
|
-
} else if (hasFailed || hasTimedOut) {
|
|
295
|
-
failed += 1;
|
|
296
|
-
} else if (hasPassed && statuses.length > 1) {
|
|
297
|
-
flaky += 1;
|
|
298
|
-
} else if (hasPassed) {
|
|
299
|
-
passed += 1;
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
suite.suites?.forEach(visitSuite);
|
|
303
|
-
};
|
|
304
|
-
report.suites?.forEach(visitSuite);
|
|
305
|
-
return { total, passed, failed, flaky, skipped };
|
|
306
|
-
}
|
|
307
|
-
function countHealed(eventLogPath) {
|
|
308
|
-
try {
|
|
309
|
-
if (!fs2.existsSync(eventLogPath)) return void 0;
|
|
310
|
-
const raw = fs2.readFileSync(eventLogPath, "utf-8").trim();
|
|
311
|
-
if (!raw) return void 0;
|
|
312
|
-
const lines = raw.split("\n");
|
|
313
|
-
let healed = 0;
|
|
314
|
-
for (const line of lines) {
|
|
315
|
-
try {
|
|
316
|
-
const event = JSON.parse(line);
|
|
317
|
-
if (event?.healed === true) healed += 1;
|
|
318
|
-
} catch {
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
return healed;
|
|
322
|
-
} catch {
|
|
323
|
-
return void 0;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// src/login.ts
|
|
328
|
-
import fs3 from "fs/promises";
|
|
329
|
-
import os2 from "os";
|
|
330
|
-
import path3 from "path";
|
|
331
|
-
import process2 from "process";
|
|
332
|
-
import { spawn as spawn2 } from "child_process";
|
|
333
|
-
var DEFAULT_APP_URL = "https://app.trycanary.ai";
|
|
334
|
-
function getArgValue(argv, key) {
|
|
335
|
-
const index = argv.indexOf(key);
|
|
336
|
-
if (index === -1) return void 0;
|
|
337
|
-
return argv[index + 1];
|
|
338
|
-
}
|
|
339
|
-
function shouldOpenBrowser(argv) {
|
|
340
|
-
return !argv.includes("--no-open");
|
|
341
|
-
}
|
|
342
|
-
function openUrl(url) {
|
|
343
|
-
const platform = process2.platform;
|
|
344
|
-
if (platform === "darwin") {
|
|
345
|
-
spawn2("open", [url], { stdio: "ignore" });
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
if (platform === "win32") {
|
|
349
|
-
spawn2("cmd", ["/c", "start", "", url], { stdio: "ignore" });
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
spawn2("xdg-open", [url], { stdio: "ignore" });
|
|
353
|
-
}
|
|
354
|
-
async function writeToken(token) {
|
|
355
|
-
const dir = path3.join(os2.homedir(), ".config", "canary-cli");
|
|
356
|
-
const filePath = path3.join(dir, "auth.json");
|
|
357
|
-
await fs3.mkdir(dir, { recursive: true });
|
|
358
|
-
await fs3.writeFile(filePath, JSON.stringify({ token }, null, 2), "utf8");
|
|
359
|
-
return filePath;
|
|
360
|
-
}
|
|
361
|
-
async function runLogin(argv) {
|
|
362
|
-
const apiUrl = getArgValue(argv, "--api-url") ?? process2.env.CANARY_API_URL ?? "https://api.trycanary.ai";
|
|
363
|
-
const appUrl = getArgValue(argv, "--app-url") ?? process2.env.CANARY_APP_URL ?? DEFAULT_APP_URL;
|
|
364
|
-
const startRes = await fetch(`${apiUrl}/cli-login/start`, {
|
|
365
|
-
method: "POST",
|
|
366
|
-
headers: { "content-type": "application/json" },
|
|
367
|
-
body: JSON.stringify({ appUrl })
|
|
368
|
-
});
|
|
369
|
-
const startJson = await startRes.json();
|
|
370
|
-
if (!startRes.ok || !startJson.ok || !startJson.deviceCode || !startJson.userCode) {
|
|
371
|
-
console.error("Login start failed", startJson.error ?? startRes.statusText);
|
|
372
|
-
process2.exit(1);
|
|
373
|
-
}
|
|
374
|
-
console.log("Login required.");
|
|
375
|
-
console.log(`User code: ${startJson.userCode}`);
|
|
376
|
-
if (startJson.verificationUrl) {
|
|
377
|
-
console.log(`Open: ${startJson.verificationUrl}`);
|
|
378
|
-
if (shouldOpenBrowser(argv)) {
|
|
379
|
-
try {
|
|
380
|
-
openUrl(startJson.verificationUrl);
|
|
381
|
-
} catch {
|
|
382
|
-
console.log("Unable to open browser automatically. Please open the URL manually.");
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
const intervalMs = (startJson.intervalSeconds ?? 3) * 1e3;
|
|
387
|
-
const expiresAt = startJson.expiresAt ? new Date(startJson.expiresAt).getTime() : null;
|
|
388
|
-
while (true) {
|
|
389
|
-
if (expiresAt && Date.now() > expiresAt) {
|
|
390
|
-
console.error("Login code expired.");
|
|
391
|
-
process2.exit(1);
|
|
392
|
-
}
|
|
393
|
-
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
394
|
-
const pollRes = await fetch(`${apiUrl}/cli-login/poll`, {
|
|
395
|
-
method: "POST",
|
|
396
|
-
headers: { "content-type": "application/json" },
|
|
397
|
-
body: JSON.stringify({ deviceCode: startJson.deviceCode })
|
|
398
|
-
});
|
|
399
|
-
const pollJson = await pollRes.json();
|
|
400
|
-
if (!pollRes.ok || !pollJson.ok) {
|
|
401
|
-
console.error("Login poll failed", pollJson.error ?? pollRes.statusText);
|
|
402
|
-
process2.exit(1);
|
|
403
|
-
}
|
|
404
|
-
if (pollJson.status === "approved" && pollJson.accessToken) {
|
|
405
|
-
const filePath = await writeToken(pollJson.accessToken);
|
|
406
|
-
console.log(`Login successful. Token saved to ${filePath}`);
|
|
407
|
-
console.log("Set CANARY_API_TOKEN to use the CLI without re-login.");
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
if (pollJson.status === "rejected") {
|
|
411
|
-
console.error("Login rejected.");
|
|
412
|
-
process2.exit(1);
|
|
413
|
-
}
|
|
414
|
-
if (pollJson.status === "expired") {
|
|
415
|
-
console.error("Login expired.");
|
|
416
|
-
process2.exit(1);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
// src/run-local.ts
|
|
422
|
-
import process3 from "process";
|
|
423
|
-
function getArgValue2(argv, key) {
|
|
424
|
-
const index = argv.indexOf(key);
|
|
425
|
-
if (index === -1) return void 0;
|
|
426
|
-
return argv[index + 1];
|
|
427
|
-
}
|
|
428
|
-
async function runLocalSession(argv) {
|
|
429
|
-
const apiUrl = getArgValue2(argv, "--api-url") ?? process3.env.CANARY_API_URL ?? "https://api.trycanary.ai";
|
|
430
|
-
const token = getArgValue2(argv, "--token") ?? process3.env.CANARY_API_TOKEN ?? await readStoredToken();
|
|
431
|
-
if (!token) {
|
|
432
|
-
console.error("Missing token. Run `canary login` first or set CANARY_API_TOKEN.");
|
|
433
|
-
process3.exit(1);
|
|
434
|
-
}
|
|
435
|
-
const portRaw = getArgValue2(argv, "--port") ?? process3.env.CANARY_LOCAL_PORT;
|
|
436
|
-
const tunnelUrl = getArgValue2(argv, "--tunnel-url");
|
|
437
|
-
const title = getArgValue2(argv, "--title");
|
|
438
|
-
const featureSpec = getArgValue2(argv, "--feature");
|
|
439
|
-
const startUrl = getArgValue2(argv, "--start-url");
|
|
440
|
-
if (!tunnelUrl && !portRaw) {
|
|
441
|
-
console.error("Missing --port or --tunnel-url");
|
|
442
|
-
process3.exit(1);
|
|
443
|
-
}
|
|
444
|
-
let publicUrl = tunnelUrl;
|
|
445
|
-
let ws = null;
|
|
446
|
-
if (!publicUrl && portRaw) {
|
|
447
|
-
const port = Number(portRaw);
|
|
448
|
-
if (Number.isNaN(port) || port <= 0) {
|
|
449
|
-
console.error("Invalid --port value");
|
|
450
|
-
process3.exit(1);
|
|
451
|
-
}
|
|
452
|
-
const tunnel = await createTunnel({ apiUrl, token, port });
|
|
453
|
-
publicUrl = tunnel.publicUrl;
|
|
454
|
-
ws = connectTunnel({
|
|
455
|
-
apiUrl,
|
|
456
|
-
tunnelId: tunnel.tunnelId,
|
|
457
|
-
token: tunnel.token,
|
|
458
|
-
port,
|
|
459
|
-
onReady: () => {
|
|
460
|
-
console.log(`Tunnel connected: ${publicUrl ?? tunnel.tunnelId}`);
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
if (!publicUrl) {
|
|
465
|
-
console.error("Failed to resolve tunnel URL");
|
|
466
|
-
process3.exit(1);
|
|
467
|
-
}
|
|
468
|
-
const run2 = await createLocalRun({
|
|
469
|
-
apiUrl,
|
|
470
|
-
token,
|
|
471
|
-
title,
|
|
472
|
-
featureSpec,
|
|
473
|
-
startUrl,
|
|
474
|
-
tunnelUrl: publicUrl
|
|
475
|
-
});
|
|
476
|
-
console.log(`Local test queued: ${run2.runId}`);
|
|
477
|
-
if (run2.watchUrl) {
|
|
478
|
-
console.log(`Watch: ${run2.watchUrl}`);
|
|
479
|
-
}
|
|
480
|
-
if (ws) {
|
|
481
|
-
console.log("Tunnel active. Press Ctrl+C to stop.");
|
|
482
|
-
process3.on("SIGINT", () => {
|
|
483
|
-
ws?.close();
|
|
484
|
-
process3.exit(0);
|
|
485
|
-
});
|
|
486
|
-
await new Promise(() => void 0);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// src/remote-test.ts
|
|
491
|
-
import process4 from "process";
|
|
492
|
-
import { createParser } from "eventsource-parser";
|
|
493
|
-
function getArgValue3(argv, key) {
|
|
494
|
-
const index = argv.indexOf(key);
|
|
495
|
-
if (index === -1 || index >= argv.length - 1) return void 0;
|
|
496
|
-
return argv[index + 1];
|
|
497
|
-
}
|
|
498
|
-
function hasFlag(argv, ...flags) {
|
|
499
|
-
return flags.some((flag) => argv.includes(flag));
|
|
500
|
-
}
|
|
501
|
-
async function runRemoteTest(argv) {
|
|
502
|
-
const apiUrl = getArgValue3(argv, "--api-url") ?? process4.env.CANARY_API_URL ?? "https://api.trycanary.ai";
|
|
503
|
-
const token = getArgValue3(argv, "--token") ?? process4.env.CANARY_API_TOKEN ?? await readStoredToken();
|
|
504
|
-
const tag = getArgValue3(argv, "--tag");
|
|
505
|
-
const namePattern = getArgValue3(argv, "--name-pattern");
|
|
506
|
-
const verbose = hasFlag(argv, "--verbose", "-v");
|
|
507
|
-
if (!token) {
|
|
508
|
-
console.error("Error: No API token found.");
|
|
509
|
-
console.error("");
|
|
510
|
-
console.error("Set CANARY_API_TOKEN environment variable or run:");
|
|
511
|
-
console.error(" canary login");
|
|
512
|
-
console.error("");
|
|
513
|
-
console.error("Or create an API key in Settings > API Keys and pass it:");
|
|
514
|
-
console.error(" canary test --remote --token cnry_...");
|
|
515
|
-
process4.exit(1);
|
|
516
|
-
}
|
|
517
|
-
console.log("Starting remote workflow tests...");
|
|
518
|
-
if (tag) console.log(` Filtering by tag: ${tag}`);
|
|
519
|
-
if (namePattern) console.log(` Filtering by name pattern: ${namePattern}`);
|
|
520
|
-
console.log("");
|
|
521
|
-
const queryParams = new URLSearchParams();
|
|
522
|
-
if (tag) queryParams.set("tag", tag);
|
|
523
|
-
if (namePattern) queryParams.set("namePattern", namePattern);
|
|
524
|
-
const triggerUrl = `${apiUrl}/workflows/test-runs${queryParams.toString() ? `?${queryParams}` : ""}`;
|
|
525
|
-
let triggerRes;
|
|
526
|
-
try {
|
|
527
|
-
triggerRes = await fetch(triggerUrl, {
|
|
528
|
-
method: "POST",
|
|
529
|
-
headers: {
|
|
530
|
-
Authorization: `Bearer ${token}`,
|
|
531
|
-
"Content-Type": "application/json"
|
|
532
|
-
}
|
|
533
|
-
});
|
|
534
|
-
} catch (err) {
|
|
535
|
-
console.error(`Failed to connect to API: ${err}`);
|
|
536
|
-
process4.exit(1);
|
|
537
|
-
}
|
|
538
|
-
if (!triggerRes.ok) {
|
|
539
|
-
const errorText = await triggerRes.text();
|
|
540
|
-
console.error(`Failed to start tests: ${triggerRes.status}`);
|
|
541
|
-
console.error(errorText);
|
|
542
|
-
process4.exit(1);
|
|
543
|
-
}
|
|
544
|
-
const triggerData = await triggerRes.json();
|
|
545
|
-
if (!triggerData.ok || !triggerData.suiteId) {
|
|
546
|
-
console.error(`Failed to start tests: ${triggerData.error ?? "Unknown error"}`);
|
|
547
|
-
process4.exit(1);
|
|
548
|
-
}
|
|
549
|
-
const { suiteId, jobId } = triggerData;
|
|
550
|
-
if (verbose) {
|
|
551
|
-
console.log(`Suite ID: ${suiteId}`);
|
|
552
|
-
console.log(`Job ID: ${jobId}`);
|
|
553
|
-
console.log("");
|
|
554
|
-
}
|
|
555
|
-
const streamUrl = `${apiUrl}/workflows/test-runs/stream?suiteId=${suiteId}`;
|
|
556
|
-
let streamRes;
|
|
557
|
-
try {
|
|
558
|
-
streamRes = await fetch(streamUrl, {
|
|
559
|
-
headers: {
|
|
560
|
-
Authorization: `Bearer ${token}`,
|
|
561
|
-
Accept: "text/event-stream"
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
} catch (err) {
|
|
565
|
-
console.error(`Failed to connect to event stream: ${err}`);
|
|
566
|
-
process4.exit(1);
|
|
567
|
-
}
|
|
568
|
-
if (!streamRes.ok || !streamRes.body) {
|
|
569
|
-
console.error(`Failed to connect to event stream: ${streamRes.status}`);
|
|
570
|
-
process4.exit(1);
|
|
571
|
-
}
|
|
572
|
-
let exitCode = 0;
|
|
573
|
-
let hasCompleted = false;
|
|
574
|
-
const workflowNames = /* @__PURE__ */ new Map();
|
|
575
|
-
let totalWorkflows = 0;
|
|
576
|
-
let completedWorkflows = 0;
|
|
577
|
-
let failedWorkflows = 0;
|
|
578
|
-
let successfulWorkflows = 0;
|
|
579
|
-
const parser = createParser({
|
|
580
|
-
onEvent: (event) => {
|
|
581
|
-
if (!event.data) return;
|
|
582
|
-
try {
|
|
583
|
-
const data = JSON.parse(event.data);
|
|
584
|
-
if (verbose) {
|
|
585
|
-
console.log(`[${event.event}] ${JSON.stringify(data)}`);
|
|
586
|
-
}
|
|
587
|
-
if (event.event === "workflow-test") {
|
|
588
|
-
const testEvent = data;
|
|
589
|
-
const { status, workflowId, message, errorMessage } = testEvent;
|
|
590
|
-
const name = workflowNames.get(workflowId) || message?.replace(/^Flow "(.+)" .*$/, "$1") || workflowId;
|
|
591
|
-
if (message?.startsWith('Flow "')) {
|
|
592
|
-
const match = message.match(/^Flow "(.+?)" /);
|
|
593
|
-
if (match) workflowNames.set(workflowId, match[1]);
|
|
594
|
-
}
|
|
595
|
-
if (!verbose) {
|
|
596
|
-
if (status === "success") {
|
|
597
|
-
console.log(` \u2713 ${name}`);
|
|
598
|
-
} else if (status === "failed") {
|
|
599
|
-
console.log(` \u2717 ${name}`);
|
|
600
|
-
if (errorMessage) {
|
|
601
|
-
console.log(` Error: ${errorMessage.slice(0, 200)}`);
|
|
602
|
-
}
|
|
603
|
-
exitCode = 1;
|
|
604
|
-
} else if (status === "running") {
|
|
605
|
-
} else if (status === "waiting") {
|
|
606
|
-
console.log(` \u23F3 ${name} (waiting for scheduled time)`);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
if (event.event === "workflow-test-suite") {
|
|
611
|
-
const suiteEvent = data;
|
|
612
|
-
totalWorkflows = suiteEvent.totalWorkflows;
|
|
613
|
-
completedWorkflows = suiteEvent.completedWorkflows;
|
|
614
|
-
failedWorkflows = suiteEvent.failedWorkflows;
|
|
615
|
-
successfulWorkflows = suiteEvent.successfulWorkflows;
|
|
616
|
-
if (suiteEvent.status === "completed") {
|
|
617
|
-
hasCompleted = true;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
if (event.event === "error") {
|
|
621
|
-
const errorData = data;
|
|
622
|
-
console.error(`Stream error: ${errorData.error ?? "Unknown error"}`);
|
|
623
|
-
exitCode = 1;
|
|
624
|
-
}
|
|
625
|
-
} catch {
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
});
|
|
629
|
-
const reader = streamRes.body.getReader();
|
|
630
|
-
const decoder = new TextDecoder();
|
|
631
|
-
try {
|
|
632
|
-
while (!hasCompleted) {
|
|
633
|
-
const { done, value } = await reader.read();
|
|
634
|
-
if (done) break;
|
|
635
|
-
parser.feed(decoder.decode(value, { stream: true }));
|
|
636
|
-
}
|
|
637
|
-
} finally {
|
|
638
|
-
reader.releaseLock();
|
|
639
|
-
}
|
|
640
|
-
console.log("");
|
|
641
|
-
console.log("\u2500".repeat(50));
|
|
642
|
-
if (totalWorkflows === 0) {
|
|
643
|
-
console.log("No workflows found matching the filter criteria.");
|
|
644
|
-
process4.exit(0);
|
|
645
|
-
}
|
|
646
|
-
const passRate = totalWorkflows > 0 ? Math.round(successfulWorkflows / totalWorkflows * 100) : 0;
|
|
647
|
-
if (failedWorkflows > 0) {
|
|
648
|
-
console.log(`FAILED: ${failedWorkflows} of ${totalWorkflows} workflows failed (${passRate}% pass rate)`);
|
|
649
|
-
exitCode = 1;
|
|
650
|
-
} else {
|
|
651
|
-
console.log(`PASSED: ${successfulWorkflows} of ${totalWorkflows} workflows passed`);
|
|
652
|
-
}
|
|
653
|
-
const waitingWorkflows = totalWorkflows - completedWorkflows;
|
|
654
|
-
if (waitingWorkflows > 0) {
|
|
655
|
-
console.log(`Note: ${waitingWorkflows} workflow(s) are still waiting (scheduled for later)`);
|
|
656
|
-
}
|
|
657
|
-
process4.exit(exitCode);
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// src/index.ts
|
|
661
|
-
var loadMcp = () => import("./mcp-P2B24MTM.js").then((m) => m.runMcp);
|
|
662
|
-
var loadLocalBrowser = () => import("./local-browser-5LJ7UPOH.js").then((m) => m.runLocalBrowser);
|
|
663
|
-
var canary = { run };
|
|
664
|
-
var baseDir = typeof __dirname !== "undefined" ? __dirname : path4.dirname(fileURLToPath2(import.meta.url));
|
|
665
|
-
var preloadPath = path4.join(baseDir, "runner", "preload.js");
|
|
666
|
-
var requireFn = makeRequire();
|
|
667
|
-
function runPlaywrightTests(args) {
|
|
668
|
-
const playwrightCli = requireFn.resolve("@playwright/test/cli");
|
|
669
|
-
const { runnerBin, preloadFlag } = resolveRunner(preloadPath);
|
|
670
|
-
const nodeOptions = process5.env.NODE_OPTIONS && preloadFlag ? `${process5.env.NODE_OPTIONS} ${preloadFlag}` : preloadFlag ?? process5.env.NODE_OPTIONS;
|
|
671
|
-
const env = {
|
|
672
|
-
...process5.env,
|
|
673
|
-
CANARY_ENABLED: process5.env.CANARY_ENABLED ?? "1",
|
|
674
|
-
CANARY_RUNNER: "canary",
|
|
675
|
-
...nodeOptions ? { NODE_OPTIONS: nodeOptions } : {}
|
|
676
|
-
};
|
|
677
|
-
const result = spawnSync2(runnerBin, [playwrightCli, "test", ...args], {
|
|
678
|
-
env,
|
|
679
|
-
stdio: "inherit",
|
|
680
|
-
cwd: process5.cwd()
|
|
681
|
-
});
|
|
682
|
-
if (result.error) {
|
|
683
|
-
console.error("canary failed to launch Playwright:", result.error);
|
|
684
|
-
process5.exit(1);
|
|
685
|
-
}
|
|
686
|
-
process5.exit(result.status ?? 1);
|
|
687
|
-
}
|
|
688
|
-
function printHelp() {
|
|
689
|
-
console.log(
|
|
690
|
-
[
|
|
691
|
-
"canary: Local and remote testing CLI",
|
|
692
|
-
"",
|
|
693
|
-
"Usage:",
|
|
694
|
-
" canary test [playwright options] Run local Playwright tests",
|
|
695
|
-
" canary test --remote [options] Run remote workflow tests",
|
|
696
|
-
" canary local-run --tunnel-url <url> [options]",
|
|
697
|
-
" canary tunnel --port <localPort> [options]",
|
|
698
|
-
" canary run --port <localPort> [options]",
|
|
699
|
-
" canary mcp",
|
|
700
|
-
" canary browser [--mode playwright|cdp] [--cdp-url <url>] [--no-headless]",
|
|
701
|
-
" canary login [--app-url https://app.trycanary.ai] [--no-open]",
|
|
702
|
-
" canary help",
|
|
703
|
-
"",
|
|
704
|
-
"Remote test options:",
|
|
705
|
-
" --token <key> API key (or set CANARY_API_TOKEN)",
|
|
706
|
-
" --api-url <url> API URL (default: https://api.trycanary.ai)",
|
|
707
|
-
" --tag <tag> Filter workflows by tag",
|
|
708
|
-
" --name-pattern <pat> Filter workflows by name pattern",
|
|
709
|
-
" --verbose, -v Show all events",
|
|
710
|
-
"",
|
|
711
|
-
"Browser options:",
|
|
712
|
-
" --mode <playwright|cdp> Browser mode (default: playwright)",
|
|
713
|
-
" --cdp-url <url> CDP endpoint for existing Chrome",
|
|
714
|
-
" --no-headless Run browser with visible UI",
|
|
715
|
-
" --storage-state <path> Path to storage state JSON",
|
|
716
|
-
" --instructions <text> Instructions for the cloud agent",
|
|
717
|
-
"",
|
|
718
|
-
"Flags:",
|
|
719
|
-
" -h, --help Show help"
|
|
720
|
-
].join("\n")
|
|
721
|
-
);
|
|
722
|
-
}
|
|
723
|
-
async function main(argv) {
|
|
724
|
-
if (argv.includes("--help") || argv.includes("-h")) {
|
|
725
|
-
printHelp();
|
|
726
|
-
return;
|
|
727
|
-
}
|
|
728
|
-
const [command, ...rest] = argv;
|
|
729
|
-
if (!command || command === "help") {
|
|
730
|
-
printHelp();
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
if (command === "test") {
|
|
734
|
-
if (rest.includes("--remote")) {
|
|
735
|
-
const remoteArgs = rest.filter((arg) => arg !== "--remote");
|
|
736
|
-
await runRemoteTest(remoteArgs);
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
runPlaywrightTests(rest);
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
if (command === "local-run") {
|
|
743
|
-
await runLocalTest(rest);
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
if (command === "run") {
|
|
747
|
-
await runLocalSession(rest);
|
|
748
|
-
return;
|
|
749
|
-
}
|
|
750
|
-
if (command === "mcp") {
|
|
751
|
-
const runMcp = await loadMcp();
|
|
752
|
-
await runMcp(rest);
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
|
-
if (command === "tunnel") {
|
|
756
|
-
await runTunnel(rest);
|
|
757
|
-
return;
|
|
758
|
-
}
|
|
759
|
-
if (command === "login") {
|
|
760
|
-
await runLogin(rest);
|
|
761
|
-
return;
|
|
762
|
-
}
|
|
763
|
-
if (command === "browser") {
|
|
764
|
-
const runLocalBrowser = await loadLocalBrowser();
|
|
765
|
-
await runLocalBrowser(rest);
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
console.log(`Unknown command "${command}".`);
|
|
769
|
-
printHelp();
|
|
770
|
-
process5.exit(1);
|
|
771
|
-
}
|
|
772
|
-
if (import.meta.url === pathToFileURL2(process5.argv[1]).href) {
|
|
773
|
-
void main(process5.argv.slice(2));
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
export {
|
|
777
|
-
run,
|
|
778
|
-
canary,
|
|
779
|
-
main
|
|
780
|
-
};
|
|
781
|
-
//# sourceMappingURL=chunk-YA43CE6P.js.map
|