Repository navigation
Commit 7f19190
fix(create-objectstack): stamp the blank template's engines.protocol from PROTOCOL_MAJOR, as os init does (#37650)
Fixes #37586
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户无感:新建项目模板里写的协议版本,改为由发版流程直接取运行时的协议常量来写(另一个建项目命令早就这样做);主干上模板今天已经是
19,发布出去的模板不变。
- 属于协议 19 升级的收尾:替以后每次升大版本的模板和镜像改动解决“模板写的版本和运行时不一致、新建项目启动不了”这一反复出现的问题。
- 如果读不到协议常量,发版流程的模板盖章步骤会直接报错停下,不会写入错误版本;这次改动可以直接撤回。
- 无
## Premise, restated after the version pass
The card was filed while `main`'s blank template carried
`engines.protocol: '^18'` (the scaffolder's package major) and the
runtime implemented protocol 19, so a project scaffolded from `main` was
refused at boot. That visible symptom was cleared by the version pass in
#35129 (merged 16:25Z): every package moved to `19.0.0-next.0` and the
stamper wrote `'^19'`, still from the package major. This PR changes
where the stamp comes from. The next time the protocol major moves ahead
of the package major (Changesets pre mode, ruling record 6049734955),
the template follows the constant in the same change, and the version
pass no longer has to catch it up. After merging `origin/main` the
template line is a no-op in this diff.
## What changes
- `scripts/sync-template-versions.mjs` stamps `engines.protocol` from
`PROTOCOL_MAJOR`, the export of
`packages/spec/src/kernel/protocol-version.ts` that `os init` stamps
from (`packages/cli/src/commands/init.ts` imports it from
`@objectstack/spec/kernel`). It never uses the scaffolder's package
major. New exports: `PROTOCOL_SOURCE` and `loadProtocolMajor()`. If the
constant cannot be read, the run exits 1, names the path and writes
nothing. It does not fall back to the package major. The
`@objectstack/*` dependencies still take the scaffolder's exact version.
- **How the constant is read, and what it costs.** The stamper evaluates
the source module: Node's `module.stripTypeScriptTypes`, then an
`import()` of the result. The export is evaluated, not re-parsed with a
regex. It does not import the built `@objectstack/spec/kernel`, for two
reasons:
- The `version-pr` lane runs `pnpm install` and never builds, so no
`dist/` exists there. Adding a build would be a `release.yml` edit,
which the card rules out.
- The root `version` script runs `sync-protocol-version.mjs` first, and
that script may rewrite the source constant. A `dist/` would answer for
the tree before that rewrite.
Costs:
- On Node 22, `stripTypeScriptTypes` prints an `ExperimentalWarning` to
stderr on every run.
- The script needs Node 22.13 or later. `.nvmrc` pins 22, and an older
Node gets a named error, not a link failure.
- `protocol-version.ts` must keep no imports of its own. A relative
import there would fail loudly in this read.
- `--self-test`: new battery Control K (floor 7, roster floor 10 to 11).
With the scaffolder at `42.6.0` and the constant at `43.0.0`, a template
at `'^43'` is judged clean and left unwritten, and a template at `'^42'`
is rewritten to `'^43'`. A checkout without the constant exits 1 naming
it, and the stale template is left untouched. Every fixture checkout now
carries its own `protocol-version.ts`, TypeScript-shaped with
`PROTOCOL_MAJOR` derived from `PROTOCOL_VERSION`.
- `template-consistency.test.ts` holds each template's range to
`PROTOCOL_MAJOR` from `@objectstack/spec/kernel` (vitest aliases it to
source), not to `create-objectstack`'s own major.
- `template-version-stamps.test.ts` (surface widened by claim amendment
7197818926): fixture setup only. The fixtures write a
`protocol-version.ts` at the fixture's major. No assertion or
expectation changed.
- The docblock sentence in `protocol-version.ts` now says the template
is stamped from the constant.
- No changeset, `skip-changeset`. The published template is
byte-identical to `main`'s (`'^19'`, from #35129). Every other path is a
repo script, tests or a TSDoc comment.
## Tests
- `node scripts/sync-template-versions.mjs --self-test` passes with 51
assertions (Control K: 7).
- `pnpm --filter create-objectstack typecheck` passes, and `pnpm
--filter create-objectstack test` passes: Test Files 26/26, Tests
396/396, at `f837e08af9`.
- **Ablation**, `src/template-consistency.test.ts`. Each on-disk
mutation was restored with `git checkout HEAD`.
- Template set to `'^18'`: 1 failed, 40 passed (`blank stamps
engines.protocol '^18' but the runtime implements protocol 19`).
- `PROTOCOL_VERSION` set to `'20.0.0'`, template `'^19'`: 1 failed, 40
passed (`… implements protocol 20`). The test reads the source, not a
stale `dist/`.
- Unmutated: 41/41.
## Acceptance notes
- **Version-pass rehearsal stays green.** The `version-pr` Render and
Validate steps were taken verbatim from `release.yml` and run in
throwaway clones (`release-rehearsal-clone.mjs --prepare`).
- Before #35129 merged, on 54d6726: the control (main) and the full
change both passed 15/15 content gates. Both stamped `'^19'`, at
`19.0.0-next.0`.
- The in-surface change without the `template-version-stamps.test.ts`
fixture lines failed 14/15, on `create-objectstack test` (2 cases,
ENOENT on the fixture's constant). That reading is why the surface was
widened.
- On the final head `f837e08af9`: 11 pending changesets, 290 paths
moved, 15/15 content gates green, 0 unvalidated, `VALIDATE_EXIT=0`.
- **Published template range: no change.** The package major and the
protocol major are both 19 on the current line.
- **Boot of a project scaffolded from this branch: NOT MEASURED.** After
the merge of `origin/main`, this diff leaves the template bytes
identical to `main`'s, so a scaffold from this branch is the scaffold
from `main`. The `'^19'` boot was measured on #37441 (build ok, test
3/3, `/ready` 200).
- The rehearsal printed two `::warning::` lines (annotate-shipped and
changeset-changelog: `cannot simplify commit`). Both come from the
container's shallow-origin object store, and both appear on the control
leg too.
## Verification
Read first:
1. `scripts/sync-template-versions.mjs`: `loadProtocolMajor()` and
`main()`. This is the risk hunk: the release lane's only read of the
constant.
2. `packages/create-objectstack/src/template-consistency.test.ts`: the
`engines.protocol` case.
3. `scripts/sync-template-versions.mjs`: self-test Control K.
Two-minute check: `node scripts/sync-template-versions.mjs` on this
branch prints `already stamps engines.protocol '^19'` and ends with
`engines.protocol at '^19' (PROTOCOL_MAJOR,
packages/spec/src/kernel/protocol-version.ts)`, plus one
`ExperimentalWarning` line on stderr. Then set `PROTOCOL_VERSION` to
`'20.0.0'` and run it again: the template moves to `'^20'` while
`create-objectstack` stays `19.0.0-next.0`. Revert both edits
afterwards.
<details>
<summary>Local gates at f837e08 (dispatch-gates derivation, 101
families)</summary>
- 97 families exit 0. They include `check:template-version-sync`,
`check:changeset-no-major`, `check:adr-0087-registration`,
`check:spec-docblock-symbol-anchors`, `check:test-source-alias`,
`check:cross-package-test-inputs`, `check:published-files`,
`check:nul-bytes`, and `check:pm-dispatch-gates` (fast tier).
- 4 exit 3, PREREQUISITE NOT MET, so NOT MEASURED; CI judges them:
- `check-plugin-teardown-shape.mjs --self-test`: shallow clone.
- `check:doc-formula-expressions`: `@objectstack/formula` is not built.
- `check:dual-build-cjs-loads` and `check:lean-entry-closure`: unbuilt
`dist/`.
- `dispatch-gates --ran`: "101 derived famil(ies) accounted for — 97
run, 4 NOT-MEASURED", exit 0.
- `overlap-check.mjs` before the push: VERDICT clean, exit 0.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cyyekQEqLjtrCLLAeV)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 468672a commit 7f19190
4 files changed
Lines changed: 204 additions & 28 deletions
File tree
- packages
- create-objectstack/src
- spec/src/kernel
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
267 | 274 | | |
268 | 275 | | |
269 | 276 | | |
| |||
272 | 279 | | |
273 | 280 | | |
274 | 281 | | |
275 | | - | |
276 | | - | |
277 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
278 | 286 | | |
279 | 287 | | |
280 | 288 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
92 | 105 | | |
93 | 106 | | |
94 | 107 | | |
| |||
141 | 154 | | |
142 | 155 | | |
143 | 156 | | |
| 157 | + | |
144 | 158 | | |
145 | 159 | | |
146 | 160 | | |
| |||
271 | 285 | | |
272 | 286 | | |
273 | 287 | | |
| 288 | + | |
274 | 289 | | |
275 | 290 | | |
276 | 291 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
0 commit comments