Skip to content

Commit 7f19190

Browse files
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/template-consistency.test.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import os from 'node:os';
1111
import path from 'node:path';
1212
import { execFileSync } from 'node:child_process';
1313
import { fileURLToPath } from 'node:url';
14+
import { PROTOCOL_MAJOR } from '@objectstack/spec/kernel';
1415
import { syncObjectStackDeps } from './pkg-utils.js';
1516
import { copyDir, TEMPLATE_FILE_ALIASES } from './template-copy.js';
1617
import { TEMPLATES } from './template-registry.js';
@@ -25,7 +26,6 @@ import {
2526
const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
2627
const repoRoot = path.resolve(pkgRoot, '..', '..');
2728
const ownPkg = JSON.parse(fs.readFileSync(path.join(pkgRoot, 'package.json'), 'utf8'));
28-
const ownMajor = Number(ownPkg.version.split('.')[0]);
2929

3030
// The catalog is imported, not text-parsed: it lives in template-registry.ts
3131
// precisely so tests can read it directly (importing index.ts would run the
@@ -263,7 +263,14 @@ describe('bundled template declared version surfaces', () => {
263263
// `objectstack.manifest.json` — the two were conflated in this suite's own
264264
// naming and in the sync script's log strings, and that conflation is part
265265
// of how the sibling key below went unwatched for eleven majors.
266-
it("objectstack.config.ts stamps engines.protocol at the scaffolder's major (ADR-0087 D1)", () => {
266+
//
267+
// The range is held to `PROTOCOL_MAJOR` — the export `os init` stamps from
268+
// (`packages/cli/src/commands/init.ts`) and the runtime's handshake checks
269+
// against — never to this package's own major. The two agree on every
270+
// published line; in Changesets pre mode the constant may lead the package
271+
// major (ruling record 6049734955), and a template held to the package
272+
// major then declared a protocol the runtime in the same commit refused.
273+
it('objectstack.config.ts stamps engines.protocol at PROTOCOL_MAJOR (ADR-0087 D1)', () => {
267274
const config = readTemplateFile('objectstack.config.ts');
268275
const match = /engines:\s*\{\s*protocol:\s*'\^(\d+)'\s*\}/.exec(config);
269276
expect(
@@ -272,9 +279,10 @@ describe('bundled template declared version surfaces', () => {
272279
).not.toBeNull();
273280
expect(
274281
Number(match![1]),
275-
`${template} stamps engines.protocol '^${match![1]}' but create-objectstack is v${ownMajor} — ` +
276-
'scripts/sync-template-versions.mjs re-stamps this at version time; keep them in lockstep',
277-
).toBe(ownMajor);
282+
`${template} stamps engines.protocol '^${match![1]}' but the runtime implements protocol ` +
283+
`${PROTOCOL_MAJOR} (PROTOCOL_MAJOR, @objectstack/spec/kernel) — run ` +
284+
'node scripts/sync-template-versions.mjs, which stamps it from that constant',
285+
).toBe(PROTOCOL_MAJOR);
278286
});
279287

280288
// The key #9264 was about, retired under ADR-0049 (#31035): nothing read

‎packages/create-objectstack/src/template-version-stamps.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ const writeFixtureFile = (file: string, content: string) => {
8989
fs.writeFileSync(file, content);
9090
};
9191

92+
/**
93+
* The stamper reads `engines.protocol`'s major from the protocol constant's
94+
* source (`PROTOCOL_SOURCE`), never from the scaffolder version, so a fixture
95+
* checkout carries its own copy, at the fixture's major. Shaped like the real
96+
* file: TypeScript the read must strip, `PROTOCOL_MAJOR` derived.
97+
*/
98+
const writeProtocolSource = (into: string, protocolVersion: string) =>
99+
writeFixtureFile(
100+
path.join(into, 'packages', 'spec', 'src', 'kernel', 'protocol-version.ts'),
101+
`export const PROTOCOL_VERSION = '${protocolVersion}';\n` +
102+
"export const PROTOCOL_MAJOR: number = Number.parseInt(PROTOCOL_VERSION.split('.')[0]!, 10);\n",
103+
);
104+
92105
/**
93106
* Copy `absFile` into the fixture at the SAME repo-relative position, then do
94107
* the same for every RELATIVE import it makes, transitively.
@@ -141,6 +154,7 @@ beforeAll(() => {
141154
path.join(fixture, 'packages', 'create-objectstack', 'package.json'),
142155
JSON.stringify({ name: 'create-objectstack', version: FIXTURE_VERSION }, null, 2) + '\n',
143156
);
157+
writeProtocolSource(fixture, FIXTURE_VERSION);
144158

145159
for (const template of FIXTURE_TEMPLATES) {
146160
const dir = fixtureTemplateDir(template);
@@ -271,6 +285,7 @@ describe('the entry-point guard leaves the CLI path working', () => {
271285
path.join(dir, 'packages', 'create-objectstack', 'package.json'),
272286
JSON.stringify({ name: 'create-objectstack', version: prerelease }, null, 2) + '\n',
273287
);
288+
writeProtocolSource(dir, '43.0.0');
274289
const templateDir = path.join(dir, 'packages', 'create-objectstack', 'src', 'templates', 'blank');
275290
writeFixtureFile(
276291
path.join(templateDir, 'package.json'),

‎packages/spec/src/kernel/protocol-version.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
* here while this package was still on its 18.x stable line, beside the v19
2222
* line's pending `major` (ruling record 7153441862, route A, item 2). In-repo
2323
* manifests that mean "the current protocol" move to `'^19'` with it; the
24-
* scaffolder's blank template follows at the version pass, and the published
25-
* skills' examples in a change of their own.
24+
* scaffolder's blank template is stamped from `PROTOCOL_MAJOR` itself
25+
* (`scripts/sync-template-versions.mjs`, as `os init` does), so it moves in the
26+
* change that moves the constant (create-objectstack's consistency test reds
27+
* until it does); the published skills' examples move in a change of their own.
2628
*/
2729
export const PROTOCOL_VERSION = '19.0.0';
2830

0 commit comments

Comments
 (0)