@rehearsal-db/core 0.1.0-beta.13 → 0.1.0-beta.15
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/CHANGELOG.md +93 -0
- package/README.md +4 -1
- package/dist/package.json +100 -0
- package/dist/scripts/install/create_root_config.d.mts +3 -0
- package/dist/scripts/install/create_root_config.mjs +13 -0
- package/dist/scripts/runtime/manage_database.d.mts +6 -0
- package/{scripts → dist/scripts}/runtime/manage_database.mjs +6 -8
- package/dist/src/application/session.d.mts +96 -0
- package/dist/src/application/session.mjs +380 -0
- package/dist/src/baseline/artifact.d.mts +119 -0
- package/dist/src/baseline/artifact.mjs +522 -0
- package/dist/src/baseline/builder.d.mts +19 -0
- package/dist/src/baseline/builder.mjs +142 -0
- package/dist/src/baseline/input_discovery.d.mts +13 -0
- package/dist/src/baseline/input_discovery.mjs +149 -0
- package/dist/src/baseline/policy_review.d.mts +56 -0
- package/dist/src/baseline/policy_review.mjs +73 -0
- package/dist/src/baseline/preparation.d.mts +63 -0
- package/dist/src/baseline/preparation.mjs +295 -0
- package/dist/src/baseline/privacy_engine.d.mts +162 -0
- package/dist/src/baseline/privacy_engine.mjs +1162 -0
- package/dist/src/baseline/privacy_structured_json.d.mts +66 -0
- package/dist/src/baseline/privacy_structured_json.mjs +464 -0
- package/dist/src/baseline/sanitization_policy.d.mts +69 -0
- package/dist/src/baseline/sanitization_policy.mjs +227 -0
- package/dist/src/baseline/schema_snapshot.d.mts +19 -0
- package/dist/src/baseline/schema_snapshot.mjs +79 -0
- package/dist/src/cli/arguments.d.mts +43 -0
- package/dist/src/cli/arguments.mjs +135 -0
- package/dist/src/cli/guided.d.mts +51 -0
- package/dist/src/cli/guided.mjs +713 -0
- package/dist/src/cli/init_command.d.mts +21 -0
- package/dist/src/cli/init_command.mjs +90 -0
- package/dist/src/cli/project_commands.d.mts +157 -0
- package/dist/src/cli/project_commands.mjs +183 -0
- package/dist/src/cli/rehearsal.d.mts +7 -0
- package/dist/src/cli/rehearsal.mjs +706 -0
- package/dist/src/cli/renderers.d.mts +299 -0
- package/dist/src/cli/renderers.mjs +554 -0
- package/dist/src/cli/runtime_commands.d.mts +265 -0
- package/dist/src/cli/runtime_commands.mjs +599 -0
- package/dist/src/cli/source_commands.d.mts +432 -0
- package/dist/src/cli/source_commands.mjs +299 -0
- package/dist/src/cli/terminal.d.mts +59 -0
- package/dist/src/cli/terminal.mjs +230 -0
- package/dist/src/identity/claim.d.mts +144 -0
- package/dist/src/identity/claim.mjs +947 -0
- package/dist/src/identity/provider_configuration.d.mts +37 -0
- package/dist/src/identity/provider_configuration.mjs +132 -0
- package/dist/src/identity/storage.d.mts +21 -0
- package/dist/src/identity/storage.mjs +122 -0
- package/dist/src/index.d.mts +4 -0
- package/dist/src/index.mjs +3 -0
- package/dist/src/project/configuration.d.mts +181 -0
- package/dist/src/project/configuration.mjs +958 -0
- package/dist/src/project/install_scaffold.d.mts +42 -0
- package/dist/src/project/install_scaffold.mjs +263 -0
- package/dist/src/project/setup.d.mts +87 -0
- package/dist/src/project/setup.mjs +414 -0
- package/dist/src/project/support_report.d.mts +88 -0
- package/dist/src/project/support_report.mjs +83 -0
- package/dist/src/runtime/cleanup.d.mts +85 -0
- package/dist/src/runtime/cleanup.mjs +311 -0
- package/dist/src/runtime/migration_history.d.mts +51 -0
- package/dist/src/runtime/migration_history.mjs +170 -0
- package/dist/src/runtime/plan.d.mts +134 -0
- package/dist/src/runtime/plan.mjs +636 -0
- package/dist/src/runtime/policy.d.mts +66 -0
- package/dist/src/runtime/policy.mjs +369 -0
- package/dist/src/runtime/restore.d.mts +22 -0
- package/dist/src/runtime/restore.mjs +276 -0
- package/dist/src/runtime/service_environment.d.mts +11 -0
- package/dist/src/runtime/service_environment.mjs +58 -0
- package/dist/src/runtime/topology.d.mts +51 -0
- package/dist/src/runtime/topology.mjs +128 -0
- package/dist/src/shared/diagnostics.d.mts +97 -0
- package/dist/src/shared/diagnostics.mjs +170 -0
- package/dist/src/shared/human_output.d.mts +2 -0
- package/{src → dist/src}/shared/human_output.mjs +1 -3
- package/dist/src/shared/node_runtime.d.mts +14 -0
- package/dist/src/shared/node_runtime.mjs +25 -0
- package/dist/src/shared/operation_guard.d.mts +22 -0
- package/dist/src/shared/operation_guard.mjs +150 -0
- package/dist/src/shared/process_environment.d.mts +15 -0
- package/dist/src/shared/process_environment.mjs +50 -0
- package/dist/src/source/access.d.mts +165 -0
- package/dist/src/source/access.mjs +602 -0
- package/dist/src/source/asset_transfer.d.mts +27 -0
- package/dist/src/source/asset_transfer.mjs +202 -0
- package/dist/src/source/baseline.d.mts +66 -0
- package/dist/src/source/baseline.mjs +372 -0
- package/dist/src/source/external_reader.d.mts +42 -0
- package/dist/src/source/external_reader.mjs +278 -0
- package/dist/src/source/postgresql_access.d.mts +86 -0
- package/dist/src/source/postgresql_access.mjs +454 -0
- package/dist/src/source/privacy_paths.d.mts +10 -0
- package/dist/src/source/privacy_paths.mjs +27 -0
- package/dist/src/targets/driver.d.mts +2 -0
- package/dist/src/targets/driver.mjs +13 -0
- package/dist/src/targets/postgresql.d.mts +5 -0
- package/dist/src/targets/postgresql.mjs +641 -0
- package/dist/src/targets/supabase.d.mts +8 -0
- package/dist/src/targets/supabase.mjs +659 -0
- package/dist/src/targets/supabase_environment.d.mts +49 -0
- package/dist/src/targets/supabase_environment.mjs +162 -0
- package/dist/src/targets/target.d.mts +33 -0
- package/dist/src/targets/target.mjs +39 -0
- package/docs/README.md +1 -0
- package/docs/architecture.md +17 -9
- package/docs/configuration.md +49 -8
- package/docs/getting-started.md +28 -0
- package/docs/index.md +1 -0
- package/docs/production-source.md +43 -7
- package/docs/releasing.md +5 -3
- package/docs/roadmap.md +3 -2
- package/docs/sanitization.md +415 -14
- package/docs/standalone-workflow.md +12 -6
- package/docs/troubleshooting.md +5 -1
- package/docs/tutorial.md +5 -0
- package/docs/typescript.md +87 -0
- package/package.json +35 -29
- package/scripts/install/create_root_config.mjs +0 -36
- package/src/README.md +0 -17
- package/src/application/session.mjs +0 -435
- package/src/baseline/artifact.mjs +0 -684
- package/src/baseline/builder.mjs +0 -164
- package/src/baseline/input_discovery.mjs +0 -155
- package/src/baseline/policy_review.mjs +0 -92
- package/src/baseline/preparation.mjs +0 -323
- package/src/baseline/privacy_engine.mjs +0 -952
- package/src/baseline/sanitization_policy.mjs +0 -299
- package/src/baseline/schema_snapshot.mjs +0 -113
- package/src/cli/arguments.mjs +0 -126
- package/src/cli/guided.mjs +0 -814
- package/src/cli/init_command.mjs +0 -94
- package/src/cli/rehearsal.mjs +0 -970
- package/src/cli/renderers.mjs +0 -626
- package/src/cli/runtime_commands.mjs +0 -707
- package/src/cli/source_commands.mjs +0 -347
- package/src/cli/terminal.mjs +0 -275
- package/src/identity/claim.mjs +0 -1163
- package/src/identity/provider_configuration.mjs +0 -177
- package/src/identity/storage.mjs +0 -165
- package/src/project/configuration.mjs +0 -1337
- package/src/project/install_scaffold.mjs +0 -291
- package/src/project/setup.mjs +0 -466
- package/src/project/support_report.mjs +0 -105
- package/src/runtime/cleanup.mjs +0 -381
- package/src/runtime/migration_history.mjs +0 -220
- package/src/runtime/plan.mjs +0 -722
- package/src/runtime/policy.mjs +0 -438
- package/src/runtime/restore.mjs +0 -337
- package/src/runtime/service_environment.mjs +0 -82
- package/src/runtime/topology.mjs +0 -177
- package/src/shared/diagnostics.mjs +0 -207
- package/src/shared/node_runtime.mjs +0 -31
- package/src/shared/operation_guard.mjs +0 -162
- package/src/shared/process_environment.mjs +0 -68
- package/src/source/access.mjs +0 -753
- package/src/source/asset_transfer.mjs +0 -207
- package/src/source/baseline.mjs +0 -482
- package/src/source/external_reader.mjs +0 -255
- package/src/source/postgresql_access.mjs +0 -581
- package/src/source/privacy_paths.mjs +0 -38
- package/src/targets/postgresql.mjs +0 -808
- package/src/targets/supabase.mjs +0 -840
- package/src/targets/supabase_environment.mjs +0 -229
- package/src/targets/target.mjs +0 -66
- /package/{src/project → types}/configuration.d.mts +0 -0
package/src/cli/rehearsal.mjs
DELETED
|
@@ -1,970 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Purpose: Run the versioned, project-configured Rehearsal developer CLI for
|
|
4
|
-
* initialization, readiness, planning, inspection, and verified local execution.
|
|
5
|
-
* Run: `npm run rehearsal -- doctor` or `npm run rehearsal -- explain`.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { createHash } from "node:crypto";
|
|
9
|
-
import { readFile } from "node:fs/promises";
|
|
10
|
-
import { join, relative } from "node:path";
|
|
11
|
-
import { performance } from "node:perf_hooks";
|
|
12
|
-
import { parseEnv } from "node:util";
|
|
13
|
-
import { fileURLToPath } from "node:url";
|
|
14
|
-
import * as prompts from "@clack/prompts";
|
|
15
|
-
import {
|
|
16
|
-
createRehearsalResult,
|
|
17
|
-
normalizeRehearsalError,
|
|
18
|
-
REHEARSAL_VERSION,
|
|
19
|
-
renderHumanError,
|
|
20
|
-
serializeRehearsalError,
|
|
21
|
-
} from "../shared/diagnostics.mjs";
|
|
22
|
-
import { loadRehearsalConfig } from "../project/configuration.mjs";
|
|
23
|
-
import {
|
|
24
|
-
inspectRehearsalBaseline,
|
|
25
|
-
inspectRehearsalMigrations,
|
|
26
|
-
runRehearsalDoctor,
|
|
27
|
-
} from "../runtime/plan.mjs";
|
|
28
|
-
import { createSyntheticBaselineFromFiles } from "../baseline/builder.mjs";
|
|
29
|
-
import {
|
|
30
|
-
applyBaselinePreparation,
|
|
31
|
-
inspectBaselineInputFiles,
|
|
32
|
-
planBaselinePreparation,
|
|
33
|
-
summarizeBaselinePreparation,
|
|
34
|
-
} from "../baseline/preparation.mjs";
|
|
35
|
-
import {
|
|
36
|
-
applyRehearsalSetup,
|
|
37
|
-
planRehearsalSetup,
|
|
38
|
-
summarizeRehearsalSetup,
|
|
39
|
-
} from "../project/setup.mjs";
|
|
40
|
-
import { formatCount } from "../shared/human_output.mjs";
|
|
41
|
-
import { collectRehearsalSupportReport } from "../project/support_report.mjs";
|
|
42
|
-
import {
|
|
43
|
-
applyRehearsalCleanup,
|
|
44
|
-
planRehearsalCleanup,
|
|
45
|
-
} from "../runtime/cleanup.mjs";
|
|
46
|
-
import { loadRuntimeTopology } from "../runtime/topology.mjs";
|
|
47
|
-
import { createPrivacyKey } from "../baseline/privacy_engine.mjs";
|
|
48
|
-
import { createSourceAccessPlan } from "../source/access.mjs";
|
|
49
|
-
import {
|
|
50
|
-
buildApplicationEnvironment,
|
|
51
|
-
runHttpProofs,
|
|
52
|
-
startApplicationSession,
|
|
53
|
-
} from "../application/session.mjs";
|
|
54
|
-
import {
|
|
55
|
-
applyIdentityClaim,
|
|
56
|
-
createIdentityClaimPlan,
|
|
57
|
-
validateIdentityPolicy,
|
|
58
|
-
} from "../identity/claim.mjs";
|
|
59
|
-
import { createSupabaseStorageTransfer } from "../identity/storage.mjs";
|
|
60
|
-
import {
|
|
61
|
-
acquireProjectOperation,
|
|
62
|
-
assertInstalledPackageFingerprint,
|
|
63
|
-
createInstalledPackageFingerprint,
|
|
64
|
-
} from "../shared/operation_guard.mjs";
|
|
65
|
-
import {
|
|
66
|
-
commandMutatesProject,
|
|
67
|
-
parseArguments,
|
|
68
|
-
resetGuidedFlags,
|
|
69
|
-
} from "./arguments.mjs";
|
|
70
|
-
import {
|
|
71
|
-
formatDuration,
|
|
72
|
-
installGuidedExitShortcut,
|
|
73
|
-
isHumanTerminal,
|
|
74
|
-
terminalStyle,
|
|
75
|
-
useStyledPrompts,
|
|
76
|
-
} from "./terminal.mjs";
|
|
77
|
-
import { createGuidedHome } from "./guided.mjs";
|
|
78
|
-
import {
|
|
79
|
-
buildRefreshWorkflowPlan,
|
|
80
|
-
createRefreshWorkflow,
|
|
81
|
-
loadPreparationContext,
|
|
82
|
-
runSourceAccess,
|
|
83
|
-
runSourceBaselineRefresh,
|
|
84
|
-
runSourceRetirement,
|
|
85
|
-
} from "./source_commands.mjs";
|
|
86
|
-
import {
|
|
87
|
-
buildRuntimeStackPlan,
|
|
88
|
-
createRuntimeCommands,
|
|
89
|
-
runRuntimeStackDoctor,
|
|
90
|
-
topologyCandidateSummary,
|
|
91
|
-
topologyCommandEnvironment,
|
|
92
|
-
topologyEnvironmentFiles,
|
|
93
|
-
} from "./runtime_commands.mjs";
|
|
94
|
-
import {
|
|
95
|
-
renderBaseline,
|
|
96
|
-
renderBaselineInputInspection,
|
|
97
|
-
renderBaselinePreparation,
|
|
98
|
-
renderCandidates,
|
|
99
|
-
renderCleanup,
|
|
100
|
-
renderDoctor,
|
|
101
|
-
formatBytes,
|
|
102
|
-
renderIdentityPlan,
|
|
103
|
-
renderInit,
|
|
104
|
-
renderMigrations,
|
|
105
|
-
renderPlan,
|
|
106
|
-
renderRefreshWorkflow,
|
|
107
|
-
renderSetup,
|
|
108
|
-
renderSourceAccessPlan,
|
|
109
|
-
renderSourceRetirement,
|
|
110
|
-
renderSupportReport,
|
|
111
|
-
} from "./renderers.mjs";
|
|
112
|
-
import { runRehearsalInit } from "./init_command.mjs";
|
|
113
|
-
|
|
114
|
-
const packageRoot = fileURLToPath(new URL("../..", import.meta.url));
|
|
115
|
-
const projectRoot = process.cwd();
|
|
116
|
-
let activePackageFingerprint = null;
|
|
117
|
-
const commandStartedAt = new Date();
|
|
118
|
-
const commandStartedMs = performance.now();
|
|
119
|
-
const managerPath = join(packageRoot, "scripts/runtime/manage_database.mjs");
|
|
120
|
-
let lastGuidedDetails;
|
|
121
|
-
|
|
122
|
-
const {
|
|
123
|
-
openRuntimeApplication,
|
|
124
|
-
prepareCandidateConfirmation,
|
|
125
|
-
prepareDependentTargets,
|
|
126
|
-
proveRuntimeStack,
|
|
127
|
-
runManager,
|
|
128
|
-
runRuntimeStack,
|
|
129
|
-
} = createRuntimeCommands({
|
|
130
|
-
packageRoot,
|
|
131
|
-
projectRoot,
|
|
132
|
-
managerPath,
|
|
133
|
-
getActivePackageFingerprint: () => activePackageFingerprint,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const emit = ({ command, data, flags, render, status = "success" }) => {
|
|
137
|
-
const result = createRehearsalResult({
|
|
138
|
-
command,
|
|
139
|
-
status,
|
|
140
|
-
data,
|
|
141
|
-
startedAt: commandStartedAt,
|
|
142
|
-
durationMs: Math.round((performance.now() - commandStartedMs) * 100) / 100,
|
|
143
|
-
});
|
|
144
|
-
if (flags.json) console.log(JSON.stringify(result, null, 2));
|
|
145
|
-
else console.log(render(data, flags.verbosity));
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const runSetup = async ({ flags, planOptions }) => {
|
|
149
|
-
const plan =
|
|
150
|
-
flags.setupPlan ??
|
|
151
|
-
(await planRehearsalSetup({
|
|
152
|
-
projectRoot,
|
|
153
|
-
configPath: planOptions.configPath,
|
|
154
|
-
target: flags.target,
|
|
155
|
-
}));
|
|
156
|
-
if (flags.write) await applyRehearsalSetup(plan);
|
|
157
|
-
const result = summarizeRehearsalSetup(plan, {
|
|
158
|
-
mode: flags.write ? "written" : "preview",
|
|
159
|
-
});
|
|
160
|
-
if (!flags.write) return result;
|
|
161
|
-
const readiness = await runRehearsalDoctor(planOptions);
|
|
162
|
-
const needsBaselinePolicy = readiness.checks.some(
|
|
163
|
-
(check) => check.id === "sanitization-policy" && check.status === "fail",
|
|
164
|
-
);
|
|
165
|
-
return {
|
|
166
|
-
...result,
|
|
167
|
-
readiness,
|
|
168
|
-
nextAction:
|
|
169
|
-
readiness.state === "READY"
|
|
170
|
-
? "Next: run rehearsal explain to review the migration plan."
|
|
171
|
-
: needsBaselinePolicy
|
|
172
|
-
? flags.guided
|
|
173
|
-
? "Next: choose Prepare the script to create a reviewable policy draft."
|
|
174
|
-
: "Next: run rehearsal again and choose Prepare a reviewable baseline policy draft."
|
|
175
|
-
: "Next: complete the remaining readiness items shown above.",
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const runBaselinePreparation = async ({ flags, planOptions }) => {
|
|
180
|
-
const plan =
|
|
181
|
-
flags.preparationPlan ??
|
|
182
|
-
(await planBaselinePreparation({
|
|
183
|
-
...planOptions,
|
|
184
|
-
recordsPath: flags.recordsPath,
|
|
185
|
-
ledgerPath: flags.ledgerPath,
|
|
186
|
-
}));
|
|
187
|
-
if (flags.write) await applyBaselinePreparation(plan);
|
|
188
|
-
const result = summarizeBaselinePreparation(plan, {
|
|
189
|
-
mode: flags.write ? "written" : "preview",
|
|
190
|
-
});
|
|
191
|
-
return flags.guided && flags.write
|
|
192
|
-
? {
|
|
193
|
-
...result,
|
|
194
|
-
nextAction:
|
|
195
|
-
"Next: choose Review the script to classify every column interactively.",
|
|
196
|
-
}
|
|
197
|
-
: result;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const planRuntimeStackCleanup = async ({ flags, planOptions }) => {
|
|
201
|
-
const topology = await loadRuntimeTopology(planOptions);
|
|
202
|
-
const targets = [];
|
|
203
|
-
for (const target of topology.targets) {
|
|
204
|
-
targets.push({
|
|
205
|
-
name: target.name,
|
|
206
|
-
configPath: target.configPath,
|
|
207
|
-
plan: await planRehearsalCleanup({
|
|
208
|
-
projectRoot: topology.projectRoot,
|
|
209
|
-
configPath: target.configPath,
|
|
210
|
-
includeRuntime: flags.includeRuntime,
|
|
211
|
-
includeImages: flags.includeImages && target.primary,
|
|
212
|
-
}),
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
if (targets.length === 1) return targets[0].plan;
|
|
216
|
-
return {
|
|
217
|
-
digest: createHash("sha256")
|
|
218
|
-
.update(
|
|
219
|
-
JSON.stringify(
|
|
220
|
-
targets.map((target) => ({
|
|
221
|
-
name: target.name,
|
|
222
|
-
digest: target.plan.digest,
|
|
223
|
-
})),
|
|
224
|
-
),
|
|
225
|
-
)
|
|
226
|
-
.digest("hex"),
|
|
227
|
-
targets,
|
|
228
|
-
};
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const runCleanup = async ({ flags, planOptions }) => {
|
|
232
|
-
const plan =
|
|
233
|
-
flags.cleanupPlan ??
|
|
234
|
-
(await planRuntimeStackCleanup({ flags, planOptions }));
|
|
235
|
-
if (!flags.write) return { mode: "preview", plan };
|
|
236
|
-
if (plan.targets) {
|
|
237
|
-
if (flags.cleanupConfirmation !== plan.digest) {
|
|
238
|
-
throw new Error(
|
|
239
|
-
"Cleanup requires the exact --confirm-cleanup digest from a fresh preview. Nothing was removed.",
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
for (const target of plan.targets) {
|
|
243
|
-
const refreshed = await planRehearsalCleanup({
|
|
244
|
-
projectRoot,
|
|
245
|
-
configPath: target.configPath,
|
|
246
|
-
includeRuntime: target.plan.runtime.included,
|
|
247
|
-
includeImages: target.plan.images.requested,
|
|
248
|
-
});
|
|
249
|
-
if (refreshed.digest !== target.plan.digest) {
|
|
250
|
-
throw new Error(
|
|
251
|
-
`Cleanup targets changed for ${target.name} after the preview. Nothing was removed; preview the cleanup again.`,
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
const appliedTargets = [];
|
|
256
|
-
for (const target of plan.targets) {
|
|
257
|
-
appliedTargets.push({
|
|
258
|
-
name: target.name,
|
|
259
|
-
applied: await applyRehearsalCleanup({
|
|
260
|
-
plan: target.plan,
|
|
261
|
-
confirmation: target.plan.digest,
|
|
262
|
-
projectRoot,
|
|
263
|
-
configPath: target.configPath,
|
|
264
|
-
removeRuntime: async () => {
|
|
265
|
-
runManager({
|
|
266
|
-
action: "discard",
|
|
267
|
-
flags,
|
|
268
|
-
configPath: target.configPath,
|
|
269
|
-
targetName: target.name,
|
|
270
|
-
});
|
|
271
|
-
},
|
|
272
|
-
}),
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
mode: "written",
|
|
277
|
-
plan,
|
|
278
|
-
applied: { targets: appliedTargets },
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
const applied = await applyRehearsalCleanup({
|
|
282
|
-
plan,
|
|
283
|
-
confirmation: flags.cleanupConfirmation,
|
|
284
|
-
...planOptions,
|
|
285
|
-
removeRuntime: async () => {
|
|
286
|
-
runManager({ action: "discard", flags });
|
|
287
|
-
},
|
|
288
|
-
});
|
|
289
|
-
return { mode: "written", plan, applied };
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
const loadIdentityClaimPlan = async ({ flags, planOptions }) => {
|
|
293
|
-
const loaded = await loadRehearsalConfig(planOptions);
|
|
294
|
-
if (!loaded.paths.identityPolicy) {
|
|
295
|
-
throw new Error("No config.identityPolicy is configured.");
|
|
296
|
-
}
|
|
297
|
-
if (!flags.identityName) {
|
|
298
|
-
throw new Error("Choose a declared identity with --identity=<name>.");
|
|
299
|
-
}
|
|
300
|
-
const policy = validateIdentityPolicy(
|
|
301
|
-
JSON.parse(await readFile(loaded.paths.identityPolicy, "utf8")),
|
|
302
|
-
);
|
|
303
|
-
return {
|
|
304
|
-
loaded,
|
|
305
|
-
plan: createIdentityClaimPlan({
|
|
306
|
-
policy,
|
|
307
|
-
name: flags.identityName,
|
|
308
|
-
}),
|
|
309
|
-
};
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
const usage = () => `Usage: rehearsal <command> [options]
|
|
313
|
-
|
|
314
|
-
Commands:
|
|
315
|
-
version Print the installed Rehearsal version
|
|
316
|
-
guide Open the interactive, state-aware home screen
|
|
317
|
-
setup [--target=] [--write] Preview or create safe first-run scaffolding
|
|
318
|
-
init [--write] Preview or explicitly write safe starter config
|
|
319
|
-
baseline prepare --records= --ledger= [--write] Create a fail-closed policy draft
|
|
320
|
-
baseline create --records= --ledger= [--assets=] Create a baseline from safe local inputs
|
|
321
|
-
privacy key [--write] Preview or create the owner-only pseudonym key
|
|
322
|
-
source plan Preview exact, temporary source access
|
|
323
|
-
source apply --confirm-source-access= Apply the reviewed source-access plan
|
|
324
|
-
source retire [--confirm-source-retirement=] Preview or retire exact source access
|
|
325
|
-
baseline refresh Replace only the baseline from a reviewed source
|
|
326
|
-
refresh [--confirm-refresh=] Replace the database copy, reset locally, and remove old copies
|
|
327
|
-
identity plan --identity= Preview an approved local identity association
|
|
328
|
-
identity claim --identity= --confirm-identity= Apply the exact local association
|
|
329
|
-
doctor Check whether Rehearsal is safe and ready
|
|
330
|
-
support Print a safe, copy-ready support report
|
|
331
|
-
explain Show the immutable execution plan
|
|
332
|
-
run --dry-run Alias the exact explain plan without mutations
|
|
333
|
-
run --confirm-candidates= Execute reset, migration, and verification locally
|
|
334
|
-
open Start the runtime and keep the application open
|
|
335
|
-
candidates Show the exact pending migration digest
|
|
336
|
-
inspect baseline Show verified baseline provenance
|
|
337
|
-
inspect migrations Classify represented, applied, and candidate migrations
|
|
338
|
-
start Start an existing verified local runtime
|
|
339
|
-
migrate --confirm-candidates= Apply the exact candidate suffix without resetting
|
|
340
|
-
reset Restore and verify the immutable local baseline
|
|
341
|
-
status Report the disposable local runtime state
|
|
342
|
-
stop Stop only this project's local runtime
|
|
343
|
-
discard Remove only this project's disposable runtime
|
|
344
|
-
cleanup [--include-runtime] [--include-images] [--write] [--confirm-cleanup=]
|
|
345
|
-
Preview or apply conservative disk cleanup
|
|
346
|
-
verify Verify the current local Rehearsal runtime
|
|
347
|
-
|
|
348
|
-
Options: --help, -h --version, -V --json --verbose --debug --plain
|
|
349
|
-
--config=<path> --target=supabase|postgresql
|
|
350
|
-
--confirm-source-access=<digest> --confirm-source-retirement=<digest>
|
|
351
|
-
--confirm-refresh=<digest>`;
|
|
352
|
-
|
|
353
|
-
const runRefreshWorkflow = createRefreshWorkflow({
|
|
354
|
-
runRuntimeStack,
|
|
355
|
-
prepareDependentTargets,
|
|
356
|
-
topologyCommandEnvironment,
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
const runGuidedHome = createGuidedHome({
|
|
360
|
-
projectRoot,
|
|
361
|
-
topologyCandidateSummary,
|
|
362
|
-
buildRefreshWorkflowPlan,
|
|
363
|
-
planRuntimeStackCleanup,
|
|
364
|
-
getLastGuidedDetails: () => lastGuidedDetails,
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
const executeCommand = async ({ command, flags, planOptions, guided }) => {
|
|
368
|
-
if (command === "version" || flags.version) {
|
|
369
|
-
if (flags.json) {
|
|
370
|
-
console.log(
|
|
371
|
-
JSON.stringify(
|
|
372
|
-
{ name: "@rehearsal-db/core", version: REHEARSAL_VERSION },
|
|
373
|
-
null,
|
|
374
|
-
2,
|
|
375
|
-
),
|
|
376
|
-
);
|
|
377
|
-
} else console.log(REHEARSAL_VERSION);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
if (command === "help" || flags.help) {
|
|
381
|
-
console.log(usage());
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
if (command === "setup") {
|
|
385
|
-
const data = await runSetup({ flags, planOptions });
|
|
386
|
-
emit({ command, data, flags, render: renderSetup });
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
if (command === "init") {
|
|
390
|
-
const data = await runRehearsalInit({ projectRoot, flags });
|
|
391
|
-
emit({ command, data, flags, render: renderInit });
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
if (command === "baseline prepare") {
|
|
395
|
-
const data = await runBaselinePreparation({ flags, planOptions });
|
|
396
|
-
emit({
|
|
397
|
-
command,
|
|
398
|
-
data,
|
|
399
|
-
flags,
|
|
400
|
-
render: (result) => renderBaselinePreparation(result, flags),
|
|
401
|
-
});
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
if (command === "baseline create") {
|
|
405
|
-
await inspectBaselineInputFiles({
|
|
406
|
-
...planOptions,
|
|
407
|
-
recordsPath: flags.recordsPath,
|
|
408
|
-
ledgerPath: flags.ledgerPath,
|
|
409
|
-
assetsPath: flags.assetsPath,
|
|
410
|
-
});
|
|
411
|
-
const data = await createSyntheticBaselineFromFiles({
|
|
412
|
-
...planOptions,
|
|
413
|
-
recordsPath: flags.recordsPath,
|
|
414
|
-
ledgerPath: flags.ledgerPath,
|
|
415
|
-
assetsPath: flags.assetsPath,
|
|
416
|
-
});
|
|
417
|
-
emit({
|
|
418
|
-
command,
|
|
419
|
-
data,
|
|
420
|
-
flags,
|
|
421
|
-
render: (baseline) =>
|
|
422
|
-
[
|
|
423
|
-
`Activated synthetic baseline ${baseline.generationId}: ${formatCount(baseline.rowCount, "row")} across ${formatCount(baseline.tableCount, "table")}; ${formatCount(baseline.migrationCount, "migration")} through ${baseline.migrationCutoff}.`,
|
|
424
|
-
"",
|
|
425
|
-
flags.guided
|
|
426
|
-
? "Next: choose Run a rehearsal when you are ready."
|
|
427
|
-
: "Next: run rehearsal doctor to check readiness.",
|
|
428
|
-
].join("\n"),
|
|
429
|
-
});
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
if (command === "privacy key") {
|
|
433
|
-
const { loaded } = await loadPreparationContext(planOptions);
|
|
434
|
-
const data = flags.write
|
|
435
|
-
? {
|
|
436
|
-
mode: "written",
|
|
437
|
-
path: relative(loaded.projectRoot, loaded.paths.privacyKey),
|
|
438
|
-
...(await createPrivacyKey(loaded.paths.privacyKey)),
|
|
439
|
-
}
|
|
440
|
-
: {
|
|
441
|
-
mode: "preview",
|
|
442
|
-
path: relative(loaded.projectRoot, loaded.paths.privacyKey),
|
|
443
|
-
};
|
|
444
|
-
emit({
|
|
445
|
-
command,
|
|
446
|
-
data,
|
|
447
|
-
flags,
|
|
448
|
-
render: (result) =>
|
|
449
|
-
result.mode === "preview"
|
|
450
|
-
? `PRIVACY KEY — PREVIEW\n\nWould create ${result.path} with owner-only permissions.\nNothing was written. Rerun with --write after reviewing the path.`
|
|
451
|
-
: `Created owner-only privacy key at ${result.path}.\nFingerprint: ${result.fingerprint}\nThe key is excluded from source control and must not be shared.`,
|
|
452
|
-
});
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
if (command === "source plan") {
|
|
456
|
-
const { sourcePolicy } = await loadPreparationContext(planOptions);
|
|
457
|
-
const data = createSourceAccessPlan({ policy: sourcePolicy });
|
|
458
|
-
emit({ command, data, flags, render: renderSourceAccessPlan });
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
if (command === "source apply") {
|
|
462
|
-
const data = await runSourceAccess({ flags, planOptions });
|
|
463
|
-
emit({
|
|
464
|
-
command,
|
|
465
|
-
data,
|
|
466
|
-
flags,
|
|
467
|
-
render: (result) =>
|
|
468
|
-
result.mode === "preview"
|
|
469
|
-
? renderSourceAccessPlan(result.plan)
|
|
470
|
-
: [
|
|
471
|
-
"SOURCE ACCESS — READY",
|
|
472
|
-
`${result.receipt.accessMode === "external" ? "External" : "Temporary"} reader expires: ${result.receipt.expiresAt}`,
|
|
473
|
-
result.receipt.accessMode === "external"
|
|
474
|
-
? "Rehearsal made no source-side changes."
|
|
475
|
-
: "Rehearsal created only the reviewed temporary source access.",
|
|
476
|
-
`Local credential: ${result.credentialFile}`,
|
|
477
|
-
"",
|
|
478
|
-
"Next: run rehearsal baseline refresh, then retire source access.",
|
|
479
|
-
].join("\n"),
|
|
480
|
-
});
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
if (command === "source retire") {
|
|
484
|
-
const data = await runSourceRetirement({ flags, planOptions });
|
|
485
|
-
emit({ command, data, flags, render: renderSourceRetirement });
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
if (command === "baseline refresh") {
|
|
489
|
-
const data = await runSourceBaselineRefresh({ planOptions });
|
|
490
|
-
emit({
|
|
491
|
-
command,
|
|
492
|
-
data,
|
|
493
|
-
flags,
|
|
494
|
-
render: (result) =>
|
|
495
|
-
[
|
|
496
|
-
`Activated refreshed baseline ${result.generationId}.`,
|
|
497
|
-
`${formatCount(result.manifest.rowCount, "sanitized row")} across ${formatCount(Object.keys(result.manifest.tableCounts).length, "table")}.`,
|
|
498
|
-
`Source estimate: ${formatCount(result.estimate.rows, "row")}, ${formatBytes(result.estimate.bytes)}.`,
|
|
499
|
-
"",
|
|
500
|
-
"Next: run rehearsal source retire, then rehearsal doctor.",
|
|
501
|
-
].join("\n"),
|
|
502
|
-
});
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
if (command === "refresh") {
|
|
506
|
-
const data = await runRefreshWorkflow({ flags, planOptions });
|
|
507
|
-
emit({ command, data, flags, render: renderRefreshWorkflow });
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
if (command === "identity plan" || command === "identity claim") {
|
|
511
|
-
const { loaded, plan } = await loadIdentityClaimPlan({
|
|
512
|
-
flags,
|
|
513
|
-
planOptions,
|
|
514
|
-
});
|
|
515
|
-
if (command === "identity plan" || !flags.identityConfirmation) {
|
|
516
|
-
emit({
|
|
517
|
-
command,
|
|
518
|
-
data: { mode: "preview", plan },
|
|
519
|
-
flags,
|
|
520
|
-
render: renderIdentityPlan,
|
|
521
|
-
});
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
const runtimeEnvironment = parseEnv(
|
|
525
|
-
await readFile(loaded.paths.applicationEnvironment, "utf8"),
|
|
526
|
-
);
|
|
527
|
-
if (!runtimeEnvironment.DATABASE_URL) {
|
|
528
|
-
throw new Error("The local runtime environment has no DATABASE_URL.");
|
|
529
|
-
}
|
|
530
|
-
const result = await applyIdentityClaim({
|
|
531
|
-
plan,
|
|
532
|
-
confirmation: flags.identityConfirmation,
|
|
533
|
-
connectionString: runtimeEnvironment.DATABASE_URL,
|
|
534
|
-
storageTransfer: plan.identity.assets.some((asset) => asset.rewritePath)
|
|
535
|
-
? createSupabaseStorageTransfer({
|
|
536
|
-
url: runtimeEnvironment.SUPABASE_URL,
|
|
537
|
-
serviceRoleKey: runtimeEnvironment.SUPABASE_SERVICE_ROLE_KEY,
|
|
538
|
-
})
|
|
539
|
-
: undefined,
|
|
540
|
-
});
|
|
541
|
-
emit({
|
|
542
|
-
command,
|
|
543
|
-
data: { mode: "written", plan, result },
|
|
544
|
-
flags,
|
|
545
|
-
render: renderIdentityPlan,
|
|
546
|
-
});
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
if (command === "doctor") {
|
|
550
|
-
const data = await runRuntimeStackDoctor(planOptions);
|
|
551
|
-
emit({
|
|
552
|
-
command,
|
|
553
|
-
data,
|
|
554
|
-
flags,
|
|
555
|
-
render: renderDoctor,
|
|
556
|
-
status: data.state === "READY" ? "success" : "not_ready",
|
|
557
|
-
});
|
|
558
|
-
if (data.state !== "READY" && !guided) process.exitCode = 1;
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
|
-
if (command === "support") {
|
|
562
|
-
const data = await collectRehearsalSupportReport(planOptions, {
|
|
563
|
-
runDoctor: async (options) => {
|
|
564
|
-
const report = await runRuntimeStackDoctor(options);
|
|
565
|
-
const targetAliases = new Map();
|
|
566
|
-
const aliasFor = (name) => {
|
|
567
|
-
if (!targetAliases.has(name)) {
|
|
568
|
-
targetAliases.set(name, `runtime-${targetAliases.size + 1}`);
|
|
569
|
-
}
|
|
570
|
-
return targetAliases.get(name);
|
|
571
|
-
};
|
|
572
|
-
return {
|
|
573
|
-
...report,
|
|
574
|
-
checks: report.checks.map((check) => {
|
|
575
|
-
const separator = check.id.indexOf(":");
|
|
576
|
-
if (separator === -1) return check;
|
|
577
|
-
const target = check.id.slice(0, separator);
|
|
578
|
-
const alias = aliasFor(target);
|
|
579
|
-
return {
|
|
580
|
-
...check,
|
|
581
|
-
id: `${alias}:${check.id.slice(separator + 1)}`,
|
|
582
|
-
label: check.label.replace(`${target}:`, `${alias}:`),
|
|
583
|
-
};
|
|
584
|
-
}),
|
|
585
|
-
};
|
|
586
|
-
},
|
|
587
|
-
});
|
|
588
|
-
emit({ command, data, flags, render: renderSupportReport });
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
if (command === "cleanup") {
|
|
592
|
-
const data = await runCleanup({ flags, planOptions });
|
|
593
|
-
emit({ command, data, flags, render: renderCleanup });
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
if (command === "explain" || (command === "run" && flags.dryRun)) {
|
|
597
|
-
const data = await buildRuntimeStackPlan(planOptions);
|
|
598
|
-
emit({ command, data, flags, render: renderPlan });
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
if (command === "inspect baseline") {
|
|
602
|
-
const data = await inspectRehearsalBaseline(planOptions);
|
|
603
|
-
emit({ command, data, flags, render: renderBaseline });
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
if (command === "inspect migrations") {
|
|
607
|
-
const data = await inspectRehearsalMigrations(planOptions);
|
|
608
|
-
emit({ command, data, flags, render: renderMigrations });
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
if (command === "candidates") {
|
|
612
|
-
const { topology: _topology, ...data } =
|
|
613
|
-
await topologyCandidateSummary(planOptions);
|
|
614
|
-
emit({ command, data, flags, render: renderCandidates });
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
if (command === "open") {
|
|
618
|
-
if (flags.dryRun) {
|
|
619
|
-
throw new Error("--dry-run is supported only by rehearsal run.");
|
|
620
|
-
}
|
|
621
|
-
const data = await openRuntimeApplication({
|
|
622
|
-
flags,
|
|
623
|
-
planOptions,
|
|
624
|
-
onReady: (ready) => {
|
|
625
|
-
const lines = [
|
|
626
|
-
`Application: ${ready.url}`,
|
|
627
|
-
"The verified database runtime stays running and keeps your local changes.",
|
|
628
|
-
guided
|
|
629
|
-
? "Press Ctrl+C to close the app and return here, or Ctrl+Z to exit Rehearsal."
|
|
630
|
-
: "Press Ctrl+C or Ctrl+Z to close the app. Rehearsal will leave the database runtime running.",
|
|
631
|
-
];
|
|
632
|
-
if (useStyledPrompts(flags)) {
|
|
633
|
-
prompts.note(lines.join("\n"), "SANDBOX READY");
|
|
634
|
-
} else if (!flags.json) {
|
|
635
|
-
console.log(["", "SANDBOX READY", ...lines, ""].join("\n"));
|
|
636
|
-
}
|
|
637
|
-
},
|
|
638
|
-
});
|
|
639
|
-
if (guided && data.application.stoppedBy === "SIGTSTP") {
|
|
640
|
-
flags.exitGuidedSession = true;
|
|
641
|
-
}
|
|
642
|
-
if (guided) {
|
|
643
|
-
lastGuidedDetails = [
|
|
644
|
-
data.started.output,
|
|
645
|
-
data.verified.output,
|
|
646
|
-
...data.preparations.map((preparation) => preparation.output),
|
|
647
|
-
]
|
|
648
|
-
.filter(Boolean)
|
|
649
|
-
.join("\n");
|
|
650
|
-
}
|
|
651
|
-
emit({
|
|
652
|
-
command,
|
|
653
|
-
data,
|
|
654
|
-
flags,
|
|
655
|
-
render: (result) =>
|
|
656
|
-
[
|
|
657
|
-
"SANDBOX APP CLOSED",
|
|
658
|
-
`Application stopped after ${result.application.stoppedBy}.`,
|
|
659
|
-
"The database runtime and its local database and Storage changes were preserved.",
|
|
660
|
-
"Run rehearsal open to return, rehearsal verify to check it, or rehearsal stop to stop the databases.",
|
|
661
|
-
].join("\n"),
|
|
662
|
-
});
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
if (
|
|
666
|
-
[
|
|
667
|
-
"run",
|
|
668
|
-
"start",
|
|
669
|
-
"migrate",
|
|
670
|
-
"reset",
|
|
671
|
-
"status",
|
|
672
|
-
"stop",
|
|
673
|
-
"discard",
|
|
674
|
-
"verify",
|
|
675
|
-
].includes(command)
|
|
676
|
-
) {
|
|
677
|
-
if (flags.dryRun && command !== "run") {
|
|
678
|
-
throw new Error("--dry-run is supported only by rehearsal run.");
|
|
679
|
-
}
|
|
680
|
-
if (
|
|
681
|
-
!(await prepareCandidateConfirmation({ command, flags, planOptions }))
|
|
682
|
-
) {
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
const stack = await runRuntimeStack({ command, flags, planOptions });
|
|
686
|
-
const { runtime, topology } = stack;
|
|
687
|
-
const stackEnvironment = topologyCommandEnvironment(topology);
|
|
688
|
-
const preparations = ["run", "reset", "migrate"].includes(command)
|
|
689
|
-
? prepareDependentTargets({
|
|
690
|
-
topology,
|
|
691
|
-
environment: stackEnvironment,
|
|
692
|
-
})
|
|
693
|
-
: [];
|
|
694
|
-
let applicationProof;
|
|
695
|
-
let dependentProofs = [];
|
|
696
|
-
let httpProofResults = [];
|
|
697
|
-
let applicationReadiness;
|
|
698
|
-
if (command === "run") {
|
|
699
|
-
const applicationConfig = topology.primary.config.application;
|
|
700
|
-
const mappedApplicationEnvironment = Object.keys(
|
|
701
|
-
applicationConfig.environmentVariables,
|
|
702
|
-
).length
|
|
703
|
-
? await buildApplicationEnvironment({
|
|
704
|
-
files: topologyEnvironmentFiles(topology),
|
|
705
|
-
mappings: applicationConfig.environmentVariables,
|
|
706
|
-
})
|
|
707
|
-
: {};
|
|
708
|
-
const proofEnvironment = {
|
|
709
|
-
...stackEnvironment,
|
|
710
|
-
...mappedApplicationEnvironment,
|
|
711
|
-
};
|
|
712
|
-
const proofLabel =
|
|
713
|
-
topology.targets.length > 1
|
|
714
|
-
? "project-owned dependent and application proofs"
|
|
715
|
-
: "project-owned application proof";
|
|
716
|
-
const proofSpinner = useStyledPrompts(flags) ? prompts.spinner() : null;
|
|
717
|
-
if (proofSpinner) {
|
|
718
|
-
proofSpinner.start(`Running the ${proofLabel}.`);
|
|
719
|
-
} else if (isHumanTerminal(flags)) {
|
|
720
|
-
console.log(
|
|
721
|
-
`${terminalStyle(flags, "36", "→")} Running the ${proofLabel}.`,
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
let applicationSession;
|
|
725
|
-
try {
|
|
726
|
-
if (applicationConfig.readiness) {
|
|
727
|
-
applicationSession = await startApplicationSession({
|
|
728
|
-
command: applicationConfig.startCommand,
|
|
729
|
-
cwd: topology.projectRoot,
|
|
730
|
-
files: topologyEnvironmentFiles(topology),
|
|
731
|
-
mappings: applicationConfig.environmentVariables,
|
|
732
|
-
readiness: applicationConfig.readiness,
|
|
733
|
-
});
|
|
734
|
-
applicationReadiness = applicationSession.ready;
|
|
735
|
-
}
|
|
736
|
-
({ applicationProof, dependentProofs } = await proveRuntimeStack({
|
|
737
|
-
topology,
|
|
738
|
-
planOptions,
|
|
739
|
-
environment: proofEnvironment,
|
|
740
|
-
}));
|
|
741
|
-
if (applicationConfig.httpProofs.length) {
|
|
742
|
-
httpProofResults = await runHttpProofs({
|
|
743
|
-
checks: applicationConfig.httpProofs,
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
} catch (error) {
|
|
747
|
-
if (proofSpinner) proofSpinner.stop("A project proof failed.");
|
|
748
|
-
throw error;
|
|
749
|
-
} finally {
|
|
750
|
-
await applicationSession?.stop();
|
|
751
|
-
}
|
|
752
|
-
if (proofSpinner) {
|
|
753
|
-
proofSpinner.stop("Project proofs passed.");
|
|
754
|
-
} else if (isHumanTerminal(flags)) {
|
|
755
|
-
console.log(
|
|
756
|
-
`${terminalStyle(flags, "32", "✓")} Project proofs passed.`,
|
|
757
|
-
);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
const data =
|
|
761
|
-
command === "run"
|
|
762
|
-
? {
|
|
763
|
-
runtime,
|
|
764
|
-
preparations,
|
|
765
|
-
dependentProofs,
|
|
766
|
-
applicationProof,
|
|
767
|
-
applicationReadiness,
|
|
768
|
-
httpProofResults,
|
|
769
|
-
}
|
|
770
|
-
: preparations.length
|
|
771
|
-
? { ...runtime, preparations }
|
|
772
|
-
: runtime;
|
|
773
|
-
if (guided) {
|
|
774
|
-
lastGuidedDetails = [
|
|
775
|
-
runtime.output,
|
|
776
|
-
...preparations.map((preparation) => preparation.output),
|
|
777
|
-
...dependentProofs.map((proof) => proof.output),
|
|
778
|
-
applicationProof?.output,
|
|
779
|
-
]
|
|
780
|
-
.filter(Boolean)
|
|
781
|
-
.join("\n");
|
|
782
|
-
}
|
|
783
|
-
emit({
|
|
784
|
-
command,
|
|
785
|
-
data,
|
|
786
|
-
flags,
|
|
787
|
-
render: (value) => {
|
|
788
|
-
const runtimeResult = value.runtime ?? value;
|
|
789
|
-
const nextAction = {
|
|
790
|
-
run: "Next: run rehearsal open for hands-on testing, then rehearsal verify.",
|
|
791
|
-
start:
|
|
792
|
-
"Next: run rehearsal open for hands-on testing or rehearsal status.",
|
|
793
|
-
migrate: "Next: run rehearsal verify to prove the current runtime.",
|
|
794
|
-
reset: "Next: run rehearsal open or rehearsal verify.",
|
|
795
|
-
status: "Next: run rehearsal verify, reset, stop, or discard.",
|
|
796
|
-
stop: "Next: run rehearsal start when you want to resume.",
|
|
797
|
-
discard:
|
|
798
|
-
"The disposable runtime was removed; the immutable baseline remains.",
|
|
799
|
-
verify:
|
|
800
|
-
"Next: continue testing, reset to the baseline, or stop the runtime.",
|
|
801
|
-
}[runtimeResult.action];
|
|
802
|
-
if (guided) {
|
|
803
|
-
const title =
|
|
804
|
-
runtimeResult.action === "run"
|
|
805
|
-
? "REHEARSAL PASSED"
|
|
806
|
-
: "ACTION COMPLETE";
|
|
807
|
-
return [
|
|
808
|
-
title,
|
|
809
|
-
`✓ ${runtimeResult.action} completed in ${formatDuration(runtimeResult.durationMs)}`,
|
|
810
|
-
...(value.preparations ?? []).map(
|
|
811
|
-
(preparation) =>
|
|
812
|
-
`✓ ${preparation.target} preparation passed: ${preparation.command}`,
|
|
813
|
-
),
|
|
814
|
-
...(value.dependentProofs ?? []).map(
|
|
815
|
-
(proof) => `✓ ${proof.target} proof passed: ${proof.command}`,
|
|
816
|
-
),
|
|
817
|
-
value.applicationProof
|
|
818
|
-
? `✓ Application proof passed: ${value.applicationProof.command}`
|
|
819
|
-
: null,
|
|
820
|
-
value.applicationReadiness
|
|
821
|
-
? `✓ Application became ready at ${value.applicationReadiness.url}`
|
|
822
|
-
: null,
|
|
823
|
-
...(value.httpProofResults ?? []).map(
|
|
824
|
-
(proof) => `✓ ${proof.kind} HTTP proof passed: ${proof.name}`,
|
|
825
|
-
),
|
|
826
|
-
"",
|
|
827
|
-
"Technical output is available from Show details in the guide.",
|
|
828
|
-
]
|
|
829
|
-
.filter(Boolean)
|
|
830
|
-
.join("\n");
|
|
831
|
-
}
|
|
832
|
-
return [
|
|
833
|
-
runtimeResult.output ||
|
|
834
|
-
`Rehearsal ${runtimeResult.action} completed.`,
|
|
835
|
-
...(value.preparations ?? []).map(
|
|
836
|
-
(preparation) =>
|
|
837
|
-
`${preparation.target} preparation passed: ${preparation.command}`,
|
|
838
|
-
),
|
|
839
|
-
...(value.dependentProofs ?? []).map(
|
|
840
|
-
(proof) => `${proof.target} proof passed: ${proof.command}`,
|
|
841
|
-
),
|
|
842
|
-
value.applicationProof
|
|
843
|
-
? `Application proof passed: ${value.applicationProof.command}`
|
|
844
|
-
: null,
|
|
845
|
-
value.applicationReadiness
|
|
846
|
-
? `Application readiness passed: ${value.applicationReadiness.url}`
|
|
847
|
-
: null,
|
|
848
|
-
...(value.httpProofResults ?? []).map(
|
|
849
|
-
(proof) => `${proof.kind} HTTP proof passed: ${proof.name}`,
|
|
850
|
-
),
|
|
851
|
-
nextAction ? "" : null,
|
|
852
|
-
nextAction,
|
|
853
|
-
]
|
|
854
|
-
.filter((entry) => entry !== null)
|
|
855
|
-
.join("\n");
|
|
856
|
-
},
|
|
857
|
-
});
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
860
|
-
throw new Error(`Unknown Rehearsal command: ${command}.\n\n${usage()}`);
|
|
861
|
-
};
|
|
862
|
-
|
|
863
|
-
const main = async () => {
|
|
864
|
-
const { flags, positionals } = parseArguments(process.argv.slice(2));
|
|
865
|
-
const command = positionals.join(" ") || "help";
|
|
866
|
-
const planOptions = {
|
|
867
|
-
projectRoot,
|
|
868
|
-
configPath: flags.configPath,
|
|
869
|
-
};
|
|
870
|
-
const wantsAutomaticGuide =
|
|
871
|
-
positionals.length === 0 &&
|
|
872
|
-
!flags.help &&
|
|
873
|
-
!flags.json &&
|
|
874
|
-
process.stdin.isTTY &&
|
|
875
|
-
process.stdout.isTTY;
|
|
876
|
-
const guided = command === "guide" || wantsAutomaticGuide;
|
|
877
|
-
const mutating = commandMutatesProject({ command, flags, guided });
|
|
878
|
-
const operation = mutating
|
|
879
|
-
? await acquireProjectOperation({ projectRoot, command })
|
|
880
|
-
: null;
|
|
881
|
-
if (operation) {
|
|
882
|
-
activePackageFingerprint = createInstalledPackageFingerprint({
|
|
883
|
-
packageRoot,
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
try {
|
|
887
|
-
if (!guided) {
|
|
888
|
-
await executeCommand({ command, flags, planOptions, guided: false });
|
|
889
|
-
return;
|
|
890
|
-
}
|
|
891
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
892
|
-
throw new Error(
|
|
893
|
-
"The guided home screen requires an interactive terminal. Run rehearsal --help to list scriptable commands.",
|
|
894
|
-
);
|
|
895
|
-
}
|
|
896
|
-
flags.guided = true;
|
|
897
|
-
const installExitShortcut = () =>
|
|
898
|
-
installGuidedExitShortcut(flags, {
|
|
899
|
-
beforeExit: () => operation?.releaseSync(),
|
|
900
|
-
});
|
|
901
|
-
let removeGuidedExitShortcut = installExitShortcut();
|
|
902
|
-
if (useStyledPrompts(flags)) {
|
|
903
|
-
prompts.intro("REHEARSAL · Safe local migration testing");
|
|
904
|
-
}
|
|
905
|
-
try {
|
|
906
|
-
while (true) {
|
|
907
|
-
resetGuidedFlags(flags);
|
|
908
|
-
const selected = await runGuidedHome({ flags, planOptions });
|
|
909
|
-
if (!selected) break;
|
|
910
|
-
if (selected === "home") continue;
|
|
911
|
-
const opensApplication = selected === "open";
|
|
912
|
-
if (opensApplication) {
|
|
913
|
-
removeGuidedExitShortcut();
|
|
914
|
-
removeGuidedExitShortcut = null;
|
|
915
|
-
}
|
|
916
|
-
try {
|
|
917
|
-
await executeCommand({
|
|
918
|
-
command: selected,
|
|
919
|
-
flags,
|
|
920
|
-
planOptions,
|
|
921
|
-
guided: true,
|
|
922
|
-
});
|
|
923
|
-
} finally {
|
|
924
|
-
if (opensApplication) {
|
|
925
|
-
removeGuidedExitShortcut = installExitShortcut();
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
if (flags.exitGuidedSession) break;
|
|
929
|
-
}
|
|
930
|
-
} finally {
|
|
931
|
-
removeGuidedExitShortcut?.();
|
|
932
|
-
}
|
|
933
|
-
if (useStyledPrompts(flags)) {
|
|
934
|
-
prompts.outro("See you at the next rehearsal.");
|
|
935
|
-
} else {
|
|
936
|
-
console.log("See you at the next rehearsal.");
|
|
937
|
-
}
|
|
938
|
-
} finally {
|
|
939
|
-
if (operation) {
|
|
940
|
-
try {
|
|
941
|
-
assertInstalledPackageFingerprint({
|
|
942
|
-
packageRoot,
|
|
943
|
-
expected: activePackageFingerprint,
|
|
944
|
-
});
|
|
945
|
-
} finally {
|
|
946
|
-
activePackageFingerprint = null;
|
|
947
|
-
await operation.release();
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
try {
|
|
954
|
-
await main();
|
|
955
|
-
} catch (error) {
|
|
956
|
-
const failure = normalizeRehearsalError(error, {
|
|
957
|
-
expected: "a safe, versioned, local-only Rehearsal operation",
|
|
958
|
-
actual: String(error?.message ?? error),
|
|
959
|
-
refused: "No further Rehearsal action was performed.",
|
|
960
|
-
suggestions: ["Run rehearsal doctor for actionable readiness checks."],
|
|
961
|
-
});
|
|
962
|
-
const wantsJson = process.argv.includes("--json");
|
|
963
|
-
const debug = process.argv.includes("--debug");
|
|
964
|
-
if (wantsJson)
|
|
965
|
-
console.log(
|
|
966
|
-
JSON.stringify(serializeRehearsalError(failure, { debug }), null, 2),
|
|
967
|
-
);
|
|
968
|
-
else console.error(renderHumanError(failure, { debug }));
|
|
969
|
-
process.exitCode = failure.exitCode;
|
|
970
|
-
}
|