@rehearsal-db/core 0.1.0-beta.1 → 0.1.0-beta.10

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +244 -1
  2. package/COMPATIBILITY.md +17 -0
  3. package/README.md +139 -346
  4. package/SECURITY.md +2 -1
  5. package/SUPPORT.md +5 -0
  6. package/docs/README.md +29 -0
  7. package/docs/adapters.md +20 -6
  8. package/docs/architecture.md +58 -0
  9. package/docs/baselines.md +102 -22
  10. package/docs/commands.md +196 -33
  11. package/docs/configuration.md +258 -13
  12. package/docs/getting-started.md +106 -182
  13. package/docs/glossary.md +11 -8
  14. package/docs/production-source.md +176 -33
  15. package/docs/releasing.md +28 -38
  16. package/docs/roadmap.md +41 -0
  17. package/docs/runtime-policies.md +193 -0
  18. package/docs/sanitization.md +43 -8
  19. package/docs/security-model.md +34 -9
  20. package/docs/standalone-workflow.md +107 -0
  21. package/docs/troubleshooting.md +102 -2
  22. package/docs/tutorial.md +70 -59
  23. package/package.json +30 -22
  24. package/scripts/runtime/manage_database.mjs +18 -0
  25. package/src/README.md +17 -0
  26. package/src/application/session.mjs +435 -0
  27. package/{scripts/lib/rehearsal/baseline_artifact.mjs → src/baseline/artifact.mjs} +142 -17
  28. package/{scripts/lib/rehearsal/baseline_builder.mjs → src/baseline/builder.mjs} +19 -10
  29. package/src/baseline/input_discovery.mjs +155 -0
  30. package/src/baseline/policy_review.mjs +92 -0
  31. package/src/baseline/preparation.mjs +323 -0
  32. package/src/baseline/privacy_engine.mjs +413 -0
  33. package/{scripts/lib/rehearsal → src/baseline}/sanitization_policy.mjs +133 -3
  34. package/{scripts/lib/rehearsal → src/baseline}/schema_snapshot.mjs +1 -1
  35. package/src/cli/arguments.mjs +123 -0
  36. package/src/cli/guided.mjs +812 -0
  37. package/src/cli/rehearsal.mjs +997 -0
  38. package/src/cli/renderers.mjs +584 -0
  39. package/src/cli/runtime_commands.mjs +624 -0
  40. package/src/cli/source_commands.mjs +326 -0
  41. package/src/cli/terminal.mjs +275 -0
  42. package/src/identity/claim.mjs +975 -0
  43. package/src/identity/storage.mjs +165 -0
  44. package/{scripts/lib/rehearsal → src/project}/configuration.d.mts +72 -4
  45. package/src/project/configuration.mjs +1199 -0
  46. package/src/project/setup.mjs +379 -0
  47. package/src/project/support_report.mjs +105 -0
  48. package/src/runtime/cleanup.mjs +381 -0
  49. package/{scripts/lib/rehearsal → src/runtime}/plan.mjs +118 -20
  50. package/src/runtime/policy.mjs +438 -0
  51. package/{scripts/lib/rehearsal/runtime_restore.mjs → src/runtime/restore.mjs} +46 -27
  52. package/src/runtime/topology.mjs +177 -0
  53. package/{scripts/lib/rehearsal → src/shared}/diagnostics.mjs +10 -3
  54. package/src/shared/human_output.mjs +4 -0
  55. package/src/shared/operation_guard.mjs +162 -0
  56. package/{scripts/lib/rehearsal → src/shared}/process_environment.mjs +5 -1
  57. package/src/source/access.mjs +578 -0
  58. package/src/source/asset_transfer.mjs +177 -0
  59. package/src/source/baseline.mjs +446 -0
  60. package/src/source/postgresql_access.mjs +480 -0
  61. package/src/targets/postgresql.mjs +808 -0
  62. package/{scripts/operations/database/manage_rehearsal_database.mjs → src/targets/supabase.mjs} +66 -20
  63. package/{scripts/lib/environment/local_supabase.mjs → src/targets/supabase_environment.mjs} +60 -28
  64. package/src/targets/target.mjs +66 -0
  65. package/scripts/lib/rehearsal/configuration.mjs +0 -559
  66. package/scripts/operations/rehearsal/rehearsal_cli.mjs +0 -565
  67. /package/{scripts/lib/rehearsal → src/runtime}/migration_history.mjs +0 -0
  68. /package/{scripts/lib/rehearsal → src/runtime}/service_environment.mjs +0 -0
