@prisma/cli-engine 0.0.8 → 8.0.0-rc.1

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.
@@ -1,4 +1,4 @@
1
- import { i as NextAction, n as CliStructuredError, r as Diagnostic, s as Result } from "./protocol-CpZLdxML.js";
1
+ import { i as NextAction, n as CliStructuredError, r as Diagnostic, s as Result } from "./protocol-YjqPCCOG.js";
2
2
  import { ManagementApiClient, TokenStorage } from "@prisma/management-api-sdk";
3
3
 
4
4
  //#region src/args.d.ts
@@ -704,6 +704,15 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
704
704
  * via ctx.env, never process.env.
705
705
  */
706
706
  readonly env: Readonly<Record<string, string | undefined>>;
707
+ /**
708
+ * Whether this run is in CI: detected from the environment the host
709
+ * injected, or forced by Runtime.isCIOverride. This is what telemetry
710
+ * gates on. It is one input to the engine's interactivity decision
711
+ * rather than the whole of it (which also weighs a TTY stdin and
712
+ * --interactive/--no-interactive), so prompts and spinners follow
713
+ * ctx.prompt and the engine's interaction handling, not this.
714
+ */
715
+ readonly isCI: boolean;
707
716
  /**
708
717
  * Conditional optional-dependency need. Resolves when the
709
718
  * optional peer dependency is importable from the user's project;
@@ -800,6 +809,140 @@ interface PromptSurface {
800
809
  readonly browserWait: (request: BrowserWaitRequest) => Promise<void>;
801
810
  }
802
811
  //#endregion
812
+ //#region src/package-manager.d.ts
813
+ /** The package managers the engine knows how to drive. */
814
+ type PackageManagerId = "npm" | "pnpm" | "yarn" | "bun" | "deno";
815
+ /**
816
+ * ctx.packages: what a command declaring `installsPackages` may do to
817
+ * the user's project. Both operations resolve — a manager that failed
818
+ * is a value, not a throw — except under cancellation, which throws the
819
+ * abort reason so the run settles the way Ctrl-C settles everywhere
820
+ * else. Neither may be called while the other is still running.
821
+ *
822
+ * Success carries nothing back: the command line stays with the engine,
823
+ * which announces it, streams the manager's output under it, and puts
824
+ * the redacted spelling on a failure's next action.
825
+ */
826
+ interface PackageOperations {
827
+ /** Adds dependencies to the project. */
828
+ install(request: {
829
+ /** Specifiers as the user would type them, e.g. "prisma@latest". */readonly packages: readonly string[];
830
+ readonly dev?: boolean; /** Defaults to ctx.cwd. */
831
+ readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
832
+ readonly manager?: PackageManagerId;
833
+ }): Promise<Result<void, CliStructuredError>>;
834
+ /** Runs a package's bin once, without adding a dependency. */
835
+ run(request: {
836
+ /** The package whose bin to execute, e.g. "skills". */readonly package: string;
837
+ readonly args: readonly string[]; /** Defaults to ctx.cwd. */
838
+ readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
839
+ readonly manager?: PackageManagerId;
840
+ }): Promise<Result<void, CliStructuredError>>;
841
+ }
842
+ /** One package-manager execution, handed to the host to spawn. */
843
+ interface PackageManagerRunRequest {
844
+ readonly file: string;
845
+ readonly args: readonly string[];
846
+ readonly cwd: string;
847
+ readonly signal: AbortSignal;
848
+ /** Called with each chunk as the child writes it, so the engine can
849
+ * emit `output` events while the operation runs. */
850
+ readonly onOutput: (channel: "data" | "diagnostic", chunk: string) => void;
851
+ }
852
+ /** What the child produced: its exit code — non-zero covers a manager
853
+ * that failed and an executable that was not there — and its stderr,
854
+ * bounded to the last 64 KiB. */
855
+ interface PackageManagerRunResult {
856
+ readonly exitCode: number;
857
+ readonly stderr: string;
858
+ }
859
+ /** Spawns a package manager on the engine's behalf. A manager that
860
+ * fails is a resolved result, never a rejection. */
861
+ type PackageManagerRunner = (request: PackageManagerRunRequest) => Promise<PackageManagerRunResult>;
862
+ //#endregion
863
+ //#region src/run-summary.d.ts
864
+ /**
865
+ * The value-free command snapshot the engine records at parse time.
866
+ * The engine's own telemetry composes its payload from it at command
867
+ * start, and it rides along on the RunSummary a bin may observe.
868
+ * Carries NO user data — command-path segments, flag names with their
869
+ * value source, and a bare count of positionals. Flag values,
870
+ * positional values, and raw argv never appear here.
871
+ */
872
+ interface EngineCommandSnapshot {
873
+ /** Mount-path segments of the executed command ('telemetry status'
874
+ * → ['telemetry', 'status']). Never includes the binary name. */
875
+ readonly commandPath: readonly string[];
876
+ /**
877
+ * One entry per flag the command accepts (the engine-injected shared
878
+ * family first, then the command's own declarations), named in the
879
+ * user-facing kebab-case spelling. `source` is what the engine knows
880
+ * at parse time: flags explicitly present on argv are 'cli'; the
881
+ * engine reads no flags from the environment today, so everything
882
+ * else is 'default'. 'env' is reserved for a future env-sourced
883
+ * flag mechanism.
884
+ */
885
+ readonly flags: ReadonlyArray<{
886
+ readonly name: string;
887
+ readonly source: "cli" | "env" | "default";
888
+ }>;
889
+ /** How many positional arguments the run supplied — a count only. */
890
+ readonly positionalCount: number;
891
+ }
892
+ /**
893
+ * What `RunHooks.onSettled` receives, exactly once per run, after the
894
+ * run has settled (exit code determined, terminal output written).
895
+ * Never fired for `--help` or `--version`, and never for a run that
896
+ * failed before a mounted command was reached (nothing executed, so
897
+ * there is no snapshot to report). `durationMs` comes from the
898
+ * engine's injectable clock.
899
+ */
900
+ interface RunSummary {
901
+ /** The mounted command's dotted id ('telemetry.status'). Derived
902
+ * from the same mount entry as `snapshot.commandPath` — it always
903
+ * equals `snapshot.commandPath.join('.')`. Both are kept: consumers
904
+ * addressing the command use the id; the snapshot is the value-free
905
+ * wire projection. */
906
+ readonly commandId: string;
907
+ readonly exitCode: number;
908
+ readonly durationMs: number;
909
+ readonly snapshot: EngineCommandSnapshot;
910
+ }
911
+ //#endregion
912
+ //#region src/telemetry/payload.d.ts
913
+ /**
914
+ * The payload the engine composes at command start and hands to
915
+ * `Runtime.spawnTelemetry`. The host forwards it to its own sender,
916
+ * which probes its process (runtime/os/arch, package manager, ts
917
+ * version, agent) for the rest of the event and POSTs it.
918
+ *
919
+ * Both sides version-couple on this shape: the carrier is Node's
920
+ * structured clone over IPC, so there is no on-wire compat to maintain.
921
+ */
922
+ interface TelemetryPayload {
923
+ readonly installationId: string;
924
+ readonly version: string;
925
+ /** The command path joined with spaces — `postgres create`. */
926
+ readonly command: string;
927
+ /** Names only, of the flags the user typed. Never values. */
928
+ readonly flags: readonly string[];
929
+ /**
930
+ * Absolute path of the user's project. The sender reads
931
+ * `<projectRoot>/package.json` for `tsVersion`.
932
+ */
933
+ readonly projectRoot: string;
934
+ /** Resolved endpoint URL (already includes the `/events` path). */
935
+ readonly endpoint: string;
936
+ /**
937
+ * Kept for wire compatibility with the ORM CLI's first-`init` flow,
938
+ * where the chosen target is known before the config file exists. The
939
+ * engine never populates it; the wire-format event keeps `null` as its
940
+ * "no target known" marker, but this channel needs only two states so
941
+ * the field is `string | undefined`.
942
+ */
943
+ readonly databaseTarget?: string;
944
+ }
945
+ //#endregion
803
946
  //#region src/runtime.d.ts
