Skip to content

Commit 4bba8b8

Browse files
fix(metadata-protocol)!: judgesPackageLessRows returns a plain boolean, and the boot load joins the hydration-state pins (objectstack-ai#33483)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DDwkEEJd65kqFZGFjQnzBQt)_ Fixes objectstack-ai#32716 Clause-②: yes (narrowing) Metadata-protocol: none **BREAKING** for a TypeScript caller that narrows `type` to `PackageScopedType` through the exported `judgesPackageLessRows(registry, type)` (for example `if (judgesPackageLessRows(r, t)) useScoped(t)`): its return type is now `boolean`, so that call no longer compiles. Call `isPackageScopedType(type)` from `@objectstack/core` first. The runtime answer is unchanged; the level stays patch. <!-- adr-0087: not-required (no-migration-prescription) no key of any schema is added, removed, renamed or re-shaped and no stored row changes shape: what moves is one exported function's TypeScript return type --> ## 维护者速读 - 改了什么:① `judgesPackageLessRows` 的返回类型由类型谓词改为普通 `boolean`,运行时答案不变;`packageLessRowOwners` 改用 `isPackageScopedType` 收窄类型。② N3 实测:按包精确读一条包外 action 存储行,在载入前后(启动加载、列表读、裸槽副本)答案一致,都是持有者自己的条目,所以不改代码,只把「启动加载」补进现有的载入状态 pin。 - 为什么改:① 谓词会让调用方的 false 分支被收窄成 never,但 false 其实取决于注册表。② 卡片说的「载入前 200、载入后 409」在当前 main 上已不存在(objectstack-ai#32568 的裁决已经处理),这里实测确认并钉住启动加载这一路。 - 风险与回滚:仅类型签名与测试;无读答案变化。回滚 = revert 本 PR。 - 先看:`packages/metadata-protocol/src/protocol-exact-qualifier.ts`(`judgesPackageLessRows` 签名与 `packageLessRowOwners` 首行);`packages/objectql/src/package-scoped-exact-qualifier.test.ts` 的 location 4 `STATES`。 - 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run src/package-scoped-exact-qualifier.test.ts -t "location 4"`,预期全部通过,含新增的 `after the boot load` 用例。 - 需要你做的:无,席位落地。 ## What changes 1. **N1.** `judgesPackageLessRows(registry, type)` returned the type predicate `type is PackageScopedType`. Its `false` depends on the registry (`readsByPackage`), so the predicate narrowed a package-scoped type to `never` in a caller's `false` branch. It now returns `boolean`. One caller relied on the predicate: `packageLessRowOwners` passed the narrowed `type` to `isPlatformRequestedBareName`. It now narrows through `isPackageScopedType`, which depends on the type alone. The CLI caller (`stored-package-references.ts`, a `filter`) typechecks unchanged. The runtime answer is unchanged. 2. **N3, measured: the answers are the same, so no read moves.** A stored package-less `action` row of a name a package ships was read at the holder's exact address (`?package=`) and in the layered read. It was read before and after each hydration path: the boot load (`loadMetaFromDb`), the list read's hydrator (`getMetaItems`), and a copy in the registry's bare slot stamped `''` or `sys_metadata`. Each path was run with one holder and with two holders in both registration orders. The answer was the holder's own item every time (200), and the layered read reported no overlay. The card's 200-before / 409-after premise came from before the epic ruling 6817768147 on objectstack-ai#32568. That ruling's change makes the hydrator decline the row (`hydrateOverlayIntoRegistry`) and makes the exact read replace a bare-slot copy (`declinedCopyReplaced`). The list read and the bare-slot copies were already pinned (location 4 of `[objectstack-ai#32568]`). The boot load was not, so this PR adds it to those pins for `action`, `queue` and `tool`, with one holder and two. No ADR-0150 D4 ruling is needed for N3: nothing differs, so nothing is implemented beyond the pins. ## Tests - `packages/metadata-protocol/src/protocol-exact-qualifier.test.ts`: a new case, `[objectstack-ai#32716 N1]`. It is checked by `tsc`, and the package's `typecheck` compiles the file (`tsc --listFiles` lists it). In the `false` branch, a `hook` typed `PackageScopedType` keeps that type. - `packages/objectql/src/package-scoped-exact-qualifier.test.ts`, location 4: a new state, `after the boot load`, in both registration orders × `action`/`queue`/`tool` (6 new cases). The one-holder case now walks before → after the boot load → after the read-side hydrator. The boot-load leg asserts the load reached the row (`loaded: 1, errors: 0`), so the pin cannot pass without a load. All runs on head `4bb529d89` (the merge of `origin/main` 0c2aeb9 into the branch), through `scripts/pm/os-verify-lock.sh`: <details><summary>Unit and package runs</summary> - `pnpm --filter @objectstack/metadata-protocol typecheck` → exit 0; `pnpm --filter @objectstack/metadata-protocol test` → Test Files 340 passed, 9 skipped (349); Tests 22866 passed, 43 skipped. VERDICT command-exit 0. - `pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/package-scoped-exact-qualifier.test.ts` → Tests 294 passed (294). Before the change the file held 288; the 6 new cases are the boot-load state. - `pnpm --filter @objectstack/cli typecheck` (after building its dependency closure, which included the new `.d.ts`) → exit 0, and `check:test-typecheck` OK. This is the one other caller of `judgesPackageLessRows`. - `objectql` is a tests-only touch here: its full suite and the `integration` layers are left to CI (`Test Core`). </details> <details><summary>Ablations (one-shot; nothing left in the tree)</summary> - **N1.** Ran `scripts/ablation-replace.mjs` on `protocol-exact-qualifier.ts`, replacing the anchor `type: string): boolean {` with the predicate `type is import('@objectstack/core').PackageScopedType`. The anchor went x1 to x0 and the blob changed. `typecheck` then went RED, with one error at the new pin: `protocol-exact-qualifier.test.ts(98,42): error TS2344 ... Actual: never`. The file was restored to blob == HEAD and `git diff HEAD` came back empty. - **N3 boot-load pin.** The hydrator's decline branch in `protocol-registry-hydration.ts` (`if (scoped && canonicalType !== 'flow' && !options.packageId && host.declinesStoredRow(`) was put behind an always-false guard. The rebuilt `dist/` was proven to carry the marker (`ablation-dist-preflight`). Location 4 then went RED, 6 failed: `after the boot load exact: expected 'stored' to be 'alpha action'`, the same for `queue` and `tool`, plus the pre-existing disabled-holder cases. After the restore, the rebuild was proven free of the marker (`--absent`), and the file is back to 294 passed. </details> <details><summary>N3 measurement on main (ba35dfd with only the type-only N1 edit on top; a throwaway describe, not committed)</summary> The stored package-less `action` row is `approve`, and A and B are the shipping packages. Below, "own" means the holder's own item, and "layered own" means the layered read reported no overlay and its effective item was the holder's own. | holders | hydration | `?package=A` before / after | `?package=B` before / after | layered before / after | |---|---|---|---|---| | A | boot load | 200 own / 200 own | 409 not held / 409 not held | own / own | | A | list read | 200 own / 200 own | 409 / 409 | own / own | | A | bare copy `''`, `sys_metadata` | 200 own / 200 own | 409 / 409 | own / own | | A+B, B+A | boot load | 200 own / 200 own | 200 own / 200 own | own / own | | A+B, B+A | list read | 200 own / 200 own | 200 own / 200 own | own / own | | A+B, B+A | bare copy `''`, `sys_metadata` | 200 own / 200 own | 200 own / 200 own | own / own | The boot load reported `{loaded:1, errors:0}` and left the holder's slot holding the holder's own item. A boot load run before the package registers, and then the package, also gives 200 own at each holder's exact address. </details> ## Acceptance notes - **Clause-② reading.** First declared `no`; review#3's contract record (6885158237) ruled the exported return type public surface, so a caller narrowing through the predicate's `true` branch stops compiling: `yes (narrowing)`, `!` title, BREAKING paragraph, one ADR-0087 not-required marker (same reading as review#1 on objectstack-ai#33121). Delta head 82cc3c1 changes only the changeset and this body. - **Not in scope, harness observation only, not filed.** In the same harness, a bare read naming no package with a bare-slot copy in place answers differently from the exact read. With one holder it serves the copy; with two it is refused naming "3 holders". The exact read serves the holder's own in both cases. The bare-slot copy is a hand-registered state: the hydrator no longer produces it, and the heal walk is said to remove a pre-install copy. This harness registers packages without that walk, so no public door was measured. `reach:` none measured. - E1's open PR objectstack-ai#33405 edits the same objectql test file at a different hunk (after line 2529); this PR's hunk is at location 4 (lines 2228–2270). ## Verification Derived gate families (`node scripts/pm/dispatch-gates.mjs --commands`, from the tree at the merge head `4bb529d89`): 64 commands. Each was run, and its exit code was captured before any pipe: - **63 exit 0.** These include `check:changeset-no-major`, `check:adr-0087-registration`, `check:empty-changeset`, `check:closing-keyword-parity`, `check:nul-bytes`, `check:test-source-alias`, `check:cross-package-test-inputs`, `check:type-check-coverage`, `check:type-check-debt`, `check:durability-log-level`, `check:engine-double-contract`, `check:published-files`, `check:dts-closure`, `check:doc-authoring` and `check:issue-citations`. - **1 NOT MEASURED:** `pnpm check:dual-build-cjs-loads`, exit 3, `PREREQUISITE NOT MET`. It reads every package's `dist/`, and this worktree did not build the whole repo. CI carries it. - **Reconciliation:** `dispatch-gates --ran` with the exit codes recorded: 64 derived, 63 run, 1 NOT-MEASURED (derived from the recorded exit 3), 0 UNRUN. - **Lint:** `eslint --no-inline-config` on the three changed `.ts` files gives exit 0. The repo-wide `pnpm lint` is CI's. - No symbol was renamed or removed, so `check-platform-checklist --changed-from` does not apply. - The full farm, dogfood and the `integration` layers are CI's. The title carries no `!` and there is no `(narrowing)` arm, so no dogfood battery is owed. Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: domain:server#5 · os-elon-musk · session_016WV4cz4f7zEQZ2C9GTG382 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5ea8ce5 commit 4bba8b8

4 files changed

Lines changed: 46 additions & 8 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol)!: `judgesPackageLessRows` returns a plain `boolean`, not a type predicate
6+
7+
Clause-②: yes (narrowing) — the exported `judgesPackageLessRows`'s return type moves from the predicate `type is PackageScopedType` to `boolean`, so a TypeScript caller that narrowed `type` through its `true` branch no longer compiles. Its runtime answer is unchanged.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) no key of any schema is added, removed, renamed or re-shaped and no stored row changes shape: what moves is one exported function's TypeScript return type, so there is nothing for `objectstack migrate meta` to rewrite -->
11+
12+
**BREAKING** for a TypeScript caller that narrows `type` to `PackageScopedType` through `judgesPackageLessRows(registry, type)` (for example `if (judgesPackageLessRows(r, t)) useScoped(t)`): it no longer compiles. Call `isPackageScopedType(type)` from `@objectstack/core` first, as `packageLessRowOwners` now does.
13+
14+
`judgesPackageLessRows(registry, type)` was declared `type is PackageScopedType`. Its `false` answer depends on the registry (`readsByPackage`), not on the type alone, so TypeScript narrowed a package-scoped type to `never` in a caller's `false` branch, although a package-scoped type the registry does not read by package (`hook`, for one) lands there. It now returns `boolean`. Its runtime answer is unchanged. To narrow a `string` to `PackageScopedType`, call `isPackageScopedType` from `@objectstack/core`, whose answer depends on the type alone.
15+
16+
No read moves. A stored package-less row of a sealed type (`action`, `queue`, `tool`) of a name a package ships, read at a holder's exact address (`?package=`), gets the holder's own item before and after the boot load (`loadMetaFromDb`), around the list read's hydrator, and with a copy in the registry's bare slot. This holds with one holder and with two. The boot load is now pinned beside the other hydration states.