@@ -1,14 +1,93 @@
1
1
  # Troubleshooting
2
2
 
3
+ Start with:
4
+
5
+ ```bash
6
+ npx rehearsal doctor
7
+ ```
8
+
9
+ Doctor names each missing or unsafe item. If you still need help, run
10
+ `npx rehearsal support`, review the report, and attach it to a GitHub issue.
11
+
12
+ ## `npx rehearsal` cannot find the command
13
+
14
+ Confirm you are in the project directory and install the beta locally:
15
+
16
+ ```bash
17
+ npm install --save-dev @rehearsal-db/core@beta
18
+ npx rehearsal --help
19
+ ```
20
+
21
+ Do not use `sudo` or require a global install.
22
+
23
+ ## Setup says Node.js 24 is required
24
+
25
+ Rehearsal intentionally supports one maintained Node.js major in its first beta. Switch
26
+ the current shell before installing or running it. With nvm:
27
+
28
+ ```bash
29
+ nvm install 24
30
+ nvm use 24
31
+ node --version
32
+ ```
33
+
34
+ Then reinstall Rehearsal in the consuming project. The guided CLI checks this before it
35
+ writes setup files.
36
+
3
37
  ## Doctor says Docker is unavailable
4
38
 
5
39
  Start Docker Desktop or Colima, confirm `docker info`, then rerun `rehearsal doctor`.
6
40
  Restarting the computer is rarely necessary.
7
41
 
42
+ ## Docker or Colima is out of disk space
43
+
44
+ Preview what Rehearsal can safely remove:
45
+
46
+ ```bash
47
+ npx rehearsal cleanup --include-images
48
+ ```
49
+
50
+ Review the list, then add `--write` and the printed `--confirm-cleanup` digest. Rehearsal
51
+ keeps the newest Supabase image for each service, refuses images used by any running or
52
+ stopped container, and never runs a global Docker or volume prune. Add
53
+ `--include-runtime` only when this project's disposable database may also be removed.
54
+
55
+ For example, copy the full digest from your preview:
56
+
57
+ ```bash
58
+ npx rehearsal cleanup --include-images --write --confirm-cleanup=PASTE_FULL_DIGEST_HERE
59
+ ```
60
+
61
+ For Colima, disk capacity belongs to the user rather than the project. Increase it with
62
+ `colima stop` followed by a larger `colima start --disk <GiB>` value. Rehearsal respects
63
+ that configuration and does not choose a disk size.
64
+
65
+ ## The guide does not show styled menus
66
+
67
+ Rehearsal uses numbered menus when terminal styling is unavailable, `NO_COLOR` is set, or
68
+ `--plain` is used. Enter the number beside your choice. This is the same workflow and has
69
+ the same safety checks.
70
+
71
+ If bare `npx rehearsal` prints help, the command is not connected to an interactive
72
+ terminal. Run it directly in a terminal rather than through a pipe or background task.
73
+
74
+ ## Doctor says the PostgreSQL image is unavailable
75
+
76
+ Rehearsal will not download an image during a rehearsal. Pull and review the exact image
77
+ declared in `rehearsal.config.mjs`, then rerun Doctor:
78
+
79
+ ```bash
80
+ docker pull postgres:17-alpine
81
+ npx rehearsal doctor
82
+ ```
83
+
8
84
  ## A port is already in use
9
85
 