804
947
  /** Minimal structural stream types; no NodeJS.* in the public surface. */
805
948
  interface OutputStream {
@@ -829,6 +972,18 @@ interface Runtime {
829
972
  readonly stdout: boolean;
830
973
  readonly stderr: boolean;
831
974
  };
975
+ /**
976
+ * Forces the answer to "is this CI", where telemetry never reports.
977
+ * Absent — the normal case — means the engine detects CI from `env`
978
+ * using ci-info's vendor table, which is why no host has to answer:
979
+ * unlike a TTY, CI-ness is derivable from the environment the host
980
+ * already injects, and every host computing the same boolean was the
981
+ * same detection table forked N ways. Set it only where detection
982
+ * cannot be right — an exotic platform, or a test that needs both
983
+ * sides of the branch. Absence means detected, never false, so a host
984
+ * that says nothing still stays silent in CI.
985
+ */
986
+ readonly isCIOverride?: boolean;
832
987
  /**
833
988
  * Ends the process. The bin passes process.exit; the engine is the
834
989
  * only caller (second-signal force exit, 130/143).
@@ -880,15 +1035,33 @@ interface Runtime {
880
1035
  * handler run, so ctx.spawn is never reached.
881
1036
  */
882
1037
  readonly spawn?: SpawnChild;
1038
+ /**
1039
+ * Fire-and-forget delivery of one composed telemetry payload. The bin
1040
+ * owns the process work and the detachment, which is why the engine
1041
+ * imports no child_process and performs no network I/O for telemetry.
1042
+ * Absent means this host reports nothing — not an error, and the whole
1043
+ * sequence is skipped rather than only the delivery: no config read,
1044
+ * no disclosure, no mint.
1045
+ */
1046
+ readonly spawnTelemetry?: (payload: TelemetryPayload) => void;
883
1047
  /** Management API endpoint config; the bin derives baseUrl from env. */
884
1048
  readonly managementApi: {
885
1049
  readonly baseUrl: string;
886
1050
  };
887
1051
  /**
888
- * Used by the ENGINE to phrase install commands (handlers never do —
889
- * see needs.dependencies and ctx.requireDependency).
1052
+ * A host that knows its user's package manager better than detection
1053
+ * does. Absent — the normal case — means the engine detects it from
1054
+ * the project at cwd.
890
1055
  */
891
- readonly packageManager: "npm" | "pnpm" | "yarn" | "bun" | "unknown";
1056
+ readonly packageManager?: PackageManagerId;
1057
+ /**
1058
+ * Spawns the package manager the engine composed. The engine never
1059
+ * imports child_process; this is the only way a manager runs. It is
1060
+ * optional so a harness can exercise the no-runner path — every
1061
+ * shipped host wires it, and a host without it can run no package
1062
+ * operation at all.
1063
+ */
1064
+ readonly runPackageManager?: PackageManagerRunner;
892
1065
  }
