@prisma/cli-engine 0.0.8 → 0.1.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/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as SpawnRequest, F as ChildResult, J as PresentedResult, R as SpawnChild, a as MountedTree, at as ActiveCredential, ct as CredentialManager, dt as Session, ft as StoredSessions, ht as TokenStorage, k as Runtime, mt as ManagementApiClientConfig, n as RunSummary, ot as Credential, pt as ManagementApiClient, r as CommandFamily, rt as StreamEvent, tt as EngineEvent } from "./run-summary-CVHIRjTS.js";
1
+ import { Ct as TokenStorage, F as TelemetryPayload, K as PackageManagerId, L as RunSummary, O as Host, P as Runtime, R as ChildResult, St as ManagementApiClientConfig, U as SpawnRequest, V as SpawnChild, Y as PackageManagerRunner, bt as StoredSessions, dt as StreamEvent, gt as CredentialManager, i as MountedTree, lt as EngineEvent, mt as Credential, n as CommandFamily, nt as PresentedResult, pt as ActiveCredential, t as TelemetryDeclaration, xt as ManagementApiClient, yt as Session } from "./report-DID_e0si.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
@@ -136,6 +136,10 @@ interface TestCli {
136
136
  stderr?: number;
137
137
  };
138
138
  readonly env?: Readonly<Record<string, string | undefined>>;
139
+ /** Overrides the CLI-level seed, so one harness can assert both
140
+ * sides of the CI branch. Absent leaves the engine to detect CI
141
+ * from `env`, which is how a test asserts detection itself. */
142
+ readonly isCI?: boolean;
139
143
  }): Promise<{
140
144
  readonly exitCode: number;
141
145
  readonly stdout: string;
@@ -148,6 +152,10 @@ interface TestCli {
148
152
  */
149
153
  readonly presented: PresentedResult<unknown> | undefined; /** Every ctx.spawn the run made, in order. */
150
154
  readonly spawns: readonly SpawnRecord[];
155
+ /** Every telemetry payload the run handed to the seam, in order.
156
+ * Empty when the CLI declared no telemetry, when gating disabled
157
+ * the run, or when the harness wired no seam. */
158
+ readonly telemetry: readonly TelemetryPayload[];
151
159
  }>;
152
160
  }
153
161
  /**
@@ -190,7 +198,17 @@ declare function createTestCli(spec: {
190
198
  readonly baseUrl?: string;
191
199
  readonly client?: ManagementApiClient;
192
200
  };
193
- readonly packageManager?: "npm" | "pnpm" | "yarn" | "bun" | "unknown";
201
+ /** Overrides detection, the same way a host's Runtime does; absent
202
+ * means the engine detects from the run's cwd. */
203
+ readonly packageManager?: PackageManagerId;
204
+ /** What the run reports itself as running on; defaults to a fixed
205
+ * host so a bug-report payload asserts the same on every machine. */
206
+ readonly host?: Host;
207
+ /** The scripted stand-in for the shipped bin's spawner: assert the
208
+ * composed file/args/cwd, script exit codes and stderr, drive
209
+ * onOutput. Absent means this host has no runner, which is the
210
+ * failure every package operation then takes. */
211
+ readonly packageManagerRunner?: PackageManagerRunner;
194
212
  /** Fixed clock for deterministic stream timestamps; a clock that
195
213
  * advances also drives prompt.browserWait's timeout. */
196
214
  readonly now?: () => Date;
@@ -207,6 +225,18 @@ declare function createTestCli(spec: {
207
225
  * how the engine package itself never imports one. */
208
226
  readonly spawn?: SpawnChild; /** Scripts the built-in fake child. Defaults to one that exits 0. */
209
227
  readonly spawnScript?: ScriptedChildProgram;
228
+ /** Declares telemetry, exactly as `createCli` does. Absent means this
229
+ * CLI reports nothing, which is what every test that says nothing
230
+ * about telemetry gets. */
231
+ readonly telemetry?: TelemetryDeclaration;
232
+ /** The seam behind Runtime.spawnTelemetry. Payloads are recorded on
233
+ * the run result either way; pass a spy to assert ordering, a
234
+ * thrower to exercise failure isolation, or `null` to model a host
235
+ * that wires no seam at all. */
236
+ readonly telemetrySpawner?: ((payload: TelemetryPayload) => void) | null;
237
+ /** Forces the CI answer for every run; `run({ isCI })` overrides it.
238
+ * Absent leaves the engine to detect CI from the run's `env`. */
239
+ readonly isCI?: boolean;
210
240
  }): TestCli;