‎packages/metadata-protocol/src/protocol-exact-qualifier.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
* by the admitted holder's.
1010
*/
1111

12-
import { describe, it, expect } from 'vitest';
12+
import { describe, it, expect, expectTypeOf } from 'vitest';
13+
import type { PackageScopedType } from '@objectstack/core';
1314
import { exactQualifierItem, judgesPackageLessRows, packageLessRowOwners, pairRowOnAddress } from './protocol-exact-qualifier.js';
1415

1516
const BASE = 'com.acme.alpha';
@@ -86,6 +87,17 @@ describe('[#31699] packageLessRowOwners', () => {
8687
expect(packageLessRowOwners({ packageScopedHoldersOf: () => ['a.x', 'b.y'] }, 'action', 'approve')).toEqual(['a.x', 'b.y']);
8788
expect(judgesPackageLessRows({ readsByPackage: () => false }, 'function')).toBe(false);
8889
});
90+
91+
// [#32716 N1] Checked by `tsc` (the package's `typecheck` compiles this
92+
// file): under the type predicate `type is PackageScopedType`, the `false`
93+
// branch below narrowed `type` to `never`, though a package-scoped type the
94+
// registry does not read by package (`hook`) lands there.
95+
it('[#32716 N1] judgesPackageLessRows is a plain boolean: a package-scoped type it does not judge keeps its type in the false branch (BASE: never)', () => {
96+
const type = 'hook' as PackageScopedType;
97+
if (judgesPackageLessRows({ readsByPackage: () => false }, type)) throw new Error('hook is not judged here');
98+
expectTypeOf(type).toEqualTypeOf<PackageScopedType>();
99+
expect(type).toBe('hook');
100+
});
89101
});
90102

