1+ /**
2+ * Remote-tab operation harness for Browser server-context tests.
3+ */
14import { vi } from "vitest" ;
25import { withBrowserFetchPreconnect } from "../../test-fetch.js" ;
36import { resolveCdpControlPolicy } from "./cdp-reachability-policy.js" ;
@@ -6,8 +9,10 @@ import { createProfileSelectionOps } from "./server-context.selection.js";
69import { createProfileTabOps } from "./server-context.tab-ops.js" ;
710import type { BrowserServerState , ProfileRuntimeState } from "./server-context.types.js" ;
811
12+ /** Original global fetch restored between remote-tab harness tests. */
913export const originalFetch = globalThis . fetch ;
1014
15+ /** Creates Browser server state for remote or local profile tab tests. */
1116export function makeState (
1217 profile : "remote" | "openclaw" ,
1318) : BrowserServerState & { profiles : Map < string , { lastTargetId ?: string | null } > } {
@@ -95,6 +100,7 @@ function resolveProfileForTest(
95100 } ;
96101}
97102
103+ /** Creates a minimal Browser route context for profile operation tests. */
98104export function createTestBrowserRouteContext ( opts : { getState : ( ) => BrowserServerState } ) {
99105 const forProfile = ( profileName ?: string ) => {
100106 const state = opts . getState ( ) ;
@@ -125,6 +131,7 @@ export function createTestBrowserRouteContext(opts: { getState: () => BrowserSer
125131 return { forProfile } ;
126132}
127133
134+ /** Creates a remote profile context with a preconnected fetch mock. */
128135export function createRemoteRouteHarness ( fetchMock ?: ( url : unknown ) => Promise < Response > ) {
129136 const activeFetchMock = fetchMock ?? makeUnexpectedFetchMock ( ) ;
130137 global . fetch = withBrowserFetchPreconnect ( activeFetchMock ) ;
@@ -133,6 +140,7 @@ export function createRemoteRouteHarness(fetchMock?: (url: unknown) => Promise<R
133140 return { state, remote : ctx . forProfile ( "remote" ) , fetchMock : activeFetchMock } ;
134141}
135142
143+ /** Returns a page lister that yields prepared responses in order. */
136144export function createSequentialPageLister < T > ( responses : T [ ] ) {
137145 return async ( ) => {
138146 const next = responses . shift ( ) ;
@@ -151,6 +159,7 @@ type JsonListEntry = {
151159 type : "page" ;
152160} ;
153161
162+ /** Creates a /json/list fetch mock with static entries. */
154163export function createJsonListFetchMock ( entries : JsonListEntry [ ] ) {
155164 return async ( url : unknown ) => {
156165 const u = String ( url ) ;
@@ -174,6 +183,7 @@ function makeManagedTab(id: string, ordinal: number): JsonListEntry {
174183 } ;
175184}
176185
186+ /** Creates eight old managed tabs plus one new tab for cleanup-limit tests. */
177187export function makeManagedTabsWithNew ( params ?: { newFirst ?: boolean } ) : JsonListEntry [ ] {
178188 const oldTabs = Array . from ( { length : 8 } , ( _ , index ) =>
179189 makeManagedTab ( `OLD${ index + 1 } ` , index + 1 ) ,
0 commit comments