Skip to content

Commit f02f4f6

Browse files
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/core': patch
3+
'@objectstack/spec': patch
4+
'@objectstack/cloud-connection': patch
5+
---
6+
7+
fix(core): a composed artifact whose packages depend on each other in a cycle is refused as `422 CYCLIC_ARTIFACT_PACKAGES` naming the cycle, and install-local answers every artifact-resolver refusal instead of a 500
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
- `@objectstack/core`: `resolveArtifactPackageEntries` / `resolveArtifactPackageOrder` refuse packages that depend on each other in a cycle with the ADR-0112 envelope their other refusals carry: `code: 'CYCLIC_ARTIFACT_PACKAGES'`, `status: 422`, and `details.cycle` listing the package ids along the cycle (each depends on the next, the first repeated last). Before, the cycle was a bare `Error` with no `code` or `status`. A caller that matched on the old message still finds `Circular dependency detected` in it. `resolvePluginOrder` now throws its cycle as `PluginOrderCycleError`, a new exported `Error` subclass that carries `cycle`. Its message is unchanged and it carries no `code`, so a kernel boot that hits a plugin cycle reads exactly as before.
13+
- `@objectstack/spec`: `CYCLIC_ARTIFACT_PACKAGES` is registered in `ERROR_CODE_LEDGER` under `@objectstack/core`, so `ErrorCode` accepts it.
14+
- `@objectstack/cloud-connection`: `POST /api/v1/marketplace/install-local` answered `500 INTERNAL_ERROR` with no reason for a composed artifact the resolver refuses: a `packages` that is not a list, a malformed entry, a duplicate package id, or a dependency cycle. On a real runtime, the step that judges the package's jobs and hooks reads the packages first and let the refusal escape. That step now answers the refusal itself, with its own status, code and `details`, and nothing is written. Every other step that reads the packages already did.

‎content/docs/references/api/automation-api.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ const result = AutomationApiErrorCode.parse(data);
417417

418418
| Property | Type | Required | Description |
419419
| :--- | :--- | :--- | :--- |
420-
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +368 more>` | ✅ | The inner refusal's code in its WIRE spelling - the ADR-0112 member a record save of the same write answers in `error.code` (e.g. `UNIQUE_VIOLATION`); the closed set `ApiErrorSchema.code` parses against |
420+
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +369 more>` | ✅ | The inner refusal's code in its WIRE spelling - the ADR-0112 member a record save of the same write answers in `error.code` (e.g. `UNIQUE_VIOLATION`); the closed set `ApiErrorSchema.code` parses against |
421421
| **message** | `string` | ✅ | The inner refusal's own diagnostic text, verbatim, without the node and operation prefixes the run's failure text adds |
422422

423423
### Allowed Values: `FlowInnerRefusal.code`
@@ -523,6 +523,7 @@ const result = AutomationApiErrorCode.parse(data);
523523
* `CREATE_FAILED`
524524
* `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`
525525
* `CUBE_NOT_FOUND`
526+
* `CYCLIC_ARTIFACT_PACKAGES`
526527
* `DATASET_INVALID`
527528
* `DATASOURCE_ADMIN_ERROR`
528529
* `DEFAULT_RECORD_PAGE_CONFLICT`

‎content/docs/references/api/contract.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const result = ApiErrorSchema.parse(data);
2828

2929
| Property | Type | Required | Description |
3030
| :--- | :--- | :--- | :--- |
31-
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +368 more>` | ✅ | Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages) |
31+
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +369 more>` | ✅ | Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages) |
3232
| **declaredCode** | `string` | optional | The producer-declared code, verbatim, when it is not a member of the closed `code` vocabulary — the open, author-authored channel (app-specific spellings; ADR-0112) |
3333
| **message** | `string` | ✅ | Readable error message |
3434
| **userMessage** | `string` | optional | Producer-marked user-facing refusal text, verbatim, in the request's locale: platform-composed text falls back to the workspace default locale, then `en`; an app-authored refusal falls back to its declared wording. Present exactly when the producer opted in at throw time; consumers render it to end users as received and keep their generic substitution for anything unmarked. Status-agnostic; never replaces `message`. |
@@ -141,6 +141,7 @@ const result = ApiErrorSchema.parse(data);
141141
* `CREATE_FAILED`
142142
* `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`
143143
* `CUBE_NOT_FOUND`
144+
* `CYCLIC_ARTIFACT_PACKAGES`
144145
* `DATASET_INVALID`
145146
* `DATASOURCE_ADMIN_ERROR`
146147
* `DEFAULT_RECORD_PAGE_CONFLICT`

‎content/docs/references/api/error-code-ledger.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ const result = ErrorCode.parse(data);
308308
* `CREATE_FAILED`
309309
* `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`
310310
* `CUBE_NOT_FOUND`
311+
* `CYCLIC_ARTIFACT_PACKAGES`
311312
* `DATASET_INVALID`
312313
* `DATASOURCE_ADMIN_ERROR`
313314
* `DEFAULT_RECORD_PAGE_CONFLICT`