10
- Choose three unique non-privileged ports in config and mirror them in the dedicated
11
- Supabase config. Do not stop an unrelated database to make the default ports fit.
86
+ Rerun `rehearsal setup` to select a different available block. Setup checks both active
87
+ listeners and whether every selected port can be bound, then checks again before writing.
88
+ For an existing configuration, choose unique non-privileged ports and mirror them in the
89
+ dedicated Supabase config when using Supabase. Do not stop an unrelated database to make
90
+ defaults fit.
12
91
 
13
92
  ## Baseline checksum mismatch
14
93
 
@@ -35,6 +114,22 @@ rerun doctor and candidates, then execute with the new digest.
35
114
  Run the project proof directly against the generated local environment. Fix the app,
36
115
  adapter, fixture expectation, or migration; do not weaken the proof to obtain a pass.
37
116
 
117
+ ## The local application loads a hosted value from `.env`
118
+
119
+ Rehearsal removes undeclared hosted credentials from the child process environment, but
120
+ frameworks such as Vite may independently read project `.env` files after the process
121
+ starts. Give the configured `startCommand` or framework test mode an explicit safe local
122
+ override for the affected value. Do not delete or rewrite a developer's normal `.env`
123
+ file as part of a rehearsal.
124
+
125
+ ## `rehearsal open` cannot start the app
126
+
127
+ `open` requires `application.readiness` in `rehearsal.config.mjs`. Confirm that its URL
128
+ uses `localhost`, `127.0.0.1`, or `::1`, matches the app's sandbox port, and returns the
129
+ configured status after startup. Rehearsal leaves the verified database runtime running
130
+ when application startup fails, so retrying does not discard local database or Storage
131
+ changes.
132
+
38
133
  ## Local authentication fails
39
134
 
40
135
  Confirm the provider is enabled in the dedicated local Supabase config, the allowlisted
@@ -46,5 +141,10 @@ is the local Auth callback. Do not paste provider secrets into config or termina
46
141
  `reset` deliberately restores the immutable baseline. `stop` should preserve Docker
47
142
  state, but runtime removal or a failed migration discards untrusted state.
48
143
 
144
+ ## `Ctrl+Z` exits instead of suspending
145
+
146
+ This is intentional inside the guided interface. It exits the entire Rehearsal session
147
+ and restores the terminal. Choose **Exit** for the same result.
148
+
49
149
  Use `--debug` only after ordinary output is insufficient. Diagnostics are redacted, but
50
150
  you should still review output before sharing it publicly.
package/docs/tutorial.md CHANGED
@@ -1,96 +1,107 @@
1
- # Tutorial: rehearse a migration in a new project
1
+ # Safe hands-on tutorial
2
2
 
3
- This walkthrough uses a fictional `widgets` application. It demonstrates the complete
4
- consumer workflow without importing private or hosted data.
3
+ This tutorial runs a complete PostgreSQL rehearsal in a temporary fictional project. It
4
+ does not use your application, production data, or a hosted database.
5
5
 
6
- ## Create the application migration history
6
+ Allow about five minutes. You need Node.js 24 and a running Docker-compatible engine.
7
7
 
8
- The project begins with one historical migration:
8
+ ## 1. Prepare Rehearsal
9
9
 
10
- ```sql
11
- create table public.widgets (
12
- id bigint generated always as identity primary key,
13
- name text not null
14
- );
10
+ If you do not already have this repository, clone it:
11
+
12
+ ```bash
13
+ git clone https://github.com/Ddupasquier/rehearsal-db.git
14
+ cd rehearsal-db
15
15
  ```
16
16
 
17
- Place it at `supabase/migrations/20260101000000_create_widgets.sql`. Add a second,
18
- candidate migration:
17
+ Then run:
19
18
 
20
- ```sql
21
- alter table public.widgets add column description text;
19
+ ```bash
20
+ npm ci --ignore-scripts
21
+ docker pull postgres:17-alpine
22
22
  ```
23
23
 
24
- Place that at `supabase/migrations/20260101000100_add_widget_description.sql`.
24
+ If you already have this repository open, use that checkout.
25
25
 
