Repository navigation
Commit 5f26be2
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
- .changeset
- content/docs/deployment
- packages/cli
- src
- commands
- package
- utils
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
| |||
3251 | 3255 | | |
3252 | 3256 | | |
3253 | 3257 | | |
| 3258 | + | |
| 3259 | + | |
3254 | 3260 | | |
3255 | 3261 | | |
3256 | 3262 | | |
| |||
3268 | 3274 | | |
3269 | 3275 | | |
3270 | 3276 | | |
3271 | | - | |
3272 | | - | |
3273 | | - | |
| 3277 | + | |
| 3278 | + | |
| 3279 | + | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + | |
| 3283 | + | |
3274 | 3284 | | |
3275 | | - | |
3276 | | - | |
3277 | | - | |
3278 | | - | |
3279 | | - | |
3280 | | - | |
3281 | | - | |
| 3285 | + | |
| 3286 | + | |
| 3287 | + | |
| 3288 | + | |
| 3289 | + | |
| 3290 | + | |
| 3291 | + | |
| 3292 | + | |
| 3293 | + | |
| 3294 | + | |
| 3295 | + | |
| 3296 | + | |
| 3297 | + | |
| 3298 | + | |
| 3299 | + | |
| 3300 | + | |
| 3301 | + | |
3282 | 3302 | | |
3283 | 3303 | | |
3284 | 3304 | | |
| |||
3288 | 3308 | | |
3289 | 3309 | | |
3290 | 3310 | | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
| 3315 | + | |
| 3316 | + | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
| 3321 | + | |
| 3322 | + | |
| 3323 | + | |
| 3324 | + | |
| 3325 | + | |
| 3326 | + | |
| 3327 | + | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
3291 | 3331 | | |
3292 | 3332 | | |
3293 | 3333 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
220 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
| |||
0 commit comments