‎packages/cloud-connection/src/marketplace-install-local-namespace-gate-33922.test.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,12 @@ describe('install-local parses the inline manifest\'s `namespace` through its de
193193

194194
it('UNMOVED — an artifact MEMBER\'s refused namespace keeps the artifact-entry parse\'s refusal, nothing written', async () => {
195195
// Each `packages[]` entry is parsed whole through `ArtifactPackageSchema`
196-
// before any write; this door adds no second judge of it.
196+
// before any write; this door adds no second judge of it. [#34574] The
197+
// refusal is ANSWERED with its own 422 and code (step 1c reads the
198+
// packages first over this real runtime), where it used to leave the
199+
// door as a throw the transport answered `500`.
197200
const h = await mount(dir);
198-
const thrown = await h.install({
201+
const res = await h.install({
199202
manifest: {
200203
id: 'com.qa.suite',
201204
version: '1.0.0',
@@ -204,10 +207,12 @@ describe('install-local parses the inline manifest\'s `namespace` through its de
204207
{ manifest: { id: 'com.qa.two', name: 'qa_two', version: '1.0.0', type: 'module', namespace: 'QA_N', objects: [] } },
205208
],
206209
},
207-
}).then(() => undefined, (e: unknown) => e as { code?: string; status?: number; message?: string });
208-
expect(thrown?.code).toBe('INVALID_ARTIFACT_PACKAGE_ENTRY');
209-
expect(thrown?.status).toBe(422);
210-
expect(thrown?.message).toContain(declaredSentence('QA_N'));
210+
});
211+
expect(res.status, JSON.stringify(res.payload)).toBe(422);
212+
expect(envelopeViolations(res.payload)).toEqual([]);
213+
expect(res.payload.success).toBe(false);
214+
expect(res.payload.error.code).toBe('INVALID_ARTIFACT_PACKAGE_ENTRY');
215+
expect(res.payload.error.message).toContain(declaredSentence('QA_N'));
211216
expectNothingWritten(h);
212217
});
213218

‎packages/cloud-connection/src/marketplace-install-local-plugin.ts‎

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -475,33 +475,40 @@ function isDeclaredRegisterRefusal(err: unknown): boolean {
475475
}
476476

477477
/**
478-
* [#34407, #34432] The answer to a package body the artifact resolver refuses
479-
* before any write (`resolveStackCollection` → `resolveArtifactPackageEntries`:
478+
* [#34407, #34432, #34574] The answer to a package body the artifact resolver
479+
* refuses before any write (`resolveArtifactPackageEntries`, reached through
480+
* `resolveStackCollection` or the runtime binder's judgements:
480481
* `INVALID_ARTIFACT_PACKAGES`, `INVALID_ARTIFACT_PACKAGE_ENTRY`,
481-
* `DUPLICATE_ARTIFACT_PACKAGE`, each an ADR-0112 envelope with its declared
482-
* `status: 422`): that refusal's own declared status and code, the resolver's
483-
* sentence, and that nothing was written. The one reader of such a refusal on
484-
* this door's pre-write steps — the D5e gate (2b) and the declared renames
485-
* (2c″) both read the bodies through the resolver, so the same bytes are
486-
* answered the same way whichever step reads them first.
482+
* `DUPLICATE_ARTIFACT_PACKAGE`, `CYCLIC_ARTIFACT_PACKAGES`, each an ADR-0112
483+
* envelope with its declared `status: 422`): that refusal's own declared
484+
* status and code, the resolver's sentence, its `details` when it states any
485+
* (a cycle's `details.cycle`), and that nothing was written. The one reader of
486+
* such a refusal on this door's pre-write steps — the unrunnable-code
487+
* judgements (1c), the datasource holder (2a), the D5e gate (2b) and the
488+
* declared renames (2c″) all read the bodies through the resolver, so the same
489+
* bytes are answered the same way whichever step reads them first.
487490
*
488491
* `undefined` for a throw that declares no status below 500 — an undeclared
489-
* throw (the resolver's own dependency-cycle error among them) or a declared
490-
* 5xx: the caller rethrows it, never relabels it.
492+
* throw or a declared 5xx: the caller rethrows it, never relabels it.
491493
*/
492494
function declaredRefusalAnswer(
493495
manifestId: string,
494496
err: unknown,
495-
): { status: number; body: { success: false; error: { code: string; message: string } } } | undefined {
497+
): { status: number; body: { success: false; error: { code: string; message: string; details?: Record<string, unknown> } } } | undefined {
496498
const refusal = resolveThrownHttpError(err);
497499
if (refusal.declaredStatus === undefined || refusal.status >= 500) return undefined;
500+
const stated = (err as { details?: unknown } | null | undefined)?.details;
501+
const details = stated !== null && typeof stated === 'object' && !Array.isArray(stated)
502+
? stated as Record<string, unknown>
503+
: undefined;
498504
return {
499505
status: refusal.status,
500506
body: {
501507
success: false,
502508
error: {
503509
code: refusal.code,
504510
message: `Package '${manifestId}' cannot be installed: ${String((err as any)?.message ?? err)} Nothing was installed or written.`,
511+
...(details !== undefined ? { details } : {}),
505512
},
506513
},
507514
};
@@ -2956,7 +2963,24 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
29562963
// unbindable `pull` is warned by the binder and NOT scheduled), and
29572964
// its hook with no `body` is warned and NOT bound
29582965
// ({@link bindArtifactHandlers}).
2959-
const unrunnable = await this.unrunnableCode(ctx, manifest, manifestId);
2966+
// [#34574] The binder's judgements read every package body of a
2967+
// composed bundle through the artifact resolver, so over a runtime
2968+
// that carries them THIS is the first step to resolve the
2969+
// packages. A `packages` the resolver refuses — not a list, a
2970+
// malformed entry, a duplicate id, packages that depend on each
2971+
// other in a cycle — is answered here with that refusal
2972+
// ({@link declaredRefusalAnswer}), as 2a, 2b and 2c″ answer it.
2973+
// Before, the refusal left the door as a throw, and the transport,
2974+
// which renders no `422`, answered `500 INTERNAL_ERROR`. An
2975+
// undeclared throw stays a throw.
2976+
let unrunnable: UnrunnableCode;
2977+
try {
2978+
unrunnable = await this.unrunnableCode(ctx, manifest, manifestId);
2979+
} catch (err: unknown) {
2980+
const refused = declaredRefusalAnswer(manifestId, err);
2981+
if (!refused) throw err;
2982+
return c.json(refused.body, refused.status);
2983+
}
29602984
if (unrunnable.jobs.length > 0 || unrunnable.sharedJobNames.length > 0 || unrunnable.hooks.length > 0) {
29612985
return c.json({
29622986
success: false,

‎packages/cloud-connection/src/marketplace-install-local-resolver-refusal-34432.test.ts‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
* `marketplace-install-local-composed-top-level-reads.test.ts`), so 2c″ is the
1818
* first step to resolve the packages. (A runtime that carries those
1919
* judgements resolves the packages at step 1c first, and the resolver's
20-
* refusal leaves the door as a throw.) The controls pin the rest of the
21-
* contract: a table that really could not be read still answers 503, and an
22-
* undeclared throw out of the resolver (its own dependency-cycle error) is
23-
* rethrown, never relabelled.
20+
* refusal is answered there, at step 1c — pinned over the real runtime in
21+
* `marketplace-install-local-resolver-refusal-real-runtime.test.ts`.) The
22+
* controls pin the rest of the contract: a table that really could not be read
23+
* still answers 503, and a dependency cycle between two packages — an
24+
* undeclared throw out of the resolver until #34574 — is now the resolver's
25+
* declared `422 CYCLIC_ARTIFACT_PACKAGES`, answered like its siblings, never
26+
* the 503.
2427
*/
2528

2629
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
@@ -188,7 +191,7 @@ describe('#34432 — step 2c″ answers a body the artifact resolver refuses wit
188191
});
189192
});
190193