26
- ## Configure the isolated runtime
26
+ ## 2. Make a temporary project
27
27
 
28
- Run `npx rehearsal init --write`, then edit the result. Give the runtime unique local
29
- ports and a unique project ID. Its `rehearsalConfig` must point at a dedicated, unlinked
30
- Supabase config. Never reuse a hosted project reference or production environment file.
28
+ From the Rehearsal repository root, run this block exactly:
31
29
 
32
- Keep the generated `.rehearsal` directory ignored. It contains local artifacts and
33
- runtime state, not source code.
30
+ ```bash
31
+ rehearsal_repo=$PWD
32
+ tutorial_dir=$(mktemp -d)
33
+ cp -R tests/fixtures/postgresql-project "$tutorial_dir/app"
34
+ cd "$tutorial_dir/app"
35
+ npm install --ignore-scripts --no-save "$rehearsal_repo"
36
+ ```
34
37
 
35
- ## Build a synthetic baseline
38
+ The temporary project contains:
36
39
 
37
- The baseline contains the historical migration bundle, a one-row sanitized data stream,
38
- and a manifest binding their checksums. Baseline construction is deliberately separate
39
- from runtime execution: the application owns extraction and policy; the engine accepts
40
- only a completed, verified artifact.
40
+ - one historical migration that creates a `widgets` table;
41
+ - one candidate migration that adds a `description` column;
42
+ - one synthetic row;
43
+ - a reviewed sanitization policy;
44
+ - an application proof that checks the migrated database.
41
45
 
42
- Write the safe rows to `rehearsal/synthetic-data.ndjson` and the exact represented
43
- statements to `rehearsal/migration-ledger.json`, then run:
46
+ ## 3. Create the baseline
47
+
48
+ Open the guide:
44
49
 
45
50
  ```bash
46
- npx rehearsal baseline create \
47
- --records=rehearsal/synthetic-data.ndjson \
48
- --ledger=rehearsal/migration-ledger.json
51
+ npx rehearsal
49
52
  ```
50
53
 
51
- For an executable sample, inspect `tests/fixtures/rehearsal-project` in the repository.
52
- The maintained fixture proof invokes this public command through the packed npm tarball
53
- and never contacts a hosted service.
54
+ The project begins at Stage 3 of 4. Choose **Create the baseline**. Accept the detected
55
+ record and ledger files, review the summary, then confirm creation.
54
56
 
55
- ## Prove planning is non-mutating
57
+ The project should advance to Stage 4 of 4 with every item checked.
56
58
 
57
- ```bash
58
- npx rehearsal doctor
59
- npx rehearsal explain
60
- npx rehearsal run --dry-run
61
- npx rehearsal candidates --json
59
+ ## 4. Run the migration
60
+
61
+ Choose **Run a rehearsal**. The guide should show exactly one candidate:
62
+
63
+ ```text
64
+ 20260101000100_add_widget_description.sql
62
65
  ```
63
66
 
64
- `explain` and `run --dry-run` return the same execution plan. At this point no local
65
- database has been restored.
67
+ Confirm it. Rehearsal creates a loopback-only PostgreSQL container, restores the baseline,
68
+ applies the candidate, and runs the fixture proof.
66
69
 
67
- ## Run and inspect
70
+ Success ends with an application-proof message and suggests exercising the local
71
+ application before verification.
68
72
 
69
- Copy the exact digest from `candidates`:
73
+ ## 5. Try the runtime commands
74
+
75
+ Exit the guide, then run:
70
76
 
71
77
  ```bash
72
- npx rehearsal run --confirm-candidates=<sha256>
73
- npx rehearsal inspect migrations
74
78
  npx rehearsal status
