Skip to content

Commit ecf6a5f

Browse files
fix(cloud-connection): install-local connects a composed bundle's package-body datasources and judges their names (#34633)
Fixes #34431 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:install-local 安装、升级和重启回灌时,数据源(datasources)、对象(objects)和连接器(connectors)改为与样例数据、翻译相同的读法,读到组合包(`packages[]`)每个子包里的声明;安装前的数据源重名检查(2a)也读子包。 - 为什么改:组合包顶层没有这三类列表。装上返回 200,但子包声明的外部数据源从不注册、不连接,绑在上面的对象无处读写;安装结果里也不列数据源和待配置的凭据;子包数据源与已有数据源重名也不拦。 - 风险与回滚:低。平铺包、以及仍带顶层合并列表的组合包读法不变,有对照测试钉住。行为变化一处:子包声明了他人已持有的数据源名的组合包,以前装上 200,现在与平铺包一样 409(见 Acceptance notes)。回滚即 revert 本 PR。 - 先看:`packages/cloud-connection/src/marketplace-install-local-plugin.ts` 的 `declaredDatasources`、2a 调用处新增的 try/catch、`connectDeclaredDatasources` 开头的读取块;再看 `marketplace-install-local-composed-top-level-reads.test.ts` 末尾两个新 describe。 - 两分钟验证:`pnpm --filter @objectstack/cloud-connection exec vitest run src/marketplace-install-local-composed-top-level-reads.test.ts`,预期 16 个用例全绿(其中 8 个新用例)。 - 需要你做的:无,席位落地。 ## What changes On a composed bundle (`dist/objectstack.json` with `packages[]`, ADR-0130 D4) every package-owned collection sits in the package bodies, and the top level carries none. `MarketplaceInstallLocalPlugin` read three of them from the top level only: 1. **Datasources** (`declaredDatasources`). This is the one reader for step 2a (`findHeldDatasourceName`), the 4b′ connect of an install or an upgrade, and the `kernel:ready` rehydrate (`connectDeclaredDatasources`). It now reads through `resolveStackCollection(artifact, 'datasources')`. The map form (keyed by name) is still read at the top level, where a flat bundle may carry it. A package body cannot carry it, because the resolver refuses a body whose `datasources` is not a list (measured below). 2. **Objects handed to `connectPackageDatasources`.** `connectDeclaredDatasources` read `manifest.objects`. It now reads `resolveStackCollection(manifest, 'objects')`. 3. **Connectors** (`describeInstalledCredentialRefs`, the install answer's `credentialRefs`). The card listed this as code-read only. It reproduced in the same harness, so it is fixed here: `resolveStackCollection(converted, 'connectors')`. All three now read the way the seed datasets (#34403) and the translations (#34407) already do: the top-level list when the body carries one (a flat bundle, or a composed artifact that still carries its flattened union, read once), otherwise every package body's, in package order. Step 2a now resolves the package bodies, so a `packages` the resolver refuses is answered at 2a with that refusal (`declaredRefusalAnswer`, the reader 2b and 2c″ share): its own `422` and code, and nothing is written. An undeclared throw is still rethrown. `connectDeclaredDatasources` keeps its contract that it never throws. A read failure there is logged at `error` and connects nothing. It is not expected, because register resolved the same bytes before this step. Ownership is unchanged. Every datasource is stamped with the install's `manifestId`, the id that the ledger entry, the `runtime.package-datasources` uninstall cleanup and `datasourceNameHolder` key on. Cleanup: `applySideEffects` no longer reads a top-level array `i18n` as extra translation bundles. In the spec `i18n` is `TranslationConfigSchema` (an object), no producer in this repository writes an array there, and the boot path (`AppPlugin`) never read one. Changeset: `@objectstack/cloud-connection` patch. ## Tests The new pins are two top-level `describe`s in the existing harness file `packages/cloud-connection/src/marketplace-install-local-composed-top-level-reads.test.ts`. That file drives the real `POST /api/v1/marketplace/install-local` route handler and the `kernel:ready` rehydrate. Its `@objectstack/runtime` mock now also carries `connectPackageDatasources`, which captures the datasource names, object names, owners and the `installed` flag, and `datasourceNameHolder`, which answers `free` unless a case marks a name held. The boot also has an `automation` service whose credential listing is empty. No existing assertion changed. - The composed install hands `connectPackageDatasources` `[erp_db, wms_db]` and `[crm_account, crm_order]`, in package order: core first, although the dependent module is listed first in the array. The answer is `datasources: [{erp_db, connected}, {wms_db, connected}]`. - The composed bundle and its flat control (the same declarations at the top level) hand the runtime equal lists and answer equal `datasources` and `credentialRefs`. - An upgrade (2.0.0 → 2.1.0) connects every body's datasources again. A restart's rehydrate does too, from the ledger. - `credentialRefs` names `ERP_TOKEN` and `WMS_TOKEN` from the two bodies' connectors. - Control: a composed artifact that still carries flattened top-level `datasources` and `objects` connects that union once, not once more per package. - Step 2a: a held name declared in a package body answers `409 RESOURCE_CONFLICT` with `details.datasource` set. No ledger entry is written and nothing is connected. Control: the flat bundle declaring the same name answers the same. <details><summary>Red first: base 8dd8192, same test file, plugin as on main</summary> `Tests 6 failed | 10 passed (16)`. The four connect pins received `datasources: []` (and `objects: []`). `credentialRefs` was `undefined`. The composed 2a case answered `200` with no `datasources` field. The flattened-union control and the flat 2a control passed, as did the 8 cases already in the file. On the way there, an earlier fixture of `{ name, driver: 'memory' }` without `config` was refused `422 INVALID_ARTIFACT_PACKAGE_ENTRY` (`manifest.datasources.0.config: expected record`): package bodies are parsed by the entry schema. The fixtures carry `config: {}`. </details> <details><summary>Ablation, one leg per behaviour (scripts/ablation-replace.mjs, at commit 31e95a8)</summary> The test imports the plugin by relative path (source, not `dist/`), so no rebuild sits in the loop. Every leg reported the anchor going 1 → 0 and the blob moving off `8405743f5ad9`. Every restore reported `blob after restore == blob at HEAD (8405743)` and an empty `git diff HEAD`. - Datasources (`return resolveStackCollection(artifact, 'datasources');` → top-level array only): `Tests 5 failed | 11 passed (16)`. Failed: install, composed-vs-flat, upgrade, rehydrate, composed 2a. - Objects (`resolveStackCollection(manifest, 'objects')` → `manifest.objects`): `4 failed | 12 passed`. Failed: install, composed-vs-flat, upgrade, rehydrate. - Connectors (`resolveStackCollection(converted, 'connectors')` → `converted.connectors`): `2 failed | 14 passed`. Failed: composed-vs-flat, credentialRefs. - 2a refusal guard (catch body → `throw err`), run with `marketplace-install-local-resolver-refusal-34432.test.ts`: `3 failed | 18 passed (21)`. Both #34432 `422` pins and the `isolated` refusal pin threw the resolver's error out of the handler. My first attempt at this leg used a replacement that contained its anchor, so the tool refused it (anchor x1 → x1) and ran nothing. I re-ran it with a non-overlapping anchor. The numbers above are from that second run. After the ablations, the `objects` declaration was retyped `any[]` to satisfy `tsc` (commit eaade30). The ablated line itself is unchanged. </details> ## Acceptance notes - **An input that answered 2xx now refuses (for the seat's Clause-② reading).** FROM, measured on base 8dd8192 through the route: a composed bundle whose package body declares a datasource name `datasourceNameHolder` reports held answered `200`. Its datasource was never registered or connected. Code-read, not measured: an object bound to that name would be served by the holder's driver. TO: `409 RESOURCE_CONFLICT`, the answer a flat bundle declaring the same name already gets, with nothing written. The claim's `Clause-②: no` is copied above unchanged. The report puts the reading to the seat with the options: keep `no` (a runtime gate the door already declares applied to bodies it skipped, no schema acceptance changed) or declare `no (narrowing)`. - **Step 2a now resolves the packages first.** On a runtime without the step-1d code judgements (the harness's mocked runtime), step 2a is now the first step to resolve a composed artifact's packages. The #34432 pins (`422 INVALID_ARTIFACT_PACKAGES` / `INVALID_ARTIFACT_PACKAGE_ENTRY`) therefore get the same bytes from 2a's `declaredRefusalAnswer` before 2c″ is reached. They pass unchanged. Code-read, not measured: 2c″'s own incoming-side pre-resolution is no longer the step those pins exercise, so an ablation of that guard alone would now stay green on them. 2c″ still owns the installed-copy side. - **Duplicate names across bodies.** These are kept as declared, in package order, and handed to the runtime path, as a flat bundle's same-name pair is (`declaredDatasources` never deduplicated a flat list). The runtime judges the pair as it does today. No pin was added for it. - **The map form in a package body** is refused by the resolver, measured: `INVALID_ARTIFACT_PACKAGE_ENTRY` 422, "manifest.datasources: expected array, received object". `resolveStackCollection` reads a top-level map as no list (`[]`), so the helper keeps the top-level map branch it had. A flat map-form bundle reads exactly as before. - **Test placement.** The claim's file surface names "one new card-named test file". AGENTS.md (ruling record 6583487846) puts a new pin for a component with a shared harness into that file as a top-level `describe`, so the pins went into `marketplace-install-local-composed-top-level-reads.test.ts`, the #34407 harness for this same family. ## Verification <details><summary>Package suite and typecheck</summary> After building the closure (`pnpm --filter '@objectstack/cloud-connection^...' build`, lock `VERDICT command-exit 0`), at eaade30: - `pnpm --filter @objectstack/cloud-connection typecheck`: exit 0, both programs. `tsconfig.test.json --listFiles` includes the harness file. - `pnpm --filter @objectstack/cloud-connection exec vitest run --maxWorkers=2`: `Test Files 89 passed (89)`, `Tests 1303 passed (1303)`, lock `VERDICT command-exit 0`. </details> <details><summary>Derived gates at 1edc890 (after merging origin/main ffa6db1)</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 3 paths, 71 commands, each run with stdin closed and its exit captured before any pipe. Reconciliation: `Run reconciliation — 71 derived, 71 run, 0 NOT-MEASURED, 0 UNRUN.` All 71 exit 0. `check:dual-build-cjs-loads` first answered exit 3 (PREREQUISITE NOT MET, no `dist/`). It was re-run green after a whole-workspace build (`turbo run build --filter=!@objectstack/docs --concurrency=2`, lock `VERDICT command-exit 0`): `124 published require entry point(s) across 72 package(s) load`. ```text node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-adoption.mjs :: exit 0 node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-issue-citations.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/docs-audit/check-affected-docs.mjs :: exit 0 node scripts/docs-audit/check-drift-comment.mjs :: exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0 pnpm check:adr-anchors :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:cli-command-ids :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:durability-log-level :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:error-status-conformance :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:init-service-contract :: exit 0 pnpm check:issue-citations :: exit 0 pnpm check:keyed-text-bounds :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:logger-receiver-detach :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:object-def-param-keys :: exit 0 pnpm check:objectql-double-limit :: exit 0 pnpm check:optional-error-sink :: exit 0 pnpm check:org-identifier :: exit 0 pnpm check:page-declaration-shape :: exit 0 pnpm check:platform-object-tenancy-census :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:route-envelope :: exit 0 pnpm check:settings-bind-window :: exit 0 pnpm check:slot-lookup :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:startup-registry-verdict :: exit 0 pnpm check:system-context-census :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:vouch-for-reference-callers :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 ``` </details> Full dogfood: not owed, since there is no `!` in the title and no `(narrowing)` arm. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmRXuRn93HphKp7kXEz)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c1ec627 commit ecf6a5f

