@sedum-dev/core 0.1.0-alpha.4 → 0.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-C32TDS2U.js +100 -0
- package/dist/index.d.ts +335 -128
- package/dist/index.js +2652 -235
- package/dist/page-script/index.global.js +29 -3
- package/dist/run-result.schema.json +37 -3
- package/dist/script-api-D3if59MQ.d.ts +212 -0
- package/dist/script-api.d.ts +3 -0
- package/dist/script-api.js +12 -0
- package/package.json +8 -2
package/dist/index.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isSecret,
|
|
3
|
+
parseFrame,
|
|
4
|
+
pathKey,
|
|
5
|
+
revealSecret,
|
|
6
|
+
samePath,
|
|
7
|
+
scriptRegistry,
|
|
8
|
+
secret,
|
|
9
|
+
sourceInFile,
|
|
10
|
+
test
|
|
11
|
+
} from "./chunk-C32TDS2U.js";
|
|
12
|
+
|
|
1
13
|
// src/run-result.ts
|
|
2
14
|
import { z } from "zod";
|
|
3
15
|
var probability = z.number().finite().min(0).max(1);
|
|
4
16
|
var nonnegative = z.number().finite().nonnegative();
|
|
5
17
|
var count = z.number().int().nonnegative();
|
|
6
18
|
var verdict = z.enum(["passed", "failed"]);
|
|
7
|
-
var
|
|
19
|
+
var stepFlag = z.enum(["low_confidence", "contradiction"]);
|
|
20
|
+
var flag = z.enum(["low_confidence", "contradiction", "flaky"]);
|
|
8
21
|
var state = z.enum(["running", "completed", "interrupted", "error"]);
|
|
9
22
|
var ResultSourceSchema = z.strictObject({
|
|
10
23
|
file: z.string().min(1),
|
|
@@ -120,10 +133,12 @@ var ResultStepSchema = z.strictObject({
|
|
|
120
133
|
phase: z.enum(["before", "steps", "after"]),
|
|
121
134
|
sentence: z.string().max(512),
|
|
122
135
|
detail: z.string().max(512),
|
|
136
|
+
/** Enclosing `ai.group` names, outermost first; absent outside a group. */
|
|
137
|
+
group: z.array(z.string().max(120)).max(16).optional(),
|
|
123
138
|
sourceStack: z.array(ResultSourceSchema).min(1),
|
|
124
139
|
state,
|
|
125
140
|
verdict: verdict.nullable(),
|
|
126
|
-
flags: z.array(
|
|
141
|
+
flags: z.array(stepFlag),
|
|
127
142
|
elapsedMs: nonnegative,
|
|
128
143
|
page: ResultPageSchema,
|
|
129
144
|
locator: ResultLocatorSchema.nullable(),
|
|
@@ -205,7 +220,12 @@ var ResultExecutionSchema = z.strictObject({
|
|
|
205
220
|
count: z.number().int().positive(),
|
|
206
221
|
globalSelectedTests: count
|
|
207
222
|
}).nullable(),
|
|
208
|
-
providerConcurrency: z.number().int().positive()
|
|
223
|
+
providerConcurrency: z.number().int().positive(),
|
|
224
|
+
/** Present when vision fallback is enabled; `key` is checked before tests run. */
|
|
225
|
+
vision: z.strictObject({
|
|
226
|
+
model: z.string().min(1).max(200),
|
|
227
|
+
key: z.enum(["accepted", "rejected", "unreachable"])
|
|
228
|
+
}).optional()
|
|
209
229
|
});
|
|
210
230
|
var RunResultSchema = z.strictObject({
|
|
211
231
|
schemaVersion: z.literal(1),
|
|
@@ -236,13 +256,13 @@ var RunResultSchema = z.strictObject({
|
|
|
236
256
|
});
|
|
237
257
|
function resultTotals(tests, setupCalls = [], selectedTestCount = tests.length) {
|
|
238
258
|
const selected = tests.flatMap(
|
|
239
|
-
(
|
|
259
|
+
(test2) => test2.attempts.filter((attempt) => attempt.id === test2.selectedAttemptId)
|
|
240
260
|
);
|
|
241
261
|
const steps = selected.flatMap((attempt) => attempt.steps);
|
|
242
262
|
const calls = [
|
|
243
263
|
...setupCalls,
|
|
244
264
|
...tests.flatMap(
|
|
245
|
-
(
|
|
265
|
+
(test2) => test2.attempts.flatMap((attempt) => [
|
|
246
266
|
...attempt.calls ?? [],
|
|
247
267
|
...attempt.steps.flatMap((step) => step.calls)
|
|
248
268
|
])
|
|
@@ -251,13 +271,13 @@ function resultTotals(tests, setupCalls = [], selectedTestCount = tests.length)
|
|
|
251
271
|
const complete = calls.every((call2) => call2.costUsd !== null);
|
|
252
272
|
return {
|
|
253
273
|
selectedTests: selectedTestCount,
|
|
254
|
-
executedTests: tests.filter((
|
|
255
|
-
passedTests: tests.filter((
|
|
256
|
-
failedTests: tests.filter((
|
|
274
|
+
executedTests: tests.filter((test2) => test2.attempts.length > 0).length,
|
|
275
|
+
passedTests: tests.filter((test2) => test2.verdict === "passed").length,
|
|
276
|
+
failedTests: tests.filter((test2) => test2.verdict === "failed").length,
|
|
257
277
|
passedSteps: steps.filter((step) => step.verdict === "passed").length,
|
|
258
278
|
failedSteps: steps.filter((step) => step.verdict === "failed").length,
|
|
259
279
|
historicalAttempts: tests.reduce(
|
|
260
|
-
(sum,
|
|
280
|
+
(sum, test2) => sum + Math.max(0, test2.attempts.length - 1),
|
|
261
281
|
0
|
|
262
282
|
),
|
|
263
283
|
flaggedSteps: steps.filter((step) => step.flags.length > 0).length,
|
|
@@ -283,11 +303,11 @@ function validateRunResult(value) {
|
|
|
283
303
|
ids.add(id);
|
|
284
304
|
};
|
|
285
305
|
addId(result.runId);
|
|
286
|
-
for (const
|
|
287
|
-
addId(
|
|
288
|
-
if (
|
|
306
|
+
for (const test2 of result.tests) {
|
|
307
|
+
addId(test2.id);
|
|
308
|
+
if (test2.state === "completed" && (test2.verdict === null || test2.attempts.some((attempt) => attempt.state === "running")))
|
|
289
309
|
throw new Error("Completed test has incomplete attempts");
|
|
290
|
-
for (const attempt of
|
|
310
|
+
for (const attempt of test2.attempts) {
|
|
291
311
|
addId(attempt.id);
|
|
292
312
|
if (attempt.state === "completed" && (attempt.verdict === null || attempt.finishedAt === null))
|
|
293
313
|
throw new Error("Completed attempt has no verdict or finish time");
|
|
@@ -334,14 +354,14 @@ function validateRunResult(value) {
|
|
|
334
354
|
if (attempt.state === "error" && attempt.problems.length > 0 && primary?.outcome !== "error")
|
|
335
355
|
throw new Error("Error attempt needs an error primary problem");
|
|
336
356
|
}
|
|
337
|
-
const selected =
|
|
338
|
-
(attempt) => attempt.id ===
|
|
357
|
+
const selected = test2.attempts.find(
|
|
358
|
+
(attempt) => attempt.id === test2.selectedAttemptId
|
|
339
359
|
);
|
|
340
|
-
if (
|
|
360
|
+
if (test2.selectedAttemptId !== null && !selected)
|
|
341
361
|
throw new Error("Selected attempt is missing");
|
|
342
|
-
if (
|
|
362
|
+
if (test2.verdict !== (selected?.verdict ?? null))
|
|
343
363
|
throw new Error("Test verdict differs from selected attempt");
|
|
344
|
-
if (JSON.stringify(
|
|
364
|
+
if (JSON.stringify(test2.flags) !== JSON.stringify(selected?.flags ?? []))
|
|
345
365
|
throw new Error("Test flags differ from selected attempt");
|
|
346
366
|
}
|
|
347
367
|
if (JSON.stringify(result.totals) !== JSON.stringify(
|
|
@@ -352,13 +372,13 @@ function validateRunResult(value) {
|
|
|
352
372
|
)
|
|
353
373
|
))
|
|
354
374
|
throw new Error("Run totals differ from children");
|
|
355
|
-
const finalVerdict = result.error || result.state !== "completed" || result.tests.length === 0 ? null : result.tests.some((
|
|
375
|
+
const finalVerdict = result.error || result.state !== "completed" || result.tests.length === 0 ? null : result.tests.some((test2) => test2.verdict === "failed") ? "failed" : result.tests.every((test2) => test2.verdict === "passed") ? "passed" : null;
|
|
356
376
|
if (result.verdict !== finalVerdict)
|
|
357
377
|
throw new Error("Run verdict differs from tests");
|
|
358
|
-
const runFlags = [...new Set(result.tests.flatMap((
|
|
378
|
+
const runFlags = [...new Set(result.tests.flatMap((test2) => test2.flags))];
|
|
359
379
|
if (JSON.stringify(result.flags) !== JSON.stringify(runFlags))
|
|
360
380
|
throw new Error("Run flags differ from tests");
|
|
361
|
-
if (result.state === "completed" && (result.error !== null || result.tests.length === 0 || result.tests.some((
|
|
381
|
+
if (result.state === "completed" && (result.error !== null || result.tests.length === 0 || result.tests.some((test2) => test2.state !== "completed")))
|
|
362
382
|
throw new Error("Completed run has no completed tests");
|
|
363
383
|
if (result.state === "running" && result.finishedAt !== null)
|
|
364
384
|
throw new Error("Running run has finish time");
|
|
@@ -419,6 +439,10 @@ var TestRecording = class {
|
|
|
419
439
|
finishTest(verdict2) {
|
|
420
440
|
return this.recorder.finishTestFor(this.testId, verdict2);
|
|
421
441
|
}
|
|
442
|
+
/** Ends a running attempt that could not run; the run itself continues. */
|
|
443
|
+
errorTest(error2) {
|
|
444
|
+
return this.recorder.errorTestFor(this.testId, error2);
|
|
445
|
+
}
|
|
422
446
|
};
|
|
423
447
|
function newAttempt(runId, ordinal, lane) {
|
|
424
448
|
return {
|
|
@@ -483,28 +507,28 @@ var RunRecorder = class {
|
|
|
483
507
|
Math.max(this.value.selectedTestCount ?? 0, this.value.tests.length)
|
|
484
508
|
),
|
|
485
509
|
flags: [
|
|
486
|
-
...new Set(this.value.tests.flatMap((
|
|
510
|
+
...new Set(this.value.tests.flatMap((test2) => test2.flags))
|
|
487
511
|
]
|
|
488
512
|
};
|
|
489
513
|
await this.sink(validateRunResult(this.value));
|
|
490
514
|
}
|
|
491
515
|
/** @internal Handles read their test through here. */
|
|
492
516
|
testById(testId) {
|
|
493
|
-
const
|
|
494
|
-
if (!
|
|
495
|
-
return
|
|
517
|
+
const test2 = this.value.tests.find((entry) => entry.id === testId);
|
|
518
|
+
if (!test2) throw new Error("Unknown test");
|
|
519
|
+
return test2;
|
|
496
520
|
}
|
|
497
521
|
replaceTest(testId, update) {
|
|
498
522
|
this.value = {
|
|
499
523
|
...this.value,
|
|
500
524
|
tests: this.value.tests.map(
|
|
501
|
-
(
|
|
525
|
+
(test2) => test2.id === testId ? update(test2) : test2
|
|
502
526
|
)
|
|
503
527
|
};
|
|
504
528
|
}
|
|
505
529
|
replaceRunningAttempt(testId, update) {
|
|
506
|
-
const
|
|
507
|
-
const attempt =
|
|
530
|
+
const test2 = this.testById(testId);
|
|
531
|
+
const attempt = test2.attempts.at(-1);
|
|
508
532
|
if (!attempt || attempt.state !== "running")
|
|
509
533
|
throw new Error("No running attempt");
|
|
510
534
|
this.replaceTest(testId, (current) => ({
|
|
@@ -566,7 +590,7 @@ var RunRecorder = class {
|
|
|
566
590
|
if ([...this.ordinals.values()].includes(ordinal))
|
|
567
591
|
throw new Error("Test ordinal already started");
|
|
568
592
|
const attempt = newAttempt(this.value.runId, 1, input.lane);
|
|
569
|
-
const
|
|
593
|
+
const test2 = {
|
|
570
594
|
id: input.id,
|
|
571
595
|
file: input.file,
|
|
572
596
|
description: input.description ?? "",
|
|
@@ -580,9 +604,9 @@ var RunRecorder = class {
|
|
|
580
604
|
const position2 = this.value.tests.findIndex(
|
|
581
605
|
(entry) => (this.ordinals.get(entry.id) ?? 0) > ordinal
|
|
582
606
|
);
|
|
583
|
-
const tests = position2 === -1 ? [...this.value.tests,
|
|
607
|
+
const tests = position2 === -1 ? [...this.value.tests, test2] : [
|
|
584
608
|
...this.value.tests.slice(0, position2),
|
|
585
|
-
|
|
609
|
+
test2,
|
|
586
610
|
...this.value.tests.slice(position2)
|
|
587
611
|
];
|
|
588
612
|
this.ordinals.set(input.id, ordinal);
|
|
@@ -603,7 +627,7 @@ var RunRecorder = class {
|
|
|
603
627
|
}
|
|
604
628
|
/** @internal Use `TestRecording.setGoal` after resolving secret bindings. */
|
|
605
629
|
async setGoalFor(testId, goal) {
|
|
606
|
-
this.replaceTest(testId, (
|
|
630
|
+
this.replaceTest(testId, (test2) => ({ ...test2, goal }));
|
|
607
631
|
await this.publish();
|
|
608
632
|
}
|
|
609
633
|
/** @internal Use `TestRecording.addAttemptCalls`. */
|
|
@@ -670,12 +694,12 @@ var RunRecorder = class {
|
|
|
670
694
|
*/
|
|
671
695
|
async startAttemptFor(testId, lane) {
|
|
672
696
|
if (this.value.state !== "running") throw new Error("Run already finished");
|
|
673
|
-
const
|
|
674
|
-
if (
|
|
697
|
+
const test2 = this.testById(testId);
|
|
698
|
+
if (test2.attempts.at(-1)?.state === "running")
|
|
675
699
|
throw new Error("No terminal attempt to retry");
|
|
676
700
|
const attempt = newAttempt(
|
|
677
701
|
this.value.runId,
|
|
678
|
-
|
|
702
|
+
test2.attempts.length + 1,
|
|
679
703
|
lane
|
|
680
704
|
);
|
|
681
705
|
this.replaceTest(testId, (current) => ({
|
|
@@ -696,11 +720,15 @@ var RunRecorder = class {
|
|
|
696
720
|
}
|
|
697
721
|
/** @internal Use `TestRecording.finishTest`. */
|
|
698
722
|
async finishTestFor(testId, verdict2) {
|
|
699
|
-
const
|
|
700
|
-
const attempt =
|
|
723
|
+
const test2 = this.testById(testId);
|
|
724
|
+
const attempt = test2.attempts.at(-1);
|
|
701
725
|
if (!attempt) throw new Error("No test to finish");
|
|
726
|
+
const retriedPass = verdict2 === "passed" && test2.attempts.slice(0, -1).some((prior) => prior.verdict === "failed");
|
|
702
727
|
const flags = [
|
|
703
|
-
|
|
728
|
+
.../* @__PURE__ */ new Set([
|
|
729
|
+
...attempt.steps.flatMap((step) => step.flags),
|
|
730
|
+
...retriedPass ? ["flaky"] : []
|
|
731
|
+
])
|
|
704
732
|
];
|
|
705
733
|
const finished = (/* @__PURE__ */ new Date()).toISOString();
|
|
706
734
|
const updatedAttempt = {
|
|
@@ -723,6 +751,31 @@ var RunRecorder = class {
|
|
|
723
751
|
}));
|
|
724
752
|
await this.publish();
|
|
725
753
|
}
|
|
754
|
+
/** @internal Use `TestRecording.errorTest`. */
|
|
755
|
+
async errorTestFor(testId, error2) {
|
|
756
|
+
const test2 = this.testById(testId);
|
|
757
|
+
const attempt = test2.attempts.at(-1);
|
|
758
|
+
if (attempt?.state !== "running") return;
|
|
759
|
+
const finished = (/* @__PURE__ */ new Date()).toISOString();
|
|
760
|
+
const updatedAttempt = {
|
|
761
|
+
...attempt,
|
|
762
|
+
state: "error",
|
|
763
|
+
verdict: null,
|
|
764
|
+
error: error2,
|
|
765
|
+
finishedAt: finished,
|
|
766
|
+
elapsedMs: Math.max(
|
|
767
|
+
0,
|
|
768
|
+
Date.parse(finished) - Date.parse(attempt.startedAt)
|
|
769
|
+
)
|
|
770
|
+
};
|
|
771
|
+
this.replaceTest(testId, (current) => ({
|
|
772
|
+
...current,
|
|
773
|
+
state: "error",
|
|
774
|
+
verdict: null,
|
|
775
|
+
attempts: [...current.attempts.slice(0, -1), updatedAttempt]
|
|
776
|
+
}));
|
|
777
|
+
await this.publish();
|
|
778
|
+
}
|
|
726
779
|
async finishTest(verdict2) {
|
|
727
780
|
if (this.lastTestId === null) throw new Error("No test to finish");
|
|
728
781
|
await this.finishTestFor(this.lastTestId, verdict2);
|
|
@@ -735,9 +788,9 @@ var RunRecorder = class {
|
|
|
735
788
|
const runError = error2;
|
|
736
789
|
this.value = {
|
|
737
790
|
...this.value,
|
|
738
|
-
tests: this.value.tests.map((
|
|
739
|
-
const attempt =
|
|
740
|
-
if (attempt?.state !== "running") return
|
|
791
|
+
tests: this.value.tests.map((test2) => {
|
|
792
|
+
const attempt = test2.attempts.at(-1);
|
|
793
|
+
if (attempt?.state !== "running") return test2;
|
|
741
794
|
const updatedAttempt = {
|
|
742
795
|
...attempt,
|
|
743
796
|
state: terminalState,
|
|
@@ -750,22 +803,22 @@ var RunRecorder = class {
|
|
|
750
803
|
)
|
|
751
804
|
};
|
|
752
805
|
return {
|
|
753
|
-
...
|
|
806
|
+
...test2,
|
|
754
807
|
state: terminalState,
|
|
755
|
-
attempts: [...
|
|
808
|
+
attempts: [...test2.attempts.slice(0, -1), updatedAttempt]
|
|
756
809
|
};
|
|
757
810
|
})
|
|
758
811
|
};
|
|
759
812
|
}
|
|
760
813
|
const tests = this.value.tests;
|
|
761
|
-
const verdict2 = error2 || tests.length === 0 || tests.some((
|
|
814
|
+
const verdict2 = error2 || tests.length === 0 || tests.some((test2) => test2.verdict === null) ? null : tests.some((test2) => test2.verdict === "failed") ? "failed" : "passed";
|
|
762
815
|
this.value = {
|
|
763
816
|
...this.value,
|
|
764
817
|
state: error2 ? terminalState : "completed",
|
|
765
818
|
error: error2,
|
|
766
819
|
verdict: verdict2,
|
|
767
820
|
flags: [
|
|
768
|
-
...new Set(tests.flatMap((
|
|
821
|
+
...new Set(tests.flatMap((test2) => test2.flags))
|
|
769
822
|
],
|
|
770
823
|
finishedAt: at2
|
|
771
824
|
};
|
|
@@ -1128,8 +1181,8 @@ async function matchLiveEntry(page, entry, key, operation, sentence, runtimeDepe
|
|
|
1128
1181
|
// src/report-privacy.ts
|
|
1129
1182
|
function safeText(value, privacy, limit) {
|
|
1130
1183
|
let text = value;
|
|
1131
|
-
for (const
|
|
1132
|
-
text = text.split(
|
|
1184
|
+
for (const secret2 of [...privacy.secretValues].filter((item) => item.length > 0).sort((a, b) => b.length - a.length)) {
|
|
1185
|
+
text = text.split(secret2).join("[REDACTED]");
|
|
1133
1186
|
}
|
|
1134
1187
|
const points = Array.from(text);
|
|
1135
1188
|
if (points.length <= limit) return text;
|
|
@@ -1348,9 +1401,10 @@ function operationError(error2, state2, subject) {
|
|
|
1348
1401
|
function safeOperationError(error2, state2, operation) {
|
|
1349
1402
|
const code = state2.crashed ? "page-crashed" : state2.disconnected ? "browser-disconnected" : state2.closed ? "page-closed" : "operation-failed";
|
|
1350
1403
|
const lines = safeCallLog(error2);
|
|
1404
|
+
const network = error2 instanceof Error ? /net::ERR_[A-Z_]+/.exec(error2.message)?.[0] ?? (/Timeout \d+ms exceeded/.test(error2.message) ? "timeout" : null) : null;
|
|
1351
1405
|
return new BrowserDriverError(
|
|
1352
1406
|
code,
|
|
1353
|
-
`${operation} failed.${lines.length ? `
|
|
1407
|
+
`${operation} failed${network ? ` (${network})` : ""}.${lines.length ? `
|
|
1354
1408
|
Call log:
|
|
1355
1409
|
${lines.join("\n")}` : ""}`
|
|
1356
1410
|
);
|
|
@@ -1376,6 +1430,9 @@ var PlaywrightPage = class {
|
|
|
1376
1430
|
get url() {
|
|
1377
1431
|
return this.page.url();
|
|
1378
1432
|
}
|
|
1433
|
+
playwright() {
|
|
1434
|
+
return { page: this.page, context: this.page.context() };
|
|
1435
|
+
}
|
|
1379
1436
|
async title() {
|
|
1380
1437
|
return this.page.title();
|
|
1381
1438
|
}
|
|
@@ -1552,6 +1609,42 @@ var PlaywrightPage = class {
|
|
|
1552
1609
|
reason: "stale"
|
|
1553
1610
|
}));
|
|
1554
1611
|
if (!ready.actionable) return ready;
|
|
1612
|
+
if (options.chooseOption) {
|
|
1613
|
+
const native = await element.evaluate(
|
|
1614
|
+
(node) => node instanceof HTMLSelectElement && !node.multiple ? Array.from(node.options).map((option) => ({
|
|
1615
|
+
label: (option.label || option.text).replace(/\s+/g, " ").trim(),
|
|
1616
|
+
disabled: option.disabled || option.parentElement instanceof HTMLOptGroupElement && option.parentElement.disabled
|
|
1617
|
+
})) : null
|
|
1618
|
+
).catch(() => null);
|
|
1619
|
+
if (native) {
|
|
1620
|
+
const label = options.chooseOption(
|
|
1621
|
+
native.map((option) => option.label)
|
|
1622
|
+
);
|
|
1623
|
+
const index = native.findIndex((option) => option.label === label);
|
|
1624
|
+
if (label === null || index < 0)
|
|
1625
|
+
return {
|
|
1626
|
+
actionable: false,
|
|
1627
|
+
reason: "option_not_named",
|
|
1628
|
+
options: native.filter((option) => !option.disabled).map((option) => option.label)
|
|
1629
|
+
};
|
|
1630
|
+
if (native[index].disabled)
|
|
1631
|
+
return { actionable: false, reason: "not_actionable" };
|
|
1632
|
+
const hide2 = await this.highlight(element);
|
|
1633
|
+
try {
|
|
1634
|
+
await element.selectOption({ index }, { timeout: remaining() });
|
|
1635
|
+
return { actionable: true, aim };
|
|
1636
|
+
} catch (error2) {
|
|
1637
|
+
return {
|
|
1638
|
+
actionable: false,
|
|
1639
|
+
reason: "action_started",
|
|
1640
|
+
retryable: false,
|
|
1641
|
+
callLog: safeCallLog(error2)
|
|
1642
|
+
};
|
|
1643
|
+
} finally {
|
|
1644
|
+
await hide2();
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1555
1648
|
const hide = await this.highlight(element);
|
|
1556
1649
|
try {
|
|
1557
1650
|
await element.click({ position: aim.point, timeout: remaining() });
|
|
@@ -1941,8 +2034,8 @@ var StepExecutionError = class extends Error {
|
|
|
1941
2034
|
phase;
|
|
1942
2035
|
retryable;
|
|
1943
2036
|
callLog;
|
|
1944
|
-
constructor(op, code, phase, callLog = []) {
|
|
1945
|
-
super(`${op} failed: ${code}`);
|
|
2037
|
+
constructor(op, code, phase, callLog = [], detail) {
|
|
2038
|
+
super(detail ?? `${op} failed: ${code}`);
|
|
1946
2039
|
this.name = "StepExecutionError";
|
|
1947
2040
|
this.op = op;
|
|
1948
2041
|
this.code = code;
|
|
@@ -2063,7 +2156,20 @@ async function executeStep(page, command, options = {}) {
|
|
|
2063
2156
|
if (options.signal?.aborted)
|
|
2064
2157
|
throw new StepExecutionError(op, "canceled", phase);
|
|
2065
2158
|
phase = "post_dispatch";
|
|
2066
|
-
const result = await active(
|
|
2159
|
+
const result = await active(
|
|
2160
|
+
page.clickRef(aimed.aim, {
|
|
2161
|
+
timeoutMs,
|
|
2162
|
+
...command.chooseOption ? { chooseOption: command.chooseOption } : {}
|
|
2163
|
+
})
|
|
2164
|
+
);
|
|
2165
|
+
if (!result.actionable && result.reason === "option_not_named")
|
|
2166
|
+
throw new StepExecutionError(
|
|
2167
|
+
op,
|
|
2168
|
+
"invalid_input",
|
|
2169
|
+
"pre_dispatch",
|
|
2170
|
+
[],
|
|
2171
|
+
result.options.length ? `This is a dropdown. Name the option to choose, one of: ${result.options.slice(0, 12).map((label) => `"${label}"`).join(", ")}${result.options.length > 12 ? ", \u2026" : ""}.` : "This is a dropdown with no option that can be chosen."
|
|
2172
|
+
);
|
|
2067
2173
|
if (!result.actionable)
|
|
2068
2174
|
throw new StepExecutionError(
|
|
2069
2175
|
op,
|
|
@@ -2166,16 +2272,21 @@ ${(result.callLog ?? []).join("\n")}`)
|
|
|
2166
2272
|
};
|
|
2167
2273
|
} catch (error2) {
|
|
2168
2274
|
if (error2 instanceof StepExecutionError) throw error2;
|
|
2275
|
+
const network = error2 instanceof Error ? /\((net::ERR_[A-Z_]+|timeout)\)/.exec(error2.message)?.[1] : void 0;
|
|
2169
2276
|
throw new StepExecutionError(
|
|
2170
2277
|
op,
|
|
2171
2278
|
"operation_failed",
|
|
2172
2279
|
phase,
|
|
2173
|
-
safeCallLog(error2)
|
|
2280
|
+
safeCallLog(error2),
|
|
2281
|
+
network ? `${op} failed: ${network}` : void 0
|
|
2174
2282
|
);
|
|
2175
2283
|
}
|
|
2176
2284
|
}
|
|
2177
2285
|
|
|
2178
2286
|
// src/provider.ts
|
|
2287
|
+
function isRunWideProviderError(error2) {
|
|
2288
|
+
return error2 instanceof ProviderError && (error2.code === "authentication" || error2.code === "configuration" || error2.code === "rate-limited");
|
|
2289
|
+
}
|
|
2179
2290
|
var ProviderError = class extends Error {
|
|
2180
2291
|
constructor(code, message, attempts = 0, failedCall) {
|
|
2181
2292
|
super(message);
|
|
@@ -2434,6 +2545,22 @@ async function captureVisionObservation(page, candidates, version, instruction,
|
|
|
2434
2545
|
}
|
|
2435
2546
|
};
|
|
2436
2547
|
}
|
|
2548
|
+
async function probeOpenRouterKey(apiKey, options = {}) {
|
|
2549
|
+
try {
|
|
2550
|
+
const response = await fetch("https://openrouter.ai/api/v1/key", {
|
|
2551
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
2552
|
+
signal: AbortSignal.any([
|
|
2553
|
+
AbortSignal.timeout(options.timeoutMs ?? 5e3),
|
|
2554
|
+
...options.signal ? [options.signal] : []
|
|
2555
|
+
])
|
|
2556
|
+
});
|
|
2557
|
+
await response.body?.cancel().catch(() => void 0);
|
|
2558
|
+
if (response.ok) return "accepted";
|
|
2559
|
+
return response.status === 401 || response.status === 403 ? "rejected" : "unreachable";
|
|
2560
|
+
} catch {
|
|
2561
|
+
return "unreachable";
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2437
2564
|
|
|
2438
2565
|
// src/locator.ts
|
|
2439
2566
|
var MAX_CANDIDATES = 4096;
|
|
@@ -3220,7 +3347,14 @@ async function resolveTarget(page, resolver, options) {
|
|
|
3220
3347
|
confidence = decision.confidence;
|
|
3221
3348
|
if (decision.selection.kind === "none") {
|
|
3222
3349
|
const fallback = codeFallback ? codeAfterNone(options.sentence, candidates) : null;
|
|
3223
|
-
if (!fallback)
|
|
3350
|
+
if (!fallback) {
|
|
3351
|
+
if (options.visionResolver && options.operation === "click") {
|
|
3352
|
+
gate = "none";
|
|
3353
|
+
const seen = await ambiguous(candidates);
|
|
3354
|
+
return seen.kind === "unresolved" && seen.reason === "ambiguous" ? { ...seen, reason: "none" } : seen;
|
|
3355
|
+
}
|
|
3356
|
+
return unresolved("none");
|
|
3357
|
+
}
|
|
3224
3358
|
gate = "resolved_in_code_after_none";
|
|
3225
3359
|
if (options.operation === "fill" && !fallback.editable)
|
|
3226
3360
|
return unresolved("not_fillable");
|
|
@@ -3448,6 +3582,10 @@ async function resolveTarget(page, resolver, options) {
|
|
|
3448
3582
|
}
|
|
3449
3583
|
return unresolved("ambiguous");
|
|
3450
3584
|
} catch {
|
|
3585
|
+
if (!sameVersion3(await pageVersion(page), source.version)) {
|
|
3586
|
+
gate = `${gate}:vision_stale_capture`;
|
|
3587
|
+
return unresolved("stale");
|
|
3588
|
+
}
|
|
3451
3589
|
gate = `${gate}:vision_unavailable`;
|
|
3452
3590
|
return unresolved("ambiguous");
|
|
3453
3591
|
}
|
|
@@ -3533,6 +3671,7 @@ async function resolveTarget(page, resolver, options) {
|
|
|
3533
3671
|
targetChanged: false
|
|
3534
3672
|
};
|
|
3535
3673
|
if (controller.signal.aborted) return unresolved("timeout");
|
|
3674
|
+
if (isRunWideProviderError(error2)) throw error2;
|
|
3536
3675
|
if (error2 instanceof LocatorError) return unresolved(error2.reason);
|
|
3537
3676
|
if (error2 instanceof PageScriptError) return unresolved("incomplete");
|
|
3538
3677
|
return unresolved("provider_error");
|
|
@@ -3544,11 +3683,11 @@ async function resolveTarget(page, resolver, options) {
|
|
|
3544
3683
|
|
|
3545
3684
|
// src/flow-types.ts
|
|
3546
3685
|
function isFullyValidated(coverage, diagnostics) {
|
|
3547
|
-
return coverage.format === "passed" && coverage.steps === "checked" && (coverage.modules === "not_needed" || coverage.modules === "checked") && !diagnostics.some((
|
|
3686
|
+
return coverage.format === "passed" && coverage.steps === "checked" && (coverage.modules === "not_needed" || coverage.modules === "checked") && !diagnostics.some((diagnostic3) => diagnostic3.severity === "error");
|
|
3548
3687
|
}
|
|
3549
|
-
function formatFlowDiagnostic(
|
|
3550
|
-
const { file, line, col } =
|
|
3551
|
-
return `${file}:${line}:${col}: ${
|
|
3688
|
+
function formatFlowDiagnostic(diagnostic3) {
|
|
3689
|
+
const { file, line, col } = diagnostic3.source;
|
|
3690
|
+
return `${file}:${line}:${col}: ${diagnostic3.message} ${diagnostic3.fix}`;
|
|
3552
3691
|
}
|
|
3553
3692
|
|
|
3554
3693
|
// src/flow-values.ts
|
|
@@ -3570,8 +3709,8 @@ function redactOpaqueText(text, entries) {
|
|
|
3570
3709
|
}
|
|
3571
3710
|
var DataResolutionError = class extends Error {
|
|
3572
3711
|
code = "missing_environment_variable";
|
|
3573
|
-
constructor(dataKey, variable,
|
|
3574
|
-
const { file, line, col } =
|
|
3712
|
+
constructor(dataKey, variable, declared2) {
|
|
3713
|
+
const { file, line, col } = declared2.source;
|
|
3575
3714
|
super(
|
|
3576
3715
|
`${file}:${line}:${col}: data.${dataKey} needs $${variable}, which is not set`
|
|
3577
3716
|
);
|
|
@@ -3635,11 +3774,11 @@ function parseDataTemplate(value) {
|
|
|
3635
3774
|
if (literal) parts.push({ literal });
|
|
3636
3775
|
return { parts };
|
|
3637
3776
|
}
|
|
3638
|
-
function resolveData(
|
|
3777
|
+
function resolveData(declared2, env) {
|
|
3639
3778
|
const resolved = /* @__PURE__ */ Object.create(
|
|
3640
3779
|
null
|
|
3641
3780
|
);
|
|
3642
|
-
for (const [key, item] of Object.entries(
|
|
3781
|
+
for (const [key, item] of Object.entries(declared2)) {
|
|
3643
3782
|
if (typeof item.value !== "string") {
|
|
3644
3783
|
resolved[key] = {
|
|
3645
3784
|
value: new RuntimeValue(String(item.value), `{{${key}}}`),
|
|
@@ -3881,8 +4020,11 @@ import { z as z3 } from "zod";
|
|
|
3881
4020
|
// src/project-discovery.ts
|
|
3882
4021
|
import { readdir, realpath, stat } from "fs/promises";
|
|
3883
4022
|
import path2 from "path";
|
|
3884
|
-
var
|
|
4023
|
+
var TEST_SUFFIXES = [".test.yaml", ".test.ts"];
|
|
3885
4024
|
var MODULE_SUFFIX = ".module.yaml";
|
|
4025
|
+
function isTestFile(name) {
|
|
4026
|
+
return TEST_SUFFIXES.some((suffix) => name.endsWith(suffix));
|
|
4027
|
+
}
|
|
3886
4028
|
function contains(root, candidate) {
|
|
3887
4029
|
const relative = path2.relative(root, candidate);
|
|
3888
4030
|
return relative === "" || relative !== ".." && !relative.startsWith(`..${path2.sep}`) && !path2.isAbsolute(relative);
|
|
@@ -3924,7 +4066,7 @@ async function discoverProjectFiles(paths, options) {
|
|
|
3924
4066
|
fix: "Run the command from the project root, or pass paths inside it."
|
|
3925
4067
|
});
|
|
3926
4068
|
const add2 = (file) => {
|
|
3927
|
-
if (file
|
|
4069
|
+
if (isTestFile(file)) tests.add(file);
|
|
3928
4070
|
else modules.add(file);
|
|
3929
4071
|
};
|
|
3930
4072
|
for (const requested of paths.length ? paths : ["."]) {
|
|
@@ -3949,7 +4091,7 @@ async function discoverProjectFiles(paths, options) {
|
|
|
3949
4091
|
}
|
|
3950
4092
|
const found = await walkSuiteFiles(
|
|
3951
4093
|
real,
|
|
3952
|
-
[
|
|
4094
|
+
[...TEST_SUFFIXES, MODULE_SUFFIX],
|
|
3953
4095
|
(folder) => problems.push({
|
|
3954
4096
|
code: "unreadable_directory",
|
|
3955
4097
|
path: path2.relative(root, folder) || ".",
|
|
@@ -3961,11 +4103,11 @@ async function discoverProjectFiles(paths, options) {
|
|
|
3961
4103
|
continue;
|
|
3962
4104
|
}
|
|
3963
4105
|
const name = path2.basename(absolute);
|
|
3964
|
-
if (!name
|
|
4106
|
+
if (!isTestFile(name) && !name.endsWith(MODULE_SUFFIX)) {
|
|
3965
4107
|
problems.push({
|
|
3966
4108
|
code: "unsupported_file",
|
|
3967
4109
|
path: requested,
|
|
3968
|
-
message: `${requested} is not a *.test.yaml or *.module.yaml file.`,
|
|
4110
|
+
message: `${requested} is not a *.test.ts, *.test.yaml, or *.module.yaml file.`,
|
|
3969
4111
|
fix: "Pass a test file, a module file, or a directory."
|
|
3970
4112
|
});
|
|
3971
4113
|
continue;
|
|
@@ -4439,7 +4581,7 @@ function parseFlow(source, file, options) {
|
|
|
4439
4581
|
"error",
|
|
4440
4582
|
"invalid_test_mode",
|
|
4441
4583
|
at(file, counter, nodes, []),
|
|
4442
|
-
"This test
|
|
4584
|
+
plain.goal === void 0 ? "This test has neither a `steps` list nor a `goal`." : "This test has both a `steps` list and a `goal`; use one.",
|
|
4443
4585
|
"Use `steps` for authored actions, or `goal` with a required `verify` claim."
|
|
4444
4586
|
);
|
|
4445
4587
|
if (plain.goal === void 0 !== (plain.verify === void 0))
|
|
@@ -4553,7 +4695,7 @@ function parseFlow(source, file, options) {
|
|
|
4553
4695
|
(step) => step.kind === "module"
|
|
4554
4696
|
);
|
|
4555
4697
|
const format = diagnostics.some(
|
|
4556
|
-
(
|
|
4698
|
+
(diagnostic3) => diagnostic3.severity === "error"
|
|
4557
4699
|
) ? "failed" : "passed";
|
|
4558
4700
|
if (!input)
|
|
4559
4701
|
return {
|
|
@@ -4647,7 +4789,7 @@ function validateFlows(inputs, options) {
|
|
|
4647
4789
|
files,
|
|
4648
4790
|
diagnostics,
|
|
4649
4791
|
coverage: {
|
|
4650
|
-
format: diagnostics.some((
|
|
4792
|
+
format: diagnostics.some((diagnostic3) => diagnostic3.severity === "error") ? "failed" : "passed",
|
|
4651
4793
|
steps: "not_checked",
|
|
4652
4794
|
modules: files.some((file) => file.coverage.modules === "not_checked") ? "not_checked" : "not_needed"
|
|
4653
4795
|
}
|
|
@@ -4831,7 +4973,7 @@ async function loadFlowFile(file, options) {
|
|
|
4831
4973
|
await handle.close();
|
|
4832
4974
|
}
|
|
4833
4975
|
} catch {
|
|
4834
|
-
const
|
|
4976
|
+
const diagnostic3 = {
|
|
4835
4977
|
severity: "error",
|
|
4836
4978
|
code: "unreadable_file",
|
|
4837
4979
|
source: { file, line: 1, col: 1 },
|
|
@@ -4839,7 +4981,7 @@ async function loadFlowFile(file, options) {
|
|
|
4839
4981
|
fix: "Check the path and file permissions."
|
|
4840
4982
|
};
|
|
4841
4983
|
return {
|
|
4842
|
-
diagnostics: [
|
|
4984
|
+
diagnostics: [diagnostic3],
|
|
4843
4985
|
coverage: {
|
|
4844
4986
|
format: "failed",
|
|
4845
4987
|
steps: "not_checked",
|
|
@@ -4979,14 +5121,14 @@ async function resolveFlowModules(parsed, options) {
|
|
|
4979
5121
|
expanded2.push({ ...step, phase, sourceStack: stack });
|
|
4980
5122
|
continue;
|
|
4981
5123
|
}
|
|
4982
|
-
const
|
|
4983
|
-
diagnostics.push(...
|
|
4984
|
-
const module =
|
|
5124
|
+
const loaded2 = await load(canonical);
|
|
5125
|
+
diagnostics.push(...loaded2.diagnostics);
|
|
5126
|
+
const module = loaded2.value;
|
|
4985
5127
|
if (!module) {
|
|
4986
5128
|
expanded2.push({ ...step, phase, sourceStack: stack });
|
|
4987
5129
|
continue;
|
|
4988
5130
|
}
|
|
4989
|
-
const
|
|
5131
|
+
const declared2 = new Set(module.parameters);
|
|
4990
5132
|
const supplied = Object.keys(step.with);
|
|
4991
5133
|
for (const parameter of module.parameters)
|
|
4992
5134
|
if (!Object.hasOwn(step.with, parameter))
|
|
@@ -4998,7 +5140,7 @@ async function resolveFlowModules(parsed, options) {
|
|
|
4998
5140
|
`Add \`${parameter}\` under with.`
|
|
4999
5141
|
);
|
|
5000
5142
|
for (const argument of supplied)
|
|
5001
|
-
if (!
|
|
5143
|
+
if (!declared2.has(argument))
|
|
5002
5144
|
diagnostics.push({
|
|
5003
5145
|
severity: "error",
|
|
5004
5146
|
code: "unknown_module_argument",
|
|
@@ -5150,12 +5292,16 @@ function preflightSentence(sentence) {
|
|
|
5150
5292
|
function patternOperation(sentence) {
|
|
5151
5293
|
const text = canonicalSentence(sentence);
|
|
5152
5294
|
if (preflightSentence(text)) return null;
|
|
5153
|
-
if (/^(?:click|type|enter|fill|press|goto|go\s+to|navigate\s+to|scroll|wait|remember)\b/iu.test(
|
|
5295
|
+
if (/^(?:click|type|enter|fill|press|goto|go\s+to|navigate\s+to|scroll|wait|remember|select|choose|pick)\b/iu.test(
|
|
5154
5296
|
text
|
|
5155
5297
|
) && (withoutQuotes(text).match(SECOND_ACTION_CONNECTOR) !== null || /;|,\s*[A-Za-z]/u.test(withoutQuotes(text))))
|
|
5156
5298
|
return null;
|
|
5157
5299
|
if (/^remember\b/iu.test(text) && BINDING.test(text)) return "remember";
|
|
5158
5300
|
if (/^click\s+\S/iu.test(text)) return "click";
|
|
5301
|
+
if (/^(?:select|choose|pick)\s+(?:"[^"]+"|“[^”]+”)\s+(?:in|from)\s+\S/iu.test(
|
|
5302
|
+
text
|
|
5303
|
+
))
|
|
5304
|
+
return "click";
|
|
5159
5305
|
if (VALUE.test(text)) return "type";
|
|
5160
5306
|
if (/^press\s+(?:the\s+)?(?:"[^"]+"|\S+)/iu.test(text)) return "press";
|
|
5161
5307
|
if (/^(?:goto|go\s+to|navigate\s+to)\s+https?:\/\/\S+/iu.test(text))
|
|
@@ -5445,8 +5591,8 @@ function validEntry2(value) {
|
|
|
5445
5591
|
return decision.accepted;
|
|
5446
5592
|
}
|
|
5447
5593
|
var FileClassificationCache = class _FileClassificationCache {
|
|
5448
|
-
constructor(
|
|
5449
|
-
this.path =
|
|
5594
|
+
constructor(path11, requestedModel, entries, loadReason, invalidKeys) {
|
|
5595
|
+
this.path = path11;
|
|
5450
5596
|
this.requestedModel = requestedModel;
|
|
5451
5597
|
this.loadReason = loadReason;
|
|
5452
5598
|
this.invalidKeys = invalidKeys;
|
|
@@ -5458,12 +5604,12 @@ var FileClassificationCache = class _FileClassificationCache {
|
|
|
5458
5604
|
invalidKeys;
|
|
5459
5605
|
entries;
|
|
5460
5606
|
dirty = false;
|
|
5461
|
-
static async load(
|
|
5607
|
+
static async load(path11, requestedModel) {
|
|
5462
5608
|
try {
|
|
5463
|
-
const value = JSON.parse(await fs.readFile(
|
|
5609
|
+
const value = JSON.parse(await fs.readFile(path11, "utf8"));
|
|
5464
5610
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
5465
5611
|
return new _FileClassificationCache(
|
|
5466
|
-
|
|
5612
|
+
path11,
|
|
5467
5613
|
requestedModel,
|
|
5468
5614
|
{},
|
|
5469
5615
|
"corrupt",
|
|
@@ -5472,7 +5618,7 @@ var FileClassificationCache = class _FileClassificationCache {
|
|
|
5472
5618
|
const file = value;
|
|
5473
5619
|
if (file.version !== FORMAT_VERSION)
|
|
5474
5620
|
return new _FileClassificationCache(
|
|
5475
|
-
|
|
5621
|
+
path11,
|
|
5476
5622
|
requestedModel,
|
|
5477
5623
|
{},
|
|
5478
5624
|
"format_mismatch",
|
|
@@ -5480,7 +5626,7 @@ var FileClassificationCache = class _FileClassificationCache {
|
|
|
5480
5626
|
);
|
|
5481
5627
|
if (!file.entries || typeof file.entries !== "object" || Array.isArray(file.entries))
|
|
5482
5628
|
return new _FileClassificationCache(
|
|
5483
|
-
|
|
5629
|
+
path11,
|
|
5484
5630
|
requestedModel,
|
|
5485
5631
|
{},
|
|
5486
5632
|
"corrupt",
|
|
@@ -5494,7 +5640,7 @@ var FileClassificationCache = class _FileClassificationCache {
|
|
|
5494
5640
|
else invalidKeys[key] = "invalid_or_incompatible";
|
|
5495
5641
|
}
|
|
5496
5642
|
return new _FileClassificationCache(
|
|
5497
|
-
|
|
5643
|
+
path11,
|
|
5498
5644
|
requestedModel,
|
|
5499
5645
|
entries,
|
|
5500
5646
|
"ok",
|
|
@@ -5503,14 +5649,14 @@ var FileClassificationCache = class _FileClassificationCache {
|
|
|
5503
5649
|
} catch (error2) {
|
|
5504
5650
|
if (error2.code === "ENOENT")
|
|
5505
5651
|
return new _FileClassificationCache(
|
|
5506
|
-
|
|
5652
|
+
path11,
|
|
5507
5653
|
requestedModel,
|
|
5508
5654
|
{},
|
|
5509
5655
|
"absent",
|
|
5510
5656
|
{}
|
|
5511
5657
|
);
|
|
5512
5658
|
return new _FileClassificationCache(
|
|
5513
|
-
|
|
5659
|
+
path11,
|
|
5514
5660
|
requestedModel,
|
|
5515
5661
|
{},
|
|
5516
5662
|
"corrupt",
|
|
@@ -5697,7 +5843,9 @@ async function classifyParsedFlow(parsed, options) {
|
|
|
5697
5843
|
}
|
|
5698
5844
|
|
|
5699
5845
|
// src/project-validation.ts
|
|
5846
|
+
import { existsSync as existsSync3, realpathSync, statSync as statSync2 } from "fs";
|
|
5700
5847
|
import { readFile as readFile2 } from "fs/promises";
|
|
5848
|
+
import path7 from "path";
|
|
5701
5849
|
|
|
5702
5850
|
// src/flow-runner.ts
|
|
5703
5851
|
import path5 from "path";
|
|
@@ -5886,6 +6034,7 @@ async function judgePage(page, judge, claim2, timeoutMs, signal, projectText) {
|
|
|
5886
6034
|
probability2(decision.contradicted, "contradicted");
|
|
5887
6035
|
} catch (error2) {
|
|
5888
6036
|
if (error2 instanceof AssertionEngineError) throw error2;
|
|
6037
|
+
if (isRunWideProviderError(error2)) throw error2;
|
|
5889
6038
|
if (decision)
|
|
5890
6039
|
throw new AssertionEngineError(
|
|
5891
6040
|
signal?.aborted ? "canceled" : "provider_failure",
|
|
@@ -6005,7 +6154,7 @@ function goalOperations(state2) {
|
|
|
6005
6154
|
])
|
|
6006
6155
|
),
|
|
6007
6156
|
DONE: "All goal requirements are visibly satisfied; request independent verification",
|
|
6008
|
-
BLOCKED: "No
|
|
6157
|
+
BLOCKED: "No offered element or field can move the goal forward from this page; abstain"
|
|
6009
6158
|
};
|
|
6010
6159
|
}
|
|
6011
6160
|
function goalChoiceAccepted(answer, ids, minMargin = 0.1) {
|
|
@@ -6076,7 +6225,7 @@ async function runGoal(page, planner, judge, options) {
|
|
|
6076
6225
|
let actions = 0;
|
|
6077
6226
|
let pendingCall = false;
|
|
6078
6227
|
let reportedCalls = 0;
|
|
6079
|
-
const result = (reason) => ({
|
|
6228
|
+
const result = (reason, detail) => ({
|
|
6080
6229
|
status: reason === "verified" ? "passed" : "failed",
|
|
6081
6230
|
reason,
|
|
6082
6231
|
requests,
|
|
@@ -6084,8 +6233,18 @@ async function runGoal(page, planner, judge, options) {
|
|
|
6084
6233
|
elapsedMs: Math.round(performance.now() - started),
|
|
6085
6234
|
calls,
|
|
6086
6235
|
history,
|
|
6236
|
+
...detail ? { detail } : {},
|
|
6087
6237
|
verification
|
|
6088
6238
|
});
|
|
6239
|
+
const uncertain = (what, answer, route, label = (choice) => choice) => {
|
|
6240
|
+
let where = route;
|
|
6241
|
+
try {
|
|
6242
|
+
where = new URL(route).pathname || route;
|
|
6243
|
+
} catch {
|
|
6244
|
+
}
|
|
6245
|
+
const top = answer ? Object.entries(answer.probabilities).sort((a, b) => b[1] - a[1]).slice(0, 3).map(([choice, p]) => `${label(choice)} ${p.toFixed(2)}`).join(", ") : "no answer";
|
|
6246
|
+
return project(`${what} on ${where}: ${top}`);
|
|
6247
|
+
};
|
|
6089
6248
|
const seen = /* @__PURE__ */ new Map();
|
|
6090
6249
|
try {
|
|
6091
6250
|
while (!signal.aborted) {
|
|
@@ -6182,7 +6341,10 @@ async function runGoal(page, planner, judge, options) {
|
|
|
6182
6341
|
Object.keys(goalOperations(state2)),
|
|
6183
6342
|
operationMinMargin
|
|
6184
6343
|
))
|
|
6185
|
-
return result(
|
|
6344
|
+
return result(
|
|
6345
|
+
"operation_abstention",
|
|
6346
|
+
uncertain("operation", decision.operation, digest.version.route)
|
|
6347
|
+
);
|
|
6186
6348
|
if (!same(digest.version, await active(pageVersion(page)))) continue;
|
|
6187
6349
|
const op = decision.operation.choice;
|
|
6188
6350
|
if (op === "BLOCKED") return result("blocked");
|
|
@@ -6222,7 +6384,19 @@ async function runGoal(page, planner, judge, options) {
|
|
|
6222
6384
|
}
|
|
6223
6385
|
const head = decision.target;
|
|
6224
6386
|
if (!head || !goalChoiceAccepted(head, Object.keys(state2.targets[op] ?? {})))
|
|
6225
|
-
return result(
|
|
6387
|
+
return result(
|
|
6388
|
+
"target_abstention",
|
|
6389
|
+
uncertain(`${op} target`, head, digest.version.route, (id) => {
|
|
6390
|
+
const name = (() => {
|
|
6391
|
+
try {
|
|
6392
|
+
return JSON.parse(state2.targets[op]?.[id] ?? "{}").name;
|
|
6393
|
+
} catch {
|
|
6394
|
+
return void 0;
|
|
6395
|
+
}
|
|
6396
|
+
})();
|
|
6397
|
+
return name ? `"${name}"` : id;
|
|
6398
|
+
})
|
|
6399
|
+
);
|
|
6226
6400
|
const command = commands.get(head.choice);
|
|
6227
6401
|
if (!command) return result("invalid_target");
|
|
6228
6402
|
if (actions >= maxActions) return result("action_limit");
|
|
@@ -6265,6 +6439,11 @@ async function runGoal(page, planner, judge, options) {
|
|
|
6265
6439
|
failed = true;
|
|
6266
6440
|
failure = error2;
|
|
6267
6441
|
}
|
|
6442
|
+
if (failed && failure instanceof StepExecutionError && failure.code === "stale" && failure.phase === "pre_dispatch" && !signal.aborted) {
|
|
6443
|
+
actions--;
|
|
6444
|
+
history.pop();
|
|
6445
|
+
continue;
|
|
6446
|
+
}
|
|
6268
6447
|
await options.onAction?.({
|
|
6269
6448
|
operation: command.op,
|
|
6270
6449
|
sentence,
|
|
@@ -6293,6 +6472,130 @@ async function runGoal(page, planner, judge, options) {
|
|
|
6293
6472
|
}
|
|
6294
6473
|
}
|
|
6295
6474
|
|
|
6475
|
+
// src/dropdown-option.ts
|
|
6476
|
+
function chooseOption(sentence, labels) {
|
|
6477
|
+
const norm = (text2) => text2.normalize("NFC").replace(/\s+/gu, " ").trim().toLowerCase();
|
|
6478
|
+
const usable = [...new Set(labels.filter((label) => norm(label)))];
|
|
6479
|
+
const quoted = [...sentence.matchAll(/"([^"]+)"|“([^”]+)”/gu)].map(
|
|
6480
|
+
(match) => norm(match[1] ?? match[2] ?? "")
|
|
6481
|
+
);
|
|
6482
|
+
const byQuote = usable.filter((label) => quoted.includes(norm(label)));
|
|
6483
|
+
if (byQuote.length === 1) return byQuote[0];
|
|
6484
|
+
if (byQuote.length > 1) return null;
|
|
6485
|
+
const text = ` ${norm(sentence).replace(/[.,;:!?]+$/u, "")} `;
|
|
6486
|
+
const named = usable.filter((label) => {
|
|
6487
|
+
const needle = norm(label);
|
|
6488
|
+
let index = text.indexOf(needle);
|
|
6489
|
+
while (index >= 0) {
|
|
6490
|
+
const before = text[index - 1] ?? " ";
|
|
6491
|
+
const after = text[index + needle.length] ?? " ";
|
|
6492
|
+
if (!/[\p{L}\p{N}]/u.test(before) && !/[\p{L}\p{N}]/u.test(after))
|
|
6493
|
+
return true;
|
|
6494
|
+
index = text.indexOf(needle, index + 1);
|
|
6495
|
+
}
|
|
6496
|
+
return false;
|
|
6497
|
+
});
|
|
6498
|
+
const distinct = named.filter(
|
|
6499
|
+
(label) => !named.some(
|
|
6500
|
+
(other) => other !== label && norm(other).includes(norm(label))
|
|
6501
|
+
)
|
|
6502
|
+
);
|
|
6503
|
+
return distinct.length === 1 ? distinct[0] : null;
|
|
6504
|
+
}
|
|
6505
|
+
|
|
6506
|
+
// src/step-operands.ts
|
|
6507
|
+
var PLAYWRIGHT_KEYS = {
|
|
6508
|
+
enter: "Enter",
|
|
6509
|
+
return: "Enter",
|
|
6510
|
+
tab: "Tab",
|
|
6511
|
+
escape: "Escape",
|
|
6512
|
+
esc: "Escape",
|
|
6513
|
+
space: "Space",
|
|
6514
|
+
spacebar: "Space",
|
|
6515
|
+
backspace: "Backspace",
|
|
6516
|
+
delete: "Delete",
|
|
6517
|
+
del: "Delete",
|
|
6518
|
+
home: "Home",
|
|
6519
|
+
end: "End",
|
|
6520
|
+
pageup: "PageUp",
|
|
6521
|
+
pagedown: "PageDown",
|
|
6522
|
+
arrowup: "ArrowUp",
|
|
6523
|
+
arrowdown: "ArrowDown",
|
|
6524
|
+
arrowleft: "ArrowLeft",
|
|
6525
|
+
arrowright: "ArrowRight",
|
|
6526
|
+
up: "ArrowUp",
|
|
6527
|
+
down: "ArrowDown",
|
|
6528
|
+
left: "ArrowLeft",
|
|
6529
|
+
right: "ArrowRight",
|
|
6530
|
+
...Object.fromEntries(
|
|
6531
|
+
Array.from({ length: 12 }, (_, index) => [
|
|
6532
|
+
`f${index + 1}`,
|
|
6533
|
+
`F${index + 1}`
|
|
6534
|
+
])
|
|
6535
|
+
)
|
|
6536
|
+
};
|
|
6537
|
+
var MODIFIERS = {
|
|
6538
|
+
ctrl: "Control",
|
|
6539
|
+
control: "Control",
|
|
6540
|
+
shift: "Shift",
|
|
6541
|
+
alt: "Alt",
|
|
6542
|
+
option: "Alt",
|
|
6543
|
+
cmd: "Meta",
|
|
6544
|
+
command: "Meta",
|
|
6545
|
+
meta: "Meta",
|
|
6546
|
+
controlormeta: "ControlOrMeta"
|
|
6547
|
+
};
|
|
6548
|
+
function playwrightKey(name) {
|
|
6549
|
+
const parts = name.trim().split(/\s*\+\s*/u);
|
|
6550
|
+
if (parts.some((part) => !part)) return null;
|
|
6551
|
+
const key = parts.pop();
|
|
6552
|
+
const modifiers = parts.map((part) => MODIFIERS[part.toLowerCase()]);
|
|
6553
|
+
if (modifiers.some((modifier) => modifier === void 0)) return null;
|
|
6554
|
+
const main = PLAYWRIGHT_KEYS[key.toLowerCase()] ?? (Array.from(key).length === 1 ? key : null);
|
|
6555
|
+
return main ? [...modifiers, main].join("+") : null;
|
|
6556
|
+
}
|
|
6557
|
+
function pressKey(sentence) {
|
|
6558
|
+
const text = canonicalSentence(sentence);
|
|
6559
|
+
const quoted = /"([^"]+)"/u.exec(text);
|
|
6560
|
+
if (quoted) return playwrightKey(quoted[1]);
|
|
6561
|
+
const keyMention = /\b([\w+-]+)\s+key\b/iu.exec(text);
|
|
6562
|
+
if (keyMention) return playwrightKey(keyMention[1]);
|
|
6563
|
+
const explicit = /^(?:press|hit|strike)\s+(?:the\s+)?([\w+-]+)\s*\.?$/iu.exec(
|
|
6564
|
+
text
|
|
6565
|
+
);
|
|
6566
|
+
return explicit ? playwrightKey(explicit[1]) : null;
|
|
6567
|
+
}
|
|
6568
|
+
function waitDurationMs(sentence) {
|
|
6569
|
+
const match = /\b(\d+(?:\.\d+)?)\s*(ms|milliseconds?|s|seconds?)\b/iu.exec(
|
|
6570
|
+
canonicalSentence(sentence)
|
|
6571
|
+
);
|
|
6572
|
+
if (!match) return null;
|
|
6573
|
+
const amount = Number(match[1]);
|
|
6574
|
+
const ms = match[2].toLowerCase().startsWith("m") ? amount : amount * 1e3;
|
|
6575
|
+
return Number.isFinite(ms) && ms > 0 && ms <= 3e4 ? Math.round(ms) : null;
|
|
6576
|
+
}
|
|
6577
|
+
function scrollDirection(sentence) {
|
|
6578
|
+
const match = /\b(up|down)\b/iu.exec(canonicalSentence(sentence));
|
|
6579
|
+
return match ? match[1].toLowerCase() : null;
|
|
6580
|
+
}
|
|
6581
|
+
function gotoUrlParts(sentence) {
|
|
6582
|
+
const urls = canonicalSentence(sentence).match(/https?:\/\/\S+/giu) ?? [];
|
|
6583
|
+
if (urls.length !== 1) return null;
|
|
6584
|
+
const url = urls[0].replace(/[.,;]+$/u, "");
|
|
6585
|
+
const literals = [];
|
|
6586
|
+
const names = [];
|
|
6587
|
+
let rest = url;
|
|
6588
|
+
for (; ; ) {
|
|
6589
|
+
const match = /\{\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/u.exec(rest);
|
|
6590
|
+
if (!match) break;
|
|
6591
|
+
literals.push(rest.slice(0, match.index));
|
|
6592
|
+
names.push(match[1]);
|
|
6593
|
+
rest = rest.slice(match.index + match[0].length);
|
|
6594
|
+
}
|
|
6595
|
+
literals.push(rest);
|
|
6596
|
+
return { literals, names };
|
|
6597
|
+
}
|
|
6598
|
+
|
|
6296
6599
|
// src/flow-runner.ts
|
|
6297
6600
|
function resultCall(call2, purpose, apiMs = null) {
|
|
6298
6601
|
return {
|
|
@@ -6315,14 +6618,14 @@ function resultCall(call2, purpose, apiMs = null) {
|
|
|
6315
6618
|
};
|
|
6316
6619
|
}
|
|
6317
6620
|
function firstDiagnostic(diagnostics) {
|
|
6318
|
-
const
|
|
6621
|
+
const diagnostic3 = diagnostics.find((item) => item.severity === "error");
|
|
6319
6622
|
return {
|
|
6320
6623
|
status: "could_not_run",
|
|
6321
|
-
file:
|
|
6624
|
+
file: diagnostic3?.source.file ?? "",
|
|
6322
6625
|
code: "invalid_test",
|
|
6323
|
-
message:
|
|
6324
|
-
...
|
|
6325
|
-
...
|
|
6626
|
+
message: diagnostic3?.message ?? "The test file could not be validated.",
|
|
6627
|
+
...diagnostic3?.fix ? { fix: diagnostic3.fix } : {},
|
|
6628
|
+
...diagnostic3 ? { source: diagnostic3.source } : {}
|
|
6326
6629
|
};
|
|
6327
6630
|
}
|
|
6328
6631
|
function unsupported(file, source, message) {
|
|
@@ -6334,6 +6637,46 @@ function unsupported(file, source, message) {
|
|
|
6334
6637
|
message
|
|
6335
6638
|
};
|
|
6336
6639
|
}
|
|
6640
|
+
function providerFailure(file, error2) {
|
|
6641
|
+
const details = {
|
|
6642
|
+
"rate-limited": {
|
|
6643
|
+
message: "The provider kept rate limiting requests for five minutes.",
|
|
6644
|
+
fix: "Lower --parallel or --provider-concurrency, or retry later."
|
|
6645
|
+
},
|
|
6646
|
+
authentication: {
|
|
6647
|
+
message: "The model provider rejected the API key.",
|
|
6648
|
+
fix: "Set TYPESAFE_API_KEY to a valid key, check it with `sedum doctor`, then rerun."
|
|
6649
|
+
},
|
|
6650
|
+
configuration: {
|
|
6651
|
+
message: "The model provider is not configured correctly.",
|
|
6652
|
+
fix: "Check TYPESAFE_API_KEY, TYPESAFE_BASE_URL and the model with `sedum doctor`, then rerun."
|
|
6653
|
+
}
|
|
6654
|
+
};
|
|
6655
|
+
return {
|
|
6656
|
+
status: "could_not_run",
|
|
6657
|
+
file,
|
|
6658
|
+
code: error2.code === "rate-limited" ? "provider_rate_limited" : `provider_${error2.code}`,
|
|
6659
|
+
...details[error2.code] ?? {
|
|
6660
|
+
message: "The model provider could not complete the run safely.",
|
|
6661
|
+
fix: "Check provider availability and the test input, then rerun the test."
|
|
6662
|
+
}
|
|
6663
|
+
};
|
|
6664
|
+
}
|
|
6665
|
+
function navigationWhy(error2) {
|
|
6666
|
+
const code = /(net::ERR_[A-Z_]+|timeout)$/.exec(error2.message)?.[1];
|
|
6667
|
+
if (!code) return "the browser could not load it";
|
|
6668
|
+
if (code === "timeout" || code.includes("TIMED_OUT"))
|
|
6669
|
+
return "it took too long to respond";
|
|
6670
|
+
if (code === "net::ERR_NAME_NOT_RESOLVED")
|
|
6671
|
+
return "the host name could not be resolved (DNS)";
|
|
6672
|
+
if (code === "net::ERR_CONNECTION_REFUSED")
|
|
6673
|
+
return "the server refused the connection";
|
|
6674
|
+
if (code === "net::ERR_INTERNET_DISCONNECTED")
|
|
6675
|
+
return "there is no network connection";
|
|
6676
|
+
if (code.startsWith("net::ERR_CERT_"))
|
|
6677
|
+
return "its TLS certificate was rejected";
|
|
6678
|
+
return `the browser reported ${code}`;
|
|
6679
|
+
}
|
|
6337
6680
|
function runtimeFailure(file, error2) {
|
|
6338
6681
|
if (error2 instanceof BrowserDriverError) {
|
|
6339
6682
|
const details = {
|
|
@@ -6377,23 +6720,15 @@ function runtimeFailure(file, error2) {
|
|
|
6377
6720
|
...details[error2.code]
|
|
6378
6721
|
};
|
|
6379
6722
|
}
|
|
6380
|
-
if (error2 instanceof ProviderError)
|
|
6381
|
-
|
|
6382
|
-
return {
|
|
6383
|
-
status: "could_not_run",
|
|
6384
|
-
file,
|
|
6385
|
-
code: "provider_rate_limited",
|
|
6386
|
-
message: "The provider kept rate limiting requests for five minutes.",
|
|
6387
|
-
fix: "Lower --parallel or --provider-concurrency, or retry later."
|
|
6388
|
-
};
|
|
6723
|
+
if (error2 instanceof ProviderError) return providerFailure(file, error2);
|
|
6724
|
+
if (error2 instanceof StepExecutionError && error2.op === "goto")
|
|
6389
6725
|
return {
|
|
6390
6726
|
status: "could_not_run",
|
|
6391
6727
|
file,
|
|
6392
|
-
code:
|
|
6393
|
-
message:
|
|
6394
|
-
fix:
|
|
6728
|
+
code: "navigation_failed",
|
|
6729
|
+
message: `Could not open the test's page: ${navigationWhy(error2)}.`,
|
|
6730
|
+
fix: "Check the test's url (or baseUrl), your network or VPN, and that the site is up."
|
|
6395
6731
|
};
|
|
6396
|
-
}
|
|
6397
6732
|
return {
|
|
6398
6733
|
status: "could_not_run",
|
|
6399
6734
|
file,
|
|
@@ -6404,7 +6739,7 @@ function runtimeFailure(file, error2) {
|
|
|
6404
6739
|
}
|
|
6405
6740
|
function claim(step, data) {
|
|
6406
6741
|
return step.text.replace(
|
|
6407
|
-
/^\s*(?:verify|assert|check|confirm|ensure|expect)\b\s*(?:that\s+)?/iu,
|
|
6742
|
+
/^\s*(?:verify|assert|check|confirm|ensure|expect|measure|note|observe)\b\s*(?:that\s+|whether\s+|if\s+)?/iu,
|
|
6408
6743
|
""
|
|
6409
6744
|
).trim().replace(
|
|
6410
6745
|
/\{\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/gu,
|
|
@@ -6440,7 +6775,51 @@ function resolveEntryUrl(testUrl, baseUrl, urlOverride) {
|
|
|
6440
6775
|
async function closeQuietly(resource) {
|
|
6441
6776
|
await resource?.close().catch(() => void 0);
|
|
6442
6777
|
}
|
|
6443
|
-
|
|
6778
|
+
var LocateRetryError = class extends Error {
|
|
6779
|
+
constructor(priorCalls) {
|
|
6780
|
+
super("The target could not be resolved.");
|
|
6781
|
+
this.priorCalls = priorCalls;
|
|
6782
|
+
}
|
|
6783
|
+
priorCalls;
|
|
6784
|
+
};
|
|
6785
|
+
async function reobserve(page, first, locate, options) {
|
|
6786
|
+
let resolved = first;
|
|
6787
|
+
if (options.staleRetry && resolved.kind === "unresolved" && resolved.reason === "stale") {
|
|
6788
|
+
const priorCalls = resolved.calls;
|
|
6789
|
+
const settled = await quietPage(page, 1e3, 4e3).catch(() => ({
|
|
6790
|
+
quiet: false
|
|
6791
|
+
}));
|
|
6792
|
+
if (settled.quiet) {
|
|
6793
|
+
try {
|
|
6794
|
+
const retried = await locate();
|
|
6795
|
+
resolved = { ...retried, calls: [...priorCalls, ...retried.calls] };
|
|
6796
|
+
} catch (error2) {
|
|
6797
|
+
if (isRunWideProviderError(error2)) throw error2;
|
|
6798
|
+
throw new LocateRetryError(priorCalls);
|
|
6799
|
+
}
|
|
6800
|
+
}
|
|
6801
|
+
}
|
|
6802
|
+
if (resolved.kind === "unresolved" && resolved.reason === "no_candidates") {
|
|
6803
|
+
const deadline = performance.now() + 8e3;
|
|
6804
|
+
while (performance.now() < deadline && !options.signal?.aborted) {
|
|
6805
|
+
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
6806
|
+
const settled = await quietPage(page, 80, 1e3).catch(() => ({
|
|
6807
|
+
quiet: false
|
|
6808
|
+
}));
|
|
6809
|
+
if (!settled.quiet) continue;
|
|
6810
|
+
try {
|
|
6811
|
+
const fresh = await locate();
|
|
6812
|
+
resolved = { ...fresh, calls: [...resolved.calls, ...fresh.calls] };
|
|
6813
|
+
if (resolved.kind !== "unresolved" || resolved.reason !== "no_candidates")
|
|
6814
|
+
break;
|
|
6815
|
+
} catch (error2) {
|
|
6816
|
+
if (isRunWideProviderError(error2)) throw error2;
|
|
6817
|
+
}
|
|
6818
|
+
}
|
|
6819
|
+
}
|
|
6820
|
+
return resolved;
|
|
6821
|
+
}
|
|
6822
|
+
async function executeSentence(page, step, dependencies, data, opaqueEntries, presentation = {}) {
|
|
6444
6823
|
const started = performance.now();
|
|
6445
6824
|
const report = dependencies.report;
|
|
6446
6825
|
const currentAttempt = report?.test.currentAttempt ?? void 0;
|
|
@@ -6476,7 +6855,7 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6476
6855
|
const sensitive = facts.page?.status === "omitted" && facts.page.reason === "sensitive_page" || acceptedVersion !== void 0 && safeUrl(acceptedVersion.route, privacy).sensitive || safeUrl(page.url, privacy).sensitive;
|
|
6477
6856
|
const isError = typeof outcome === "object" && outcome.status === "could_not_run";
|
|
6478
6857
|
const failed = outcome === "failed" || typeof outcome === "object" && outcome.status === "failed";
|
|
6479
|
-
const flags = facts.verify?.flags
|
|
6858
|
+
const flags = facts.verify?.kind === "verify" ? facts.verify.flags : [];
|
|
6480
6859
|
const needsEvidence = failed || isError || flags.length > 0;
|
|
6481
6860
|
const evidence = !needsEvidence ? { status: "omitted", reason: "clean_step" } : sensitive ? { status: "omitted", reason: "sensitive_page" } : !report.evidenceEnabled ? { status: "omitted", reason: "disabled" } : await capture("evidence", acceptedVersion);
|
|
6482
6861
|
const replayFrame2 = !report.replay ? null : sensitive ? { status: "omitted", reason: "sensitive_page" } : facts.replayFrame ?? await capture("replay", acceptedVersion);
|
|
@@ -6492,12 +6871,13 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6492
6871
|
...facts.failedCalls ?? [],
|
|
6493
6872
|
...facts.verify ? [resultCall(facts.verify.call, "judge", facts.verify.elapsedMs)] : []
|
|
6494
6873
|
];
|
|
6874
|
+
const policy = facts.verify?.kind === "verify" ? facts.verify : null;
|
|
6495
6875
|
const judgement = facts.verify ? {
|
|
6496
6876
|
holds: facts.verify.holds,
|
|
6497
6877
|
contradicted: facts.verify.contradicted,
|
|
6498
|
-
threshold:
|
|
6499
|
-
band:
|
|
6500
|
-
contradictionCutoff:
|
|
6878
|
+
threshold: policy?.minP ?? null,
|
|
6879
|
+
band: policy?.band ?? null,
|
|
6880
|
+
contradictionCutoff: policy?.contradictionCutoff ?? null,
|
|
6501
6881
|
judgedExcerpt: !sensitive && facts.verify.judgedExcerpt ? safeText(facts.verify.judgedExcerpt, privacy, 1500) : null
|
|
6502
6882
|
} : null;
|
|
6503
6883
|
const result = {
|
|
@@ -6506,8 +6886,13 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6506
6886
|
kind,
|
|
6507
6887
|
operation: step.op,
|
|
6508
6888
|
phase: step.phase,
|
|
6509
|
-
sentence: safeText(step.text, privacy, 512),
|
|
6889
|
+
sentence: safeText(presentation.display ?? step.text, privacy, 512),
|
|
6510
6890
|
detail: safeText(facts.detail ?? "", privacy, 512),
|
|
6891
|
+
...presentation.group?.length ? {
|
|
6892
|
+
group: presentation.group.map(
|
|
6893
|
+
(name) => safeText(name, privacy, 120)
|
|
6894
|
+
)
|
|
6895
|
+
} : {},
|
|
6511
6896
|
sourceStack: (step.sourceStack ?? [step.source]).map(
|
|
6512
6897
|
(source) => safeSource(source, dependencies.repoRoot, privacy)
|
|
6513
6898
|
),
|
|
@@ -6553,6 +6938,13 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6553
6938
|
await report.test.addStep(result);
|
|
6554
6939
|
return outcome;
|
|
6555
6940
|
};
|
|
6941
|
+
const runWide = async (error2) => {
|
|
6942
|
+
const outcome = providerFailure(step.source.file, error2);
|
|
6943
|
+
await record(outcome, {
|
|
6944
|
+
error: { code: outcome.code, message: outcome.message }
|
|
6945
|
+
});
|
|
6946
|
+
return error2;
|
|
6947
|
+
};
|
|
6556
6948
|
const quiet = await quietPage(page, 80, 4e3).catch(() => ({
|
|
6557
6949
|
quiet: false
|
|
6558
6950
|
}));
|
|
@@ -6615,12 +7007,16 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6615
7007
|
if (/^(?:the\s+)?page\s+text$/iu.test(match[1].trim())) {
|
|
6616
7008
|
remembered = await page.text();
|
|
6617
7009
|
} else {
|
|
6618
|
-
|
|
7010
|
+
const locateRead = () => resolveTarget(page, dependencies.provider, {
|
|
6619
7011
|
operation: "read",
|
|
6620
7012
|
sentence: match[1],
|
|
6621
7013
|
projectText: (text) => redactOpaqueText(text, opaqueEntries),
|
|
6622
7014
|
...dependencies.signal ? { signal: dependencies.signal } : {}
|
|
6623
7015
|
});
|
|
7016
|
+
locator = await reobserve(page, await locateRead(), locateRead, {
|
|
7017
|
+
staleRetry: true,
|
|
7018
|
+
...dependencies.signal ? { signal: dependencies.signal } : {}
|
|
7019
|
+
});
|
|
6624
7020
|
if (locator.kind !== "resolved")
|
|
6625
7021
|
return record("failed", {
|
|
6626
7022
|
locator,
|
|
@@ -6651,16 +7047,18 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6651
7047
|
const echoedSecrets = opaqueMatches(remembered, opaqueEntries);
|
|
6652
7048
|
const sensitivePage = report ? safeUrl(page.url, report.privacy).sensitive : false;
|
|
6653
7049
|
const opaqueValues = sensitivePage ? [...echoedSecrets, new RuntimeValue(remembered, `{{${match[2]}}}`)] : echoedSecrets;
|
|
7050
|
+
const secret2 = opaqueValues.length > 0;
|
|
6654
7051
|
data[match[2]] = {
|
|
6655
7052
|
value: new RuntimeValue(remembered, `{{${match[2]}}}`),
|
|
6656
|
-
sensitive:
|
|
6657
|
-
modelVisible:
|
|
7053
|
+
sensitive: secret2,
|
|
7054
|
+
modelVisible: !secret2,
|
|
6658
7055
|
opaqueValues
|
|
6659
7056
|
};
|
|
6660
7057
|
opaqueEntries.push(data[match[2]]);
|
|
6661
|
-
report?.privacy.secretValues.push(remembered);
|
|
7058
|
+
if (secret2) report?.privacy.secretValues.push(remembered);
|
|
6662
7059
|
return record("continue", locator ? { locator } : {});
|
|
6663
|
-
} catch {
|
|
7060
|
+
} catch (error2) {
|
|
7061
|
+
if (isRunWideProviderError(error2)) throw await runWide(error2);
|
|
6664
7062
|
return record(
|
|
6665
7063
|
unsupported(
|
|
6666
7064
|
step.source.file,
|
|
@@ -6676,18 +7074,23 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6676
7074
|
);
|
|
6677
7075
|
}
|
|
6678
7076
|
}
|
|
6679
|
-
if (step.op === "verify") {
|
|
6680
|
-
const
|
|
7077
|
+
if (step.op === "verify" || step.op === "measure") {
|
|
7078
|
+
const assertion = {
|
|
6681
7079
|
...dependencies.signal ? { signal: dependencies.signal } : {},
|
|
6682
|
-
projectText: (text) => redactOpaqueText(text, opaqueEntries)
|
|
7080
|
+
projectText: (text) => redactOpaqueText(text, opaqueEntries)
|
|
7081
|
+
};
|
|
7082
|
+
const judge = () => step.op === "measure" ? measure(page, dependencies.provider, claim(step, data), assertion) : verify(page, dependencies.provider, claim(step, data), {
|
|
7083
|
+
...assertion,
|
|
6683
7084
|
...dependencies.verifyPolicy ?? {}
|
|
6684
7085
|
});
|
|
7086
|
+
const outcome = (result) => result.kind === "verify" && result.verdict === "failed" ? "failed" : "continue";
|
|
6685
7087
|
try {
|
|
6686
7088
|
const result = await judge();
|
|
6687
|
-
return record(result
|
|
7089
|
+
return record(outcome(result), {
|
|
6688
7090
|
verify: result
|
|
6689
7091
|
});
|
|
6690
7092
|
} catch (error2) {
|
|
7093
|
+
if (isRunWideProviderError(error2)) throw await runWide(error2);
|
|
6691
7094
|
const priorCalls = error2 instanceof AssertionEngineError && error2.failedCall ? [resultCall(error2.failedCall, "judge")] : [];
|
|
6692
7095
|
if (error2 instanceof AssertionEngineError && error2.code === "stale_observation") {
|
|
6693
7096
|
const settled = await quietPage(page, 80, 4e3).catch(() => ({
|
|
@@ -6696,11 +7099,13 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6696
7099
|
if (settled.quiet) {
|
|
6697
7100
|
try {
|
|
6698
7101
|
const result = await judge();
|
|
6699
|
-
return record(result
|
|
7102
|
+
return record(outcome(result), {
|
|
6700
7103
|
verify: result,
|
|
6701
7104
|
failedCalls: priorCalls
|
|
6702
7105
|
});
|
|
6703
7106
|
} catch (retryError) {
|
|
7107
|
+
if (isRunWideProviderError(retryError))
|
|
7108
|
+
throw await runWide(retryError);
|
|
6704
7109
|
return record(
|
|
6705
7110
|
unsupported(
|
|
6706
7111
|
step.source.file,
|
|
@@ -6737,20 +7142,85 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6737
7142
|
);
|
|
6738
7143
|
}
|
|
6739
7144
|
}
|
|
6740
|
-
if (step.op
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
step.source,
|
|
6745
|
-
`The ${step.op} operation is not part of this walking skeleton.`
|
|
6746
|
-
),
|
|
7145
|
+
if (step.op === "wait" || step.op === "press" || step.op === "scroll" || step.op === "goto") {
|
|
7146
|
+
let command2;
|
|
7147
|
+
let detail = "";
|
|
7148
|
+
const invalid = (message) => record(
|
|
6747
7149
|
{
|
|
7150
|
+
status: "could_not_run",
|
|
7151
|
+
file: step.source.file,
|
|
7152
|
+
code: "invalid_test",
|
|
7153
|
+
source: step.source,
|
|
7154
|
+
message
|
|
7155
|
+
},
|
|
7156
|
+
{ error: { code: "invalid_operand", message } }
|
|
7157
|
+
);
|
|
7158
|
+
if (step.op === "wait") {
|
|
7159
|
+
const durationMs = waitDurationMs(step.text);
|
|
7160
|
+
if (durationMs === null)
|
|
7161
|
+
return invalid("Use a positive wait duration of at most 30 seconds.");
|
|
7162
|
+
command2 = { op: "wait", durationMs };
|
|
7163
|
+
} else if (step.op === "press") {
|
|
7164
|
+
const key = pressKey(step.text);
|
|
7165
|
+
if (key === null)
|
|
7166
|
+
return invalid(
|
|
7167
|
+
'Name one key to press, such as Enter, Tab, Escape, or "Control+A".'
|
|
7168
|
+
);
|
|
7169
|
+
command2 = { op: "press", key };
|
|
7170
|
+
detail = `Pressed ${key}.`;
|
|
7171
|
+
} else if (step.op === "scroll") {
|
|
7172
|
+
const direction = scrollDirection(step.text);
|
|
7173
|
+
if (direction === null) return invalid("Say scroll up or scroll down.");
|
|
7174
|
+
const height = await page.evaluate("window.innerHeight").catch(() => 800);
|
|
7175
|
+
const deltaY = Math.round(Math.max(200, height * 0.8));
|
|
7176
|
+
command2 = {
|
|
7177
|
+
op: "scroll",
|
|
7178
|
+
deltaY: direction === "down" ? deltaY : -deltaY
|
|
7179
|
+
};
|
|
7180
|
+
} else {
|
|
7181
|
+
const parts = gotoUrlParts(step.text);
|
|
7182
|
+
if (parts === null) return invalid("Name exactly one http(s) address.");
|
|
7183
|
+
const values = parts.names.map((name) => data[name]?.value);
|
|
7184
|
+
if (values.some((value) => value === void 0))
|
|
7185
|
+
return record("failed", {
|
|
7186
|
+
error: {
|
|
7187
|
+
code: "missing_remembered_binding",
|
|
7188
|
+
message: "This step needs a value that is unavailable in this attempt."
|
|
7189
|
+
}
|
|
7190
|
+
});
|
|
7191
|
+
const url = new RuntimeUrl(parts.literals, values);
|
|
7192
|
+
try {
|
|
7193
|
+
new URL(url.reveal());
|
|
7194
|
+
} catch {
|
|
7195
|
+
return invalid("The goto address is not a valid URL.");
|
|
7196
|
+
}
|
|
7197
|
+
command2 = { op: "goto", url };
|
|
7198
|
+
detail = `Opened ${url.toString()}.`;
|
|
7199
|
+
}
|
|
7200
|
+
try {
|
|
7201
|
+
await executeStep(page, command2, {
|
|
7202
|
+
...dependencies.signal ? { signal: dependencies.signal } : {}
|
|
7203
|
+
});
|
|
7204
|
+
return record("continue", detail ? { detail } : {});
|
|
7205
|
+
} catch (error2) {
|
|
7206
|
+
const actionError = error2 instanceof StepExecutionError ? error2 : null;
|
|
7207
|
+
const facts = {
|
|
6748
7208
|
error: {
|
|
6749
|
-
code: "
|
|
6750
|
-
message:
|
|
7209
|
+
code: actionError?.code ?? "action_error",
|
|
7210
|
+
message: actionError?.message ?? "The action could not complete.",
|
|
7211
|
+
callLog: actionError?.callLog
|
|
6751
7212
|
}
|
|
6752
|
-
}
|
|
6753
|
-
|
|
7213
|
+
};
|
|
7214
|
+
return actionError?.code === "invalid_input" ? record("failed", facts) : record(
|
|
7215
|
+
unsupported(
|
|
7216
|
+
step.source.file,
|
|
7217
|
+
step.source,
|
|
7218
|
+
actionError?.op === "goto" ? `Could not open the address: ${navigationWhy(actionError)}.` : `The ${step.op} step could not complete.`
|
|
7219
|
+
),
|
|
7220
|
+
facts
|
|
7221
|
+
);
|
|
7222
|
+
}
|
|
7223
|
+
}
|
|
6754
7224
|
const typeOperand = step.op === "type" ? validateTypeOperand(step) : null;
|
|
6755
7225
|
const runtimeDependent = step.tokens.some(
|
|
6756
7226
|
(token) => token.kind === "placeholder" && (step.op === "click" || !typeOperand || "diagnostic" in typeOperand || token.start < typeOperand.operand.start || token.end > typeOperand.operand.end)
|
|
@@ -6780,7 +7250,8 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6780
7250
|
let resolved;
|
|
6781
7251
|
try {
|
|
6782
7252
|
resolved = await locate();
|
|
6783
|
-
} catch {
|
|
7253
|
+
} catch (error2) {
|
|
7254
|
+
if (isRunWideProviderError(error2)) throw await runWide(error2);
|
|
6784
7255
|
return record(
|
|
6785
7256
|
unsupported(
|
|
6786
7257
|
step.source.file,
|
|
@@ -6795,57 +7266,43 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6795
7266
|
}
|
|
6796
7267
|
);
|
|
6797
7268
|
}
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
})
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
}
|
|
6821
|
-
);
|
|
6822
|
-
}
|
|
6823
|
-
}
|
|
6824
|
-
}
|
|
6825
|
-
if (resolved.kind === "unresolved" && resolved.reason === "no_candidates") {
|
|
6826
|
-
const deadline = performance.now() + 8e3;
|
|
6827
|
-
while (performance.now() < deadline && !dependencies.signal?.aborted) {
|
|
6828
|
-
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
6829
|
-
const settled = await quietPage(page, 80, 1e3).catch(() => ({
|
|
6830
|
-
quiet: false
|
|
6831
|
-
}));
|
|
6832
|
-
if (!settled.quiet) continue;
|
|
6833
|
-
try {
|
|
6834
|
-
const fresh = await locate();
|
|
6835
|
-
resolved = { ...fresh, calls: [...resolved.calls, ...fresh.calls] };
|
|
6836
|
-
if (resolved.kind !== "unresolved" || resolved.reason !== "no_candidates")
|
|
6837
|
-
break;
|
|
6838
|
-
} catch {
|
|
7269
|
+
try {
|
|
7270
|
+
resolved = await reobserve(page, resolved, locate, {
|
|
7271
|
+
staleRetry: !visionAttempted,
|
|
7272
|
+
...dependencies.signal ? { signal: dependencies.signal } : {}
|
|
7273
|
+
});
|
|
7274
|
+
} catch (error2) {
|
|
7275
|
+
if (isRunWideProviderError(error2)) throw await runWide(error2);
|
|
7276
|
+
if (!(error2 instanceof LocateRetryError)) throw error2;
|
|
7277
|
+
return record(
|
|
7278
|
+
unsupported(
|
|
7279
|
+
step.source.file,
|
|
7280
|
+
step.source,
|
|
7281
|
+
"The target could not be resolved."
|
|
7282
|
+
),
|
|
7283
|
+
{
|
|
7284
|
+
failedCalls: error2.priorCalls.map(
|
|
7285
|
+
(call2) => resultCall(call2, "locator")
|
|
7286
|
+
),
|
|
7287
|
+
error: {
|
|
7288
|
+
code: "locator_error",
|
|
7289
|
+
message: "The target could not be resolved."
|
|
7290
|
+
}
|
|
6839
7291
|
}
|
|
6840
|
-
|
|
7292
|
+
);
|
|
6841
7293
|
}
|
|
6842
7294
|
if (resolved.kind !== "resolved") {
|
|
6843
7295
|
if (resolved.reason === "none" || resolved.reason === "ambiguous" || resolved.reason === "no_candidates")
|
|
6844
7296
|
return record("failed", {
|
|
6845
7297
|
locator: resolved,
|
|
6846
7298
|
error: {
|
|
6847
|
-
|
|
6848
|
-
|
|
7299
|
+
// "none" reads like "no error"; say what happened.
|
|
7300
|
+
code: resolved.reason === "none" ? "no_match" : resolved.reason,
|
|
7301
|
+
message: `Could not resolve this ${step.op} step: ${unresolvedWhy(
|
|
7302
|
+
resolved,
|
|
7303
|
+
step.op,
|
|
7304
|
+
Boolean(dependencies.visionResolver) && step.op === "click"
|
|
7305
|
+
)}.`
|
|
6849
7306
|
}
|
|
6850
7307
|
});
|
|
6851
7308
|
return record(
|
|
@@ -6863,7 +7320,12 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6863
7320
|
}
|
|
6864
7321
|
);
|
|
6865
7322
|
}
|
|
6866
|
-
|
|
7323
|
+
let chosenOption = null;
|
|
7324
|
+
const commandFor = (target) => step.op === "click" ? {
|
|
7325
|
+
op: "click",
|
|
7326
|
+
target,
|
|
7327
|
+
chooseOption: (labels) => chosenOption = chooseOption(step.text, labels)
|
|
7328
|
+
} : { op: "type", target, value: typeValue };
|
|
6867
7329
|
let command = commandFor(resolved.target);
|
|
6868
7330
|
let locatedPage = report ? await reportPage(
|
|
6869
7331
|
page,
|
|
@@ -6931,7 +7393,12 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6931
7393
|
);
|
|
6932
7394
|
await dependencies.locatorCache.put(seed.key, entry);
|
|
6933
7395
|
} catch (error2) {
|
|
6934
|
-
if (error2 instanceof Error && error2.message
|
|
7396
|
+
if (error2 instanceof Error && error2.message === "candidate_not_distinguishable" && resolved.cache?.reason === "absent")
|
|
7397
|
+
recordedLocator = {
|
|
7398
|
+
...resolved,
|
|
7399
|
+
cache: { ...resolved.cache, reason: "not_cacheable" }
|
|
7400
|
+
};
|
|
7401
|
+
else if (error2 instanceof Error && error2.message !== "candidate_not_distinguishable" && resolved.cache)
|
|
6935
7402
|
recordedLocator = {
|
|
6936
7403
|
...resolved,
|
|
6937
7404
|
cache: {
|
|
@@ -6945,9 +7412,11 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6945
7412
|
locator: recordedLocator,
|
|
6946
7413
|
replayFrame,
|
|
6947
7414
|
targetBox,
|
|
6948
|
-
page: locatedPage
|
|
7415
|
+
page: locatedPage,
|
|
7416
|
+
...chosenOption === null ? {} : { detail: `Chose "${chosenOption}" in the dropdown.` }
|
|
6949
7417
|
});
|
|
6950
7418
|
} catch (error2) {
|
|
7419
|
+
if (isRunWideProviderError(error2)) throw await runWide(error2);
|
|
6951
7420
|
const actionError = error2 instanceof StepExecutionError ? error2 : null;
|
|
6952
7421
|
const failed = actionError && (actionError.code === "not_actionable" || actionError.code === "invalid_input");
|
|
6953
7422
|
const facts = {
|
|
@@ -6971,6 +7440,18 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries) {
|
|
|
6971
7440
|
);
|
|
6972
7441
|
}
|
|
6973
7442
|
}
|
|
7443
|
+
function unresolvedWhy(resolved, op, visionEnabled) {
|
|
7444
|
+
const vision = resolved.diagnostic.vision;
|
|
7445
|
+
const why = resolved.reason === "none" ? "no element on the page matches it; check the wording against the page" : resolved.reason === "no_candidates" ? `the page had nothing to ${op === "type" ? "type into" : op}` : "several elements match it; name the one you mean more precisely";
|
|
7446
|
+
if (vision?.failure)
|
|
7447
|
+
return `${why} (vision ${vision.failure}${vision.httpStatus ? `, HTTP ${vision.httpStatus}` : ""})`;
|
|
7448
|
+
if (!visionEnabled) return why;
|
|
7449
|
+
if (vision?.outcome === "abstained")
|
|
7450
|
+
return `${why}; the vision model did not find it either`;
|
|
7451
|
+
if (!vision && resolved.reason !== "no_candidates")
|
|
7452
|
+
return `${why}; vision fallback could not run (it needs 2 to 40 fully visible, unobscured controls on screen)`;
|
|
7453
|
+
return why;
|
|
7454
|
+
}
|
|
6974
7455
|
async function recordGoalAction(page, action, report, repoRoot, source) {
|
|
6975
7456
|
const attempt = report.test.currentAttempt;
|
|
6976
7457
|
const index = attempt.stepCount + 1;
|
|
@@ -7035,11 +7516,11 @@ async function recordGoalAction(page, action, report, repoRoot, source) {
|
|
|
7035
7516
|
}
|
|
7036
7517
|
async function runFlow(file, runDependencies) {
|
|
7037
7518
|
const absolute = path5.resolve(file);
|
|
7038
|
-
const
|
|
7519
|
+
const loaded2 = await loadFlowFile(absolute, {
|
|
7039
7520
|
repoRoot: runDependencies.repoRoot,
|
|
7040
7521
|
rejectSymlinks: true
|
|
7041
7522
|
});
|
|
7042
|
-
const parsed = await resolveFlowModules(
|
|
7523
|
+
const parsed = await resolveFlowModules(loaded2, {
|
|
7043
7524
|
repoRoot: runDependencies.repoRoot
|
|
7044
7525
|
});
|
|
7045
7526
|
if (!parsed.value) return firstDiagnostic(parsed.diagnostics);
|
|
@@ -7081,7 +7562,7 @@ async function runFlow(file, runDependencies) {
|
|
|
7081
7562
|
).file;
|
|
7082
7563
|
const existing = slot ? recorder.testAt(slot.ordinal) : recorder.latestTest();
|
|
7083
7564
|
const retrying = existing?.file === file2 && existing.currentAttempt?.running === true;
|
|
7084
|
-
const
|
|
7565
|
+
const test2 = retrying ? existing : await recorder.beginTest({
|
|
7085
7566
|
id: parsed.value.identity,
|
|
7086
7567
|
file: file2,
|
|
7087
7568
|
description: safeText(parsed.value.description ?? "", privacy, 512),
|
|
@@ -7089,7 +7570,7 @@ async function runFlow(file, runDependencies) {
|
|
|
7089
7570
|
...slot ? { ordinal: slot.ordinal } : {},
|
|
7090
7571
|
...slot?.lane === void 0 ? {} : { lane: slot.lane }
|
|
7091
7572
|
});
|
|
7092
|
-
dependencies = { ...runBase, report: { ...shared, privacy, test } };
|
|
7573
|
+
dependencies = { ...runBase, report: { ...shared, privacy, test: test2 } };
|
|
7093
7574
|
} else dependencies = runBase;
|
|
7094
7575
|
const classified = await classifyParsedFlow(parsed, {
|
|
7095
7576
|
mode: "allow-model",
|
|
@@ -7119,8 +7600,8 @@ async function runFlow(file, runDependencies) {
|
|
|
7119
7600
|
...Object.values(data).filter((entry) => entry.sensitive).map((entry) => entry.value.reveal())
|
|
7120
7601
|
);
|
|
7121
7602
|
if (dependencies.report && classified.value.goal) {
|
|
7122
|
-
const { test, privacy } = dependencies.report;
|
|
7123
|
-
await
|
|
7603
|
+
const { test: test2, privacy } = dependencies.report;
|
|
7604
|
+
await test2.setGoal({
|
|
7124
7605
|
text: safeText(classified.value.goal.text, privacy, Infinity),
|
|
7125
7606
|
verify: safeText(classified.value.goal.verify, privacy, Infinity)
|
|
7126
7607
|
});
|
|
@@ -7275,10 +7756,10 @@ async function runFlow(file, runDependencies) {
|
|
|
7275
7756
|
);
|
|
7276
7757
|
const goalSource = goalResult.reason === "verification_failed" ? goal.verifySource : goal.source;
|
|
7277
7758
|
if (dependencies.report) {
|
|
7278
|
-
const { test, privacy } = dependencies.report;
|
|
7279
|
-
const attempt =
|
|
7759
|
+
const { test: test2, privacy } = dependencies.report;
|
|
7760
|
+
const attempt = test2.currentAttempt;
|
|
7280
7761
|
const checked = goalResult.verification[0];
|
|
7281
|
-
await
|
|
7762
|
+
await test2.addStep({
|
|
7282
7763
|
id: `${attempt.id}:step:${attempt.stepCount + 1}`,
|
|
7283
7764
|
index: attempt.stepCount + 1,
|
|
7284
7765
|
kind: "verify",
|
|
@@ -7315,7 +7796,11 @@ async function runFlow(file, runDependencies) {
|
|
|
7315
7796
|
),
|
|
7316
7797
|
error: goalResult.status === "failed" ? {
|
|
7317
7798
|
code: goalResult.reason,
|
|
7318
|
-
message:
|
|
7799
|
+
message: safeText(
|
|
7800
|
+
`Goal did not pass: ${goalResult.reason}.${goalResult.detail ? ` The planner was unsure of the ${goalResult.detail}.` : ""}${goalResult.reason.endsWith("_abstention") ? " Name the page or control for that step in the goal, or split the goal into authored steps around it." : ""}`,
|
|
7801
|
+
privacy,
|
|
7802
|
+
512
|
|
7803
|
+
)
|
|
7319
7804
|
} : null,
|
|
7320
7805
|
evidence: { status: "omitted", reason: "goal_summary" },
|
|
7321
7806
|
replayFrame: null,
|
|
@@ -7350,31 +7835,963 @@ async function runFlow(file, runDependencies) {
|
|
|
7350
7835
|
}
|
|
7351
7836
|
}
|
|
7352
7837
|
|
|
7353
|
-
// src/
|
|
7354
|
-
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
}
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
|
|
7838
|
+
// src/script-loader.ts
|
|
7839
|
+
import { existsSync as existsSync2 } from "fs";
|
|
7840
|
+
import path6 from "path";
|
|
7841
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
7842
|
+
import { createJiti } from "jiti";
|
|
7843
|
+
var SCRIPT_TEST_SUFFIX = ".test.ts";
|
|
7844
|
+
function isScriptTestFile(file) {
|
|
7845
|
+
return file.endsWith(SCRIPT_TEST_SUFFIX);
|
|
7846
|
+
}
|
|
7847
|
+
var ID = /^[A-Za-z0-9][A-Za-z0-9._/#:-]{0,199}$/u;
|
|
7848
|
+
var TAG = /^[^\s,][^,]{0,119}$/u;
|
|
7849
|
+
var OPTION_KEYS = /* @__PURE__ */ new Set(["id", "url", "tags"]);
|
|
7850
|
+
var jiti;
|
|
7851
|
+
var loaded = /* @__PURE__ */ new Map();
|
|
7852
|
+
var declared = /* @__PURE__ */ new Map();
|
|
7853
|
+
var queue = Promise.resolve();
|
|
7854
|
+
function diagnostic2(code, source, message, fix) {
|
|
7855
|
+
return { severity: "error", code, source, message, fix };
|
|
7856
|
+
}
|
|
7857
|
+
function checkRegistrations(file, registrations, repoRoot) {
|
|
7858
|
+
const relative = path6.relative(repoRoot, file).split(path6.sep).join("/");
|
|
7859
|
+
const top = { file, line: 1, col: 1 };
|
|
7860
|
+
const diagnostics = [];
|
|
7861
|
+
const tests = [];
|
|
7862
|
+
const titles = /* @__PURE__ */ new Map();
|
|
7863
|
+
const ids = /* @__PURE__ */ new Map();
|
|
7864
|
+
if (registrations.length === 0)
|
|
7865
|
+
diagnostics.push(
|
|
7866
|
+
diagnostic2(
|
|
7867
|
+
"no_tests",
|
|
7868
|
+
top,
|
|
7869
|
+
"This file declares no test.",
|
|
7870
|
+
'Call test("title", async ({ page, ai }) => { ... }) at the top level of the file.'
|
|
7871
|
+
)
|
|
7872
|
+
);
|
|
7873
|
+
for (const registration of registrations) {
|
|
7874
|
+
const called = registration.callSite ? parseFrame(registration.callSite) : void 0;
|
|
7875
|
+
const source = called && samePath(called.file, file) ? { ...called, file } : top;
|
|
7876
|
+
const problems = [];
|
|
7877
|
+
const { title, options, body } = registration;
|
|
7878
|
+
if (typeof title !== "string" || !title.trim() || title.length > 512)
|
|
7879
|
+
problems.push(
|
|
7880
|
+
diagnostic2(
|
|
7881
|
+
"invalid_title",
|
|
7882
|
+
source,
|
|
7883
|
+
"A test title must be a nonblank string of at most 512 characters.",
|
|
7884
|
+
'Write test("a customer signs in", ...).'
|
|
7885
|
+
)
|
|
7886
|
+
);
|
|
7887
|
+
if (typeof body !== "function")
|
|
7888
|
+
problems.push(
|
|
7889
|
+
diagnostic2(
|
|
7890
|
+
"missing_body",
|
|
7891
|
+
source,
|
|
7892
|
+
"This test has no body function.",
|
|
7893
|
+
"Pass an async function as the last argument to test()."
|
|
7894
|
+
)
|
|
7895
|
+
);
|
|
7896
|
+
if (typeof options !== "object" || options === null)
|
|
7897
|
+
problems.push(
|
|
7898
|
+
diagnostic2(
|
|
7899
|
+
"invalid_options",
|
|
7900
|
+
source,
|
|
7901
|
+
"Test options must be an object.",
|
|
7902
|
+
"Pass { url, id, tags } or omit the options."
|
|
7903
|
+
)
|
|
7904
|
+
);
|
|
7905
|
+
else {
|
|
7906
|
+
for (const key of Object.keys(options))
|
|
7907
|
+
if (!OPTION_KEYS.has(key))
|
|
7908
|
+
problems.push(
|
|
7909
|
+
diagnostic2(
|
|
7910
|
+
"unknown_option",
|
|
7911
|
+
source,
|
|
7912
|
+
`Unknown test option \`${key}\`.`,
|
|
7913
|
+
"Use only `url`, `id`, and `tags`."
|
|
7914
|
+
)
|
|
7915
|
+
);
|
|
7916
|
+
if (options.id !== void 0 && (typeof options.id !== "string" || !ID.test(options.id)))
|
|
7917
|
+
problems.push(
|
|
7918
|
+
diagnostic2(
|
|
7919
|
+
"invalid_id",
|
|
7920
|
+
source,
|
|
7921
|
+
"A test id uses letters, digits, and . _ / # : - (at most 200).",
|
|
7922
|
+
"Choose an id such as `checkout-new-user`."
|
|
7923
|
+
)
|
|
7924
|
+
);
|
|
7925
|
+
if (options.url !== void 0 && (typeof options.url !== "string" || !options.url.trim()))
|
|
7926
|
+
problems.push(
|
|
7927
|
+
diagnostic2(
|
|
7928
|
+
"invalid_url",
|
|
7929
|
+
source,
|
|
7930
|
+
"The test url must be a nonblank string.",
|
|
7931
|
+
"Use an absolute URL, or a path relative to baseUrl."
|
|
7932
|
+
)
|
|
7933
|
+
);
|
|
7934
|
+
if (options.tags !== void 0 && (!Array.isArray(options.tags) || options.tags.some((tag) => typeof tag !== "string" || !TAG.test(tag))))
|
|
7935
|
+
problems.push(
|
|
7936
|
+
diagnostic2(
|
|
7937
|
+
"invalid_tags",
|
|
7938
|
+
source,
|
|
7939
|
+
"Tags must be a list of nonblank strings without commas.",
|
|
7940
|
+
'Write tags: ["checkout", "smoke"].'
|
|
7941
|
+
)
|
|
7942
|
+
);
|
|
7943
|
+
}
|
|
7944
|
+
if (problems.length) {
|
|
7945
|
+
diagnostics.push(...problems);
|
|
7946
|
+
continue;
|
|
7947
|
+
}
|
|
7948
|
+
const identity = options.id ?? `${relative}#${title}`;
|
|
7949
|
+
const earlierTitle = titles.get(title);
|
|
7950
|
+
if (earlierTitle) {
|
|
7951
|
+
diagnostics.push(
|
|
7952
|
+
diagnostic2(
|
|
7953
|
+
"duplicate_title",
|
|
7954
|
+
source,
|
|
7955
|
+
`Duplicate test title ${JSON.stringify(title)}; first used on line ${earlierTitle.line}.`,
|
|
7956
|
+
"Give each test in a file its own title."
|
|
7957
|
+
)
|
|
7958
|
+
);
|
|
7959
|
+
continue;
|
|
7960
|
+
}
|
|
7961
|
+
titles.set(title, source);
|
|
7962
|
+
const earlierId = ids.get(identity);
|
|
7963
|
+
if (earlierId) {
|
|
7964
|
+
diagnostics.push(
|
|
7965
|
+
diagnostic2(
|
|
7966
|
+
"duplicate_id",
|
|
7967
|
+
source,
|
|
7968
|
+
`Duplicate test id \`${identity}\`; first used on line ${earlierId.line}.`,
|
|
7969
|
+
"Give each test a unique id."
|
|
7970
|
+
)
|
|
7971
|
+
);
|
|
7972
|
+
continue;
|
|
7973
|
+
}
|
|
7974
|
+
ids.set(identity, source);
|
|
7975
|
+
tests.push({
|
|
7976
|
+
file,
|
|
7977
|
+
title,
|
|
7978
|
+
identity,
|
|
7979
|
+
...options.id === void 0 ? {} : { explicitId: options.id },
|
|
7980
|
+
...options.url === void 0 ? {} : { url: options.url },
|
|
7981
|
+
tags: [...options.tags ?? []],
|
|
7982
|
+
body,
|
|
7983
|
+
source
|
|
7984
|
+
});
|
|
7985
|
+
}
|
|
7986
|
+
return { file, tests, diagnostics };
|
|
7987
|
+
}
|
|
7988
|
+
function authoringEntry() {
|
|
7989
|
+
for (const name of ["./script-api.js", "./script-api.ts"]) {
|
|
7990
|
+
const candidate = fileURLToPath2(new URL(name, import.meta.url));
|
|
7991
|
+
if (existsSync2(candidate)) return candidate;
|
|
7992
|
+
}
|
|
7993
|
+
throw new Error("The Sedum authoring API is missing from this install.");
|
|
7994
|
+
}
|
|
7995
|
+
async function importOnce(file, repoRoot) {
|
|
7996
|
+
jiti ??= createJiti(import.meta.url, {
|
|
7997
|
+
moduleCache: true,
|
|
7998
|
+
alias: { "sedum-cli": authoringEntry() }
|
|
7999
|
+
});
|
|
8000
|
+
const registry = scriptRegistry();
|
|
8001
|
+
registry.pending = [];
|
|
8002
|
+
let failure;
|
|
8003
|
+
try {
|
|
8004
|
+
await jiti.import(file);
|
|
8005
|
+
} catch (error2) {
|
|
8006
|
+
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
8007
|
+
const message = error2 instanceof Error ? error2.message.split("\n")[0] : String(error2);
|
|
8008
|
+
failure = {
|
|
8009
|
+
file,
|
|
8010
|
+
tests: [],
|
|
8011
|
+
diagnostics: [
|
|
8012
|
+
diagnostic2(
|
|
8013
|
+
"load_error",
|
|
8014
|
+
sourceInFile(stack, file) ?? { file, line: 1, col: 1 },
|
|
8015
|
+
`The test file could not be loaded: ${message.slice(0, 300)}`,
|
|
8016
|
+
"Fix the error, or check that its imports are installed."
|
|
8017
|
+
)
|
|
8018
|
+
]
|
|
8019
|
+
};
|
|
8020
|
+
}
|
|
8021
|
+
const evaluated = /* @__PURE__ */ new Map();
|
|
8022
|
+
for (const registration of registry.pending) {
|
|
8023
|
+
const called = registration.callSite ? parseFrame(registration.callSite) : void 0;
|
|
8024
|
+
const owner = pathKey(
|
|
8025
|
+
called && isScriptTestFile(called.file) ? called.file : file
|
|
8026
|
+
);
|
|
8027
|
+
evaluated.set(owner, [...evaluated.get(owner) ?? [], registration]);
|
|
8028
|
+
}
|
|
8029
|
+
for (const [owner, registrations] of evaluated)
|
|
8030
|
+
declared.set(owner, registrations);
|
|
8031
|
+
registry.pending = [];
|
|
8032
|
+
return failure ?? checkRegistrations(file, declared.get(pathKey(file)) ?? [], repoRoot);
|
|
8033
|
+
}
|
|
8034
|
+
function loadScriptFile(file, options) {
|
|
8035
|
+
const absolute = path6.resolve(file);
|
|
8036
|
+
let pending = loaded.get(absolute);
|
|
8037
|
+
if (!pending) {
|
|
8038
|
+
pending = queue.then(() => importOnce(absolute, options.repoRoot));
|
|
8039
|
+
queue = pending.catch(() => void 0);
|
|
8040
|
+
loaded.set(absolute, pending);
|
|
8041
|
+
}
|
|
8042
|
+
return pending;
|
|
8043
|
+
}
|
|
8044
|
+
function scriptListingEntries(script) {
|
|
8045
|
+
const coverage = {
|
|
8046
|
+
format: "passed",
|
|
8047
|
+
steps: "not_checked",
|
|
8048
|
+
modules: "not_needed"
|
|
8049
|
+
};
|
|
8050
|
+
const problems = script.diagnostics.length ? [
|
|
8051
|
+
{
|
|
8052
|
+
file: script.file,
|
|
8053
|
+
result: {
|
|
8054
|
+
diagnostics: script.diagnostics,
|
|
8055
|
+
coverage: { ...coverage, format: "failed" }
|
|
8056
|
+
}
|
|
8057
|
+
}
|
|
8058
|
+
] : [];
|
|
8059
|
+
return [
|
|
8060
|
+
...problems,
|
|
8061
|
+
...script.tests.map((test2) => {
|
|
8062
|
+
const header = {
|
|
8063
|
+
version: 1,
|
|
8064
|
+
file: test2.file,
|
|
8065
|
+
identity: test2.identity,
|
|
8066
|
+
...test2.explicitId === void 0 ? {} : { explicitId: test2.explicitId, idSource: test2.source },
|
|
8067
|
+
description: test2.title,
|
|
8068
|
+
...test2.url === void 0 ? {} : { url: test2.url },
|
|
8069
|
+
tags: test2.tags,
|
|
8070
|
+
meta: {},
|
|
8071
|
+
data: {},
|
|
8072
|
+
before: [],
|
|
8073
|
+
steps: [],
|
|
8074
|
+
after: []
|
|
8075
|
+
};
|
|
8076
|
+
return {
|
|
8077
|
+
file: test2.file,
|
|
8078
|
+
result: { value: header, diagnostics: [], coverage }
|
|
8079
|
+
};
|
|
8080
|
+
})
|
|
8081
|
+
];
|
|
8082
|
+
}
|
|
8083
|
+
|
|
8084
|
+
// src/script-sentences.ts
|
|
8085
|
+
var IDENT_START = /[A-Za-z_$]/u;
|
|
8086
|
+
var IDENT_PART = /[A-Za-z0-9_$]/u;
|
|
8087
|
+
var REGEX_AFTER = /* @__PURE__ */ new Set([
|
|
8088
|
+
"(",
|
|
8089
|
+
",",
|
|
8090
|
+
"=",
|
|
8091
|
+
":",
|
|
8092
|
+
"[",
|
|
8093
|
+
"!",
|
|
8094
|
+
"&",
|
|
8095
|
+
"|",
|
|
8096
|
+
"?",
|
|
8097
|
+
"{",
|
|
8098
|
+
"}",
|
|
8099
|
+
";",
|
|
8100
|
+
"+",
|
|
8101
|
+
"-",
|
|
8102
|
+
"*",
|
|
8103
|
+
"%",
|
|
8104
|
+
"<",
|
|
8105
|
+
">",
|
|
8106
|
+
"~",
|
|
8107
|
+
"^",
|
|
8108
|
+
"=>",
|
|
8109
|
+
"return",
|
|
8110
|
+
"typeof",
|
|
8111
|
+
"case",
|
|
8112
|
+
"do",
|
|
8113
|
+
"else",
|
|
8114
|
+
"in",
|
|
8115
|
+
"of",
|
|
8116
|
+
"new",
|
|
8117
|
+
"delete",
|
|
8118
|
+
"void",
|
|
8119
|
+
"throw",
|
|
8120
|
+
"yield",
|
|
8121
|
+
"await"
|
|
8122
|
+
]);
|
|
8123
|
+
function tokenize(source) {
|
|
8124
|
+
const tokens = [];
|
|
8125
|
+
let index = 0;
|
|
8126
|
+
let line = 1;
|
|
8127
|
+
let col = 1;
|
|
8128
|
+
const advance = (count2 = 1) => {
|
|
8129
|
+
for (let step = 0; step < count2 && index < source.length; step++) {
|
|
8130
|
+
if (source[index] === "\n") {
|
|
8131
|
+
line++;
|
|
8132
|
+
col = 1;
|
|
8133
|
+
} else col++;
|
|
8134
|
+
index++;
|
|
8135
|
+
}
|
|
8136
|
+
};
|
|
8137
|
+
const readQuoted = (quote) => {
|
|
8138
|
+
let value = "";
|
|
8139
|
+
let dynamic = false;
|
|
8140
|
+
let depth = 0;
|
|
8141
|
+
advance();
|
|
8142
|
+
while (index < source.length) {
|
|
8143
|
+
const char = source[index];
|
|
8144
|
+
if (char === "\\") {
|
|
8145
|
+
const next = source[index + 1] ?? "";
|
|
8146
|
+
const hex = next === "x" ? /^[0-9A-Fa-f]{2}/u.exec(source.slice(index + 2))?.[0] : next === "u" ? /^\{([0-9A-Fa-f]{1,6})\}/u.exec(source.slice(index + 2)) ?? /^([0-9A-Fa-f]{4})/u.exec(source.slice(index + 2)) : void 0;
|
|
8147
|
+
if (typeof hex === "string") {
|
|
8148
|
+
value += String.fromCharCode(parseInt(hex, 16));
|
|
8149
|
+
advance(4);
|
|
8150
|
+
} else if (hex) {
|
|
8151
|
+
const code = parseInt(hex[1], 16);
|
|
8152
|
+
value += code <= 1114111 ? String.fromCodePoint(code) : "";
|
|
8153
|
+
advance(2 + hex[0].length);
|
|
8154
|
+
} else {
|
|
8155
|
+
const escapes = {
|
|
8156
|
+
n: "\n",
|
|
8157
|
+
t: " ",
|
|
8158
|
+
r: "\r",
|
|
8159
|
+
b: "\b",
|
|
8160
|
+
f: "\f",
|
|
8161
|
+
v: "\v",
|
|
8162
|
+
"0": "\0",
|
|
8163
|
+
"\n": ""
|
|
8164
|
+
};
|
|
8165
|
+
value += escapes[next] ?? next;
|
|
8166
|
+
advance(2);
|
|
8167
|
+
}
|
|
8168
|
+
continue;
|
|
8169
|
+
}
|
|
8170
|
+
if (quote === "`" && char === "$" && source[index + 1] === "{") {
|
|
8171
|
+
dynamic = true;
|
|
8172
|
+
depth = 1;
|
|
8173
|
+
advance(2);
|
|
8174
|
+
while (index < source.length && depth > 0) {
|
|
8175
|
+
const inner = source[index];
|
|
8176
|
+
if (inner === "{") depth++;
|
|
8177
|
+
else if (inner === "}") depth--;
|
|
8178
|
+
else if (inner === '"' || inner === "'" || inner === "`") {
|
|
8179
|
+
readQuoted(inner);
|
|
8180
|
+
continue;
|
|
8181
|
+
}
|
|
8182
|
+
advance();
|
|
8183
|
+
}
|
|
8184
|
+
continue;
|
|
8185
|
+
}
|
|
8186
|
+
if (char === quote) {
|
|
8187
|
+
advance();
|
|
8188
|
+
break;
|
|
8189
|
+
}
|
|
8190
|
+
if (quote !== "`" && char === "\n") break;
|
|
8191
|
+
value += char;
|
|
8192
|
+
advance();
|
|
8193
|
+
}
|
|
8194
|
+
return { value, dynamic };
|
|
8195
|
+
};
|
|
8196
|
+
while (index < source.length) {
|
|
8197
|
+
const char = source[index];
|
|
8198
|
+
const next = source[index + 1];
|
|
8199
|
+
if (/\s/u.test(char)) {
|
|
8200
|
+
advance();
|
|
8201
|
+
continue;
|
|
8202
|
+
}
|
|
8203
|
+
if (char === "/" && next === "/") {
|
|
8204
|
+
while (index < source.length && source[index] !== "\n") advance();
|
|
8205
|
+
continue;
|
|
8206
|
+
}
|
|
8207
|
+
if (char === "/" && next === "*") {
|
|
8208
|
+
advance(2);
|
|
8209
|
+
while (index < source.length && !(source[index] === "*" && source[index + 1] === "/"))
|
|
8210
|
+
advance();
|
|
8211
|
+
advance(2);
|
|
8212
|
+
continue;
|
|
8213
|
+
}
|
|
8214
|
+
const startLine = line;
|
|
8215
|
+
const startCol = col;
|
|
8216
|
+
if (char === '"' || char === "'" || char === "`") {
|
|
8217
|
+
const { value, dynamic } = readQuoted(char);
|
|
8218
|
+
tokens.push({
|
|
8219
|
+
kind: "string",
|
|
8220
|
+
value,
|
|
8221
|
+
dynamic,
|
|
8222
|
+
line: startLine,
|
|
8223
|
+
col: startCol
|
|
8224
|
+
});
|
|
8225
|
+
continue;
|
|
8226
|
+
}
|
|
8227
|
+
if (char === "/") {
|
|
8228
|
+
const previous = tokens.at(-1);
|
|
8229
|
+
const before = tokens.at(-2);
|
|
8230
|
+
const postfix = (previous?.value === "+" || previous?.value === "-") && before?.value === previous.value;
|
|
8231
|
+
if (!postfix && (!previous || REGEX_AFTER.has(previous.value))) {
|
|
8232
|
+
let inClass = false;
|
|
8233
|
+
advance();
|
|
8234
|
+
while (index < source.length && source[index] !== "\n") {
|
|
8235
|
+
const inner = source[index];
|
|
8236
|
+
if (inner === "\\") {
|
|
8237
|
+
advance(2);
|
|
8238
|
+
continue;
|
|
8239
|
+
}
|
|
8240
|
+
if (inner === "[") inClass = true;
|
|
8241
|
+
else if (inner === "]") inClass = false;
|
|
8242
|
+
else if (inner === "/" && !inClass) {
|
|
8243
|
+
advance();
|
|
8244
|
+
break;
|
|
8245
|
+
}
|
|
8246
|
+
advance();
|
|
8247
|
+
}
|
|
8248
|
+
while (index < source.length && IDENT_PART.test(source[index]))
|
|
8249
|
+
advance();
|
|
8250
|
+
tokens.push({
|
|
8251
|
+
kind: "punct",
|
|
8252
|
+
value: "/re/",
|
|
8253
|
+
line: startLine,
|
|
8254
|
+
col: startCol
|
|
8255
|
+
});
|
|
8256
|
+
continue;
|
|
8257
|
+
}
|
|
8258
|
+
}
|
|
8259
|
+
if (IDENT_START.test(char)) {
|
|
8260
|
+
let value = "";
|
|
8261
|
+
while (index < source.length && IDENT_PART.test(source[index])) {
|
|
8262
|
+
value += source[index];
|
|
8263
|
+
advance();
|
|
8264
|
+
}
|
|
8265
|
+
tokens.push({ kind: "ident", value, line: startLine, col: startCol });
|
|
8266
|
+
continue;
|
|
8267
|
+
}
|
|
8268
|
+
if (char === "=" && next === ">") {
|
|
8269
|
+
advance(2);
|
|
8270
|
+
tokens.push({
|
|
8271
|
+
kind: "punct",
|
|
8272
|
+
value: "=>",
|
|
8273
|
+
line: startLine,
|
|
8274
|
+
col: startCol
|
|
8275
|
+
});
|
|
8276
|
+
continue;
|
|
8277
|
+
}
|
|
8278
|
+
advance();
|
|
8279
|
+
tokens.push({ kind: "punct", value: char, line: startLine, col: startCol });
|
|
8280
|
+
}
|
|
8281
|
+
return tokens;
|
|
8282
|
+
}
|
|
8283
|
+
function scanScriptSentences(source, file) {
|
|
8284
|
+
const tokens = tokenize(source);
|
|
8285
|
+
const sentences = [];
|
|
8286
|
+
const warnings = [];
|
|
8287
|
+
const at2 = (index) => tokens[index];
|
|
8288
|
+
const isPunct = (index, value2) => at2(index)?.kind === "punct" && at2(index).value === value2;
|
|
8289
|
+
const dynamic = (token) => warnings.push({
|
|
8290
|
+
severity: "warning",
|
|
8291
|
+
code: "dynamic_sentence",
|
|
8292
|
+
source: { file, line: token.line, col: token.col },
|
|
8293
|
+
message: "This step sentence is not a literal, so it cannot be checked before a run, and a sentence built from values is classified again for every value.",
|
|
8294
|
+
fix: 'Write a literal sentence with {{name}} and pass the value separately: ai("type {{email}} into the Email field", { email }).'
|
|
8295
|
+
});
|
|
8296
|
+
const TERMINATORS = /* @__PURE__ */ new Set([",", ")", "]", ";"]);
|
|
8297
|
+
const skipExpression = (index) => {
|
|
8298
|
+
let depth = 0;
|
|
8299
|
+
let cursor = index;
|
|
8300
|
+
for (; cursor < tokens.length; cursor++) {
|
|
8301
|
+
const token = tokens[cursor];
|
|
8302
|
+
if (token.kind !== "punct") continue;
|
|
8303
|
+
if (depth === 0 && TERMINATORS.has(token.value)) return cursor;
|
|
8304
|
+
if ("([{".includes(token.value)) depth++;
|
|
8305
|
+
else if (")]}".includes(token.value)) depth--;
|
|
8306
|
+
}
|
|
8307
|
+
return cursor;
|
|
8308
|
+
};
|
|
8309
|
+
const match = /* @__PURE__ */ new Map();
|
|
8310
|
+
const parentOf = [];
|
|
8311
|
+
{
|
|
8312
|
+
const open2 = [];
|
|
8313
|
+
tokens.forEach((token, index) => {
|
|
8314
|
+
parentOf[index] = open2.at(-1);
|
|
8315
|
+
if (token.kind !== "punct") return;
|
|
8316
|
+
if ("([{".includes(token.value)) open2.push(index);
|
|
8317
|
+
else if (")]}".includes(token.value)) {
|
|
8318
|
+
const opener = open2.pop();
|
|
8319
|
+
if (opener !== void 0) match.set(opener, index);
|
|
8320
|
+
}
|
|
8321
|
+
});
|
|
8322
|
+
}
|
|
8323
|
+
const value = (index) => at2(index)?.value;
|
|
8324
|
+
const DECLARE = /* @__PURE__ */ new Set(["const", "let", "var", "function", "class"]);
|
|
8325
|
+
const COMPOUND = /* @__PURE__ */ new Set([
|
|
8326
|
+
"+",
|
|
8327
|
+
"-",
|
|
8328
|
+
"*",
|
|
8329
|
+
"/",
|
|
8330
|
+
"%",
|
|
8331
|
+
"&",
|
|
8332
|
+
"|",
|
|
8333
|
+
"^",
|
|
8334
|
+
"<",
|
|
8335
|
+
">",
|
|
8336
|
+
"?"
|
|
8337
|
+
]);
|
|
8338
|
+
const CONTROL = /* @__PURE__ */ new Set(["if", "while", "for", "switch", "with"]);
|
|
8339
|
+
const MUTATORS = /* @__PURE__ */ new Set([
|
|
8340
|
+
"push",
|
|
8341
|
+
"unshift",
|
|
8342
|
+
"splice",
|
|
8343
|
+
"pop",
|
|
8344
|
+
"shift",
|
|
8345
|
+
"sort",
|
|
8346
|
+
"reverse",
|
|
8347
|
+
"fill",
|
|
8348
|
+
"copyWithin"
|
|
8349
|
+
]);
|
|
8350
|
+
const binds = (index) => {
|
|
8351
|
+
const next = value(index + 1);
|
|
8352
|
+
const prev = value(index - 1);
|
|
8353
|
+
if (DECLARE.has(prev ?? "") || next === "=>") return true;
|
|
8354
|
+
if (next === "=" && value(index + 2) !== "=") return true;
|
|
8355
|
+
if (COMPOUND.has(next ?? "") && value(index + 2) === "=") return true;
|
|
8356
|
+
if (next === "+" && value(index + 2) === "+" || next === "-" && value(index + 2) === "-" || prev === "+" && value(index - 2) === "+" || prev === "-" && value(index - 2) === "-")
|
|
8357
|
+
return true;
|
|
8358
|
+
if (next === "." && MUTATORS.has(value(index + 2) ?? "")) return true;
|
|
8359
|
+
if (next === "[") {
|
|
8360
|
+
const close = match.get(index + 1);
|
|
8361
|
+
if (close !== void 0 && value(close + 1) === "=" && value(close + 2) !== "=")
|
|
8362
|
+
return true;
|
|
8363
|
+
}
|
|
8364
|
+
for (let parent = parentOf[index]; parent !== void 0; ) {
|
|
8365
|
+
const close = match.get(parent);
|
|
8366
|
+
const after = close === void 0 ? void 0 : value(close + 1);
|
|
8367
|
+
if (value(parent) === "(") {
|
|
8368
|
+
if (after === "=>") return true;
|
|
8369
|
+
if (after === "{" && !CONTROL.has(value(parent - 1) ?? "")) return true;
|
|
8370
|
+
if (after === ":" && close !== void 0) {
|
|
8371
|
+
for (let cursor = close + 2; cursor < close + 40; cursor++) {
|
|
8372
|
+
const token = value(cursor);
|
|
8373
|
+
if (token === "=>" || token === "{") return true;
|
|
8374
|
+
if (token === void 0 || token === ";" || token === ")") break;
|
|
8375
|
+
const skip = match.get(cursor);
|
|
8376
|
+
if (skip !== void 0 && token !== "{") cursor = skip;
|
|
8377
|
+
}
|
|
8378
|
+
}
|
|
8379
|
+
return false;
|
|
8380
|
+
}
|
|
8381
|
+
if (after === "=" && value((close ?? 0) + 2) !== "=") return true;
|
|
8382
|
+
if (DECLARE.has(value(parent - 1) ?? "")) return true;
|
|
8383
|
+
parent = parentOf[parent];
|
|
8384
|
+
}
|
|
8385
|
+
return false;
|
|
8386
|
+
};
|
|
8387
|
+
const endsCleanly = (last) => {
|
|
8388
|
+
const next = at2(last + 1);
|
|
8389
|
+
return next === void 0 || next.line > at2(last).line && !".[(?".includes(next.value) || next.value === ";" || next.value === "," || next.value === "as" && value(last + 2) === "const";
|
|
8390
|
+
};
|
|
8391
|
+
const constants3 = /* @__PURE__ */ new Map();
|
|
8392
|
+
{
|
|
8393
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
8394
|
+
tokens.forEach((token, index) => {
|
|
8395
|
+
if (token.kind === "ident" && binds(index) && value(index - 1) !== ".")
|
|
8396
|
+
bindings.set(token.value, (bindings.get(token.value) ?? 0) + 1);
|
|
8397
|
+
});
|
|
8398
|
+
tokens.forEach((token, index) => {
|
|
8399
|
+
const name = at2(index + 1);
|
|
8400
|
+
if (token.kind !== "ident" || token.value !== "const" || name?.kind !== "ident" || !isPunct(index + 2, "=") || bindings.get(name.value) !== 1)
|
|
8401
|
+
return;
|
|
8402
|
+
const start = index + 3;
|
|
8403
|
+
const last = at2(start)?.kind === "string" ? start : isPunct(start, "[") ? match.get(start) : void 0;
|
|
8404
|
+
if (last !== void 0 && endsCleanly(last))
|
|
8405
|
+
constants3.set(name.value, start);
|
|
8406
|
+
});
|
|
8407
|
+
}
|
|
8408
|
+
const MAX_SENTENCES = 1e4;
|
|
8409
|
+
const MAX_DEPTH = 32;
|
|
8410
|
+
let truncated = false;
|
|
8411
|
+
const reading = /* @__PURE__ */ new Set();
|
|
8412
|
+
const argument = (index) => {
|
|
8413
|
+
const token = at2(index);
|
|
8414
|
+
if (!token) return index;
|
|
8415
|
+
const end = skipExpression(index);
|
|
8416
|
+
if (token.kind === "string" && end === index + 1) {
|
|
8417
|
+
if (token.dynamic) dynamic(token);
|
|
8418
|
+
else if (sentences.length >= MAX_SENTENCES) truncated = true;
|
|
8419
|
+
else
|
|
8420
|
+
sentences.push({
|
|
8421
|
+
text: token.value,
|
|
8422
|
+
source: { file, line: token.line, col: token.col }
|
|
8423
|
+
});
|
|
8424
|
+
return end;
|
|
8425
|
+
}
|
|
8426
|
+
const declared2 = token.kind === "ident" && end === index + 1 ? constants3.get(token.value) : void 0;
|
|
8427
|
+
if (declared2 !== void 0 && (reading.size >= MAX_DEPTH || sentences.length >= MAX_SENTENCES)) {
|
|
8428
|
+
truncated = true;
|
|
8429
|
+
return end;
|
|
8430
|
+
}
|
|
8431
|
+
if (declared2 !== void 0 && !reading.has(token.value)) {
|
|
8432
|
+
reading.add(token.value);
|
|
8433
|
+
if (isPunct(declared2, "[")) list(declared2);
|
|
8434
|
+
else argument(declared2);
|
|
8435
|
+
reading.delete(token.value);
|
|
8436
|
+
return end;
|
|
8437
|
+
}
|
|
8438
|
+
dynamic(token);
|
|
8439
|
+
return end;
|
|
8440
|
+
};
|
|
8441
|
+
const list = (index) => {
|
|
8442
|
+
let cursor = index + 1;
|
|
8443
|
+
while (cursor < tokens.length && !isPunct(cursor, "]")) {
|
|
8444
|
+
cursor = argument(cursor);
|
|
8445
|
+
if (isPunct(cursor, ",")) cursor++;
|
|
8446
|
+
else if (!isPunct(cursor, "]")) cursor++;
|
|
8447
|
+
}
|
|
8448
|
+
};
|
|
8449
|
+
const call2 = (open2) => {
|
|
8450
|
+
const first = open2 + 1;
|
|
8451
|
+
if (isPunct(first, ")")) return;
|
|
8452
|
+
if (isPunct(first, "[")) list(first);
|
|
8453
|
+
else argument(first);
|
|
8454
|
+
};
|
|
8455
|
+
const inlineFunction = (index) => {
|
|
8456
|
+
let cursor = index;
|
|
8457
|
+
if (value(cursor) === "async") cursor++;
|
|
8458
|
+
if (value(cursor) === "function") return true;
|
|
8459
|
+
if (at2(cursor)?.kind === "ident" && value(cursor + 1) === "=>") return true;
|
|
8460
|
+
const close = isPunct(cursor, "(") ? match.get(cursor) : void 0;
|
|
8461
|
+
return close !== void 0 && value(close + 1) === "=>";
|
|
8462
|
+
};
|
|
8463
|
+
const parameters = (paren) => {
|
|
8464
|
+
const close = match.get(paren);
|
|
8465
|
+
if (close === void 0) return [];
|
|
8466
|
+
const names = [];
|
|
8467
|
+
let expectName = true;
|
|
8468
|
+
for (let cursor = paren + 1; cursor < close; cursor++) {
|
|
8469
|
+
if (expectName) {
|
|
8470
|
+
const token = at2(cursor);
|
|
8471
|
+
names.push(token?.kind === "ident" ? token.value : "");
|
|
8472
|
+
expectName = false;
|
|
8473
|
+
}
|
|
8474
|
+
const skip = match.get(cursor);
|
|
8475
|
+
if (skip !== void 0) cursor = skip;
|
|
8476
|
+
else if (isPunct(cursor, ",")) expectName = true;
|
|
8477
|
+
}
|
|
8478
|
+
return names;
|
|
8479
|
+
};
|
|
8480
|
+
const bindingCount = /* @__PURE__ */ new Map();
|
|
8481
|
+
tokens.forEach((token, index) => {
|
|
8482
|
+
if (token.kind === "ident" && value(index - 1) !== "." && binds(index))
|
|
8483
|
+
bindingCount.set(token.value, (bindingCount.get(token.value) ?? 0) + 1);
|
|
8484
|
+
});
|
|
8485
|
+
const functions = /* @__PURE__ */ new Map();
|
|
8486
|
+
const ambiguous = /* @__PURE__ */ new Set();
|
|
8487
|
+
tokens.forEach((token, index) => {
|
|
8488
|
+
const name = at2(index + 1);
|
|
8489
|
+
if (token.kind !== "ident" || name?.kind !== "ident") return;
|
|
8490
|
+
if ((bindingCount.get(name.value) ?? 0) > 1) {
|
|
8491
|
+
if (token.value === "function" && isPunct(index + 2, "(") || ["const", "let", "var"].includes(token.value) && isPunct(index + 2, "=") && inlineFunction(index + 3))
|
|
8492
|
+
ambiguous.add(name.value);
|
|
8493
|
+
return;
|
|
8494
|
+
}
|
|
8495
|
+
if (token.value === "function" && isPunct(index + 2, "("))
|
|
8496
|
+
functions.set(name.value, parameters(index + 2));
|
|
8497
|
+
else if (["const", "let", "var"].includes(token.value) && isPunct(index + 2, "=") && inlineFunction(index + 3)) {
|
|
8498
|
+
let start = index + 3;
|
|
8499
|
+
if (value(start) === "async") start++;
|
|
8500
|
+
if (value(start) === "function") start++;
|
|
8501
|
+
if (isPunct(start, "(")) functions.set(name.value, parameters(start));
|
|
8502
|
+
else if (at2(start)?.kind === "ident" && isPunct(start + 1, "("))
|
|
8503
|
+
functions.set(name.value, parameters(start + 1));
|
|
8504
|
+
else if (at2(start)?.kind === "ident")
|
|
8505
|
+
functions.set(name.value, [value(start)]);
|
|
8506
|
+
}
|
|
8507
|
+
});
|
|
8508
|
+
const helperCalls = [];
|
|
8509
|
+
const aliasUse = (index) => {
|
|
8510
|
+
const next = value(index + 1);
|
|
8511
|
+
const prev = value(index - 1);
|
|
8512
|
+
if (next === "(" || next === "?") return void 0;
|
|
8513
|
+
if (next === ".") {
|
|
8514
|
+
const member = value(index + 2);
|
|
8515
|
+
return ["call", "apply", "bind"].includes(member ?? "") ? "This ai call is written indirectly, so its sentences are not checked before a run." : void 0;
|
|
8516
|
+
}
|
|
8517
|
+
if (next === ":") {
|
|
8518
|
+
const brace = parentOf[index];
|
|
8519
|
+
return brace !== void 0 && DECLARE.has(value(brace - 1) ?? "") && at2(index + 2)?.kind === "ident" ? "`ai` is renamed here, so the steps called through the new name are not checked before a run." : void 0;
|
|
8520
|
+
}
|
|
8521
|
+
if ((prev === "{" || prev === ",") && (next === "}" || next === ",")) {
|
|
8522
|
+
const brace = parentOf[index];
|
|
8523
|
+
if (brace !== void 0 && value(brace) === "{")
|
|
8524
|
+
return handedOver(brace, "`{ ai }`");
|
|
8525
|
+
}
|
|
8526
|
+
const parent = parentOf[index];
|
|
8527
|
+
if (parent !== void 0 && value(parent) === "(") {
|
|
8528
|
+
const close = match.get(parent);
|
|
8529
|
+
const after = close === void 0 ? void 0 : value(close + 1);
|
|
8530
|
+
if (after === "=>" || after === "{" || after === ":") return void 0;
|
|
8531
|
+
const callee = at2(parent - 1);
|
|
8532
|
+
if (callee?.kind === "ident" && value(parent - 2) !== "." && !CONTROL.has(callee.value) && (next === "," || next === ")")) {
|
|
8533
|
+
let position2 = 0;
|
|
8534
|
+
for (let cursor = parent + 1; cursor < index; cursor++) {
|
|
8535
|
+
const skip = match.get(cursor);
|
|
8536
|
+
if (skip !== void 0) cursor = skip;
|
|
8537
|
+
else if (isPunct(cursor, ",")) position2++;
|
|
8538
|
+
}
|
|
8539
|
+
if (ambiguous.has(callee.value))
|
|
8540
|
+
return `\`${callee.value}\` is declared more than once in this file, so validation cannot tell which one receives the test's ai.`;
|
|
8541
|
+
const local = functions.get(callee.value);
|
|
8542
|
+
if (local)
|
|
8543
|
+
return local[position2] === "ai" ? void 0 : `\`${callee.value}\` receives the test's ai under another name, so the steps it runs are not checked before a run.`;
|
|
8544
|
+
const token = at2(index);
|
|
8545
|
+
helperCalls.push({
|
|
8546
|
+
callee: callee.value,
|
|
8547
|
+
position: position2,
|
|
8548
|
+
source: { file, line: token.line, col: token.col },
|
|
8549
|
+
passes: "ai"
|
|
8550
|
+
});
|
|
8551
|
+
return void 0;
|
|
8552
|
+
}
|
|
8553
|
+
}
|
|
8554
|
+
return "`ai` is passed on as a value here, so the steps it runs are not checked before a run.";
|
|
8555
|
+
};
|
|
8556
|
+
const handedOver = (index, what) => {
|
|
8557
|
+
const parent = parentOf[index];
|
|
8558
|
+
if (parent === void 0 || value(parent) !== "(") return void 0;
|
|
8559
|
+
const close = match.get(parent);
|
|
8560
|
+
const after = close === void 0 ? void 0 : value(close + 1);
|
|
8561
|
+
if (after === "=>" || after === "{" || after === ":") return void 0;
|
|
8562
|
+
const callee = at2(parent - 1);
|
|
8563
|
+
if (callee?.kind !== "ident" || CONTROL.has(callee.value)) return void 0;
|
|
8564
|
+
if (value(parent - 2) === ".")
|
|
8565
|
+
return `${what} is handed to \`${callee.value}\` through another object, so the steps it runs are not checked before a run.`;
|
|
8566
|
+
if (ambiguous.has(callee.value))
|
|
8567
|
+
return `\`${callee.value}\` is declared more than once in this file, so validation cannot tell which one receives ${what}.`;
|
|
8568
|
+
if (functions.has(callee.value)) return void 0;
|
|
8569
|
+
let position2 = 0;
|
|
8570
|
+
for (let cursor = parent + 1; cursor < index; cursor++) {
|
|
8571
|
+
const skip = match.get(cursor);
|
|
8572
|
+
if (skip !== void 0) cursor = skip;
|
|
8573
|
+
else if (isPunct(cursor, ",")) position2++;
|
|
8574
|
+
}
|
|
8575
|
+
const token = at2(index);
|
|
8576
|
+
helperCalls.push({
|
|
8577
|
+
callee: callee.value,
|
|
8578
|
+
position: position2,
|
|
8579
|
+
source: { file, line: token.line, col: token.col },
|
|
8580
|
+
passes: "context"
|
|
8581
|
+
});
|
|
8582
|
+
return void 0;
|
|
8583
|
+
};
|
|
8584
|
+
const unchecked = (token, message) => warnings.push({
|
|
8585
|
+
severity: "warning",
|
|
8586
|
+
code: "unchecked_call",
|
|
8587
|
+
source: { file, line: token.line, col: token.col },
|
|
8588
|
+
message,
|
|
8589
|
+
fix: "Call the test's `ai` directly, as ai(...) or ai.group(...), so its sentences can be checked before a run."
|
|
8590
|
+
});
|
|
8591
|
+
const renamedParameter = (index) => {
|
|
8592
|
+
if (!isPunct(index + 1, ":") || at2(index + 2)?.kind !== "ident")
|
|
8593
|
+
return false;
|
|
8594
|
+
const brace = parentOf[index];
|
|
8595
|
+
if (brace === void 0 || value(brace) !== "{") return false;
|
|
8596
|
+
if (value(brace - 1) === ":") return false;
|
|
8597
|
+
const paren = parentOf[brace];
|
|
8598
|
+
if (paren === void 0 || value(paren) !== "(") return false;
|
|
8599
|
+
const close = match.get(paren);
|
|
8600
|
+
return close !== void 0 && (value(close + 1) === "=>" || value(close + 1) === "{");
|
|
8601
|
+
};
|
|
8602
|
+
tokens.forEach((token, index) => {
|
|
8603
|
+
if (token.kind === "string" && !token.dynamic && token.value === "ai" && isPunct(index - 1, "[") && isPunct(index + 1, "]") && value(index - 2) !== "TestContext")
|
|
8604
|
+
unchecked(
|
|
8605
|
+
token,
|
|
8606
|
+
"This reaches ai through another object, so the steps it runs are not checked before a run."
|
|
8607
|
+
);
|
|
8608
|
+
});
|
|
8609
|
+
const contexts = /* @__PURE__ */ new Set();
|
|
8610
|
+
tokens.forEach((token, index) => {
|
|
8611
|
+
if (token.kind !== "ident" || token.value !== "test" || !isPunct(index + 1, "("))
|
|
8612
|
+
return;
|
|
8613
|
+
const close = match.get(index + 1);
|
|
8614
|
+
if (close === void 0) return;
|
|
8615
|
+
for (let cursor = index + 2; cursor < close; cursor++) {
|
|
8616
|
+
if (parentOf[cursor] !== index + 1) continue;
|
|
8617
|
+
let start = cursor;
|
|
8618
|
+
if (value(start) === "async") start++;
|
|
8619
|
+
if (value(start) === "function") start++;
|
|
8620
|
+
const inner = isPunct(start, "(") ? match.get(start) : void 0;
|
|
8621
|
+
if (inner !== void 0 && (value(inner + 1) === "=>" || value(start - 1) === "function")) {
|
|
8622
|
+
const first = parameters(start)[0];
|
|
8623
|
+
if (first) contexts.add(first);
|
|
8624
|
+
}
|
|
8625
|
+
}
|
|
8626
|
+
});
|
|
8627
|
+
tokens.forEach((token, index) => {
|
|
8628
|
+
if (token.kind !== "ident" || !contexts.has(token.value) || value(index - 1) === "." || !["(", ","].includes(value(index - 1) ?? "") || ![")", ","].includes(value(index + 1) ?? ""))
|
|
8629
|
+
return;
|
|
8630
|
+
const reason = handedOver(index, `The test's context \`${token.value}\``);
|
|
8631
|
+
if (reason) unchecked(token, reason);
|
|
8632
|
+
});
|
|
8633
|
+
tokens.forEach((token, index) => {
|
|
8634
|
+
if (token.kind === "ident" && token.value !== "ai" && value(index - 1) !== "." && isPunct(index + 1, ":") && (value(index + 2) === "Ai" || value(index + 2) === "TestContext" && isPunct(index + 3, "[") && at2(index + 4)?.kind === "string" && value(index + 4) === "ai"))
|
|
8635
|
+
unchecked(
|
|
8636
|
+
token,
|
|
8637
|
+
`\`${token.value}\` holds the test's ai, so the steps called through it are not checked before a run.`
|
|
8638
|
+
);
|
|
8639
|
+
});
|
|
8640
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
8641
|
+
const token = tokens[index];
|
|
8642
|
+
if (token.kind !== "ident" || token.value !== "ai") continue;
|
|
8643
|
+
if (isPunct(index - 1, ".")) {
|
|
8644
|
+
unchecked(
|
|
8645
|
+
token,
|
|
8646
|
+
"This reaches ai through another object, so the steps it runs are not checked before a run."
|
|
8647
|
+
);
|
|
8648
|
+
continue;
|
|
8649
|
+
}
|
|
8650
|
+
if (renamedParameter(index)) {
|
|
8651
|
+
unchecked(
|
|
8652
|
+
token,
|
|
8653
|
+
"`ai` is renamed here, so the steps called through the new name are not checked before a run."
|
|
8654
|
+
);
|
|
8655
|
+
continue;
|
|
8656
|
+
}
|
|
8657
|
+
if (isPunct(index + 1, "?") && isPunct(index + 2, ".") && isPunct(index + 3, "(") || isPunct(index - 1, "(") && isPunct(index + 1, ")") && isPunct(index + 2, "(")) {
|
|
8658
|
+
unchecked(
|
|
8659
|
+
token,
|
|
8660
|
+
"This ai call is written indirectly, so its sentences are not checked before a run."
|
|
8661
|
+
);
|
|
8662
|
+
continue;
|
|
8663
|
+
}
|
|
8664
|
+
const alias = aliasUse(index);
|
|
8665
|
+
if (alias) {
|
|
8666
|
+
unchecked(token, alias);
|
|
8667
|
+
continue;
|
|
8668
|
+
}
|
|
8669
|
+
if (isPunct(index + 1, "(")) {
|
|
8670
|
+
call2(index + 1);
|
|
8671
|
+
continue;
|
|
8672
|
+
}
|
|
8673
|
+
if (isPunct(index + 1, ".") && at2(index + 2)?.kind === "ident" && at2(index + 2).value === "group" && isPunct(index + 3, "(")) {
|
|
8674
|
+
const afterName = skipExpression(index + 4);
|
|
8675
|
+
if (!isPunct(afterName, ",")) continue;
|
|
8676
|
+
const second = afterName + 1;
|
|
8677
|
+
const first = at2(second);
|
|
8678
|
+
if (isPunct(second, "[")) list(second);
|
|
8679
|
+
else if (first?.kind === "string" || first?.kind === "ident" && constants3.has(first.value))
|
|
8680
|
+
argument(second);
|
|
8681
|
+
else if (!inlineFunction(second) && !(first?.kind === "ident" && functions.has(first.value) && skipExpression(second) === second + 1))
|
|
8682
|
+
argument(second);
|
|
8683
|
+
}
|
|
8684
|
+
}
|
|
8685
|
+
if (truncated)
|
|
8686
|
+
warnings.push({
|
|
8687
|
+
severity: "warning",
|
|
8688
|
+
code: "too_many_sentences",
|
|
8689
|
+
source: { file, line: 1, col: 1 },
|
|
8690
|
+
message: `This file's lists expand to more than ${MAX_SENTENCES} step sentences, or nest more than ${MAX_DEPTH} deep; the rest were not checked.`,
|
|
8691
|
+
fix: "Split the lists, or pass fewer copies of them to ai()."
|
|
8692
|
+
});
|
|
8693
|
+
return { sentences, warnings, functions, helperCalls };
|
|
8694
|
+
}
|
|
8695
|
+
function scanLocalImports(source) {
|
|
8696
|
+
const tokens = tokenize(source);
|
|
8697
|
+
const found = /* @__PURE__ */ new Set();
|
|
8698
|
+
tokens.forEach((token, index) => {
|
|
8699
|
+
const next = tokens[index + 1];
|
|
8700
|
+
const after = tokens[index + 2];
|
|
8701
|
+
let specifier;
|
|
8702
|
+
if (token.kind === "ident" && token.value === "from") specifier = next;
|
|
8703
|
+
else if (token.kind === "ident" && token.value === "import")
|
|
8704
|
+
specifier = next?.kind === "punct" && next.value === "(" ? after : next;
|
|
8705
|
+
else if (token.kind === "ident" && token.value === "require" && next?.kind === "punct" && next.value === "(")
|
|
8706
|
+
specifier = after;
|
|
8707
|
+
if (specifier?.kind === "string" && !specifier.dynamic && /^\.\.?\//u.test(specifier.value))
|
|
8708
|
+
found.add(specifier.value);
|
|
8709
|
+
});
|
|
8710
|
+
return [...found];
|
|
8711
|
+
}
|
|
8712
|
+
function scanImportBindings(source) {
|
|
8713
|
+
const tokens = tokenize(source);
|
|
8714
|
+
const bindings = [];
|
|
8715
|
+
tokens.forEach((token, index) => {
|
|
8716
|
+
if (token.kind !== "ident" || token.value !== "import") return;
|
|
8717
|
+
const names = [];
|
|
8718
|
+
let cursor = index + 1;
|
|
8719
|
+
if (tokens[cursor]?.kind === "ident" && tokens[cursor].value === "type")
|
|
8720
|
+
cursor++;
|
|
8721
|
+
if (tokens[cursor]?.kind === "ident" && tokens[cursor].value !== "from") {
|
|
8722
|
+
names.push({ local: tokens[cursor].value, imported: "default" });
|
|
8723
|
+
cursor++;
|
|
8724
|
+
if (tokens[cursor]?.value === ",") cursor++;
|
|
8725
|
+
}
|
|
8726
|
+
if (tokens[cursor]?.value === "{") {
|
|
8727
|
+
cursor++;
|
|
8728
|
+
while (cursor < tokens.length && tokens[cursor].value !== "}") {
|
|
8729
|
+
const name = tokens[cursor];
|
|
8730
|
+
if (name?.kind === "ident" && name.value !== "type") {
|
|
8731
|
+
if (tokens[cursor + 1]?.value === "as" && tokens[cursor + 2]?.kind === "ident") {
|
|
8732
|
+
names.push({
|
|
8733
|
+
local: tokens[cursor + 2].value,
|
|
8734
|
+
imported: name.value
|
|
8735
|
+
});
|
|
8736
|
+
cursor += 3;
|
|
8737
|
+
continue;
|
|
8738
|
+
}
|
|
8739
|
+
names.push({ local: name.value, imported: name.value });
|
|
8740
|
+
}
|
|
8741
|
+
cursor++;
|
|
8742
|
+
}
|
|
8743
|
+
cursor++;
|
|
8744
|
+
}
|
|
8745
|
+
const from = tokens[cursor];
|
|
8746
|
+
const specifier = tokens[cursor + 1];
|
|
8747
|
+
if (from?.kind === "ident" && from.value === "from" && specifier?.kind === "string" && !specifier.dynamic)
|
|
8748
|
+
for (const name of names)
|
|
8749
|
+
bindings.push({ ...name, specifier: specifier.value });
|
|
8750
|
+
});
|
|
8751
|
+
return bindings;
|
|
8752
|
+
}
|
|
8753
|
+
function callExtent(source, line) {
|
|
8754
|
+
const tokens = tokenize(source);
|
|
8755
|
+
const open2 = [];
|
|
8756
|
+
let best;
|
|
8757
|
+
tokens.forEach((token, index) => {
|
|
8758
|
+
if (token.kind !== "punct") return;
|
|
8759
|
+
if ("([{".includes(token.value)) open2.push(index);
|
|
8760
|
+
else if (")]}".includes(token.value)) {
|
|
8761
|
+
const opener = open2.pop();
|
|
8762
|
+
if (opener === void 0 || tokens[opener].value !== "(" || tokens[opener].line !== line || tokens[opener - 1]?.kind !== "ident")
|
|
8763
|
+
return;
|
|
8764
|
+
if (best === void 0 || token.line > tokens[best].line) best = index;
|
|
8765
|
+
}
|
|
8766
|
+
});
|
|
8767
|
+
return best === void 0 ? void 0 : { start: line, end: tokens[best].line };
|
|
8768
|
+
}
|
|
8769
|
+
|
|
8770
|
+
// src/project-validation.ts
|
|
8771
|
+
var NOT_CHECKED_OFFLINE_CODE = "unavailable";
|
|
8772
|
+
var OPERATIONAL_CODES = /* @__PURE__ */ new Set([
|
|
8773
|
+
"provider_error",
|
|
8774
|
+
"cache_error",
|
|
8775
|
+
"unreadable_file"
|
|
8776
|
+
]);
|
|
8777
|
+
function compareDiagnostics3(a, b) {
|
|
8778
|
+
const text = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
8779
|
+
return text(a.source.file, b.source.file) || a.source.line - b.source.line || a.source.col - b.source.col || text(a.code, b.code) || text(a.message, b.message);
|
|
8780
|
+
}
|
|
8781
|
+
function dedupeDiagnostics(diagnostics) {
|
|
8782
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8783
|
+
const unique = [];
|
|
8784
|
+
for (const item of diagnostics) {
|
|
8785
|
+
const key = JSON.stringify([
|
|
8786
|
+
item.severity,
|
|
8787
|
+
item.code,
|
|
8788
|
+
item.source.file,
|
|
8789
|
+
item.source.line,
|
|
8790
|
+
item.source.col,
|
|
8791
|
+
item.message
|
|
8792
|
+
]);
|
|
8793
|
+
if (seen.has(key)) continue;
|
|
8794
|
+
seen.add(key);
|
|
7378
8795
|
unique.push(item);
|
|
7379
8796
|
}
|
|
7380
8797
|
return unique.sort(compareDiagnostics3);
|
|
@@ -7396,30 +8813,181 @@ function entryUrlDiagnostic(flow, baseUrl) {
|
|
|
7396
8813
|
};
|
|
7397
8814
|
}
|
|
7398
8815
|
}
|
|
7399
|
-
async function
|
|
8816
|
+
async function validateScriptFile(file, options, classify) {
|
|
8817
|
+
const script = await loadScriptFile(file, { repoRoot: options.repoRoot });
|
|
8818
|
+
const headers = scriptListingEntries(script).flatMap(
|
|
8819
|
+
(entry) => entry.result.value ? [entry.result.value] : []
|
|
8820
|
+
);
|
|
8821
|
+
const diagnostics = [...script.diagnostics];
|
|
8822
|
+
for (const header of headers) {
|
|
8823
|
+
if (header.url === void 0 || options.baseUrl === void 0) continue;
|
|
8824
|
+
const entry = entryUrlDiagnostic(header, options.baseUrl);
|
|
8825
|
+
if (entry)
|
|
8826
|
+
diagnostics.push({
|
|
8827
|
+
...entry,
|
|
8828
|
+
source: script.tests.find((test2) => test2.identity === header.identity)?.source ?? entry.source
|
|
8829
|
+
});
|
|
8830
|
+
}
|
|
7400
8831
|
let source;
|
|
7401
8832
|
try {
|
|
7402
8833
|
source = await readFile2(file, "utf8");
|
|
7403
8834
|
} catch {
|
|
7404
8835
|
return {
|
|
8836
|
+
headers,
|
|
7405
8837
|
diagnostics: [
|
|
8838
|
+
...diagnostics,
|
|
7406
8839
|
{
|
|
7407
8840
|
severity: "error",
|
|
7408
8841
|
code: "unreadable_file",
|
|
7409
8842
|
source: { file, line: 1, col: 1 },
|
|
7410
|
-
message: "
|
|
7411
|
-
fix: "Check the
|
|
8843
|
+
message: "The test file could not be read.",
|
|
8844
|
+
fix: "Check the file permissions and rerun."
|
|
7412
8845
|
}
|
|
7413
8846
|
],
|
|
7414
|
-
calls: []
|
|
8847
|
+
calls: [],
|
|
8848
|
+
coverage: {
|
|
8849
|
+
format: "failed",
|
|
8850
|
+
steps: "not_checked",
|
|
8851
|
+
modules: "not_needed"
|
|
8852
|
+
}
|
|
7415
8853
|
};
|
|
7416
8854
|
}
|
|
7417
|
-
const
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
options
|
|
7422
|
-
);
|
|
8855
|
+
const read = [{ file, source, scan: scanScriptSentences(source, file) }];
|
|
8856
|
+
const { helpers, truncated } = await localHelpers(
|
|
8857
|
+
file,
|
|
8858
|
+
source,
|
|
8859
|
+
options.repoRoot
|
|
8860
|
+
);
|
|
8861
|
+
for (const helper of helpers) {
|
|
8862
|
+
const text = await readFile2(helper, "utf8").catch(() => "");
|
|
8863
|
+
read.push({
|
|
8864
|
+
file: helper,
|
|
8865
|
+
source: text,
|
|
8866
|
+
scan: scanScriptSentences(text, helper)
|
|
8867
|
+
});
|
|
8868
|
+
}
|
|
8869
|
+
const scans = read.map((item) => item.scan);
|
|
8870
|
+
const warnings = [
|
|
8871
|
+
...scans.flatMap((scan) => scan.warnings),
|
|
8872
|
+
...unresolvedHelperCalls(read)
|
|
8873
|
+
];
|
|
8874
|
+
if (truncated)
|
|
8875
|
+
warnings.push({
|
|
8876
|
+
severity: "warning",
|
|
8877
|
+
code: "too_many_helpers",
|
|
8878
|
+
source: { file, line: 1, col: 1 },
|
|
8879
|
+
message: `This test imports more than ${MAX_HELPERS} local modules; the sentences in the rest were not checked.`,
|
|
8880
|
+
fix: "Keep shared steps in fewer modules."
|
|
8881
|
+
});
|
|
8882
|
+
diagnostics.push(...warnings);
|
|
8883
|
+
const sentences = scans.flatMap((scan) => scan.sentences).map((item) => ({
|
|
8884
|
+
kind: "sentence",
|
|
8885
|
+
phase: "steps",
|
|
8886
|
+
text: item.text,
|
|
8887
|
+
tokens: tokenizeStep(item.text).tokens,
|
|
8888
|
+
source: item.source
|
|
8889
|
+
}));
|
|
8890
|
+
const checked = await classifySentenceSteps(sentences, classify);
|
|
8891
|
+
diagnostics.push(...checked.diagnostics);
|
|
8892
|
+
const complete = checked.classification.steps.every((step) => step !== null) && checked.diagnostics.length === 0 && warnings.length === 0;
|
|
8893
|
+
return {
|
|
8894
|
+
headers,
|
|
8895
|
+
diagnostics,
|
|
8896
|
+
calls: checked.classification.calls,
|
|
8897
|
+
coverage: {
|
|
8898
|
+
format: script.diagnostics.length ? "failed" : "passed",
|
|
8899
|
+
steps: complete ? "checked" : "incomplete",
|
|
8900
|
+
modules: "not_needed"
|
|
8901
|
+
}
|
|
8902
|
+
};
|
|
8903
|
+
}
|
|
8904
|
+
var HELPER_EXTENSIONS = [".ts", ".mts", ".cts", ".tsx", ".js", ".mjs"];
|
|
8905
|
+
var MAX_HELPERS = 64;
|
|
8906
|
+
function resolveHelper(from, specifier) {
|
|
8907
|
+
const base = path7.resolve(path7.dirname(from), specifier);
|
|
8908
|
+
const stem = base.replace(/\.(?:m|c)?js$/u, "");
|
|
8909
|
+
const candidates = [
|
|
8910
|
+
base,
|
|
8911
|
+
...HELPER_EXTENSIONS.map((extension) => stem + extension),
|
|
8912
|
+
...HELPER_EXTENSIONS.map(
|
|
8913
|
+
(extension) => path7.join(base, `index${extension}`)
|
|
8914
|
+
)
|
|
8915
|
+
];
|
|
8916
|
+
return candidates.find(
|
|
8917
|
+
(candidate) => HELPER_EXTENSIONS.some((extension) => candidate.endsWith(extension)) && existsSync3(candidate) && statSync2(candidate).isFile()
|
|
8918
|
+
);
|
|
8919
|
+
}
|
|
8920
|
+
function unresolvedHelperCalls(read) {
|
|
8921
|
+
const byPath = new Map(
|
|
8922
|
+
read.map((item) => [realpathSync.native(item.file), item.scan])
|
|
8923
|
+
);
|
|
8924
|
+
const warnings = [];
|
|
8925
|
+
for (const { file, source, scan } of read) {
|
|
8926
|
+
if (!scan.helperCalls.length) continue;
|
|
8927
|
+
const imports = scanImportBindings(source);
|
|
8928
|
+
for (const call2 of scan.helperCalls) {
|
|
8929
|
+
const binding = imports.find((item) => item.local === call2.callee);
|
|
8930
|
+
const target = binding ? resolveHelper(file, binding.specifier) : void 0;
|
|
8931
|
+
const helper = target ? byPath.get(realpathSync.native(target)) : void 0;
|
|
8932
|
+
const parameters = binding && helper ? helper.functions.get(binding.imported) : void 0;
|
|
8933
|
+
if (call2.passes === "context" ? parameters : parameters?.[call2.position] === "ai")
|
|
8934
|
+
continue;
|
|
8935
|
+
warnings.push({
|
|
8936
|
+
severity: "warning",
|
|
8937
|
+
code: "unchecked_call",
|
|
8938
|
+
source: call2.source,
|
|
8939
|
+
message: parameters ? `\`${call2.callee}\` receives the test's ai under another name, so the steps it runs are not checked before a run.` : `Validation cannot follow \`${call2.callee}\` to a local module, so the steps it runs with the test's ai are not checked before a run.`,
|
|
8940
|
+
fix: "Declare the helper in the test file or a local module, with its parameter named `ai`."
|
|
8941
|
+
});
|
|
8942
|
+
}
|
|
8943
|
+
}
|
|
8944
|
+
return warnings;
|
|
8945
|
+
}
|
|
8946
|
+
async function localHelpers(file, source, repoRoot) {
|
|
8947
|
+
const root = realpathSync.native(repoRoot);
|
|
8948
|
+
const seen = /* @__PURE__ */ new Set([realpathSync.native(file)]);
|
|
8949
|
+
const helpers = [];
|
|
8950
|
+
const queue2 = [[file, source]];
|
|
8951
|
+
while (queue2.length) {
|
|
8952
|
+
const [from, text] = queue2.shift();
|
|
8953
|
+
for (const specifier of scanLocalImports(text)) {
|
|
8954
|
+
const found = resolveHelper(from, specifier);
|
|
8955
|
+
const target = found && realpathSync.native(found);
|
|
8956
|
+
const relative = target && path7.relative(root, target);
|
|
8957
|
+
if (!target || seen.has(target) || !relative || relative.startsWith("..") || path7.isAbsolute(relative) || relative.split(path7.sep).includes("node_modules"))
|
|
8958
|
+
continue;
|
|
8959
|
+
if (helpers.length >= MAX_HELPERS) return { helpers, truncated: true };
|
|
8960
|
+
seen.add(target);
|
|
8961
|
+
helpers.push(target);
|
|
8962
|
+
queue2.push([target, await readFile2(target, "utf8").catch(() => "")]);
|
|
8963
|
+
}
|
|
8964
|
+
}
|
|
8965
|
+
return { helpers, truncated: false };
|
|
8966
|
+
}
|
|
8967
|
+
async function checkUnreferencedModule(file, options) {
|
|
8968
|
+
let source;
|
|
8969
|
+
try {
|
|
8970
|
+
source = await readFile2(file, "utf8");
|
|
8971
|
+
} catch {
|
|
8972
|
+
return {
|
|
8973
|
+
diagnostics: [
|
|
8974
|
+
{
|
|
8975
|
+
severity: "error",
|
|
8976
|
+
code: "unreadable_file",
|
|
8977
|
+
source: { file, line: 1, col: 1 },
|
|
8978
|
+
message: "Could not read this module file.",
|
|
8979
|
+
fix: "Check the path and file permissions."
|
|
8980
|
+
}
|
|
8981
|
+
],
|
|
8982
|
+
calls: []
|
|
8983
|
+
};
|
|
8984
|
+
}
|
|
8985
|
+
const parsed = parseModule(source, file);
|
|
8986
|
+
if (!parsed.value) return { diagnostics: parsed.diagnostics, calls: [] };
|
|
8987
|
+
const checked = await classifySentenceSteps(
|
|
8988
|
+
directSentences(parsed.value.steps),
|
|
8989
|
+
options
|
|
8990
|
+
);
|
|
7423
8991
|
return {
|
|
7424
8992
|
diagnostics: [...parsed.diagnostics, ...checked.diagnostics],
|
|
7425
8993
|
calls: checked.classification.calls
|
|
@@ -7439,18 +9007,33 @@ async function validateProject(input, options) {
|
|
|
7439
9007
|
const flows = [];
|
|
7440
9008
|
let allTestsValidated = true;
|
|
7441
9009
|
for (const file of input.tests) {
|
|
7442
|
-
|
|
9010
|
+
if (isScriptTestFile(file)) {
|
|
9011
|
+
const checked = await validateScriptFile(file, options, classify);
|
|
9012
|
+
flows.push(...checked.headers);
|
|
9013
|
+
diagnostics.push(...checked.diagnostics);
|
|
9014
|
+
calls.push(...checked.calls);
|
|
9015
|
+
if (!isFullyValidated(checked.coverage, checked.diagnostics))
|
|
9016
|
+
allTestsValidated = false;
|
|
9017
|
+
files.push({
|
|
9018
|
+
file,
|
|
9019
|
+
kind: "test",
|
|
9020
|
+
...checked.headers[0] ? { identity: checked.headers[0].identity } : {},
|
|
9021
|
+
coverage: checked.coverage
|
|
9022
|
+
});
|
|
9023
|
+
continue;
|
|
9024
|
+
}
|
|
9025
|
+
const loaded2 = await loadFlowFile(file, {
|
|
7443
9026
|
repoRoot: options.repoRoot,
|
|
7444
9027
|
...options.baseUrl ? { baseUrl: options.baseUrl } : {}
|
|
7445
9028
|
});
|
|
7446
|
-
const flow =
|
|
9029
|
+
const flow = loaded2.value ?? loaded2.candidate;
|
|
7447
9030
|
if (flow) flows.push(flow);
|
|
7448
9031
|
const entry = flow && options.baseUrl !== void 0 ? entryUrlDiagnostic(flow, options.baseUrl) : null;
|
|
7449
9032
|
if (entry) {
|
|
7450
9033
|
diagnostics.push(entry);
|
|
7451
9034
|
allTestsValidated = false;
|
|
7452
9035
|
}
|
|
7453
|
-
const resolved = await resolveFlowModules(
|
|
9036
|
+
const resolved = await resolveFlowModules(loaded2, {
|
|
7454
9037
|
repoRoot: options.repoRoot,
|
|
7455
9038
|
partial: true
|
|
7456
9039
|
});
|
|
@@ -7504,9 +9087,9 @@ async function validateProject(input, options) {
|
|
|
7504
9087
|
}
|
|
7505
9088
|
|
|
7506
9089
|
// src/project-listing.ts
|
|
7507
|
-
import
|
|
9090
|
+
import path8 from "path";
|
|
7508
9091
|
function displayPath(root, file) {
|
|
7509
|
-
return
|
|
9092
|
+
return path8.relative(root, file).split(path8.sep).join("/");
|
|
7510
9093
|
}
|
|
7511
9094
|
function listTests(parsed, options) {
|
|
7512
9095
|
const collisions = findIdentityCollisions(
|
|
@@ -7550,6 +9133,803 @@ function listTests(parsed, options) {
|
|
|
7550
9133
|
}
|
|
7551
9134
|
return { tests, invalid };
|
|
7552
9135
|
}
|
|
9136
|
+
async function loadListingEntries(files, options) {
|
|
9137
|
+
const entries = [];
|
|
9138
|
+
for (const file of files) {
|
|
9139
|
+
if (isScriptTestFile(file))
|
|
9140
|
+
entries.push(
|
|
9141
|
+
...scriptListingEntries(
|
|
9142
|
+
await loadScriptFile(file, { repoRoot: options.repoRoot })
|
|
9143
|
+
)
|
|
9144
|
+
);
|
|
9145
|
+
else
|
|
9146
|
+
entries.push({
|
|
9147
|
+
file,
|
|
9148
|
+
result: await loadFlowFile(file, {
|
|
9149
|
+
repoRoot: options.repoRoot,
|
|
9150
|
+
...options.rejectSymlinks ? { rejectSymlinks: true } : {}
|
|
9151
|
+
})
|
|
9152
|
+
});
|
|
9153
|
+
}
|
|
9154
|
+
return entries;
|
|
9155
|
+
}
|
|
9156
|
+
|
|
9157
|
+
// src/script-runner.ts
|
|
9158
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
9159
|
+
import path10 from "path";
|
|
9160
|
+
|
|
9161
|
+
// src/script-rejections.ts
|
|
9162
|
+
import path9 from "path";
|
|
9163
|
+
function insideProject(file, root) {
|
|
9164
|
+
const relative = path9.relative(root, file);
|
|
9165
|
+
return relative !== "" && !relative.startsWith("..") && !path9.isAbsolute(relative) && !relative.split(/[\\/]/u).includes("node_modules");
|
|
9166
|
+
}
|
|
9167
|
+
function attributeRejection(reason, running, known, projectRoot) {
|
|
9168
|
+
const stack = reason instanceof Error ? reason.stack : void 0;
|
|
9169
|
+
const frames = (stack?.split("\n").slice(1) ?? []).flatMap((frame) => {
|
|
9170
|
+
const source = parseFrame(frame);
|
|
9171
|
+
return source ? [source] : [];
|
|
9172
|
+
});
|
|
9173
|
+
const root = pathKey(projectRoot);
|
|
9174
|
+
const project = frames.filter(
|
|
9175
|
+
(frame) => insideProject(pathKey(frame.file), root)
|
|
9176
|
+
);
|
|
9177
|
+
const inside2 = (line, lines) => line >= lines.start && line <= lines.end;
|
|
9178
|
+
for (const frame of project) {
|
|
9179
|
+
if (!frame.file.endsWith(".test.ts")) continue;
|
|
9180
|
+
const key = pathKey(frame.file);
|
|
9181
|
+
const holders = (known.get(key) ?? []).filter(
|
|
9182
|
+
(lines) => inside2(frame.line, lines)
|
|
9183
|
+
);
|
|
9184
|
+
const owners = running.flatMap(
|
|
9185
|
+
(test2, index) => pathKey(test2.file) === key && inside2(frame.line, test2.lines) ? [index] : []
|
|
9186
|
+
);
|
|
9187
|
+
if (holders.length > 1 || owners.length > 1)
|
|
9188
|
+
return { kind: "run", reason: "shared", source: frame };
|
|
9189
|
+
if (owners.length === 1) return { kind: "attempt", index: owners[0] };
|
|
9190
|
+
if (holders.length === 1)
|
|
9191
|
+
return {
|
|
9192
|
+
kind: "run",
|
|
9193
|
+
reason: "finished",
|
|
9194
|
+
source: frame,
|
|
9195
|
+
...holders[0].id ? { test: holders[0].id } : {}
|
|
9196
|
+
};
|
|
9197
|
+
}
|
|
9198
|
+
if (project[0]) return { kind: "run", reason: "outside", source: project[0] };
|
|
9199
|
+
return { kind: "run", reason: frames.length ? "internal" : "unknown" };
|
|
9200
|
+
}
|
|
9201
|
+
function describeRejection(reason) {
|
|
9202
|
+
const text = reason instanceof Error ? `${reason.name}: ${reason.message}` : typeof reason === "string" ? reason : "a non-Error value";
|
|
9203
|
+
return (text.split("\n")[0] ?? text).slice(0, 300);
|
|
9204
|
+
}
|
|
9205
|
+
var RejectionRouter = class _RejectionRouter {
|
|
9206
|
+
constructor(projectRoot) {
|
|
9207
|
+
this.projectRoot = projectRoot;
|
|
9208
|
+
}
|
|
9209
|
+
projectRoot;
|
|
9210
|
+
#attempts = /* @__PURE__ */ new Map();
|
|
9211
|
+
/** Every test's lines seen this run, by file, kept after it finishes. */
|
|
9212
|
+
#known = /* @__PURE__ */ new Map();
|
|
9213
|
+
#unattributed = [];
|
|
9214
|
+
#installed = false;
|
|
9215
|
+
static #routing = 0;
|
|
9216
|
+
/**
|
|
9217
|
+
* Whether any router is listening. A process-wide fallback for rejections
|
|
9218
|
+
* that arrive after a run (the `sedum` binary installs one) stands aside
|
|
9219
|
+
* while a router owns them.
|
|
9220
|
+
*/
|
|
9221
|
+
static get routing() {
|
|
9222
|
+
return _RejectionRouter.#routing > 0;
|
|
9223
|
+
}
|
|
9224
|
+
/** Rejections no running test could own, in arrival order. */
|
|
9225
|
+
get unattributed() {
|
|
9226
|
+
return this.#unattributed;
|
|
9227
|
+
}
|
|
9228
|
+
#handle = (reason) => {
|
|
9229
|
+
const attempts = [...this.#attempts.values()];
|
|
9230
|
+
const owner = attributeRejection(
|
|
9231
|
+
reason,
|
|
9232
|
+
attempts,
|
|
9233
|
+
this.#known,
|
|
9234
|
+
this.projectRoot
|
|
9235
|
+
);
|
|
9236
|
+
if (owner.kind === "attempt") {
|
|
9237
|
+
attempts[owner.index].receive(reason);
|
|
9238
|
+
return;
|
|
9239
|
+
}
|
|
9240
|
+
this.#unattributed.push({
|
|
9241
|
+
reason: owner.reason,
|
|
9242
|
+
message: describeRejection(reason),
|
|
9243
|
+
...owner.source ? { source: owner.source } : {},
|
|
9244
|
+
...owner.test ? { test: owner.test } : {}
|
|
9245
|
+
});
|
|
9246
|
+
};
|
|
9247
|
+
install() {
|
|
9248
|
+
if (this.#installed) return;
|
|
9249
|
+
process.on("unhandledRejection", this.#handle);
|
|
9250
|
+
this.#installed = true;
|
|
9251
|
+
_RejectionRouter.#routing++;
|
|
9252
|
+
}
|
|
9253
|
+
dispose() {
|
|
9254
|
+
if (!this.#installed) return;
|
|
9255
|
+
process.off("unhandledRejection", this.#handle);
|
|
9256
|
+
this.#installed = false;
|
|
9257
|
+
_RejectionRouter.#routing--;
|
|
9258
|
+
}
|
|
9259
|
+
/**
|
|
9260
|
+
* Route rejections from one running test to `receive` until released.
|
|
9261
|
+
* `lines` is that test's range; `fileTests` are all of its file's tests.
|
|
9262
|
+
*/
|
|
9263
|
+
register(test2, fileTests, receive) {
|
|
9264
|
+
this.#known.set(pathKey(test2.file), fileTests);
|
|
9265
|
+
const key = Symbol(test2.file);
|
|
9266
|
+
this.#attempts.set(key, { ...test2, receive });
|
|
9267
|
+
return () => {
|
|
9268
|
+
this.#attempts.delete(key);
|
|
9269
|
+
};
|
|
9270
|
+
}
|
|
9271
|
+
};
|
|
9272
|
+
|
|
9273
|
+
// src/script-runner.ts
|
|
9274
|
+
var KEY = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
9275
|
+
var EXTRACT_KEY = "sedum_extracted";
|
|
9276
|
+
var MAX_GROUP_DEPTH = 16;
|
|
9277
|
+
var REMEMBER_AS = /^(?:remember|capture)\b.*\bas\s+\{\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}\s*\.?$/iu;
|
|
9278
|
+
var STEP_ERROR = /* @__PURE__ */ Symbol.for("sedum.script.stepError");
|
|
9279
|
+
var THROWN_IN = /* @__PURE__ */ Symbol("sedum.script.thrownIn");
|
|
9280
|
+
var ScriptUsageError = class extends Error {
|
|
9281
|
+
constructor(code, message, fix) {
|
|
9282
|
+
super(message);
|
|
9283
|
+
this.code = code;
|
|
9284
|
+
this.fix = fix;
|
|
9285
|
+
this.name = "ScriptUsageError";
|
|
9286
|
+
}
|
|
9287
|
+
code;
|
|
9288
|
+
fix;
|
|
9289
|
+
};
|
|
9290
|
+
var StepStop = class extends Error {
|
|
9291
|
+
constructor(problem) {
|
|
9292
|
+
super(
|
|
9293
|
+
problem.status === "failed" ? "A Sedum step failed; see the run report." : `A Sedum step could not run: ${problem.message}`
|
|
9294
|
+
);
|
|
9295
|
+
this.problem = problem;
|
|
9296
|
+
this.name = "SedumStepError";
|
|
9297
|
+
}
|
|
9298
|
+
problem;
|
|
9299
|
+
[STEP_ERROR] = true;
|
|
9300
|
+
};
|
|
9301
|
+
function isStepStop(error2) {
|
|
9302
|
+
return typeof error2 === "object" && error2 !== null && error2[STEP_ERROR] === true;
|
|
9303
|
+
}
|
|
9304
|
+
var StepPromise = class extends Promise {
|
|
9305
|
+
observed = false;
|
|
9306
|
+
static get [Symbol.species]() {
|
|
9307
|
+
return Promise;
|
|
9308
|
+
}
|
|
9309
|
+
then(onFulfilled, onRejected) {
|
|
9310
|
+
this.observed = true;
|
|
9311
|
+
return super.then(onFulfilled, onRejected);
|
|
9312
|
+
}
|
|
9313
|
+
};
|
|
9314
|
+
function testLines(tests, test2, source) {
|
|
9315
|
+
const call2 = source ? callExtent(source, test2.source.line) : void 0;
|
|
9316
|
+
if (call2) return { ...call2, id: test2.identity };
|
|
9317
|
+
const later = tests.map((other) => other.source.line).filter((line) => line > test2.source.line);
|
|
9318
|
+
return {
|
|
9319
|
+
start: test2.source.line,
|
|
9320
|
+
end: later.length ? Math.min(...later) - 1 : Number.MAX_SAFE_INTEGER,
|
|
9321
|
+
id: test2.identity
|
|
9322
|
+
};
|
|
9323
|
+
}
|
|
9324
|
+
function valueEntries(values) {
|
|
9325
|
+
const entries = /* @__PURE__ */ Object.create(
|
|
9326
|
+
null
|
|
9327
|
+
);
|
|
9328
|
+
if (values === void 0) return entries;
|
|
9329
|
+
if (typeof values !== "object" || values === null || Array.isArray(values))
|
|
9330
|
+
throw new ScriptUsageError(
|
|
9331
|
+
"invalid_values",
|
|
9332
|
+
"The values argument must be an object of {{name}} values.",
|
|
9333
|
+
'Pass values as an object: ai("type {{email}} into the Email field", { email }).'
|
|
9334
|
+
);
|
|
9335
|
+
for (const [key, value] of Object.entries(values)) {
|
|
9336
|
+
if (!KEY.test(key))
|
|
9337
|
+
throw new ScriptUsageError(
|
|
9338
|
+
"invalid_value_name",
|
|
9339
|
+
`\`${key}\` is not a valid placeholder name.`,
|
|
9340
|
+
"Use letters, digits, and underscores, starting with a letter or underscore."
|
|
9341
|
+
);
|
|
9342
|
+
const display = `{{${key}}}`;
|
|
9343
|
+
if (isSecret(value)) {
|
|
9344
|
+
const text = revealSecret(value);
|
|
9345
|
+
entries[key] = {
|
|
9346
|
+
value: new RuntimeValue(text, display),
|
|
9347
|
+
sensitive: true,
|
|
9348
|
+
modelVisible: false,
|
|
9349
|
+
opaqueValues: [new RuntimeValue(text, display)]
|
|
9350
|
+
};
|
|
9351
|
+
} else if (typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))
|
|
9352
|
+
entries[key] = {
|
|
9353
|
+
value: new RuntimeValue(String(value), display),
|
|
9354
|
+
sensitive: false,
|
|
9355
|
+
modelVisible: true
|
|
9356
|
+
};
|
|
9357
|
+
else
|
|
9358
|
+
throw new ScriptUsageError(
|
|
9359
|
+
"invalid_value",
|
|
9360
|
+
`The value for {{${key}}} must be a string, a finite number, a boolean, or secret().`,
|
|
9361
|
+
"Convert it with String(...) or wrap sensitive text in secret()."
|
|
9362
|
+
);
|
|
9363
|
+
}
|
|
9364
|
+
return entries;
|
|
9365
|
+
}
|
|
9366
|
+
function inlineValues(step, op, values) {
|
|
9367
|
+
const operand = op === "type" ? validateTypeOperand(step) : null;
|
|
9368
|
+
const span = operand && "operand" in operand ? operand.operand : { start: -1, end: -1 };
|
|
9369
|
+
let text = step.text;
|
|
9370
|
+
for (const token of [...step.tokens].reverse()) {
|
|
9371
|
+
if (token.kind !== "placeholder") continue;
|
|
9372
|
+
if (token.start >= span.start && token.end <= span.end) continue;
|
|
9373
|
+
const entry = values[token.key];
|
|
9374
|
+
if (!entry || entry.sensitive) continue;
|
|
9375
|
+
const value = entry.value.reveal();
|
|
9376
|
+
if (/["\n]|\{\{|\}\}/u.test(value)) continue;
|
|
9377
|
+
text = text.slice(0, token.start) + value + text.slice(token.end);
|
|
9378
|
+
}
|
|
9379
|
+
return text;
|
|
9380
|
+
}
|
|
9381
|
+
function sentenceStep(text, source) {
|
|
9382
|
+
return {
|
|
9383
|
+
kind: "sentence",
|
|
9384
|
+
phase: "steps",
|
|
9385
|
+
text,
|
|
9386
|
+
tokens: tokenizeStep(text).tokens,
|
|
9387
|
+
source,
|
|
9388
|
+
sourceStack: [source]
|
|
9389
|
+
};
|
|
9390
|
+
}
|
|
9391
|
+
async function runScriptTest(file, identity, runDependencies) {
|
|
9392
|
+
const absolute = path10.resolve(file);
|
|
9393
|
+
const script = await loadScriptFile(absolute, {
|
|
9394
|
+
repoRoot: runDependencies.repoRoot
|
|
9395
|
+
});
|
|
9396
|
+
const test2 = identity === void 0 ? script.tests.length === 1 ? script.tests[0] : void 0 : script.tests.find((candidate) => candidate.identity === identity);
|
|
9397
|
+
if (!test2) {
|
|
9398
|
+
if (script.diagnostics.length) return firstDiagnostic(script.diagnostics);
|
|
9399
|
+
return {
|
|
9400
|
+
status: "could_not_run",
|
|
9401
|
+
file: absolute,
|
|
9402
|
+
code: "test_not_found",
|
|
9403
|
+
message: identity === void 0 ? "This file declares several tests; one must be selected." : `No test with id ${JSON.stringify(identity)} is declared in this file.`,
|
|
9404
|
+
fix: "Run `sedum list` to see the test ids in this file."
|
|
9405
|
+
};
|
|
9406
|
+
}
|
|
9407
|
+
let entryUrl;
|
|
9408
|
+
if (test2.url !== void 0 || runDependencies.baseUrl) {
|
|
9409
|
+
try {
|
|
9410
|
+
entryUrl = resolveEntryUrl(
|
|
9411
|
+
test2.url,
|
|
9412
|
+
runDependencies.baseUrl,
|
|
9413
|
+
runDependencies.urlOverride
|
|
9414
|
+
);
|
|
9415
|
+
} catch (error2) {
|
|
9416
|
+
return {
|
|
9417
|
+
status: "could_not_run",
|
|
9418
|
+
file: absolute,
|
|
9419
|
+
code: "invalid_test",
|
|
9420
|
+
source: test2.source,
|
|
9421
|
+
message: error2 instanceof Error ? error2.message : "The test entry URL could not be resolved.",
|
|
9422
|
+
fix: "Use an absolute test url or configure baseUrl in sedum.config.yaml."
|
|
9423
|
+
};
|
|
9424
|
+
}
|
|
9425
|
+
}
|
|
9426
|
+
let dependencies;
|
|
9427
|
+
const { report: runReport, ...runBase } = runDependencies;
|
|
9428
|
+
if (runReport) {
|
|
9429
|
+
const { recorder, slot, ...shared } = runReport;
|
|
9430
|
+
const privacy = {
|
|
9431
|
+
...shared.privacy,
|
|
9432
|
+
secretValues: [...shared.privacy.secretValues]
|
|
9433
|
+
};
|
|
9434
|
+
const shownFile = safeSource(
|
|
9435
|
+
{ file: absolute, line: 1, col: 1 },
|
|
9436
|
+
runDependencies.repoRoot,
|
|
9437
|
+
privacy
|
|
9438
|
+
).file;
|
|
9439
|
+
const existing = slot ? recorder.testAt(slot.ordinal) : recorder.latestTest();
|
|
9440
|
+
const retrying = existing?.file === shownFile && existing.test.id === test2.identity && existing.currentAttempt?.running === true;
|
|
9441
|
+
const recording = retrying ? existing : await recorder.beginTest({
|
|
9442
|
+
id: test2.identity,
|
|
9443
|
+
file: shownFile,
|
|
9444
|
+
description: safeText(test2.title, privacy, 512),
|
|
9445
|
+
tags: test2.tags.map((tag) => safeText(tag, privacy, 120)),
|
|
9446
|
+
...slot ? { ordinal: slot.ordinal } : {},
|
|
9447
|
+
...slot?.lane === void 0 ? {} : { lane: slot.lane }
|
|
9448
|
+
});
|
|
9449
|
+
dependencies = {
|
|
9450
|
+
...runBase,
|
|
9451
|
+
report: { ...shared, privacy, test: recording }
|
|
9452
|
+
};
|
|
9453
|
+
} else dependencies = runBase;
|
|
9454
|
+
const report = dependencies.report;
|
|
9455
|
+
const classifyOptions = {
|
|
9456
|
+
mode: "allow-model",
|
|
9457
|
+
cache: dependencies.classificationCache,
|
|
9458
|
+
provider: dependencies.provider,
|
|
9459
|
+
...dependencies.signal ? { signal: dependencies.signal } : {}
|
|
9460
|
+
};
|
|
9461
|
+
const source = await readFile3(absolute, "utf8").catch(() => void 0);
|
|
9462
|
+
try {
|
|
9463
|
+
const scan = scanScriptSentences(source ?? "", absolute);
|
|
9464
|
+
if (scan.sentences.length) {
|
|
9465
|
+
const warm = await classifySentenceSteps(
|
|
9466
|
+
scan.sentences.map((item) => sentenceStep(item.text, item.source)),
|
|
9467
|
+
classifyOptions
|
|
9468
|
+
);
|
|
9469
|
+
if (report && warm.classification.calls.length)
|
|
9470
|
+
await report.test.addAttemptCalls(
|
|
9471
|
+
warm.classification.calls.map(
|
|
9472
|
+
(call2) => resultCall(call2, "classification")
|
|
9473
|
+
)
|
|
9474
|
+
);
|
|
9475
|
+
}
|
|
9476
|
+
} catch {
|
|
9477
|
+
}
|
|
9478
|
+
const bindings = /* @__PURE__ */ Object.create(
|
|
9479
|
+
null
|
|
9480
|
+
);
|
|
9481
|
+
const opaqueEntries = [];
|
|
9482
|
+
let firstProblem = null;
|
|
9483
|
+
let inFlight = null;
|
|
9484
|
+
const outstanding = /* @__PURE__ */ new Set();
|
|
9485
|
+
const rejected = [];
|
|
9486
|
+
const unhandled = [];
|
|
9487
|
+
let stopListening;
|
|
9488
|
+
const ownRouter = runDependencies.rejections ? void 0 : new RejectionRouter(runDependencies.repoRoot);
|
|
9489
|
+
const router = runDependencies.rejections ?? ownRouter;
|
|
9490
|
+
ownRouter?.install();
|
|
9491
|
+
let finished = false;
|
|
9492
|
+
const groups = [];
|
|
9493
|
+
let session;
|
|
9494
|
+
let context;
|
|
9495
|
+
let page;
|
|
9496
|
+
try {
|
|
9497
|
+
session = await dependencies.browser.launch({
|
|
9498
|
+
...dependencies.browserKind === void 0 ? {} : { browser: dependencies.browserKind },
|
|
9499
|
+
...dependencies.headless === void 0 ? {} : { headless: dependencies.headless },
|
|
9500
|
+
...dependencies.slowMoMs === void 0 ? {} : { slowMoMs: dependencies.slowMoMs },
|
|
9501
|
+
...dependencies.headedOverlay ? { overlay: true } : {}
|
|
9502
|
+
});
|
|
9503
|
+
context = await session.newContext(
|
|
9504
|
+
dependencies.viewport === void 0 ? {} : { viewport: dependencies.viewport }
|
|
9505
|
+
);
|
|
9506
|
+
page = await context.newPage();
|
|
9507
|
+
const activePage = page;
|
|
9508
|
+
if (entryUrl !== void 0)
|
|
9509
|
+
await executeStep(
|
|
9510
|
+
activePage,
|
|
9511
|
+
{ op: "goto", url: new RuntimeUrl([entryUrl]) },
|
|
9512
|
+
dependencies.signal ? { signal: dependencies.signal } : {}
|
|
9513
|
+
);
|
|
9514
|
+
const where = (stack) => sourceInFile(stack, absolute) ?? test2.source;
|
|
9515
|
+
const stop = (problem) => {
|
|
9516
|
+
firstProblem ??= problem;
|
|
9517
|
+
throw new StepStop(problem);
|
|
9518
|
+
};
|
|
9519
|
+
const usage = (error2, source2) => stop({
|
|
9520
|
+
status: "could_not_run",
|
|
9521
|
+
file: absolute,
|
|
9522
|
+
code: "invalid_test",
|
|
9523
|
+
source: source2,
|
|
9524
|
+
message: error2.message,
|
|
9525
|
+
fix: error2.fix
|
|
9526
|
+
});
|
|
9527
|
+
const exclusive = async (source2, work) => {
|
|
9528
|
+
if (finished)
|
|
9529
|
+
usage(
|
|
9530
|
+
new ScriptUsageError(
|
|
9531
|
+
"step_after_test",
|
|
9532
|
+
"An ai step ran after the test body had finished.",
|
|
9533
|
+
"Await every ai(...) call inside the test body."
|
|
9534
|
+
),
|
|
9535
|
+
source2
|
|
9536
|
+
);
|
|
9537
|
+
if (inFlight)
|
|
9538
|
+
usage(
|
|
9539
|
+
new ScriptUsageError(
|
|
9540
|
+
"step_not_awaited",
|
|
9541
|
+
"An ai step started while the previous one was still running.",
|
|
9542
|
+
"Add `await` before each ai(...) call."
|
|
9543
|
+
),
|
|
9544
|
+
source2
|
|
9545
|
+
);
|
|
9546
|
+
if (dependencies.signal?.aborted)
|
|
9547
|
+
stop({
|
|
9548
|
+
status: "could_not_run",
|
|
9549
|
+
file: absolute,
|
|
9550
|
+
code: "canceled",
|
|
9551
|
+
source: source2,
|
|
9552
|
+
message: "The run was interrupted."
|
|
9553
|
+
});
|
|
9554
|
+
const running = work();
|
|
9555
|
+
inFlight = running;
|
|
9556
|
+
try {
|
|
9557
|
+
return await running;
|
|
9558
|
+
} finally {
|
|
9559
|
+
inFlight = null;
|
|
9560
|
+
}
|
|
9561
|
+
};
|
|
9562
|
+
const runStep = async (step, scope, presentation) => {
|
|
9563
|
+
let outcome;
|
|
9564
|
+
try {
|
|
9565
|
+
outcome = await executeSentence(
|
|
9566
|
+
activePage,
|
|
9567
|
+
step,
|
|
9568
|
+
dependencies,
|
|
9569
|
+
scope,
|
|
9570
|
+
opaqueEntries,
|
|
9571
|
+
presentation
|
|
9572
|
+
);
|
|
9573
|
+
} catch (error2) {
|
|
9574
|
+
return stop(runtimeFailure(absolute, error2));
|
|
9575
|
+
}
|
|
9576
|
+
if (outcome === "continue") return;
|
|
9577
|
+
if (outcome === "failed")
|
|
9578
|
+
stop({ status: "failed", file: absolute, source: step.source });
|
|
9579
|
+
else if (outcome.status !== "passed") stop(outcome);
|
|
9580
|
+
};
|
|
9581
|
+
const sentence = async (text, values, source2) => {
|
|
9582
|
+
try {
|
|
9583
|
+
if (typeof text !== "string" || !text.trim())
|
|
9584
|
+
throw new ScriptUsageError(
|
|
9585
|
+
"invalid_sentence",
|
|
9586
|
+
"An ai step must be a nonblank sentence.",
|
|
9587
|
+
'Write one action or claim, such as ai("click the Login button").'
|
|
9588
|
+
);
|
|
9589
|
+
const own = valueEntries(values);
|
|
9590
|
+
const tokenized = tokenizeStep(text);
|
|
9591
|
+
const problem = tokenized.problems[0];
|
|
9592
|
+
if (problem)
|
|
9593
|
+
throw new ScriptUsageError(
|
|
9594
|
+
problem.code,
|
|
9595
|
+
problem.message,
|
|
9596
|
+
problem.fix
|
|
9597
|
+
);
|
|
9598
|
+
const binds = REMEMBER_AS.exec(text.trim())?.[1];
|
|
9599
|
+
for (const token of tokenized.tokens)
|
|
9600
|
+
if (token.kind === "placeholder" && token.key !== binds && !(token.key in own) && !(token.key in bindings))
|
|
9601
|
+
throw new ScriptUsageError(
|
|
9602
|
+
"missing_value",
|
|
9603
|
+
`{{${token.key}}} has no value.`,
|
|
9604
|
+
`Pass it as the second argument: ai(${JSON.stringify(text)}, { ${token.key}: ... }).`
|
|
9605
|
+
);
|
|
9606
|
+
const template = sentenceStep(text, source2);
|
|
9607
|
+
const checked = await classifySentenceSteps(
|
|
9608
|
+
[template],
|
|
9609
|
+
classifyOptions
|
|
9610
|
+
);
|
|
9611
|
+
if (report && checked.classification.calls.length)
|
|
9612
|
+
await report.test.addAttemptCalls(
|
|
9613
|
+
checked.classification.calls.map(
|
|
9614
|
+
(call2) => resultCall(call2, "classification")
|
|
9615
|
+
)
|
|
9616
|
+
);
|
|
9617
|
+
const classified = checked.classification.steps[0];
|
|
9618
|
+
if (checked.diagnostics.length || !classified) {
|
|
9619
|
+
const diagnostic3 = checked.diagnostics[0];
|
|
9620
|
+
stop({
|
|
9621
|
+
status: "could_not_run",
|
|
9622
|
+
file: absolute,
|
|
9623
|
+
code: "invalid_test",
|
|
9624
|
+
source: source2,
|
|
9625
|
+
message: diagnostic3?.message ?? "This step could not be classified.",
|
|
9626
|
+
fix: diagnostic3?.fix ?? "Rewrite it as one action or one claim."
|
|
9627
|
+
});
|
|
9628
|
+
}
|
|
9629
|
+
const secrets = Object.values(own).filter((entry) => entry.sensitive);
|
|
9630
|
+
opaqueEntries.push(...secrets);
|
|
9631
|
+
report?.privacy.secretValues.push(
|
|
9632
|
+
...secrets.map((entry) => entry.value.reveal())
|
|
9633
|
+
);
|
|
9634
|
+
const scope = Object.assign(
|
|
9635
|
+
/* @__PURE__ */ Object.create(null),
|
|
9636
|
+
bindings,
|
|
9637
|
+
own
|
|
9638
|
+
);
|
|
9639
|
+
const shown = sentenceStep(
|
|
9640
|
+
inlineValues(template, classified.op, own),
|
|
9641
|
+
source2
|
|
9642
|
+
);
|
|
9643
|
+
await runStep(
|
|
9644
|
+
{
|
|
9645
|
+
...shown,
|
|
9646
|
+
op: classified.op,
|
|
9647
|
+
classificationSource: classified.classificationSource,
|
|
9648
|
+
probability: classified.probability
|
|
9649
|
+
},
|
|
9650
|
+
scope,
|
|
9651
|
+
{ group: [...groups] }
|
|
9652
|
+
);
|
|
9653
|
+
for (const [key, entry] of Object.entries(scope))
|
|
9654
|
+
if (!(key in own) && !(key in bindings)) bindings[key] = entry;
|
|
9655
|
+
} catch (error2) {
|
|
9656
|
+
if (error2 instanceof ScriptUsageError) usage(error2, source2);
|
|
9657
|
+
throw error2;
|
|
9658
|
+
}
|
|
9659
|
+
};
|
|
9660
|
+
const sentences = async (input, values, source2) => {
|
|
9661
|
+
if (Array.isArray(input)) {
|
|
9662
|
+
if (!input.length)
|
|
9663
|
+
usage(
|
|
9664
|
+
new ScriptUsageError(
|
|
9665
|
+
"empty_steps",
|
|
9666
|
+
"An ai step list is empty.",
|
|
9667
|
+
"Pass at least one sentence."
|
|
9668
|
+
),
|
|
9669
|
+
source2
|
|
9670
|
+
);
|
|
9671
|
+
for (const item of input)
|
|
9672
|
+
await exclusive(source2, () => sentence(item, values, source2));
|
|
9673
|
+
} else await exclusive(source2, () => sentence(input, values, source2));
|
|
9674
|
+
};
|
|
9675
|
+
const track = (work) => {
|
|
9676
|
+
const step = new StepPromise(
|
|
9677
|
+
(resolve, reject) => work.then(resolve, reject)
|
|
9678
|
+
);
|
|
9679
|
+
outstanding.add(step);
|
|
9680
|
+
Promise.prototype.then.call(
|
|
9681
|
+
step,
|
|
9682
|
+
() => outstanding.delete(step),
|
|
9683
|
+
(error2) => {
|
|
9684
|
+
outstanding.delete(step);
|
|
9685
|
+
rejected.push({ step, error: error2 });
|
|
9686
|
+
}
|
|
9687
|
+
);
|
|
9688
|
+
return step;
|
|
9689
|
+
};
|
|
9690
|
+
const ai = ((input, values) => track(sentences(input, values, where(new Error().stack))));
|
|
9691
|
+
const group = async (name, body, values, source2) => {
|
|
9692
|
+
if (finished)
|
|
9693
|
+
usage(
|
|
9694
|
+
new ScriptUsageError(
|
|
9695
|
+
"step_after_test",
|
|
9696
|
+
"An ai.group ran after the test body had finished.",
|
|
9697
|
+
"Await every ai.group(...) call inside the test body."
|
|
9698
|
+
),
|
|
9699
|
+
source2
|
|
9700
|
+
);
|
|
9701
|
+
if (groups.length >= MAX_GROUP_DEPTH)
|
|
9702
|
+
usage(
|
|
9703
|
+
new ScriptUsageError(
|
|
9704
|
+
"invalid_group",
|
|
9705
|
+
`Groups nest at most ${MAX_GROUP_DEPTH} deep.`,
|
|
9706
|
+
"Flatten the inner groups."
|
|
9707
|
+
),
|
|
9708
|
+
source2
|
|
9709
|
+
);
|
|
9710
|
+
if (typeof name !== "string" || !name.trim() || name.length > 120)
|
|
9711
|
+
usage(
|
|
9712
|
+
new ScriptUsageError(
|
|
9713
|
+
"invalid_group",
|
|
9714
|
+
"A group name must be a nonblank string of at most 120 characters.",
|
|
9715
|
+
'Write ai.group("Checkout", async () => { ... }).'
|
|
9716
|
+
),
|
|
9717
|
+
source2
|
|
9718
|
+
);
|
|
9719
|
+
if (typeof body !== "function" && !Array.isArray(body))
|
|
9720
|
+
usage(
|
|
9721
|
+
new ScriptUsageError(
|
|
9722
|
+
"invalid_group",
|
|
9723
|
+
"A group needs a list of sentences or an async function.",
|
|
9724
|
+
'Write ai.group("Log in", ["click the Login button"]).'
|
|
9725
|
+
),
|
|
9726
|
+
source2
|
|
9727
|
+
);
|
|
9728
|
+
groups.push(name);
|
|
9729
|
+
try {
|
|
9730
|
+
return typeof body === "function" ? await body() : await sentences(body, values, source2);
|
|
9731
|
+
} catch (error2) {
|
|
9732
|
+
if (typeof error2 === "object" && error2 !== null && !(THROWN_IN in error2))
|
|
9733
|
+
Object.defineProperty(error2, THROWN_IN, { value: [...groups] });
|
|
9734
|
+
throw error2;
|
|
9735
|
+
} finally {
|
|
9736
|
+
groups.pop();
|
|
9737
|
+
}
|
|
9738
|
+
};
|
|
9739
|
+
ai.group = ((name, body, values) => track(
|
|
9740
|
+
group(name, body, values, where(new Error().stack))
|
|
9741
|
+
));
|
|
9742
|
+
const extract = async (description, parser, source2) => {
|
|
9743
|
+
if (typeof description !== "string" || !description.trim() || /[\n{}]/u.test(description))
|
|
9744
|
+
usage(
|
|
9745
|
+
new ScriptUsageError(
|
|
9746
|
+
"invalid_extract",
|
|
9747
|
+
"ai.extract takes a one-line description without placeholders.",
|
|
9748
|
+
'Write ai.extract("the order total").'
|
|
9749
|
+
),
|
|
9750
|
+
source2
|
|
9751
|
+
);
|
|
9752
|
+
const text = await exclusive(source2, async () => {
|
|
9753
|
+
const scope = Object.assign(
|
|
9754
|
+
/* @__PURE__ */ Object.create(null),
|
|
9755
|
+
bindings
|
|
9756
|
+
);
|
|
9757
|
+
delete scope[EXTRACT_KEY];
|
|
9758
|
+
const step = sentenceStep(
|
|
9759
|
+
`remember ${description.trim()} as {{${EXTRACT_KEY}}}`,
|
|
9760
|
+
source2
|
|
9761
|
+
);
|
|
9762
|
+
await runStep(
|
|
9763
|
+
{
|
|
9764
|
+
...step,
|
|
9765
|
+
op: "remember",
|
|
9766
|
+
classificationSource: "pattern",
|
|
9767
|
+
probability: null
|
|
9768
|
+
},
|
|
9769
|
+
scope,
|
|
9770
|
+
{ group: [...groups], display: `extract ${description.trim()}` }
|
|
9771
|
+
);
|
|
9772
|
+
return scope[EXTRACT_KEY].value.reveal();
|
|
9773
|
+
});
|
|
9774
|
+
return parser ? parser.parse(text) : text;
|
|
9775
|
+
};
|
|
9776
|
+
ai.extract = ((description, parser) => track(
|
|
9777
|
+
extract(description, parser, where(new Error().stack))
|
|
9778
|
+
));
|
|
9779
|
+
const raw = activePage.playwright?.();
|
|
9780
|
+
const unavailable = () => {
|
|
9781
|
+
throw new Error(
|
|
9782
|
+
"The Playwright page is not available with this browser driver."
|
|
9783
|
+
);
|
|
9784
|
+
};
|
|
9785
|
+
const env = Object.freeze({ ...dependencies.env });
|
|
9786
|
+
const attemptOrdinal = report?.test.currentAttempt?.ordinal ?? 1;
|
|
9787
|
+
const testContext = {
|
|
9788
|
+
get page() {
|
|
9789
|
+
return raw?.page ?? unavailable();
|
|
9790
|
+
},
|
|
9791
|
+
get context() {
|
|
9792
|
+
return raw?.context ?? unavailable();
|
|
9793
|
+
},
|
|
9794
|
+
ai,
|
|
9795
|
+
env,
|
|
9796
|
+
testInfo: Object.freeze({
|
|
9797
|
+
id: test2.identity,
|
|
9798
|
+
title: test2.title,
|
|
9799
|
+
file: absolute,
|
|
9800
|
+
tags: [...test2.tags],
|
|
9801
|
+
attempt: attemptOrdinal
|
|
9802
|
+
})
|
|
9803
|
+
};
|
|
9804
|
+
let thrown;
|
|
9805
|
+
let threw = false;
|
|
9806
|
+
stopListening = router.register(
|
|
9807
|
+
{ file: absolute, lines: testLines(script.tests, test2, source) },
|
|
9808
|
+
script.tests.map((other) => testLines(script.tests, other, source)),
|
|
9809
|
+
(reason) => unhandled.push(reason)
|
|
9810
|
+
);
|
|
9811
|
+
try {
|
|
9812
|
+
await test2.body(testContext);
|
|
9813
|
+
} catch (error2) {
|
|
9814
|
+
thrown = error2;
|
|
9815
|
+
threw = true;
|
|
9816
|
+
}
|
|
9817
|
+
if (outstanding.size) {
|
|
9818
|
+
while (outstanding.size)
|
|
9819
|
+
await Promise.allSettled(
|
|
9820
|
+
[...outstanding].map(
|
|
9821
|
+
(step) => new Promise(
|
|
9822
|
+
(settle) => Promise.prototype.then.call(step, settle, settle)
|
|
9823
|
+
)
|
|
9824
|
+
)
|
|
9825
|
+
);
|
|
9826
|
+
firstProblem ??= {
|
|
9827
|
+
status: "could_not_run",
|
|
9828
|
+
file: absolute,
|
|
9829
|
+
code: "invalid_test",
|
|
9830
|
+
source: test2.source,
|
|
9831
|
+
message: "The test body finished while an ai step was still running.",
|
|
9832
|
+
fix: "Add `await` before each ai(...) call."
|
|
9833
|
+
};
|
|
9834
|
+
}
|
|
9835
|
+
finished = true;
|
|
9836
|
+
const groupsOf = (error2) => typeof error2 === "object" && error2 !== null && THROWN_IN in error2 ? error2[THROWN_IN] : [];
|
|
9837
|
+
const codeFailure = async (error2) => {
|
|
9838
|
+
if (error2 instanceof BrowserDriverError || error2 instanceof ProviderError)
|
|
9839
|
+
return runtimeFailure(absolute, error2);
|
|
9840
|
+
const source2 = error2 instanceof Error ? where(error2.stack) : test2.source;
|
|
9841
|
+
await recordCodeFailure(
|
|
9842
|
+
activePage,
|
|
9843
|
+
dependencies,
|
|
9844
|
+
source2,
|
|
9845
|
+
error2,
|
|
9846
|
+
groupsOf(error2)
|
|
9847
|
+
);
|
|
9848
|
+
return { status: "failed", file: absolute, source: source2 };
|
|
9849
|
+
};
|
|
9850
|
+
let primary = firstProblem;
|
|
9851
|
+
const ignored = rejected.find(
|
|
9852
|
+
({ step, error: error2 }) => !step.observed && !isStepStop(error2)
|
|
9853
|
+
);
|
|
9854
|
+
if (!primary && threw && !isStepStop(thrown))
|
|
9855
|
+
primary = await codeFailure(thrown);
|
|
9856
|
+
else if (!primary && ignored) primary = await codeFailure(ignored.error);
|
|
9857
|
+
await closeQuietly(page);
|
|
9858
|
+
await closeQuietly(context);
|
|
9859
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
9860
|
+
stopListening();
|
|
9861
|
+
const ownedOnlyByRun = ownRouter?.unattributed[0];
|
|
9862
|
+
const stray = unhandled[0] ?? (ownedOnlyByRun ? new Error(ownedOnlyByRun.message) : void 0);
|
|
9863
|
+
if (!primary && stray !== void 0) primary = await codeFailure(stray);
|
|
9864
|
+
if (!primary) {
|
|
9865
|
+
await report?.test.finishTest("passed");
|
|
9866
|
+
return { status: "passed", file: absolute };
|
|
9867
|
+
}
|
|
9868
|
+
if (primary.status === "failed") await report?.test.finishTest("failed");
|
|
9869
|
+
return primary;
|
|
9870
|
+
} catch (error2) {
|
|
9871
|
+
if (isStepStop(error2)) return error2.problem;
|
|
9872
|
+
return runtimeFailure(absolute, error2);
|
|
9873
|
+
} finally {
|
|
9874
|
+
finished = true;
|
|
9875
|
+
stopListening?.();
|
|
9876
|
+
ownRouter?.dispose();
|
|
9877
|
+
await closeQuietly(page);
|
|
9878
|
+
await closeQuietly(context);
|
|
9879
|
+
await closeQuietly(session);
|
|
9880
|
+
}
|
|
9881
|
+
}
|
|
9882
|
+
async function recordCodeFailure(page, dependencies, source, error2, group) {
|
|
9883
|
+
const report = dependencies.report;
|
|
9884
|
+
if (!report) return;
|
|
9885
|
+
const attempt = report.test.currentAttempt;
|
|
9886
|
+
if (!attempt) return;
|
|
9887
|
+
const privacy = report.privacy;
|
|
9888
|
+
const index = attempt.stepCount + 1;
|
|
9889
|
+
const id = `${attempt.id}:step:${index}`;
|
|
9890
|
+
const message = error2 instanceof Error ? error2.message : typeof error2 === "string" ? error2 : "The test body threw a non-Error value.";
|
|
9891
|
+
const expectation = error2 instanceof Error && "matcherResult" in error2 ? "expect_failed" : "code_error";
|
|
9892
|
+
const firstLine = message.split("\n").find((line) => line.trim()) ?? message;
|
|
9893
|
+
let evidence = !report.evidenceEnabled ? { status: "omitted", reason: "disabled" } : page.closed ? { status: "unavailable", reason: "page_closed" } : !page.captureFrame ? { status: "unavailable", reason: "capture_unavailable" } : { status: "unavailable", reason: "capture_failed" };
|
|
9894
|
+
if (report.evidenceEnabled && page.captureFrame && !page.closed)
|
|
9895
|
+
try {
|
|
9896
|
+
evidence = await report.saveFrame(
|
|
9897
|
+
attempt,
|
|
9898
|
+
`${id}:evidence`,
|
|
9899
|
+
await page.captureFrame()
|
|
9900
|
+
);
|
|
9901
|
+
} catch {
|
|
9902
|
+
evidence = { status: "unavailable", reason: "capture_failed" };
|
|
9903
|
+
}
|
|
9904
|
+
await report.test.addStep({
|
|
9905
|
+
id,
|
|
9906
|
+
index,
|
|
9907
|
+
kind: "verify",
|
|
9908
|
+
operation: "code",
|
|
9909
|
+
phase: "steps",
|
|
9910
|
+
sentence: safeText(firstLine.trim(), privacy, 512),
|
|
9911
|
+
detail: safeText(
|
|
9912
|
+
error2 instanceof Error ? `${error2.name} thrown by the test code.` : "",
|
|
9913
|
+
privacy,
|
|
9914
|
+
512
|
|
9915
|
+
),
|
|
9916
|
+
...group.length ? { group: group.map((name) => safeText(name, privacy, 120)) } : {},
|
|
9917
|
+
sourceStack: [safeSource(source, dependencies.repoRoot, privacy)],
|
|
9918
|
+
state: "completed",
|
|
9919
|
+
verdict: "failed",
|
|
9920
|
+
flags: [],
|
|
9921
|
+
elapsedMs: 0,
|
|
9922
|
+
page: { status: "omitted", reason: "code_step" },
|
|
9923
|
+
locator: null,
|
|
9924
|
+
judgement: null,
|
|
9925
|
+
observations: [],
|
|
9926
|
+
calls: [],
|
|
9927
|
+
error: { code: expectation, message: safeText(message, privacy, 512) },
|
|
9928
|
+
evidence,
|
|
9929
|
+
replayFrame: null,
|
|
9930
|
+
targetBox: null
|
|
9931
|
+
});
|
|
9932
|
+
}
|
|
7553
9933
|
export {
|
|
7554
9934
|
ACCEPTANCE_POLICY_VERSION,
|
|
7555
9935
|
AssertionEngineError,
|
|
@@ -7583,6 +9963,7 @@ export {
|
|
|
7583
9963
|
PageScriptError,
|
|
7584
9964
|
PlaywrightBrowserDriver,
|
|
7585
9965
|
ProviderError,
|
|
9966
|
+
RejectionRouter,
|
|
7586
9967
|
ResolvedStepTarget,
|
|
7587
9968
|
ResultAttemptSchema,
|
|
7588
9969
|
ResultCallSchema,
|
|
@@ -7603,45 +9984,62 @@ export {
|
|
|
7603
9984
|
RunResultSchema,
|
|
7604
9985
|
RuntimeUrl,
|
|
7605
9986
|
RuntimeValue,
|
|
9987
|
+
SCRIPT_TEST_SUFFIX,
|
|
9988
|
+
ScriptUsageError,
|
|
7606
9989
|
StepExecutionError,
|
|
9990
|
+
TEST_SUFFIXES,
|
|
7607
9991
|
TestRecording,
|
|
7608
9992
|
VISION_PROMPT,
|
|
7609
9993
|
VisionRequestError,
|
|
9994
|
+
attributeRejection,
|
|
9995
|
+
callExtent,
|
|
7610
9996
|
canonicalSentence,
|
|
7611
9997
|
captureVisionObservation,
|
|
9998
|
+
checkRegistrations,
|
|
7612
9999
|
classificationKey,
|
|
7613
10000
|
classifyParsedFlow,
|
|
7614
10001
|
classifySentenceSteps,
|
|
7615
10002
|
classifySteps,
|
|
7616
10003
|
clearPageRefs,
|
|
7617
10004
|
clickTarget,
|
|
10005
|
+
closeQuietly,
|
|
7618
10006
|
codePoints,
|
|
7619
10007
|
collectCandidates,
|
|
7620
10008
|
compareDiagnostics3 as compareDiagnostics,
|
|
7621
10009
|
dedupeDiagnostics,
|
|
10010
|
+
describeRejection,
|
|
7622
10011
|
discoverFlowFiles,
|
|
7623
10012
|
discoverProjectFiles,
|
|
7624
10013
|
displayPath,
|
|
7625
10014
|
evaluateModelAnswer,
|
|
7626
10015
|
evaluateVerifyScores,
|
|
10016
|
+
executeSentence,
|
|
7627
10017
|
executeStep,
|
|
7628
10018
|
findBrowserExecutable,
|
|
7629
10019
|
findIdentityCollisions,
|
|
10020
|
+
firstDiagnostic,
|
|
7630
10021
|
formatFlowDiagnostic,
|
|
7631
10022
|
goalChoiceAccepted,
|
|
7632
10023
|
goalOperations,
|
|
10024
|
+
inlineValues,
|
|
7633
10025
|
installChromium,
|
|
7634
10026
|
isFlowScalar,
|
|
7635
10027
|
isFullyValidated,
|
|
10028
|
+
isRunWideProviderError,
|
|
7636
10029
|
isSafeRole,
|
|
10030
|
+
isScriptTestFile,
|
|
10031
|
+
isSecret,
|
|
7637
10032
|
isWeakPeer,
|
|
7638
10033
|
keyedDigest,
|
|
7639
10034
|
listTests,
|
|
7640
10035
|
liveCandidates,
|
|
7641
10036
|
loadFlowFile,
|
|
10037
|
+
loadListingEntries,
|
|
10038
|
+
loadScriptFile,
|
|
7642
10039
|
matchEntry,
|
|
7643
10040
|
matchLiveEntry,
|
|
7644
10041
|
measure,
|
|
10042
|
+
navigationWhy,
|
|
7645
10043
|
normalizeSignal,
|
|
7646
10044
|
opaqueMatches,
|
|
7647
10045
|
pageDigest,
|
|
@@ -7649,9 +10047,12 @@ export {
|
|
|
7649
10047
|
pageVersion,
|
|
7650
10048
|
parseDataTemplate,
|
|
7651
10049
|
parseFlow,
|
|
10050
|
+
parseFrame,
|
|
7652
10051
|
parseModule,
|
|
10052
|
+
pathKey,
|
|
7653
10053
|
patternOperation,
|
|
7654
10054
|
preflightSentence,
|
|
10055
|
+
probeOpenRouterKey,
|
|
7655
10056
|
projectCandidates,
|
|
7656
10057
|
projectDigest,
|
|
7657
10058
|
quietPage,
|
|
@@ -7664,22 +10065,38 @@ export {
|
|
|
7664
10065
|
resolveModuleBindings,
|
|
7665
10066
|
resolveTarget,
|
|
7666
10067
|
resolveTypeOperand,
|
|
10068
|
+
resultCall,
|
|
7667
10069
|
resultTotals,
|
|
10070
|
+
revealSecret,
|
|
7668
10071
|
runFlow,
|
|
7669
10072
|
runGoal,
|
|
7670
10073
|
runResultJsonSchema,
|
|
10074
|
+
runScriptTest,
|
|
10075
|
+
runtimeFailure,
|
|
7671
10076
|
safeSource,
|
|
7672
10077
|
safeText,
|
|
7673
10078
|
safeUrl,
|
|
10079
|
+
samePath,
|
|
7674
10080
|
sameVisualVersion,
|
|
10081
|
+
scanImportBindings,
|
|
10082
|
+
scanLocalImports,
|
|
10083
|
+
scanScriptSentences,
|
|
10084
|
+
scriptListingEntries,
|
|
10085
|
+
scriptRegistry,
|
|
10086
|
+
secret,
|
|
10087
|
+
sourceInFile,
|
|
7675
10088
|
stageEntry,
|
|
10089
|
+
test,
|
|
10090
|
+
tokenize,
|
|
7676
10091
|
tokenizeStep,
|
|
7677
10092
|
unknownCostCall,
|
|
10093
|
+
unsupported,
|
|
7678
10094
|
validateFlows,
|
|
7679
10095
|
validateOperand,
|
|
7680
10096
|
validateProject,
|
|
7681
10097
|
validateRunResult,
|
|
7682
10098
|
validateTypeOperand,
|
|
10099
|
+
valueEntries,
|
|
7683
10100
|
verify,
|
|
7684
10101
|
visualCandidates,
|
|
7685
10102
|
walkSuiteFiles
|