79
+ npx rehearsal verify
80
+ npx rehearsal reset
81
+ npx rehearsal stop
82
+ npx rehearsal discard
75
83
  ```
76
84
 
77
- The historical migration should be `represented_by_baseline`; the description migration
78
- should be `applied_to_current_runtime`. Test normal creates, updates, and deletes through
79
- your local application. They affect only this disposable database.
85
+ `discard` removes only the labeled tutorial container and volume. The temporary project
86
+ directory remains on disk and can be deleted when you no longer need it.
87
+
88
+ ## What you proved
80
89
 
81
- ## Prove failure behavior
90
+ You used the same packaged CLI a normal project installs. Rehearsal verified the baseline,
91
+ approved an exact migration, ran it in a disposable database, tested the result, and
92
+ cleaned up only its own runtime.
82
93
 
83
- Add a timestamped migration containing invalid SQL, rerun `candidates`, and use its new
84
- digest. The command must fail with `migration_candidate_failure`, remove the untrusted
85
- runtime, and never produce a successful receipt.
94
+ Next, follow [Getting started](getting-started.md) in your own project. Start with synthetic
95
+ rows until the workflow and application proof are reliable.
86
96
 
87
- Then restore the valid migration set and rerun:
97
+ ## Supabase check
98
+
99
+ If Supabase CLI 2.117.0 is installed, the repository also has a fully automated Supabase
100
+ proof:
88
101
 
89
102
  ```bash