91103
/**

‎packages/metadata-protocol/src/protocol-exact-qualifier.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import {
5454
type PackageScopedHolder,
5555
type PackageScopedRefusalReason,
5656
type PackageScopedResolvableType,
57-
type PackageScopedType,
5857
} from '@objectstack/core';
5958
import { ENVIRONMENT_ADDRESS_SEGMENT, readNamespacePositionSegment } from '@objectstack/spec/kernel';
6059
import { installedManifestsOfEngine } from './installed-manifests.js';
@@ -612,8 +611,13 @@ export function resolveCallerPackageAddress(
612611
* narrowed type lets two namespaces hold one name whether or not its readers
613612
* are wired, so the refusal is in place from the change that narrows it
614613
* (`action` since #31697, read through `getItem`), never one reader card later.
614+
*
615+
* A plain `boolean`, never the type predicate `type is PackageScopedType`:
616+
* the `false` answer depends on the registry (`readsByPackage`), not on the
617+
* type alone, so a predicate would narrow a package-scoped type to `never` in
618+
* a caller's `false` branch (#32716 N1).
615619
*/
616-
export function judgesPackageLessRows(registry: { readsByPackage?(type: string): boolean }, type: string): type is PackageScopedType {
620+
export function judgesPackageLessRows(registry: { readsByPackage?(type: string): boolean }, type: string): boolean {
617621
if (!isPackageScopedType(type)) return false;
618622
return registry.readsByPackage?.(type) === true || isNamespaceScopedBareNameType(type);
619623
}
@@ -643,7 +647,9 @@ export function packageLessRowOwners(
643647
name: string,
644648
options?: { includeDisabledPackages?: boolean },
645649
): string[] {
646-
if (!judgesPackageLessRows(registry, type)) return [];
650+
// `isPackageScopedType` narrows `type` (its answer is the type's alone);
651+
// `judgesPackageLessRows` is a plain boolean (its answer is the registry's too).
652+
if (!isPackageScopedType(type) || !judgesPackageLessRows(registry, type)) return [];
647653
if (isPlatformRequestedBareName(type, name)) return [];
648654
// [#32183] The served holders: a read judges them, so a package-less row
649655
// of a name an enabled and a disabled package hold is the enabled one's.

‎packages/objectql/src/package-scoped-exact-qualifier.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,10 +2226,13 @@ describe('[#32568] a package-less row at a holder\'s exact address: declined for
22262226
});
22272227

22282228
describe('location 4: one answer in every hydration state (both registration orders)', () => {
2229-
const STATES = ['stored, not hydrated', 'after the read-side hydrator', "bare-slot copy stamped ''", "bare-slot copy stamped 'sys_metadata'"] as const;
2229+
// [#32716 N3] The boot load (`loadMetaFromDb`) is the other hydration the
2230+
// card names beside the list read: the same answers before and after it.
2231+
const STATES = ['stored, not hydrated', 'after the read-side hydrator', 'after the boot load', "bare-slot copy stamped ''", "bare-slot copy stamped 'sys_metadata'"] as const;
22302232
const enter = async (type: string, state: (typeof STATES)[number]) => {
22312233
storeRow(type, 'active', 'stored');
22322234
if (state === 'after the read-side hydrator') await protocol.getMetaItems({ type } as never);
2235+
if (state === 'after the boot load') expect(await protocol.loadMetaFromDb(), 'the boot load read the row').toMatchObject({ loaded: 1, errors: 0 });
22332236
if (state.startsWith('bare-slot')) {
22342237
registry.registerItem(type, { ...sealedBody(type, 'stored'), _provenance: 'org', _packageId: state.endsWith("''") ? '' : 'sys_metadata' }, 'name' as never);
22352238
}
@@ -2258,11 +2261,12 @@ describe('[#32568] a package-less row at a holder\'s exact address: declined for
22582261
}
22592262
}
22602263

2261-
it(`${type}, one holder: the stored row is declined before and after the read-side hydrator, on the exact and the bare read (BASE: after it, both served the row)`, async () => {
2264+
it(`${type}, one holder: the stored row is declined before and after the boot load and the read-side hydrator, on the exact and the bare read (BASE: after the hydrator, both served the row)`, async () => {
22622265
shipSealed(type, A);
22632266
storeRow(type, 'active', 'stored');
2264-
for (const when of ['before', 'after']) {
2265-
if (when === 'after') await protocol.getMetaItems({ type } as never);
2267+
for (const when of ['before', 'after the boot load', 'after the read-side hydrator']) {
2268+
if (when === 'after the boot load') await protocol.loadMetaFromDb();
2269+
if (when === 'after the read-side hydrator') await protocol.getMetaItems({ type } as never);
22662270
expect(labelOf(await read(type, 'approve', A)), `${when} exact`).toBe(`alpha ${type}`);
22672271
expect(labelOf(await protocol.getMetaItem({ type, name: 'approve' } as never)), `${when} bare`).toBe(`alpha ${type}`);
22682272
}

0 commit comments

Comments
 (0)