211
241
  //#endregion
212
242
  export { InMemoryCredentialManager, type InMemoryCredentialManagerSeed, type InMemoryCredentialManagerState, type ScriptedChildProgram, type SessionRecord, type SpawnRecord, type TestCli, createTestCli, mintTestJwt };
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { g as noSessionForWorkspaceError, i as buildEngine, m as credentialsRequiredError, n as claimedIdentity, p as credentialWorkspaceMismatchError, r as credentialWorkspaceId, t as claimedExpiresAt } from "./token-claims-_AF7BYbq.js";
1
+ import { _ as noSessionForWorkspaceError, h as credentialsRequiredError, i as buildEngine, m as credentialWorkspaceMismatchError, n as claimedIdentity, r as credentialWorkspaceId, t as claimedExpiresAt } from "./token-claims-CJNNCGkL.js";
2
2
  import { Buffer } from "node:buffer";
3
3
  //#region src/in-memory-credential-manager.ts
4
4
  /**
@@ -317,6 +317,21 @@ function recordingSpawn(adapter, spawns) {
317
317
  };
318
318
  };
319
319
  }
320
+ function runEnv(environmentCredential, env) {
321
+ if (environmentCredential === void 0) return env ?? {};
322
+ return {
323
+ PRISMA_SERVICE_TOKEN: environmentCredential.token,
324
+ ...env
325
+ };
326
+ }
327
+ function relaySignalOnAbort(abort, deliver) {
328
+ if (abort === void 0) return;
329
+ if (abort.aborted) {
330
+ deliver(abort.reason);
331
+ return;
332
+ }
333
+ abort.addEventListener("abort", () => deliver(abort.reason), { once: true });
334
+ }
320
335
  function inputStreamFromString(text) {
321
336
  const bytes = new TextEncoder().encode(text);
322
337
  return { async *[Symbol.asyncIterator]() {
@@ -337,19 +352,31 @@ function createTestCli(spec) {
337
352
  credential: spec.credential,
338
353
  environmentCredential: spec.environmentCredential
339
354
  });
355
+ const managementApiBaseUrl = spec.managementApi?.baseUrl ?? "https://test.invalid";
340
356
  const managementApiClientConfig = spec.managementApiClientConfig ?? {
341
357
  clientId: "test-client-id",
342
358
  redirectUri: "https://test.invalid/auth/callback",
343
- apiBaseUrl: spec.managementApi?.baseUrl ?? "https://test.invalid",
359
+ apiBaseUrl: managementApiBaseUrl,
344
360
  authBaseUrl: "https://auth.test.invalid"
345
361
  };
362
+ const loadConfig = spec.loadConfig ?? (async (configPath) => ({
363
+ path: configPath ?? "prisma.config.ts",
364
+ sections: spec.config ?? {},
365
+ diagnostics: []
366
+ }));
367
+ const spawnChild = spec.spawn ?? scriptedSpawn(spec.spawnScript ?? (() => ({
368
+ exitCode: 0,
369
+ signal: null
370
+ })));
371
+ const openUrl = spec.openUrl ?? (() => {});
346
372
  const engine = buildEngine(
347
373
  {
348
374
  name: "prisma-test",
349
375
  version: "0.0.0",
350
376
  commandFamilies: spec.commandFamilies ?? [],
351
377
  groups: spec.groups ?? {},
352
- commands: spec.commands
378
+ commands: spec.commands,
379
+ telemetry: spec.telemetry
353
380
  },
354
381
  /** Waiting is instant under test: browserWait's polling is driven
355
382
  * by the seeded clock, never by real time. */
