@prisma/cli-engine 0.0.1 → 0.0.3

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/testing.d.ts CHANGED
@@ -1,7 +1,112 @@
1
- import { F as PresentedResult, O as Credentials, R as ManagementApiClient, V as StreamEvent, i as MountedTree, n as RunSummary, r as CommandFamily, z as EngineEvent } from "./run-summary-CPpYAYtS.js";
1
+ import { $ as ActiveCredential, I as SpawnChild, K as PresentedResult, N as ChildResult, R as SpawnRequest, Y as EngineEvent, Z as StreamEvent, at as StoredSessions, ct as TokenStorage, et as Credential, i as MountedTree, it as Session, n as RunSummary, nt as CredentialManager, ot as ManagementApiClient, r as CommandFamily, st as ManagementApiClientConfig } from "./run-summary-DMFNIvjx.js";
2
2
 
3
+ //#region src/in-memory-credential-manager.d.ts
4
+ /** A stored session with its credential material — what the manager
5
+ * holds, seeded in and read back out. Mirrors the state file's
6
+ * records. */
7
+ interface SessionRecord {
8
+ readonly workspaceId: string;
9
+ readonly workspaceName: string | undefined;
10
+ readonly credential: Credential;
11
+ }
12
+ interface InMemoryCredentialManagerSeed {
13
+ /** Stored sessions, mirroring the state file's records. */
14
+ readonly sessions?: readonly SessionRecord[];
15
+ /** The stored selection — the workspace whose session is used where
16
+ * a session is needed. */
17
+ readonly selectedWorkspaceId?: string;
18
+ /** Convenience seed: runs createSession's real claims derivation.
19
+ * The token must be a JWT with `workspace_id` (use mintTestJwt). */
20
+ readonly credential?: Credential;
21
+ /** The credential PRISMA_SERVICE_TOKEN supplies. Its token may carry
22
+ * no `workspace_id` claim, and it may carry a refresh token. */
23
+ readonly environmentCredential?: Credential;
24
+ }
25
+ /** The whole stored state, readable back after a run. */
26
+ interface InMemoryCredentialManagerState {
27
+ readonly sessions: readonly SessionRecord[];
28
+ readonly selectedWorkspaceId: string | undefined;
29
+ }
30
+ /** Mints an unsigned JWT whose payload is exactly `claims` — the
31
+ * harness's claim source (`sub`, `workspace_id`, `exp`, `email`). */
32
+ declare function mintTestJwt(claims: Readonly<Record<string, unknown>>): string;
33
+ /**
34
+ * The harness's mutable in-memory CredentialManager: the same
35
+ * interface commands see, with the whole stored state readable back
36
+ * after a run, and the design's process pinning — which credential
37
+ * this process acts as is fixed at the first activeCredential() read,
38
+ * while the material behind it is re-read on every call. No
39
+ * persistence, no locking — those belong to the real manager and its
40
+ * own tests.
41
+ */
42
+ declare class InMemoryCredentialManager implements CredentialManager {
43
+ #private;
44
+ private storedSessions;
45
+ private selection;
46
+ private readonly environmentCredential;
47
+ private pin;
48
+ private activeStorage;
49
+ constructor(seed: InMemoryCredentialManagerSeed);
50
+ state(): InMemoryCredentialManagerState;
51
+ /** Applies a write as ANOTHER process would: the stored state
52
+ * changes, but this process's pinned decision does not move. */
53
+ overwriteStoredState(state: {
54
+ readonly sessions?: readonly SessionRecord[];
55
+ readonly selectedWorkspaceId?: string | undefined;
56
+ }): void;
57
+ activeCredential(): Promise<ActiveCredential | null>;
58
+ sessions(): Promise<StoredSessions>;
59
+ createSession(credential: Credential, workspaceId: string): Promise<Session>;
60
+ selectSession(workspaceId: string): Promise<Session>;
61
+ endSession(workspaceId: string): Promise<void>;
62
+ endAllSessions(): Promise<void>;
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>;
69
+ private buildActiveStorage;
70
+ /** The file-backed storage's analogue: the record is read afresh on
71
+ * every call, never snapshotted. */
72
+ private storedSessionStorage;
73
+ private removeRecord;
74
+ private resolvePin;
75
+ /** The selection the manager will admit to: one that names a stored
76
+ * session, or none. A dangling selection never escapes. */
77
+ private resolvedSelection;
78
+ private credentialForPin;
79
+ private requireEnvironmentCredential;
80
+ private applyCreateSession;
81
+ }
82
+ //#endregion
3
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
+ }
4
103
  interface TestCli {
104
+ /**
105
+ * The mutable in-memory credential manager backing the runs — the
106
+ * whole stored state (sessions with their credentials, the
107
+ * selection) is readable back after a run via state().
108
+ */
109
+ readonly credentialManager: InMemoryCredentialManager;
5
110
  run(argv: readonly string[], opts?: {
6
111
  readonly stdin?: string;
7
112
  /**
@@ -36,7 +141,8 @@ interface TestCli {
36
141
  * The PresentedResult the handler returned, for semantic assertions
37
142
  * without byte-scraping; undefined when the run never presented.
38
143
  */
39
- readonly presented: PresentedResult<unknown> | undefined;
144
+ readonly presented: PresentedResult<unknown> | undefined; /** Every ctx.spawn the run made, in order. */
145
+ readonly spawns: readonly SpawnRecord[];
40
146
  }>;
41
147
  }
42
148
  /**
@@ -53,15 +159,41 @@ declare function createTestCli(spec: {
53
159
  readonly brief: string;
54
160
  }>>;
55
161
  readonly config?: Readonly<Record<string, unknown>>;
56
- readonly credentials?: Credentials;
162
+ /** Convenience manager seed: createSession runs its real claims
163
+ * derivation on this credential (mint the token with mintTestJwt). */
164
+ readonly credential?: Credential; /** Stored sessions, mirroring the state file's records. */
165
+ readonly sessions?: readonly SessionRecord[]; /** The stored selection. */
166
+ readonly selectedWorkspaceId?: string;
167
+ /** The credential PRISMA_SERVICE_TOKEN supplies. Its access token is
168
+ * also exported to each run's env as PRISMA_SERVICE_TOKEN
169
+ * (overridable per run). */
170
+ readonly environmentCredential?: Credential;
171
+ /** The SDK client construction config; defaults point every
172
+ * endpoint at test.invalid hosts. */
173
+ readonly managementApiClientConfig?: ManagementApiClientConfig;
57
174
  /** baseUrl defaults to "https://test.invalid"; when `client` is
58
175
  * supplied, ctx.api IS that object. */
59
176
  readonly managementApi?: {
60
177
  readonly baseUrl?: string;
61
178
  readonly client?: ManagementApiClient;
62
179
  };
63
- readonly packageManager?: "npm" | "pnpm" | "yarn" | "bun" | "unknown"; /** Fixed clock for deterministic stream timestamps. */
180
+ readonly packageManager?: "npm" | "pnpm" | "yarn" | "bun" | "unknown";
181
+ /** Fixed clock for deterministic stream timestamps; a clock that
182
+ * advances also drives prompt.browserWait's timeout. */
64
183
  readonly now?: () => Date;
184
+ /** The browser opener behind ctx.openUrl and prompt.browserWait.
185
+ * Defaults to one that succeeds without doing anything; pass a spy
186
+ * to assert what was opened, or a thrower to exercise the
187
+ * could-not-open path. */
188
+ readonly openUrl?: (url: string) => Promise<void> | void;
189
+ /** Waiting is instant under test whatever this does; pass a spy to
190
+ * assert the interval a poll loop asked for. */
191
+ readonly delay?: (ms: number, signal: AbortSignal) => Promise<void>;
192
+ /** The spawn adapter behind ctx.spawn. Defaults to the scripted fake;
193
+ * the real-child tests pass a node:child_process adapter, which is
194
+ * how the engine package itself never imports one. */
195
+ readonly spawn?: SpawnChild; /** Scripts the built-in fake child. Defaults to one that exits 0. */
196
+ readonly spawnScript?: ScriptedChildProgram;
65
197
  }): TestCli;
66
198
  //#endregion
67
- export { type TestCli, createTestCli };
199
+ export { InMemoryCredentialManager, type InMemoryCredentialManagerSeed, type InMemoryCredentialManagerState, type ScriptedChildProgram, type SessionRecord, type SpawnRecord, type TestCli, createTestCli, mintTestJwt };