import { $ as Runtime, B as EngineEvent, Et as Credential, Ft as ManagementApiClient, H as StreamEvent, It as ManagementApiClientConfig, Lt as TokenStorage, Mt as StoredSessions, N as PresentedResult, Ot as CredentialManager, Pt as CredentialRefresher, Tt as ActiveCredential, ct as SpawnRequest, dt as PackageManagerId, et as TelemetryPayload, i as MountedTree, jt as Session, mt as PackageManagerRunner, n as CommandFamily, nt as RunSummary, ot as SpawnChild, q as Host, rt as ChildResult, t as TelemetryDeclaration, wt as ActiveAccessTokenOptions } from "./report-DR2h7YIG.js"; //#region src/in-memory-credential-manager.d.ts /** A stored session with its credential material — what the manager * holds, seeded in and read back out. Mirrors the state file's * records. */ interface SessionRecord { readonly workspaceId: string; readonly workspaceName: string | undefined; readonly credential: Credential; } interface InMemoryCredentialManagerSeed { /** Stored sessions, mirroring the state file's records. */ readonly sessions?: readonly SessionRecord[]; /** The stored selection — the workspace whose session is used where * a session is needed. */ readonly selectedWorkspaceId?: string; /** Convenience seed: runs createSession's real claims derivation. * The token must be a JWT with `workspace_id` (use mintTestJwt). */ readonly credential?: Credential; /** The credential PRISMA_SERVICE_TOKEN supplies. Its token may carry * no `workspace_id` claim, and it may carry a refresh token. */ readonly environmentCredential?: Credential; /** OAuth exchange used when delegated credentials need rotation. */ readonly refreshCredential?: CredentialRefresher; } /** The whole stored state, readable back after a run. */ interface InMemoryCredentialManagerState { readonly sessions: readonly SessionRecord[]; readonly selectedWorkspaceId: string | undefined; } /** Mints an unsigned JWT whose payload is exactly `claims` — the * harness's claim source (`sub`, `workspace_id`, `exp`, `email`). */ declare function mintTestJwt(claims: Readonly>): string; /** * The harness's mutable in-memory CredentialManager: the same * interface commands see, with the whole stored state readable back * after a run, and the design's process pinning — which credential * this process acts as is fixed at the first activeCredential() read, * while the material behind it is re-read on every call. No * persistence, no locking — those belong to the real manager and its * own tests. */ declare class InMemoryCredentialManager implements CredentialManager { #private; private storedSessions; private selection; private readonly environmentCredential; private readonly refreshCredential; private pin; private activeStorage; constructor(seed: InMemoryCredentialManagerSeed); state(): InMemoryCredentialManagerState; /** Applies a write as ANOTHER process would: the stored state * changes, but this process's pinned decision does not move. */ overwriteStoredState(state: { readonly sessions?: readonly SessionRecord[]; readonly selectedWorkspaceId?: string | undefined; }): void; activeCredential(): Promise; sessions(): Promise; createSession(credential: Credential, workspaceId: string): Promise; selectSession(workspaceId: string): Promise; endSession(workspaceId: string): Promise; endAllSessions(): Promise; activeCredentialStorage(): Promise; /** The delegated path's read: the active credential's access token, * fresh on every call, never the refresh token. Null when there is * no active credential to read — storage exists only once * activeCredential() has returned non-null. */ activeAccessToken(options: ActiveAccessTokenOptions): Promise; private buildActiveStorage; /** The file-backed storage's analogue: the record is read afresh on * every call, never snapshotted. */ private storedSessionStorage; private removeRecord; private resolvePin; /** The selection the manager will admit to: one that names a stored * session, or none. A dangling selection never escapes. */ private resolvedSelection; private credentialForPin; private requireEnvironmentCredential; private applyCreateSession; } //#endregion //#region src/testing.d.ts /** * What a scripted fake child does. `nextKill` resolves with each signal * the engine delivers, so a script can model a child that ignores * SIGTERM and only dies on SIGKILL. */ type ScriptedChildProgram = (request: SpawnRequest, child: { readonly nextKill: () => Promise<"SIGTERM" | "SIGKILL">; }) => ChildResult | Promise; /** One ctx.spawn call, as the harness saw it. */ interface SpawnRecord { readonly command: string; readonly args: readonly string[]; readonly cwd: string; readonly output: SpawnRequest["output"]; /** Environment KEYS only. Values are never recorded: a fixture file * must not be able to carry token material. */ readonly envKeys: readonly string[]; /** The signals the engine delivered to the child, in order. */ readonly kills: readonly ("SIGTERM" | "SIGKILL")[]; } interface TestCli { /** * The mutable in-memory credential manager backing the runs — the * whole stored state (sessions with their credentials, the * selection) is readable back after a run via state(). */ readonly credentialManager: InMemoryCredentialManager; run(argv: readonly string[], opts?: { readonly stdin?: string; /** * Scripted prompt answers, consumed in order; a run that prompts * past the script fails the test. */ readonly answers?: ReadonlyArray; /** * Abort the run (session tests): its firing is delivered to the * engine as a signal (SIGTERM when the reason is 'SIGTERM', * SIGINT otherwise). */ readonly abort?: AbortSignal; /** Live event tap, for asserting mid-session behavior. */ readonly onEvent?: (event: EngineEvent) => void; /** Settlement tap: receives the RunSummary the engine fires * after settlement (once, mounted runs only). */ readonly onSettled?: (summary: RunSummary) => void; readonly cwd?: string; readonly isTty?: { stdin?: boolean; stdout?: boolean; stderr?: boolean; }; /** Terminal width, as the stream would report it. Absent means * not a terminal, which is what ui.width reads as unbounded. */ readonly columns?: { stderr?: number; }; readonly env?: Readonly>; /** Overrides the CLI-level seed, so one harness can assert both * sides of the CI branch. Absent leaves the engine to detect CI * from `env`, which is how a test asserts detection itself. */ readonly isCI?: boolean; }): Promise<{ readonly exitCode: number; readonly stdout: string; readonly stderr: string; /** Parsed stream (events + the terminal result) when json mode. */ readonly json: readonly StreamEvent[]; /** Every EngineEvent the handler emitted, for semantic assertions. */ readonly events: readonly EngineEvent[]; /** * The PresentedResult the handler returned, for semantic assertions * without byte-scraping; undefined when the run never presented. */ readonly presented: PresentedResult | undefined; /** Every ctx.spawn the run made, in order. */ readonly spawns: readonly SpawnRecord[]; /** Every telemetry payload the run handed to the seam, in order. * Empty when the CLI declared no telemetry, when gating disabled * the run, or when the harness wired no seam. */ readonly telemetry: readonly TelemetryPayload[]; }>; } /** * The test harness: the same engine over in-memory streams. The * harness hands the engine no real process access at all — its exit * proxy throws and its streams are in-memory — which is how "the engine * never touches process globals and writes only to provided streams" is * proven by construction. */ declare function createTestCli(spec: { readonly commandFamilies?: readonly CommandFamily[]; readonly commands: MountedTree; readonly groups?: Readonly>; /** Seeds the sections the config file would have held. The engine * asks for them only when the command declares a config section, and * checks them as it would a real file's: a section name no mounted * command declares fails the run. */ readonly config?: Readonly>; /** Replaces the loader outright — to assert what --config asked for, * to return file-level diagnostics, or to prove a run never reads * the config at all. Wins over `config` when both are given. */ readonly loadConfig?: Runtime["loadConfig"]; /** Convenience manager seed: createSession runs its real claims * derivation on this credential (mint the token with mintTestJwt). */ readonly credential?: Credential; /** Stored sessions, mirroring the state file's records. */ readonly sessions?: readonly SessionRecord[]; /** The stored selection. */ readonly selectedWorkspaceId?: string; /** The credential PRISMA_SERVICE_TOKEN supplies. Its access token is * also exported to each run's env as PRISMA_SERVICE_TOKEN * (overridable per run). */ readonly environmentCredential?: Credential; /** The SDK client construction config; defaults point every * endpoint at test.invalid hosts. */ readonly managementApiClientConfig?: ManagementApiClientConfig; /** OAuth exchange behind delegated-credential preparation. */ readonly refreshCredential?: CredentialRefresher; /** baseUrl defaults to "https://test.invalid"; when `client` is * supplied, ctx.api IS that object. */ readonly managementApi?: { readonly baseUrl?: string; readonly client?: ManagementApiClient; }; /** Overrides detection, the same way a host's Runtime does; absent * means the engine detects from the run's cwd. */ readonly packageManager?: PackageManagerId; /** What the run reports itself as running on; defaults to a fixed * host so a bug-report payload asserts the same on every machine. */ readonly host?: Host; /** The scripted stand-in for the shipped bin's spawner: assert the * composed file/args/cwd, script exit codes and stderr, drive * onOutput. Absent means this host has no runner, which is the * failure every package operation then takes. */ readonly packageManagerRunner?: PackageManagerRunner; /** Fixed clock for deterministic stream timestamps; a clock that * advances also drives prompt.browserWait's timeout. */ readonly now?: () => Date; /** The browser opener behind ctx.openUrl and prompt.browserWait. * Defaults to one that succeeds without doing anything; pass a spy * to assert what was opened, or a thrower to exercise the * could-not-open path. */ readonly openUrl?: (url: string) => Promise | void; /** Waiting is instant under test whatever this does; pass a spy to * assert the interval a poll loop asked for. */ readonly delay?: (ms: number, signal: AbortSignal) => Promise; /** The spawn adapter behind ctx.spawn. Defaults to the scripted fake; * the real-child tests pass a node:child_process adapter, which is * how the engine package itself never imports one. */ readonly spawn?: SpawnChild; /** Scripts the built-in fake child. Defaults to one that exits 0. */ readonly spawnScript?: ScriptedChildProgram; /** Declares telemetry, exactly as `createCli` does. Absent means this * CLI reports nothing, which is what every test that says nothing * about telemetry gets. */ readonly telemetry?: TelemetryDeclaration; /** The seam behind Runtime.spawnTelemetry. Payloads are recorded on * the run result either way; pass a spy to assert ordering, a * thrower to exercise failure isolation, or `null` to model a host * that wires no seam at all. */ readonly telemetrySpawner?: ((payload: TelemetryPayload) => void) | null; /** Forces the CI answer for every run; `run({ isCI })` overrides it. * Absent leaves the engine to detect CI from the run's `env`. */ readonly isCI?: boolean; }): TestCli; //#endregion export { InMemoryCredentialManager, type InMemoryCredentialManagerSeed, type InMemoryCredentialManagerState, type ScriptedChildProgram, type SessionRecord, type SpawnRecord, type TestCli, createTestCli, mintTestJwt };