3 files changed

Lines changed: 267 additions & 15 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/cloud-connection': patch
3+
---
4+
5+
fix(cloud-connection): install-local connects a composed bundle's package-body datasources, judges their names before any write, and names their connector credentials
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A composed bundle (`dist/objectstack.json` with `packages[]`, ADR-0130 D4) carries its datasources, connectors and objects in each package body, and none at the top level. `POST /api/v1/marketplace/install-local` read those three from the top level only. A composed install answered 200, but `connectPackageDatasources` was handed no datasources and no objects, so a datasource declared in a package body was never registered or connected, and the objects bound to it had no driver. The install answer carried no `datasources` and no `credentialRefs`. The held-name check (step 2a) never saw a body's datasource names either.
11+
12+
Install, upgrade and the restart's rehydrate now read datasources and objects through `resolveStackCollection`, the reader the seed datasets and translations already use: the top-level list when the bundle carries one, otherwise every package body's, in package order. A composed bundle now hands the runtime the same lists as the same declarations in a flat bundle, and the answer lists the same `datasources` and `credentialRefs`.
13+
14+
Step 2a now judges every package body's datasource names. A composed install that declares a name another holder owns is refused `409 RESOURCE_CONFLICT` before any write, as a flat bundle declaring that name already was. Before this, such an install answered 200 and left the name with its holder. A `packages` the artifact resolver refuses is answered at this step with the resolver's own `422`, and nothing is written.
15+
16+
The side effects no longer read a top-level array `i18n` as extra translation bundles. `i18n` is a configuration object in the spec, and the boot path never read an array there.