@@ -369,6 +396,7 @@ function createTestCli(spec) {
369
396
  const events = [];
370
397
  let presented;
371
398
  const spawns = [];
399
+ const telemetry = [];
372
400
  const signalListeners = /* @__PURE__ */ new Set();
373
401
  const deliverSignal = (reason) => {
374
402
  const signal = reason === "SIGTERM" ? "SIGTERM" : "SIGINT";
@@ -386,15 +414,13 @@ function createTestCli(spec) {
386
414
  },
387
415
  stdin: inputStreamFromString(opts?.stdin ?? ""),
388
416
  cwd: opts?.cwd ?? "/",
389
- env: spec.environmentCredential === void 0 ? opts?.env ?? {} : {
390
- PRISMA_SERVICE_TOKEN: spec.environmentCredential.token,
391
- ...opts?.env
392
- },
417
+ env: runEnv(spec.environmentCredential, opts?.env),
393
418
  isTty: {
394
419
  stdin: opts?.isTty?.stdin ?? false,
395
420
  stdout: opts?.isTty?.stdout ?? false,
396
421
  stderr: opts?.isTty?.stderr ?? false
397
422
  },
423
+ isCIOverride: opts?.isCI ?? spec.isCI,
398
424
  exit: (code) => {
399
425
  throw new Error(`@prisma/cli-engine: runtime.exit(${code}) reached the test harness`);
400
426
  },
@@ -404,20 +430,26 @@ function createTestCli(spec) {
404
430
  signalListeners.delete(cb);
405
431
  };
406
432
  },
407
- loadConfig: spec.loadConfig ?? (async (configPath) => ({
408
- path: configPath ?? "prisma.config.ts",
409
- sections: spec.config ?? {},
410
- diagnostics: []
411
- })),
433
+ loadConfig,
412
434
  credentialManager,
413
435
  managementApiClientConfig,
414
- spawn: recordingSpawn(spec.spawn ?? scriptedSpawn(spec.spawnScript ?? (() => ({
415
- exitCode: 0,
416
- signal: null
417
- }))), spawns),
418
- openUrl: spec.openUrl ?? (() => {}),
419
- managementApi: { baseUrl: spec.managementApi?.baseUrl ?? "https://test.invalid" },
420
- packageManager: spec.packageManager ?? "unknown"
436
+ spawn: recordingSpawn(spawnChild, spawns),
437
+ spawnTelemetry: spec.telemetrySpawner === null ? void 0 : (payload) => {
438
+ telemetry.push(payload);
439
+ spec.telemetrySpawner?.(payload);
440
+ },
441
+ openUrl,
442
+ managementApi: { baseUrl: managementApiBaseUrl },
443
+ packageManager: spec.packageManager,
444
+ runPackageManager: spec.packageManagerRunner,
445
+ host: spec.host ?? {
446
+ runtime: {
447
+ name: "node",
448
+ version: "v22.12.0"
449
+ },
450
+ platform: "linux",
451
+ arch: "x64"
452
+ }
421
453
  };
422
454
  const running = engine.execute(argv, runtime, {
423
455
  onEvent: (event) => {
@@ -434,9 +466,7 @@ function createTestCli(spec) {
434
466
  answers: opts?.answers,
435
467
  managementApi: spec.managementApi?.client === void 0 ? void 0 : { client: spec.managementApi.client }
436
468
  });
437
- const abort = opts?.abort;
438
- if (abort !== void 0) if (abort.aborted) deliverSignal(abort.reason);
439
- else abort.addEventListener("abort", () => deliverSignal(abort.reason), { once: true });
469
+ relaySignalOnAbort(opts?.abort, deliverSignal);
440
470
  return {
441
471
  exitCode: await running,
442
472
  stdout: stdoutText,
@@ -444,7 +474,8 @@ function createTestCli(spec) {
444
474
  json: frames,
445
475
  events,
446
476
  presented,
447
- spawns
477
+ spawns,
478
+ telemetry
448
479
  };
449
480
  }
450
481
  };