You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1a66fcf
Browse filesBrowse the repository at this point in the historyBrowse files
refactor(core,objectql,plugin-sharing): one PackageScopedNameRefusedError class for every package-scoped by-name refusal (#31876)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9Pd2vxfndbHVQLiX3wzkDSN)_Fixes#31852
Clause-②: yes (widening) — `@objectstack/core` and the lean entry
`@objectstack/objectql/core` gain `PackageScopedNameRefusedError`
Metadata-protocol: none
## 维护者速读
- 改了什么:包作用域按名读取被拒时抛出的 `PackageScopedNameRefusedError` 原本在 objectql 和
plugin-sharing 各有一份,现在只在 `@objectstack/core` 声明一次,两个包原名转出同一个类;objectql
的精简入口 `@objectstack/objectql/core`
也导出它。导航翻译检查脚本遇到同名应用被拒时,改为报一条列出所有候选包的组合错误,不再抛出 409 中断。
- 为什么改:两份同名类互不 `instanceof`,以后谁要捕获"包作用域名字冲突"就得猜用哪一份,猜错一半;精简入口的使用者只能按
code 和 status 匹配。
- 风险与回滚:每个入口仍返回 409 `RESOURCE_CONFLICT`、同一句话,行为不变;plugin-sharing
抛出的错误多带一个值相同的 `httpStatus` 字段。回滚即还原本 PR。
-
先看:`packages/core/src/package-scoped-resolution.ts`(类本体)、`packages/plugins/plugin-sharing/src/package-scoped-declarations.ts`(改为转出)、`packages/cli/scripts/check-app-nav-i18n.mjs`(`readMergedApp`)。
- 两分钟验证:`pnpm --filter @objectstack/plugin-sharing exec vitest run
src/package-scoped-declarations.test.ts`,预期 26 个全过,其中 3 个是本 PR 新增的跨包
`instanceof` 断言。
- 需要你做的:无,席位落地。
## What changes
- **`@objectstack/core`** (`package-scoped-resolution.ts`):
`PackageScopedNameRefusedError` is declared here once, beside
`PackageScopedRefusal` and `packageScopedRefusalMessage`. It carries the
union of the two old copies' fields: `code = 'RESOURCE_CONFLICT'`,
`status = 409`, `httpStatus = 409` and `refusal`, and its message is the
refusal's own sentence. Core's barrel already re-exports the module
(`export *`), so no barrel edit.
- **`@objectstack/objectql`** (`package-scoped-read.ts`): the local
class is gone; the module re-exports core's binding under the same name,
so the barrel, `metadata-facade.ts` and `registry.ts` keep their
imports.
- **`@objectstack/objectql/core`** (lean entry, `core.ts`): exports the
class too, since the `SchemaRegistry` it exports throws it from
`getApp`. Core is already in the entry's closure, so
`core-boundary.ratchet.test.ts` stays green.
- **`@objectstack/plugin-sharing`** (`package-scoped-declarations.ts`):
the local class is gone; the module re-exports core's binding under the
same name, so `sharing-rule-service.ts` and `ownership-queue-service.ts`
keep their imports. Its refusals gain `httpStatus: 409`.
- **`packages/cli/scripts/check-app-nav-i18n.mjs`** (N1): the app is
read through a new pure `readMergedApp(name, getApp, isRefusal)`. A
`PackageScopedNameRefusedError` from `registry.getApp(name)` becomes a
composition finding naming the app and every candidate, reported beside
the gate's other composition errors (so the coverage verdict is not
attempted). It never reads as "not registered", whose remedy is the
opposite. Any other error is rethrown untouched. I chose "catch and
report" over "read by the shell's package": a read naming the shell
package would silently pick the shell's app and hide a real name clash
from the gate.
Measured site census (delta ruling 1), `git grep -n
"PackageScopedNameRefusedError\|RESOURCE_CONFLICT.*refusal"` on
`origin/main` `074a014c`: two declarations (objectql
`package-scoped-read.ts`, plugin-sharing
`package-scoped-declarations.ts`); throws in `package-scoped-read.ts`,
`sharing-rule-service.ts` (2) and `ownership-queue-service.ts` (2);
`instanceof` in `metadata-facade.ts`, `sharing-rule-service.ts` and
`ownership-queue-service.ts` (2). No third copy on main. Open PRs read
at their heads: E3 #31815 adds no site. plugin-email #31825 adds a
separate class, `EmailTemplateAmbiguousError` (same 409
`RESOURCE_CONFLICT` envelope, different name, extra `template` and
`candidates` fields), in `plugin-email/src/template-loader.ts`. It is
left to that PR's seat, as ruled.
Changeset: `.changeset/31852-one-package-scoped-refusal-class.md`, patch
for core, objectql and plugin-sharing. `@objectstack/cli` takes none:
its `files` is `dist`, `README.md` and `CHANGELOG.md`, so `scripts/`
does not publish.
## Tests
- `packages/core/src/package-scoped-resolution.test.ts`: the class
carries `code`, `status`, `httpStatus`, `refusal` and the refusal's
sentence.
- `packages/objectql/src/package-scoped-e8-readers.test.ts`: `toBe`
identity of the class from `package-scoped-read.js`, the barrel and the
lean `./core` entry against core's; a `getApp` refusal is `instanceof`
the lean entry's class.
-
`packages/plugins/plugin-sharing/src/package-scoped-declarations.test.ts`:
`toBe` identity of plugin-sharing's and objectql's export against
core's; a refusal from objectql's by-name reader
(`SchemaRegistry#getApp`) is `instanceof` plugin-sharing's class, and a
refusal from plugin-sharing's door
(`SharingRuleService#declaredRuleNamed`) is `instanceof` objectql's
class.
- `check-app-nav-i18n.mjs --self-test`: six new cases for
`readMergedApp` (refusal becomes a finding, names every candidate, never
reads as unregistered; served and unregistered reads unchanged; a
non-refusal error is rethrown, as a negative control; the boot read
passes the class test).
- Wire envelope (delta ruling 5) already pinned by existing tests,
unchanged: objectql `package-scoped-e8-readers.test.ts` ("the refusal
crosses a wire door as 409 RESOURCE_CONFLICT") and plugin-sharing
`package-scoped-declarations.test.ts` ("refuses the sharing rule by name
with 409 RESOURCE_CONFLICT naming both packages").
No existing test was edited or deleted.
## Acceptance notes
- plugin-email #31825 adds `EmailTemplateAmbiguousError`, a third class
for the same refusal family. Not touched here (ruling 1); its seat
decides whether it extends or reuses this class.
## Verification
Head `3bb5c3e6` (`02e922a7` plus a merge of `origin/main`).
<details><summary>Red first, on origin/main 074a014 (tests added, fix
not yet applied)</summary>
- core `package-scoped-resolution.test.ts`: `Tests 1 failed | 23 passed
(24)`.
- objectql `package-scoped-e8-readers.test.ts`: `Tests 2 failed | 71
passed (73)`.
- plugin-sharing `package-scoped-declarations.test.ts` (core and
objectql built from main): `Tests 3 failed | 23 passed (26)`.
</details>
<details><summary>Ablation (scripts/ablation-replace.mjs, both legs
restored to HEAD by blob hash)</summary>
- plugin-sharing: `export { PackageScopedNameRefusedError };` replaced
by a local class. `mutation landed: anchor 1 -> 0`; `Tests 3 failed | 23
passed (26)`, all three new cross-package pins red; `restored: blob ==
HEAD (339e4de)`.
- objectql: the same replacement in `package-scoped-read.ts`. `mutation
landed: anchor 1 -> 0`; `Tests 1 failed | 72 passed (73)` (the identity
pin); `restored: blob == HEAD (45f07d0)`.
</details>
<details><summary>Builds, tests, typecheck, lint</summary>
- `turbo run build --filter='./packages/**' --concurrency=2` under the
lock at `02e922a7`: `VERDICT command-exit 0`, `Tasks: 81 successful, 81
total`.
- At `02e922a7`, one lock run: `typecheck` for core, objectql,
plugin-sharing, then `pnpm --filter @objectstack/core test` (`Test Files
139 passed`, `Tests 3207 passed`), plugin-sharing (`Test Files 72
passed`, `Tests 1496 passed`), objectql (`Test Files 580 passed`, `Tests
11936 passed`): `VERDICT command-exit 0`.
- At `3bb5c3e6` (after the merge; incoming main touched other files of
core and objectql): rebuild of the three packages, their `typecheck`,
and the three changed test files plus `core-boundary.ratchet.test.ts`:
24/24, 75/75, 26/26, `VERDICT command-exit 0`.
- `pnpm check:app-nav-i18n` (self-test, then the live composition): exit
0, `OK (13 contributor(s), 11 locale(s), 2 app(s) — setup: 57 merged nav
id(s), account: 13 merged nav id(s) …)`.
- `eslint --no-inline-config` on `packages/core/src`,
`packages/objectql/src`, `packages/plugins/plugin-sharing/src` and the
script: exit 0.
</details>
<details><summary>Derived gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 73 commands, each run with its exit code
captured before any pipe, all exit 0 at `02e922a7`. Reconciliation: `73
derived famil(ies) accounted for — 73 run, 0 NOT-MEASURED (a DERIVED
zero — all 73 recorded an exit code and none of them is 3)`. Re-run at
`3bb5c3e6`: see the report comment on the card.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmQHXhv9SKTU1qQ9CNC)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
refactor(core,objectql,plugin-sharing): one `PackageScopedNameRefusedError` class for the 409 a package-scoped by-name read refuses with
8
+
9
+
Clause-②: yes (widening)
10
+
Metadata-protocol: none
11
+
12
+
-**`@objectstack/core`: `PackageScopedNameRefusedError`** (new export), beside `PackageScopedRefusal` and `packageScopedRefusalMessage`. It carries `code: 'RESOURCE_CONFLICT'`, `status: 409`, `httpStatus: 409` and the resolver's `refusal`, and its message is the refusal's own sentence, which names every candidate.
13
+
-**`@objectstack/objectql`** and **`@objectstack/plugin-sharing`** each declared a class of that name before, and an `instanceof` against one never matched the other. Both now re-export core's class under the same name, so every existing import keeps resolving and one `instanceof` matches a refusal from an objectql reader (`SchemaRegistry#getApp` and the other ADR-0150 by-name readers) and from a plugin-sharing door (a declared sharing rule, queue or assignment rule name) alike. objectql's copy already carried `httpStatus`; plugin-sharing's refusal now carries it too, with the same value.
14
+
-**`@objectstack/objectql/core`** (the lean entry) now exports `PackageScopedNameRefusedError` too, since the `SchemaRegistry` it exports throws it.
15
+
16
+
No door changes its answer: each still refuses `409 RESOURCE_CONFLICT` with the same sentence.
* The pass line, as a VALUE so `--self-test` can pin it.
236
273
*
@@ -702,6 +739,51 @@ function selfTest() {
702
739
expect('#14857 NEGATIVE CONTROL: the literal-advisory pin can still fail',spellsALiteralCode(controlLiteralAdvisory),'the predicate no longer sees a spelled-out code');
703
740
expect('#14857 NEGATIVE CONTROL: the stale-code pin can still fail',/Exitcode1\b/.test(controlLiteralAdvisory()),'the stale-spelling predicate no longer sees `Exit code 1`');
704
741
742
+
// ── A REFUSED app read is a composition finding, never a throw or a miss (#31852) ──
743
+
//
744
+
// `getApp(name)` naming no package is refused when two packages ship the name
745
+
// (ADR-0150 D3). Recorded shape: the refusal class carries `code`, `status`
746
+
// and the resolver's `refusal` with every candidate. The local class stands
747
+
// in for `PackageScopedNameRefusedError` so this runs without a build.
0 commit comments