@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/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { z } from 'zod';
2
+ import { Page, BrowserContext } from 'playwright-core';
3
+ import { F as FlowSource, D as DeclaredDataValue, M as ModuleBinding, a as FlowToken, b as FlowScalar, S as SentenceStep, c as FlowDiagnostic, d as FlowDefinition, P as ParsedFlowResult, e as ParsedModuleResult, V as ValidationInput, f as FlowValidationResult, g as ModuleStep, R as ResolvedModuleCall, h as FullValidationCoverage, T as TestBody, i as ScriptRegistration, A as AiValues } from './script-api-D3if59MQ.js';
4
+ export { j as Ai, k as AiValue, l as FlowStep, m as FormatCoverage, n as ModuleDefinition, o as Parser, p as SecretValue, q as TestContext, r as TestInfo, s as TestOptions, t as formatFlowDiagnostic, u as isFullyValidated, v as isSecret, w as parseFrame, x as pathKey, y as revealSecret, z as samePath, B as scriptRegistry, C as secret, E as sourceInFile, G as test } from './script-api-D3if59MQ.js';
2
5
  import { inspect } from 'node:util';
6
+ import 'playwright/test';
3
7
 
4
8
  declare const ResultSourceSchema: z.ZodObject<{
5
9
  file: z.ZodString;
@@ -137,6 +141,7 @@ declare const ResultStepSchema: z.ZodObject<{
137
141
  }>;
138
142
  sentence: z.ZodString;
139
143
  detail: z.ZodString;
144
+ group: z.ZodOptional<z.ZodArray<z.ZodString>>;
140
145
  sourceStack: z.ZodArray<z.ZodObject<{
141
146
  file: z.ZodString;
142
147
  line: z.ZodNumber;
@@ -334,6 +339,7 @@ declare const ResultAttemptSchema: z.ZodObject<{
334
339
  flags: z.ZodArray<z.ZodEnum<{
335
340
  low_confidence: "low_confidence";
336
341
  contradiction: "contradiction";
342
+ flaky: "flaky";
337
343
  }>>;
338
344
  startedAt: z.ZodString;
339
345
  finishedAt: z.ZodNullable<z.ZodString>;
@@ -361,6 +367,7 @@ declare const ResultAttemptSchema: z.ZodObject<{
361
367
  }>;
362
368
  sentence: z.ZodString;
363
369
  detail: z.ZodString;
370
+ group: z.ZodOptional<z.ZodArray<z.ZodString>>;
364
371
  sourceStack: z.ZodArray<z.ZodObject<{
365
372
  file: z.ZodString;
366
373
  line: z.ZodNumber;
@@ -589,6 +596,7 @@ declare const ResultTestSchema: z.ZodObject<{
589
596
  flags: z.ZodArray<z.ZodEnum<{
590
597
  low_confidence: "low_confidence";
591
598
  contradiction: "contradiction";
599
+ flaky: "flaky";
592
600
  }>>;
593
601
  selectedAttemptId: z.ZodNullable<z.ZodString>;
594
602
  attempts: z.ZodArray<z.ZodObject<{
@@ -607,6 +615,7 @@ declare const ResultTestSchema: z.ZodObject<{
607
615
  flags: z.ZodArray<z.ZodEnum<{
608
616
  low_confidence: "low_confidence";
609
617
  contradiction: "contradiction";
618
+ flaky: "flaky";
610
619
  }>>;
611
620
  startedAt: z.ZodString;
612
621
  finishedAt: z.ZodNullable<z.ZodString>;
@@ -634,6 +643,7 @@ declare const ResultTestSchema: z.ZodObject<{
634
643
  }>;
635
644
  sentence: z.ZodString;
636
645
  detail: z.ZodString;
646
+ group: z.ZodOptional<z.ZodArray<z.ZodString>>;
637
647
  sourceStack: z.ZodArray<z.ZodObject<{
638
648
  file: z.ZodString;
639
649
  line: z.ZodNumber;
@@ -867,6 +877,14 @@ declare const ResultExecutionSchema: z.ZodObject<{
867
877
  globalSelectedTests: z.ZodNumber;
868
878
  }, z.core.$strict>>;
869
879
  providerConcurrency: z.ZodNumber;
880
+ vision: z.ZodOptional<z.ZodObject<{
881
+ model: z.ZodString;
882
+ key: z.ZodEnum<{
883
+ accepted: "accepted";
884
+ rejected: "rejected";
885
+ unreachable: "unreachable";
886
+ }>;
887
+ }, z.core.$strict>>;
870
888
  }, z.core.$strict>;
871
889
  declare const RunResultSchema: z.ZodObject<{
872
890
  schemaVersion: z.ZodLiteral<1>;
@@ -884,6 +902,7 @@ declare const RunResultSchema: z.ZodObject<{
884
902
  flags: z.ZodArray<z.ZodEnum<{
885
903
  low_confidence: "low_confidence";
886
904
  contradiction: "contradiction";
905
+ flaky: "flaky";
887
906
  }>>;
888
907
  startedAt: z.ZodString;
889
908
  updatedAt: z.ZodString;
@@ -901,6 +920,14 @@ declare const RunResultSchema: z.ZodObject<{
901
920
  globalSelectedTests: z.ZodNumber;
902
921
  }, z.core.$strict>>;
903
922
  providerConcurrency: z.ZodNumber;
923
+ vision: z.ZodOptional<z.ZodObject<{
924
+ model: z.ZodString;
925
+ key: z.ZodEnum<{
926
+ accepted: "accepted";
927
+ rejected: "rejected";
928
+ unreachable: "unreachable";
929
+ }>;
930
+ }, z.core.$strict>>;
904
931
  }, z.core.$strict>>;
905
932
  totals: z.ZodObject<{
906
933
  selectedTests: z.ZodNumber;
@@ -962,6 +989,7 @@ declare const RunResultSchema: z.ZodObject<{
962
989
  flags: z.ZodArray<z.ZodEnum<{
963
990
  low_confidence: "low_confidence";
964
991
  contradiction: "contradiction";
992
+ flaky: "flaky";
965
993
  }>>;
966
994
  selectedAttemptId: z.ZodNullable<z.ZodString>;
967
995
  attempts: z.ZodArray<z.ZodObject<{
@@ -980,6 +1008,7 @@ declare const RunResultSchema: z.ZodObject<{
980
1008
  flags: z.ZodArray<z.ZodEnum<{
981
1009
  low_confidence: "low_confidence";
982
1010
  contradiction: "contradiction";
1011
+ flaky: "flaky";
983
1012
  }>>;
984
1013
  startedAt: z.ZodString;
985
1014
  finishedAt: z.ZodNullable<z.ZodString>;
@@ -1007,6 +1036,7 @@ declare const RunResultSchema: z.ZodObject<{
1007
1036
  }>;
1008
1037
  sentence: z.ZodString;
1009
1038
  detail: z.ZodString;
1039
+ group: z.ZodOptional<z.ZodArray<z.ZodString>>;
1010
1040
  sourceStack: z.ZodArray<z.ZodObject<{
1011
1041
  file: z.ZodString;
1012
1042
  line: z.ZodNumber;
@@ -1278,6 +1308,8 @@ declare class TestRecording {
1278
1308
  addProblem(input: ProblemInput): Promise<void>;
1279
1309
  addAttemptCalls(calls: readonly ResultCall[]): Promise<void>;
1280
1310
  finishTest(verdict: "passed" | "failed"): Promise<void>;
1311
+ /** Ends a running attempt that could not run; the run itself continues. */
1312
+ errorTest(error: NonNullable<ResultAttempt["error"]>): Promise<void>;
1281
1313
  }
1282
1314
  /** One run owns the mutable journal; each published value is a validated copy. */
1283
1315
  declare class RunRecorder {
@@ -1326,6 +1358,8 @@ declare class RunRecorder {
1326
1358
  startAttempt(): Promise<void>;
1327
1359
  /** @internal Use `TestRecording.finishTest`. */
1328
1360
  finishTestFor(testId: string, verdict: "passed" | "failed"): Promise<void>;
1361
+ /** @internal Use `TestRecording.errorTest`. */
1362
+ errorTestFor(testId: string, error: NonNullable<ResultAttempt["error"]>): Promise<void>;
1329
1363
  finishTest(verdict: "passed" | "failed"): Promise<void>;
1330
1364
  finish(error?: RunResult["error"], terminalState?: "error" | "interrupted"): Promise<void>;
1331
1365
  }
@@ -1550,19 +1584,34 @@ declare class BrowserDriverError extends Error {
1550
1584
  readonly code: BrowserDriverErrorCode;
1551
1585
  constructor(code: BrowserDriverErrorCode, message: string, cause?: unknown);
1552
1586
  }
1587
+ /** A click on a native dropdown chooses one of its options instead. */
1588
+ interface ClickOptions {
1589
+ readonly timeoutMs?: number;
1590
+ /** Returns the option label to choose, or null when none is named. */
1591
+ readonly chooseOption?: (labels: readonly string[]) => string | null;
1592
+ }
1593
+ type ClickResult = AimResult | {
1594
+ readonly actionable: false;
1595
+ readonly reason: "option_not_named";
1596
+ /** The enabled options, so the step can say what to name. */
1597
+ readonly options: readonly string[];
1598
+ };
1553
1599
  interface BrowserPage {
1554
1600
  readonly url: string;
1555
1601
  readonly closed: boolean;
1556
1602
  /** Optional diagnostic effects; fake pages may leave them unavailable. */
1557
1603
  title?(): Promise<string>;
1558
1604
  captureFrame?(): Promise<Uint8Array>;
1605
+ /** The underlying Playwright objects, for code in `*.test.ts` bodies. */
1606
+ playwright?(): {
1607
+ readonly page: Page;
1608
+ readonly context: BrowserContext;
1609
+ };
1559
1610
  goto(url: string, options?: NavigationOptions): Promise<NavigationResult>;
1560
1611
  settle(options?: SettleOptions): Promise<SettleResult>;
1561
1612
  text(): Promise<string>;
1562
1613
  evaluate<T>(expression: string, argument?: unknown): Promise<T>;
1563
- clickRef(aim: Aim, options?: {
1564
- readonly timeoutMs?: number;
1565
- }): Promise<AimResult>;
1614
+ clickRef(aim: Aim, options?: ClickOptions): Promise<ClickResult>;
1566
1615
  fillRef(target: FillTarget, value: string, options?: {
1567
1616
  readonly timeoutMs?: number;
1568
1617
  }): Promise<FillResult>;
@@ -1595,128 +1644,6 @@ declare class PlaywrightBrowserDriver implements BrowserDriver {
1595
1644
  }
1596
1645
  declare function installChromium(withDeps?: boolean): BrowserInstallResult;
1597
1646
 
1598
- /** Source positions come from YAML nodes, never from searching the source text. */
1599
- interface FlowSource {
1600
- readonly file: string;
1601
- readonly line: number;
1602
- readonly col: number;
1603
- }
1604
- interface FlowDiagnostic {
1605
- readonly severity: "error" | "warning";
1606
- readonly code: string;
1607
- readonly source: FlowSource;
1608
- readonly message: string;
1609
- readonly fix: string;
1610
- }
1611
- type FlowScalar = string | number | boolean | null;
1612
- interface DeclaredDataValue {
1613
- readonly value: FlowScalar;
1614
- readonly source: FlowSource;
1615
- }
1616
- interface FlowToken {
1617
- readonly kind: "placeholder" | "quoted";
1618
- readonly start: number;
1619
- readonly end: number;
1620
- readonly text: string;
1621
- readonly key?: string;
1622
- }
1623
- interface SentenceStep {
1624
- readonly kind: "sentence";
1625
- readonly phase: "before" | "steps" | "after";
1626
- readonly text: string;
1627
- readonly tokens: readonly FlowToken[];
1628
- readonly source: FlowSource;
1629
- /** SED-29 adds module call sites before the sentence source. */
1630
- readonly sourceStack?: readonly FlowSource[];
1631
- }
1632
- interface ModuleBinding {
1633
- readonly value: FlowScalar;
1634
- readonly source: FlowSource;
1635
- }
1636
- interface ModuleStep {
1637
- readonly kind: "module";
1638
- readonly phase: "before" | "steps" | "after";
1639
- readonly use: string;
1640
- readonly with: Readonly<Record<string, FlowScalar>>;
1641
- readonly withSources: Readonly<Record<string, FlowSource>>;
1642
- readonly source: FlowSource;
1643
- /** SED-29 adds each resolved module source after this call site. */
1644
- readonly sourceStack: readonly FlowSource[];
1645
- /** Present only after the complete module graph has been resolved. */
1646
- readonly resolved?: ResolvedModuleCall;
1647
- }
1648
- interface ResolvedModuleCall {
1649
- readonly id: string;
1650
- readonly file: string;
1651
- readonly parameters: readonly string[];
1652
- readonly bindings: Readonly<Record<string, ModuleBinding>>;
1653
- readonly steps: readonly FlowStep[];
1654
- }
1655
- type FlowStep = SentenceStep | ModuleStep;
1656
- interface FlowDefinition {
1657
- readonly version: 1;
1658
- readonly file: string;
1659
- readonly identity: string;
1660
- readonly explicitId?: string;
1661
- readonly idSource?: FlowSource;
1662
- readonly description?: string;
1663
- readonly url?: string;
1664
- /** Position of the `url` value, for entry-URL diagnostics. */
1665
- readonly urlSource?: FlowSource;
1666
- readonly tags: readonly string[];
1667
- readonly meta: Readonly<Record<string, unknown>>;
1668
- readonly data: Readonly<Record<string, DeclaredDataValue>>;
1669
- readonly before: readonly FlowStep[];
1670
- readonly steps: readonly FlowStep[];
1671
- readonly after: readonly FlowStep[];
1672
- readonly goal?: {
1673
- readonly text: string;
1674
- readonly source: FlowSource;
1675
- readonly verify: string;
1676
- readonly verifySource: FlowSource;
1677
- };
1678
- }
1679
- interface ModuleDefinition {
1680
- readonly file: string;
1681
- readonly source: FlowSource;
1682
- readonly parameters: readonly string[];
1683
- readonly steps: readonly FlowStep[];
1684
- }
1685
- interface ParsedModuleResult {
1686
- readonly value?: ModuleDefinition;
1687
- readonly diagnostics: readonly FlowDiagnostic[];
1688
- }
1689
- /** A format-only result cannot be mistaken for full validation. */
1690
- interface FormatCoverage {
1691
- readonly format: "passed" | "failed";
1692
- readonly steps: "not_checked";
1693
- readonly modules: "not_needed" | "not_checked";
1694
- }
1695
- interface ParsedFlowResult {
1696
- readonly value?: FlowDefinition;
1697
- /** Parsed steps retained only for collecting later errors; never executable. */
1698
- readonly candidate?: FlowDefinition;
1699
- readonly diagnostics: readonly FlowDiagnostic[];
1700
- readonly coverage: FullValidationCoverage;
1701
- }
1702
- interface ValidationInput {
1703
- readonly source: string;
1704
- readonly path: string;
1705
- }
1706
- interface FlowValidationResult {
1707
- readonly files: readonly ParsedFlowResult[];
1708
- readonly diagnostics: readonly FlowDiagnostic[];
1709
- readonly coverage: FormatCoverage;
1710
- }
1711
- /** SED-28/29/37 may only mark checks complete after actually performing them. */
1712
- interface FullValidationCoverage {
1713
- readonly format: "passed" | "failed";
1714
- readonly steps: "not_checked" | "checked" | "incomplete";
1715
- readonly modules: "not_needed" | "not_checked" | "checked" | "incomplete";
1716
- }
1717
- declare function isFullyValidated(coverage: FullValidationCoverage, diagnostics: readonly FlowDiagnostic[]): boolean;
1718
- declare function formatFlowDiagnostic(diagnostic: FlowDiagnostic): string;
1719
-
1720
1647
  interface ReportPrivacy {
1721
1648
  readonly secretValues: string[];
1722
1649
  readonly sensitiveOrigins?: readonly string[];
@@ -1749,7 +1676,9 @@ declare class ReusableBrowserDriver implements BrowserDriver {
1749
1676
 
1750
1677
  declare const CACHE_FORMAT = 1;
1751
1678
  declare const MATCHER_VERSION = 1;
1752
- type CacheMissReason = "absent" | "disabled" | "ci_default" | "outside_git" | "runtime_dependent" | "format_mismatch" | "matcher_mismatch" | "corrupt" | "storage_error" | "conflict" | "target_missing" | "strong_signal_conflict" | "low_score" | "near_tie" | "candidate_set_incomplete" | "not_actionable";
1679
+ type CacheMissReason = "absent"
1680
+ /** The target has no signal that can safely find it again, such as an input button. */
1681
+ | "not_cacheable" | "disabled" | "ci_default" | "outside_git" | "runtime_dependent" | "format_mismatch" | "matcher_mismatch" | "corrupt" | "storage_error" | "conflict" | "target_missing" | "strong_signal_conflict" | "low_score" | "near_tie" | "candidate_set_incomplete" | "not_actionable";
1753
1682
  interface CacheEntry {
1754
1683
  readonly format: number;
1755
1684
  readonly matcher: number;
@@ -1865,6 +1794,8 @@ declare class ResolvedStepTarget {
1865
1794
  type StepCommand = {
1866
1795
  readonly op: "click";
1867
1796
  readonly target: ResolvedStepTarget;
1797
+ /** Picks the option to choose when the target is a native dropdown. */
1798
+ readonly chooseOption?: (labels: readonly string[]) => string | null;
1868
1799
  } | {
1869
1800
  readonly op: "type";
1870
1801
  readonly target: ResolvedStepTarget;
@@ -1898,7 +1829,9 @@ declare class StepExecutionError extends Error {
1898
1829
  readonly phase: StepFailurePhase;
1899
1830
  readonly retryable: boolean;
1900
1831
  readonly callLog: readonly string[];
1901
- constructor(op: StepOperation, code: StepFailureCode, phase: StepFailurePhase, callLog?: readonly string[]);
1832
+ constructor(op: StepOperation, code: StepFailureCode, phase: StepFailurePhase, callLog?: readonly string[],
1833
+ /** A reader-facing explanation that replaces the generic message. */
1834
+ detail?: string);
1902
1835
  toJSON(): object;
1903
1836
  }
1904
1837
  interface StepExecutionOptions {
@@ -2010,6 +1943,13 @@ interface Judge {
2010
1943
  holds(claim: string, pageDigest: JudgePageDigest, options?: ProviderCallOptions): Promise<JudgeDecision>;
2011
1944
  }
2012
1945
  type ProviderErrorCode = "configuration" | "authentication" | "unsupported-input" | "invalid-input" | "invalid-response" | "timeout" | "connection" | "retry-exhausted" | "rate-limited";
1946
+ /**
1947
+ * A provider failure that every later request will hit too: a rejected key,
1948
+ * a bad configuration, or rate limiting that outlasted its waits. Engines
1949
+ * pass these through instead of turning them into a step outcome, so the
1950
+ * run stops instead of failing each remaining test the same way.
1951
+ */
1952
+ declare function isRunWideProviderError(error: unknown): error is ProviderError;
2013
1953
  declare class ProviderError extends Error {
2014
1954
  readonly code: ProviderErrorCode;
2015
1955
  readonly attempts: number;
@@ -2085,6 +2025,15 @@ declare function captureVisionObservation(page: BrowserPage, candidates: readonl
2085
2025
  observation: VisionObservation;
2086
2026
  candidates: readonly Candidate[];
2087
2027
  } | null>;
2028
+ type VisionKeyProbe = "accepted" | "rejected" | "unreachable";
2029
+ /**
2030
+ * Checks OPEN_ROUTER_API_KEY without a model request: OpenRouter's key
2031
+ * endpoint answers 401 for an unknown key and is not billed.
2032
+ */
2033
+ declare function probeOpenRouterKey(apiKey: string, options?: {
2034
+ readonly timeoutMs?: number;
2035
+ readonly signal?: AbortSignal;
2036
+ }): Promise<VisionKeyProbe>;
2088
2037
 
2089
2038
  type LocatorFailure = "none" | "ambiguous" | "stale" | "no_candidates" | "incomplete" | "resource_limit" | "not_fillable" | "provider_error" | "request_too_large" | "invalid_input" | "timeout";
2090
2039
  interface LocatorOptionDiagnostic {
@@ -2483,6 +2432,8 @@ interface ProjectFiles {
2483
2432
  readonly modules: readonly string[];
2484
2433
  readonly problems: readonly DiscoveryProblem[];
2485
2434
  }
2435
+ /** YAML tests and TypeScript tests; a `*.test.ts` file may declare several. */
2436
+ declare const TEST_SUFFIXES: readonly [".test.yaml", ".test.ts"];
2486
2437
  /**
2487
2438
  * Recursively list files with one of the suffixes, sorted by path. Symlinked
2488
2439
  * entries are not followed. Unreadable subdirectories are reported, not thrown.
@@ -2589,6 +2540,17 @@ declare function listTests(parsed: readonly {
2589
2540
  }[], options: {
2590
2541
  readonly repoRoot: string;
2591
2542
  }): TestListing;
2543
+ /**
2544
+ * Load test headers for listing and selection. A YAML file is one entry; a
2545
+ * `*.test.ts` file is imported and contributes one entry per `test()`.
2546
+ */
2547
+ declare function loadListingEntries(files: readonly string[], options: {
2548
+ readonly repoRoot: string;
2549
+ readonly rejectSymlinks?: boolean;
2550
+ }): Promise<{
2551
+ readonly file: string;
2552
+ readonly result: ParsedFlowResult;
2553
+ }[]>;
2592
2554
 
2593
2555
  declare const DEFAULT_MIN_P = 0.75;
2594
2556
  declare const DEFAULT_BAND = 0.15;
@@ -2719,6 +2681,12 @@ interface GoalResult {
2719
2681
  readonly elapsedMs: number;
2720
2682
  readonly calls: readonly ProviderCall[];
2721
2683
  readonly history: readonly string[];
2684
+ /**
2685
+ * For an abstention: which choice was uncertain, where, and its top
2686
+ * probabilities, e.g. "operation on …/inventory.html: BLOCKED 0.48,
2687
+ * CLICK 0.46". Contains no typed values.
2688
+ */
2689
+ readonly detail?: string;
2722
2690
  readonly verification: readonly {
2723
2691
  claim: string;
2724
2692
  verdict: string;
@@ -2733,6 +2701,86 @@ declare function goalChoiceAccepted(answer: GoalChoice, ids: readonly string[],
2733
2701
  /** No generated text, selectors, JavaScript, arbitrary keys, or navigation URLs. */
2734
2702
  declare function runGoal(page: BrowserPage, planner: GoalPlanner, judge: Judge, options: GoalOptions): Promise<GoalResult>;
2735
2703
 
2704
+ /**
2705
+ * Where a rejection that no code handled belongs. Test code can start work it
2706
+ * never awaits, such as `expect.poll` or an API call, and that work can reject
2707
+ * after its own test has finished, while another test runs.
2708
+ */
2709
+ type RejectionOwner = {
2710
+ readonly kind: "attempt";
2711
+ readonly index: number;
2712
+ } | {
2713
+ readonly kind: "run";
2714
+ readonly reason: StrayReason;
2715
+ readonly source?: FlowSource;
2716
+ /** The test whose lines hold the frame, when exactly one does. */
2717
+ readonly test?: string;
2718
+ };
2719
+ /**
2720
+ * Why no test could be blamed: its test had `finished`; the lines are
2721
+ * `shared` by several tests, as when tests are declared in a loop; project
2722
+ * code threw `outside` any test's lines; the stack has only Sedum or library
2723
+ * code (`internal`); or the value carries no stack (`unknown`).
2724
+ */
2725
+ type StrayReason = "finished" | "shared" | "outside" | "internal" | "unknown";
2726
+ /** The lines a `test()` covers: its declaration up to the next test's. */
2727
+ interface LineRange {
2728
+ readonly start: number;
2729
+ readonly end: number;
2730
+ /** The test's id, to name it when it leaves work behind. */
2731
+ readonly id?: string;
2732
+ }
2733
+ interface RunningTest {
2734
+ readonly file: string;
2735
+ readonly lines: LineRange;
2736
+ }
2737
+ /**
2738
+ * Attribute a rejection by its stack, innermost frame first. A test is blamed
2739
+ * only when a frame lies inside its lines, and no other test's, while it
2740
+ * runs. A frame inside the lines of a test that is not running means that
2741
+ * test left work behind. Lines several tests share, as when tests are
2742
+ * declared in a loop, cannot tell them apart, so nobody is blamed.
2743
+ * Anything else, such as a helper at the top of a file, which any test could
2744
+ * have called, is reported for the run rather than blamed on whichever test
2745
+ * happens to be running. `known` is keyed by `pathKey(file)`. Pure, so the
2746
+ * policy is testable without a listener.
2747
+ */
2748
+ declare function attributeRejection(reason: unknown, running: readonly RunningTest[], known: ReadonlyMap<string, readonly LineRange[]>, projectRoot: string): RejectionOwner;
2749
+ interface UnattributedRejection {
2750
+ readonly reason: StrayReason;
2751
+ readonly message: string;
2752
+ readonly source?: FlowSource;
2753
+ readonly test?: string;
2754
+ }
2755
+ /** One line naming a rejection's value, for a report or the terminal. */
2756
+ declare function describeRejection(reason: unknown): string;
2757
+ /**
2758
+ * One `unhandledRejection` listener for a whole run. Attempts register while
2759
+ * they run; a rejection is handed to the attempt that owns it or kept for the
2760
+ * run to report, so a stray promise never kills the process or blames an
2761
+ * unrelated test.
2762
+ */
2763
+ declare class RejectionRouter {
2764
+ #private;
2765
+ private readonly projectRoot;
2766
+ constructor(projectRoot: string);
2767
+ /**
2768
+ * Whether any router is listening. A process-wide fallback for rejections
2769
+ * that arrive after a run (the `sedum` binary installs one) stands aside
2770
+ * while a router owns them.
2771
+ */
2772
+ static get routing(): boolean;
2773
+ /** Rejections no running test could own, in arrival order. */
2774
+ get unattributed(): readonly UnattributedRejection[];
2775
+ install(): void;
2776
+ dispose(): void;
2777
+ /**
2778
+ * Route rejections from one running test to `receive` until released.
2779
+ * `lines` is that test's range; `fileTests` are all of its file's tests.
2780
+ */
2781
+ register(test: RunningTest, fileTests: readonly LineRange[], receive: (reason: unknown) => void): () => void;
2782
+ }
2783
+
2736
2784
  type FlowRunResult = {
2737
2785
  readonly status: "passed";
2738
2786
  readonly file: string;
@@ -2773,6 +2821,8 @@ interface FlowRunnerDependencies {
2773
2821
  readonly slowMoMs?: number;
2774
2822
  readonly headedOverlay?: boolean;
2775
2823
  readonly signal?: AbortSignal;
2824
+ /** Routes stray rejections from TypeScript test code; one per run. */
2825
+ readonly rejections?: RejectionRouter;
2776
2826
  readonly report?: {
2777
2827
  readonly recorder: RunRecorder;
2778
2828
  /**
@@ -2793,14 +2843,171 @@ interface FlowRunnerDependencies {
2793
2843
  }, frameId: string, bytes: Uint8Array) => Promise<ResultFrame>;
2794
2844
  };
2795
2845
  }
2846
+ type RunReport = NonNullable<FlowRunnerDependencies["report"]>;
2847
+ /** One attempt's report: its own test handle and its own privacy state. */
2848
+ /** @internal */
2849
+ type AttemptReport = Omit<RunReport, "recorder" | "slot"> & {
2850
+ readonly test: TestRecording;
2851
+ };
2852
+ /** @internal Shared with the script runner. */
2853
+ type AttemptDependencies = Omit<FlowRunnerDependencies, "report"> & {
2854
+ readonly report?: AttemptReport;
2855
+ };
2856
+ /** @internal */
2857
+ declare function resultCall(call: ProviderCall, purpose: ResultCall["purpose"], apiMs?: number | null): ResultCall;
2858
+ /** @internal */
2859
+ declare function firstDiagnostic(diagnostics: readonly FlowDiagnostic[]): FlowRunResult;
2860
+ /** @internal */
2861
+ declare function unsupported(file: string, source: FlowSource, message: string): FlowRunResult;
2862
+ /** A navigation failure, in words: which network problem stopped it. */
2863
+ declare function navigationWhy(error: StepExecutionError): string;
2864
+ /** @internal */
2865
+ declare function runtimeFailure(file: string, error: unknown): FlowRunResult;
2796
2866
  /** SED-10 entry URL semantics; SED-33 adds origin-preserving --url-override. */
2797
2867
  declare function resolveEntryUrl(testUrl?: string, baseUrl?: string, urlOverride?: string): string;
2868
+ /** @internal */
2869
+ declare function closeQuietly(resource: {
2870
+ close(): Promise<void>;
2871
+ } | undefined): Promise<void>;
2872
+ /** How a script step is shown: its group path and, for extracts, its words. */
2873
+ interface SentencePresentation {
2874
+ readonly group?: readonly string[];
2875
+ readonly display?: string;
2876
+ }
2877
+ /** @internal Execute one classified sentence and record it as one step. */
2878
+ declare function executeSentence(page: BrowserPage, step: ClassifiedFlowSentence, dependencies: AttemptDependencies, data: Record<string, ResolvedDataEntry>, opaqueEntries: ResolvedDataEntry[], presentation?: SentencePresentation): Promise<"continue" | "failed" | FlowRunResult>;
2798
2879
  /** Run one validated attempt with setup, body, and exhaustive teardown. */
2799
2880
  declare function runFlow(file: string, runDependencies: FlowRunnerDependencies): Promise<FlowRunResult>;
2800
2881
 
2882
+ declare const SCRIPT_TEST_SUFFIX = ".test.ts";
2883
+ interface ScriptTest {
2884
+ readonly file: string;
2885
+ readonly title: string;
2886
+ readonly identity: string;
2887
+ readonly explicitId?: string;
2888
+ readonly url?: string;
2889
+ readonly tags: readonly string[];
2890
+ readonly body: TestBody;
2891
+ readonly source: FlowSource;
2892
+ }
2893
+ interface LoadedScriptFile {
2894
+ readonly file: string;
2895
+ readonly tests: readonly ScriptTest[];
2896
+ readonly diagnostics: readonly FlowDiagnostic[];
2897
+ }
2898
+ declare function isScriptTestFile(file: string): boolean;
2899
+ /** Pure validation of what one file registered; exported for tests. */
2900
+ declare function checkRegistrations(file: string, registrations: readonly ScriptRegistration[], repoRoot: string): LoadedScriptFile;
2901
+ /**
2902
+ * Import a `*.test.ts` file once per process and collect its `test()` calls.
2903
+ * Imports run one at a time, because registration goes through one shared
2904
+ * list; the result is cached, as the module itself is.
2905
+ */
2906
+ declare function loadScriptFile(file: string, options: {
2907
+ readonly repoRoot: string;
2908
+ }): Promise<LoadedScriptFile>;
2909
+ /**
2910
+ * Listing and selection work on flow headers; each script test becomes one
2911
+ * header whose identity selects it inside its file.
2912
+ */
2913
+ declare function scriptListingEntries(script: LoadedScriptFile): readonly {
2914
+ readonly file: string;
2915
+ readonly result: ParsedFlowResult;
2916
+ }[];
2917
+
2918
+ /** A literal step sentence written in a `*.test.ts` file. */
2919
+ interface ScriptSentence {
2920
+ readonly text: string;
2921
+ readonly source: FlowSource;
2922
+ }
2923
+ interface ScriptSentenceScan {
2924
+ readonly sentences: readonly ScriptSentence[];
2925
+ /** Sentences built at run time; they cannot be checked before a run. */
2926
+ readonly warnings: readonly FlowDiagnostic[];
2927
+ /** Parameter names of the functions this file declares, by position. */
2928
+ readonly functions: ReadonlyMap<string, readonly string[]>;
2929
+ /**
2930
+ * `f(ai)` calls to a function this file does not declare. Validation
2931
+ * resolves them through imports: the parameter must be named `ai`.
2932
+ */
2933
+ readonly helperCalls: readonly HelperCall[];
2934
+ }
2935
+ interface HelperCall {
2936
+ readonly callee: string;
2937
+ readonly position: number;
2938
+ readonly source: FlowSource;
2939
+ /**
2940
+ * `ai`: the test's ai itself, so the parameter must be named `ai`.
2941
+ * `context`: the test's context or `{ ai }`, so the helper must be one
2942
+ * validation reads.
2943
+ */
2944
+ readonly passes: "ai" | "context";
2945
+ }
2946
+ type Token = {
2947
+ readonly kind: "ident" | "punct";
2948
+ readonly value: string;
2949
+ readonly line: number;
2950
+ readonly col: number;
2951
+ } | {
2952
+ readonly kind: "string";
2953
+ readonly value: string;
2954
+ /** A template literal with `${}` has no single value. */
2955
+ readonly dynamic: boolean;
2956
+ readonly line: number;
2957
+ readonly col: number;
2958
+ };
2959
+ /** A small JavaScript lexer: enough to find string arguments of `ai` calls. */
2960
+ declare function tokenize(source: string): Token[];
2961
+ /**
2962
+ * Find the literal sentences passed to `ai(...)`, `ai([...])`, and
2963
+ * `ai.group(name, [...])`. A sentence built with `${}` or `+` is reported as
2964
+ * a warning: it defeats the classification cache and cannot be checked
2965
+ * before a run. `ai.extract` takes a description, not a step, so it is skipped.
2966
+ */
2967
+ declare function scanScriptSentences(source: string, file: string): ScriptSentenceScan;
2968
+ /**
2969
+ * Relative module specifiers a file imports, such as `./support/login.js`.
2970
+ * Validation follows them to check the sentences in shared helpers.
2971
+ */
2972
+ declare function scanLocalImports(source: string): readonly string[];
2973
+ interface ImportBinding {
2974
+ readonly local: string;
2975
+ readonly imported: string;
2976
+ readonly specifier: string;
2977
+ }
2978
+ /** Named and default imports: `import login, { a, b as c } from "./x.js"`. */
2979
+ declare function scanImportBindings(source: string): readonly ImportBinding[];
2980
+ /**
2981
+ * The lines of the call expression that starts on `line`, such as a whole
2982
+ * `test("…", async () => { … })`, so a helper declared elsewhere in the file
2983
+ * is not mistaken for part of a test. The outermost call on the line wins.
2984
+ */
2985
+ declare function callExtent(source: string, line: number): {
2986
+ readonly start: number;
2987
+ readonly end: number;
2988
+ } | undefined;
2989
+
2990
+ /** A misuse of the `ai` API: the test cannot run as written. */
2991
+ declare class ScriptUsageError extends Error {
2992
+ readonly code: string;
2993
+ readonly fix: string;
2994
+ constructor(code: string, message: string, fix: string);
2995
+ }
2996
+ /** Convert `{{name}}` values to the runner's opaque data entries. */
2997
+ declare function valueEntries(values: AiValues | undefined): Record<string, ResolvedDataEntry>;
2998
+ /**
2999
+ * Inline plain values into the sentence the locator and Judge read, so
3000
+ * `click Add to cart for {{product}}` names the product. A `type` value and
3001
+ * secrets stay placeholders, as does a value that would change the sentence's
3002
+ * own quotes or placeholders.
3003
+ */
3004
+ declare function inlineValues(step: SentenceStep, op: string, values: Readonly<Record<string, ResolvedDataEntry>>): string;
3005
+ /** Run one `test()` from a `*.test.ts` file as one attempt. */
3006
+ declare function runScriptTest(file: string, identity: string | undefined, runDependencies: FlowRunnerDependencies): Promise<FlowRunResult>;
3007
+
2801
3008
  /** A browser action requested by a Sedum flow. */
2802
3009
  interface ActionRequest {
2803
3010
  readonly description: string;
2804
3011
  }
2805
3012
 
2806
- export { ACCEPTANCE_POLICY_VERSION, type ActionRequest, type Aim, type AimResult, AssertionEngineError, type AssertionEngineErrorCode, type AssertionOptions, type BrowserContextOptions, type BrowserContextSession, type BrowserDriver, BrowserDriverError, type BrowserDriverErrorCode, type BrowserInstallResult, type BrowserKind, type BrowserLaunchOptions, type BrowserPage, type BrowserSession, CACHE_FORMAT, CANDIDATE_LIMIT, CLASSIFICATION_PROMPT_VERSION, type CacheEntry, type CacheLookup, type CacheMissReason, type CacheStore, type CachedClassification, type Candidate, type CandidatePage, ClassificationBatchError, type ClassificationCache, type ClassificationDiagnostic, type ClassificationDiagnosticCode, type ClassificationInput, type ClassificationMetrics, type ClassificationProvider, type ClassificationResult, type ClassifiedFlowDefinition, type ClassifiedFlowSentence, type ClassifiedFlowStep, type ClassifiedModuleStep, type ClassifiedStep, type ClassifyFlowOptions, DEFAULT_BAND, DEFAULT_CONTRADICTION_CUTOFF, DEFAULT_MIN_P, DEFAULT_VISION_MODEL, DIGEST_LIMIT, DataResolutionError, type DeclaredDataValue, type DigestResult, type DiscoveryProblem, type DiscoveryProblemCode, FileClassificationCache, type FillResult, type FillTarget, type FlowClassificationDiagnostic, type FlowClassificationResult, type FlowDefinition, type FlowDiagnostic, type FlowRunResult, type FlowRunnerDependencies, type FlowScalar, type FlowSource, type FlowStep, type FlowToken, type FlowValidationResult, type FormatCoverage, type FullValidationCoverage, type GoalAction, type GoalChoice, type GoalDecision, type GoalOptions, type GoalPlanner, type GoalResult, type GoalState, type InvalidListEntry, type ItemVerdict, type Judge, type JudgeDecision, type JudgePageDigest, type ListedDiagnostic, type ListedTest, LocatorCacheConflict, type LocatorCacheDiagnostic, type LocatorCacheLookup, type LocatorCacheSeed, type LocatorDiagnostic, type LocatorFailure, type LocatorOptionDiagnostic, type LocatorOptions, type LocatorResult, MATCHER_VERSION, MIN_MODEL_MARGIN, MIN_MODEL_PROBABILITY, MODEL_CHOICES, type MatchResult, type MeasureResult, type ModelChoice, type ModelClassification, type ModuleBinding, ModuleBindingResolutionError, type ModuleDefinition, type ModuleStep, NAME_LIMIT, NOT_CHECKED_OFFLINE_CODE, type NavigationOptions, type NavigationResult, NoopCacheStore, NoopClassificationCache, OPERATIONS, OPERATION_SET_VERSION, OpenRouterVisionResolver, type Operation, PAGE_PROTOCOL, PEER_LIMIT, type PageBridge, PageScriptError, type PageVersion, type ParseFlowOptions, type ParsedFlowResult, type ParsedModuleResult, PlaywrightBrowserDriver, type ProjectFileValidation, type ProjectFiles, type ProjectValidationCounts, type ProjectValidationOptions, type ProjectValidationResult, type ProviderCall, type ProviderCallOptions, ProviderError, type ProviderErrorCode, type ProviderRate, type ProviderTokenUsage, type ReadTargetResult, type RepeatedMemberPolicy, type ReportPrivacy, type ResolveFlowModulesOptions, type ResolvedDataEntry, type ResolvedFlowResult, type ResolvedModuleCall, ResolvedStepTarget, type Resolver, type ResolverCandidate, type ResolverCandidates, type ResolverDecision, type ResolverItem, type ResolverOption, type ResultAttempt, ResultAttemptSchema, type ResultCall, ResultCallSchema, ResultErrorSchema, type ResultExecution, ResultExecutionSchema, type ResultFrame, ResultFrameSchema, ResultJudgementSchema, ResultLocatorSchema, ResultObservationSchema, type ResultPage, ResultPageSchema, type ResultProblem, ResultProblemSchema, type ResultSink, ResultSourceSchema, type ResultStep, ResultStepSchema, type ResultTest, ResultTestSchema, ResultTotalsSchema, ReusableBrowserDriver, RunRecorder, type RunResult, RunResultSchema, RuntimeUrl, RuntimeValue, type SentenceClassification, type SentenceStep, type SettleOptions, type SettleResult, type StepCommand, StepExecutionError, type StepExecutionOptions, type StepExecutionResult, type StepFailureCode, type StepFailurePhase, type StepOperation, type StepOperationKind, type StepOutcome, type StepSource, type StepTokenization, type TestListing, TestRecording, type TestStartInput, VISION_PROMPT, type ValidationInput, type VerifyDecision, type VerifyFlag, type VerifyOptions, type VerifyPolicy, type VerifyResult, type VisionFailure, type VisionObservation, VisionRequestError, type VisionResolver, canonicalSentence, captureVisionObservation, classificationKey, classifyParsedFlow, classifySentenceSteps, classifySteps, clearPageRefs, clickTarget, codePoints, collectCandidates, compareDiagnostics, dedupeDiagnostics, discoverFlowFiles, discoverProjectFiles, displayPath, evaluateModelAnswer, evaluateVerifyScores, executeStep, findBrowserExecutable, findIdentityCollisions, formatFlowDiagnostic, goalChoiceAccepted, goalOperations, installChromium, isFlowScalar, isFullyValidated, isSafeRole, isWeakPeer, keyedDigest, listTests, liveCandidates, loadFlowFile, matchEntry, matchLiveEntry, measure, normalizeSignal, opaqueMatches, pageDigest, pageKey, pageVersion, parseDataTemplate, parseFlow, parseModule, patternOperation, preflightSentence, projectCandidates, projectDigest, quietPage, readTarget, redactOpaqueText, reportPage, resolveData, resolveEntryUrl, resolveFlowModules, resolveModuleBindings, resolveTarget, resolveTypeOperand, resultTotals, runFlow, runGoal, runResultJsonSchema, safeSource, safeText, safeUrl, sameVisualVersion, stageEntry, tokenizeStep, unknownCostCall, validateFlows, validateOperand, validateProject, validateRunResult, validateTypeOperand, verify, visualCandidates, walkSuiteFiles };
3013
+ export { ACCEPTANCE_POLICY_VERSION, type ActionRequest, AiValues, type Aim, type AimResult, AssertionEngineError, type AssertionEngineErrorCode, type AssertionOptions, type AttemptDependencies, type AttemptReport, type BrowserContextOptions, type BrowserContextSession, type BrowserDriver, BrowserDriverError, type BrowserDriverErrorCode, type BrowserInstallResult, type BrowserKind, type BrowserLaunchOptions, type BrowserPage, type BrowserSession, CACHE_FORMAT, CANDIDATE_LIMIT, CLASSIFICATION_PROMPT_VERSION, type CacheEntry, type CacheLookup, type CacheMissReason, type CacheStore, type CachedClassification, type Candidate, type CandidatePage, ClassificationBatchError, type ClassificationCache, type ClassificationDiagnostic, type ClassificationDiagnosticCode, type ClassificationInput, type ClassificationMetrics, type ClassificationProvider, type ClassificationResult, type ClassifiedFlowDefinition, type ClassifiedFlowSentence, type ClassifiedFlowStep, type ClassifiedModuleStep, type ClassifiedStep, type ClassifyFlowOptions, type ClickOptions, type ClickResult, DEFAULT_BAND, DEFAULT_CONTRADICTION_CUTOFF, DEFAULT_MIN_P, DEFAULT_VISION_MODEL, DIGEST_LIMIT, DataResolutionError, DeclaredDataValue, type DigestResult, type DiscoveryProblem, type DiscoveryProblemCode, FileClassificationCache, type FillResult, type FillTarget, type FlowClassificationDiagnostic, type FlowClassificationResult, FlowDefinition, FlowDiagnostic, type FlowRunResult, type FlowRunnerDependencies, FlowScalar, FlowSource, FlowToken, FlowValidationResult, FullValidationCoverage, type GoalAction, type GoalChoice, type GoalDecision, type GoalOptions, type GoalPlanner, type GoalResult, type GoalState, type HelperCall, type ImportBinding, type InvalidListEntry, type ItemVerdict, type Judge, type JudgeDecision, type JudgePageDigest, type LineRange, type ListedDiagnostic, type ListedTest, type LoadedScriptFile, LocatorCacheConflict, type LocatorCacheDiagnostic, type LocatorCacheLookup, type LocatorCacheSeed, type LocatorDiagnostic, type LocatorFailure, type LocatorOptionDiagnostic, type LocatorOptions, type LocatorResult, MATCHER_VERSION, MIN_MODEL_MARGIN, MIN_MODEL_PROBABILITY, MODEL_CHOICES, type MatchResult, type MeasureResult, type ModelChoice, type ModelClassification, ModuleBinding, ModuleBindingResolutionError, ModuleStep, NAME_LIMIT, NOT_CHECKED_OFFLINE_CODE, type NavigationOptions, type NavigationResult, NoopCacheStore, NoopClassificationCache, OPERATIONS, OPERATION_SET_VERSION, OpenRouterVisionResolver, type Operation, PAGE_PROTOCOL, PEER_LIMIT, type PageBridge, PageScriptError, type PageVersion, type ParseFlowOptions, ParsedFlowResult, ParsedModuleResult, PlaywrightBrowserDriver, type ProjectFileValidation, type ProjectFiles, type ProjectValidationCounts, type ProjectValidationOptions, type ProjectValidationResult, type ProviderCall, type ProviderCallOptions, ProviderError, type ProviderErrorCode, type ProviderRate, type ProviderTokenUsage, type ReadTargetResult, type RejectionOwner, RejectionRouter, type RepeatedMemberPolicy, type ReportPrivacy, type ResolveFlowModulesOptions, type ResolvedDataEntry, type ResolvedFlowResult, ResolvedModuleCall, ResolvedStepTarget, type Resolver, type ResolverCandidate, type ResolverCandidates, type ResolverDecision, type ResolverItem, type ResolverOption, type ResultAttempt, ResultAttemptSchema, type ResultCall, ResultCallSchema, ResultErrorSchema, type ResultExecution, ResultExecutionSchema, type ResultFrame, ResultFrameSchema, ResultJudgementSchema, ResultLocatorSchema, ResultObservationSchema, type ResultPage, ResultPageSchema, type ResultProblem, ResultProblemSchema, type ResultSink, ResultSourceSchema, type ResultStep, ResultStepSchema, type ResultTest, ResultTestSchema, ResultTotalsSchema, ReusableBrowserDriver, RunRecorder, type RunResult, RunResultSchema, type RunningTest, RuntimeUrl, RuntimeValue, SCRIPT_TEST_SUFFIX, ScriptRegistration, type ScriptSentence, type ScriptSentenceScan, type ScriptTest, ScriptUsageError, type SentenceClassification, type SentencePresentation, SentenceStep, type SettleOptions, type SettleResult, type StepCommand, StepExecutionError, type StepExecutionOptions, type StepExecutionResult, type StepFailureCode, type StepFailurePhase, type StepOperation, type StepOperationKind, type StepOutcome, type StepSource, type StepTokenization, type StrayReason, TEST_SUFFIXES, TestBody, type TestListing, TestRecording, type TestStartInput, type UnattributedRejection, VISION_PROMPT, ValidationInput, type VerifyDecision, type VerifyFlag, type VerifyOptions, type VerifyPolicy, type VerifyResult, type VisionFailure, type VisionKeyProbe, type VisionObservation, VisionRequestError, type VisionResolver, attributeRejection, callExtent, canonicalSentence, captureVisionObservation, checkRegistrations, classificationKey, classifyParsedFlow, classifySentenceSteps, classifySteps, clearPageRefs, clickTarget, closeQuietly, codePoints, collectCandidates, compareDiagnostics, dedupeDiagnostics, describeRejection, discoverFlowFiles, discoverProjectFiles, displayPath, evaluateModelAnswer, evaluateVerifyScores, executeSentence, executeStep, findBrowserExecutable, findIdentityCollisions, firstDiagnostic, goalChoiceAccepted, goalOperations, inlineValues, installChromium, isFlowScalar, isRunWideProviderError, isSafeRole, isScriptTestFile, isWeakPeer, keyedDigest, listTests, liveCandidates, loadFlowFile, loadListingEntries, loadScriptFile, matchEntry, matchLiveEntry, measure, navigationWhy, normalizeSignal, opaqueMatches, pageDigest, pageKey, pageVersion, parseDataTemplate, parseFlow, parseModule, patternOperation, preflightSentence, probeOpenRouterKey, projectCandidates, projectDigest, quietPage, readTarget, redactOpaqueText, reportPage, resolveData, resolveEntryUrl, resolveFlowModules, resolveModuleBindings, resolveTarget, resolveTypeOperand, resultCall, resultTotals, runFlow, runGoal, runResultJsonSchema, runScriptTest, runtimeFailure, safeSource, safeText, safeUrl, sameVisualVersion, scanImportBindings, scanLocalImports, scanScriptSentences, scriptListingEntries, stageEntry, tokenize, tokenizeStep, unknownCostCall, unsupported, validateFlows, validateOperand, validateProject, validateRunResult, validateTypeOperand, valueEntries, verify, visualCandidates, walkSuiteFiles };