‎packages/cloud-connection/src/marketplace-install-local-composed-top-level-reads.test.ts‎

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,29 @@
2222
* the artifact's package order. The controls pin that a flat bundle reads its
2323
* own top-level list unchanged, and that a composed artifact which still
2424
* carries its flattened union reads it once, never once more per package.
25+
*
26+
* [#34431] The same holds for the datasources and objects the install, the
27+
* upgrade and the rehydrate hand `connectPackageDatasources`, for the
28+
* datasource names step 2a judges against held names, and for the connectors
29+
* whose credentials the install answer names: a composed bundle and the flat
30+
* control carrying the same declarations hand the runtime the same lists and
31+
* answer the same `datasources` and `credentialRefs`.
2532
*/
2633

2734
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2835
import { mkdtempSync, rmSync } from 'node:fs';
2936
import { join } from 'node:path';
3037
import { tmpdir } from 'node:os';
3138

39+
/**
40+
* [#34431] What the runtime's datasource path is handed, one entry per call:
41+
* the datasource names, the object names, each datasource's owner and whether
42+
* the call was an installed one.
43+
*/
44+
const connectCalls = vi.hoisted(() => [] as Array<{ datasources: string[]; objects: string[]; owners: string[]; installed: boolean }>);
45+
/** [#34431] The datasource names another holder owns, as the runtime's judge answers them. */
46+
const heldDatasources = vi.hoisted(() => new Map<string, string>());
47+
3248
vi.mock('@objectstack/runtime', () => ({
3349
SeedLoaderService: class {
3450
async load() { return { summary: { totalInserted: 0, totalUpdated: 0, totalSkipped: 0 }, errors: [] }; }
@@ -37,6 +53,17 @@ vi.mock('@objectstack/runtime', () => ({
3753
resolveSeedLocaleForLoad: async () => undefined,
3854
appDefaultSeedLocale: () => undefined,
3955
describeSeedLocale: () => 'none',
56+
connectPackageDatasources: async (_ctx: unknown, options: any) => {
57+
connectCalls.push({
58+
datasources: options.datasources.map((d: any) => d.name),
59+
objects: options.objects.map((o: any) => o.name),
60+
owners: options.owned.map((o: any) => o.owner.packageId),
61+
installed: options.installed === true,
62+
});
63+
return options.datasources.map((d: any) => ({ name: d.name, status: 'connected' }));
64+
},
65+
datasourceNameHolder: async (_ctx: unknown, _appId: string, name: string) =>
66+
heldDatasources.has(name) ? { status: 'held', holder: heldDatasources.get(name) } : { status: 'free' },
4067
}));
4168

4269
import { MarketplaceInstallLocalPlugin } from './marketplace-install-local-plugin.js';
@@ -132,6 +159,8 @@ async function boot(dir: string) {
132159
auth: installerAuthService(),
133160
objectql: withInstallerGrants({ syncSchemas: async () => undefined }),
134161
metadata: {},
162+
// [#34431] Every credential reference is unset: the install answer names each one.
163+
automation: { listConnectorCredentialRefs: async () => [] },
135164
i18n: {
136165
loadTranslations: (locale: string, data: any) => {
137166
const labels = Object.values(data?.objects ?? {}).map((o: any) => o.label).join('|');
@@ -169,6 +198,8 @@ beforeEach(() => {
169198
// The request carries no organization, and the ceremony runs walled: the
170199
// installer is the deployment's declared platform owner.
171200
restoreOwner = declareInstallerPlatformOwner('admin');
201+
connectCalls.length = 0;
202+
heldDatasources.clear();
172203
});
173204
afterEach(() => {
174205
restoreOwner();
@@ -262,3 +293,158 @@ describe("ADR-0120 D5e — a composed bundle installed into an 'isolated' enviro
262293
expect(new LocalManifestSource(dir).read(SUITE).entry).toBeNull();
263294
});
264295
});
296+
297+
// ── [#34431] Datasources and connectors ────────────────────────────────────
298+
299+
const ERP_DB = { name: 'erp_db', driver: 'memory', config: {} };
300+
const WMS_DB = { name: 'wms_db', driver: 'memory', config: {} };
301+
const ERP_API = { name: 'erp_api', label: 'ERP API', type: 'api', provider: 'rest', providerConfig: { baseUrl: 'https://erp.example.test' }, auth: { type: 'bearer', credentialRef: 'ERP_TOKEN' } };
302+
const WMS_API = { name: 'wms_api', label: 'WMS API', type: 'api', provider: 'rest', providerConfig: { baseUrl: 'https://wms.example.test' }, auth: { type: 'bearer', credentialRef: 'WMS_TOKEN' } };
303+
304+
const sourceBody = (
305+
id: string,
306+
version: string,
307+
object: Record<string, unknown>,
308+
datasources: unknown[],
309+
connectors: unknown[],
310+
dependencies?: Record<string, string>,
311+
) => ({
312+
manifest: {
313+
id,
314+
name: id,
315+
version,
316+
type: 'module',
317+
...(dependencies ? { dependencies } : {}),
318+
objects: [object],
319+
datasources,
320+
connectors,
321+
},
322+
});
323+
324+
/**
325+
* A composed artifact whose package bodies each declare a datasource and a
326+
* connector, with no top-level `datasources`, `connectors` or `objects`. The
327+
* order module is listed FIRST and depends on the core one, so package order
328+
* (core, then orders) is not array order.
329+
*/
330+
const composedSources = (version = '2.0.0', extra: Record<string, unknown> = {}) => ({
331+
id: SUITE,
332+
name: 'Suite',
333+
version,
334+
type: 'app',
335+
packages: [
336+
sourceBody(`${SUITE}.o2c`, version, ORDER, [WMS_DB], [WMS_API], { [`${SUITE}.core`]: '*' }),
337+
sourceBody(`${SUITE}.core`, version, ACCOUNT, [ERP_DB], [ERP_API]),
338+
],
339+
...extra,
340+
});
341+
342+
/** The flat control: the same declarations at the top level, in package order. */
343+
const flatSources = (version = '2.0.0') => ({
344+
id: SUITE,
345+
name: 'Suite',
346+
version,
347+
type: 'app',
348+
objects: [ACCOUNT, ORDER],
349+
datasources: [ERP_DB, WMS_DB],
350+
connectors: [ERP_API, WMS_API],
351+
});
352+
353+
const CONNECTED = [{ name: 'erp_db', status: 'connected' }, { name: 'wms_db', status: 'connected' }];
354+
const HANDED = { datasources: ['erp_db', 'wms_db'], objects: ['crm_account', 'crm_order'], owners: [SUITE, SUITE], installed: true };
355+
356+
describe('[#34431] a composed bundle: install connects every package body\'s datasources, in package order', () => {
357+
it('install hands connectPackageDatasources every body\'s datasources and objects, core first, and the answer lists them', async () => {
358+
const rt = await boot(dir);
359+
const res = await rt.install({ manifest: composedSources() });
360+
expect(res.status, JSON.stringify(res.payload)).toBe(200);
361+
expect(connectCalls).toEqual([HANDED]);
362+
expect(res.payload.data.datasources).toEqual(CONNECTED);
363+
});
364+
365+
it('a composed bundle and its flat control answer the same datasources and hand connectPackageDatasources the same lists', async () => {
366+
const composedRt = await boot(dir);
367+
const composedRes = await composedRt.install({ manifest: composedSources() });
368+
const composedCalls = connectCalls.splice(0);
369+
370+
const flatDir = mkdtempSync(join(tmpdir(), 'mil-composed-reads-flat-'));
371+
try {
372+
const flatRt = await boot(flatDir);
373+
const flatRes = await flatRt.install({ manifest: flatSources() });
374+
expect(flatRes.status, JSON.stringify(flatRes.payload)).toBe(200);
375+
expect(composedRes.status, JSON.stringify(composedRes.payload)).toBe(200);
376+
expect(composedCalls).toEqual(connectCalls);
377+
expect(composedRes.payload.data.datasources).toEqual(flatRes.payload.data.datasources);
378+
expect(composedRes.payload.data.credentialRefs).toEqual(flatRes.payload.data.credentialRefs);
379+
} finally {
380+
rmSync(flatDir, { recursive: true, force: true });
381+
}
382+
});
383+
384+
it('an upgrade connects the new version\'s datasources across every body', async () => {
385+
const rt = await boot(dir);
386+
expect((await rt.install({ manifest: composedSources('2.0.0') })).status).toBe(200);
387+
connectCalls.length = 0;
388+
389+
const res = await rt.install({ manifest: composedSources('2.1.0') });
390+
expect(res.status, JSON.stringify(res.payload)).toBe(200);
391+
expect(connectCalls).toEqual([HANDED]);
392+
expect(res.payload.data.datasources).toEqual(CONNECTED);
393+
});
394+
395+
it('a restart\'s rehydrate connects them again from the ledger', async () => {
396+
const first = await boot(dir);
397+
expect((await first.install({ manifest: composedSources() })).status).toBe(200);
398+
connectCalls.length = 0;
399+
400+
await boot(dir);
401+
expect(connectCalls).toEqual([HANDED]);
402+
});
403+
404+
it('the answer names the connector credentials every package body declares', async () => {
405+
const rt = await boot(dir);
406+
const res = await rt.install({ manifest: composedSources() });
407+
expect(res.status, JSON.stringify(res.payload)).toBe(200);
408+
expect(res.payload.data.credentialRefs).toEqual([
409+
{ ref: 'ERP_TOKEN', connectors: ['erp_api'], status: 'missing', source: null },
410+
{ ref: 'WMS_TOKEN', connectors: ['wms_api'], status: 'missing', source: null },
411+
]);
412+
});
413+
414+
it('control: a composed artifact that still carries its flattened top-level datasources connects that union once', async () => {
415+
const rt = await boot(dir);
416+
const res = await rt.install({
417+
manifest: composedSources('2.0.0', { objects: [ACCOUNT, ORDER], datasources: [ERP_DB, WMS_DB] }),
418+
});
419+
expect(res.status, JSON.stringify(res.payload)).toBe(200);
420+
expect(connectCalls).toEqual([HANDED]);
421+
expect(res.payload.data.datasources).toEqual(CONNECTED);
422+
});
423+
});
424+
425+
describe('[#34431] step 2a judges a composed body\'s datasource names as a flat bundle\'s', () => {
426+
it('a name another holder owns, declared by a package body, refuses the install 409 before any write', async () => {
427+
heldDatasources.set('wms_db', "the datasource 'wms_db' created in Setup");
428+
const rt = await boot(dir);
429+
430+
const res = await rt.install({ manifest: composedSources() });
431+
432+
expect(res.status, JSON.stringify(res.payload)).toBe(409);
433+
expect(res.payload.success).toBe(false);
434+
expect(res.payload.error.code).toBe('RESOURCE_CONFLICT');
435+
expect(res.payload.error.details).toEqual({ datasource: 'wms_db' });
436+
expect(new LocalManifestSource(dir).read(SUITE).entry).toBeNull();
437+
expect(connectCalls).toEqual([]);
438+
});
439+
440+
it('control: the flat bundle declaring the same name is refused the same way', async () => {
441+
heldDatasources.set('wms_db', "the datasource 'wms_db' created in Setup");
442+
const rt = await boot(dir);
443+
444+
const res = await rt.install({ manifest: flatSources() });
445+
446+
expect(res.status, JSON.stringify(res.payload)).toBe(409);
447+
expect(res.payload.error.code).toBe('RESOURCE_CONFLICT');
448+
expect(res.payload.error.details).toEqual({ datasource: 'wms_db' });
449+
});
450+
});

0 commit comments

Comments
 (0)