@prisma/cli-engine 0.0.2 → 0.0.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.
@@ -154,6 +154,11 @@ interface ManagementApiClientConfig {
154
154
  }
155
155
  //#endregion
156
156
  //#region src/credential-manager.d.ts
157
+ /** The environment variables that supply a credential to a process: a
158
+ * service token, plus the workspace it acts in when the token's own
159
+ * claims name none. EnvironmentCredentialManager reads the pair; the
160
+ * spawn path writes it into a child's environment. */
161
+ declare const SERVICE_TOKEN_ENV_VAR = "PRISMA_SERVICE_TOKEN";
157
162
  /**
158
163
  * The proof material. Seen by the login flow (which mints it),
159
164
  * createSession (which stores it), and the engine (which authenticates
@@ -267,8 +272,22 @@ interface CredentialManager {
267
272
  * already ruled there is one credential per process, and an
268
273
  * environment credential may have no workspace id to key on. Only
269
274
  * valid once `activeCredential()` has returned non-null.
275
+ *
276
+ * The engine forwards the storage into SDK client config and never
277
+ * calls its methods itself — no exceptions. The engine's own read of
278
+ * token material goes through `activeAccessToken()`.
270
279
  */
271
280
  activeCredentialStorage(): Promise<TokenStorage$1>;
281
+ /**
282
+ * ENGINE-FACING. The active credential's ACCESS token, read fresh on
283
+ * every call, for handing to a child process that authenticates as
284
+ * this process does. Never the refresh token: the child gets a
285
+ * snapshot it cannot refresh. Null when the material is gone (the
286
+ * session ended). Single consumer: ctx.spawn's credential injection
287
+ * (credential-manager-design.md §11.5) — the read builds no second
288
+ * API client, so the one-client-per-process invariant holds.
289
+ */
290
+ activeAccessToken(): Promise<string | null>;
272
291
  }
273
292
  //#endregion
274
293
  //#region src/events.d.ts
@@ -459,6 +478,72 @@ interface Ui {
459
478
  readonly code: (text: string) => string;
460
479
  }
461
480
  //#endregion
481
+ //#region src/spawn.d.ts
482
+ /** A fully composed child invocation. `env` is the child's COMPLETE
483
+ * environment: the engine has already merged the invocation
484
+ * environment, the handler's additions, and the credential variables. */
485
+ interface SpawnRequest {
486
+ readonly command: string;
487
+ readonly args: readonly string[];
488
+ readonly cwd: string;
489
+ readonly env: Readonly<Record<string, string | undefined>>;
490
+ }
491
+ /** How a child ended. A signal-killed child carries `signal` and a null
492
+ * `exitCode`; handlers branch on `signal` first — a signal-killed child
493
+ * is an abort, not a failure. */
494
+ interface ChildResult {
495
+ readonly exitCode: number | null;
496
+ readonly signal: string | null;
497
+ }
498
+ /** The live child an adapter returns. */
499
+ interface SpawnedChild {
500
+ /** Resolves when the child ends. Rejects when it could not be
501
+ * launched at all; the engine phrases that as CLI.SPAWN_FAILED. */
502
+ readonly ended: Promise<ChildResult>;
503
+ readonly kill: (signal: "SIGTERM" | "SIGKILL") => void;
504
+ }
505
+ /**
506
+ * The Runtime seam. The adapter starts the child with INHERITED stdio,
507
+ * in the caller's own process group (POSIX) / console (Windows) — no
508
+ * `detached`, no new console — so the terminal delivers Ctrl-C to the
509
+ * child natively.
510
+ */
511
+ type SpawnChild = (request: SpawnRequest) => SpawnedChild;
512
+ /** What a handler passes to ctx.spawn. */
513
+ interface SpawnOptions {
514
+ readonly command: string;
515
+ readonly args?: readonly string[];
516
+ /** Defaults to ctx.cwd. */
517
+ readonly cwd?: string;
518
+ /** Added to, and overriding, the invocation environment. The engine's
519
+ * credential variables are applied last and cannot be overridden. */
520
+ readonly env?: Readonly<Record<string, string | undefined>>;
521
+ }
522
+ declare const CHILD_STATUS: unique symbol;
523
+ /**
524
+ * The sanctioned settlement outcome for "exit with the child's status
525
+ * verbatim": no envelope, the same settlement bypass server commands
526
+ * use. Built exclusively by exitWithChildStatus, and only settled by a
527
+ * command that declares maySpawn, from a child result the engine
528
+ * itself produced. `nextActions` render to stderr before the process
529
+ * exits with the child's code.
530
+ */
531
+ interface ChildStatusSettlement {
532
+ readonly [CHILD_STATUS]: true;
533
+ readonly exitCode: number;
534
+ readonly nextActions: readonly NextAction[];
535
+ }
536
+ interface ExitWithChildStatusOptions {
537
+ /** Engine-styled guidance printed to stderr before the exit — a
538
+ * failed converge's reproduce hint. The envelope stays absent. */
539
+ readonly nextActions?: readonly NextAction[];
540
+ }
541
+ /** Settles the run with the status of the child `ctx.spawn` returned.
542
+ * A result the engine did not produce is a construction error at
543
+ * settlement: this is how a real child's status reaches the exit code,
544
+ * not how a handler picks one. */
545
+ declare function exitWithChildStatus(child: ChildResult, options?: ExitWithChildStatusOptions): ChildStatusSettlement;
546
+ //#endregion
462
547
  //#region src/context.d.ts
