@hasna/testers 0.0.1
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/LICENSE +21 -0
- package/README.md +196 -0
- package/dashboard/dist/assets/index-CDcHt94n.css +1 -0
- package/dashboard/dist/assets/index-DCNDCh61.js +49 -0
- package/dashboard/dist/index.html +13 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +4112 -0
- package/dist/db/agents.d.ts +10 -0
- package/dist/db/agents.d.ts.map +1 -0
- package/dist/db/database.d.ts +10 -0
- package/dist/db/database.d.ts.map +1 -0
- package/dist/db/projects.d.ts +11 -0
- package/dist/db/projects.d.ts.map +1 -0
- package/dist/db/results.d.ts +20 -0
- package/dist/db/results.d.ts.map +1 -0
- package/dist/db/runs.d.ts +9 -0
- package/dist/db/runs.d.ts.map +1 -0
- package/dist/db/scenarios.d.ts +8 -0
- package/dist/db/scenarios.d.ts.map +1 -0
- package/dist/db/screenshots.d.ts +13 -0
- package/dist/db/screenshots.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2515 -0
- package/dist/lib/ai-client.d.ts +66 -0
- package/dist/lib/ai-client.d.ts.map +1 -0
- package/dist/lib/browser.d.ts +64 -0
- package/dist/lib/browser.d.ts.map +1 -0
- package/dist/lib/config.d.ts +18 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/reporter.d.ts +18 -0
- package/dist/lib/reporter.d.ts.map +1 -0
- package/dist/lib/runner.d.ts +36 -0
- package/dist/lib/runner.d.ts.map +1 -0
- package/dist/lib/screenshotter.d.ts +60 -0
- package/dist/lib/screenshotter.d.ts.map +1 -0
- package/dist/lib/todos-connector.d.ts +32 -0
- package/dist/lib/todos-connector.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +5903 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +1654 -0
- package/dist/types/index.d.ts +276 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +78 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2515 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/types/index.ts
|
|
3
|
+
var MODEL_MAP = {
|
|
4
|
+
quick: "claude-haiku-4-5-20251001",
|
|
5
|
+
thorough: "claude-sonnet-4-6-20260311",
|
|
6
|
+
deep: "claude-opus-4-6-20260311"
|
|
7
|
+
};
|
|
8
|
+
function projectFromRow(row) {
|
|
9
|
+
return {
|
|
10
|
+
id: row.id,
|
|
11
|
+
name: row.name,
|
|
12
|
+
path: row.path,
|
|
13
|
+
description: row.description,
|
|
14
|
+
createdAt: row.created_at,
|
|
15
|
+
updatedAt: row.updated_at
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function agentFromRow(row) {
|
|
19
|
+
return {
|
|
20
|
+
id: row.id,
|
|
21
|
+
name: row.name,
|
|
22
|
+
description: row.description,
|
|
23
|
+
role: row.role,
|
|
24
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : null,
|
|
25
|
+
createdAt: row.created_at,
|
|
26
|
+
lastSeenAt: row.last_seen_at
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function scenarioFromRow(row) {
|
|
30
|
+
return {
|
|
31
|
+
id: row.id,
|
|
32
|
+
shortId: row.short_id,
|
|
33
|
+
projectId: row.project_id,
|
|
34
|
+
name: row.name,
|
|
35
|
+
description: row.description,
|
|
36
|
+
steps: JSON.parse(row.steps),
|
|
37
|
+
tags: JSON.parse(row.tags),
|
|
38
|
+
priority: row.priority,
|
|
39
|
+
model: row.model,
|
|
40
|
+
timeoutMs: row.timeout_ms,
|
|
41
|
+
targetPath: row.target_path,
|
|
42
|
+
requiresAuth: row.requires_auth === 1,
|
|
43
|
+
authConfig: row.auth_config ? JSON.parse(row.auth_config) : null,
|
|
44
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : null,
|
|
45
|
+
version: row.version,
|
|
46
|
+
createdAt: row.created_at,
|
|
47
|
+
updatedAt: row.updated_at
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function runFromRow(row) {
|
|
51
|
+
return {
|
|
52
|
+
id: row.id,
|
|
53
|
+
projectId: row.project_id,
|
|
54
|
+
status: row.status,
|
|
55
|
+
url: row.url,
|
|
56
|
+
model: row.model,
|
|
57
|
+
headed: row.headed === 1,
|
|
58
|
+
parallel: row.parallel,
|
|
59
|
+
total: row.total,
|
|
60
|
+
passed: row.passed,
|
|
61
|
+
failed: row.failed,
|
|
62
|
+
startedAt: row.started_at,
|
|
63
|
+
finishedAt: row.finished_at,
|
|
64
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : null
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function resultFromRow(row) {
|
|
68
|
+
return {
|
|
69
|
+
id: row.id,
|
|
70
|
+
runId: row.run_id,
|
|
71
|
+
scenarioId: row.scenario_id,
|
|
72
|
+
status: row.status,
|
|
73
|
+
reasoning: row.reasoning,
|
|
74
|
+
error: row.error,
|
|
75
|
+
stepsCompleted: row.steps_completed,
|
|
76
|
+
stepsTotal: row.steps_total,
|
|
77
|
+
durationMs: row.duration_ms,
|
|
78
|
+
model: row.model,
|
|
79
|
+
tokensUsed: row.tokens_used,
|
|
80
|
+
costCents: row.cost_cents,
|
|
81
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : null,
|
|
82
|
+
createdAt: row.created_at
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function screenshotFromRow(row) {
|
|
86
|
+
return {
|
|
87
|
+
id: row.id,
|
|
88
|
+
resultId: row.result_id,
|
|
89
|
+
stepNumber: row.step_number,
|
|
90
|
+
action: row.action,
|
|
91
|
+
filePath: row.file_path,
|
|
92
|
+
width: row.width,
|
|
93
|
+
height: row.height,
|
|
94
|
+
timestamp: row.timestamp
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
class ScenarioNotFoundError extends Error {
|
|
99
|
+
constructor(id) {
|
|
100
|
+
super(`Scenario not found: ${id}`);
|
|
101
|
+
this.name = "ScenarioNotFoundError";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
class RunNotFoundError extends Error {
|
|
106
|
+
constructor(id) {
|
|
107
|
+
super(`Run not found: ${id}`);
|
|
108
|
+
this.name = "RunNotFoundError";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class ResultNotFoundError extends Error {
|
|
113
|
+
constructor(id) {
|
|
114
|
+
super(`Result not found: ${id}`);
|
|
115
|
+
this.name = "ResultNotFoundError";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
class VersionConflictError extends Error {
|
|
120
|
+
constructor(entity, id) {
|
|
121
|
+
super(`Version conflict on ${entity}: ${id}`);
|
|
122
|
+
this.name = "VersionConflictError";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
class BrowserError extends Error {
|
|
127
|
+
constructor(message) {
|
|
128
|
+
super(message);
|
|
129
|
+
this.name = "BrowserError";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
class AIClientError extends Error {
|
|
134
|
+
constructor(message) {
|
|
135
|
+
super(message);
|
|
136
|
+
this.name = "AIClientError";
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
class TodosConnectionError extends Error {
|
|
141
|
+
constructor(message) {
|
|
142
|
+
super(message);
|
|
143
|
+
this.name = "TodosConnectionError";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
class ProjectNotFoundError extends Error {
|
|
148
|
+
constructor(id) {
|
|
149
|
+
super(`Project not found: ${id}`);
|
|
150
|
+
this.name = "ProjectNotFoundError";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
class AgentNotFoundError extends Error {
|
|
155
|
+
constructor(id) {
|
|
156
|
+
super(`Agent not found: ${id}`);
|
|
157
|
+
this.name = "AgentNotFoundError";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// src/db/database.ts
|
|
161
|
+
import { Database } from "bun:sqlite";
|
|
162
|
+
import { mkdirSync, existsSync } from "fs";
|
|
163
|
+
import { dirname, join } from "path";
|
|
164
|
+
import { homedir } from "os";
|
|
165
|
+
var db = null;
|
|
166
|
+
function now() {
|
|
167
|
+
return new Date().toISOString();
|
|
168
|
+
}
|
|
169
|
+
function uuid() {
|
|
170
|
+
return crypto.randomUUID();
|
|
171
|
+
}
|
|
172
|
+
function shortUuid() {
|
|
173
|
+
return uuid().slice(0, 8);
|
|
174
|
+
}
|
|
175
|
+
function resolveDbPath() {
|
|
176
|
+
const envPath = process.env["TESTERS_DB_PATH"];
|
|
177
|
+
if (envPath)
|
|
178
|
+
return envPath;
|
|
179
|
+
const dir = join(homedir(), ".testers");
|
|
180
|
+
if (!existsSync(dir))
|
|
181
|
+
mkdirSync(dir, { recursive: true });
|
|
182
|
+
return join(dir, "testers.db");
|
|
183
|
+
}
|
|
184
|
+
var MIGRATIONS = [
|
|
185
|
+
`
|
|
186
|
+
CREATE TABLE IF NOT EXISTS projects (
|
|
187
|
+
id TEXT PRIMARY KEY,
|
|
188
|
+
name TEXT NOT NULL UNIQUE,
|
|
189
|
+
path TEXT UNIQUE,
|
|
190
|
+
description TEXT,
|
|
191
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
192
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
CREATE TABLE IF NOT EXISTS agents (
|
|
196
|
+
id TEXT PRIMARY KEY,
|
|
197
|
+
name TEXT NOT NULL UNIQUE,
|
|
198
|
+
description TEXT,
|
|
199
|
+
role TEXT,
|
|
200
|
+
metadata TEXT DEFAULT '{}',
|
|
201
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
202
|
+
last_seen_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
CREATE TABLE IF NOT EXISTS scenarios (
|
|
206
|
+
id TEXT PRIMARY KEY,
|
|
207
|
+
short_id TEXT NOT NULL UNIQUE,
|
|
208
|
+
project_id TEXT REFERENCES projects(id) ON DELETE SET NULL,
|
|
209
|
+
name TEXT NOT NULL,
|
|
210
|
+
description TEXT NOT NULL DEFAULT '',
|
|
211
|
+
steps TEXT NOT NULL DEFAULT '[]',
|
|
212
|
+
tags TEXT NOT NULL DEFAULT '[]',
|
|
213
|
+
priority TEXT NOT NULL DEFAULT 'medium' CHECK(priority IN ('low','medium','high','critical')),
|
|
214
|
+
model TEXT,
|
|
215
|
+
timeout_ms INTEGER,
|
|
216
|
+
target_path TEXT,
|
|
217
|
+
requires_auth INTEGER NOT NULL DEFAULT 0,
|
|
218
|
+
auth_config TEXT,
|
|
219
|
+
metadata TEXT DEFAULT '{}',
|
|
220
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
221
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
222
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
CREATE TABLE IF NOT EXISTS runs (
|
|
226
|
+
id TEXT PRIMARY KEY,
|
|
227
|
+
project_id TEXT REFERENCES projects(id) ON DELETE SET NULL,
|
|
228
|
+
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','running','passed','failed','cancelled')),
|
|
229
|
+
url TEXT NOT NULL,
|
|
230
|
+
model TEXT NOT NULL,
|
|
231
|
+
headed INTEGER NOT NULL DEFAULT 0,
|
|
232
|
+
parallel INTEGER NOT NULL DEFAULT 1,
|
|
233
|
+
total INTEGER NOT NULL DEFAULT 0,
|
|
234
|
+
passed INTEGER NOT NULL DEFAULT 0,
|
|
235
|
+
failed INTEGER NOT NULL DEFAULT 0,
|
|
236
|
+
started_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
237
|
+
finished_at TEXT,
|
|
238
|
+
metadata TEXT DEFAULT '{}'
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
CREATE TABLE IF NOT EXISTS results (
|
|
242
|
+
id TEXT PRIMARY KEY,
|
|
243
|
+
run_id TEXT NOT NULL REFERENCES runs(id) ON DELETE CASCADE,
|
|
244
|
+
scenario_id TEXT NOT NULL REFERENCES scenarios(id) ON DELETE CASCADE,
|
|
245
|
+
status TEXT NOT NULL DEFAULT 'skipped' CHECK(status IN ('passed','failed','error','skipped')),
|
|
246
|
+
reasoning TEXT,
|
|
247
|
+
error TEXT,
|
|
248
|
+
steps_completed INTEGER NOT NULL DEFAULT 0,
|
|
249
|
+
steps_total INTEGER NOT NULL DEFAULT 0,
|
|
250
|
+
duration_ms INTEGER NOT NULL DEFAULT 0,
|
|
251
|
+
model TEXT NOT NULL,
|
|
252
|
+
tokens_used INTEGER NOT NULL DEFAULT 0,
|
|
253
|
+
cost_cents REAL NOT NULL DEFAULT 0,
|
|
254
|
+
metadata TEXT DEFAULT '{}',
|
|
255
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
CREATE TABLE IF NOT EXISTS screenshots (
|
|
259
|
+
id TEXT PRIMARY KEY,
|
|
260
|
+
result_id TEXT NOT NULL REFERENCES results(id) ON DELETE CASCADE,
|
|
261
|
+
step_number INTEGER NOT NULL,
|
|
262
|
+
action TEXT NOT NULL,
|
|
263
|
+
file_path TEXT NOT NULL,
|
|
264
|
+
width INTEGER NOT NULL DEFAULT 0,
|
|
265
|
+
height INTEGER NOT NULL DEFAULT 0,
|
|
266
|
+
timestamp TEXT NOT NULL DEFAULT (datetime('now'))
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
CREATE TABLE IF NOT EXISTS _migrations (
|
|
270
|
+
id INTEGER PRIMARY KEY,
|
|
271
|
+
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
272
|
+
);
|
|
273
|
+
`,
|
|
274
|
+
`
|
|
275
|
+
CREATE INDEX IF NOT EXISTS idx_scenarios_project ON scenarios(project_id);
|
|
276
|
+
CREATE INDEX IF NOT EXISTS idx_scenarios_priority ON scenarios(priority);
|
|
277
|
+
CREATE INDEX IF NOT EXISTS idx_scenarios_short_id ON scenarios(short_id);
|
|
278
|
+
CREATE INDEX IF NOT EXISTS idx_runs_project ON runs(project_id);
|
|
279
|
+
CREATE INDEX IF NOT EXISTS idx_runs_status ON runs(status);
|
|
280
|
+
CREATE INDEX IF NOT EXISTS idx_results_run ON results(run_id);
|
|
281
|
+
CREATE INDEX IF NOT EXISTS idx_results_scenario ON results(scenario_id);
|
|
282
|
+
CREATE INDEX IF NOT EXISTS idx_results_status ON results(status);
|
|
283
|
+
CREATE INDEX IF NOT EXISTS idx_screenshots_result ON screenshots(result_id);
|
|
284
|
+
`,
|
|
285
|
+
`
|
|
286
|
+
ALTER TABLE projects ADD COLUMN scenario_prefix TEXT DEFAULT 'TST';
|
|
287
|
+
ALTER TABLE projects ADD COLUMN scenario_counter INTEGER DEFAULT 0;
|
|
288
|
+
`
|
|
289
|
+
];
|
|
290
|
+
function applyMigrations(database) {
|
|
291
|
+
const applied = database.query("SELECT id FROM _migrations ORDER BY id").all();
|
|
292
|
+
const appliedIds = new Set(applied.map((r) => r.id));
|
|
293
|
+
for (let i = 0;i < MIGRATIONS.length; i++) {
|
|
294
|
+
const migrationId = i + 1;
|
|
295
|
+
if (appliedIds.has(migrationId))
|
|
296
|
+
continue;
|
|
297
|
+
const migration = MIGRATIONS[i];
|
|
298
|
+
database.exec(migration);
|
|
299
|
+
database.query("INSERT INTO _migrations (id, applied_at) VALUES (?, ?)").run(migrationId, now());
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function getDatabase() {
|
|
303
|
+
if (db)
|
|
304
|
+
return db;
|
|
305
|
+
const dbPath = resolveDbPath();
|
|
306
|
+
const dir = dirname(dbPath);
|
|
307
|
+
if (dbPath !== ":memory:" && !existsSync(dir)) {
|
|
308
|
+
mkdirSync(dir, { recursive: true });
|
|
309
|
+
}
|
|
310
|
+
db = new Database(dbPath);
|
|
311
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
312
|
+
db.exec("PRAGMA foreign_keys = ON");
|
|
313
|
+
db.exec("PRAGMA busy_timeout = 5000");
|
|
314
|
+
db.exec(`
|
|
315
|
+
CREATE TABLE IF NOT EXISTS _migrations (
|
|
316
|
+
id INTEGER PRIMARY KEY,
|
|
317
|
+
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
318
|
+
);
|
|
319
|
+
`);
|
|
320
|
+
applyMigrations(db);
|
|
321
|
+
return db;
|
|
322
|
+
}
|
|
323
|
+
function closeDatabase() {
|
|
324
|
+
if (db) {
|
|
325
|
+
db.close();
|
|
326
|
+
db = null;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function resetDatabase() {
|
|
330
|
+
closeDatabase();
|
|
331
|
+
const database = getDatabase();
|
|
332
|
+
database.exec("DELETE FROM screenshots");
|
|
333
|
+
database.exec("DELETE FROM results");
|
|
334
|
+
database.exec("DELETE FROM runs");
|
|
335
|
+
database.exec("DELETE FROM scenarios");
|
|
336
|
+
database.exec("DELETE FROM agents");
|
|
337
|
+
database.exec("DELETE FROM projects");
|
|
338
|
+
}
|
|
339
|
+
function resolvePartialId(table, partialId) {
|
|
340
|
+
const database = getDatabase();
|
|
341
|
+
const rows = database.query(`SELECT id FROM ${table} WHERE id LIKE ? || '%'`).all(partialId);
|
|
342
|
+
if (rows.length === 1)
|
|
343
|
+
return rows[0].id;
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
// src/db/scenarios.ts
|
|
347
|
+
function nextShortId(projectId) {
|
|
348
|
+
const db2 = getDatabase();
|
|
349
|
+
if (projectId) {
|
|
350
|
+
const project = db2.query("SELECT scenario_prefix, scenario_counter FROM projects WHERE id = ?").get(projectId);
|
|
351
|
+
if (project) {
|
|
352
|
+
const next = project.scenario_counter + 1;
|
|
353
|
+
db2.query("UPDATE projects SET scenario_counter = ? WHERE id = ?").run(next, projectId);
|
|
354
|
+
return `${project.scenario_prefix}-${next}`;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return shortUuid();
|
|
358
|
+
}
|
|
359
|
+
function createScenario(input) {
|
|
360
|
+
const db2 = getDatabase();
|
|
361
|
+
const id = uuid();
|
|
362
|
+
const short_id = nextShortId(input.projectId);
|
|
363
|
+
const timestamp = now();
|
|
364
|
+
db2.query(`
|
|
365
|
+
INSERT INTO scenarios (id, short_id, project_id, name, description, steps, tags, priority, model, timeout_ms, target_path, requires_auth, auth_config, metadata, version, created_at, updated_at)
|
|
366
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
|
|
367
|
+
`).run(id, short_id, input.projectId ?? null, input.name, input.description, JSON.stringify(input.steps ?? []), JSON.stringify(input.tags ?? []), input.priority ?? "medium", input.model ?? null, input.timeoutMs ?? null, input.targetPath ?? null, input.requiresAuth ? 1 : 0, input.authConfig ? JSON.stringify(input.authConfig) : null, input.metadata ? JSON.stringify(input.metadata) : null, timestamp, timestamp);
|
|
368
|
+
return getScenario(id);
|
|
369
|
+
}
|
|
370
|
+
function getScenario(id) {
|
|
371
|
+
const db2 = getDatabase();
|
|
372
|
+
let row = db2.query("SELECT * FROM scenarios WHERE id = ?").get(id);
|
|
373
|
+
if (row)
|
|
374
|
+
return scenarioFromRow(row);
|
|
375
|
+
row = db2.query("SELECT * FROM scenarios WHERE short_id = ?").get(id);
|
|
376
|
+
if (row)
|
|
377
|
+
return scenarioFromRow(row);
|
|
378
|
+
const fullId = resolvePartialId("scenarios", id);
|
|
379
|
+
if (fullId) {
|
|
380
|
+
row = db2.query("SELECT * FROM scenarios WHERE id = ?").get(fullId);
|
|
381
|
+
if (row)
|
|
382
|
+
return scenarioFromRow(row);
|
|
383
|
+
}
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
function getScenarioByShortId(shortId) {
|
|
387
|
+
const db2 = getDatabase();
|
|
388
|
+
const row = db2.query("SELECT * FROM scenarios WHERE short_id = ?").get(shortId);
|
|
389
|
+
return row ? scenarioFromRow(row) : null;
|
|
390
|
+
}
|
|
391
|
+
function listScenarios(filter) {
|
|
392
|
+
const db2 = getDatabase();
|
|
393
|
+
const conditions = [];
|
|
394
|
+
const params = [];
|
|
395
|
+
if (filter?.projectId) {
|
|
396
|
+
conditions.push("project_id = ?");
|
|
397
|
+
params.push(filter.projectId);
|
|
398
|
+
}
|
|
399
|
+
if (filter?.tags && filter.tags.length > 0) {
|
|
400
|
+
for (const tag of filter.tags) {
|
|
401
|
+
conditions.push("tags LIKE ?");
|
|
402
|
+
params.push(`%"${tag}"%`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (filter?.priority) {
|
|
406
|
+
conditions.push("priority = ?");
|
|
407
|
+
params.push(filter.priority);
|
|
408
|
+
}
|
|
409
|
+
if (filter?.search) {
|
|
410
|
+
conditions.push("(name LIKE ? OR description LIKE ?)");
|
|
411
|
+
const term = `%${filter.search}%`;
|
|
412
|
+
params.push(term, term);
|
|
413
|
+
}
|
|
414
|
+
let sql = "SELECT * FROM scenarios";
|
|
415
|
+
if (conditions.length > 0) {
|
|
416
|
+
sql += " WHERE " + conditions.join(" AND ");
|
|
417
|
+
}
|
|
418
|
+
sql += " ORDER BY created_at DESC";
|
|
419
|
+
if (filter?.limit) {
|
|
420
|
+
sql += " LIMIT ?";
|
|
421
|
+
params.push(filter.limit);
|
|
422
|
+
}
|
|
423
|
+
if (filter?.offset) {
|
|
424
|
+
sql += " OFFSET ?";
|
|
425
|
+
params.push(filter.offset);
|
|
426
|
+
}
|
|
427
|
+
const rows = db2.query(sql).all(...params);
|
|
428
|
+
return rows.map(scenarioFromRow);
|
|
429
|
+
}
|
|
430
|
+
function updateScenario(id, input, version) {
|
|
431
|
+
const db2 = getDatabase();
|
|
432
|
+
const existing = getScenario(id);
|
|
433
|
+
if (!existing) {
|
|
434
|
+
throw new Error(`Scenario not found: ${id}`);
|
|
435
|
+
}
|
|
436
|
+
if (existing.version !== version) {
|
|
437
|
+
throw new VersionConflictError("scenario", existing.id);
|
|
438
|
+
}
|
|
439
|
+
const sets = [];
|
|
440
|
+
const params = [];
|
|
441
|
+
if (input.name !== undefined) {
|
|
442
|
+
sets.push("name = ?");
|
|
443
|
+
params.push(input.name);
|
|
444
|
+
}
|
|
445
|
+
if (input.description !== undefined) {
|
|
446
|
+
sets.push("description = ?");
|
|
447
|
+
params.push(input.description);
|
|
448
|
+
}
|
|
449
|
+
if (input.steps !== undefined) {
|
|
450
|
+
sets.push("steps = ?");
|
|
451
|
+
params.push(JSON.stringify(input.steps));
|
|
452
|
+
}
|
|
453
|
+
if (input.tags !== undefined) {
|
|
454
|
+
sets.push("tags = ?");
|
|
455
|
+
params.push(JSON.stringify(input.tags));
|
|
456
|
+
}
|
|
457
|
+
if (input.priority !== undefined) {
|
|
458
|
+
sets.push("priority = ?");
|
|
459
|
+
params.push(input.priority);
|
|
460
|
+
}
|
|
461
|
+
if (input.model !== undefined) {
|
|
462
|
+
sets.push("model = ?");
|
|
463
|
+
params.push(input.model);
|
|
464
|
+
}
|
|
465
|
+
if (input.timeoutMs !== undefined) {
|
|
466
|
+
sets.push("timeout_ms = ?");
|
|
467
|
+
params.push(input.timeoutMs);
|
|
468
|
+
}
|
|
469
|
+
if (input.targetPath !== undefined) {
|
|
470
|
+
sets.push("target_path = ?");
|
|
471
|
+
params.push(input.targetPath);
|
|
472
|
+
}
|
|
473
|
+
if (input.requiresAuth !== undefined) {
|
|
474
|
+
sets.push("requires_auth = ?");
|
|
475
|
+
params.push(input.requiresAuth ? 1 : 0);
|
|
476
|
+
}
|
|
477
|
+
if (input.authConfig !== undefined) {
|
|
478
|
+
sets.push("auth_config = ?");
|
|
479
|
+
params.push(JSON.stringify(input.authConfig));
|
|
480
|
+
}
|
|
481
|
+
if (input.metadata !== undefined) {
|
|
482
|
+
sets.push("metadata = ?");
|
|
483
|
+
params.push(JSON.stringify(input.metadata));
|
|
484
|
+
}
|
|
485
|
+
if (sets.length === 0) {
|
|
486
|
+
return existing;
|
|
487
|
+
}
|
|
488
|
+
sets.push("version = ?");
|
|
489
|
+
params.push(version + 1);
|
|
490
|
+
sets.push("updated_at = ?");
|
|
491
|
+
params.push(now());
|
|
492
|
+
params.push(existing.id);
|
|
493
|
+
params.push(version);
|
|
494
|
+
const result = db2.query(`UPDATE scenarios SET ${sets.join(", ")} WHERE id = ? AND version = ?`).run(...params);
|
|
495
|
+
if (result.changes === 0) {
|
|
496
|
+
throw new VersionConflictError("scenario", existing.id);
|
|
497
|
+
}
|
|
498
|
+
return getScenario(existing.id);
|
|
499
|
+
}
|
|
500
|
+
function deleteScenario(id) {
|
|
501
|
+
const db2 = getDatabase();
|
|
502
|
+
const scenario = getScenario(id);
|
|
503
|
+
if (!scenario)
|
|
504
|
+
return false;
|
|
505
|
+
const result = db2.query("DELETE FROM scenarios WHERE id = ?").run(scenario.id);
|
|
506
|
+
return result.changes > 0;
|
|
507
|
+
}
|
|
508
|
+
// src/db/runs.ts
|
|
509
|
+
function createRun(input) {
|
|
510
|
+
const db2 = getDatabase();
|
|
511
|
+
const id = uuid();
|
|
512
|
+
const timestamp = now();
|
|
513
|
+
db2.query(`
|
|
514
|
+
INSERT INTO runs (id, project_id, status, url, model, headed, parallel, total, passed, failed, started_at, finished_at, metadata)
|
|
515
|
+
VALUES (?, ?, 'pending', ?, ?, ?, ?, 0, 0, 0, ?, NULL, ?)
|
|
516
|
+
`).run(id, input.projectId ?? null, input.url, input.model, input.headed ? 1 : 0, input.parallel ?? 1, timestamp, input.model ? JSON.stringify({}) : null);
|
|
517
|
+
return getRun(id);
|
|
518
|
+
}
|
|
519
|
+
function getRun(id) {
|
|
520
|
+
const db2 = getDatabase();
|
|
521
|
+
let row = db2.query("SELECT * FROM runs WHERE id = ?").get(id);
|
|
522
|
+
if (row)
|
|
523
|
+
return runFromRow(row);
|
|
524
|
+
const fullId = resolvePartialId("runs", id);
|
|
525
|
+
if (fullId) {
|
|
526
|
+
row = db2.query("SELECT * FROM runs WHERE id = ?").get(fullId);
|
|
527
|
+
if (row)
|
|
528
|
+
return runFromRow(row);
|
|
529
|
+
}
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
function listRuns(filter) {
|
|
533
|
+
const db2 = getDatabase();
|
|
534
|
+
const conditions = [];
|
|
535
|
+
const params = [];
|
|
536
|
+
if (filter?.projectId) {
|
|
537
|
+
conditions.push("project_id = ?");
|
|
538
|
+
params.push(filter.projectId);
|
|
539
|
+
}
|
|
540
|
+
if (filter?.status) {
|
|
541
|
+
conditions.push("status = ?");
|
|
542
|
+
params.push(filter.status);
|
|
543
|
+
}
|
|
544
|
+
let sql = "SELECT * FROM runs";
|
|
545
|
+
if (conditions.length > 0) {
|
|
546
|
+
sql += " WHERE " + conditions.join(" AND ");
|
|
547
|
+
}
|
|
548
|
+
sql += " ORDER BY started_at DESC";
|
|
549
|
+
if (filter?.limit) {
|
|
550
|
+
sql += " LIMIT ?";
|
|
551
|
+
params.push(filter.limit);
|
|
552
|
+
}
|
|
553
|
+
if (filter?.offset) {
|
|
554
|
+
sql += " OFFSET ?";
|
|
555
|
+
params.push(filter.offset);
|
|
556
|
+
}
|
|
557
|
+
const rows = db2.query(sql).all(...params);
|
|
558
|
+
return rows.map(runFromRow);
|
|
559
|
+
}
|
|
560
|
+
function updateRun(id, updates) {
|
|
561
|
+
const db2 = getDatabase();
|
|
562
|
+
const existing = getRun(id);
|
|
563
|
+
if (!existing) {
|
|
564
|
+
throw new Error(`Run not found: ${id}`);
|
|
565
|
+
}
|
|
566
|
+
const sets = [];
|
|
567
|
+
const params = [];
|
|
568
|
+
if (updates.status !== undefined) {
|
|
569
|
+
sets.push("status = ?");
|
|
570
|
+
params.push(updates.status);
|
|
571
|
+
}
|
|
572
|
+
if (updates.url !== undefined) {
|
|
573
|
+
sets.push("url = ?");
|
|
574
|
+
params.push(updates.url);
|
|
575
|
+
}
|
|
576
|
+
if (updates.model !== undefined) {
|
|
577
|
+
sets.push("model = ?");
|
|
578
|
+
params.push(updates.model);
|
|
579
|
+
}
|
|
580
|
+
if (updates.headed !== undefined) {
|
|
581
|
+
sets.push("headed = ?");
|
|
582
|
+
params.push(updates.headed);
|
|
583
|
+
}
|
|
584
|
+
if (updates.parallel !== undefined) {
|
|
585
|
+
sets.push("parallel = ?");
|
|
586
|
+
params.push(updates.parallel);
|
|
587
|
+
}
|
|
588
|
+
if (updates.total !== undefined) {
|
|
589
|
+
sets.push("total = ?");
|
|
590
|
+
params.push(updates.total);
|
|
591
|
+
}
|
|
592
|
+
if (updates.passed !== undefined) {
|
|
593
|
+
sets.push("passed = ?");
|
|
594
|
+
params.push(updates.passed);
|
|
595
|
+
}
|
|
596
|
+
if (updates.failed !== undefined) {
|
|
597
|
+
sets.push("failed = ?");
|
|
598
|
+
params.push(updates.failed);
|
|
599
|
+
}
|
|
600
|
+
if (updates.started_at !== undefined) {
|
|
601
|
+
sets.push("started_at = ?");
|
|
602
|
+
params.push(updates.started_at);
|
|
603
|
+
}
|
|
604
|
+
if (updates.finished_at !== undefined) {
|
|
605
|
+
sets.push("finished_at = ?");
|
|
606
|
+
params.push(updates.finished_at);
|
|
607
|
+
}
|
|
608
|
+
if (updates.metadata !== undefined) {
|
|
609
|
+
sets.push("metadata = ?");
|
|
610
|
+
params.push(updates.metadata);
|
|
611
|
+
}
|
|
612
|
+
if (sets.length === 0) {
|
|
613
|
+
return existing;
|
|
614
|
+
}
|
|
615
|
+
params.push(existing.id);
|
|
616
|
+
db2.query(`UPDATE runs SET ${sets.join(", ")} WHERE id = ?`).run(...params);
|
|
617
|
+
return getRun(existing.id);
|
|
618
|
+
}
|
|
619
|
+
function deleteRun(id) {
|
|
620
|
+
const db2 = getDatabase();
|
|
621
|
+
const run = getRun(id);
|
|
622
|
+
if (!run)
|
|
623
|
+
return false;
|
|
624
|
+
const result = db2.query("DELETE FROM runs WHERE id = ?").run(run.id);
|
|
625
|
+
return result.changes > 0;
|
|
626
|
+
}
|
|
627
|
+
// src/db/results.ts
|
|
628
|
+
function createResult(input) {
|
|
629
|
+
const db2 = getDatabase();
|
|
630
|
+
const id = uuid();
|
|
631
|
+
const timestamp = now();
|
|
632
|
+
db2.query(`
|
|
633
|
+
INSERT INTO results (id, run_id, scenario_id, status, reasoning, error, steps_completed, steps_total, duration_ms, model, tokens_used, cost_cents, metadata, created_at)
|
|
634
|
+
VALUES (?, ?, ?, 'skipped', NULL, NULL, 0, ?, 0, ?, 0, 0, '{}', ?)
|
|
635
|
+
`).run(id, input.runId, input.scenarioId, input.stepsTotal, input.model, timestamp);
|
|
636
|
+
return getResult(id);
|
|
637
|
+
}
|
|
638
|
+
function getResult(id) {
|
|
639
|
+
const db2 = getDatabase();
|
|
640
|
+
let row = db2.query("SELECT * FROM results WHERE id = ?").get(id);
|
|
641
|
+
if (row)
|
|
642
|
+
return resultFromRow(row);
|
|
643
|
+
const fullId = resolvePartialId("results", id);
|
|
644
|
+
if (fullId) {
|
|
645
|
+
row = db2.query("SELECT * FROM results WHERE id = ?").get(fullId);
|
|
646
|
+
if (row)
|
|
647
|
+
return resultFromRow(row);
|
|
648
|
+
}
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
function listResults(runId) {
|
|
652
|
+
const db2 = getDatabase();
|
|
653
|
+
const rows = db2.query("SELECT * FROM results WHERE run_id = ? ORDER BY created_at ASC").all(runId);
|
|
654
|
+
return rows.map(resultFromRow);
|
|
655
|
+
}
|
|
656
|
+
function updateResult(id, updates) {
|
|
657
|
+
const db2 = getDatabase();
|
|
658
|
+
const existing = getResult(id);
|
|
659
|
+
if (!existing) {
|
|
660
|
+
throw new Error(`Result not found: ${id}`);
|
|
661
|
+
}
|
|
662
|
+
const sets = [];
|
|
663
|
+
const params = [];
|
|
664
|
+
if (updates.status !== undefined) {
|
|
665
|
+
sets.push("status = ?");
|
|
666
|
+
params.push(updates.status);
|
|
667
|
+
}
|
|
668
|
+
if (updates.reasoning !== undefined) {
|
|
669
|
+
sets.push("reasoning = ?");
|
|
670
|
+
params.push(updates.reasoning);
|
|
671
|
+
}
|
|
672
|
+
if (updates.error !== undefined) {
|
|
673
|
+
sets.push("error = ?");
|
|
674
|
+
params.push(updates.error);
|
|
675
|
+
}
|
|
676
|
+
if (updates.stepsCompleted !== undefined) {
|
|
677
|
+
sets.push("steps_completed = ?");
|
|
678
|
+
params.push(updates.stepsCompleted);
|
|
679
|
+
}
|
|
680
|
+
if (updates.durationMs !== undefined) {
|
|
681
|
+
sets.push("duration_ms = ?");
|
|
682
|
+
params.push(updates.durationMs);
|
|
683
|
+
}
|
|
684
|
+
if (updates.tokensUsed !== undefined) {
|
|
685
|
+
sets.push("tokens_used = ?");
|
|
686
|
+
params.push(updates.tokensUsed);
|
|
687
|
+
}
|
|
688
|
+
if (updates.costCents !== undefined) {
|
|
689
|
+
sets.push("cost_cents = ?");
|
|
690
|
+
params.push(updates.costCents);
|
|
691
|
+
}
|
|
692
|
+
if (sets.length === 0) {
|
|
693
|
+
return existing;
|
|
694
|
+
}
|
|
695
|
+
params.push(existing.id);
|
|
696
|
+
db2.query(`UPDATE results SET ${sets.join(", ")} WHERE id = ?`).run(...params);
|
|
697
|
+
return getResult(existing.id);
|
|
698
|
+
}
|
|
699
|
+
function getResultsByRun(runId) {
|
|
700
|
+
return listResults(runId);
|
|
701
|
+
}
|
|
702
|
+
// src/db/screenshots.ts
|
|
703
|
+
function createScreenshot(input) {
|
|
704
|
+
const db2 = getDatabase();
|
|
705
|
+
const id = uuid();
|
|
706
|
+
const timestamp = now();
|
|
707
|
+
db2.query(`
|
|
708
|
+
INSERT INTO screenshots (id, result_id, step_number, action, file_path, width, height, timestamp)
|
|
709
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
710
|
+
`).run(id, input.resultId, input.stepNumber, input.action, input.filePath, input.width, input.height, timestamp);
|
|
711
|
+
return getScreenshot(id);
|
|
712
|
+
}
|
|
713
|
+
function getScreenshot(id) {
|
|
714
|
+
const db2 = getDatabase();
|
|
715
|
+
const row = db2.query("SELECT * FROM screenshots WHERE id = ?").get(id);
|
|
716
|
+
return row ? screenshotFromRow(row) : null;
|
|
717
|
+
}
|
|
718
|
+
function listScreenshots(resultId) {
|
|
719
|
+
const db2 = getDatabase();
|
|
720
|
+
const rows = db2.query("SELECT * FROM screenshots WHERE result_id = ? ORDER BY step_number ASC").all(resultId);
|
|
721
|
+
return rows.map(screenshotFromRow);
|
|
722
|
+
}
|
|
723
|
+
function getScreenshotsByResult(resultId) {
|
|
724
|
+
return listScreenshots(resultId);
|
|
725
|
+
}
|
|
726
|
+
// src/db/projects.ts
|
|
727
|
+
function createProject(input) {
|
|
728
|
+
const db2 = getDatabase();
|
|
729
|
+
const id = uuid();
|
|
730
|
+
const timestamp = now();
|
|
731
|
+
db2.query(`
|
|
732
|
+
INSERT INTO projects (id, name, path, description, created_at, updated_at)
|
|
733
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
734
|
+
`).run(id, input.name, input.path ?? null, input.description ?? null, timestamp, timestamp);
|
|
735
|
+
return getProject(id);
|
|
736
|
+
}
|
|
737
|
+
function getProject(id) {
|
|
738
|
+
const db2 = getDatabase();
|
|
739
|
+
const row = db2.query("SELECT * FROM projects WHERE id = ?").get(id);
|
|
740
|
+
return row ? projectFromRow(row) : null;
|
|
741
|
+
}
|
|
742
|
+
function getProjectByPath(path) {
|
|
743
|
+
const db2 = getDatabase();
|
|
744
|
+
const row = db2.query("SELECT * FROM projects WHERE path = ?").get(path);
|
|
745
|
+
return row ? projectFromRow(row) : null;
|
|
746
|
+
}
|
|
747
|
+
function listProjects() {
|
|
748
|
+
const db2 = getDatabase();
|
|
749
|
+
const rows = db2.query("SELECT * FROM projects ORDER BY created_at DESC").all();
|
|
750
|
+
return rows.map(projectFromRow);
|
|
751
|
+
}
|
|
752
|
+
function ensureProject(name, path) {
|
|
753
|
+
const db2 = getDatabase();
|
|
754
|
+
const byPath = db2.query("SELECT * FROM projects WHERE path = ?").get(path);
|
|
755
|
+
if (byPath)
|
|
756
|
+
return projectFromRow(byPath);
|
|
757
|
+
const byName = db2.query("SELECT * FROM projects WHERE name = ?").get(name);
|
|
758
|
+
if (byName)
|
|
759
|
+
return projectFromRow(byName);
|
|
760
|
+
return createProject({ name, path });
|
|
761
|
+
}
|
|
762
|
+
// src/db/agents.ts
|
|
763
|
+
function registerAgent(input) {
|
|
764
|
+
const db2 = getDatabase();
|
|
765
|
+
const existing = db2.query("SELECT * FROM agents WHERE name = ?").get(input.name);
|
|
766
|
+
if (existing) {
|
|
767
|
+
db2.query("UPDATE agents SET last_seen_at = ? WHERE id = ?").run(now(), existing.id);
|
|
768
|
+
return getAgent(existing.id);
|
|
769
|
+
}
|
|
770
|
+
const id = uuid();
|
|
771
|
+
const timestamp = now();
|
|
772
|
+
db2.query(`
|
|
773
|
+
INSERT INTO agents (id, name, description, role, metadata, created_at, last_seen_at)
|
|
774
|
+
VALUES (?, ?, ?, ?, '{}', ?, ?)
|
|
775
|
+
`).run(id, input.name, input.description ?? null, input.role ?? null, timestamp, timestamp);
|
|
776
|
+
return getAgent(id);
|
|
777
|
+
}
|
|
778
|
+
function getAgent(id) {
|
|
779
|
+
const db2 = getDatabase();
|
|
780
|
+
const row = db2.query("SELECT * FROM agents WHERE id = ?").get(id);
|
|
781
|
+
return row ? agentFromRow(row) : null;
|
|
782
|
+
}
|
|
783
|
+
function getAgentByName(name) {
|
|
784
|
+
const db2 = getDatabase();
|
|
785
|
+
const row = db2.query("SELECT * FROM agents WHERE name = ?").get(name);
|
|
786
|
+
return row ? agentFromRow(row) : null;
|
|
787
|
+
}
|
|
788
|
+
function listAgents() {
|
|
789
|
+
const db2 = getDatabase();
|
|
790
|
+
const rows = db2.query("SELECT * FROM agents ORDER BY created_at DESC").all();
|
|
791
|
+
return rows.map(agentFromRow);
|
|
792
|
+
}
|
|
793
|
+
// src/lib/config.ts
|
|
794
|
+
import { homedir as homedir2 } from "os";
|
|
795
|
+
import { join as join2 } from "path";
|
|
796
|
+
import { readFileSync, existsSync as existsSync2 } from "fs";
|
|
797
|
+
var CONFIG_DIR = join2(homedir2(), ".testers");
|
|
798
|
+
var CONFIG_PATH = join2(CONFIG_DIR, "config.json");
|
|
799
|
+
function getDefaultConfig() {
|
|
800
|
+
return {
|
|
801
|
+
defaultModel: "claude-haiku-4-5-20251001",
|
|
802
|
+
models: { ...MODEL_MAP },
|
|
803
|
+
browser: {
|
|
804
|
+
headless: true,
|
|
805
|
+
viewport: { width: 1280, height: 720 },
|
|
806
|
+
timeout: 60000
|
|
807
|
+
},
|
|
808
|
+
screenshots: {
|
|
809
|
+
dir: join2(homedir2(), ".testers", "screenshots"),
|
|
810
|
+
format: "png",
|
|
811
|
+
quality: 90,
|
|
812
|
+
fullPage: false
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
function loadConfig() {
|
|
817
|
+
const defaults = getDefaultConfig();
|
|
818
|
+
let fileConfig = {};
|
|
819
|
+
if (existsSync2(CONFIG_PATH)) {
|
|
820
|
+
try {
|
|
821
|
+
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
822
|
+
fileConfig = JSON.parse(raw);
|
|
823
|
+
} catch {}
|
|
824
|
+
}
|
|
825
|
+
const config = {
|
|
826
|
+
defaultModel: fileConfig.defaultModel ?? defaults.defaultModel,
|
|
827
|
+
models: fileConfig.models ? { ...defaults.models, ...fileConfig.models } : { ...defaults.models },
|
|
828
|
+
browser: fileConfig.browser ? { ...defaults.browser, ...fileConfig.browser } : { ...defaults.browser },
|
|
829
|
+
screenshots: fileConfig.screenshots ? { ...defaults.screenshots, ...fileConfig.screenshots } : { ...defaults.screenshots },
|
|
830
|
+
anthropicApiKey: fileConfig.anthropicApiKey,
|
|
831
|
+
todosDbPath: fileConfig.todosDbPath
|
|
832
|
+
};
|
|
833
|
+
const envModel = process.env["TESTERS_MODEL"];
|
|
834
|
+
if (envModel) {
|
|
835
|
+
config.defaultModel = envModel;
|
|
836
|
+
}
|
|
837
|
+
const envScreenshotsDir = process.env["TESTERS_SCREENSHOTS_DIR"];
|
|
838
|
+
if (envScreenshotsDir) {
|
|
839
|
+
config.screenshots.dir = envScreenshotsDir;
|
|
840
|
+
}
|
|
841
|
+
const envApiKey = process.env["ANTHROPIC_API_KEY"];
|
|
842
|
+
if (envApiKey) {
|
|
843
|
+
config.anthropicApiKey = envApiKey;
|
|
844
|
+
}
|
|
845
|
+
return config;
|
|
846
|
+
}
|
|
847
|
+
function resolveModel(nameOrId) {
|
|
848
|
+
if (nameOrId in MODEL_MAP) {
|
|
849
|
+
return MODEL_MAP[nameOrId];
|
|
850
|
+
}
|
|
851
|
+
return nameOrId;
|
|
852
|
+
}
|
|
853
|
+
// src/lib/browser.ts
|
|
854
|
+
import { chromium } from "playwright";
|
|
855
|
+
import { execSync } from "child_process";
|
|
856
|
+
var DEFAULT_VIEWPORT = { width: 1280, height: 720 };
|
|
857
|
+
async function launchBrowser(options) {
|
|
858
|
+
const headless = options?.headless ?? true;
|
|
859
|
+
const viewport = options?.viewport ?? DEFAULT_VIEWPORT;
|
|
860
|
+
try {
|
|
861
|
+
const browser = await chromium.launch({
|
|
862
|
+
headless,
|
|
863
|
+
args: [
|
|
864
|
+
`--window-size=${viewport.width},${viewport.height}`
|
|
865
|
+
]
|
|
866
|
+
});
|
|
867
|
+
return browser;
|
|
868
|
+
} catch (error) {
|
|
869
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
870
|
+
throw new BrowserError(`Failed to launch browser: ${message}`);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
async function getPage(browser, options) {
|
|
874
|
+
const viewport = options?.viewport ?? DEFAULT_VIEWPORT;
|
|
875
|
+
try {
|
|
876
|
+
const context = await browser.newContext({
|
|
877
|
+
viewport,
|
|
878
|
+
userAgent: options?.userAgent,
|
|
879
|
+
locale: options?.locale
|
|
880
|
+
});
|
|
881
|
+
const page = await context.newPage();
|
|
882
|
+
return page;
|
|
883
|
+
} catch (error) {
|
|
884
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
885
|
+
throw new BrowserError(`Failed to create page: ${message}`);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
async function closeBrowser(browser) {
|
|
889
|
+
try {
|
|
890
|
+
await browser.close();
|
|
891
|
+
} catch (error) {
|
|
892
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
893
|
+
throw new BrowserError(`Failed to close browser: ${message}`);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
class BrowserPool {
|
|
898
|
+
pool = [];
|
|
899
|
+
maxSize;
|
|
900
|
+
headless;
|
|
901
|
+
viewport;
|
|
902
|
+
constructor(size, options) {
|
|
903
|
+
this.maxSize = size;
|
|
904
|
+
this.headless = options?.headless ?? true;
|
|
905
|
+
this.viewport = options?.viewport ?? DEFAULT_VIEWPORT;
|
|
906
|
+
}
|
|
907
|
+
async acquire() {
|
|
908
|
+
const idle = this.pool.find((entry) => !entry.inUse);
|
|
909
|
+
if (idle) {
|
|
910
|
+
idle.inUse = true;
|
|
911
|
+
const page = await getPage(idle.browser, { viewport: this.viewport });
|
|
912
|
+
return { browser: idle.browser, page };
|
|
913
|
+
}
|
|
914
|
+
if (this.pool.length < this.maxSize) {
|
|
915
|
+
const browser = await launchBrowser({
|
|
916
|
+
headless: this.headless,
|
|
917
|
+
viewport: this.viewport
|
|
918
|
+
});
|
|
919
|
+
const entry = { browser, inUse: true };
|
|
920
|
+
this.pool.push(entry);
|
|
921
|
+
const page = await getPage(browser, { viewport: this.viewport });
|
|
922
|
+
return { browser, page };
|
|
923
|
+
}
|
|
924
|
+
return new Promise((resolve, reject) => {
|
|
925
|
+
const interval = setInterval(() => {
|
|
926
|
+
const available = this.pool.find((entry) => !entry.inUse);
|
|
927
|
+
if (available) {
|
|
928
|
+
clearInterval(interval);
|
|
929
|
+
available.inUse = true;
|
|
930
|
+
getPage(available.browser, { viewport: this.viewport }).then((page) => resolve({ browser: available.browser, page })).catch(reject);
|
|
931
|
+
}
|
|
932
|
+
}, 50);
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
release(browser) {
|
|
936
|
+
const entry = this.pool.find((e) => e.browser === browser);
|
|
937
|
+
if (entry) {
|
|
938
|
+
entry.inUse = false;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
async closeAll() {
|
|
942
|
+
const closePromises = this.pool.map((entry) => entry.browser.close().catch(() => {}));
|
|
943
|
+
await Promise.all(closePromises);
|
|
944
|
+
this.pool.length = 0;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
async function installBrowser() {
|
|
948
|
+
try {
|
|
949
|
+
execSync("bunx playwright install chromium", {
|
|
950
|
+
stdio: "inherit"
|
|
951
|
+
});
|
|
952
|
+
} catch (error) {
|
|
953
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
954
|
+
throw new BrowserError(`Failed to install browser: ${message}`);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
// src/lib/screenshotter.ts
|
|
958
|
+
import { mkdirSync as mkdirSync2, existsSync as existsSync3 } from "fs";
|
|
959
|
+
import { join as join3 } from "path";
|
|
960
|
+
import { homedir as homedir3 } from "os";
|
|
961
|
+
function slugify(text) {
|
|
962
|
+
return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
963
|
+
}
|
|
964
|
+
function generateFilename(stepNumber, action) {
|
|
965
|
+
const padded = String(stepNumber).padStart(3, "0");
|
|
966
|
+
const slug = slugify(action);
|
|
967
|
+
return `${padded}-${slug}.png`;
|
|
968
|
+
}
|
|
969
|
+
function getScreenshotDir(baseDir, runId, scenarioSlug) {
|
|
970
|
+
return join3(baseDir, runId, scenarioSlug);
|
|
971
|
+
}
|
|
972
|
+
function ensureDir(dirPath) {
|
|
973
|
+
if (!existsSync3(dirPath)) {
|
|
974
|
+
mkdirSync2(dirPath, { recursive: true });
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
var DEFAULT_BASE_DIR = join3(homedir3(), ".testers", "screenshots");
|
|
978
|
+
|
|
979
|
+
class Screenshotter {
|
|
980
|
+
baseDir;
|
|
981
|
+
format;
|
|
982
|
+
quality;
|
|
983
|
+
fullPage;
|
|
984
|
+
constructor(options = {}) {
|
|
985
|
+
this.baseDir = options.baseDir ?? DEFAULT_BASE_DIR;
|
|
986
|
+
this.format = options.format ?? "png";
|
|
987
|
+
this.quality = options.quality ?? 90;
|
|
988
|
+
this.fullPage = options.fullPage ?? false;
|
|
989
|
+
}
|
|
990
|
+
async capture(page, options) {
|
|
991
|
+
const dir = getScreenshotDir(this.baseDir, options.runId, options.scenarioSlug);
|
|
992
|
+
const filename = generateFilename(options.stepNumber, options.action);
|
|
993
|
+
const filePath = join3(dir, filename);
|
|
994
|
+
ensureDir(dir);
|
|
995
|
+
await page.screenshot({
|
|
996
|
+
path: filePath,
|
|
997
|
+
fullPage: this.fullPage,
|
|
998
|
+
type: this.format,
|
|
999
|
+
quality: this.format === "jpeg" ? this.quality : undefined
|
|
1000
|
+
});
|
|
1001
|
+
const viewport = page.viewportSize() ?? { width: 0, height: 0 };
|
|
1002
|
+
return {
|
|
1003
|
+
filePath,
|
|
1004
|
+
width: viewport.width,
|
|
1005
|
+
height: viewport.height,
|
|
1006
|
+
timestamp: new Date().toISOString()
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
async captureFullPage(page, options) {
|
|
1010
|
+
const dir = getScreenshotDir(this.baseDir, options.runId, options.scenarioSlug);
|
|
1011
|
+
const filename = generateFilename(options.stepNumber, options.action);
|
|
1012
|
+
const filePath = join3(dir, filename);
|
|
1013
|
+
ensureDir(dir);
|
|
1014
|
+
await page.screenshot({
|
|
1015
|
+
path: filePath,
|
|
1016
|
+
fullPage: true,
|
|
1017
|
+
type: this.format,
|
|
1018
|
+
quality: this.format === "jpeg" ? this.quality : undefined
|
|
1019
|
+
});
|
|
1020
|
+
const viewport = page.viewportSize() ?? { width: 0, height: 0 };
|
|
1021
|
+
return {
|
|
1022
|
+
filePath,
|
|
1023
|
+
width: viewport.width,
|
|
1024
|
+
height: viewport.height,
|
|
1025
|
+
timestamp: new Date().toISOString()
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
async captureElement(page, selector, options) {
|
|
1029
|
+
const dir = getScreenshotDir(this.baseDir, options.runId, options.scenarioSlug);
|
|
1030
|
+
const filename = generateFilename(options.stepNumber, options.action);
|
|
1031
|
+
const filePath = join3(dir, filename);
|
|
1032
|
+
ensureDir(dir);
|
|
1033
|
+
await page.locator(selector).screenshot({
|
|
1034
|
+
path: filePath,
|
|
1035
|
+
type: this.format,
|
|
1036
|
+
quality: this.format === "jpeg" ? this.quality : undefined
|
|
1037
|
+
});
|
|
1038
|
+
const viewport = page.viewportSize() ?? { width: 0, height: 0 };
|
|
1039
|
+
return {
|
|
1040
|
+
filePath,
|
|
1041
|
+
width: viewport.width,
|
|
1042
|
+
height: viewport.height,
|
|
1043
|
+
timestamp: new Date().toISOString()
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
// src/lib/ai-client.ts
|
|
1048
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
1049
|
+
function resolveModel2(nameOrPreset) {
|
|
1050
|
+
if (nameOrPreset in MODEL_MAP) {
|
|
1051
|
+
return MODEL_MAP[nameOrPreset];
|
|
1052
|
+
}
|
|
1053
|
+
return nameOrPreset;
|
|
1054
|
+
}
|
|
1055
|
+
var BROWSER_TOOLS = [
|
|
1056
|
+
{
|
|
1057
|
+
name: "navigate",
|
|
1058
|
+
description: "Navigate the browser to a specific URL.",
|
|
1059
|
+
input_schema: {
|
|
1060
|
+
type: "object",
|
|
1061
|
+
properties: {
|
|
1062
|
+
url: { type: "string", description: "The URL to navigate to." }
|
|
1063
|
+
},
|
|
1064
|
+
required: ["url"]
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
{
|
|
1068
|
+
name: "click",
|
|
1069
|
+
description: "Click on an element matching the given CSS selector.",
|
|
1070
|
+
input_schema: {
|
|
1071
|
+
type: "object",
|
|
1072
|
+
properties: {
|
|
1073
|
+
selector: {
|
|
1074
|
+
type: "string",
|
|
1075
|
+
description: "CSS selector of the element to click."
|
|
1076
|
+
}
|
|
1077
|
+
},
|
|
1078
|
+
required: ["selector"]
|
|
1079
|
+
}
|
|
1080
|
+
},
|
|
1081
|
+
{
|
|
1082
|
+
name: "fill",
|
|
1083
|
+
description: "Fill an input field with the given value.",
|
|
1084
|
+
input_schema: {
|
|
1085
|
+
type: "object",
|
|
1086
|
+
properties: {
|
|
1087
|
+
selector: {
|
|
1088
|
+
type: "string",
|
|
1089
|
+
description: "CSS selector of the input field."
|
|
1090
|
+
},
|
|
1091
|
+
value: {
|
|
1092
|
+
type: "string",
|
|
1093
|
+
description: "The value to fill into the input."
|
|
1094
|
+
}
|
|
1095
|
+
},
|
|
1096
|
+
required: ["selector", "value"]
|
|
1097
|
+
}
|
|
1098
|
+
},
|
|
1099
|
+
{
|
|
1100
|
+
name: "select_option",
|
|
1101
|
+
description: "Select an option from a dropdown/select element.",
|
|
1102
|
+
input_schema: {
|
|
1103
|
+
type: "object",
|
|
1104
|
+
properties: {
|
|
1105
|
+
selector: {
|
|
1106
|
+
type: "string",
|
|
1107
|
+
description: "CSS selector of the select element."
|
|
1108
|
+
},
|
|
1109
|
+
value: {
|
|
1110
|
+
type: "string",
|
|
1111
|
+
description: "The value of the option to select."
|
|
1112
|
+
}
|
|
1113
|
+
},
|
|
1114
|
+
required: ["selector", "value"]
|
|
1115
|
+
}
|
|
1116
|
+
},
|
|
1117
|
+
{
|
|
1118
|
+
name: "screenshot",
|
|
1119
|
+
description: "Take a screenshot of the current page state.",
|
|
1120
|
+
input_schema: {
|
|
1121
|
+
type: "object",
|
|
1122
|
+
properties: {},
|
|
1123
|
+
required: []
|
|
1124
|
+
}
|
|
1125
|
+
},
|
|
1126
|
+
{
|
|
1127
|
+
name: "get_text",
|
|
1128
|
+
description: "Get the text content of an element matching the selector.",
|
|
1129
|
+
input_schema: {
|
|
1130
|
+
type: "object",
|
|
1131
|
+
properties: {
|
|
1132
|
+
selector: {
|
|
1133
|
+
type: "string",
|
|
1134
|
+
description: "CSS selector of the element."
|
|
1135
|
+
}
|
|
1136
|
+
},
|
|
1137
|
+
required: ["selector"]
|
|
1138
|
+
}
|
|
1139
|
+
},
|
|
1140
|
+
{
|
|
1141
|
+
name: "get_url",
|
|
1142
|
+
description: "Get the current page URL.",
|
|
1143
|
+
input_schema: {
|
|
1144
|
+
type: "object",
|
|
1145
|
+
properties: {},
|
|
1146
|
+
required: []
|
|
1147
|
+
}
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
name: "wait_for",
|
|
1151
|
+
description: "Wait for an element matching the selector to appear on the page.",
|
|
1152
|
+
input_schema: {
|
|
1153
|
+
type: "object",
|
|
1154
|
+
properties: {
|
|
1155
|
+
selector: {
|
|
1156
|
+
type: "string",
|
|
1157
|
+
description: "CSS selector to wait for."
|
|
1158
|
+
},
|
|
1159
|
+
timeout: {
|
|
1160
|
+
type: "number",
|
|
1161
|
+
description: "Maximum time to wait in milliseconds (default: 10000)."
|
|
1162
|
+
}
|
|
1163
|
+
},
|
|
1164
|
+
required: ["selector"]
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
name: "go_back",
|
|
1169
|
+
description: "Navigate back to the previous page.",
|
|
1170
|
+
input_schema: {
|
|
1171
|
+
type: "object",
|
|
1172
|
+
properties: {},
|
|
1173
|
+
required: []
|
|
1174
|
+
}
|
|
1175
|
+
},
|
|
1176
|
+
{
|
|
1177
|
+
name: "press_key",
|
|
1178
|
+
description: "Press a keyboard key (e.g., Enter, Tab, Escape, ArrowDown).",
|
|
1179
|
+
input_schema: {
|
|
1180
|
+
type: "object",
|
|
1181
|
+
properties: {
|
|
1182
|
+
key: {
|
|
1183
|
+
type: "string",
|
|
1184
|
+
description: "The key to press (e.g., 'Enter', 'Tab', 'Escape')."
|
|
1185
|
+
}
|
|
1186
|
+
},
|
|
1187
|
+
required: ["key"]
|
|
1188
|
+
}
|
|
1189
|
+
},
|
|
1190
|
+
{
|
|
1191
|
+
name: "assert_visible",
|
|
1192
|
+
description: "Assert that an element matching the selector is visible on the page. Returns 'true' or 'false'.",
|
|
1193
|
+
input_schema: {
|
|
1194
|
+
type: "object",
|
|
1195
|
+
properties: {
|
|
1196
|
+
selector: {
|
|
1197
|
+
type: "string",
|
|
1198
|
+
description: "CSS selector of the element to check."
|
|
1199
|
+
}
|
|
1200
|
+
},
|
|
1201
|
+
required: ["selector"]
|
|
1202
|
+
}
|
|
1203
|
+
},
|
|
1204
|
+
{
|
|
1205
|
+
name: "assert_text",
|
|
1206
|
+
description: "Assert that the given text is visible somewhere on the page. Returns 'true' or 'false'.",
|
|
1207
|
+
input_schema: {
|
|
1208
|
+
type: "object",
|
|
1209
|
+
properties: {
|
|
1210
|
+
text: {
|
|
1211
|
+
type: "string",
|
|
1212
|
+
description: "The text to search for on the page."
|
|
1213
|
+
}
|
|
1214
|
+
},
|
|
1215
|
+
required: ["text"]
|
|
1216
|
+
}
|
|
1217
|
+
},
|
|
1218
|
+
{
|
|
1219
|
+
name: "report_result",
|
|
1220
|
+
description: "Report the final test result. Call this when you have completed testing the scenario. This MUST be the last tool you call.",
|
|
1221
|
+
input_schema: {
|
|
1222
|
+
type: "object",
|
|
1223
|
+
properties: {
|
|
1224
|
+
status: {
|
|
1225
|
+
type: "string",
|
|
1226
|
+
enum: ["passed", "failed"],
|
|
1227
|
+
description: "Whether the test scenario passed or failed."
|
|
1228
|
+
},
|
|
1229
|
+
reasoning: {
|
|
1230
|
+
type: "string",
|
|
1231
|
+
description: "Detailed explanation of why the test passed or failed, including any issues found."
|
|
1232
|
+
}
|
|
1233
|
+
},
|
|
1234
|
+
required: ["status", "reasoning"]
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
];
|
|
1238
|
+
async function executeTool(page, screenshotter, toolName, toolInput, context) {
|
|
1239
|
+
try {
|
|
1240
|
+
switch (toolName) {
|
|
1241
|
+
case "navigate": {
|
|
1242
|
+
const url = toolInput.url;
|
|
1243
|
+
await page.goto(url, { waitUntil: "domcontentloaded" });
|
|
1244
|
+
const screenshot = await screenshotter.capture(page, {
|
|
1245
|
+
runId: context.runId,
|
|
1246
|
+
scenarioSlug: context.scenarioSlug,
|
|
1247
|
+
stepNumber: context.stepNumber,
|
|
1248
|
+
action: "navigate"
|
|
1249
|
+
});
|
|
1250
|
+
return {
|
|
1251
|
+
result: `Navigated to ${url}`,
|
|
1252
|
+
screenshot
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
case "click": {
|
|
1256
|
+
const selector = toolInput.selector;
|
|
1257
|
+
await page.click(selector);
|
|
1258
|
+
const screenshot = await screenshotter.capture(page, {
|
|
1259
|
+
runId: context.runId,
|
|
1260
|
+
scenarioSlug: context.scenarioSlug,
|
|
1261
|
+
stepNumber: context.stepNumber,
|
|
1262
|
+
action: "click"
|
|
1263
|
+
});
|
|
1264
|
+
return {
|
|
1265
|
+
result: `Clicked element: ${selector}`,
|
|
1266
|
+
screenshot
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
case "fill": {
|
|
1270
|
+
const selector = toolInput.selector;
|
|
1271
|
+
const value = toolInput.value;
|
|
1272
|
+
await page.fill(selector, value);
|
|
1273
|
+
return {
|
|
1274
|
+
result: `Filled "${selector}" with value`
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
case "select_option": {
|
|
1278
|
+
const selector = toolInput.selector;
|
|
1279
|
+
const value = toolInput.value;
|
|
1280
|
+
await page.selectOption(selector, value);
|
|
1281
|
+
return {
|
|
1282
|
+
result: `Selected option "${value}" in ${selector}`
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
case "screenshot": {
|
|
1286
|
+
const screenshot = await screenshotter.capture(page, {
|
|
1287
|
+
runId: context.runId,
|
|
1288
|
+
scenarioSlug: context.scenarioSlug,
|
|
1289
|
+
stepNumber: context.stepNumber,
|
|
1290
|
+
action: "screenshot"
|
|
1291
|
+
});
|
|
1292
|
+
return {
|
|
1293
|
+
result: "Screenshot captured",
|
|
1294
|
+
screenshot
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
case "get_text": {
|
|
1298
|
+
const selector = toolInput.selector;
|
|
1299
|
+
const text = await page.locator(selector).textContent();
|
|
1300
|
+
return {
|
|
1301
|
+
result: text ?? "(no text content)"
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
case "get_url": {
|
|
1305
|
+
return {
|
|
1306
|
+
result: page.url()
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
case "wait_for": {
|
|
1310
|
+
const selector = toolInput.selector;
|
|
1311
|
+
const timeout = typeof toolInput.timeout === "number" ? toolInput.timeout : 1e4;
|
|
1312
|
+
await page.waitForSelector(selector, { timeout });
|
|
1313
|
+
return {
|
|
1314
|
+
result: `Element "${selector}" appeared`
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
case "go_back": {
|
|
1318
|
+
await page.goBack();
|
|
1319
|
+
return {
|
|
1320
|
+
result: "Navigated back"
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
case "press_key": {
|
|
1324
|
+
const key = toolInput.key;
|
|
1325
|
+
await page.keyboard.press(key);
|
|
1326
|
+
return {
|
|
1327
|
+
result: `Pressed key: ${key}`
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
case "assert_visible": {
|
|
1331
|
+
const selector = toolInput.selector;
|
|
1332
|
+
try {
|
|
1333
|
+
const visible = await page.locator(selector).isVisible();
|
|
1334
|
+
return { result: visible ? "true" : "false" };
|
|
1335
|
+
} catch {
|
|
1336
|
+
return { result: "false" };
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
case "assert_text": {
|
|
1340
|
+
const text = toolInput.text;
|
|
1341
|
+
try {
|
|
1342
|
+
const bodyText = await page.locator("body").textContent();
|
|
1343
|
+
const found = bodyText ? bodyText.includes(text) : false;
|
|
1344
|
+
return { result: found ? "true" : "false" };
|
|
1345
|
+
} catch {
|
|
1346
|
+
return { result: "false" };
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
case "report_result": {
|
|
1350
|
+
const status = toolInput.status;
|
|
1351
|
+
const reasoning = toolInput.reasoning;
|
|
1352
|
+
return {
|
|
1353
|
+
result: `Test ${status}: ${reasoning}`
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
default:
|
|
1357
|
+
return { result: `Unknown tool: ${toolName}` };
|
|
1358
|
+
}
|
|
1359
|
+
} catch (error) {
|
|
1360
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1361
|
+
return { result: `Error executing ${toolName}: ${message}` };
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
async function runAgentLoop(options) {
|
|
1365
|
+
const {
|
|
1366
|
+
client,
|
|
1367
|
+
page,
|
|
1368
|
+
scenario,
|
|
1369
|
+
screenshotter,
|
|
1370
|
+
model,
|
|
1371
|
+
runId,
|
|
1372
|
+
maxTurns = 30
|
|
1373
|
+
} = options;
|
|
1374
|
+
const systemPrompt = [
|
|
1375
|
+
"You are a QA testing agent. Test the following scenario by interacting with the browser.",
|
|
1376
|
+
"Use the provided tools to navigate, click, fill forms, and verify results.",
|
|
1377
|
+
"When done, call report_result with your findings.",
|
|
1378
|
+
"Be methodical: navigate to the target page first, then follow the test steps.",
|
|
1379
|
+
"If a step fails, try reasonable alternatives before reporting failure.",
|
|
1380
|
+
"Always report a final result \u2014 never leave a test incomplete."
|
|
1381
|
+
].join(" ");
|
|
1382
|
+
const userParts = [
|
|
1383
|
+
`**Scenario:** ${scenario.name}`,
|
|
1384
|
+
`**Description:** ${scenario.description}`
|
|
1385
|
+
];
|
|
1386
|
+
if (scenario.targetPath) {
|
|
1387
|
+
userParts.push(`**Target Path:** ${scenario.targetPath}`);
|
|
1388
|
+
}
|
|
1389
|
+
if (scenario.steps.length > 0) {
|
|
1390
|
+
userParts.push("**Steps:**");
|
|
1391
|
+
for (let i = 0;i < scenario.steps.length; i++) {
|
|
1392
|
+
userParts.push(`${i + 1}. ${scenario.steps[i]}`);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
const userMessage = userParts.join(`
|
|
1396
|
+
`);
|
|
1397
|
+
const screenshots = [];
|
|
1398
|
+
let tokensUsed = 0;
|
|
1399
|
+
let stepNumber = 0;
|
|
1400
|
+
const scenarioSlug = scenario.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
1401
|
+
let messages = [
|
|
1402
|
+
{ role: "user", content: userMessage }
|
|
1403
|
+
];
|
|
1404
|
+
try {
|
|
1405
|
+
for (let turn = 0;turn < maxTurns; turn++) {
|
|
1406
|
+
const response = await client.messages.create({
|
|
1407
|
+
model,
|
|
1408
|
+
max_tokens: 4096,
|
|
1409
|
+
system: systemPrompt,
|
|
1410
|
+
tools: BROWSER_TOOLS,
|
|
1411
|
+
messages
|
|
1412
|
+
});
|
|
1413
|
+
if (response.usage) {
|
|
1414
|
+
tokensUsed += response.usage.input_tokens + response.usage.output_tokens;
|
|
1415
|
+
}
|
|
1416
|
+
const toolUseBlocks = response.content.filter((block) => block.type === "tool_use");
|
|
1417
|
+
if (toolUseBlocks.length === 0 && response.stop_reason === "end_turn") {
|
|
1418
|
+
const textBlocks = response.content.filter((block) => block.type === "text");
|
|
1419
|
+
const textReasoning = textBlocks.map((b) => b.text).join(`
|
|
1420
|
+
`);
|
|
1421
|
+
return {
|
|
1422
|
+
status: "error",
|
|
1423
|
+
reasoning: textReasoning || "Agent ended without calling report_result",
|
|
1424
|
+
stepsCompleted: stepNumber,
|
|
1425
|
+
tokensUsed,
|
|
1426
|
+
screenshots
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
const toolResults = [];
|
|
1430
|
+
for (const toolBlock of toolUseBlocks) {
|
|
1431
|
+
stepNumber++;
|
|
1432
|
+
const toolInput = toolBlock.input;
|
|
1433
|
+
const execResult = await executeTool(page, screenshotter, toolBlock.name, toolInput, { runId, scenarioSlug, stepNumber });
|
|
1434
|
+
if (execResult.screenshot) {
|
|
1435
|
+
screenshots.push({
|
|
1436
|
+
...execResult.screenshot,
|
|
1437
|
+
action: toolBlock.name,
|
|
1438
|
+
stepNumber
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
toolResults.push({
|
|
1442
|
+
type: "tool_result",
|
|
1443
|
+
tool_use_id: toolBlock.id,
|
|
1444
|
+
content: execResult.result
|
|
1445
|
+
});
|
|
1446
|
+
if (toolBlock.name === "report_result") {
|
|
1447
|
+
const status = toolInput.status;
|
|
1448
|
+
const reasoning = toolInput.reasoning;
|
|
1449
|
+
return {
|
|
1450
|
+
status,
|
|
1451
|
+
reasoning,
|
|
1452
|
+
stepsCompleted: stepNumber,
|
|
1453
|
+
tokensUsed,
|
|
1454
|
+
screenshots
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
messages = [
|
|
1459
|
+
...messages,
|
|
1460
|
+
{ role: "assistant", content: response.content },
|
|
1461
|
+
{ role: "user", content: toolResults }
|
|
1462
|
+
];
|
|
1463
|
+
}
|
|
1464
|
+
return {
|
|
1465
|
+
status: "error",
|
|
1466
|
+
reasoning: `Agent reached maximum turn limit (${maxTurns}) without reporting a result`,
|
|
1467
|
+
stepsCompleted: stepNumber,
|
|
1468
|
+
tokensUsed,
|
|
1469
|
+
screenshots
|
|
1470
|
+
};
|
|
1471
|
+
} catch (error) {
|
|
1472
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1473
|
+
throw new AIClientError(`Agent loop failed: ${message}`);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
function createClient(apiKey) {
|
|
1477
|
+
const key = apiKey ?? process.env["ANTHROPIC_API_KEY"];
|
|
1478
|
+
if (!key) {
|
|
1479
|
+
throw new AIClientError("No Anthropic API key provided. Set ANTHROPIC_API_KEY or pass it explicitly.");
|
|
1480
|
+
}
|
|
1481
|
+
return new Anthropic({ apiKey: key });
|
|
1482
|
+
}
|
|
1483
|
+
// src/lib/runner.ts
|
|
1484
|
+
var eventHandler = null;
|
|
1485
|
+
function onRunEvent(handler) {
|
|
1486
|
+
eventHandler = handler;
|
|
1487
|
+
}
|
|
1488
|
+
function emit(event) {
|
|
1489
|
+
if (eventHandler)
|
|
1490
|
+
eventHandler(event);
|
|
1491
|
+
}
|
|
1492
|
+
async function runSingleScenario(scenario, runId, options) {
|
|
1493
|
+
const config = loadConfig();
|
|
1494
|
+
const model = resolveModel2(options.model ?? scenario.model ?? config.defaultModel);
|
|
1495
|
+
const client = createClient(options.apiKey ?? config.anthropicApiKey);
|
|
1496
|
+
const screenshotter = new Screenshotter({
|
|
1497
|
+
baseDir: options.screenshotDir ?? config.screenshots.dir
|
|
1498
|
+
});
|
|
1499
|
+
const result = createResult({
|
|
1500
|
+
runId,
|
|
1501
|
+
scenarioId: scenario.id,
|
|
1502
|
+
model,
|
|
1503
|
+
stepsTotal: scenario.steps.length || 10
|
|
1504
|
+
});
|
|
1505
|
+
emit({ type: "scenario:start", scenarioId: scenario.id, scenarioName: scenario.name, resultId: result.id, runId });
|
|
1506
|
+
let browser = null;
|
|
1507
|
+
let page = null;
|
|
1508
|
+
try {
|
|
1509
|
+
browser = await launchBrowser({ headless: !(options.headed ?? false) });
|
|
1510
|
+
page = await getPage(browser, {
|
|
1511
|
+
viewport: config.browser.viewport
|
|
1512
|
+
});
|
|
1513
|
+
const targetUrl = scenario.targetPath ? `${options.url.replace(/\/$/, "")}${scenario.targetPath}` : options.url;
|
|
1514
|
+
await page.goto(targetUrl, { timeout: options.timeout ?? config.browser.timeout });
|
|
1515
|
+
const agentResult = await runAgentLoop({
|
|
1516
|
+
client,
|
|
1517
|
+
page,
|
|
1518
|
+
scenario,
|
|
1519
|
+
screenshotter,
|
|
1520
|
+
model,
|
|
1521
|
+
runId,
|
|
1522
|
+
maxTurns: 30
|
|
1523
|
+
});
|
|
1524
|
+
for (const ss of agentResult.screenshots) {
|
|
1525
|
+
createScreenshot({
|
|
1526
|
+
resultId: result.id,
|
|
1527
|
+
stepNumber: ss.stepNumber,
|
|
1528
|
+
action: ss.action,
|
|
1529
|
+
filePath: ss.filePath,
|
|
1530
|
+
width: ss.width,
|
|
1531
|
+
height: ss.height
|
|
1532
|
+
});
|
|
1533
|
+
emit({ type: "screenshot:captured", screenshotPath: ss.filePath, scenarioId: scenario.id, runId });
|
|
1534
|
+
}
|
|
1535
|
+
const updatedResult = updateResult(result.id, {
|
|
1536
|
+
status: agentResult.status,
|
|
1537
|
+
reasoning: agentResult.reasoning,
|
|
1538
|
+
stepsCompleted: agentResult.stepsCompleted,
|
|
1539
|
+
durationMs: Date.now() - new Date(result.createdAt).getTime(),
|
|
1540
|
+
tokensUsed: agentResult.tokensUsed,
|
|
1541
|
+
costCents: estimateCost(model, agentResult.tokensUsed)
|
|
1542
|
+
});
|
|
1543
|
+
const eventType = agentResult.status === "passed" ? "scenario:pass" : "scenario:fail";
|
|
1544
|
+
emit({ type: eventType, scenarioId: scenario.id, scenarioName: scenario.name, resultId: result.id, runId });
|
|
1545
|
+
return updatedResult;
|
|
1546
|
+
} catch (error) {
|
|
1547
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
1548
|
+
const updatedResult = updateResult(result.id, {
|
|
1549
|
+
status: "error",
|
|
1550
|
+
error: errorMsg,
|
|
1551
|
+
durationMs: Date.now() - new Date(result.createdAt).getTime()
|
|
1552
|
+
});
|
|
1553
|
+
emit({ type: "scenario:error", scenarioId: scenario.id, scenarioName: scenario.name, error: errorMsg, runId });
|
|
1554
|
+
return updatedResult;
|
|
1555
|
+
} finally {
|
|
1556
|
+
if (browser)
|
|
1557
|
+
await closeBrowser(browser);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
async function runBatch(scenarios, options) {
|
|
1561
|
+
const config = loadConfig();
|
|
1562
|
+
const model = resolveModel2(options.model ?? config.defaultModel);
|
|
1563
|
+
const parallel = options.parallel ?? 1;
|
|
1564
|
+
const run = createRun({
|
|
1565
|
+
url: options.url,
|
|
1566
|
+
model,
|
|
1567
|
+
headed: options.headed,
|
|
1568
|
+
parallel,
|
|
1569
|
+
projectId: options.projectId
|
|
1570
|
+
});
|
|
1571
|
+
updateRun(run.id, { status: "running", total: scenarios.length });
|
|
1572
|
+
const results = [];
|
|
1573
|
+
if (parallel <= 1) {
|
|
1574
|
+
for (const scenario of scenarios) {
|
|
1575
|
+
const result = await runSingleScenario(scenario, run.id, options);
|
|
1576
|
+
results.push(result);
|
|
1577
|
+
}
|
|
1578
|
+
} else {
|
|
1579
|
+
const queue = [...scenarios];
|
|
1580
|
+
const running = [];
|
|
1581
|
+
const processNext = async () => {
|
|
1582
|
+
const scenario = queue.shift();
|
|
1583
|
+
if (!scenario)
|
|
1584
|
+
return;
|
|
1585
|
+
const result = await runSingleScenario(scenario, run.id, options);
|
|
1586
|
+
results.push(result);
|
|
1587
|
+
await processNext();
|
|
1588
|
+
};
|
|
1589
|
+
const workers = Math.min(parallel, scenarios.length);
|
|
1590
|
+
for (let i = 0;i < workers; i++) {
|
|
1591
|
+
running.push(processNext());
|
|
1592
|
+
}
|
|
1593
|
+
await Promise.all(running);
|
|
1594
|
+
}
|
|
1595
|
+
const passed = results.filter((r) => r.status === "passed").length;
|
|
1596
|
+
const failed = results.filter((r) => r.status === "failed" || r.status === "error").length;
|
|
1597
|
+
const finalStatus = failed > 0 ? "failed" : "passed";
|
|
1598
|
+
const finalRun = updateRun(run.id, {
|
|
1599
|
+
status: finalStatus,
|
|
1600
|
+
passed,
|
|
1601
|
+
failed,
|
|
1602
|
+
total: scenarios.length,
|
|
1603
|
+
finished_at: new Date().toISOString()
|
|
1604
|
+
});
|
|
1605
|
+
emit({ type: "run:complete", runId: run.id });
|
|
1606
|
+
return { run: finalRun, results };
|
|
1607
|
+
}
|
|
1608
|
+
async function runByFilter(options) {
|
|
1609
|
+
let scenarios;
|
|
1610
|
+
if (options.scenarioIds && options.scenarioIds.length > 0) {
|
|
1611
|
+
const all = listScenarios({ projectId: options.projectId });
|
|
1612
|
+
scenarios = all.filter((s) => options.scenarioIds.includes(s.id) || options.scenarioIds.includes(s.shortId));
|
|
1613
|
+
} else {
|
|
1614
|
+
scenarios = listScenarios({
|
|
1615
|
+
projectId: options.projectId,
|
|
1616
|
+
tags: options.tags,
|
|
1617
|
+
priority: options.priority
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
if (scenarios.length === 0) {
|
|
1621
|
+
const config = loadConfig();
|
|
1622
|
+
const model = resolveModel2(options.model ?? config.defaultModel);
|
|
1623
|
+
const run = createRun({ url: options.url, model, projectId: options.projectId });
|
|
1624
|
+
updateRun(run.id, { status: "passed", total: 0, finished_at: new Date().toISOString() });
|
|
1625
|
+
return { run: getRun(run.id), results: [] };
|
|
1626
|
+
}
|
|
1627
|
+
return runBatch(scenarios, options);
|
|
1628
|
+
}
|
|
1629
|
+
function estimateCost(model, tokens) {
|
|
1630
|
+
const costs = {
|
|
1631
|
+
"claude-haiku-4-5-20251001": 0.1,
|
|
1632
|
+
"claude-sonnet-4-6-20260311": 0.9,
|
|
1633
|
+
"claude-opus-4-6-20260311": 3
|
|
1634
|
+
};
|
|
1635
|
+
const costPer1M = costs[model] ?? 0.5;
|
|
1636
|
+
return tokens / 1e6 * costPer1M * 100;
|
|
1637
|
+
}
|
|
1638
|
+
// node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
1639
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
1640
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
1641
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
1642
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
1643
|
+
var styles = {
|
|
1644
|
+
modifier: {
|
|
1645
|
+
reset: [0, 0],
|
|
1646
|
+
bold: [1, 22],
|
|
1647
|
+
dim: [2, 22],
|
|
1648
|
+
italic: [3, 23],
|
|
1649
|
+
underline: [4, 24],
|
|
1650
|
+
overline: [53, 55],
|
|
1651
|
+
inverse: [7, 27],
|
|
1652
|
+
hidden: [8, 28],
|
|
1653
|
+
strikethrough: [9, 29]
|
|
1654
|
+
},
|
|
1655
|
+
color: {
|
|
1656
|
+
black: [30, 39],
|
|
1657
|
+
red: [31, 39],
|
|
1658
|
+
green: [32, 39],
|
|
1659
|
+
yellow: [33, 39],
|
|
1660
|
+
blue: [34, 39],
|
|
1661
|
+
magenta: [35, 39],
|
|
1662
|
+
cyan: [36, 39],
|
|
1663
|
+
white: [37, 39],
|
|
1664
|
+
blackBright: [90, 39],
|
|
1665
|
+
gray: [90, 39],
|
|
1666
|
+
grey: [90, 39],
|
|
1667
|
+
redBright: [91, 39],
|
|
1668
|
+
greenBright: [92, 39],
|
|
1669
|
+
yellowBright: [93, 39],
|
|
1670
|
+
blueBright: [94, 39],
|
|
1671
|
+
magentaBright: [95, 39],
|
|
1672
|
+
cyanBright: [96, 39],
|
|
1673
|
+
whiteBright: [97, 39]
|
|
1674
|
+
},
|
|
1675
|
+
bgColor: {
|
|
1676
|
+
bgBlack: [40, 49],
|
|
1677
|
+
bgRed: [41, 49],
|
|
1678
|
+
bgGreen: [42, 49],
|
|
1679
|
+
bgYellow: [43, 49],
|
|
1680
|
+
bgBlue: [44, 49],
|
|
1681
|
+
bgMagenta: [45, 49],
|
|
1682
|
+
bgCyan: [46, 49],
|
|
1683
|
+
bgWhite: [47, 49],
|
|
1684
|
+
bgBlackBright: [100, 49],
|
|
1685
|
+
bgGray: [100, 49],
|
|
1686
|
+
bgGrey: [100, 49],
|
|
1687
|
+
bgRedBright: [101, 49],
|
|
1688
|
+
bgGreenBright: [102, 49],
|
|
1689
|
+
bgYellowBright: [103, 49],
|
|
1690
|
+
bgBlueBright: [104, 49],
|
|
1691
|
+
bgMagentaBright: [105, 49],
|
|
1692
|
+
bgCyanBright: [106, 49],
|
|
1693
|
+
bgWhiteBright: [107, 49]
|
|
1694
|
+
}
|
|
1695
|
+
};
|
|
1696
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
1697
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
1698
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
1699
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
1700
|
+
function assembleStyles() {
|
|
1701
|
+
const codes = new Map;
|
|
1702
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
1703
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
1704
|
+
styles[styleName] = {
|
|
1705
|
+
open: `\x1B[${style[0]}m`,
|
|
1706
|
+
close: `\x1B[${style[1]}m`
|
|
1707
|
+
};
|
|
1708
|
+
group[styleName] = styles[styleName];
|
|
1709
|
+
codes.set(style[0], style[1]);
|
|
1710
|
+
}
|
|
1711
|
+
Object.defineProperty(styles, groupName, {
|
|
1712
|
+
value: group,
|
|
1713
|
+
enumerable: false
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
Object.defineProperty(styles, "codes", {
|
|
1717
|
+
value: codes,
|
|
1718
|
+
enumerable: false
|
|
1719
|
+
});
|
|
1720
|
+
styles.color.close = "\x1B[39m";
|
|
1721
|
+
styles.bgColor.close = "\x1B[49m";
|
|
1722
|
+
styles.color.ansi = wrapAnsi16();
|
|
1723
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
1724
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
1725
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
1726
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
1727
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
1728
|
+
Object.defineProperties(styles, {
|
|
1729
|
+
rgbToAnsi256: {
|
|
1730
|
+
value(red, green, blue) {
|
|
1731
|
+
if (red === green && green === blue) {
|
|
1732
|
+
if (red < 8) {
|
|
1733
|
+
return 16;
|
|
1734
|
+
}
|
|
1735
|
+
if (red > 248) {
|
|
1736
|
+
return 231;
|
|
1737
|
+
}
|
|
1738
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
1739
|
+
}
|
|
1740
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
1741
|
+
},
|
|
1742
|
+
enumerable: false
|
|
1743
|
+
},
|
|
1744
|
+
hexToRgb: {
|
|
1745
|
+
value(hex) {
|
|
1746
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
1747
|
+
if (!matches) {
|
|
1748
|
+
return [0, 0, 0];
|
|
1749
|
+
}
|
|
1750
|
+
let [colorString] = matches;
|
|
1751
|
+
if (colorString.length === 3) {
|
|
1752
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
1753
|
+
}
|
|
1754
|
+
const integer = Number.parseInt(colorString, 16);
|
|
1755
|
+
return [
|
|
1756
|
+
integer >> 16 & 255,
|
|
1757
|
+
integer >> 8 & 255,
|
|
1758
|
+
integer & 255
|
|
1759
|
+
];
|
|
1760
|
+
},
|
|
1761
|
+
enumerable: false
|
|
1762
|
+
},
|
|
1763
|
+
hexToAnsi256: {
|
|
1764
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
1765
|
+
enumerable: false
|
|
1766
|
+
},
|
|
1767
|
+
ansi256ToAnsi: {
|
|
1768
|
+
value(code) {
|
|
1769
|
+
if (code < 8) {
|
|
1770
|
+
return 30 + code;
|
|
1771
|
+
}
|
|
1772
|
+
if (code < 16) {
|
|
1773
|
+
return 90 + (code - 8);
|
|
1774
|
+
}
|
|
1775
|
+
let red;
|
|
1776
|
+
let green;
|
|
1777
|
+
let blue;
|
|
1778
|
+
if (code >= 232) {
|
|
1779
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
1780
|
+
green = red;
|
|
1781
|
+
blue = red;
|
|
1782
|
+
} else {
|
|
1783
|
+
code -= 16;
|
|
1784
|
+
const remainder = code % 36;
|
|
1785
|
+
red = Math.floor(code / 36) / 5;
|
|
1786
|
+
green = Math.floor(remainder / 6) / 5;
|
|
1787
|
+
blue = remainder % 6 / 5;
|
|
1788
|
+
}
|
|
1789
|
+
const value = Math.max(red, green, blue) * 2;
|
|
1790
|
+
if (value === 0) {
|
|
1791
|
+
return 30;
|
|
1792
|
+
}
|
|
1793
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
1794
|
+
if (value === 2) {
|
|
1795
|
+
result += 60;
|
|
1796
|
+
}
|
|
1797
|
+
return result;
|
|
1798
|
+
},
|
|
1799
|
+
enumerable: false
|
|
1800
|
+
},
|
|
1801
|
+
rgbToAnsi: {
|
|
1802
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
1803
|
+
enumerable: false
|
|
1804
|
+
},
|
|
1805
|
+
hexToAnsi: {
|
|
1806
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
1807
|
+
enumerable: false
|
|
1808
|
+
}
|
|
1809
|
+
});
|
|
1810
|
+
return styles;
|
|
1811
|
+
}
|
|
1812
|
+
var ansiStyles = assembleStyles();
|
|
1813
|
+
var ansi_styles_default = ansiStyles;
|
|
1814
|
+
|
|
1815
|
+
// node_modules/chalk/source/vendor/supports-color/index.js
|
|
1816
|
+
import process2 from "process";
|
|
1817
|
+
import os from "os";
|
|
1818
|
+
import tty from "tty";
|
|
1819
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
|
|
1820
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
1821
|
+
const position = argv.indexOf(prefix + flag);
|
|
1822
|
+
const terminatorPosition = argv.indexOf("--");
|
|
1823
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
1824
|
+
}
|
|
1825
|
+
var { env } = process2;
|
|
1826
|
+
var flagForceColor;
|
|
1827
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
1828
|
+
flagForceColor = 0;
|
|
1829
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
1830
|
+
flagForceColor = 1;
|
|
1831
|
+
}
|
|
1832
|
+
function envForceColor() {
|
|
1833
|
+
if ("FORCE_COLOR" in env) {
|
|
1834
|
+
if (env.FORCE_COLOR === "true") {
|
|
1835
|
+
return 1;
|
|
1836
|
+
}
|
|
1837
|
+
if (env.FORCE_COLOR === "false") {
|
|
1838
|
+
return 0;
|
|
1839
|
+
}
|
|
1840
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
function translateLevel(level) {
|
|
1844
|
+
if (level === 0) {
|
|
1845
|
+
return false;
|
|
1846
|
+
}
|
|
1847
|
+
return {
|
|
1848
|
+
level,
|
|
1849
|
+
hasBasic: true,
|
|
1850
|
+
has256: level >= 2,
|
|
1851
|
+
has16m: level >= 3
|
|
1852
|
+
};
|
|
1853
|
+
}
|
|
1854
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
1855
|
+
const noFlagForceColor = envForceColor();
|
|
1856
|
+
if (noFlagForceColor !== undefined) {
|
|
1857
|
+
flagForceColor = noFlagForceColor;
|
|
1858
|
+
}
|
|
1859
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
1860
|
+
if (forceColor === 0) {
|
|
1861
|
+
return 0;
|
|
1862
|
+
}
|
|
1863
|
+
if (sniffFlags) {
|
|
1864
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
1865
|
+
return 3;
|
|
1866
|
+
}
|
|
1867
|
+
if (hasFlag("color=256")) {
|
|
1868
|
+
return 2;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
1872
|
+
return 1;
|
|
1873
|
+
}
|
|
1874
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
1875
|
+
return 0;
|
|
1876
|
+
}
|
|
1877
|
+
const min = forceColor || 0;
|
|
1878
|
+
if (env.TERM === "dumb") {
|
|
1879
|
+
return min;
|
|
1880
|
+
}
|
|
1881
|
+
if (process2.platform === "win32") {
|
|
1882
|
+
const osRelease = os.release().split(".");
|
|
1883
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
1884
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
1885
|
+
}
|
|
1886
|
+
return 1;
|
|
1887
|
+
}
|
|
1888
|
+
if ("CI" in env) {
|
|
1889
|
+
if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => (key in env))) {
|
|
1890
|
+
return 3;
|
|
1891
|
+
}
|
|
1892
|
+
if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
|
|
1893
|
+
return 1;
|
|
1894
|
+
}
|
|
1895
|
+
return min;
|
|
1896
|
+
}
|
|
1897
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
1898
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
1899
|
+
}
|
|
1900
|
+
if (env.COLORTERM === "truecolor") {
|
|
1901
|
+
return 3;
|
|
1902
|
+
}
|
|
1903
|
+
if (env.TERM === "xterm-kitty") {
|
|
1904
|
+
return 3;
|
|
1905
|
+
}
|
|
1906
|
+
if (env.TERM === "xterm-ghostty") {
|
|
1907
|
+
return 3;
|
|
1908
|
+
}
|
|
1909
|
+
if (env.TERM === "wezterm") {
|
|
1910
|
+
return 3;
|
|
1911
|
+
}
|
|
1912
|
+
if ("TERM_PROGRAM" in env) {
|
|
1913
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
1914
|
+
switch (env.TERM_PROGRAM) {
|
|
1915
|
+
case "iTerm.app": {
|
|
1916
|
+
return version >= 3 ? 3 : 2;
|
|
1917
|
+
}
|
|
1918
|
+
case "Apple_Terminal": {
|
|
1919
|
+
return 2;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
1924
|
+
return 2;
|
|
1925
|
+
}
|
|
1926
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
1927
|
+
return 1;
|
|
1928
|
+
}
|
|
1929
|
+
if ("COLORTERM" in env) {
|
|
1930
|
+
return 1;
|
|
1931
|
+
}
|
|
1932
|
+
return min;
|
|
1933
|
+
}
|
|
1934
|
+
function createSupportsColor(stream, options = {}) {
|
|
1935
|
+
const level = _supportsColor(stream, {
|
|
1936
|
+
streamIsTTY: stream && stream.isTTY,
|
|
1937
|
+
...options
|
|
1938
|
+
});
|
|
1939
|
+
return translateLevel(level);
|
|
1940
|
+
}
|
|
1941
|
+
var supportsColor = {
|
|
1942
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
1943
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
1944
|
+
};
|
|
1945
|
+
var supports_color_default = supportsColor;
|
|
1946
|
+
|
|
1947
|
+
// node_modules/chalk/source/utilities.js
|
|
1948
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
1949
|
+
let index = string.indexOf(substring);
|
|
1950
|
+
if (index === -1) {
|
|
1951
|
+
return string;
|
|
1952
|
+
}
|
|
1953
|
+
const substringLength = substring.length;
|
|
1954
|
+
let endIndex = 0;
|
|
1955
|
+
let returnValue = "";
|
|
1956
|
+
do {
|
|
1957
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
1958
|
+
endIndex = index + substringLength;
|
|
1959
|
+
index = string.indexOf(substring, endIndex);
|
|
1960
|
+
} while (index !== -1);
|
|
1961
|
+
returnValue += string.slice(endIndex);
|
|
1962
|
+
return returnValue;
|
|
1963
|
+
}
|
|
1964
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
1965
|
+
let endIndex = 0;
|
|
1966
|
+
let returnValue = "";
|
|
1967
|
+
do {
|
|
1968
|
+
const gotCR = string[index - 1] === "\r";
|
|
1969
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
|
|
1970
|
+
` : `
|
|
1971
|
+
`) + postfix;
|
|
1972
|
+
endIndex = index + 1;
|
|
1973
|
+
index = string.indexOf(`
|
|
1974
|
+
`, endIndex);
|
|
1975
|
+
} while (index !== -1);
|
|
1976
|
+
returnValue += string.slice(endIndex);
|
|
1977
|
+
return returnValue;
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
// node_modules/chalk/source/index.js
|
|
1981
|
+
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
|
1982
|
+
var GENERATOR = Symbol("GENERATOR");
|
|
1983
|
+
var STYLER = Symbol("STYLER");
|
|
1984
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
1985
|
+
var levelMapping = [
|
|
1986
|
+
"ansi",
|
|
1987
|
+
"ansi",
|
|
1988
|
+
"ansi256",
|
|
1989
|
+
"ansi16m"
|
|
1990
|
+
];
|
|
1991
|
+
var styles2 = Object.create(null);
|
|
1992
|
+
var applyOptions = (object, options = {}) => {
|
|
1993
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
1994
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
1995
|
+
}
|
|
1996
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
1997
|
+
object.level = options.level === undefined ? colorLevel : options.level;
|
|
1998
|
+
};
|
|
1999
|
+
var chalkFactory = (options) => {
|
|
2000
|
+
const chalk = (...strings) => strings.join(" ");
|
|
2001
|
+
applyOptions(chalk, options);
|
|
2002
|
+
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
2003
|
+
return chalk;
|
|
2004
|
+
};
|
|
2005
|
+
function createChalk(options) {
|
|
2006
|
+
return chalkFactory(options);
|
|
2007
|
+
}
|
|
2008
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
2009
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
2010
|
+
styles2[styleName] = {
|
|
2011
|
+
get() {
|
|
2012
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
2013
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
2014
|
+
return builder;
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
styles2.visible = {
|
|
2019
|
+
get() {
|
|
2020
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
2021
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
2022
|
+
return builder;
|
|
2023
|
+
}
|
|
2024
|
+
};
|
|
2025
|
+
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
2026
|
+
if (model === "rgb") {
|
|
2027
|
+
if (level === "ansi16m") {
|
|
2028
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
2029
|
+
}
|
|
2030
|
+
if (level === "ansi256") {
|
|
2031
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
2032
|
+
}
|
|
2033
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
2034
|
+
}
|
|
2035
|
+
if (model === "hex") {
|
|
2036
|
+
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
2037
|
+
}
|
|
2038
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
2039
|
+
};
|
|
2040
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
|
2041
|
+
for (const model of usedModels) {
|
|
2042
|
+
styles2[model] = {
|
|
2043
|
+
get() {
|
|
2044
|
+
const { level } = this;
|
|
2045
|
+
return function(...arguments_) {
|
|
2046
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
2047
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
2052
|
+
styles2[bgModel] = {
|
|
2053
|
+
get() {
|
|
2054
|
+
const { level } = this;
|
|
2055
|
+
return function(...arguments_) {
|
|
2056
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
2057
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
2058
|
+
};
|
|
2059
|
+
}
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
var proto = Object.defineProperties(() => {}, {
|
|
2063
|
+
...styles2,
|
|
2064
|
+
level: {
|
|
2065
|
+
enumerable: true,
|
|
2066
|
+
get() {
|
|
2067
|
+
return this[GENERATOR].level;
|
|
2068
|
+
},
|
|
2069
|
+
set(level) {
|
|
2070
|
+
this[GENERATOR].level = level;
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
});
|
|
2074
|
+
var createStyler = (open, close, parent) => {
|
|
2075
|
+
let openAll;
|
|
2076
|
+
let closeAll;
|
|
2077
|
+
if (parent === undefined) {
|
|
2078
|
+
openAll = open;
|
|
2079
|
+
closeAll = close;
|
|
2080
|
+
} else {
|
|
2081
|
+
openAll = parent.openAll + open;
|
|
2082
|
+
closeAll = close + parent.closeAll;
|
|
2083
|
+
}
|
|
2084
|
+
return {
|
|
2085
|
+
open,
|
|
2086
|
+
close,
|
|
2087
|
+
openAll,
|
|
2088
|
+
closeAll,
|
|
2089
|
+
parent
|
|
2090
|
+
};
|
|
2091
|
+
};
|
|
2092
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
2093
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
2094
|
+
Object.setPrototypeOf(builder, proto);
|
|
2095
|
+
builder[GENERATOR] = self;
|
|
2096
|
+
builder[STYLER] = _styler;
|
|
2097
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
2098
|
+
return builder;
|
|
2099
|
+
};
|
|
2100
|
+
var applyStyle = (self, string) => {
|
|
2101
|
+
if (self.level <= 0 || !string) {
|
|
2102
|
+
return self[IS_EMPTY] ? "" : string;
|
|
2103
|
+
}
|
|
2104
|
+
let styler = self[STYLER];
|
|
2105
|
+
if (styler === undefined) {
|
|
2106
|
+
return string;
|
|
2107
|
+
}
|
|
2108
|
+
const { openAll, closeAll } = styler;
|
|
2109
|
+
if (string.includes("\x1B")) {
|
|
2110
|
+
while (styler !== undefined) {
|
|
2111
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
2112
|
+
styler = styler.parent;
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
const lfIndex = string.indexOf(`
|
|
2116
|
+
`);
|
|
2117
|
+
if (lfIndex !== -1) {
|
|
2118
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
2119
|
+
}
|
|
2120
|
+
return openAll + string + closeAll;
|
|
2121
|
+
};
|
|
2122
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
2123
|
+
var chalk = createChalk();
|
|
2124
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
2125
|
+
var source_default = chalk;
|
|
2126
|
+
|
|
2127
|
+
// src/lib/reporter.ts
|
|
2128
|
+
function formatTerminal(run, results) {
|
|
2129
|
+
const lines = [];
|
|
2130
|
+
lines.push("");
|
|
2131
|
+
lines.push(source_default.bold(` Run ${run.id.slice(0, 8)} \u2014 ${run.url}`));
|
|
2132
|
+
lines.push(source_default.dim(` Model: ${run.model} | Parallel: ${run.parallel} | Headed: ${run.headed ? "yes" : "no"}`));
|
|
2133
|
+
lines.push("");
|
|
2134
|
+
for (const result of results) {
|
|
2135
|
+
const scenario = getScenario(result.scenarioId);
|
|
2136
|
+
const name = scenario ? `${scenario.shortId}: ${scenario.name}` : result.scenarioId.slice(0, 8);
|
|
2137
|
+
const screenshots = listScreenshots(result.id);
|
|
2138
|
+
const duration = `${(result.durationMs / 1000).toFixed(1)}s`;
|
|
2139
|
+
const screenshotCount = screenshots.length;
|
|
2140
|
+
let statusIcon;
|
|
2141
|
+
let statusColor;
|
|
2142
|
+
switch (result.status) {
|
|
2143
|
+
case "passed":
|
|
2144
|
+
statusIcon = source_default.green("PASS");
|
|
2145
|
+
statusColor = source_default.green;
|
|
2146
|
+
break;
|
|
2147
|
+
case "failed":
|
|
2148
|
+
statusIcon = source_default.red("FAIL");
|
|
2149
|
+
statusColor = source_default.red;
|
|
2150
|
+
break;
|
|
2151
|
+
case "error":
|
|
2152
|
+
statusIcon = source_default.yellow("ERR ");
|
|
2153
|
+
statusColor = source_default.yellow;
|
|
2154
|
+
break;
|
|
2155
|
+
default:
|
|
2156
|
+
statusIcon = source_default.dim("SKIP");
|
|
2157
|
+
statusColor = source_default.dim;
|
|
2158
|
+
break;
|
|
2159
|
+
}
|
|
2160
|
+
lines.push(` ${statusIcon} ${statusColor(name)} ${source_default.dim(duration)} ${source_default.dim(`${screenshotCount} screenshots`)}`);
|
|
2161
|
+
if (result.reasoning && (result.status === "failed" || result.status === "error")) {
|
|
2162
|
+
lines.push(source_default.dim(` ${result.reasoning}`));
|
|
2163
|
+
}
|
|
2164
|
+
if (result.error) {
|
|
2165
|
+
lines.push(source_default.red(` ${result.error}`));
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
lines.push("");
|
|
2169
|
+
lines.push(formatSummary(run));
|
|
2170
|
+
lines.push("");
|
|
2171
|
+
return lines.join(`
|
|
2172
|
+
`);
|
|
2173
|
+
}
|
|
2174
|
+
function formatSummary(run) {
|
|
2175
|
+
const duration = run.finishedAt ? `${((new Date(run.finishedAt).getTime() - new Date(run.startedAt).getTime()) / 1000).toFixed(1)}s` : "running";
|
|
2176
|
+
const passedStr = source_default.green(`${run.passed} passed`);
|
|
2177
|
+
const failedStr = run.failed > 0 ? source_default.red(` ${run.failed} failed`) : "";
|
|
2178
|
+
const totalStr = source_default.dim(` (${run.total} total)`);
|
|
2179
|
+
return ` ${passedStr}${failedStr}${totalStr} in ${duration}`;
|
|
2180
|
+
}
|
|
2181
|
+
function formatJSON(run, results) {
|
|
2182
|
+
const output = {
|
|
2183
|
+
run: {
|
|
2184
|
+
id: run.id,
|
|
2185
|
+
url: run.url,
|
|
2186
|
+
status: run.status,
|
|
2187
|
+
model: run.model,
|
|
2188
|
+
headed: run.headed,
|
|
2189
|
+
parallel: run.parallel,
|
|
2190
|
+
total: run.total,
|
|
2191
|
+
passed: run.passed,
|
|
2192
|
+
failed: run.failed,
|
|
2193
|
+
startedAt: run.startedAt,
|
|
2194
|
+
finishedAt: run.finishedAt
|
|
2195
|
+
},
|
|
2196
|
+
results: results.map((r) => {
|
|
2197
|
+
const scenario = getScenario(r.scenarioId);
|
|
2198
|
+
const screenshots = listScreenshots(r.id);
|
|
2199
|
+
return {
|
|
2200
|
+
id: r.id,
|
|
2201
|
+
scenarioId: r.scenarioId,
|
|
2202
|
+
scenarioName: scenario?.name ?? null,
|
|
2203
|
+
scenarioShortId: scenario?.shortId ?? null,
|
|
2204
|
+
status: r.status,
|
|
2205
|
+
reasoning: r.reasoning,
|
|
2206
|
+
error: r.error,
|
|
2207
|
+
stepsCompleted: r.stepsCompleted,
|
|
2208
|
+
stepsTotal: r.stepsTotal,
|
|
2209
|
+
durationMs: r.durationMs,
|
|
2210
|
+
model: r.model,
|
|
2211
|
+
tokensUsed: r.tokensUsed,
|
|
2212
|
+
costCents: r.costCents,
|
|
2213
|
+
screenshots: screenshots.map((s) => ({
|
|
2214
|
+
stepNumber: s.stepNumber,
|
|
2215
|
+
action: s.action,
|
|
2216
|
+
filePath: s.filePath
|
|
2217
|
+
}))
|
|
2218
|
+
};
|
|
2219
|
+
}),
|
|
2220
|
+
summary: {
|
|
2221
|
+
total: run.total,
|
|
2222
|
+
passed: run.passed,
|
|
2223
|
+
failed: run.failed,
|
|
2224
|
+
totalTokens: results.reduce((sum, r) => sum + r.tokensUsed, 0),
|
|
2225
|
+
totalCostCents: results.reduce((sum, r) => sum + r.costCents, 0),
|
|
2226
|
+
durationMs: run.finishedAt ? new Date(run.finishedAt).getTime() - new Date(run.startedAt).getTime() : null
|
|
2227
|
+
}
|
|
2228
|
+
};
|
|
2229
|
+
return JSON.stringify(output, null, 2);
|
|
2230
|
+
}
|
|
2231
|
+
function getExitCode(run) {
|
|
2232
|
+
if (run.status === "passed")
|
|
2233
|
+
return 0;
|
|
2234
|
+
if (run.status === "failed")
|
|
2235
|
+
return 1;
|
|
2236
|
+
return 2;
|
|
2237
|
+
}
|
|
2238
|
+
function formatRunList(runs) {
|
|
2239
|
+
const lines = [];
|
|
2240
|
+
lines.push("");
|
|
2241
|
+
lines.push(source_default.bold(" Recent Runs"));
|
|
2242
|
+
lines.push("");
|
|
2243
|
+
if (runs.length === 0) {
|
|
2244
|
+
lines.push(source_default.dim(" No runs found."));
|
|
2245
|
+
lines.push("");
|
|
2246
|
+
return lines.join(`
|
|
2247
|
+
`);
|
|
2248
|
+
}
|
|
2249
|
+
for (const run of runs) {
|
|
2250
|
+
const statusIcon = run.status === "passed" ? source_default.green("PASS") : run.status === "failed" ? source_default.red("FAIL") : run.status === "running" ? source_default.blue("RUN ") : source_default.dim(run.status.toUpperCase().padEnd(4));
|
|
2251
|
+
const date = new Date(run.startedAt).toLocaleString();
|
|
2252
|
+
const id = run.id.slice(0, 8);
|
|
2253
|
+
lines.push(` ${statusIcon} ${source_default.dim(id)} ${run.url} ${source_default.dim(`${run.passed}/${run.total}`)} ${source_default.dim(date)}`);
|
|
2254
|
+
}
|
|
2255
|
+
lines.push("");
|
|
2256
|
+
return lines.join(`
|
|
2257
|
+
`);
|
|
2258
|
+
}
|
|
2259
|
+
function formatScenarioList(scenarios) {
|
|
2260
|
+
const lines = [];
|
|
2261
|
+
lines.push("");
|
|
2262
|
+
lines.push(source_default.bold(" Scenarios"));
|
|
2263
|
+
lines.push("");
|
|
2264
|
+
if (scenarios.length === 0) {
|
|
2265
|
+
lines.push(source_default.dim(" No scenarios found. Use 'testers add' to create one."));
|
|
2266
|
+
lines.push("");
|
|
2267
|
+
return lines.join(`
|
|
2268
|
+
`);
|
|
2269
|
+
}
|
|
2270
|
+
for (const s of scenarios) {
|
|
2271
|
+
const priorityColor = s.priority === "critical" ? source_default.red : s.priority === "high" ? source_default.yellow : s.priority === "medium" ? source_default.blue : source_default.dim;
|
|
2272
|
+
const tags = s.tags.length > 0 ? source_default.dim(` [${s.tags.join(", ")}]`) : "";
|
|
2273
|
+
lines.push(` ${source_default.cyan(s.shortId)} ${s.name} ${priorityColor(s.priority)}${tags}`);
|
|
2274
|
+
}
|
|
2275
|
+
lines.push("");
|
|
2276
|
+
return lines.join(`
|
|
2277
|
+
`);
|
|
2278
|
+
}
|
|
2279
|
+
function formatResultDetail(result, screenshots) {
|
|
2280
|
+
const lines = [];
|
|
2281
|
+
const scenario = getScenario(result.scenarioId);
|
|
2282
|
+
lines.push("");
|
|
2283
|
+
lines.push(source_default.bold(` Result ${result.id.slice(0, 8)}`));
|
|
2284
|
+
if (scenario) {
|
|
2285
|
+
lines.push(` Scenario: ${scenario.shortId} \u2014 ${scenario.name}`);
|
|
2286
|
+
}
|
|
2287
|
+
lines.push(` Status: ${result.status === "passed" ? source_default.green("PASSED") : source_default.red(result.status.toUpperCase())}`);
|
|
2288
|
+
lines.push(` Model: ${result.model}`);
|
|
2289
|
+
lines.push(` Duration: ${(result.durationMs / 1000).toFixed(1)}s`);
|
|
2290
|
+
lines.push(` Steps: ${result.stepsCompleted}/${result.stepsTotal}`);
|
|
2291
|
+
lines.push(` Tokens: ${result.tokensUsed} (~$${(result.costCents / 100).toFixed(4)})`);
|
|
2292
|
+
if (result.reasoning) {
|
|
2293
|
+
lines.push("");
|
|
2294
|
+
lines.push(source_default.bold(" Reasoning:"));
|
|
2295
|
+
lines.push(` ${result.reasoning}`);
|
|
2296
|
+
}
|
|
2297
|
+
if (result.error) {
|
|
2298
|
+
lines.push("");
|
|
2299
|
+
lines.push(source_default.red.bold(" Error:"));
|
|
2300
|
+
lines.push(source_default.red(` ${result.error}`));
|
|
2301
|
+
}
|
|
2302
|
+
if (screenshots.length > 0) {
|
|
2303
|
+
lines.push("");
|
|
2304
|
+
lines.push(source_default.bold(` Screenshots (${screenshots.length}):`));
|
|
2305
|
+
for (const ss of screenshots) {
|
|
2306
|
+
lines.push(` ${source_default.dim(`${String(ss.stepNumber).padStart(3, "0")}`)} ${ss.action} \u2014 ${source_default.dim(ss.filePath)}`);
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
lines.push("");
|
|
2310
|
+
return lines.join(`
|
|
2311
|
+
`);
|
|
2312
|
+
}
|
|
2313
|
+
// src/lib/todos-connector.ts
|
|
2314
|
+
import { Database as Database2 } from "bun:sqlite";
|
|
2315
|
+
import { existsSync as existsSync4 } from "fs";
|
|
2316
|
+
import { join as join4 } from "path";
|
|
2317
|
+
import { homedir as homedir4 } from "os";
|
|
2318
|
+
function resolveTodosDbPath() {
|
|
2319
|
+
const envPath = process.env["TODOS_DB_PATH"];
|
|
2320
|
+
if (envPath)
|
|
2321
|
+
return envPath;
|
|
2322
|
+
return join4(homedir4(), ".todos", "todos.db");
|
|
2323
|
+
}
|
|
2324
|
+
function connectToTodos() {
|
|
2325
|
+
const dbPath = resolveTodosDbPath();
|
|
2326
|
+
if (!existsSync4(dbPath)) {
|
|
2327
|
+
throw new TodosConnectionError(`Todos database not found at ${dbPath}. Install @hasna/todos or set TODOS_DB_PATH.`);
|
|
2328
|
+
}
|
|
2329
|
+
const db2 = new Database2(dbPath, { readonly: true });
|
|
2330
|
+
db2.exec("PRAGMA foreign_keys = ON");
|
|
2331
|
+
return db2;
|
|
2332
|
+
}
|
|
2333
|
+
function pullTasks(options = {}) {
|
|
2334
|
+
const db2 = connectToTodos();
|
|
2335
|
+
try {
|
|
2336
|
+
let query = "SELECT id, short_id, title, description, status, priority, tags, project_id FROM tasks WHERE 1=1";
|
|
2337
|
+
const params = [];
|
|
2338
|
+
if (options.status) {
|
|
2339
|
+
query += " AND status = ?";
|
|
2340
|
+
params.push(options.status);
|
|
2341
|
+
} else {
|
|
2342
|
+
query += " AND status IN ('pending', 'in_progress')";
|
|
2343
|
+
}
|
|
2344
|
+
if (options.priority) {
|
|
2345
|
+
query += " AND priority = ?";
|
|
2346
|
+
params.push(options.priority);
|
|
2347
|
+
}
|
|
2348
|
+
if (options.projectName) {
|
|
2349
|
+
const project = db2.query("SELECT id FROM projects WHERE name = ?").get(options.projectName);
|
|
2350
|
+
if (project) {
|
|
2351
|
+
query += " AND project_id = ?";
|
|
2352
|
+
params.push(project.id);
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
query += " ORDER BY CASE priority WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END";
|
|
2356
|
+
const tasks = db2.query(query).all(...params);
|
|
2357
|
+
if (options.tags && options.tags.length > 0) {
|
|
2358
|
+
return tasks.filter((task) => {
|
|
2359
|
+
const taskTags = JSON.parse(task.tags || "[]");
|
|
2360
|
+
return options.tags.some((tag) => taskTags.includes(tag));
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
return tasks;
|
|
2364
|
+
} finally {
|
|
2365
|
+
db2.close();
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
function taskToScenarioInput(task, projectId) {
|
|
2369
|
+
const tags = JSON.parse(task.tags || "[]");
|
|
2370
|
+
const priority = ["low", "medium", "high", "critical"].includes(task.priority) ? task.priority : "medium";
|
|
2371
|
+
const steps = [];
|
|
2372
|
+
if (task.description) {
|
|
2373
|
+
const lines = task.description.split(`
|
|
2374
|
+
`);
|
|
2375
|
+
for (const line of lines) {
|
|
2376
|
+
const match = line.match(/^\s*\d+[\.\)]\s*(.+)/);
|
|
2377
|
+
if (match?.[1]) {
|
|
2378
|
+
steps.push(match[1].trim());
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
return {
|
|
2383
|
+
name: task.title.replace(/^(OPE\d+-\d+|[A-Z]+-\d+):\s*/, ""),
|
|
2384
|
+
description: task.description || task.title,
|
|
2385
|
+
steps,
|
|
2386
|
+
tags,
|
|
2387
|
+
priority,
|
|
2388
|
+
projectId,
|
|
2389
|
+
metadata: { todosTaskId: task.id, todosShortId: task.short_id }
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
function importFromTodos(options = {}) {
|
|
2393
|
+
const tasks = pullTasks({
|
|
2394
|
+
projectName: options.projectName,
|
|
2395
|
+
tags: options.tags ?? ["qa", "test", "testing"],
|
|
2396
|
+
priority: options.priority
|
|
2397
|
+
});
|
|
2398
|
+
const existing = listScenarios({ projectId: options.projectId });
|
|
2399
|
+
const existingTodoIds = new Set(existing.filter((s) => s.metadata?.todosTaskId).map((s) => s.metadata.todosTaskId));
|
|
2400
|
+
let imported = 0;
|
|
2401
|
+
let skipped = 0;
|
|
2402
|
+
for (const task of tasks) {
|
|
2403
|
+
if (existingTodoIds.has(task.id)) {
|
|
2404
|
+
skipped++;
|
|
2405
|
+
continue;
|
|
2406
|
+
}
|
|
2407
|
+
const input = taskToScenarioInput(task, options.projectId);
|
|
2408
|
+
createScenario(input);
|
|
2409
|
+
imported++;
|
|
2410
|
+
}
|
|
2411
|
+
return { imported, skipped };
|
|
2412
|
+
}
|
|
2413
|
+
function markTodoDone(taskId) {
|
|
2414
|
+
const dbPath = resolveTodosDbPath();
|
|
2415
|
+
if (!existsSync4(dbPath))
|
|
2416
|
+
return false;
|
|
2417
|
+
const db2 = new Database2(dbPath);
|
|
2418
|
+
try {
|
|
2419
|
+
const task = db2.query("SELECT id, version FROM tasks WHERE id LIKE ? || '%'").get(taskId);
|
|
2420
|
+
if (!task)
|
|
2421
|
+
return false;
|
|
2422
|
+
db2.query("UPDATE tasks SET status = 'completed', completed_at = datetime('now'), version = version + 1, updated_at = datetime('now') WHERE id = ? AND version = ?").run(task.id, task.version);
|
|
2423
|
+
return true;
|
|
2424
|
+
} finally {
|
|
2425
|
+
db2.close();
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
export {
|
|
2429
|
+
uuid,
|
|
2430
|
+
updateScenario,
|
|
2431
|
+
updateRun,
|
|
2432
|
+
updateResult,
|
|
2433
|
+
taskToScenarioInput,
|
|
2434
|
+
slugify,
|
|
2435
|
+
shortUuid,
|
|
2436
|
+
screenshotFromRow,
|
|
2437
|
+
scenarioFromRow,
|
|
2438
|
+
runSingleScenario,
|
|
2439
|
+
runFromRow,
|
|
2440
|
+
runByFilter,
|
|
2441
|
+
runBatch,
|
|
2442
|
+
runAgentLoop,
|
|
2443
|
+
resultFromRow,
|
|
2444
|
+
resolvePartialId,
|
|
2445
|
+
resolveModel as resolveModelConfig,
|
|
2446
|
+
resolveModel2 as resolveModel,
|
|
2447
|
+
resetDatabase,
|
|
2448
|
+
registerAgent,
|
|
2449
|
+
pullTasks,
|
|
2450
|
+
projectFromRow,
|
|
2451
|
+
onRunEvent,
|
|
2452
|
+
now,
|
|
2453
|
+
markTodoDone,
|
|
2454
|
+
loadConfig,
|
|
2455
|
+
listScreenshots,
|
|
2456
|
+
listScenarios,
|
|
2457
|
+
listRuns,
|
|
2458
|
+
listResults,
|
|
2459
|
+
listProjects,
|
|
2460
|
+
listAgents,
|
|
2461
|
+
launchBrowser,
|
|
2462
|
+
installBrowser,
|
|
2463
|
+
importFromTodos,
|
|
2464
|
+
getScreenshotsByResult,
|
|
2465
|
+
getScreenshotDir,
|
|
2466
|
+
getScreenshot,
|
|
2467
|
+
getScenarioByShortId,
|
|
2468
|
+
getScenario,
|
|
2469
|
+
getRun,
|
|
2470
|
+
getResultsByRun,
|
|
2471
|
+
getResult,
|
|
2472
|
+
getProjectByPath,
|
|
2473
|
+
getProject,
|
|
2474
|
+
getPage,
|
|
2475
|
+
getExitCode,
|
|
2476
|
+
getDefaultConfig,
|
|
2477
|
+
getDatabase,
|
|
2478
|
+
getAgentByName,
|
|
2479
|
+
getAgent,
|
|
2480
|
+
generateFilename,
|
|
2481
|
+
formatTerminal,
|
|
2482
|
+
formatSummary,
|
|
2483
|
+
formatScenarioList,
|
|
2484
|
+
formatRunList,
|
|
2485
|
+
formatResultDetail,
|
|
2486
|
+
formatJSON,
|
|
2487
|
+
executeTool,
|
|
2488
|
+
ensureProject,
|
|
2489
|
+
ensureDir,
|
|
2490
|
+
deleteScenario,
|
|
2491
|
+
deleteRun,
|
|
2492
|
+
createScreenshot,
|
|
2493
|
+
createScenario,
|
|
2494
|
+
createRun,
|
|
2495
|
+
createResult,
|
|
2496
|
+
createProject,
|
|
2497
|
+
createClient,
|
|
2498
|
+
connectToTodos,
|
|
2499
|
+
closeDatabase,
|
|
2500
|
+
closeBrowser,
|
|
2501
|
+
agentFromRow,
|
|
2502
|
+
VersionConflictError,
|
|
2503
|
+
TodosConnectionError,
|
|
2504
|
+
Screenshotter,
|
|
2505
|
+
ScenarioNotFoundError,
|
|
2506
|
+
RunNotFoundError,
|
|
2507
|
+
ResultNotFoundError,
|
|
2508
|
+
ProjectNotFoundError,
|
|
2509
|
+
MODEL_MAP,
|
|
2510
|
+
BrowserPool,
|
|
2511
|
+
BrowserError,
|
|
2512
|
+
BROWSER_TOOLS,
|
|
2513
|
+
AgentNotFoundError,
|
|
2514
|
+
AIClientError
|
|
2515
|
+
};
|