893
1066
  /**
894
1067
  * The minimal process surface a bin adapts a Runtime from — Node's
@@ -1038,7 +1211,7 @@ interface CommandNeeds<TConfig> {
1038
1211
  interface SpawnDeclarations {
1039
1212
  readonly maySpawn?: boolean;
1040
1213
  }
1041
- 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> {
1214
+ 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, TInstallsPackages extends boolean = false> {
1042
1215
  readonly kind: "result-command";
1043
1216
  readonly help: CommandHelp;
1044
1217
  readonly args: CommandArgs<TFlags, TPositionals>;
@@ -1060,6 +1233,12 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
1060
1233
  readonly managesCredentials: TManagesCredentials;
1061
1234
  /** See SpawnDeclarations. */
1062
1235
  readonly maySpawn: boolean;
1236
+ /**
1237
+ * A CAPABILITY, not a need: when true, ctx.packages appears on the
1238
+ * context and the command may run the user's package manager in the
1239
+ * user's project. Declaring it never fails a run.
1240
+ */
1241
+ readonly installsPackages: TInstallsPackages;
1063
1242
  /**
1064
1243
  * The handler function, referenced directly — never a dynamic import
1065
1244
  * (operator ruling, 2026-08-09). A handler that needs heavy
@@ -1067,28 +1246,24 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
1067
1246
  * handler defined in another file is imported statically and
1068
1247
  * annotated CommandHandler<typeof def>.
1069
1248
  */
1070
- readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, TManagesCredentials>;
1249
+ readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, TManagesCredentials, TInstallsPackages>;
1071
1250
  }
