Repository navigation
Commit 9ed2ee1
refactor(metadata-core): look up a package's customization pair through the App that carries it (pairOf), behaviour unchanged (#31026)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoGiPU3nfGMxJdPY5ydbkoUG)_
Refs #29594 (PR 1 of 5–7: the lookup refactor only; the ensure door
returning the App's pair, the `customizable` verdict, the `sys_`
pass-through close and the platform pair follow in later PRs)
Clause-②: yes (widening)
Metadata-protocol: none
Ruling-ref: 6691022506
## 维护者速读
- 改了什么:「这个包的定制包是哪个」这个问题现在只有一个答案入口 `pairOf(base)`(在
`@objectstack/metadata-core`),它先问「这个包属于哪个 App」(`appOf`),再按 App 推出
`<id>.custom`。原来散在 metadata-protocol、objectql、两个 service 里的 20 处直接推导和 3
处 `isCustomizationPairOf` 判定都改走它。
- 为什么改:裁决 ① 定制单位 = App(HotCRM 四个包只有一个
`app.objectstack.hotcrm.custom`)。下一个 PR 只要改 `appOf` 一处,所有读写门、列表、卸载拒绝就一起按
App 找定制包,不会有漏改的地方各说各话。
- 风险与回滚:本 PR 不改任何行为:`appOf` 现在原样返回包自己,所以每处答案、拒绝原因、定制包 id
都和今天一模一样;`runtime` 的两处留给下一个 PR。回滚即 revert 本 PR。
- 先看:`packages/metadata-core/src/customization-pair-lookup.ts`(整个查找就 3
个函数);`packages/metadata-protocol/src/protocol-packaged-base-refusal.ts`(改动最多的一处,5
个调用点 + 1
处判定);`packages/metadata-protocol/src/served-override.ts`(被五个读路径共用的判定)。
- 两分钟验证:`pnpm --filter @objectstack/metadata-core exec vitest run
--maxWorkers=2 src/customization-pair-lookup.test.ts`,预期 16
个用例全绿(App、模块、独立包、`sys` 内核包、无命名空间的包都与旧推导相同)。
- 需要你做的:无,席位落地。
## What changes
**The lookup (`packages/metadata-core/src/customization-pair-lookup.ts`,
exported from `@objectstack/metadata-core`).**
- `appOf(packageId)`: the App that carries a package for customization.
Today the identity: every package is its own App, which is what every
call site assumed.
- `pairOf(base)` = `customizationPackageId(appOf(base))`: the pair, or
the same refusal the id rule names (`base_id_missing`,
`base_is_customization_package`, `base_id_invalid`).
- `isPairOf(pairId, base)`: whether `pairId` is THE pair of `base`, the
predicate `isCustomizationPairOf` answered.
The id rule itself stays in `@objectstack/spec/kernel`; `packages/spec`
is untouched. **Why metadata-core and not metadata-protocol or
objectql:** `service-datasource` (a class (i) site) declares neither of
those, only `metadata-core`, and `metadata-core` is the one package
every class (i) caller already declares (metadata-protocol, objectql,
service-automation, service-datasource, runtime). No new dependency
edge, no lockfile change. That is the criterion already used for the
write dispatch predicates and the code-artifact provenance test in that
package (claim amendment 6691222368).
**The call sites.** Each class (i) site now calls `pairOf` / `isPairOf`
where it called `customizationPackageId(base)` /
`isCustomizationPairOf(pair, base)`. Nothing else in those functions
moved: same branches, same sentences, same refusal codes.
**Census** of `git grep -n customizationPackageId origin/main --
'packages/**/*.ts' ':!*.test.ts'` at `69e133ea`: 53 hits in 17 files.
(i) = "the pair of this package" derivation, routed through the lookup.
(ii) = the definition, a parse ("is this id a pair"), an import, a doc
mention or a field name; stays.
| File | Hits | (i) routed | (i) deferred | (ii) stays |
|:--|--:|--:|--:|:--|
| `lint/src/validate-customization-namespace.ts` | 3 | 0 | 0 | 3:
import, doc, L108 is-a-pair skip (the `base_is_customization_package`
reason on the manifest's own id, the same parse as
`isCustomizationPackage(manifest.id)`) |
| `metadata-protocol/src/protocol-customization-package.ts` | 3 | 1
(L255, ensure door's pair id) | 0 | 2: import (removed), doc (reworded)
|
| `metadata-protocol/src/protocol-discovery-and-bases.ts` | 2 | 1 (L330,
pair translation bundle) | 0 | 1: import |
| `metadata-protocol/src/protocol-environment-rows.ts` | 2 | 1 (L296,
`baseAddressServesMember`) | 0 | 1: import |
| `metadata-protocol/src/protocol-meta-layered-reads.ts` | 3 | 2 (L408,
L413) | 0 | 1: import |
| `metadata-protocol/src/protocol-meta-list-reads.ts` | 4 | 3 (L197,
L531, L675) | 0 | 1: import |
| `metadata-protocol/src/protocol-overlay-merge.ts` | 2 | 1 (L114) | 0 |
1: import |
| `metadata-protocol/src/protocol-packaged-base-refusal.ts` | 7 | 5
(L197, L217, L419, L684, L1075) | 0 | 2: import, doc |
| `metadata-protocol/src/protocol-packageless-overlay-migration.ts` | 3
| 1 (L383) | 0 | 2: import, doc |
| `metadata-protocol/src/protocol-served-overrides.ts` | 2 | 1 (L98) | 0
| 1: import |
| `metadata-protocol/src/protocol-write-gates.ts` | 2 | 1 (L330,
`pairOfAddedMember`) | 0 | 1: import |
| `objectql/src/registry.ts` | 6 | 1 (L7311, uninstall refusal) | 0 | 5:
import, 2 docs, `PackageUninstallExtendedError.customizationPackageId`
field declaration + assignment (a public property name, not a
derivation) |
| `runtime/src/domains/packages.ts` | 4 | 0 | 2 (L669
`customizeInPairRemedy`, L3628 package customizations read) | 2: import,
doc |
| `services/service-automation/src/flow-precedence.ts` | 2 | 1 (L259,
`undeclaredRemedy`) | 0 | 1: import |
| `services/service-datasource/src/plugin.ts` | 2 | 1 (L372, import
landing) | 0 | 1: import |
| `spec/src/kernel/customization-package.ts` | 5 | 0 | 0 | 5: the
definition and its own inverse/predicate |
| `spec/src/api/package-lifecycle.zod.ts` | 1 | 0 | 0 | 1: doc |
| **Total** | **53** | **20** | **2** | **31** |
Class (i) is 22 (the ruling estimated about 20): 20 routed here, 2 in
`packages/runtime/src/domains/packages.ts` left for PR 2 by the order,
because #30756 (same seat) is editing that file.
Plus 3 `isCustomizationPairOf(pair, base)` sites, the same derivation
through a second spec helper, routed to `isPairOf` (claim amendment
6691222368): `metadata-protocol/src/served-override.ts:88`
(`isServedOverrideRowOf`, the predicate five reads share),
`protocol-class-head.ts:190` (restore intent),
`protocol-packaged-base-refusal.ts:1076` (declared-override gate, which
already reads `pairOf` two lines up). After this PR, `git grep -n
"customizationPackageId(\|isCustomizationPairOf(" -- 'packages/**/*.ts'
':!*.test.ts' ':!packages/spec/**'` answers 4 lines: the lookup itself,
lint's is-a-pair skip, and the 2 deferred runtime sites.
**Not in this PR:** the ensure door resolving a member to its App and
answering the App's pair (200), the `customizable` verdict, the `sys_`
pass-through in `validateObjectNamespacePrefix`, the platform pair, the
ADR-0146 D3 amendment (#31014, spec seat). Kernel objects stay not
customizable: ③ is ruled (6691217245), the kernel whitelist (Users,
Organizations) is a later version's work.
## Tests
New `packages/metadata-core/src/customization-pair-lookup.test.ts` (16
cases): for an App package (`app.objectstack.hotcrm`), a module its
artifact brings (`app.objectstack.hotcrm.service`, still its own pair
today), a standalone package, a `sys` kernel package
(`com.objectstack.plugin-auth`, scope `system`) and a manifest with no
namespace, `appOf` is the identity and `pairOf` equals
`customizationPackageId` and the literal pair; the five refusals match
the id rule; `isPairOf` equals `isCustomizationPairOf` over seven
candidates per row.
The existing suites of every touched package are the behaviour pin: they
assert the served answers (pair ids in refusal sentences, served
override rows, list and layered reads, uninstall refusal, flow
precedence remedy, datasource import landing) and none of them changed.
<details><summary>Ablation (appOf moved off the identity,
twice)</summary>
Both mutations through `node scripts/ablation-replace.mjs` on the line `
return packageId;` of `customization-pair-lookup.ts`, each restored and
proved (`blob == HEAD bd176c7`, `git diff HEAD` empty, whole-tree
`git status --porcelain` empty).
1. Source, the unit table: `return packageId ===
'app.objectstack.hotcrm.service' ? 'app.objectstack.hotcrm' :
packageId;` (the HotCRM module resolved to its App). `Tests 2 failed |
14 passed (16)`: the module row's `appOf` (`Expected:
"app.objectstack.hotcrm.service"`, `Received: "app.objectstack.hotcrm"`)
and its `isPairOf` (`expected false to be true`). The other rows stay
green.
2. Through `dist/`, the consumers: `return packageId === 'com.acme.crm'
? 'com.acme.suite' : packageId;`, `pnpm --filter
@objectstack/metadata-core build`, `ablation-dist-preflight.mjs
@objectstack/metadata-core '"com.acme.suite"' --source-marker=…` exit 0
(marker in 2 built files). `metadata-protocol`
`served-override.test.ts`, `protocol.pair-translation-bundle.test.ts`,
`protocol.named-base-overlay-write.test.ts`,
`protocol.packaged-base-refusal.test.ts`: **48 failed** (23 + 22 + 1 +
2), for example `Expected: "'com.acme.crm.custom'
(?package=com.acme.crm.custom)"`, `Received: "… save it into
'com.acme.suite.custom' (?package=com.acme.suite.custom) …"`. So the
write gates, the served-override predicate and the pair translation read
ask the lookup through the published build. Restore, rebuild, preflight
`--absent` exit 0 (absent from all 12 built files), tree clean.
</details>
## Verification
<details><summary>Suites, typechecks, lint</summary>
Before the merge of `origin/main` (head `33e47fa35`):
- `pnpm --filter @objectstack/metadata-core test`: Test Files 25 passed,
Tests 944 passed
- `pnpm --filter @objectstack/lint test`: Test Files 196 passed, Tests
8275 passed
- `pnpm --filter @objectstack/service-datasource test`: Test Files 72
passed, Tests 1239 passed
- `pnpm --filter @objectstack/service-automation test`: Test Files 264
passed, Tests 3431 passed
- `pnpm --filter @objectstack/metadata-protocol test`: Test Files 320
passed, 4 skipped; Tests 22487 passed, 26 skipped
- `pnpm --filter @objectstack/objectql test`: Test Files 560 passed,
Tests 11207 passed
- `typecheck` on metadata-core, metadata-protocol, objectql,
service-automation, service-datasource: exit 0 each
- `pnpm exec eslint --no-inline-config` over the 18 changed `.ts` files:
exit 0
- `node scripts/check-platform-checklist.mjs --changed-from
origin/main`: exit 0 (22 anchors judged, 0 lost)
After merging `origin/main` at `33bc8ae5f` (one conflict, the spec
import line of `protocol-write-gates.ts`: main added
`DEFAULT_METADATA_TYPE_REGISTRY` beside `customizationPackageId`;
resolved to `DEFAULT_METADATA_TYPE_REGISTRY` alone, the body already
read `pairOf`), `pnpm install --frozen-lockfile` + closure rebuild, head
`979d839e4`:
- `pnpm --filter @objectstack/metadata-core test`: Test Files 25 passed,
Tests 944 passed
- `pnpm --filter @objectstack/metadata-protocol test`: Test Files 320
passed, 4 skipped; Tests 22489 passed, 26 skipped
- `pnpm --filter @objectstack/objectql test`: Test Files 560 passed,
Tests 11207 passed
- `pnpm --filter @objectstack/service-automation test`: Test Files 264
passed, Tests 3431 passed
- `pnpm --filter @objectstack/service-datasource test`: Test Files 72
passed, Tests 1279 passed
- `typecheck` on the same five: exit 0 each
- census re-run on the merged tree: no new `customizationPackageId(` /
`isCustomizationPairOf(` call site arrived with main
</details>
<details><summary>Derived gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` against this diff, every line run with stdin
closed, exit codes recorded before any pipe: record
`/mnt/project-files/server-seat-2/r2026-11-06/out/29594-gates-ran-33e47fa35.list`.
`--ran` reconciliation: **65 derived, 64 run, 1 NOT-MEASURED, 0 UNRUN**;
every run family exit 0.
- NOT MEASURED: `pnpm check:dual-build-cjs-loads`, reason: PREREQUISITE
NOT MET (it reads every package's `dist/`; this worktree built the
closure of the touched packages, not the whole workspace). CI's `Lint &
Repo Gates` runs it on a full build.
- `node scripts/check-plugin-teardown-shape.mjs --self-test` first
answered exit 3 on the shallow clone (pinned fixture commit `621a4876`
unreachable); after `git fetch origin 621a487…` it is exit 0 (48
cases).
</details>
## Acceptance notes
- **Changeset:** `Clause-②: yes (widening)` (the contract review's
reading: three new names on the published `@objectstack/metadata-core`
entry), patch on `@objectstack/metadata-core` (three new exports),
`metadata-protocol`, `objectql`, `service-automation`,
`service-datasource` (their dist now imports the lookup). No served
answer changes, so `Metadata-protocol: none`.
- **Deferred to PR 2, named here so it is not lost:**
`packages/runtime/src/domains/packages.ts` L669 and L3628 (now L672 /
L3737 after the merge). The parse direction
(`customizationBasePackageId` in cli `package/install.ts`,
cloud-connection `marketplace-install-local-plugin.ts`, runtime,
metadata-protocol) is class (ii) and stays: it maps a pair to its base,
which under the App unit is the App.
- **Outside this census (`packages/**` only), for PR 2's rehearsal and
the `domain:ui` half:** six client-side derivations in
`ui/packages/app-shell` call `customizationPackageId` from the spec
directly: `views/metadata-admin/ResourceListPage.tsx:211`,
`views/studio-design/AutomationsFlowRail.tsx:367`,
`BuilderLanding.tsx:163`, `CustomizationMark.tsx:143`,
`customizationMarks.ts:58`, `packages-io.ts:239`. They answer the same
as the server today; once `appOf` resolves a module to its App they
would still derive the module's own pair (for example
`app.objectstack.hotcrm.service.custom`) until the console reads the
served pair (ruling 6691022506 routes that to `domain:ui`, after
#29591).
- **For PR 2:** the module row of the new unit table
(`app.objectstack.hotcrm.service` →
`app.objectstack.hotcrm.service.custom`) pins today's answer on purpose;
it is the row the App resolver is meant to flip.
- `PackageUninstallExtendedError.customizationPackageId` keeps its name:
it is a public error property, and renaming it is not part of a
no-behaviour-change refactor.
- GitHub writes: this PR through the fleet-write relay `pr_create`; the
harness's assignee/reviewer step is skipped per the dispatch frame (the
seat assigns at hand-over).
Head after the review fixes: `678d6d6e` (changeset declaration + one
test docblock line).
<!-- signed: domain:server#2 · os-tesla ·
session_01L9qibyvxbrLP4jm4PargoH -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9052337 commit 9ed2ee1
19 files changed
Lines changed: 236 additions & 53 deletions
File tree
- .changeset
- packages
- metadata-core/src
- metadata-protocol/src
- objectql/src
- services
- service-automation/src
- service-datasource/src
| 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 | + | |
| 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 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 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 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | 104 | | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | | - | |
| 410 | + | |
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | | - | |
| 296 | + | |
297 | 297 | | |
298 | 298 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | | - | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
| 408 | + | |
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
413 | | - | |
| 413 | + | |
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
194 | 193 | | |
195 | 194 | | |
196 | 195 | | |
197 | | - | |
| 196 | + | |
198 | 197 | | |
199 | 198 | | |
200 | 199 | | |
| |||
528 | 527 | | |
529 | 528 | | |
530 | 529 | | |
531 | | - | |
| 530 | + | |
532 | 531 | | |
533 | 532 | | |
534 | 533 | | |
| |||
672 | 671 | | |
673 | 672 | | |
674 | 673 | | |
675 | | - | |
| 674 | + | |
676 | 675 | | |
677 | 676 | | |
678 | 677 | | |
| |||
0 commit comments