spana-test 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/spana-testing/SKILL.md +122 -246
- package/README.md +2 -2
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +5 -5
- package/dist/{storybook-CxaP3YDz.d.ts → app-DcLXtpv4.d.ts} +205 -9
- package/dist/{chunk-3YE2POGD.js → chunk-3SH5JQF7.js} +143 -3
- package/dist/chunk-3SH5JQF7.js.map +1 -0
- package/dist/chunk-4K3FZTSV.js +179 -0
- package/dist/chunk-4K3FZTSV.js.map +1 -0
- package/dist/{chunk-H3RWZCID.js → chunk-C4E4XULT.js} +104 -3
- package/dist/chunk-C4E4XULT.js.map +1 -0
- package/dist/{chunk-SQL3YRR5.js → chunk-KBRLIQRA.js} +16 -1
- package/dist/chunk-KBRLIQRA.js.map +1 -0
- package/dist/{chunk-LRGT342X.js → chunk-KEUZLBQS.js} +1110 -475
- package/dist/chunk-KEUZLBQS.js.map +1 -0
- package/dist/{chunk-XENRC3YO.js → chunk-LCV673G3.js} +605 -41
- package/dist/chunk-LCV673G3.js.map +1 -0
- package/dist/{chunk-3TRMQCUT.js → chunk-PLE7RFQE.js} +31 -2
- package/dist/chunk-PLE7RFQE.js.map +1 -0
- package/dist/{chunk-PJKIXVSO.js → chunk-PWUJT5HE.js} +898 -238
- package/dist/chunk-PWUJT5HE.js.map +1 -0
- package/dist/{chunk-WSA5QPTA.js → chunk-S4JVAHBR.js} +2 -2
- package/dist/{chunk-UJQ7PID5.js → chunk-WBBMEAHU.js} +78 -3
- package/dist/chunk-WBBMEAHU.js.map +1 -0
- package/dist/{chunk-5245YBLL.js → chunk-Y2RZNOKU.js} +2 -2
- package/dist/cli.js +11 -11
- package/dist/cli.js.map +1 -1
- package/dist/config-loader-J4Z2PMUQ.js +9 -0
- package/dist/{doctor-command-WB3O2H64.js → doctor-command-WEHFANT7.js} +3 -3
- package/dist/{filters-Q3ALKWZ5.js → filters-MQG2RMPX.js} +4 -2
- package/dist/flow-C2JQ7gUu.d.ts +95 -0
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/index.d.ts +214 -20
- package/dist/index.js +173 -6
- package/dist/index.js.map +1 -1
- package/dist/{runner-6HK62Q7B.js → runner-TF4OKPYP.js} +2 -2
- package/dist/{screenshot-compare-3QRHHSFZ.js → screenshot-compare-5NINZVOK.js} +21 -1
- package/dist/screenshot-compare-5NINZVOK.js.map +1 -0
- package/dist/{server-QWJJB3WG.js → server-3MGZNK67.js} +2 -2
- package/dist/{server-PRM7BVVD.js → server-OANRDAHN.js} +5 -5
- package/dist/{session-Ddem-Q5n.d.ts → session-Daq0mE_a.d.ts} +22 -1
- package/dist/{session-2E6OK6BH.js → session-Q3QYHT4Q.js} +4 -4
- package/dist/{studio-command-O3NN5BCG.js → studio-command-RJYLJT4I.js} +2 -2
- package/dist/{test-command-FYOZ6QAE.js → test-command-ALH5ZQY5.js} +23 -9
- package/dist/test-command-ALH5ZQY5.js.map +1 -0
- package/dist/{validator-HZ2A3NEI.js → validator-BLOLIHUY.js} +3 -3
- package/package.json +2 -2
- package/dist/chunk-3TRMQCUT.js.map +0 -1
- package/dist/chunk-3YE2POGD.js.map +0 -1
- package/dist/chunk-H3RWZCID.js.map +0 -1
- package/dist/chunk-LRGT342X.js.map +0 -1
- package/dist/chunk-PJKIXVSO.js.map +0 -1
- package/dist/chunk-SQL3YRR5.js.map +0 -1
- package/dist/chunk-UJQ7PID5.js.map +0 -1
- package/dist/chunk-XENRC3YO.js.map +0 -1
- package/dist/config-loader-XGDDJGVY.js +0 -9
- package/dist/flow-CyRC-tTc.d.ts +0 -176
- package/dist/screenshot-compare-3QRHHSFZ.js.map +0 -1
- package/dist/test-command-FYOZ6QAE.js.map +0 -1
- /package/dist/{chunk-WSA5QPTA.js.map → chunk-S4JVAHBR.js.map} +0 -0
- /package/dist/{chunk-5245YBLL.js.map → chunk-Y2RZNOKU.js.map} +0 -0
- /package/dist/{config-loader-XGDDJGVY.js.map → config-loader-J4Z2PMUQ.js.map} +0 -0
- /package/dist/{doctor-command-WB3O2H64.js.map → doctor-command-WEHFANT7.js.map} +0 -0
- /package/dist/{filters-Q3ALKWZ5.js.map → filters-MQG2RMPX.js.map} +0 -0
- /package/dist/{runner-6HK62Q7B.js.map → runner-TF4OKPYP.js.map} +0 -0
- /package/dist/{server-QWJJB3WG.js.map → server-3MGZNK67.js.map} +0 -0
- /package/dist/{server-PRM7BVVD.js.map → server-OANRDAHN.js.map} +0 -0
- /package/dist/{session-2E6OK6BH.js.map → session-Q3QYHT4Q.js.map} +0 -0
- /package/dist/{studio-command-O3NN5BCG.js.map → studio-command-RJYLJT4I.js.map} +0 -0
- /package/dist/{validator-HZ2A3NEI.js.map → validator-BLOLIHUY.js.map} +0 -0
package/dist/gherkin/steps.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { F as FlowDefinition, a as FlowContext, b as FlowConfig
|
|
2
|
-
export { c as FlowFn,
|
|
3
|
-
import { R as RawDriverService, D as DriverError, a as DomElementMatch, P as Platform, E as ExtendedSelector, T as TapMode, b as ProvConfig, c as DomChannel, d as DomTargetInfo, S as Selector, e as DomWaitForSelectorOptions, f as
|
|
4
|
-
export {
|
|
5
|
-
import { E as Element, B as Bounds, C as ConnectOptions, S as Session } from './session-
|
|
1
|
+
import { F as FlowDefinition, a as FlowContext, b as FlowConfig } from './flow-C2JQ7gUu.js';
|
|
2
|
+
export { c as FlowFn, P as PromiseExpectation, S as SecondarySession, d as SecondarySessionOptions, e as Sessions, f as flow } from './flow-C2JQ7gUu.js';
|
|
3
|
+
import { R as RawDriverService, D as DriverError, a as DomElementMatch, P as Platform, E as ExtendedSelector, T as TapMode, b as ProvConfig, c as DomChannel, d as DomTargetInfo, S as Selector, e as DomWaitForSelectorOptions, f as DomWaitForHiddenOptions, g as DomWaitForMatchOptions, h as DomWaitForMatchResult, i as DomFillOptions, j as DomIdleOptions, k as DomStorageEntries, l as DomClearStorageOptions, B as BrowserRouteMatcher, m as BrowserMockResponse, n as BrowserConsoleLog, o as BrowserJSError, p as BrowserName, V as VirtualAuthenticatorOptions, q as ElectrobunAppConfig, r as ElectrobunRenderer, A as AppiumExecutionConfig, s as AppConfig, t as PromiseApp } from './app-DcLXtpv4.js';
|
|
4
|
+
export { u as ArtifactConfig, v as BackUntilVisibleOptions, w as BridgeConfig, x as BrowserHAR, y as BrowserNetworkConditions, z as DeviceInfo, C as DeviceStateConfig, F as DismissKeyboardOptions, G as DomChannelKind, H as DomRect, I as ElectronAppConfig, L as LaunchOptions, J as RelativeSelector, K as ScrollUntilVisibleOptions, M as StorybookConfig, N as StorybookOpenOptions, O as StorybookValue, Q as TouchAction, U as TouchSequence, W as VirtualCredential, X as WarmDaemonConfig, Y as WebBrowserEngine, Z as WebExecutionConfig, _ as WebResourceBlockType, $ as buildDomFillScript, a0 as buildDomWaitForHiddenScript, a1 as buildDomWaitForMatchScript, a2 as buildDomWaitForSelectorScript, a3 as defineConfig, a4 as isSystemUISelector, a5 as isTestIDSelector, a6 as systemUI } from './app-DcLXtpv4.js';
|
|
5
|
+
import { E as Element, B as Bounds, C as ConnectOptions, S as Session } from './session-Daq0mE_a.js';
|
|
6
6
|
import { Socket } from 'node:net';
|
|
7
7
|
import { Effect } from 'effect';
|
|
8
8
|
import { Browser, _electron, chromium } from 'playwright-core';
|
|
@@ -297,7 +297,9 @@ declare class CdpDomChannel implements DomChannel {
|
|
|
297
297
|
private connected;
|
|
298
298
|
private nextId;
|
|
299
299
|
private pending;
|
|
300
|
+
private eventListeners;
|
|
300
301
|
private currentTargetId;
|
|
302
|
+
private activeSessionId;
|
|
301
303
|
constructor(options: CdpDomChannelOptions);
|
|
302
304
|
isConnected(): boolean;
|
|
303
305
|
listTargets(): Promise<DomTargetInfo[]>;
|
|
@@ -306,10 +308,17 @@ declare class CdpDomChannel implements DomChannel {
|
|
|
306
308
|
connect(): Promise<void>;
|
|
307
309
|
private openSocket;
|
|
308
310
|
private rejectAllPending;
|
|
309
|
-
|
|
311
|
+
setSessionId(sessionId: string | null): void;
|
|
312
|
+
get sessionId(): string | null;
|
|
313
|
+
onEvent(method: string, listener: (params: any, sessionId?: string) => void): () => void;
|
|
314
|
+
waitForEvent<T = any>(method: string, timeoutMs?: number, predicate?: (params: T, sessionId?: string) => boolean): Promise<T>;
|
|
315
|
+
sendCommand<T = any>(method: string, params?: Record<string, unknown>, sessionId?: string | null): Promise<T>;
|
|
310
316
|
evaluate<T = unknown>(script: string | ((...args: any[]) => T), ...args: any[]): Promise<T>;
|
|
311
317
|
query(selector: Selector): Promise<DomElementMatch[]>;
|
|
312
318
|
waitForSelector(selector: Selector, opts?: DomWaitForSelectorOptions): Promise<DomElementMatch[]>;
|
|
319
|
+
waitForHidden(selector: Selector, opts?: DomWaitForHiddenOptions): Promise<boolean>;
|
|
320
|
+
waitForMatch(selector: Selector, opts: DomWaitForMatchOptions): Promise<DomWaitForMatchResult>;
|
|
321
|
+
fillDom(selector: Selector, value: string, opts?: DomFillOptions): Promise<boolean>;
|
|
313
322
|
tapDom(selector: Selector): Promise<boolean>;
|
|
314
323
|
scrollIntoView(selector: Selector): Promise<DomElementMatch | null>;
|
|
315
324
|
reload(): Promise<void>;
|
|
@@ -611,8 +620,16 @@ interface PlaywrightConfig {
|
|
|
611
620
|
blockResources?: Array<"image" | "font" | "media" | "stylesheet">;
|
|
612
621
|
/** Connect to an already-running warm Chromium CDP endpoint instead of launching a new browser process. */
|
|
613
622
|
cdpEndpoint?: string;
|
|
623
|
+
/** Connect to a remote Playwright WebSocket server (e.g. BrowserStack Automate Web `wss://cdp.browserstack.com/playwright?...`). */
|
|
624
|
+
wsEndpoint?: string;
|
|
614
625
|
/** Reuse a persistent detached headless Chromium daemon across CLI runs (Flashwright-style warm session). */
|
|
615
626
|
warmBrowser?: boolean;
|
|
627
|
+
/** Scope key for isolating warm Chromium daemons across concurrent repos/runs (defaults to cwd hash). */
|
|
628
|
+
warmBrowserScope?: string;
|
|
629
|
+
/** Create a fresh isolated BrowserContext per flow via a pre-warmed context pool + background teardown. */
|
|
630
|
+
freshContextPerFlow?: boolean;
|
|
631
|
+
/** Automatically attach a CDP WebAuthn virtual authenticator (passkey) to every fresh context. */
|
|
632
|
+
virtualAuthenticator?: boolean | VirtualAuthenticatorOptions;
|
|
616
633
|
/** Attach a built-in zero-setup Playwright DOM channel for ~1ms `{ testID }` queries without full DOM dumps. Default: true. */
|
|
617
634
|
enableDomChannel?: boolean;
|
|
618
635
|
}
|
|
@@ -620,28 +637,46 @@ interface PlaywrightConfig {
|
|
|
620
637
|
* Connect to an existing warm headless Chromium daemon or start a detached one
|
|
621
638
|
* registered in Spana's warm daemon registry (`spana daemon status|stop`).
|
|
622
639
|
*/
|
|
623
|
-
declare function ensureWarmBrowserDaemon(config?: Pick<PlaywrightConfig, "executablePath" | "headless">): Promise<{
|
|
640
|
+
declare function ensureWarmBrowserDaemon(config?: Pick<PlaywrightConfig, "executablePath" | "headless" | "warmBrowserScope">): Promise<{
|
|
624
641
|
browser: Browser;
|
|
625
642
|
cdpUrl: string;
|
|
626
643
|
reused: boolean;
|
|
627
644
|
}>;
|
|
628
645
|
declare function connectPlaywrightOverCDP(cdpEndpoint: string): Promise<Browser>;
|
|
646
|
+
declare function connectPlaywrightOverWS(wsEndpoint: string, browserName?: BrowserName): Promise<Browser>;
|
|
629
647
|
declare function launchPlaywrightBrowser(config?: Pick<PlaywrightConfig, "browser" | "headless" | "channel" | "executablePath">): Promise<Browser>;
|
|
630
648
|
|
|
631
|
-
interface
|
|
632
|
-
|
|
633
|
-
|
|
649
|
+
interface DirectCdpBrowserLaunchOptions {
|
|
650
|
+
/** Explicit Chromium/Chrome binary path. Auto-detects system Chrome or Playwright Chromium if omitted. */
|
|
651
|
+
executablePath?: string;
|
|
652
|
+
/** Run headless (default: true). */
|
|
653
|
+
headless?: boolean;
|
|
654
|
+
/** Reuse a detached warm Chromium daemon across CLI runs. */
|
|
655
|
+
warmBrowser?: boolean;
|
|
656
|
+
/** Isolation scope key for warm Chromium daemon (defaults to cwd hash). */
|
|
657
|
+
warmBrowserScope?: string;
|
|
658
|
+
/** Extra Chrome launch flags. */
|
|
659
|
+
args?: string[];
|
|
660
|
+
}
|
|
661
|
+
interface DirectCdpBrowserHandle {
|
|
662
|
+
/** HTTP debugging endpoint, e.g. `http://127.0.0.1:9322`. */
|
|
663
|
+
httpEndpoint: string;
|
|
664
|
+
/** Browser-level CDP WebSocket URL (`ws://127.0.0.1:.../devtools/browser/...`). */
|
|
665
|
+
browserWsUrl: string;
|
|
666
|
+
/** True when attached to a pre-existing warm daemon (close will NOT kill it). */
|
|
667
|
+
reused: boolean;
|
|
668
|
+
pid?: number;
|
|
669
|
+
close(): Promise<void>;
|
|
634
670
|
}
|
|
635
671
|
/**
|
|
636
|
-
*
|
|
637
|
-
*
|
|
672
|
+
* Launch (or attach to a warm) Chromium process directly over raw CDP WebSocket —
|
|
673
|
+
* completely bypassing Playwright's Node client↔server IPC pipe!
|
|
638
674
|
*/
|
|
639
|
-
declare function
|
|
640
|
-
|
|
675
|
+
declare function launchDirectCdpBrowser(options?: DirectCdpBrowserLaunchOptions): Promise<DirectCdpBrowserHandle>;
|
|
641
676
|
interface LightweightCdpDriverOptions {
|
|
642
677
|
/**
|
|
643
678
|
* HTTP CDP endpoint (e.g. `"http://127.0.0.1:9222"` for Lightpanda or Chrome `--remote-debugging-port`)
|
|
644
|
-
* OR direct WebSocket debugger URL (`"ws://127.0.0.1:9222/devtools/page/..."`).
|
|
679
|
+
* OR direct WebSocket debugger URL (`"ws://127.0.0.1:9222/devtools/page/..."` or `"/devtools/browser/..."`).
|
|
645
680
|
*/
|
|
646
681
|
cdpUrl: string;
|
|
647
682
|
/** Optional base URL used when `launchApp()` receives a relative path. */
|
|
@@ -653,19 +688,54 @@ interface LightweightCdpDriverOptions {
|
|
|
653
688
|
width: number;
|
|
654
689
|
height: number;
|
|
655
690
|
};
|
|
691
|
+
/**
|
|
692
|
+
* Use isolated CDP browser contexts (`Target.createBrowserContext` + flattened CDP sessions)
|
|
693
|
+
* on a browser-level WebSocket — zero Playwright Node client↔server pipe!
|
|
694
|
+
* Auto-enabled when `cdpUrl` is a `/devtools/browser/` URL or `freshContextPerFlow` is true.
|
|
695
|
+
*/
|
|
696
|
+
useBrowserContexts?: boolean;
|
|
697
|
+
/** Pre-warm the next isolated CDP browser context while the current flow runs, and dispose old contexts asynchronously. */
|
|
698
|
+
freshContextPerFlow?: boolean;
|
|
699
|
+
/** Navigation wait condition (`"load"`, `"domcontentloaded"`, or `"commit"`). Default: `"load"` in browser-context mode. */
|
|
700
|
+
waitUntil?: "domcontentloaded" | "load" | "networkidle" | "commit";
|
|
701
|
+
/** Collapse CSS transitions & animations to 0.001ms via `Page.addScriptToEvaluateOnNewDocument`. */
|
|
702
|
+
instantAnimations?: boolean;
|
|
703
|
+
/** Abort specified resource types before hitting the network. */
|
|
704
|
+
blockResources?: Array<"image" | "font" | "media" | "stylesheet">;
|
|
705
|
+
/** Automatically attach a CDP WebAuthn virtual authenticator (passkey) to every context. */
|
|
706
|
+
virtualAuthenticator?: boolean | VirtualAuthenticatorOptions;
|
|
707
|
+
/** Optional Playwright-compatible storageState JSON path to preload into contexts. */
|
|
708
|
+
storageState?: string;
|
|
656
709
|
/** Injectable fetch & WebSocket factory for tests. */
|
|
657
710
|
fetchFn?: typeof fetch;
|
|
658
711
|
createWebSocket?: WebSocketFactory;
|
|
659
712
|
}
|
|
660
713
|
/**
|
|
661
|
-
*
|
|
662
|
-
*
|
|
714
|
+
* Direct CDP Chromium / Lightpanda driver speaking raw WebSocket CDP directly
|
|
715
|
+
* from Bun/Node to the browser — completely eliminating Playwright's Node
|
|
716
|
+
* client↔server IPC pipe!
|
|
663
717
|
*
|
|
664
|
-
*
|
|
665
|
-
*
|
|
718
|
+
* Supports:
|
|
719
|
+
* - Page-level attach (Lightpanda or existing tab)
|
|
720
|
+
* - Full browser-level isolated contexts (`Target.createBrowserContext`), pre-warmed
|
|
721
|
+
* context pooling (`freshContextPerFlow`), background async context disposal,
|
|
722
|
+
* built-in WebAuthn virtual passkeys, network mocking (`Fetch`), cookies/auth state,
|
|
723
|
+
* and single-round-trip MutationObserver actionability via `CdpDomChannel`.
|
|
666
724
|
*/
|
|
667
725
|
declare function makeLightweightCdpDriver(options: LightweightCdpDriverOptions): Effect.Effect<RawDriverService, DriverError>;
|
|
668
726
|
|
|
727
|
+
interface PrelaunchedWebBrowser {
|
|
728
|
+
browserPromise: Promise<Browser>;
|
|
729
|
+
ownsBrowser: boolean;
|
|
730
|
+
/** Populated when `execution.web.engine === "cdp"` speculatively launches direct Chromium. */
|
|
731
|
+
cdpBrowserPromise?: Promise<DirectCdpBrowserHandle>;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Start launching (or connecting to a warm/CDP) browser immediately
|
|
735
|
+
* so browser boot overlaps with flow discovery and TypeScript imports.
|
|
736
|
+
*/
|
|
737
|
+
declare function speculativelyPrelaunchWebBrowser(config: ProvConfig): PrelaunchedWebBrowser | undefined;
|
|
738
|
+
|
|
669
739
|
/** Order flows descending by known duration (longest first) while preserving order on ties. */
|
|
670
740
|
declare function orderFlowsLongestFirst(flows: FlowDefinition[], durationHintsMs?: Record<string, number>): FlowDefinition[];
|
|
671
741
|
|
|
@@ -1021,6 +1091,32 @@ interface PathRuleFilterOptions {
|
|
|
1021
1091
|
* Flows not matched by any rule fail open and run automatically.
|
|
1022
1092
|
*/
|
|
1023
1093
|
declare function pathRuleFilter(options: PathRuleFilterOptions): TestFilter;
|
|
1094
|
+
interface DeterministicImpactFilterOptions {
|
|
1095
|
+
name?: string;
|
|
1096
|
+
/** Additional path-to-flow rules combined with automatic static import-graph tracing. */
|
|
1097
|
+
pathMappings?: PathRule[];
|
|
1098
|
+
/** Flow tags that are NEVER skipped (e.g. `["smoke"]`). */
|
|
1099
|
+
alwaysRunTags?: string[];
|
|
1100
|
+
/** Path prefixes that force the entire suite to run (e.g. `["src/shared/", "db/"]`). */
|
|
1101
|
+
runAllOnPaths?: string[];
|
|
1102
|
+
/**
|
|
1103
|
+
* When true (default), if a changed file is NOT imported by any flow and does not
|
|
1104
|
+
* match any `pathMappings`, fail open and run all flows so unmapped app changes are
|
|
1105
|
+
* never silently missed. Set to `false` for strict import-graph-only selection.
|
|
1106
|
+
*/
|
|
1107
|
+
failOpenOnUnmappedChange?: boolean;
|
|
1108
|
+
/** Max recursive import depth to trace from each flow file. Default: 12. */
|
|
1109
|
+
maxDepth?: number;
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* 100% deterministic, zero-AI test impact filter for `--changed-since`.
|
|
1113
|
+
*
|
|
1114
|
+
* Recursively traces static ESM/CJS imports (`import`, `export ... from`, `require`)
|
|
1115
|
+
* from every `.flow.ts` file and combines them with optional `pathMappings`.
|
|
1116
|
+
* Fails open on config/lockfile changes, `runAllOnPaths`, and (by default) any
|
|
1117
|
+
* changed file not covered by any import graph or path mapping.
|
|
1118
|
+
*/
|
|
1119
|
+
declare function deterministicImpactFilter(options?: DeterministicImpactFilterOptions): TestFilter;
|
|
1024
1120
|
/**
|
|
1025
1121
|
* Run a chain of `TestFilter`s sequentially over candidate flows.
|
|
1026
1122
|
* Any filter that throws fails open (keeps all remaining flows) and logs a note.
|
|
@@ -1091,6 +1187,83 @@ declare function createFlowWithFixtures<Fixtures extends Record<string, unknown>
|
|
|
1091
1187
|
(name: string, fn: (ctx: FlowContext<T, R> & Fixtures) => Promise<void>): FlowDefinition<T, R>;
|
|
1092
1188
|
(name: string, config: ExtendedFlowConfig<R, SessionName>, fn: (ctx: FlowContext<T, R> & Fixtures) => Promise<void>): FlowDefinition<T, R>;
|
|
1093
1189
|
};
|
|
1190
|
+
interface ApiClientOptions {
|
|
1191
|
+
/** Base URL for API/test-control endpoints (e.g. `"http://localhost:3000/api"`). */
|
|
1192
|
+
baseUrl: string;
|
|
1193
|
+
/** Default headers attached to every request (e.g. `{ Authorization: "Bearer ..." }`). */
|
|
1194
|
+
headers?: Record<string, string>;
|
|
1195
|
+
/** Optional custom fetch implementation for testing. */
|
|
1196
|
+
fetchFn?: typeof fetch;
|
|
1197
|
+
}
|
|
1198
|
+
interface ApiRequestOptions {
|
|
1199
|
+
headers?: Record<string, string>;
|
|
1200
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
1201
|
+
signal?: AbortSignal;
|
|
1202
|
+
}
|
|
1203
|
+
interface ApiResponse<T = unknown> {
|
|
1204
|
+
status: number;
|
|
1205
|
+
ok: boolean;
|
|
1206
|
+
headers: Headers;
|
|
1207
|
+
data: T;
|
|
1208
|
+
}
|
|
1209
|
+
interface ApiClient {
|
|
1210
|
+
get<T = unknown>(path: string, opts?: ApiRequestOptions): Promise<ApiResponse<T>>;
|
|
1211
|
+
post<T = unknown>(path: string, body?: unknown, opts?: ApiRequestOptions): Promise<ApiResponse<T>>;
|
|
1212
|
+
put<T = unknown>(path: string, body?: unknown, opts?: ApiRequestOptions): Promise<ApiResponse<T>>;
|
|
1213
|
+
patch<T = unknown>(path: string, body?: unknown, opts?: ApiRequestOptions): Promise<ApiResponse<T>>;
|
|
1214
|
+
delete<T = unknown>(path: string, opts?: ApiRequestOptions): Promise<ApiResponse<T>>;
|
|
1215
|
+
/** Register an automatic teardown callback (runs in strict LIFO order on `cleanup()`). */
|
|
1216
|
+
onCleanup(fn: () => Promise<void> | void): void;
|
|
1217
|
+
/** Run all registered cleanup callbacks in reverse (LIFO) order and clear the queue. */
|
|
1218
|
+
cleanup(): Promise<void>;
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* First-class HTTP client for seeding and tearing down test data via API/test-control
|
|
1222
|
+
* endpoints inside Spana flows and lazy fixtures (far faster than UI setup).
|
|
1223
|
+
*/
|
|
1224
|
+
declare function createApiClient(options: ApiClientOptions): ApiClient;
|
|
1225
|
+
/**
|
|
1226
|
+
* Convenience lazy fixture builder for `createFlowWithFixtures`:
|
|
1227
|
+
* provides a fresh `ApiClient` to each flow and automatically executes all
|
|
1228
|
+
* `api.onCleanup(...)` hooks in LIFO order even when the flow throws.
|
|
1229
|
+
*/
|
|
1230
|
+
declare function createApiFixture<Deps extends Record<string, unknown> = Record<string, never>, T extends string = string, R extends string = string>(options: ApiClientOptions | ((ctx: FlowContext<T, R> & Deps) => ApiClientOptions)): FixtureFn<ApiClient, Deps, T, R>;
|
|
1231
|
+
interface PersonaDefinition<T extends string = string, R extends string = string> {
|
|
1232
|
+
name: string;
|
|
1233
|
+
/** Sign in once (via API, virtual passkey, or UI) and return storage entries or a saved storageStatePath. */
|
|
1234
|
+
signIn: (ctx: FlowContext<T, R>) => Promise<{
|
|
1235
|
+
storage?: DomStorageEntries;
|
|
1236
|
+
storageStatePath?: string;
|
|
1237
|
+
} | void>;
|
|
1238
|
+
/** Optional cache key discriminator (e.g. base URL or tenant ID). */
|
|
1239
|
+
cacheKey?: string;
|
|
1240
|
+
/** Optional route to navigate to after restoring cached auth state. */
|
|
1241
|
+
navigateTo?: R;
|
|
1242
|
+
}
|
|
1243
|
+
/** Define a reusable authenticated persona for `PersonaAuthCache`. */
|
|
1244
|
+
declare function definePersona<T extends string = string, R extends string = string>(name: string, config: Omit<PersonaDefinition<T, R>, "name">): PersonaDefinition<T, R>;
|
|
1245
|
+
interface CachedPersonaState {
|
|
1246
|
+
storage?: DomStorageEntries;
|
|
1247
|
+
storageStatePath?: string;
|
|
1248
|
+
cachedAt: number;
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* In-memory per-persona auth state cache (single-flight safe across parallel workers).
|
|
1252
|
+
* Signs a persona in ONCE (including passkey / WebAuthn flows), caches its auth state,
|
|
1253
|
+
* and restores it in milliseconds across all remaining flows.
|
|
1254
|
+
*/
|
|
1255
|
+
declare class PersonaAuthCache {
|
|
1256
|
+
private readonly cache;
|
|
1257
|
+
private readonly inflight;
|
|
1258
|
+
private keyFor;
|
|
1259
|
+
get(name: string, cacheKey?: string): CachedPersonaState | undefined;
|
|
1260
|
+
invalidate(name?: string, cacheKey?: string): void;
|
|
1261
|
+
/**
|
|
1262
|
+
* Ensure `persona` is authenticated in `ctx`. On cache miss, executes `persona.signIn(ctx)`
|
|
1263
|
+
* once (coalescing concurrent callers); on cache hit, restores cookies/storageState directly.
|
|
1264
|
+
*/
|
|
1265
|
+
authenticate<T extends string = string, R extends string = string>(persona: PersonaDefinition<T, R>, ctx: FlowContext<T, R>): Promise<CachedPersonaState>;
|
|
1266
|
+
}
|
|
1094
1267
|
|
|
1095
1268
|
/** A deterministic action recorded from an `agent.act(goal)` execution. */
|
|
1096
1269
|
type RecordedAction = {
|
|
@@ -1217,6 +1390,27 @@ declare class ReplaySession {
|
|
|
1217
1390
|
getSummary(): ReplayCacheSummary;
|
|
1218
1391
|
}
|
|
1219
1392
|
|
|
1393
|
+
interface NativePngCompareResult {
|
|
1394
|
+
match: boolean;
|
|
1395
|
+
sizeMismatch: boolean;
|
|
1396
|
+
diffPixelCount: number;
|
|
1397
|
+
diffPixelRatio: number;
|
|
1398
|
+
diffImage?: Buffer;
|
|
1399
|
+
}
|
|
1400
|
+
interface NativeXmlRawNode {
|
|
1401
|
+
tagName: string;
|
|
1402
|
+
attrs: Record<string, string>;
|
|
1403
|
+
children: NativeXmlRawNode[];
|
|
1404
|
+
}
|
|
1405
|
+
/** Check whether Spana's native Rust accelerator (`libspana_native`) is loaded and active. */
|
|
1406
|
+
declare function isNativeAcceleratorActive(): boolean;
|
|
1407
|
+
/** Return the loaded native Rust library path, or `null` when running in pure-JS fallback mode. */
|
|
1408
|
+
declare function getNativeAcceleratorPath(): string | null;
|
|
1409
|
+
/** Accelerated Rust PNG diff (returns `null` if unavailable so caller falls back cleanly to JS). */
|
|
1410
|
+
declare function comparePngNative(expected: Buffer | Uint8Array, actual: Buffer | Uint8Array, threshold: number, maxDiffRatio: number, layoutTolerant: boolean): NativePngCompareResult | null;
|
|
1411
|
+
/** Accelerated Rust XML hierarchy tokenizer (returns `null` if unavailable so caller falls back to JS). */
|
|
1412
|
+
declare function tokenizeXmlNative(xml: string, wrapperTag: string): NativeXmlRawNode[] | null;
|
|
1413
|
+
|
|
1220
1414
|
/** MCP Tool definition advertised by `tools/list`. */
|
|
1221
1415
|
interface McpToolDefinition {
|
|
1222
1416
|
name: string;
|
|
@@ -1288,4 +1482,4 @@ declare class SpanaMcpServer {
|
|
|
1288
1482
|
runStdio(): Promise<void>;
|
|
1289
1483
|
}
|
|
1290
1484
|
|
|
1291
|
-
export { type AgentActExecutor, AndroidWebViewCdpChannel, type AndroidWebViewCdpOptions, AppConfig, AppleWebInspectorClient, type AppliedFilterReport, type ApplyFiltersResult, type Attachment, BrowserConsoleLog, BrowserJSError, BrowserMockResponse, BrowserName, BrowserRouteMatcher, type CacheWriteStatus, CdpDomChannel, type CdpDomChannelOptions, type ChangedFile, type CloudProvider, type CloudProviderHelper, type CreateFixturesOptions, type DecisionBatchJudge, type DecisionBatchJudgeResult, type DecisionFilterOptions, type DecisionModelJudge, DomChannel, DomClearStorageOptions, DomElementMatch, DomIdleOptions, DomStorageEntries, DomTargetInfo, DomWaitForSelectorOptions, ElectrobunAppConfig, type ElectrobunDriverOptions, type ElectrobunLaunchPlan, ElectrobunRenderer, type ElectronDriverOptions, Element, type ExtendedFlowConfig, ExtendedSelector, type FailureCategory, type FilterCandidate, type FilterContext, type FilterDecisionOutput, type FilterUsage, type FixtureDefinition, type FixtureFn, type FixtureMap, FlowConfig, FlowContext, FlowDefinition, type FlowError, type FlowResult, type GitChanges, type GitHubPrReporterOptions, type HostOS, type JsonRpcRequest, type JsonRpcResponse, type LightweightCdpDriverOptions, type LogprobDecisionJudgeOptions, type McpContentBlock, type McpToolDefinition, type McpToolResult, type NamedSetupDefinition, type OllamaDecisionJudgeOptions, type PathRule, type PathRuleFilterOptions, Platform, type PrelaunchedWebBrowser, PromiseApp, ProvConfig, type RecordedAction, type ReplayCacheEntry, type ReplayCacheMode, ReplayCacheStore, type ReplayCacheSummary, ReplaySession, type ReplaySessionOptions, type ReplayStepOutcome, type Reporter, type ResolvedElementResult, type RunSummary, SPANA_MCP_TOOLS, type ScenarioStepResult, Selector, SpanaBridgeChannel, type SpanaBridgeServerOptions, SpanaMcpServer, type SpanaMcpServerOptions, type StepResult, TARGET_CHANNEL_MATRIX, TapMode, type TargetChannel, type TargetDescriptor, type TargetEngine, type TargetShell, type TestFilter, type WarmDaemonRecord, type WebInspectorListingPage, WebKitInspectorChannel, type WebKitInspectorOptions, applyNamedSetup, applyTestFilters, buildFilterCandidates, buildFlowFileFromLines, buildReplayCacheKey, collectGitChanges, connectPlaywrightOverCDP, createAndroidWebViewCdpChannel, createCdpDomChannel, createCompositeDomChannel, createFlowWithFixtures, createGitHubPrReporter, createLogprobDecisionJudge, createOllamaDecisionJudge, createSpanaBridgeChannel, createWebKitInspectorChannel, decisionFilter, decodeWebInspectorFrames, defineSetup, domRectToScreenBounds, encodeWebInspectorPacket, ensureWarmBrowserDaemon, extractDestructuredParamNames, findSimulatorWebInspectorSocket, findWebViewFrame, formatFilterSummary, formatGitHubPrMarkdown, formatSelectorCode, formatTargetMatrixTable, getHealthyWarmDaemon, invalidateWebViewFrameCache, isOffscreenInViewport, launchPlaywrightBrowser, listWarmDaemons, makeElectrobunDriver, makeElectronDriver, makeLightweightCdpDriver, orderFlowsLongestFirst, parseAndroidWebViewSockets, parseWebInspectorXmlFrame, pathRuleFilter, probabilityFromTopLogprobs, replayRecordedAction, resolveElectrobunEngine, resolveElectrobunLaunchPlan, resolveElementAcrossChannels, resolveTargetDescriptor, speculativelyPrelaunchWebBrowser, stopAllWarmDaemons, stopWarmDaemon, updateWarmDaemonSession };
|
|
1485
|
+
export { type AgentActExecutor, AndroidWebViewCdpChannel, type AndroidWebViewCdpOptions, type ApiClient, type ApiClientOptions, type ApiRequestOptions, type ApiResponse, AppConfig, AppleWebInspectorClient, type AppliedFilterReport, type ApplyFiltersResult, type Attachment, BrowserConsoleLog, BrowserJSError, BrowserMockResponse, BrowserName, BrowserRouteMatcher, type CacheWriteStatus, type CachedPersonaState, CdpDomChannel, type CdpDomChannelOptions, type ChangedFile, type CloudProvider, type CloudProviderHelper, type CreateFixturesOptions, type DecisionBatchJudge, type DecisionBatchJudgeResult, type DecisionFilterOptions, type DecisionModelJudge, type DeterministicImpactFilterOptions, type DirectCdpBrowserHandle, type DirectCdpBrowserLaunchOptions, DomChannel, DomClearStorageOptions, DomElementMatch, DomFillOptions, DomIdleOptions, DomStorageEntries, DomTargetInfo, DomWaitForHiddenOptions, DomWaitForMatchOptions, DomWaitForMatchResult, DomWaitForSelectorOptions, ElectrobunAppConfig, type ElectrobunDriverOptions, type ElectrobunLaunchPlan, ElectrobunRenderer, type ElectronDriverOptions, Element, type ExtendedFlowConfig, ExtendedSelector, type FailureCategory, type FilterCandidate, type FilterContext, type FilterDecisionOutput, type FilterUsage, type FixtureDefinition, type FixtureFn, type FixtureMap, FlowConfig, FlowContext, FlowDefinition, type FlowError, type FlowResult, type GitChanges, type GitHubPrReporterOptions, type HostOS, type JsonRpcRequest, type JsonRpcResponse, type LightweightCdpDriverOptions, type LogprobDecisionJudgeOptions, type McpContentBlock, type McpToolDefinition, type McpToolResult, type NamedSetupDefinition, type NativePngCompareResult, type NativeXmlRawNode, type OllamaDecisionJudgeOptions, type PathRule, type PathRuleFilterOptions, PersonaAuthCache, type PersonaDefinition, Platform, type PrelaunchedWebBrowser, PromiseApp, ProvConfig, type RecordedAction, type ReplayCacheEntry, type ReplayCacheMode, ReplayCacheStore, type ReplayCacheSummary, ReplaySession, type ReplaySessionOptions, type ReplayStepOutcome, type Reporter, type ResolvedElementResult, type RunSummary, SPANA_MCP_TOOLS, type ScenarioStepResult, Selector, SpanaBridgeChannel, type SpanaBridgeServerOptions, SpanaMcpServer, type SpanaMcpServerOptions, type StepResult, TARGET_CHANNEL_MATRIX, TapMode, type TargetChannel, type TargetDescriptor, type TargetEngine, type TargetShell, type TestFilter, VirtualAuthenticatorOptions, type WarmDaemonRecord, type WebInspectorListingPage, WebKitInspectorChannel, type WebKitInspectorOptions, applyNamedSetup, applyTestFilters, buildFilterCandidates, buildFlowFileFromLines, buildReplayCacheKey, collectGitChanges, comparePngNative, connectPlaywrightOverCDP, connectPlaywrightOverWS, createAndroidWebViewCdpChannel, createApiClient, createApiFixture, createCdpDomChannel, createCompositeDomChannel, createFlowWithFixtures, createGitHubPrReporter, createLogprobDecisionJudge, createOllamaDecisionJudge, createSpanaBridgeChannel, createWebKitInspectorChannel, decisionFilter, decodeWebInspectorFrames, definePersona, defineSetup, deterministicImpactFilter, domRectToScreenBounds, encodeWebInspectorPacket, ensureWarmBrowserDaemon, extractDestructuredParamNames, findSimulatorWebInspectorSocket, findWebViewFrame, formatFilterSummary, formatGitHubPrMarkdown, formatSelectorCode, formatTargetMatrixTable, getHealthyWarmDaemon, getNativeAcceleratorPath, invalidateWebViewFrameCache, isNativeAcceleratorActive, isOffscreenInViewport, launchDirectCdpBrowser, launchPlaywrightBrowser, listWarmDaemons, makeElectrobunDriver, makeElectronDriver, makeLightweightCdpDriver, orderFlowsLongestFirst, parseAndroidWebViewSockets, parseWebInspectorXmlFrame, pathRuleFilter, probabilityFromTopLogprobs, replayRecordedAction, resolveElectrobunEngine, resolveElectrobunLaunchPlan, resolveElementAcrossChannels, resolveTargetDescriptor, speculativelyPrelaunchWebBrowser, stopAllWarmDaemons, stopWarmDaemon, tokenizeXmlNative, updateWarmDaemonSession };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
+
launchDirectCdpBrowser,
|
|
2
3
|
makeLightweightCdpDriver,
|
|
3
4
|
orderFlowsLongestFirst,
|
|
4
5
|
speculativelyPrelaunchWebBrowser
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-KEUZLBQS.js";
|
|
6
7
|
import {
|
|
7
8
|
SPANA_MCP_TOOLS,
|
|
8
9
|
SpanaMcpServer,
|
|
9
10
|
buildFlowFileFromLines,
|
|
10
11
|
formatSelectorCode
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-C4E4XULT.js";
|
|
12
13
|
import {
|
|
13
14
|
defineConfig
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-KBRLIQRA.js";
|
|
15
16
|
import "./chunk-X2TJP7LB.js";
|
|
16
17
|
import {
|
|
17
18
|
createGitHubPrReporter,
|
|
@@ -24,12 +25,14 @@ import {
|
|
|
24
25
|
createLogprobDecisionJudge,
|
|
25
26
|
createOllamaDecisionJudge,
|
|
26
27
|
decisionFilter,
|
|
28
|
+
deterministicImpactFilter,
|
|
27
29
|
formatFilterSummary,
|
|
28
30
|
pathRuleFilter,
|
|
29
31
|
probabilityFromTopLogprobs
|
|
30
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-3SH5JQF7.js";
|
|
31
33
|
import {
|
|
32
34
|
connectPlaywrightOverCDP,
|
|
35
|
+
connectPlaywrightOverWS,
|
|
33
36
|
domRectToScreenBounds,
|
|
34
37
|
ensureWarmBrowserDaemon,
|
|
35
38
|
findWebViewFrame,
|
|
@@ -41,7 +44,7 @@ import {
|
|
|
41
44
|
makeElectronDriver,
|
|
42
45
|
resolveElementAcrossChannels,
|
|
43
46
|
systemUI
|
|
44
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-PWUJT5HE.js";
|
|
45
48
|
import {
|
|
46
49
|
AndroidWebViewCdpChannel,
|
|
47
50
|
AppleWebInspectorClient,
|
|
@@ -49,6 +52,9 @@ import {
|
|
|
49
52
|
SpanaBridgeChannel,
|
|
50
53
|
TARGET_CHANNEL_MATRIX,
|
|
51
54
|
WebKitInspectorChannel,
|
|
55
|
+
buildDomFillScript,
|
|
56
|
+
buildDomWaitForHiddenScript,
|
|
57
|
+
buildDomWaitForMatchScript,
|
|
52
58
|
buildDomWaitForSelectorScript,
|
|
53
59
|
createAndroidWebViewCdpChannel,
|
|
54
60
|
createCdpDomChannel,
|
|
@@ -65,7 +71,7 @@ import {
|
|
|
65
71
|
resolveElectrobunEngine,
|
|
66
72
|
resolveElectrobunLaunchPlan,
|
|
67
73
|
resolveTargetDescriptor
|
|
68
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-LCV673G3.js";
|
|
69
75
|
import "./chunk-HYSTRWYN.js";
|
|
70
76
|
import {
|
|
71
77
|
getHealthyWarmDaemon,
|
|
@@ -76,6 +82,12 @@ import {
|
|
|
76
82
|
} from "./chunk-DTNK54C2.js";
|
|
77
83
|
import "./chunk-S5JNNDXS.js";
|
|
78
84
|
import "./chunk-OBCFACUW.js";
|
|
85
|
+
import {
|
|
86
|
+
comparePngNative,
|
|
87
|
+
getNativeAcceleratorPath,
|
|
88
|
+
isNativeAcceleratorActive,
|
|
89
|
+
tokenizeXmlNative
|
|
90
|
+
} from "./chunk-4K3FZTSV.js";
|
|
79
91
|
import "./chunk-H27IBIGA.js";
|
|
80
92
|
import "./chunk-DGUM43GV.js";
|
|
81
93
|
|
|
@@ -333,6 +345,147 @@ function createFlowWithFixtures(options) {
|
|
|
333
345
|
}
|
|
334
346
|
return extendedFlow;
|
|
335
347
|
}
|
|
348
|
+
function createApiClient(options) {
|
|
349
|
+
const baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
350
|
+
const defaultHeaders = options.headers ?? {};
|
|
351
|
+
const fetchFn = options.fetchFn ?? fetch;
|
|
352
|
+
const cleanups = [];
|
|
353
|
+
const request = async (method, path, body, opts) => {
|
|
354
|
+
const cleanPath = path.startsWith("http://") || path.startsWith("https://") ? path : `${baseUrl}/${path.replace(/^\/+/, "")}`;
|
|
355
|
+
const url = new URL(cleanPath);
|
|
356
|
+
if (opts?.query) {
|
|
357
|
+
for (const [k, v] of Object.entries(opts.query)) {
|
|
358
|
+
if (v !== void 0) url.searchParams.set(k, String(v));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const headers = {
|
|
362
|
+
...defaultHeaders,
|
|
363
|
+
...body !== void 0 ? { "content-type": "application/json" } : {},
|
|
364
|
+
...opts?.headers
|
|
365
|
+
};
|
|
366
|
+
const res = await fetchFn(url.toString(), {
|
|
367
|
+
method,
|
|
368
|
+
headers,
|
|
369
|
+
...body !== void 0 ? { body: typeof body === "string" ? body : JSON.stringify(body) } : {},
|
|
370
|
+
...opts?.signal ? { signal: opts.signal } : {}
|
|
371
|
+
});
|
|
372
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
373
|
+
let data;
|
|
374
|
+
if (contentType.includes("application/json")) {
|
|
375
|
+
data = await res.json().catch(() => null);
|
|
376
|
+
} else {
|
|
377
|
+
const text = await res.text().catch(() => "");
|
|
378
|
+
try {
|
|
379
|
+
data = text ? JSON.parse(text) : text;
|
|
380
|
+
} catch {
|
|
381
|
+
data = text;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
status: res.status,
|
|
386
|
+
ok: res.ok,
|
|
387
|
+
headers: res.headers,
|
|
388
|
+
data
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
return {
|
|
392
|
+
get: (path, opts) => request("GET", path, void 0, opts),
|
|
393
|
+
post: (path, body, opts) => request("POST", path, body, opts),
|
|
394
|
+
put: (path, body, opts) => request("PUT", path, body, opts),
|
|
395
|
+
patch: (path, body, opts) => request("PATCH", path, body, opts),
|
|
396
|
+
delete: (path, opts) => request("DELETE", path, void 0, opts),
|
|
397
|
+
onCleanup: (fn) => {
|
|
398
|
+
cleanups.push(fn);
|
|
399
|
+
},
|
|
400
|
+
cleanup: async () => {
|
|
401
|
+
const pending = cleanups.splice(0, cleanups.length).toReversed();
|
|
402
|
+
const errors = [];
|
|
403
|
+
for (const fn of pending) {
|
|
404
|
+
try {
|
|
405
|
+
await fn();
|
|
406
|
+
} catch (err) {
|
|
407
|
+
errors.push(err);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (errors.length > 0) {
|
|
411
|
+
throw errors[0];
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function createApiFixture(options) {
|
|
417
|
+
return async (ctx, use) => {
|
|
418
|
+
const resolved = typeof options === "function" ? options(ctx) : options;
|
|
419
|
+
const api = createApiClient(resolved);
|
|
420
|
+
try {
|
|
421
|
+
await use(api);
|
|
422
|
+
} finally {
|
|
423
|
+
await api.cleanup();
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function definePersona(name, config) {
|
|
428
|
+
return { name, ...config };
|
|
429
|
+
}
|
|
430
|
+
var PersonaAuthCache = class {
|
|
431
|
+
cache = /* @__PURE__ */ new Map();
|
|
432
|
+
inflight = /* @__PURE__ */ new Map();
|
|
433
|
+
keyFor(persona) {
|
|
434
|
+
return `${persona.name}::${persona.cacheKey ?? "default"}`;
|
|
435
|
+
}
|
|
436
|
+
get(name, cacheKey = "default") {
|
|
437
|
+
return this.cache.get(`${name}::${cacheKey}`);
|
|
438
|
+
}
|
|
439
|
+
invalidate(name, cacheKey = "default") {
|
|
440
|
+
if (!name) {
|
|
441
|
+
this.cache.clear();
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
this.cache.delete(`${name}::${cacheKey}`);
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Ensure `persona` is authenticated in `ctx`. On cache miss, executes `persona.signIn(ctx)`
|
|
448
|
+
* once (coalescing concurrent callers); on cache hit, restores cookies/storageState directly.
|
|
449
|
+
*/
|
|
450
|
+
async authenticate(persona, ctx) {
|
|
451
|
+
const key = this.keyFor(persona);
|
|
452
|
+
let state = this.cache.get(key);
|
|
453
|
+
let wasMiss = false;
|
|
454
|
+
if (!state) {
|
|
455
|
+
wasMiss = true;
|
|
456
|
+
let pending = this.inflight.get(key);
|
|
457
|
+
if (!pending) {
|
|
458
|
+
pending = (async () => {
|
|
459
|
+
const produced = await persona.signIn(ctx) ?? {};
|
|
460
|
+
const entry = {
|
|
461
|
+
storage: produced.storage,
|
|
462
|
+
storageStatePath: produced.storageStatePath,
|
|
463
|
+
cachedAt: Date.now()
|
|
464
|
+
};
|
|
465
|
+
this.cache.set(key, entry);
|
|
466
|
+
return entry;
|
|
467
|
+
})().finally(() => {
|
|
468
|
+
this.inflight.delete(key);
|
|
469
|
+
});
|
|
470
|
+
this.inflight.set(key, pending);
|
|
471
|
+
}
|
|
472
|
+
state = await pending;
|
|
473
|
+
}
|
|
474
|
+
const app = ctx.app;
|
|
475
|
+
if (!wasMiss) {
|
|
476
|
+
if (state.storageStatePath && ctx.platform === "web") {
|
|
477
|
+
await app.loadAuthState(state.storageStatePath);
|
|
478
|
+
}
|
|
479
|
+
if (state.storage) {
|
|
480
|
+
await app.setStorage(state.storage);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (persona.navigateTo) {
|
|
484
|
+
await app.openLink(persona.navigateTo);
|
|
485
|
+
}
|
|
486
|
+
return state;
|
|
487
|
+
}
|
|
488
|
+
};
|
|
336
489
|
|
|
337
490
|
// src/core/replay-cache.ts
|
|
338
491
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
@@ -563,6 +716,7 @@ export {
|
|
|
563
716
|
AndroidWebViewCdpChannel,
|
|
564
717
|
AppleWebInspectorClient,
|
|
565
718
|
CdpDomChannel,
|
|
719
|
+
PersonaAuthCache,
|
|
566
720
|
ReplayCacheStore,
|
|
567
721
|
ReplaySession,
|
|
568
722
|
SPANA_MCP_TOOLS,
|
|
@@ -572,13 +726,20 @@ export {
|
|
|
572
726
|
WebKitInspectorChannel,
|
|
573
727
|
applyNamedSetup,
|
|
574
728
|
applyTestFilters,
|
|
729
|
+
buildDomFillScript,
|
|
730
|
+
buildDomWaitForHiddenScript,
|
|
731
|
+
buildDomWaitForMatchScript,
|
|
575
732
|
buildDomWaitForSelectorScript,
|
|
576
733
|
buildFilterCandidates,
|
|
577
734
|
buildFlowFileFromLines,
|
|
578
735
|
buildReplayCacheKey,
|
|
579
736
|
collectGitChanges,
|
|
737
|
+
comparePngNative,
|
|
580
738
|
connectPlaywrightOverCDP,
|
|
739
|
+
connectPlaywrightOverWS,
|
|
581
740
|
createAndroidWebViewCdpChannel,
|
|
741
|
+
createApiClient,
|
|
742
|
+
createApiFixture,
|
|
582
743
|
createCdpDomChannel,
|
|
583
744
|
createCompositeDomChannel,
|
|
584
745
|
createFlowWithFixtures,
|
|
@@ -590,7 +751,9 @@ export {
|
|
|
590
751
|
decisionFilter,
|
|
591
752
|
decodeWebInspectorFrames,
|
|
592
753
|
defineConfig,
|
|
754
|
+
definePersona,
|
|
593
755
|
defineSetup,
|
|
756
|
+
deterministicImpactFilter,
|
|
594
757
|
domRectToScreenBounds,
|
|
595
758
|
encodeWebInspectorPacket,
|
|
596
759
|
ensureWarmBrowserDaemon,
|
|
@@ -603,10 +766,13 @@ export {
|
|
|
603
766
|
formatSelectorCode,
|
|
604
767
|
formatTargetMatrixTable,
|
|
605
768
|
getHealthyWarmDaemon,
|
|
769
|
+
getNativeAcceleratorPath,
|
|
606
770
|
invalidateWebViewFrameCache,
|
|
771
|
+
isNativeAcceleratorActive,
|
|
607
772
|
isOffscreenInViewport,
|
|
608
773
|
isSystemUISelector,
|
|
609
774
|
isTestIDSelector,
|
|
775
|
+
launchDirectCdpBrowser,
|
|
610
776
|
launchPlaywrightBrowser,
|
|
611
777
|
listWarmDaemons,
|
|
612
778
|
makeElectrobunDriver,
|
|
@@ -626,6 +792,7 @@ export {
|
|
|
626
792
|
stopAllWarmDaemons,
|
|
627
793
|
stopWarmDaemon,
|
|
628
794
|
systemUI,
|
|
795
|
+
tokenizeXmlNative,
|
|
629
796
|
updateWarmDaemonSession
|
|
630
797
|
};
|
|
631
798
|
//# sourceMappingURL=index.js.map
|