Skip to content

Commit 5f26be2

Browse files
feat(cli): show the upgrade plan before a self-hosted deploy — os deploy --dry-run, --json, and a terminal confirmation for an undeclared rename (#31776)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9GnhGS7ULbZBJ1qXqKpezda)_ Part of #30887 Clause-②: yes (widening) Metadata-protocol: none This is the self-hosted half only, per the seat's ruling B on the card. The ObjectOS Cloud half (`os deploy` to a cloud environment, and `os package publish --install --confirm-upgrade`) waits for the cloud plan door's shape (cloud#3654) to be read onto the card, and this PR leaves that path untouched. The card stays open for it. Clause-② is `yes (widening)`, not the claim's `no`: `os deploy` gains two published flags (`--dry-run`, `--json`) and a terminal question. Nothing that was accepted before is refused. The two new flags are refused on the ObjectOS Cloud target, where they did not exist before. Metadata-protocol is `none`, so the changeset is `patch`. ## 维护者速读 - 改了什么:部署到自托管运行时时,`os deploy` 新增 `--dry-run`(只看计划、不安装)和 `--json`(计划、结果、拒绝原因合成一份 JSON,被拒时非零退出);在终端上遇到没声明的改名或有风险的改类型,会直接问一句「仍要部署吗」,`os dev` 里按 `d` 也一样。 - 为什么改:按 Q3「默认拒绝,需显式映射」,开发者部署前应先看到升级计划;以前被拒后只能复制令牌重跑,现在可以当场确认。 - 风险与回滚:只动 CLI,云端部署路径一行未改;只有新增和已声明改名时照旧不打扰;回滚即还原本 PR。 - 先看:`packages/cli/src/commands/deploy.ts`(`deployToRuntime` 里的提问与 `--json` 文档),`packages/cli/src/utils/upgrade-plan.ts`(共用的计划打印与预判),`packages/cli/test/deploy.test.ts`(新加的 #30887 用例)。 - 两分钟验证:`pnpm --filter @objectstack/cli exec vitest run --project unit test/deploy.test.ts`,预期 47 条全过。 - 需要你做的:无,席位落地。 ## What changes - **`packages/cli/src/utils/upgrade-plan.ts` (new): one printer for the plan and the Q3 refusal.** `renderUpgradePlan` moved here from `install.ts` verbatim; `install.ts` still exports it. New beside it: - `readSchemaUpgradeRefusal` reads a `SCHEMA_UPGRADE_CONFIRMATION_REQUIRED` envelope into its findings and token. The code constant is imported from `@objectstack/metadata-core` (PR #31529), not re-spelled. - `renderSchemaUpgradeRefusal` holds the refusal lines `install.ts` printed inline, unchanged in wording. - `previewSchemaUpgradeStop` runs the framework's own `schemaUpgradeVerdict` on the plan a dry run answered, to say whether the install would stop. It is a preview, never a token: the door judges again on its own reading of the installed version, and only its refusal carries the token. - The input is the plan reading (`{ plan, environment }`), so a hosted door that answers the same reading can hand it to the same printer later. - **`os package install`** sets `outcome` on a refusal too: `kind: 'refused'` with the status, code, message and details verbatim, plus the read Q3 refusal. The dry-run outcome now carries the plan reading and `installedRecordUnreadable`. Printing is unchanged. - **`os deploy`, self-hosted runtime target** (`deployToRuntime`): - `--dry-run`: build, dry run, plan printed, then whether the install would stop and on what. Nothing is installed; exit 0. - On a terminal (stdin and stdout both TTY), a Q3 refusal is followed by `Deploy anyway, accepting each finding as listed? [y/N]`. Yes sends the same install again with the refusal's own finding-set token (`confirmSchemaUpgrade`). Anything else prints `Nothing was deployed` and exits 1. Only the Q3 stop asks: the access-upgrade and global-uniques stops print their retry as before. Off a terminal, or under `--json`, nothing is asked. - `--json`: `reserveStdoutForJson` sends every human line to stderr, and the build child's stdout goes to stderr (`compileForDeploy`'s new `stdoutToStderr`). One document reaches stdout: `target`, `url`, `result` (`planned`, `installed`, `refused`, `failed`), `package`, `plan`, `environment`, `wouldStop`, `refusal` (verbatim), `confirm` (`os deploy --confirm-upgrade TOKEN` when the refusal is Q3), `error`. A refusal or a failure exits 1. - The embedded install's own exit is now caught inside `deployToRuntime`, so the command asks, writes the document and exits once. Exit codes are unchanged for every path that existed. - **`os deploy`, ObjectOS Cloud target:** `--dry-run` and `--json` are refused by name before anything is built or sent, the same way the three confirmations already are. Under `--json` the refusal is itself the document. Nothing else on that path changed. - **The `d` key in `os dev` is unchanged.** It already hands the terminal back (raw mode off) while its child `os deploy` runs, so the child's question reads a cooked terminal. A pin below holds that. - ⛔ No `--rename` flag (ruling D3). The refusal's first way forward is still `renamedFrom` on the new field. - **Docs** (the seat's OQ2: in this PR): `content/docs/deployment/cli.mdx` gains `--dry-run` and `--json` rows in the `os deploy` flag table; "To a self-hosted runtime" says what the dry run prints, when the install asks `Deploy anyway?` on a terminal and what each answer does, and a table lists the `--json` keys and exit codes; the `os dev` `d`-key paragraph says the key gets the same question. `content/docs/deployment/publish-and-preview.mdx` says the same in one sentence. No release notes or CHANGELOG touched. - **Changeset:** besides the user-facing bullets, it names the `refused` variant `PackageInstall.outcome` gains, for code that runs the install command in-process. ## Tests New pins in the existing shared harnesses, as top-level cases (no new test file): - `packages/cli/test/deploy.test.ts`, in the self-hosted describe: - additions plus a declared rename install with no question, even on a terminal, and the rename is printed; - an undeclared suspected rename stops off a terminal: the plan, the `renamedFrom` hint, the retry with the token, exit 1, no question, no confirmed install; - on a terminal, yes installs with the refusal's own token in the request body (`[null, null, 'schema-upgrade:abc']` across the three calls); - on a terminal, no deploys nothing: exit 1, no third call; - only the Q3 stop asks (an access-upgrade refusal asks nothing); - `--dry-run` sends only the dry run and says what would stop; a clean plan says it installs as it is; - `--json`: refused, planned and installed each give one parseable document; never asked under `--json`; the build is told to keep stdout clean; - `--dry-run` and `--json` refused on the ObjectOS Cloud target before anything is built or sent; - the `d` key on a plan with an undeclared rename: the question is asked on a cooked terminal, declining deploys nothing, and the key listens again. - `packages/cli/test/package-install-dry-run.test.ts`: the refusal reader (the Q3 code with a token, nothing else), and the preview (a suspected rename and a `needs_confirm` type change ask; a declared rename, a removal and a `safe` change do not; an unreadable installed record previews its one finding; an unreadable plan previews nothing, never "nothing to confirm"). - Forced test edits: none. The `compileForDeploy` mock forwards its options only when given, so the existing one-argument assertions stand unchanged. ## Acceptance notes - **Not built here (the card's cloud half):** reading cloud's plan door before a cloud deploy, `os package publish --install --confirm-upgrade`, and the Expected-1 "permission widening" group on the cloud path. The self-hosted path shows permission findings as the access-upgrade stop, as before. - **The terminal question also appears for a typed `os deploy` on a terminal**, not only under the `d` key. The key runs exactly the command a developer would type (the design `utils/dev-deploy-key.ts` states), so one deploy path asks in both. Off a terminal, behaviour is as before. - **Docs:** the seat widened the file surface to the hand-written `content/docs` pages that document `os deploy` flags or the `d` key, and ruled the docs into this PR (OQ2). They are in the docs commit; nothing is left for the seat. `connect-mcp.mdx` mentions `os deploy` only for how it picks an environment, so it is unchanged. - The dry-run preview and the install's verdict can differ in one case: an orphaned install (no ledger entry, registry body present) is compared by the door against the registry body, and by the dry run against no installed version. The install's refusal is the authority either way; the preview never carries a token. ## Verification Head `bbeb6018` adds two prose-only commits on top of `4a7dafdb` (the docs, and one changeset sentence); no `.ts` file changed. On `bbeb6018`, `node scripts/pm/dispatch-gates.mjs --commands` derives 97 commands (the docs pages add the doc families): all run, all exit 0; `--ran` reconciliation: 97 derived, 97 run, 0 NOT-MEASURED, 0 UNRUN. Everything below was measured on `4a7dafdb` (after merging `origin/main` `f65c36fc`), in a card worktree. <details><summary>Typecheck, unit tier, lint</summary> - Dependency closure `pnpm --filter '@objectstack/cli^...' build`: exit 0. - `pnpm --filter @objectstack/cli typecheck`: exit 0. - `pnpm --filter @objectstack/cli exec vitest run --project unit`: 405 of 407 files passed at first. The other two (`published-subpath-console.pin`, `published-subpath-hook-body.pin`) need the CLI's own `dist` and refused for that reason. After `pnpm --filter @objectstack/cli build` they pass (2 files, 29 tests). Total: 407 of 407 files. - Targeted: `test/deploy.test.ts`, `test/package-install-dry-run.test.ts`, `test/dev-deploy-key.test.ts`: 3 files, 68 tests passed. - Lint (root eslint, `--no-inline-config`) on the 7 changed source and test files: exit 0. - Integration tier: not run locally. No integration-tier file or spawn entry is touched; CI runs it. </details> <details><summary>Ablations (each negative pin turned red, then restored; git diff HEAD empty after each)</summary> All mutations went through `scripts/ablation-replace.mjs` (the anchor hit once, the blob moved). The tests import `src` directly, so no rebuild was needed. - A: ask before every install on a terminal → "installs without a question" red (`askYesNo` called once). - B: drop the terminal check → "stops before any write off a terminal" red. - C: a declined question still installs → "declining deploys nothing" and the `d`-key case red (exit undefined, not 1). - D: every refusal treated as Q3 (in `install.ts`'s outcome) → "only the Q3 stop asks" red. A first attempt, which dropped the guard in `deploy.ts`, stayed green because the missing token threw before the question. It was replaced by this mutation and is declared here. - E: ask under `--json` → "ONE document" red ("never asked under --json"). - F: `--dry-run` falls through to the install → "--dry-run … installs nothing" red. - G: the cloud loop reads only the confirmations → both cloud refusals red (one call sent). - H: a tokenless refusal read as Q3 → "reads a Q3 refusal" red. - I: an unreadable plan previewed as empty → "never nothing to confirm" red. </details> <details><summary>Derived gates</summary> `node scripts/pm/dispatch-gates.mjs --commands` on `4a7dafdb`: 66 commands, all run, all exit 0. `--ran` reconciliation: 66 derived, 66 run, 0 NOT-MEASURED, 0 UNRUN. `check-plugin-teardown-shape --self-test` first exited 3 because the pinned fixture commit was not in the clone; after fetching it, it exits 0 (48 cases). The examples were built first for `check:i18n-coverage`. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmNyKKDzf9hWGt2cQYb)_ <!-- signed: domain:server#4 · os-steve · session_01ADHkmP8JJo4zF2sjTBRwnX --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5b7269f commit 5f26be2

10 files changed

Lines changed: 868 additions & 158 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
feat(cli): `os deploy` to a self-hosted runtime shows the upgrade plan before it installs: `--dry-run`, `--json`, and a confirmation on the terminal for an undeclared rename or a risky type change
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
Who sees it: a developer deploying to a self-hosted runtime (`os environments use-runtime`) with `os deploy`, or with the `d` key in `os dev`.
11+
12+
- **The plan comes first, and a plain upgrade is not interrupted.** `os deploy` already printed the runtime's upgrade plan (added and removed fields, type changes, renames declared with `renamedFrom`, suspected renames, seed datasets) before it installed. A plan with only additions and declared renames still installs with no question, so the `d` key stays one key press.
13+
- **An undeclared rename or a risky type change stops the deploy before anything is written**, as before, and now asks on a terminal: "Deploy anyway, accepting each finding as listed?". Yes sends the same install again with the finding-set token from the runtime's refusal. Anything else deploys nothing and exits 1. The `d` key gets the same question, because it runs `os deploy` on the same terminal. Off a terminal (CI, a pipe) nothing is asked: the refusal prints both ways forward, as before. Either declare the old key in the new field's `renamedFrom` and rebuild, or run `os deploy --confirm-upgrade <token>`. There is no `--rename` flag: a rename is declared in the package.
14+
- **`os deploy --dry-run`** builds, prints the plan and installs nothing. It also says whether the install would stop for a confirmation, using the framework's own verdict on the plan the runtime answered. The token that confirms comes only from the install's refusal.
15+
- **`os deploy --json`** prints one JSON document on stdout: `target`, `url`, `result` (`planned`, `installed`, `refused` or `failed`), `package`, `plan`, `environment`, `wouldStop`, `refusal` (the runtime's error, verbatim), `confirm` (the command that confirms the refused findings) and `error`. Progress goes to stderr. A refusal or a failure exits non-zero.
16+
- With ObjectOS Cloud as the target, `--dry-run` and `--json` are refused by name before anything is built or sent. This command does not read a cloud environment's plan yet.
17+
- `os package install --dry-run` and `os deploy` print the plan and the refusal with one shared printer, so the two cannot disagree.
18+
- For code that runs the install command in-process: `PackageInstall.outcome` (the `os package install` command class) gains a `refused` variant (`status`, `code`, `message`, `details`, and `schemaUpgrade` when the refusal is a schema upgrade stop), and it is set whenever the endpoint answers the install with a refusal (any non-zero error status; a timeout or a refused connection is not one).

‎content/docs/deployment/cli.mdx‎

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ Once the local server is up, `os dev` in an interactive terminal offers
171171
the target is ObjectOS Cloud and you are not logged in, the same key runs
172172
`os cloud login` first. When the target is a runtime
173173
[`os environments use-runtime`](#deploy-to-a-self-hosted-runtime) remembered, the
174-
key deploys there and asks for no cloud login. Saving a file never deploys.
174+
key deploys there and asks for no cloud login. On a self-hosted runtime an
175+
upgrade that would rename or retype a stored field without declaring it asks
176+
"Deploy anyway?" in the same terminal (see
177+
[To a self-hosted runtime](#to-a-self-hosted-runtime)); answering no deploys
178+
nothing. Saving a file never deploys.
175179

176180
```bash
177181
os dev # Auto-compile cwd config, then start
@@ -3251,6 +3255,8 @@ is its production, so a deploy is always a deliberate act.
32513255
| `--confirm-global-uniques` | — | Self-hosted target only: confirm the app's installation-wide `unique` constraints are genuinely platform-wide when the runtime's refusal asks (as [`os package install`](#os-package-install)). Refused when the target is ObjectOS Cloud |
32523256
| `--confirm-access-upgrade <token>` | — | Self-hosted target only: confirm the upgrade's access findings with the finding-set token the runtime's refusal printed (as [`os package install`](#os-package-install)). Refused when the target is ObjectOS Cloud |
32533257
| `--confirm-upgrade <token>` | — | Self-hosted target only: confirm the upgrade's schema findings (a suspected rename, a type change that is not safe) with the finding-set token the runtime's refusal printed (as [`os package install`](#os-package-install)). Refused when the target is ObjectOS Cloud |
3258+
| `--dry-run` | — | Self-hosted target only: build, print the upgrade plan, say whether the install would stop for a confirmation, and install nothing. Refused when the target is ObjectOS Cloud |
3259+
| `--json` | — | Self-hosted target only: print one JSON document on stdout (see below); progress goes to stderr. Refused when the target is ObjectOS Cloud; the document then says so (`target: cloud`, `result: failed`) |
32543260
32553261
`os package publish` stays the command for a **release**: it publishes the
32563262
version the manifest declares, with `--install` optional.
@@ -3268,17 +3274,31 @@ answers are the ones printed.
32683274
1. **Build** — the same compile as above. A failed build prints its errors, and
32693275
nothing is installed.
32703276
2. **Dry run** — the runtime's upgrade plan of the installed version against this
3271-
build is printed; nothing is installed. A runtime that refuses it, or does not
3272-
serve install-local, stops the deploy with exit `1`. A runtime that predates the
3273-
dry run ignores it and installs: the command says so and exits `1`.
3277+
build is printed, grouped by change: objects and fields added and removed,
3278+
renames declared with `renamedFrom` (`old → new`), suspected renames, type
3279+
changes, and seed datasets with their mode. Nothing is installed. A runtime that
3280+
refuses it, or does not serve install-local, stops the deploy with exit `1`. A
3281+
runtime that predates the dry run ignores it and installs: the command says so
3282+
and exits `1`. With `--dry-run` the deploy stops here and exits `0`, after saying
3283+
whether the install would stop for a confirmation and on which findings.
32743284
3. **Install** — with `--confirm-global-uniques`, `--confirm-access-upgrade` and
3275-
`--confirm-upgrade` passed through. The endpoint's refusals (installation-wide
3276-
uniques to confirm on an `isolated` runtime, an access upgrade to confirm, a
3277-
schema upgrade to confirm, a package the running kernel cannot register, …)
3278-
stop the deploy with exit `1`, and the retry they print names `os deploy`:
3279-
`os deploy --confirm-global-uniques` for installation-wide uniques,
3280-
`os deploy --confirm-access-upgrade <token>` for access findings, or
3281-
`os deploy --confirm-upgrade <token>` for schema findings.
3285+
`--confirm-upgrade` passed through. A plan with only additions and declared
3286+
renames installs without a question. The endpoint's refusals
3287+
(installation-wide uniques to confirm on an `isolated` runtime, an access
3288+
upgrade to confirm, a schema upgrade to confirm, a package the running kernel
3289+
cannot register, …) stop the deploy with exit `1`, and the retry they print
3290+
names `os deploy`: `os deploy --confirm-global-uniques` for installation-wide
3291+
uniques, `os deploy --confirm-access-upgrade <token>` for access findings, or
3292+
`os deploy --confirm-upgrade <token>` for schema findings. A schema upgrade
3293+
stop (an undeclared suspected rename, a type change that is not safe) also
3294+
names the other way forward: declare the old key in the new field's
3295+
`renamedFrom` and rebuild. There is no rename flag; a rename is declared in the
3296+
package.
3297+
- **On a terminal** (stdin and stdout both interactive, so also under the `d`
3298+
key), the schema upgrade stop asks `Deploy anyway, accepting each finding as
3299+
listed? [y/N]`. Yes installs again with the refusal's own finding-set token;
3300+
anything else deploys nothing and exits `1`. Only the schema upgrade stop
3301+
asks. Off a terminal, or with `--json`, nothing is asked.
32823302
4. **Live** — install-local registers the package in the running kernel before it
32833303
answers, so the answer is the verdict: `hotLoaded` prints `Live: … now serves …`
32843304
and exits `0`. A package the runtime recorded but its running kernel could not
@@ -3288,6 +3308,26 @@ answers are the ones printed.
32883308
The `d` key in [`os dev`](#os-dev) runs the same `os deploy`, so it deploys to the
32893309
runtime too and asks for no cloud login.
32903310

3311+
With `--json`, stdout carries one JSON document and every progress line goes to
3312+
stderr. A refusal or a failure exits `1`; a dry run or a live install exits `0`.
3313+
3314+
| Key | Value |
3315+
|---|---|
3316+
| `target` | `runtime` (or `cloud` when the flag is refused there) |
3317+
| `url` | The runtime's URL |
3318+
| `result` | `planned` (`--dry-run`), `installed`, `refused` or `failed` |
3319+
| `package` | `{ manifestId, version, installedVersion }` from the dry run |
3320+
| `plan`, `environment` | The runtime's dry-run reading, verbatim |
3321+
| `wouldStop` | The schema findings the install would ask to confirm, previewed from the plan (`[]`: none; `null`: not read) |
3322+
| `refusal` | The runtime's refusal, verbatim: `{ status, code, message, details }` |
3323+
| `confirm` | `os deploy --confirm-upgrade <token>` when the refusal is a schema upgrade stop |
3324+
| `error` | What stopped the deploy, when something did |
3325+
3326+
```bash
3327+
os deploy --dry-run # the plan, and whether the install would stop; nothing installed
3328+
os deploy --json | jq .result # one document on stdout
3329+
```
3330+
32913331
### MCP
32923332
32933333
#### `os mcp connect`

‎content/docs/deployment/publish-and-preview.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,10 @@ Remember it once with
216216
— and the `d` key in `os dev`, which runs it — then deploys there with no URL or
217217
key to type: it builds, prints the runtime's upgrade plan from a dry run,
218218
installs the build inline, and reports the app live once the running kernel has
219-
loaded it (`hotLoaded`). `os package install` uses the same runtime when `-u` /
220-
`-t` are not given. `os environments use-runtime --forget`, or an
219+
loaded it (`hotLoaded`). An undeclared rename or a risky type change stops it
220+
before anything is written, and on a terminal it asks whether to deploy anyway;
221+
`os deploy --dry-run` prints the plan and installs nothing. `os package install`
222+
uses the same runtime when `-u` / `-t` are not given. `os environments use-runtime --forget`, or an
221223
`os environments switch <id>` recorded for your `os cloud login` control plane,
222224
makes ObjectOS Cloud the target again.
223225

0 commit comments

Comments
 (0)