1072
- 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 ? {
1251
+ type Handler<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>, TConfig, TCode extends number = never, TManagesCredentials extends boolean = false, TInstallsPackages extends boolean = false> = (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig, TCode> & (TManagesCredentials extends true ? {
1073
1252
  readonly credentialManager: CredentialManager;
1253
+ } : unknown) & (TInstallsPackages extends true ? {
1254
+ readonly packages: PackageOperations;
1074
1255
  } : unknown)) => Promise<Result<PresentedResult<unknown> | ChildStatusSettlement, CliStructuredError>>;
1075
1256
  /** For impl files: `const run: CommandHandler<typeof migrateCommand> = …` */
1076
- type CommandHandler<D> = D extends CommandDefinition<infer F, infer P, infer C, infer K, infer M> ? Handler<F, P, C, K, M> : never;
1077
- 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: {
1257
+ type CommandHandler<D> = D extends CommandDefinition<infer F, infer P, infer C, infer K, infer M, infer I> ? Handler<F, P, C, K, M, I> : never;
1258
+ 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, TManagesCredentials extends boolean = false, TInstallsPackages extends boolean = false>(def: {
1078
1259
  readonly help: HelpSpec;
1079
1260
  readonly args?: ArgsSpec<TFlags, TPositionals>;
1080
1261
  readonly needs?: NeedsSpec<TConfig>;
1081
1262
  readonly exitCodes?: Readonly<Record<TCode, string>>;
1082
- readonly managesCredentials: true;
1083
- readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, true>;
1084
- } & SpawnDeclarations): CommandDefinition<TFlags, TPositionals, TConfig, TCode, true>;
1085
- 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: {
1086
- readonly help: HelpSpec;
1087
- readonly args?: ArgsSpec<TFlags, TPositionals>;
1088
- readonly needs?: NeedsSpec<TConfig>;
1089
- readonly exitCodes?: Readonly<Record<TCode, string>>;
1090
- readonly handler: Handler<TFlags, TPositionals, TConfig, TCode>;
1091
- } & SpawnDeclarations): CommandDefinition<TFlags, TPositionals, TConfig, TCode>;
1263
+ readonly managesCredentials?: TManagesCredentials;
1264
+ readonly installsPackages?: TInstallsPackages;
1265
+ readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, TManagesCredentials, TInstallsPackages>;
1266
+ } & SpawnDeclarations): CommandDefinition<TFlags, TPositionals, TConfig, TCode, TManagesCredentials, TInstallsPackages>;
1092
1267
  /**
1093
1268
  * A session command (dev, log tail): runs until the signal fires,
1094
1269
  * speaks entirely through events, returns Result<void>. No
@@ -1155,7 +1330,7 @@ declare function defineServerCommand<TFlags extends Record<string, FlagSpec<unkn
1155
1330
  * concrete types travel through each definition's generics, not through
1156
1331
  * this union.
1157
1332
  */