463
548
  /** The handler context — the whole world arrives as one argument. */
464
549
  interface CommandContext<TConfig = undefined, TCode extends number = never> {
@@ -490,6 +575,28 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
490
575
  * needs.credentials check uses).
491
576
  */
492
577
  readonly api: ManagementApiClient$1;
578
+ /**
579
+ * Hands the terminal to a child process and resolves when it ends.
580
+ * The child inherits stdio and runs in this process's own group
581
+ * (POSIX) or console (Windows), so Ctrl-C reaches it natively.
582
+ *
583
+ * While a child is live the engine neither aborts nor exits on a
584
+ * delivered signal: it records signals and replays them into its
585
+ * normal ladder once the child has ended, so the engine always
586
+ * outlives the child. SIGTERM, which has no native path to the child,
587
+ * is forwarded to it. A programmatic abort of ctx.signal terminates
588
+ * the child with SIGTERM, a grace period, then SIGKILL.
589
+ *
590
+ * ctx.report is buffered for the duration and flushed in order when
591
+ * the child ends; ctx.present during a live child, and a second
592
+ * concurrent ctx.spawn, are engine-internal errors. A launch failure
593
+ * (no such command) throws CLI.SPAWN_FAILED.
594
+ *
595
+ * Only commands declaring `maySpawn` may call it. Branch on `signal`
596
+ * before `exitCode`: a signal-killed child is an abort, not a
597
+ * failure.
598
+ */
599
+ readonly spawn: (options: SpawnOptions) => Promise<ChildResult>;
493
600
  /** The one way to emit while running. */
494
601
  readonly report: (event: EngineEvent) => void;
495
602
  /** Interactive input. */
