@prisma/cli-engine 0.0.8 → 0.0.9
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/index.d.ts +54 -3
- package/dist/index.js +165 -3
- package/dist/{protocol-C1JQcGl9.js → protocol-D1CRNkhv.js} +25 -4
- package/dist/{protocol-CpZLdxML.d.ts → protocol-YjqPCCOG.d.ts} +23 -3
- package/dist/protocol.d.ts +2 -2
- package/dist/protocol.js +2 -2
- package/dist/{run-summary-CVHIRjTS.d.ts → report-Bh6-ntIa.d.ts} +198 -65
- package/dist/testing.d.ts +26 -2
- package/dist/testing.js +46 -23
- package/dist/{token-claims-_AF7BYbq.js → token-claims-CGQ-5m9N.js} +898 -136
- package/package.json +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as NextAction, n as CliStructuredError, r as Diagnostic, s as Result } from "./protocol-
|
|
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,14 @@ 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
|
+
* The host's answer to "is this CI", from Runtime.isCI — what
|
|
709
|
+
* telemetry gates on. Not the engine's interactivity decision, which
|
|
710
|
+
* is its own thing (stdin a TTY, no CI in the environment,
|
|
711
|
+
* --interactive/--no-interactive), so prompts and spinners follow
|
|
712
|
+
* ctx.prompt and the engine's interaction handling, not this.
|
|
713
|
+
*/
|
|
714
|
+
readonly isCI: boolean;
|
|
707
715
|
/**
|
|
708
716
|
* Conditional optional-dependency need. Resolves when the
|
|
709
717
|
* optional peer dependency is importable from the user's project;
|
|
@@ -800,6 +808,140 @@ interface PromptSurface {
|
|
|
800
808
|
readonly browserWait: (request: BrowserWaitRequest) => Promise<void>;
|
|
801
809
|
}
|
|
802
810
|
//#endregion
|
|
811
|
+
//#region src/package-manager.d.ts
|
|
812
|
+
/** The package managers the engine knows how to drive. */
|
|
813
|
+
type PackageManagerId = "npm" | "pnpm" | "yarn" | "bun" | "deno";
|
|
814
|
+
/**
|
|
815
|
+
* ctx.packages: what a command declaring `installsPackages` may do to
|
|
816
|
+
* the user's project. Both operations resolve — a manager that failed
|
|
817
|
+
* is a value, not a throw — except under cancellation, which throws the
|
|
818
|
+
* abort reason so the run settles the way Ctrl-C settles everywhere
|
|
819
|
+
* else. Neither may be called while the other is still running.
|
|
820
|
+
*
|
|
821
|
+
* Success carries nothing back: the command line stays with the engine,
|
|
822
|
+
* which announces it, streams the manager's output under it, and puts
|
|
823
|
+
* the redacted spelling on a failure's next action.
|
|
824
|
+
*/
|
|
825
|
+
interface PackageOperations {
|
|
826
|
+
/** Adds dependencies to the project. */
|
|
827
|
+
install(request: {
|
|
828
|
+
/** Specifiers as the user would type them, e.g. "prisma@latest". */readonly packages: readonly string[];
|
|
829
|
+
readonly dev?: boolean; /** Defaults to ctx.cwd. */
|
|
830
|
+
readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
|
|
831
|
+
readonly manager?: PackageManagerId;
|
|
832
|
+
}): Promise<Result<void, CliStructuredError>>;
|
|
833
|
+
/** Runs a package's bin once, without adding a dependency. */
|
|
834
|
+
run(request: {
|
|
835
|
+
/** The package whose bin to execute, e.g. "skills". */readonly package: string;
|
|
836
|
+
readonly args: readonly string[]; /** Defaults to ctx.cwd. */
|
|
837
|
+
readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
|
|
838
|
+
readonly manager?: PackageManagerId;
|
|
839
|
+
}): Promise<Result<void, CliStructuredError>>;
|
|
840
|
+
}
|
|
841
|
+
/** One package-manager execution, handed to the host to spawn. */
|
|
842
|
+
interface PackageManagerRunRequest {
|
|
843
|
+
readonly file: string;
|
|
844
|
+
readonly args: readonly string[];
|
|
845
|
+
readonly cwd: string;
|
|
846
|
+
readonly signal: AbortSignal;
|
|
847
|
+
/** Called with each chunk as the child writes it, so the engine can
|
|
848
|
+
* emit `output` events while the operation runs. */
|
|
849
|
+
readonly onOutput: (channel: "data" | "diagnostic", chunk: string) => void;
|
|
850
|
+
}
|
|
851
|
+
/** What the child produced: its exit code — non-zero covers a manager
|
|
852
|
+
* that failed and an executable that was not there — and its stderr,
|
|
853
|
+
* bounded to the last 64 KiB. */
|
|
854
|
+
interface PackageManagerRunResult {
|
|
855
|
+
readonly exitCode: number;
|
|
856
|
+
readonly stderr: string;
|
|
857
|
+
}
|
|
858
|
+
/** Spawns a package manager on the engine's behalf. A manager that
|
|
859
|
+
* fails is a resolved result, never a rejection. */
|
|
860
|
+
type PackageManagerRunner = (request: PackageManagerRunRequest) => Promise<PackageManagerRunResult>;
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/run-summary.d.ts
|
|
863
|
+
/**
|
|
864
|
+
* The value-free command snapshot the engine records at parse time.
|
|
865
|
+
* The engine's own telemetry composes its payload from it at command
|
|
866
|
+
* start, and it rides along on the RunSummary a bin may observe.
|
|
867
|
+
* Carries NO user data — command-path segments, flag names with their
|
|
868
|
+
* value source, and a bare count of positionals. Flag values,
|
|
869
|
+
* positional values, and raw argv never appear here.
|
|
870
|
+
*/
|
|
871
|
+
interface EngineCommandSnapshot {
|
|
872
|
+
/** Mount-path segments of the executed command ('telemetry status'
|
|
873
|
+
* → ['telemetry', 'status']). Never includes the binary name. */
|
|
874
|
+
readonly commandPath: readonly string[];
|
|
875
|
+
/**
|
|
876
|
+
* One entry per flag the command accepts (the engine-injected shared
|
|
877
|
+
* family first, then the command's own declarations), named in the
|
|
878
|
+
* user-facing kebab-case spelling. `source` is what the engine knows
|
|
879
|
+
* at parse time: flags explicitly present on argv are 'cli'; the
|
|
880
|
+
* engine reads no flags from the environment today, so everything
|
|
881
|
+
* else is 'default'. 'env' is reserved for a future env-sourced
|
|
882
|
+
* flag mechanism.
|
|
883
|
+
*/
|
|
884
|
+
readonly flags: ReadonlyArray<{
|
|
885
|
+
readonly name: string;
|
|
886
|
+
readonly source: "cli" | "env" | "default";
|
|
887
|
+
}>;
|
|
888
|
+
/** How many positional arguments the run supplied — a count only. */
|
|
889
|
+
readonly positionalCount: number;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* What `RunHooks.onSettled` receives, exactly once per run, after the
|
|
893
|
+
* run has settled (exit code determined, terminal output written).
|
|
894
|
+
* Never fired for `--help` or `--version`, and never for a run that
|
|
895
|
+
* failed before a mounted command was reached (nothing executed, so
|
|
896
|
+
* there is no snapshot to report). `durationMs` comes from the
|
|
897
|
+
* engine's injectable clock.
|
|
898
|
+
*/
|
|
899
|
+
interface RunSummary {
|
|
900
|
+
/** The mounted command's dotted id ('telemetry.status'). Derived
|
|
901
|
+
* from the same mount entry as `snapshot.commandPath` — it always
|
|
902
|
+
* equals `snapshot.commandPath.join('.')`. Both are kept: consumers
|
|
903
|
+
* addressing the command use the id; the snapshot is the value-free
|
|
904
|
+
* wire projection. */
|
|
905
|
+
readonly commandId: string;
|
|
906
|
+
readonly exitCode: number;
|
|
907
|
+
readonly durationMs: number;
|
|
908
|
+
readonly snapshot: EngineCommandSnapshot;
|
|
909
|
+
}
|
|
910
|
+
//#endregion
|
|
911
|
+
//#region src/telemetry/payload.d.ts
|
|
912
|
+
/**
|
|
913
|
+
* The payload the engine composes at command start and hands to
|
|
914
|
+
* `Runtime.spawnTelemetry`. The host forwards it to its own sender,
|
|
915
|
+
* which probes its process (runtime/os/arch, package manager, ts
|
|
916
|
+
* version, agent) for the rest of the event and POSTs it.
|
|
917
|
+
*
|
|
918
|
+
* Both sides version-couple on this shape: the carrier is Node's
|
|
919
|
+
* structured clone over IPC, so there is no on-wire compat to maintain.
|
|
920
|
+
*/
|
|
921
|
+
interface TelemetryPayload {
|
|
922
|
+
readonly installationId: string;
|
|
923
|
+
readonly version: string;
|
|
924
|
+
/** The command path joined with spaces — `postgres create`. */
|
|
925
|
+
readonly command: string;
|
|
926
|
+
/** Names only, of the flags the user typed. Never values. */
|
|
927
|
+
readonly flags: readonly string[];
|
|
928
|
+
/**
|
|
929
|
+
* Absolute path of the user's project. The sender reads
|
|
930
|
+
* `<projectRoot>/package.json` for `tsVersion`.
|
|
931
|
+
*/
|
|
932
|
+
readonly projectRoot: string;
|
|
933
|
+
/** Resolved endpoint URL (already includes the `/events` path). */
|
|
934
|
+
readonly endpoint: string;
|
|
935
|
+
/**
|
|
936
|
+
* Kept for wire compatibility with the ORM CLI's first-`init` flow,
|
|
937
|
+
* where the chosen target is known before the config file exists. The
|
|
938
|
+
* engine never populates it; the wire-format event keeps `null` as its
|
|
939
|
+
* "no target known" marker, but this channel needs only two states so
|
|
940
|
+
* the field is `string | undefined`.
|
|
941
|
+
*/
|
|
942
|
+
readonly databaseTarget?: string;
|
|
943
|
+
}
|
|
944
|
+
//#endregion
|
|
803
945
|
//#region src/runtime.d.ts
|
|
804
946
|
/** Minimal structural stream types; no NodeJS.* in the public surface. */
|
|
805
947
|
interface OutputStream {
|
|
@@ -829,6 +971,13 @@ interface Runtime {
|
|
|
829
971
|
readonly stdout: boolean;
|
|
830
972
|
readonly stderr: boolean;
|
|
831
973
|
};
|
|
974
|
+
/**
|
|
975
|
+
* True when this process runs in CI, where telemetry never reports.
|
|
976
|
+
* The bin wires `ci-info`; the engine detects CI no more than it
|
|
977
|
+
* detects a TTY. Required, not optional: a host that forgot it would
|
|
978
|
+
* silently report from CI.
|
|
979
|
+
*/
|
|
980
|
+
readonly isCI: boolean;
|
|
832
981
|
/**
|
|
833
982
|
* Ends the process. The bin passes process.exit; the engine is the
|
|
834
983
|
* only caller (second-signal force exit, 130/143).
|
|
@@ -880,15 +1029,33 @@ interface Runtime {
|
|
|
880
1029
|
* handler run, so ctx.spawn is never reached.
|
|
881
1030
|
*/
|
|
882
1031
|
readonly spawn?: SpawnChild;
|
|
1032
|
+
/**
|
|
1033
|
+
* Fire-and-forget delivery of one composed telemetry payload. The bin
|
|
1034
|
+
* owns the process work and the detachment, which is why the engine
|
|
1035
|
+
* imports no child_process and performs no network I/O for telemetry.
|
|
1036
|
+
* Absent means this host reports nothing — not an error, and the whole
|
|
1037
|
+
* sequence is skipped rather than only the delivery: no config read,
|
|
1038
|
+
* no disclosure, no mint.
|
|
1039
|
+
*/
|
|
1040
|
+
readonly spawnTelemetry?: (payload: TelemetryPayload) => void;
|
|
883
1041
|
/** Management API endpoint config; the bin derives baseUrl from env. */
|
|
884
1042
|
readonly managementApi: {
|
|
885
1043
|
readonly baseUrl: string;
|
|
886
1044
|
};
|
|
887
1045
|
/**
|
|
888
|
-
*
|
|
889
|
-
*
|
|
1046
|
+
* A host that knows its user's package manager better than detection
|
|
1047
|
+
* does. Absent — the normal case — means the engine detects it from
|
|
1048
|
+
* the project at cwd.
|
|
890
1049
|
*/
|
|
891
|
-
readonly packageManager
|
|
1050
|
+
readonly packageManager?: PackageManagerId;
|
|
1051
|
+
/**
|
|
1052
|
+
* Spawns the package manager the engine composed. The engine never
|
|
1053
|
+
* imports child_process; this is the only way a manager runs. It is
|
|
1054
|
+
* optional so a harness can exercise the no-runner path — every
|
|
1055
|
+
* shipped host wires it, and a host without it can run no package
|
|
1056
|
+
* operation at all.
|
|
1057
|
+
*/
|
|
1058
|
+
readonly runPackageManager?: PackageManagerRunner;
|
|
892
1059
|
}
|
|
893
1060
|
/**
|
|
894
1061
|
* The minimal process surface a bin adapts a Runtime from — Node's
|
|
@@ -1038,7 +1205,7 @@ interface CommandNeeds<TConfig> {
|
|
|
1038
1205
|
interface SpawnDeclarations {
|
|
1039
1206
|
readonly maySpawn?: boolean;
|
|
1040
1207
|
}
|
|
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> {
|
|
1208
|
+
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
1209
|
readonly kind: "result-command";
|
|
1043
1210
|
readonly help: CommandHelp;
|
|
1044
1211
|
readonly args: CommandArgs<TFlags, TPositionals>;
|
|
@@ -1060,6 +1227,12 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
|
|
|
1060
1227
|
readonly managesCredentials: TManagesCredentials;
|
|
1061
1228
|
/** See SpawnDeclarations. */
|
|
1062
1229
|
readonly maySpawn: boolean;
|
|
1230
|
+
/**
|
|
1231
|
+
* A CAPABILITY, not a need: when true, ctx.packages appears on the
|
|
1232
|
+
* context and the command may run the user's package manager in the
|
|
1233
|
+
* user's project. Declaring it never fails a run.
|
|
1234
|
+
*/
|
|
1235
|
+
readonly installsPackages: TInstallsPackages;
|
|
1063
1236
|
/**
|
|
1064
1237
|
* The handler function, referenced directly — never a dynamic import
|
|
1065
1238
|
* (operator ruling, 2026-08-09). A handler that needs heavy
|
|
@@ -1067,28 +1240,24 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
|
|
|
1067
1240
|
* handler defined in another file is imported statically and
|
|
1068
1241
|
* annotated CommandHandler<typeof def>.
|
|
1069
1242
|
*/
|
|
1070
|
-
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, TManagesCredentials>;
|
|
1243
|
+
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, TManagesCredentials, TInstallsPackages>;
|
|
1071
1244
|
}
|
|
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 ? {
|
|
1245
|
+
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
1246
|
readonly credentialManager: CredentialManager;
|
|
1247
|
+
} : unknown) & (TInstallsPackages extends true ? {
|
|
1248
|
+
readonly packages: PackageOperations;
|
|
1074
1249
|
} : unknown)) => Promise<Result<PresentedResult<unknown> | ChildStatusSettlement, CliStructuredError>>;
|
|
1075
1250
|
/** 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: {
|
|
1251
|
+
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;
|
|
1252
|
+
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
1253
|
readonly help: HelpSpec;
|
|
1079
1254
|
readonly args?: ArgsSpec<TFlags, TPositionals>;
|
|
1080
1255
|
readonly needs?: NeedsSpec<TConfig>;
|
|
1081
1256
|
readonly exitCodes?: Readonly<Record<TCode, string>>;
|
|
1082
|
-
readonly managesCredentials
|
|
1083
|
-
readonly
|
|
1084
|
-
|
|
1085
|
-
|
|
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>;
|
|
1257
|
+
readonly managesCredentials?: TManagesCredentials;
|
|
1258
|
+
readonly installsPackages?: TInstallsPackages;
|
|
1259
|
+
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, TManagesCredentials, TInstallsPackages>;
|
|
1260
|
+
} & SpawnDeclarations): CommandDefinition<TFlags, TPositionals, TConfig, TCode, TManagesCredentials, TInstallsPackages>;
|
|
1092
1261
|
/**
|
|
1093
1262
|
* A session command (dev, log tail): runs until the signal fires,
|
|
1094
1263
|
* speaks entirely through events, returns Result<void>. No
|
|
@@ -1155,7 +1324,7 @@ declare function defineServerCommand<TFlags extends Record<string, FlagSpec<unkn
|
|
|
1155
1324
|
* concrete types travel through each definition's generics, not through
|
|
1156
1325
|
* this union.
|
|
1157
1326
|
*/
|
|
1158
|
-
type AnyCommand = (Omit<CommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown, number, boolean>, "handler"> & {
|
|
1327
|
+
type AnyCommand = (Omit<CommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown, number, boolean, boolean>, "handler"> & {
|
|
1159
1328
|
readonly handler: unknown;
|
|
1160
1329
|
}) | (Omit<SessionCommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown>, "handler"> & {
|
|
1161
1330
|
readonly handler: unknown;
|
|
@@ -1263,52 +1432,16 @@ declare function defineCommandFamily(spec: {
|
|
|
1263
1432
|
/** What the shell builds: commands by PATH (space-separated, 'db migrate'). */
|
|
1264
1433
|
type MountedTree = Readonly<Record<string, AnyCommand>>;
|
|
1265
1434
|
//#endregion
|
|
1266
|
-
//#region src/
|
|
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
|
-
}
|
|
1435
|
+
//#region src/telemetry/report.d.ts
|
|
1294
1436
|
/**
|
|
1295
|
-
* What
|
|
1296
|
-
*
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1299
|
-
* there is no snapshot to report). `durationMs` comes from the
|
|
1300
|
-
* engine's injectable clock.
|
|
1437
|
+
* What a CLI declares to report. One field: the endpoint, the opt-out
|
|
1438
|
+
* variable names, the config path and the disclosure wording are Prisma
|
|
1439
|
+
* constants the engine owns. Omitting the declaration means the CLI
|
|
1440
|
+
* reports nothing at all.
|
|
1301
1441
|
*/
|
|
1302
|
-
interface
|
|
1303
|
-
/**
|
|
1304
|
-
|
|
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;
|
|
1442
|
+
interface TelemetryDeclaration {
|
|
1443
|
+
/** Named in the first-run disclosure as where to read what is collected. */
|
|
1444
|
+
readonly docsUrl: string;
|
|
1312
1445
|
}
|
|
1313
1446
|
//#endregion
|
|
1314
|
-
export {
|
|
1447
|
+
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 {
|
|
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-Bh6-ntIa.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,9 @@ 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. */
|
|
141
|
+
readonly isCI?: boolean;
|
|
139
142
|
}): Promise<{
|
|
140
143
|
readonly exitCode: number;
|
|
141
144
|
readonly stdout: string;
|
|
@@ -148,6 +151,10 @@ interface TestCli {
|
|
|
148
151
|
*/
|
|
149
152
|
readonly presented: PresentedResult<unknown> | undefined; /** Every ctx.spawn the run made, in order. */
|
|
150
153
|
readonly spawns: readonly SpawnRecord[];
|
|
154
|
+
/** Every telemetry payload the run handed to the seam, in order.
|
|
155
|
+
* Empty when the CLI declared no telemetry, when gating disabled
|
|
156
|
+
* the run, or when the harness wired no seam. */
|
|
157
|
+
readonly telemetry: readonly TelemetryPayload[];
|
|
151
158
|
}>;
|
|
152
159
|
}
|
|
153
160
|
/**
|
|
@@ -190,7 +197,14 @@ declare function createTestCli(spec: {
|
|
|
190
197
|
readonly baseUrl?: string;
|
|
191
198
|
readonly client?: ManagementApiClient;
|
|
192
199
|
};
|
|
193
|
-
|
|
200
|
+
/** Overrides detection, the same way a host's Runtime does; absent
|
|
201
|
+
* means the engine detects from the run's cwd. */
|
|
202
|
+
readonly packageManager?: PackageManagerId;
|
|
203
|
+
/** The scripted stand-in for the shipped bin's spawner: assert the
|
|
204
|
+
* composed file/args/cwd, script exit codes and stderr, drive
|
|
205
|
+
* onOutput. Absent means this host has no runner, which is the
|
|
206
|
+
* failure every package operation then takes. */
|
|
207
|
+
readonly packageManagerRunner?: PackageManagerRunner;
|
|
194
208
|
/** Fixed clock for deterministic stream timestamps; a clock that
|
|
195
209
|
* advances also drives prompt.browserWait's timeout. */
|
|
196
210
|
readonly now?: () => Date;
|
|
@@ -207,6 +221,16 @@ declare function createTestCli(spec: {
|
|
|
207
221
|
* how the engine package itself never imports one. */
|
|
208
222
|
readonly spawn?: SpawnChild; /** Scripts the built-in fake child. Defaults to one that exits 0. */
|
|
209
223
|
readonly spawnScript?: ScriptedChildProgram;
|
|
224
|
+
/** Declares telemetry, exactly as `createCli` does. Absent means this
|
|
225
|
+
* CLI reports nothing, which is what every test that says nothing
|
|
226
|
+
* about telemetry gets. */
|
|
227
|
+
readonly telemetry?: TelemetryDeclaration;
|
|
228
|
+
/** The seam behind Runtime.spawnTelemetry. Payloads are recorded on
|
|
229
|
+
* the run result either way; pass a spy to assert ordering, a
|
|
230
|
+
* thrower to exercise failure isolation, or `null` to model a host
|
|
231
|
+
* that wires no seam at all. */
|
|
232
|
+
readonly telemetrySpawner?: ((payload: TelemetryPayload) => void) | null; /** Seeds Runtime.isCI for every run; `run({ isCI })` overrides it. */
|
|
233
|
+
readonly isCI?: boolean;
|
|
210
234
|
}): TestCli;
|
|
211
235
|
//#endregion
|
|
212
236
|
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-
|
|
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-CGQ-5m9N.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:
|
|
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
|
|
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
|
+
isCI: opts?.isCI ?? spec.isCI ?? false,
|
|
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
|
|
408
|
-
path: configPath ?? "prisma.config.ts",
|
|
409
|
-
sections: spec.config ?? {},
|
|
410
|
-
diagnostics: []
|
|
411
|
-
})),
|
|
433
|
+
loadConfig,
|
|
412
434
|
credentialManager,
|
|
413
435
|
managementApiClientConfig,
|
|
414
|
-
spawn: recordingSpawn(
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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
|
-
|
|
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
|
};
|