90
- npx rehearsal reset
91
- npx rehearsal verify
92
- npx rehearsal stop
103
+ cd "$rehearsal_repo"
104
+ npm run test:fixture
93
105
  ```
94
106
 
95
- That cycle—plan, confirm exact bytes, run, exercise the app, reset—is the normal Rehearsal
96
- workflow.
107
+ The PostgreSQL equivalent is `npm run test:fixture:postgresql`.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@rehearsal-db/core",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.10",
4
4
  "private": false,
5
- "description": "Safely rehearse Supabase migrations against sanitized, production-shaped PostgreSQL data.",
5
+ "description": "Safely rehearse PostgreSQL and Supabase migrations against sanitized, production-shaped data.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/Ddupasquier/rehearsal-db.git"
@@ -21,26 +21,26 @@
21
21
  "node": ">=24 <25"
22
22
  },
23
23
  "bin": {
24
- "rehearsal": "scripts/operations/rehearsal/rehearsal_cli.mjs"
24
+ "rehearsal": "src/cli/rehearsal.mjs"
25
25
  },
26
26
  "exports": {
27
27
  ".": {
28
- "types": "./scripts/lib/rehearsal/configuration.d.mts",
29
- "import": "./scripts/lib/rehearsal/configuration.mjs"
28
+ "types": "./src/project/configuration.d.mts",
29
+ "import": "./src/project/configuration.mjs"
30
30
  },
31
- "./baseline": "./scripts/lib/rehearsal/baseline_artifact.mjs",
32
- "./baseline-builder": "./scripts/lib/rehearsal/baseline_builder.mjs",
33
- "./diagnostics": "./scripts/lib/rehearsal/diagnostics.mjs",
34
- "./migrations": "./scripts/lib/rehearsal/migration_history.mjs",
35
- "./process-environment": "./scripts/lib/rehearsal/process_environment.mjs",
36
- "./schema": "./scripts/lib/rehearsal/schema_snapshot.mjs",
37
- "./service-environment": "./scripts/lib/rehearsal/service_environment.mjs"
31
+ "./baseline": "./src/baseline/artifact.mjs",
32
+ "./baseline-builder": "./src/baseline/builder.mjs",
33
+ "./diagnostics": "./src/shared/diagnostics.mjs",
34
+ "./migrations": "./src/runtime/migration_history.mjs",
35
+ "./process-environment": "./src/shared/process_environment.mjs",
36
+ "./privacy": "./src/baseline/privacy_engine.mjs",
37
+ "./schema": "./src/baseline/schema_snapshot.mjs",
38
+ "./service-environment": "./src/runtime/service_environment.mjs",
39
+ "./source-access": "./src/source/access.mjs"
38
40
  },
39
41
  "files": [
40
- "scripts/lib/environment/local_supabase.mjs",
41
- "scripts/lib/rehearsal",
42
- "scripts/operations/database/manage_rehearsal_database.mjs",
43
- "scripts/operations/rehearsal/rehearsal_cli.mjs",
42
+ "src",
43
+ "scripts/runtime/manage_database.mjs",
44
44
  "docs/*.md",
45
45
  "README.md",
46
46
  "BENCHMARKS.md",
@@ -52,14 +52,18 @@
52
52
  ],
53
53
  "scripts": {
54
54
  "test": "vitest run",
55
- "test:unit": "vitest run tests/scripts",
55
+ "test:unit": "vitest run tests/unit",
56
+ "test:integration": "vitest run tests/integration tests/contracts",
56
57
  "test:docs": "vitest run tests/contracts/documentationCommands.test.mjs",
57
- "test:fixture": "node scripts/operations/rehearsal/prove_independent_fixture.mjs",
58
+ "test:fixture": "node scripts/verification/fixtures/supabase.mjs",
59
+ "test:fixture:postgresql": "node scripts/verification/fixtures/postgresql.mjs",
60
+ "test:fixture:dependent": "node scripts/verification/fixtures/dependent.mjs",
61
+ "test:fixture:standalone": "node scripts/verification/fixtures/standalone.mjs",
58
62
  "check": "npm run check:syntax && npm run test && npm run format:check && npm run package:audit",
59
- "check:syntax": "find scripts tests -type f -name '*.mjs' -exec node --check {} +",
63
+ "check:syntax": "find src scripts tests -type f -name '*.mjs' -exec node --check {} +",
60
64
  "format": "prettier --write .",
61
65
  "format:check": "prettier --check .",
62
- "package:audit": "node scripts/operations/rehearsal/audit_package.mjs"
66
+ "package:audit": "node scripts/verification/audit_package.mjs"
63
67
  },
64
68
  "keywords": [
65
69
  "postgresql",
@@ -69,9 +73,13 @@
69
73
  "database"
70
74
  ],
71
75
  "license": "MIT",
72
- "dependencies": {},
76
+ "dependencies": {
77
+ "@clack/prompts": "^1.8.1",
78
+ "pg": "^8.23.1"
79
+ },
73
80
  "devDependencies": {
81
+ "@lydell/node-pty": "^1.2.0-beta.15",
74
82
  "prettier": "^3.9.6",
75
- "vitest": "^4.1.10"
83
+ "vitest": "^5.0.2"
76
84
  }
77
85
  }
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Purpose: Select the configured database runtime and forward the requested
4
+ * lifecycle action to its isolated driver.
5
+ */
6
+
7
+ import { loadRehearsalConfig } from "../../src/project/configuration.mjs";
8
+ import {
9
+ parseRuntimeInvocation,
10
+ runRuntimeTarget,
11
+ } from "../../src/targets/target.mjs";
12
+
13
+ const invocation = parseRuntimeInvocation();
14
+ const { config } = await loadRehearsalConfig({
15
+ projectRoot: process.cwd(),
16
+ configPath: invocation.configPath,
17
+ });
18
+ await runRuntimeTarget(config.runtime.target);
package/src/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Source layout
2
+
3
+ Production code is grouped by the responsibility it owns:
4
+
5
+ - `application/` starts and proves the project application.
6
+ - `baseline/` creates, validates, and stores safe baseline artifacts.
7
+ - `cli/` is the human and automation entry point.
8
+ - `identity/` associates copied data with verified local users.
9
+ - `project/` owns configuration, setup, and support reporting.
10
+ - `runtime/` plans, verifies, resets, migrates, and cleans local runtimes.
11
+ - `shared/` contains small target-neutral infrastructure.
12
+ - `source/` controls approved source access and baseline refresh.
13
+ - `targets/` contains the PostgreSQL and Supabase runtime adapters.
14
+
15
+ Place a new module in the domain that owns its policy. Keep database-specific behavior
16
+ behind `targets/`, repository-only checks under `scripts/verification/`, and public
17
+ imports behind the export map in `package.json`.