1158
- type AnyCommand = (Omit<CommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown, number, boolean>, "handler"> & {
1333
+ type AnyCommand = (Omit<CommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown, number, boolean, boolean>, "handler"> & {
1159
1334
  readonly handler: unknown;
1160
1335
  }) | (Omit<SessionCommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown>, "handler"> & {
1161
1336
  readonly handler: unknown;
@@ -1263,52 +1438,16 @@ declare function defineCommandFamily(spec: {
1263
1438
  /** What the shell builds: commands by PATH (space-separated, 'db migrate'). */
1264
1439
  type MountedTree = Readonly<Record<string, AnyCommand>>;
1265
1440
  //#endregion
1266
- //#region src/run-summary.d.ts
1267
- /**
1268
- * The value-free command snapshot the engine records at parse time and
1269
- * hands to `RunHooks.onSettled`. Consumed by the shell's telemetry
1270
- * wiring; carries NO user data — command-path segments, flag names
1271
- * with their value source, and a bare count of positionals. Flag
1272
- * values, positional values, and raw argv never appear here.
1273
- */
1274
- interface EngineCommandSnapshot {
1275
- /** Mount-path segments of the executed command ('telemetry status'
1276
- * → ['telemetry', 'status']). Never includes the binary name. */
1277
- readonly commandPath: readonly string[];
1278
- /**
1279
- * One entry per flag the command accepts (the engine-injected shared
1280
- * family first, then the command's own declarations), named in the
1281
- * user-facing kebab-case spelling. `source` is what the engine knows
1282
- * at parse time: flags explicitly present on argv are 'cli'; the
1283
- * engine reads no flags from the environment today, so everything
1284
- * else is 'default'. 'env' is reserved for a future env-sourced
1285
- * flag mechanism.
1286
- */
1287
- readonly flags: ReadonlyArray<{
1288
- readonly name: string;
1289
- readonly source: "cli" | "env" | "default";
1290
- }>;
1291
- /** How many positional arguments the run supplied — a count only. */
1292
- readonly positionalCount: number;
1293
- }
1441
+ //#region src/telemetry/report.d.ts
1294
1442
  /**
1295
- * What `RunHooks.onSettled` receives, exactly once per run, after the
1296
- * run has settled (exit code determined, terminal output written).
1297
- * Never fired for `--help` or `--version`, and never for a run that
1298
- * failed before a mounted command was reached (nothing executed, so
1299
- * there is no snapshot to report). `durationMs` comes from the
1300
- * engine's injectable clock.
1443
+ * What a CLI declares to report. One field: the endpoint, the opt-out
1444
+ * variable names, the config path and the disclosure wording are Prisma
1445
+ * constants the engine owns. Omitting the declaration means the CLI
1446
+ * reports nothing at all.
1301
1447
  */
1302
- interface RunSummary {
1303
- /** The mounted command's dotted id ('telemetry.status'). Derived
1304
- * from the same mount entry as `snapshot.commandPath` — it always
1305
- * equals `snapshot.commandPath.join('.')`. Both are kept: consumers
1306
- * addressing the command use the id; the snapshot is the value-free
1307
- * wire projection. */
1308
- readonly commandId: string;
1309
- readonly exitCode: number;
1310
- readonly durationMs: number;
1311
- readonly snapshot: EngineCommandSnapshot;
1448
+ interface TelemetryDeclaration {
1449
+ /** Named in the first-run disclosure as where to read what is collected. */
1450
+ readonly docsUrl: string;
1312
1451
  }
1313
1452
  //#endregion
1314
- export { TreeNode as $, BrowserWaitRequest as A, SpawnRequest as B, defineSessionCommand as C, FlagSpec as Ct, OutputStream as D, LoadedConfig as E, positional as Et, ChildResult as F, Outcome as G, exitWithChildStatus as H, ChildStatusSettlement as I, PresentedResult as J, PRESENTED as K, ExitWithChildStatusOptions as L, OpenUrlOutcome as M, OpenUrlRequest as N, PRISMA_CONFIG_VERSION as O, PromptSurface as P, Tone as Q, SpawnChild as R, defineServerCommand as S, CommandArgs as St, InputStream as T, flag as Tt, Block as U, SpawnedChild as V, Format as W, Status as X, Span as Y, Text as Z, NeedsSpec as _, SectionValidation as _t, MountedTree as a, ActiveCredential as at, SpawnDeclarations as b, ArgsSpec as bt, AnyCommand as c, CredentialManager as ct, CommandHelp as d, Session as dt, Ui as et, CommandNeeds as f, StoredSessions as ft, HelpSpec as g, ConfigSection as gt, Handler as h, TokenStorage$1 as ht, CommandRedirect as i, StreamMeta as it, CommandContext as j, Runtime as k, CommandDefinition as l, CredentialOrigin as lt, ErroredEnvelope as m, ManagementApiClientConfig as mt, RunSummary as n, Severity as nt, RedirectSpec as o, Credential as ot, CompletedEnvelope as p, ManagementApiClient$1 as pt, Presentations as q, CommandFamily as r, StreamEvent as rt, defineCommandFamily as s, CredentialIdentity as st, EngineCommandSnapshot as t, EngineEvent as tt, CommandHandler as u, SERVICE_TOKEN_ENV_VAR as ut, ServerCommandDefinition as v, defineConfigSection as vt, HostProcess as w, PositionalSpec as wt, defineCommand as x, Char as xt, SessionCommandDefinition as y, Args as yt, SpawnOptions as z };
1453
+ export { PRESENTED as $, EngineCommandSnapshot as A, FlagSpec as At, OpenUrlRequest as B, HostProcess as C, ConfigSection as Ct, PRISMA_CONFIG_VERSION as D, ArgsSpec as Dt, OutputStream as E, Args as Et, PackageManagerRunner as F, SpawnChild as G, ChildResult as H, PackageOperations as I, SpawnedChild as J, SpawnOptions as K, BrowserWaitRequest as L, PackageManagerId as M, flag as Mt, PackageManagerRunRequest as N, positional as Nt, Runtime as O, Char as Ot, PackageManagerRunResult as P, Outcome as Q, CommandContext as R, defineSessionCommand as S, TokenStorage$1 as St, LoadedConfig as T, defineConfigSection as Tt, ChildStatusSettlement as U, PromptSurface as V, ExitWithChildStatusOptions as W, Block as X, exitWithChildStatus as Y, Format as Z, ServerCommandDefinition as _, SERVICE_TOKEN_ENV_VAR as _t, RedirectSpec as a, Tone as at, defineCommand as b, ManagementApiClient$1 as bt, CommandDefinition as c, EngineEvent as ct, CommandNeeds as d, StreamMeta as dt, Presentations as et, CompletedEnvelope as f, ActiveCredential as ft, NeedsSpec as g, CredentialOrigin as gt, HelpSpec as h, CredentialManager as ht, MountedTree as i, Text as it, RunSummary as j, PositionalSpec as jt, TelemetryPayload as k, CommandArgs as kt, CommandHandler as l, Severity as lt, Handler as m, CredentialIdentity as mt, CommandFamily as n, Span as nt, defineCommandFamily as o, TreeNode as ot, ErroredEnvelope as p, Credential as pt, SpawnRequest as q, CommandRedirect as r, Status as rt, AnyCommand as s, Ui as st, TelemetryDeclaration as t, PresentedResult as tt, CommandHelp as u, StreamEvent as ut, SessionCommandDefinition as v, Session as vt, InputStream as w, SectionValidation as wt, defineServerCommand as x, ManagementApiClientConfig as xt, SpawnDeclarations as y, StoredSessions as yt, OpenUrlOutcome as z };
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 { F as PackageManagerRunner, G as SpawnChild, H as ChildResult, M as PackageManagerId, O as Runtime, St as TokenStorage, bt as ManagementApiClient, ct as EngineEvent, ft as ActiveCredential, ht as CredentialManager, i as MountedTree, j as RunSummary, k as TelemetryPayload, n as CommandFamily, pt as Credential, q as SpawnRequest, t as TelemetryDeclaration, tt as PresentedResult, ut as StreamEvent, vt as Session, xt as ManagementApiClientConfig, yt as StoredSessions } from "./report-B7M-sp7P.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,14 @@ 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
+ /** The scripted stand-in for the shipped bin's spawner: assert the
205
+ * composed file/args/cwd, script exit codes and stderr, drive
206
+ * onOutput. Absent means this host has no runner, which is the
207
+ * failure every package operation then takes. */
208
+ readonly packageManagerRunner?: PackageManagerRunner;
194
209
  /** Fixed clock for deterministic stream timestamps; a clock that
195
210
  * advances also drives prompt.browserWait's timeout. */
196
211
  readonly now?: () => Date;
@@ -207,6 +222,18 @@ declare function createTestCli(spec: {
207
222
  * how the engine package itself never imports one. */
208
223
  readonly spawn?: SpawnChild; /** Scripts the built-in fake child. Defaults to one that exits 0. */
209
224
  readonly spawnScript?: ScriptedChildProgram;
225
+ /** Declares telemetry, exactly as `createCli` does. Absent means this
226
+ * CLI reports nothing, which is what every test that says nothing
227
+ * about telemetry gets. */
228
+ readonly telemetry?: TelemetryDeclaration;
229
+ /** The seam behind Runtime.spawnTelemetry. Payloads are recorded on
230
+ * the run result either way; pass a spy to assert ordering, a
231
+ * thrower to exercise failure isolation, or `null` to model a host
232
+ * that wires no seam at all. */
233
+ readonly telemetrySpawner?: ((payload: TelemetryPayload) => void) | null;
234
+ /** Forces the CI answer for every run; `run({ isCI })` overrides it.
235
+ * Absent leaves the engine to detect CI from the run's `env`. */
236
+ readonly isCI?: boolean;
210
237
  }): TestCli;
211
238
  //#endregion
212
239
  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 { g as noSessionForWorkspaceError, i as buildEngine, m as credentialsRequiredError, n as claimedIdentity, p as credentialWorkspaceMismatchError, r as credentialWorkspaceId, t as claimedExpiresAt } from "./token-claims-Cwrz7N2O.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,18 @@ 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
421
445
  };
422
446
  const running = engine.execute(argv, runtime, {
423
447
  onEvent: (event) => {
@@ -434,9 +458,7 @@ function createTestCli(spec) {
434
458
  answers: opts?.answers,
435
459
  managementApi: spec.managementApi?.client === void 0 ? void 0 : { client: spec.managementApi.client }
436
460
  });
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 });
461
+ relaySignalOnAbort(opts?.abort, deliverSignal);
440
462
  return {
441
463
  exitCode: await running,
442
464
  stdout: stdoutText,
@@ -444,7 +466,8 @@ function createTestCli(spec) {
444
466
  json: frames,
445
467
  events,
446
468
  presented,
447
- spawns
469
+ spawns,
470
+ telemetry
448
471
  };
449
472
  }
450
473
  };