Repository navigation
Commit f02f4f6
fix(core): refuse an artifact package cycle as 422 CYCLIC_ARTIFACT_PACKAGES; install-local answers resolver refusals instead of a 500 (#34708)
Fixes #34574
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:组合制品里的包如果互相依赖成环,安装接口现在回 422,错误码是新登记的
`CYCLIC_ARTIFACT_PACKAGES`,`details.cycle`
列出环上的包。另外,本地安装在真实运行时下遇到制品解析器的其它三种拒绝时,也按各自的 422 回答,不再回不透明的 500。
- 为什么改:以前作者只拿到一个不说原因的 500,要翻服务端日志才知道是循环依赖,或是 `packages` 写错了。
- 风险与回滚:只改了被拒绝的请求怎么回答,原来能装上的制品照样能装。内核启动遇到插件循环时,报错文字与以前逐字相同。回滚就是 revert 本
PR,新错误码随之撤销。
-
先看:`packages/cloud-connection/src/marketplace-install-local-plugin.ts`(1c
步新增的拦截,以及 `declaredRefusalAnswer` 转发
`details`)、`packages/core/src/artifact-packages.ts`(环如何变成
422)、`packages/spec/src/api/error-code-ledger.zod.ts`(新错误码的登记行)。
- 两分钟验证:`pnpm --filter @objectstack/cloud-connection exec vitest run
src/marketplace-install-local-resolver-refusal-real-runtime.test.ts`,预期
5 个用例全部通过:环、`packages` 不是数组、包 id 重复这三种都回 422 和各自的错误码,合法的组合制品照常装上(200)。
- 需要你做的:无,由席位在契约档审核后落地。
## What changes
- **`@objectstack/core`**
- `resolvePluginOrder` now throws a cycle as `PluginOrderCycleError`.
This is a new exported `Error` subclass with a `cycle` property listing
the names along the cycle: each depends on the next, and the first is
repeated last. The message is still `[Kernel] Circular dependency
detected: NAME`, and the error carries no `code` or `status`, so kernel
boot and the other callers of the sorter see no change.
- `resolveArtifactPackageEntries` reads the cycle off that error, not
off a second walk of the graph. It refuses with the envelope its sibling
refusals use: `code: 'CYCLIC_ARTIFACT_PACKAGES'`, `status: 422` and
`details: { cycle }`. The message names the cycle as `"a" -> "b" -> "a"`
and still contains `Circular dependency detected`. Any other throw from
the sorter is rethrown unchanged.
- **`@objectstack/spec`**: `CYCLIC_ARTIFACT_PACKAGES` is registered in
`ERROR_CODE_LEDGER` under `@objectstack/core`, beside its three
siblings, using the seat's ledger text. The generated API references
were regenerated with `check:generated --fix`; only `check:docs` was
stale:
`content/docs/references/api/{error-code-ledger,contract,automation-api}.mdx`.
- **`@objectstack/cloud-connection`** (`POST
/api/v1/marketplace/install-local`)
- Step 1c, the runtime binder's unrunnable-code judgements, now answers
a refusal from the artifact resolver with that refusal, through
`declaredRefusalAnswer`. Steps 2a, 2b and 2c″ already did this. An
undeclared throw is still rethrown.
- Over the real runtime, step 1c is the first step that resolves a
composed bundle's packages. Before this change, every resolver refusal
(all three siblings, and the cycle) left the handler as a throw there.
The transport renders no 422, so it answered `500 INTERNAL_ERROR`.
- `declaredRefusalAnswer` now also forwards the refusal's own `details`,
which is how a cycle's `details.cycle` reaches the client.
- Docblocks that described the cycle as a bare `Error` are corrected in
`dev-i18n.ts` and `runtime/src/artifact-collections.ts`. Both are
comment-only, so those packages get no changeset entry.
- `scripts/driver-memory-census.ledger.json` gains one
`mock-replacement` row, for `dev-i18n-packages-reader.test.ts`. That
suite now replaces `@objectstack/driver-memory` with a
not-found-throwing `vi.mock`, as five sibling plugin-dev harnesses do.
Every DevPlugin boot in the file passes `driver: false`, so the real
driver is never loaded. The mock exists because
`check:test-source-alias` asks an edited test that reaches
`dev-plugin.ts`'s lazy driver import either to pay that load at
collection or to mock it. The file's old comment forbidding a mock is
rewritten to say why a replacement mock is not a consumer. The seat
approved this in amendment 6941981971.
## Tests
- **New pin, over the REAL runtime** (no module mock):
`packages/cloud-connection/src/marketplace-install-local-resolver-refusal-real-runtime.test.ts`
drives the real install-local handler.
- A two-package cycle answers `422 CYCLIC_ARTIFACT_PACKAGES` with
`details.cycle`.
- `packages: 'not-a-list'` answers `422 INVALID_ARTIFACT_PACKAGES`.
- A duplicate package id answers `422 DUPLICATE_ARTIFACT_PACKAGE`.
- In those three cases nothing is registered, ledgered or read.
- Control: the same packages without the closing dependency install
(200).
- A probe asserts that the runtime under test really carries
`collectJobsWithoutBody`.
- It is a new file rather than a `describe` in the #34432 file because
that file mocks `@objectstack/runtime` for the whole file.
- **Core**
- `artifact-packages.test.ts` covers a two-package cycle (code, status,
`details.cycle`, the message path) and a cycle path that skips packages
outside the cycle and ignores an external dependency. Its control is the
same packages without the closing edge, which resolve in dependency
order.
- `plugin-order.test.ts` covers `PluginOrderCycleError`'s path,
unchanged message and absent `code`/`status`, and a self-dependency.
- **Tests this change forced to move**, each named:
- `marketplace-install-local-resolver-refusal-34432.test.ts`: its cycle
case pinned the cycle as an undeclared throw that is rethrown. It now
pins the declared `422 CYCLIC_ARTIFACT_PACKAGES` and `details.cycle`
under that file's runtime mock, where step 2a reaches the resolver
first. The rethrow leg has no other producer: the resolver's only
remaining non-envelope throws are `Plugin not found` and `Dependency not
found`, and neither is reachable through `optionalDependencies`. The 503
control (an unreadable table) is unchanged.
- `dev-i18n-packages-reader.test.ts`: its cycle case pinned `code` and
`status` as undefined. It now pins `CYCLIC_ARTIFACT_PACKAGES`, 422 and
`details.cycle`. The memory driver is now a replacement mock (see What
changes).
- `marketplace-install-local-namespace-gate-33922.test.ts`, case
"UNMOVED — an artifact MEMBER's refused namespace...": this case boots
the real runtime and pinned the resolver's
`INVALID_ARTIFACT_PACKAGE_ENTRY` as a throw out of the handler, which is
the step-1c escape this PR closes. It now asserts the answered 422 with
the same code and sentence, ADR-0112 envelope-clean.
<details><summary>Test runs (b1dc2a6, the last code commit; 8490dc5
adds only a merge of ui/ files from main)</summary>
- On b1dc2a6, after a full `turbo run build`, under the verify lock
(VERDICT command-exit 0):
- spec `check:generated`: 14/14 up to date.
- plugin-dev `test`: Test Files 10/10, Tests 89/89.
- core `plugin-order` + `artifact-packages`: Test Files 2/2, Tests
42/42.
- cloud-connection real-runtime + 34432 + namespace-gate-33922: Test
Files 3/3, Tests 25/25.
- `typecheck` for plugin-dev and cloud-connection: exit 0.
- Whole-package runs on 1270f90 + f118d4c, before the forced moves:
- `typecheck` for core, cloud-connection, plugin-dev, spec and runtime:
exit 0.
- core `test`: 151 files, 3611 tests, all passed.
- plugin-dev `test`: 10 files, 89 tests, all passed.
- spec `test`: 847 files, 27154 passed, 1 todo.
- objectql `artifact-load-path` + `package-source-stamp`: 2/2 files,
26/26 tests.
- cloud-connection `test`: 1 failed of 1308. That was the namespace-gate
case named above; after its move the file reads 15/15.
- The typecheck for those five packages was re-run after the forced
moves: exit 0.
</details>
<details><summary>Ablations, one per behaviour
(scripts/ablation-replace.mjs, anchor hit 1, mutation landed, restore
proven blob == HEAD and git diff HEAD empty)</summary>
Every mutated file is read from source by the suite that runs, so no
dist preflight is needed. The core suites import their own src. The
cloud-connection suites import the handler by relative path; it reads
`@objectstack/core` from dist, which was built from this head.
- A1, `artifact-packages.ts`: the cycle rethrown bare (`throw err;`).
Core: 2 failed / 40 passed, the two cycle cases.
- A4, `plugin-order.ts`: the sorter throws the old bare `Error`. Core: 4
failed / 38 passed, the two `PluginOrderCycleError` cases and the two
resolver cycle cases.
- A2, `marketplace-install-local-plugin.ts`: step 1c's call moved ahead
of its `try`. Cloud-connection: 3 failed / 7 passed, the real-runtime
cycle, not-a-list and duplicate cases. The control and the
mocked-runtime file stay green.
- A3, `declaredRefusalAnswer`: the `details` spread deleted.
Cloud-connection: 2 failed / 8 passed, the `details.cycle` assertions in
both files.
</details>
## Acceptance notes
- **FROM → TO, measured.**
- FROM, on 60552cd: a two-package cycle POSTed to
`/api/v1/marketplace/install-local` through a real `HonoHttpServer` raw
app answered `500 {"code":"INTERNAL_ERROR","message":"Internal server
error"}`. That held both under the #34432 runtime mock and over the real
runtime. Over the real runtime, `packages: 'not-a-list'` and a duplicate
id also answered `500 INTERNAL_ERROR`: the escape frame is
`unrunnableCode` → runtime `collectJobsWithoutBody`, and
`declaredEnvelopeForThrow` renders no 422.
- TO: 422 with the resolver's own code, and `details.cycle` for a cycle.
- **Clause-②: yes (widening)**, per claim amendment 6939909352. One
public error code is minted, and a 500 becomes a typed 422. Nothing that
was accepted before is refused now.
- **Surface:** amendment 6941981971 added
`marketplace-install-local-namespace-gate-33922.test.ts` (moved by the
step-1c fix, named under Tests) and
`scripts/driver-memory-census.ledger.json` (one `mock-replacement` row).
`check:driver-memory-census` and `check:test-source-alias` both exit 0
on 8490dc5.
- **Generated:** only `check:docs` was stale after the ledger row. It
was regenerated with `check:generated --fix` into
`content/docs/references/api/error-code-ledger.mdx`, `contract.mdx` and
`automation-api.mdx`. The other 13 artifacts were up to date, and they
still were after the last `origin/main` merge, when `check:generated`
was re-run.
- **Callers of `resolveArtifactPackageEntries` /
`resolveArtifactPackageOrder`** (cli namespace utils, core
stack-collections, metadata, objectql, plugin-dev, plugin-security,
runtime, verify) now see a cycle as the typed refusal.
- No caller in `packages/**` source reads the old message text.
- Two tests match only `/Circular dependency detected/`: the dogfood
`dataset-app-reads-module` cell 3 and core `plugin-order.test.ts:69`.
The new message keeps that phrase.
- install-local's rehydrate classifies a declared 4xx as a refusal that
no restart heals, which is the correct reading for a cycle.
## Verification
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` at head 8490dc5 derived 129 families. All
129 were run, each with stdin from `/dev/null` and its exit code
captured before any pipe; **all 129 exited 0**.
- `--ran` reconciliation: 129 derived, 129 run, 0 NOT-MEASURED, 0 UNRUN.
- `node scripts/pm/check-governed-merges.mjs --pr 34708` at 8490dc5:
- `✅ NOT governed — ordinary queue landing applies to a PR with exactly
this file list.`
- It reports 0 of 17 paths on the register and a size of 548 changed
lines (+463 / -85), under 3000.
- Separately, the claim routes the review to the contract tier because
of the spec ledger row and the new export.
- On earlier heads: `check:skill-examples`, `check:dual-build-cjs-loads`
and `check:dts-closure` refused on build prerequisites, which a full
build cleared. `check:test-source-alias` and
`check:driver-memory-census` were each red once, cleared by the two test
edits and the ledger row above.
- The dogfood battery is not run locally: the title carries no `!` and
Clause-② has no `(narrowing)` arm.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmRXuRn93HphKp7kXEz)_
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmRXuRn93HphKp7kXEz -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f6f5b50 commit f02f4f6
17 files changed
Lines changed: 463 additions & 85 deletions
File tree
- .changeset
- content/docs/references/api
- packages
- cloud-connection/src
- core/src
- plugins/plugin-dev/src
- runtime/src
- spec/src/api
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
| 420 | + | |
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
| 526 | + | |
526 | 527 | | |
527 | 528 | | |
528 | 529 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| 311 | + | |
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
197 | 200 | | |
198 | | - | |
| 201 | + | |
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
| |||
204 | 207 | | |
205 | 208 | | |
206 | 209 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
211 | 216 | | |
212 | 217 | | |
213 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
475 | 475 | | |
476 | 476 | | |
477 | 477 | | |
478 | | - | |
479 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
480 | 481 | | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
487 | 490 | | |
488 | 491 | | |
489 | | - | |
490 | | - | |
| 492 | + | |
491 | 493 | | |
492 | 494 | | |
493 | 495 | | |
494 | 496 | | |
495 | | - | |
| 497 | + | |
496 | 498 | | |
497 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
498 | 504 | | |
499 | 505 | | |
500 | 506 | | |
501 | 507 | | |
502 | 508 | | |
503 | 509 | | |
504 | 510 | | |
| 511 | + | |
505 | 512 | | |
506 | 513 | | |
507 | 514 | | |
| |||
2956 | 2963 | | |
2957 | 2964 | | |
2958 | 2965 | | |
2959 | | - | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
2960 | 2984 | | |
2961 | 2985 | | |
2962 | 2986 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| |||
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
191 | | - | |
| 194 | + | |
192 | 195 | | |
193 | 196 | | |
194 | 197 | | |
| |||
212 | 215 | | |
213 | 216 | | |
214 | 217 | | |
215 | | - | |
| 218 | + | |
216 | 219 | | |
217 | 220 | | |
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
221 | 224 | | |
222 | 225 | | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
| 226 | + | |
227 | 227 | | |
228 | | - | |
229 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
230 | 232 | | |
231 | 233 | | |
232 | 234 | | |
0 commit comments