@@ -508,6 +615,10 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
508
615
  * Fires on Ctrl-C/SIGTERM (engine-owned; a second signal force-exits
509
616
  * through the runtime's exit proxy). Session commands run until it
510
617
  * fires.
618
+ *
619
+ * Once it has fired the engine settles the run at 130/143 from its
620
+ * own record of the signal, whatever the handler goes on to return —
621
+ * so cleanup code never states an exit code of its own.
511
622
  */
512
623
  readonly signal: AbortSignal;
513
624
  /** Where the user invoked the CLI. Handlers never read process.cwd(). */
@@ -651,10 +762,15 @@ interface Runtime {
651
762
  */
652
763
  readonly onSignal: (cb: (signal: "SIGINT" | "SIGTERM") => void) => () => void;
653
764
  /**
654
- * Loaded config + file-level diagnostics; the shell builds this via
655
- * the unified loader. Tests hand in fixtures.
765
+ * Reads prisma.config.ts, on demand. The engine calls it only when
766
+ * the command it is about to run declares a config section, so a run
767
+ * that needs no config never touches the file. `configPath` is the
768
+ * file `--config` named: the loader resolves it against the runtime's
769
+ * cwd and reports its absence. Absent means look for prisma.config.ts
770
+ * in cwd, where absence is not an error. The bin wires the real disk
771
+ * loader; tests hand in fixtures.
656
772
  */
657
- readonly config: LoadedConfig;
773
+ readonly loadConfig: (configPath?: string) => Promise<LoadedConfig>;
658
774
  /**
659
775
  * The credential manager the bin wires. It is the only source of
660
776
  * the needs check, ctx.activeCredential, and ctx.api; absent means
@@ -676,6 +792,14 @@ interface Runtime {
676
792
  * announces the URL instead.
677
793
  */
678
794
  readonly openUrl?: (url: string) => Promise<void> | void;
795
+ /**
796
+ * Starts a child process with inherited stdio, wired by the bin (a
797
+ * node:child_process adapter) so the engine never imports it. Absent
798
+ * means this host cannot hand the terminal to a child: a maySpawn
799
+ * command is refused as an internal error before its needs check and
800
+ * handler run, so ctx.spawn is never reached.
801
+ */
802
+ readonly spawn?: SpawnChild;
679
803
  /** Management API endpoint config; the bin derives baseUrl from env. */
680
804
  readonly managementApi: {
681
805
  readonly baseUrl: string;
@@ -713,9 +837,19 @@ interface HostProcess {
713
837
  exit(code: number): never;
714
838
  }
715
839
  interface LoadedConfig {
840
+ /**
841
+ * The file this config came from, absolute: the one `--config` named,
842
+ * or prisma.config.ts in cwd. A loader that found no file still names
843
+ * the file it looked for — with no file there are no sections, and
844
+ * the engine reads the path only to name the file when it reports a
845
+ * top-level key that is not one of the CLI's sections.
846
+ */
847
+ readonly path: string;
716
848
  /**
717
849
  * Raw section values by name; validation happens per command via its
718
- * command family's section token.
850
+ * command family's section token. The engine, not the loader, checks
851
+ * these names against the sections the CLI declares, so the closed
852
+ * set holds whatever loader a host wires.
719
853
  */
720
854
  readonly sections: Readonly<Record<string, unknown>>;
721
855
  /**
@@ -775,8 +909,17 @@ interface NeedsSpec<TConfig> {
775
909
  * its error diagnostics, hand me the value as ctx.config.
776
910
  */
777
911
  readonly config?: ConfigSection<TConfig>;
778
- /** Fail early with the sign-in error when unauthenticated. */
779
- readonly credentials?: true;
912
+ /**
913
+ * Fail early with the sign-in error when unauthenticated. The
914
+ * `"child"` form (S3) additionally makes the engine compose the
915
+ * active credential into every child environment
916
+ * (PRISMA_SERVICE_TOKEN, PRISMA_WORKSPACE_ID) and refuse the run
917
+ * before the handler when that credential expires too soon to hand
918
+ * out — a child cannot refresh the snapshot it is given. It
919
+ * requires `maySpawn` (construction error otherwise) and entails
920
+ * the plain credentials need.
921
+ */
922
+ readonly credentials?: true | "child";
780
923
  /**
781
924
  * Optional peer dependencies this command cannot run without; the
782
925
  * engine probes resolvability and phrases the install error.
@@ -797,10 +940,23 @@ interface NeedsSpec<TConfig> {
797
940
  /** The normalized preconditions a definition carries. */
798
941
  interface CommandNeeds<TConfig> {
799
942
  readonly config: ConfigSection<TConfig> | undefined;
800
- readonly credentials: boolean;
943
+ readonly credentials: boolean | "child";
801
944
  readonly dependencies: readonly string[];
802
945
  readonly interaction: boolean;
803
946
  }
947
+ /**
948
+ * The terminal-handoff declaration, normalized onto every definition
949
+ * (server commands normalize to false: they own stdio already).
950
+ *
951
+ * `maySpawn` unlocks ctx.spawn and makes the command reject `--json`
952
+ * as soon as the command is known, before anything runs: output
953
+ * delegated to a child process cannot be framed. Handing credentials
954
+ * to the child is a precondition, declared as
955
+ * `needs: { credentials: "child" }`.
956
+ */
957
+ interface SpawnDeclarations {
958
+ readonly maySpawn?: boolean;
959
+ }
804
960
  interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never, TManagesCredentials extends boolean = false> {
805
961
  readonly kind: "result-command";
806
962
  readonly help: CommandHelp;
@@ -821,6 +977,8 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
821
977
  * machinery.
822
978
  */
823
979
  readonly managesCredentials: TManagesCredentials;
980
+ /** See SpawnDeclarations. */
981
+ readonly maySpawn: boolean;
824
982
  /**
825
983
  * The handler function, referenced directly — never a dynamic import
826
984
  * (operator ruling, 2026-08-09). A handler that needs heavy
@@ -832,7 +990,7 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
832
990
  }
833
991
  type Handler<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>, TConfig, TCode extends number = never, TManagesCredentials extends boolean = false> = (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig, TCode> & (TManagesCredentials extends true ? {
834
992
  readonly credentialManager: CredentialManager;
835
- } : unknown)) => Promise<Result<PresentedResult<unknown>, CliStructuredError>>;
993
+ } : unknown)) => Promise<Result<PresentedResult<unknown> | ChildStatusSettlement, CliStructuredError>>;
836
994
  /** For impl files: `const run: CommandHandler<typeof migrateCommand> = …` */
837
995
  type CommandHandler<D> = D extends CommandDefinition<infer F, infer P, infer C, infer K, infer M> ? Handler<F, P, C, K, M> : never;
838
996
  declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never>(def: {
@@ -842,33 +1000,43 @@ declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>>
842
1000
  readonly exitCodes?: Readonly<Record<TCode, string>>;
843
1001
  readonly managesCredentials: true;
844
1002
  readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, true>;
845
- }): CommandDefinition<TFlags, TPositionals, TConfig, TCode, true>;
1003
+ } & SpawnDeclarations): CommandDefinition<TFlags, TPositionals, TConfig, TCode, true>;
846
1004
  declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never>(def: {
847
1005
  readonly help: HelpSpec;
848
1006
  readonly args?: ArgsSpec<TFlags, TPositionals>;
849
1007
  readonly needs?: NeedsSpec<TConfig>;
850
1008
  readonly exitCodes?: Readonly<Record<TCode, string>>;
851
1009
  readonly handler: Handler<TFlags, TPositionals, TConfig, TCode>;
852
- }): CommandDefinition<TFlags, TPositionals, TConfig, TCode>;
1010
+ } & SpawnDeclarations): CommandDefinition<TFlags, TPositionals, TConfig, TCode>;
853
1011
  /**
854
1012
  * A session command (dev, log tail): runs until the signal fires,
855
1013
  * speaks entirely through events, returns Result<void>. No
856
- * presentation, no exit-code set. A session always supports json mode:
857
- * the event stream is its json surface.
1014
+ * presentation, no exit-code set.
1015
+ *
1016
+ * A session supports json mode — the event stream is its json surface —
1017
+ * UNLESS it declares `maySpawn`, in which case it rejects --json as soon
1018
+ * as the command is known, before anything runs (S3): output delegated
1019
+ * to a child process cannot be framed. A session that returns
1020
+ * ok(undefined) exits 0 — or 130/143 when a signal ended the run, which
1021
+ * the engine settles from its own record of that signal, not from
1022
+ * anything the handler returns; one that returns
1023
+ * ok(exitWithChildStatus(child)) exits with the child's status.
858
1024
  */
859
1025
  interface SessionCommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined> {
860
1026
  readonly kind: "session-command";
861
1027
  readonly help: CommandHelp;
862
1028
  readonly args: CommandArgs<TFlags, TPositionals>;
863
1029
  readonly needs: CommandNeeds<TConfig>;
864
- readonly handler: (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig>) => Promise<Result<void, CliStructuredError>>;
1030
+ /** See SpawnDeclarations. */
1031
+ readonly maySpawn: boolean;
1032
+ readonly handler: (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig>) => Promise<Result<undefined | ChildStatusSettlement, CliStructuredError>>;
865
1033
  }
866
1034
  declare function defineSessionCommand<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined>(def: {
867
1035
  readonly help: HelpSpec;
868
1036
  readonly args?: ArgsSpec<TFlags, TPositionals>;
869
1037
  readonly needs?: NeedsSpec<TConfig>;
870
1038
  readonly handler: SessionCommandDefinition<TFlags, TPositionals, TConfig>["handler"];
871
- }): SessionCommandDefinition<TFlags, TPositionals, TConfig>;
1039
+ } & SpawnDeclarations): SessionCommandDefinition<TFlags, TPositionals, TConfig>;
872
1040
  /**
873
1041
  * A server command (lsp): a foreign client on the other end of stdio
874
1042
  * owns the conversation, so the engine hands over the streams. Events,
@@ -880,6 +1048,9 @@ interface ServerCommandDefinition<TFlags extends Record<string, FlagSpec<unknown
880
1048
  readonly help: CommandHelp;
881
1049
  readonly args: CommandArgs<TFlags, Record<never, PositionalSpec<unknown>>>;
882
1050
  readonly needs: CommandNeeds<TConfig>;
1051
+ /** Always false — a server command owns stdio already. Normalized so
1052
+ * every definition carries the field and callers read it directly. */
1053
+ readonly maySpawn: false;
883
1054
  readonly handler: (args: Args<TFlags, Record<never, PositionalSpec<unknown>>>, io: {
884
1055
  readonly stdin: InputStream;
885
1056
  readonly stdout: OutputStream;
@@ -1019,4 +1190,4 @@ interface RunSummary {
1019
1190
  readonly snapshot: EngineCommandSnapshot;
1020
1191
  }
1021
1192
  //#endregion
1022
- export { TokenStorage$1 as $, OpenUrlRequest as A, EngineEvent as B, LoadedConfig as C, BrowserWaitRequest as D, Runtime as E, PRESENTED as F, Credential as G, StreamEvent as H, Presentations as I, CredentialOrigin as J, CredentialIdentity as K, PresentedResult as L, Block as M, Format as N, CommandContext as O, Outcome as P, ManagementApiClientConfig as Q, TreeNode as R, InputStream as S, PRISMA_CONFIG_VERSION as T, StreamMeta as U, Severity as V, ActiveCredential as W, StoredSessions as X, Session as Y, ManagementApiClient$1 as Z, SessionCommandDefinition as _, defineCommandFamily as a, Char as at, defineSessionCommand as b, CommandHandler as c, PositionalSpec as ct, CompletedEnvelope as d, ConfigSection as et, ErroredEnvelope as f, ServerCommandDefinition as g, NeedsSpec as h, MountedTree as i, ArgsSpec as it, PromptSurface as j, OpenUrlOutcome as k, CommandHelp as l, flag as lt, HelpSpec as m, RunSummary as n, defineConfigSection as nt, AnyCommand as o, CommandArgs as ot, Handler as p, CredentialManager as q, CommandFamily as r, Args as rt, CommandDefinition as s, FlagSpec as st, EngineCommandSnapshot as t, SectionValidation as tt, CommandNeeds as u, positional as ut, defineCommand as v, OutputStream as w, HostProcess as x, defineServerCommand as y, Ui as z };
1193
+ export { ActiveCredential as $, OpenUrlOutcome as A, exitWithChildStatus as B, InputStream as C, Runtime as D, PRISMA_CONFIG_VERSION as E, ExitWithChildStatusOptions as F, Presentations as G, Format as H, SpawnChild as I, Ui as J, PresentedResult as K, SpawnOptions as L, PromptSurface as M, ChildResult as N, BrowserWaitRequest as O, ChildStatusSettlement as P, StreamMeta as Q, SpawnRequest as R, HostProcess as S, OutputStream as T, Outcome as U, Block as V, PRESENTED as W, Severity as X, EngineEvent as Y, StreamEvent as Z, SessionCommandDefinition as _, FlagSpec as _t, defineCommandFamily as a, Session as at, defineServerCommand as b, positional as bt, CommandHandler as c, ManagementApiClientConfig as ct, CompletedEnvelope as d, SectionValidation as dt, Credential as et, ErroredEnvelope as f, defineConfigSection as ft, ServerCommandDefinition as g, CommandArgs as gt, NeedsSpec as h, Char as ht, MountedTree as i, SERVICE_TOKEN_ENV_VAR as it, OpenUrlRequest as j, CommandContext as k, CommandHelp as l, TokenStorage$1 as lt, HelpSpec as m, ArgsSpec as mt, RunSummary as n, CredentialManager as nt, AnyCommand as o, StoredSessions as ot, Handler as p, Args as pt, TreeNode as q, CommandFamily as r, CredentialOrigin as rt, CommandDefinition as s, ManagementApiClient$1 as st, EngineCommandSnapshot as t, CredentialIdentity as tt, CommandNeeds as u, ConfigSection as ut, SpawnDeclarations as v, PositionalSpec as vt, LoadedConfig as w, defineSessionCommand as x, defineCommand as y, flag as yt, SpawnedChild as z };
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as TokenStorage, B as EngineEvent, G as Credential, H as StreamEvent, L as PresentedResult, Q as ManagementApiClientConfig, W as ActiveCredential, X as StoredSessions, Y as Session, Z as ManagementApiClient, i as MountedTree, n as RunSummary, q as CredentialManager, r as CommandFamily } from "./run-summary-CZITSYO_.js";
1
+ import { $ as ActiveCredential, D as Runtime, I as SpawnChild, K as PresentedResult, N as ChildResult, R as SpawnRequest, Y as EngineEvent, Z as StreamEvent, at as Session, ct as ManagementApiClientConfig, et as Credential, i as MountedTree, lt as TokenStorage, n as RunSummary, nt as CredentialManager, ot as StoredSessions, r as CommandFamily, st as ManagementApiClient } from "./run-summary-CLpl1gmC.js";
2
2
 
3
3
  //#region src/in-memory-credential-manager.d.ts
4
4
  /** A stored session with its credential material — what the manager
@@ -40,6 +40,7 @@ declare function mintTestJwt(claims: Readonly<Record<string, unknown>>): string;
40
40
  * own tests.
41
41
  */
42
42
  declare class InMemoryCredentialManager implements CredentialManager {
43
+ #private;
43
44
  private storedSessions;
44
45
  private selection;
45
46
  private readonly environmentCredential;
@@ -60,6 +61,11 @@ declare class InMemoryCredentialManager implements CredentialManager {
60
61
  endSession(workspaceId: string): Promise<void>;
61
62
  endAllSessions(): Promise<void>;
62
63
  activeCredentialStorage(): Promise<TokenStorage>;
64
+ /** The spawn path's read: the active credential's access token,
65
+ * fresh on every call, never the refresh token. Null when there is
66
+ * no active credential to read — storage exists only once
67
+ * activeCredential() has returned non-null. */
68
+ activeAccessToken(): Promise<string | null>;
63
69
  private buildActiveStorage;
64
70
  /** The file-backed storage's analogue: the record is read afresh on
65
71
  * every call, never snapshotted. */
@@ -75,6 +81,25 @@ declare class InMemoryCredentialManager implements CredentialManager {
75
81
  }
76
82
  //#endregion
77
83
  //#region src/testing.d.ts
84
+ /**
85
+ * What a scripted fake child does. `nextKill` resolves with each signal
86
+ * the engine delivers, so a script can model a child that ignores
87
+ * SIGTERM and only dies on SIGKILL.
88
+ */
89
+ type ScriptedChildProgram = (request: SpawnRequest, child: {
90
+ readonly nextKill: () => Promise<"SIGTERM" | "SIGKILL">;
91
+ }) => ChildResult | Promise<ChildResult>;
92
+ /** One ctx.spawn call, as the harness saw it. */
93
+ interface SpawnRecord {
94
+ readonly command: string;
95
+ readonly args: readonly string[];
96
+ readonly cwd: string;
97
+ /** Environment KEYS only. Values are never recorded: a fixture file
98
+ * must not be able to carry token material. */
99
+ readonly envKeys: readonly string[];
100
+ /** The signals the engine delivered to the child, in order. */
101
+ readonly kills: readonly ("SIGTERM" | "SIGKILL")[];
102
+ }
78
103
  interface TestCli {
79
104
  /**
80
105
  * The mutable in-memory credential manager backing the runs — the
@@ -116,7 +141,8 @@ interface TestCli {
116
141
  * The PresentedResult the handler returned, for semantic assertions
117
142
  * without byte-scraping; undefined when the run never presented.
118
143
  */
119
- readonly presented: PresentedResult<unknown> | undefined;
144
+ readonly presented: PresentedResult<unknown> | undefined; /** Every ctx.spawn the run made, in order. */
145
+ readonly spawns: readonly SpawnRecord[];
120
146
  }>;
121
147
  }
122
148
  /**
@@ -132,7 +158,15 @@ declare function createTestCli(spec: {
132
158
  readonly groups?: Readonly<Record<string, {
133
159
  readonly brief: string;
134
160
  }>>;
161
+ /** Seeds the sections the config file would have held. The engine
162
+ * asks for them only when the command declares a config section, and
163
+ * checks them as it would a real file's: a section name no mounted
164
+ * command declares fails the run. */
135
165
  readonly config?: Readonly<Record<string, unknown>>;
166
+ /** Replaces the loader outright — to assert what --config asked for,
167
+ * to return file-level diagnostics, or to prove a run never reads
168
+ * the config at all. Wins over `config` when both are given. */
169
+ readonly loadConfig?: Runtime["loadConfig"];
136
170
  /** Convenience manager seed: createSession runs its real claims
137
171
  * derivation on this credential (mint the token with mintTestJwt). */
138
172
  readonly credential?: Credential; /** Stored sessions, mirroring the state file's records. */
@@ -163,6 +197,11 @@ declare function createTestCli(spec: {
163
197
  /** Waiting is instant under test whatever this does; pass a spy to
164
198
  * assert the interval a poll loop asked for. */
165
199
  readonly delay?: (ms: number, signal: AbortSignal) => Promise<void>;
200
+ /** The spawn adapter behind ctx.spawn. Defaults to the scripted fake;
201
+ * the real-child tests pass a node:child_process adapter, which is
202
+ * how the engine package itself never imports one. */
203
+ readonly spawn?: SpawnChild; /** Scripts the built-in fake child. Defaults to one that exits 0. */
204
+ readonly spawnScript?: ScriptedChildProgram;
166
205
  }): TestCli;
167
206
  //#endregion
168
- export { InMemoryCredentialManager, type InMemoryCredentialManagerSeed, type InMemoryCredentialManagerState, type SessionRecord, type TestCli, createTestCli, mintTestJwt };
207
+ export { InMemoryCredentialManager, type InMemoryCredentialManagerSeed, type InMemoryCredentialManagerState, type ScriptedChildProgram, type SessionRecord, type SpawnRecord, type TestCli, createTestCli, mintTestJwt };