191-
describe('#34432 — controls: the 503 stays the unread table\'s, and an undeclared throw stays a throw', () => {
194+
describe('#34432 — controls: the 503 stays the unread table\'s, and a cycle is the resolver\'s declared refusal', () => {
192195
it('CONTROL: a well-formed composed artifact whose renamed field\'s table cannot be read still answers 503 SERVICE_UNAVAILABLE', async () => {
193196
const driver = fakeDriver({ planThrows: true });
194197
const rt = await boot(dir, driver);
@@ -212,21 +215,20 @@ describe('#34432 — controls: the 503 stays the unread table\'s, and an undecla
212215
expect(driver.planDeclaredRenames).toHaveBeenCalledTimes(1);
213216
});
214217

215-
it('an undeclared throw out of the resolver (a dependency cycle between two packages) is rethrown, never answered 503', async () => {
218+
it('a dependency cycle between two packages answers 422 CYCLIC_ARTIFACT_PACKAGES naming the cycle, never 503, and nothing is written', async () => {
216219
const driver = fakeDriver();
217220
const rt = await boot(dir, driver);
218221
const cyclic = [
219222
entry(`${SUITE}.core`, [ACCOUNT], { [`${SUITE}.leads`]: '*' }),
220223
entry(`${SUITE}.leads`, [LEAD], { [`${SUITE}.core`]: '*' }),
221224
];
222225

223-
const outcome = await rt.install({ manifest: composed(cyclic) }).then(
224-
(res: any) => ({ answered: res }),
225-
(err: unknown) => ({ thrown: err as Error }),
226-
);
226+
const res = await rt.install({ manifest: composed(cyclic) });
227227

228-
expect('answered' in outcome ? JSON.stringify(outcome.answered.payload) : 'thrown').toBe('thrown');
229-
expect((outcome as { thrown: Error }).thrown.message).toContain('Circular dependency');
228+
expect(res.status, JSON.stringify(res.payload)).toBe(422);
229+
expect(res.payload.success).toBe(false);
230+
expect(res.payload.error.code).toBe('CYCLIC_ARTIFACT_PACKAGES');
231+
expect(res.payload.error.details).toEqual({ cycle: [`${SUITE}.core`, `${SUITE}.leads`, `${SUITE}.core`] });
230232
expectNothingWritten(rt, driver);
231233
});
232234
});

0 commit comments

Comments
 (0)