Skip to content

Commit f3fe660

Browse files
fix(spec): composeStacks says why a top-level connector beside a package body's same-named entry is ambiguous (#28026)
epic:#27261#1 · marchtian · session_017ihL2c5z3q4h8inrn5kwqV <!-- claude-projects-attribution: {"github_login":"marchtian"} --> _Requested by **田騏** · [project thread](https://claude.ai/code/project/chan_01VmuUhXU9SSUzqJYyXSmYSi?thread=cmsg_01VmuUhXU9SSUzqJYyXSmYSiAgqyfAMFoGxrddntu1VW4z)_ **Full review owed at the reviewer tier.** Developed on the default tier while the reviewer tier's quota is out. This PR touches the published spec (`packages/spec/src/**`), so it lands only after a full review at the reviewer tier and a `CONTRACT_REVIEW_TIER` contract review record PASS on the current head. Fixes #28006 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么:** #27939 的合成检查里,有一种情形的拒收理由不对:包体里的连接器和产物顶层的同名连接器一个能出借、一个不能。原提示说「运行时每个包各留一条,先注册的出借」。实际上,开机时顶层那条不注册,由包体那条出借;开发态重载时,顶层那条会替换包体那条。现在提示写明这一点;`slot` 文档和 `providedCollectionEntries` 的说明也写清了。另外改了一个测试名,并补了 `preserve` 下混合嵌套输入的测试。 - **为什么改:** 结论正确但理由错误,会误导作者判断该改哪一条声明。 - **风险与回滚:** 接受集不变:原来拒收的仍拒收,原来通过的仍通过,只改提示文字。两个包体之间冲突的提示一字未改。回滚即 revert。 - **先看:** `packages/spec/src/stack.zod.ts` 中 `collectComposedDatasourceConnectorErrors` 的歧义分支,以及 `ProvidedCollectionEntry.inBody` 的文档。 - **两分钟验证:** `pnpm --filter @objectstack/spec exec vitest run src/stack-datasource-connector.test.ts`,预期 30 个测试全过。 - **需要您做的:** 无(需审阅档全量复审与合约复审 PASS)。 ## What changes - **`packages/spec/src/stack.zod.ts`:** - `ProvidedCollectionEntry` gains `inBody`: whether the entry boots as a package body's own item. That covers an entry of a `packages[]` body, and, under `preserve`, the top level of an input that `preservePackageEntries` folds into a body of its own id. Its doc states the mechanism for every other top-level entry beside package bodies. The residual rule (`unclaimedTopLevel`) does not register such an entry when a body declares its name. When no body declares the name, the rule registers it under the composed artifact's `manifest.id` (the last input's). A dev reload replaces the booted entries of the name with the artifact's top-level list (`mergeDeclaredConnectorSources`). So its `slot` (`'artifact'`, or a mixed `preserve` input's own `package:${id}`) is a stand-in. It stays a stand-in because keeping it apart from the bodies is what refuses the boot-or-reload split as ambiguous. - The ambiguity finding now names the mechanism that applies: - **Two package bodies:** unchanged, byte for byte ("the runtime keeps one entry per package and lends from whichever registers first"). - **A package body and a top-level entry:** "which the composed artifact declares both in a package body and at its top level, … The boot does not register a top-level entry whose name a package body declares, so the body's entry lends, and a dev reload replaces it with the artifact's top-level entries of the name, the first of which lends, so the entry the datasource borrows depends on whether the artifact was booted or reloaded and on the order of its inputs." - **Top-level entries of two inputs, beside bodies that do not declare the name:** a sentence of its own: no door registers either as a package body's entry, and a dev reload lends from the first top-level entry of the name. - `providedCollectionEntries`' docblock and `collectComposedDatasourceConnectorErrors`' docblock say the same. - **`packages/spec/src/stack-datasource-connector.test.ts`:** - "treats a package body and another input's top level as two slots" is renamed to "refuses as ambiguous a top-level entry beside a package body's same-named entry, and names the body". It now asserts the new sentence and the absence of "one entry per package". - A new group pins the `preserve` reading of an input that carries `packages` beside its own top-level `connectors`. With a descriptor at its top level and another package's lending instance, it is refused as ambiguous, with the beside-a-body sentence, in both input orders. With two lending instances it composes in both orders. The composed artifact keeps that top level beside the inner and plain bodies only, under the last input's `manifest.id`, and the whole flattened `connectors` list in input order (pinned both ways, since a dev reload lends from the first). Two such inputs whose top-level entries disagree, beside bodies silent on the name, are refused with the top-level-only sentence in both orders. - **`.changeset/28006-composed-connector-ambiguity-reason.md`:** `@objectstack/spec` `patch` (the message text ships), both declaration lines, and an ADR-0087 `not-required (no-migration-prescription)` marker. ## Why Should-fix 1 of contract record 6516406275 on PR #27939: the refusal was right for a reason the message, the slot doc and the test name did not give. ## Verification All on head `541d7f5b3d` (should-fixes 1 and 2 of contract record 6519281283 in 1580237, then a merge of `origin/main`). - **Verdicts unchanged:** the 30 tests were run against `origin/main`'s `stack.zod.ts`. The 25 that do not assert the new wording passed. The 5 that do failed only on that wording: each first asserted the envelope (`STACK_CROSS_REFERENCE_INVALID`, 422) and exactly one finding for the datasource, and those assertions passed. So every composition this file covers is refused or accepted exactly as before. - **Ablation:** with the mixed input's top level judged in the composed artifact's slot instead of its own, both orders of the mixed `preserve` refusal go red, and the mixed-first order is accepted. The 26 other cases stay green. Restored, 28/28 pass (measured on `55b0c85641`, before the two cases should-fix 2 added). - **Package:** `pnpm --filter @objectstack/spec build`, `test` and `typecheck` under the verify lock: build exit 0; 756 test files passed, 22505 tests passed (1 todo); typecheck passed (`check:test-typecheck: OK`). - **Local gates:** `node scripts/pm/dispatch-gates.mjs --commands`, derived after merging `origin/main`, named 80 families (re-derived after the second merge of `origin/main`). All were run, with exit codes recorded before any pipe, and every one exited 0. `dispatch-gates --ran`: "80 derived famil(ies) accounted for — 80 run, 0 NOT-MEASURED (a DERIVED zero)". The tree was clean after the gate run, so no generated reference moved. The full gate battery is CI's. Dogfood was not run: `Clause-②: no` does not owe it, and no verdict moves. ## Acceptance notes - **The slot stays a stand-in on purpose.** Judging a mixed input's top level in the composed artifact's `manifest.id` slot, where the residual rule registers it, would move a verdict: with the plain input last, a descriptor at the mixed input's top level would be judged last-wins against the plain body's instance and accepted. The card forbids that, so the doc states the mechanism instead. - **Worktree:** `objectstack-issue-28006` on the claimed branch, as the Claim names. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (Message wording of a build-time collector and one module-private field; no schema changed.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` is CI's. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: no generated artifact changes (only JSDoc and a refusal's text; the gate run left the tree clean). - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English (the 维护者速读 block is the repo's own Chinese reader section). - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017ihL2cLiZUHvCtV2YGRWAd --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3e0fd7a commit f3fe660

3 files changed

Lines changed: 186 additions & 24 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
fix(spec): `composeStacks` says why a top-level connector beside a package body's same-named entry is ambiguous (#28006)
6+
7+
Clause-②: no (message text only: every composition `composeStacks` refused it still refuses, under the same `STACK_CROSS_REFERENCE_INVALID` envelope, and every one it accepted it still accepts)
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, no export or type changes, and no verdict moves: only the wording of one refusal changes. There is nothing for `objectstack migrate meta` to rewrite. -->
11+
12+
A datasource whose `external.connector` names a connector that a package body and the composed artifact's top level both declare, one able to lend and the other not, was already refused as ambiguous. The refusal gave the reason that holds between two package bodies ("the runtime keeps one entry per package and lends from whichever registers first"), which is not what happens here. The boot does not register a top-level entry whose name a package body declares, so the body's entry lends, and a dev reload replaces it with the artifact's top-level entries of the name, the first of which lends. The finding now says that, and opens with "which the composed artifact declares both in a package body and at its top level".
13+
14+
- **Where it applies.** A `last` composition with a nested multi-package input, where another input's top level declares the same name as one of its bodies. A `preserve` composition with an input that carries `packages` beside its own top-level collections, where another package declares the same name.
15+
- **Top-level entries only.** Two inputs' top-level entries that disagree, beside package bodies that do not declare the name, get a sentence of their own: no door registers either as a package body's entry, and a dev reload lends from the first top-level entry of the name.
16+
- **Unchanged.** Two package bodies that disagree keep the first-registered wording. The remedy is the same: rename or remove the entry that cannot lend.

‎packages/spec/src/stack-datasource-connector.test.ts‎

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
* both, and the first registered lends) is refused as ambiguous in either
3232
* order when one entry can lend and the other cannot, and accepted when
3333
* both can;
34+
* - a top-level entry beside a package body's same-named entry (a nested
35+
* input's body under `last`, or another package's body under `preserve`
36+
* beside an input that carries `packages` and its own top level) is refused
37+
* as ambiguous when the two disagree, for the reason the runtime gives: the
38+
* boot keeps the body's entry, a dev reload replaces it with the
39+
* artifact's top-level entries of the name, the first of which lends; and
40+
* two such inputs' top-level entries, beside bodies silent on the name,
41+
* are refused with a sentence of their own;
3442
* - a nested multi-package input (a `manifest: 'preserve'` artifact) is read
3543
* through its package bodies, where its connectors and datasources live,
3644
* and an entry it carries in both halves is read once;
@@ -162,6 +170,10 @@ describe('composeStacks judges external.connector against the connectors of ever
162170
return err as Envelope;
163171
}
164172
};
173+
const BESIDE_BODY = 'which the composed artifact declares both in a package body and at its top level, and they disagree';
174+
const BOOT_OR_RELOAD =
175+
"The boot does not register a top-level entry whose name a package body declares, so the body's entry " +
176+
"lends, and a dev reload replaces it with the artifact's top-level entries of the name, the first of which lends";
165177
const expectComposedFinding = (refused: Envelope | undefined, fragment: string): void => {
166178
expectOneFinding(refused, fragment);
167179
expect(refused?.issues).toHaveLength(1);
@@ -275,17 +287,21 @@ describe('composeStacks judges external.connector against the connectors of ever
275287
]);
276288
});
277289

278-
it("treats a package body and another input's top level as two slots, and names the body", () => {
290+
it("refuses as ambiguous a top-level entry beside a package body's same-named entry, and names the body", () => {
279291
const strictPair = defineStack({
280292
manifest: pluginManifest('com.acme.orders'),
281293
datasources: [sapOrders()],
282294
connectors: [instance()],
283295
} as never);
284296
const refused = composeRefusal([nested(strictPair), owner({ name: 'sap_s4', label: 'SAP', type: 'api' })]);
285-
expectComposedFinding(refused, 'which more than one package of the composed artifact declares, and they disagree');
286-
expect(String(refused?.issues?.[0])).toContain(
287-
"package 'com.acme.orders' of 'com.acme.other' (stack #0) declares an instance that can lend",
297+
expectComposedFinding(refused, BESIDE_BODY);
298+
const finding = String(refused?.issues?.[0]);
299+
expect(finding).toContain(
300+
"package 'com.acme.orders' of 'com.acme.other' (stack #0) declares an instance that can lend, " +
301+
"and 'com.acme.sap' (stack #1) declares an entry that cannot.",
288302
);
303+
expect(finding).toContain(BOOT_OR_RELOAD);
304+
expect(finding).not.toContain('one entry per package');
289305
});
290306

291307
it('reads an entry the nested input carries in both halves once', () => {
@@ -306,6 +322,81 @@ describe('composeStacks judges external.connector against the connectors of ever
306322
});
307323
});
308324

325+
describe('a `preserve` input that carries `packages` beside its own top-level collections', () => {
326+
// Hand-assembled: `preservePackageEntries` passes its bodies through and
327+
// assembles its own top level into none, so that top level boots through
328+
// the residual rule (under the composed artifact's `manifest.id`, the last
329+
// input's), and the collector judges it in its own `package:${id}` slot.
330+
const mixed = (connector: Record<string, unknown>, id = 'com.acme.bundle', inner = 'com.acme.inner') =>
331+
defineStack({
332+
manifest: pluginManifest(id),
333+
connectors: [connector],
334+
packages: [{ manifest: pluginManifest(inner) }],
335+
} as never);
336+
const strictPair = () =>
337+
defineStack({
338+
manifest: pluginManifest('com.acme.orders'),
339+
datasources: [sapOrders()],
340+
connectors: [instance()],
341+
} as never);
342+
const descriptor = { name: 'sap_s4', label: 'SAP S/4HANA', type: 'api' };
343+
344+
it.each([
345+
['mixed input first', false],
346+
['mixed input last', true],
347+
])("refuses as ambiguous its top-level entry beside another package's body — %s", (_order, reversed) => {
348+
const stacks = reversed ? [strictPair(), mixed(descriptor)] : [mixed(descriptor), strictPair()];
349+
const refused = composeRefusal(stacks, { manifest: 'preserve' });
350+
expectComposedFinding(refused, BESIDE_BODY);
351+
const finding = String(refused?.issues?.[0]);
352+
expect(finding).toContain("'com.acme.orders' (stack #");
353+
expect(finding).toContain("declares an instance that can lend, and 'com.acme.bundle' (stack #");
354+
expect(finding).toContain(BOOT_OR_RELOAD);
355+
});
356+
357+
it('CONTROL: its top-level instance composes beside a body whose same-named instance can lend too, in either order', () => {
358+
const other = instance({ auth: { type: 'bearer', credentialRef: 'sap_token_2' } });
359+
const credentialRefs = (artifact: Record<string, unknown>): unknown[] =>
360+
(artifact.connectors as { auth: { credentialRef: unknown } }[]).map((c) => c.auth.credentialRef);
361+
const artifact = composeStacks([mixed(other), strictPair()] as never, { manifest: 'preserve' }) as Record<string, unknown>;
362+
// No body owns the mixed input's top level, so the artifact keeps the
363+
// whole flattened list, in input order, beside bodies of the inner
364+
// package and the plain input only, and the residual rule reads it
365+
// under the last input's manifest id. A dev reload lends from the first
366+
// entry of that list, which is why the order is pinned.
367+
expect((artifact.manifest as Record<string, unknown>).id).toBe('com.acme.orders');
368+
expect(
369+
(artifact.packages as { manifest: Record<string, unknown> }[]).map((pkg) => pkg.manifest.id),
370+
).toEqual(['com.acme.inner', 'com.acme.orders']);
371+
expect(credentialRefs(artifact)).toEqual(['sap_token_2', 'sap_token']);
372+
const mixedLast = composeStacks([strictPair(), mixed(other)] as never, { manifest: 'preserve' }) as Record<
373+
string,
374+
unknown
375+
>;
376+
expect(credentialRefs(mixedLast)).toEqual(['sap_token', 'sap_token_2']);
377+
});
378+
379+
it.each([
380+
['descriptor first', false],
381+
['instance first', true],
382+
])('refuses two such inputs whose top-level entries disagree, beside bodies silent on the name — %s', (_order, reversed) => {
383+
const withDescriptor = mixed(descriptor, 'com.acme.bundle', 'com.acme.inner');
384+
const withInstance = mixed(instance(), 'com.acme.kit', 'com.acme.toolkit');
385+
const pair = reversed ? [withInstance, withDescriptor] : [withDescriptor, withInstance];
386+
const refused = composeRefusal([...pair, looseBorrower()], { manifest: 'preserve' });
387+
expectComposedFinding(
388+
refused,
389+
'which more than one input declares at the top level of a composed artifact that carries package bodies, and they disagree',
390+
);
391+
const finding = String(refused?.issues?.[0]);
392+
expect(finding).toContain("'com.acme.kit' (stack #");
393+
expect(finding).toContain("declares an instance that can lend, and 'com.acme.bundle' (stack #");
394+
expect(finding).toContain(
395+
"No door registers either as a package body's entry, and a dev reload lends from the first top-level entry of the name",
396+
);
397+
});
398+
});
399+
309400
it('CONTROL: the per-stack strict refusal is unchanged — a strict input never carries a dangling name in', () => {
310401
const refused = refusalOf({ manifest: pluginManifest('com.acme.orders'), datasources: [sapOrders()] });
311402
expectOneFinding(refused, 'which is not defined in connectors');

‎packages/spec/src/stack.zod.ts‎

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4514,11 +4514,35 @@ interface ProvidedCollectionEntry {
45144514
/** Where it was declared, for a finding: the input, or a package body of it. */
45154515
declaredIn: string;
45164516
/**
4517-
* The registry slot the entry registers in: the registry keys a
4517+
* The registry slot the entry is judged in: the registry keys a
45184518
* package-owned item by package id and name, so two entries under one name
45194519
* in one slot are one item (the later wins), and in two slots they are two.
4520+
* For a package body's own entry ({@link ProvidedCollectionEntry.inBody})
4521+
* that is the slot it boots into. For a top-level entry that boots beside
4522+
* package bodies it is a stand-in, one per input: see `inBody`.
45204523
*/
45214524
slot: string;
4525+
/**
4526+
* Whether the entry boots as a package body's own item: an entry of a
4527+
* `packages[]` body, or, under `preserve`, the top level of an input that
4528+
* `preservePackageEntries` folds into a body of its own manifest id.
4529+
*
4530+
* `false` for every other top-level entry. When the artifact carries
4531+
* package bodies, such an entry boots through the residual rule
4532+
* (`unclaimedTopLevel`, `@objectstack/metadata`): it is not registered at
4533+
* all when a body declares its name, and is registered under the composed
4534+
* artifact's `manifest.id` (the last input's) when none does; a dev reload
4535+
* then replaces the booted entries of the name with the artifact's
4536+
* top-level list (`mergeDeclaredConnectorSources`,
4537+
* `@objectstack/service-automation`). Its `slot` is therefore not the slot
4538+
* it boots into: `'artifact'` under `last` and for an input with no
4539+
* manifest id, and under `preserve` the input's own `package:${id}` for an
4540+
* input that carries `packages` beside its own collections. Keeping such a
4541+
* top level in a slot apart from the bodies is what refuses a disagreement
4542+
* with a body's entry as ambiguous, which is the verdict the boot-or-reload
4543+
* split asks for, so the stand-in stays.
4544+
*/
4545+
inBody: boolean;
45224546
}
45234547

45244548
/**
@@ -4532,9 +4556,13 @@ interface ProvidedCollectionEntry {
45324556
* reproduce its flattened half keeps both halves, holding the same entry
45334557
* objects in each, so the bodies are read first and the top level adds only
45344558
* what no body carries. The slot follows how the artifact boots: a package
4535-
* body registers under its own id; a top-level entry registers under the
4536-
* input's own package when `preserve` folds each input into a package body,
4537-
* and under the composed artifact's one package otherwise.
4559+
* body registers under its own id, and so does the top level of an input that
4560+
* `preserve` folds into a package body. Any other top-level entry takes the
4561+
* input's own `package:${id}` under `preserve` when the input has a manifest
4562+
* id, and the `'artifact'` slot otherwise. When no input carries package
4563+
* bodies, `'artifact'` is the composed artifact's one package. Beside package
4564+
* bodies both are stand-ins, because such an entry boots through the residual
4565+
* rule and a dev reload replaces it (see {@link ProvidedCollectionEntry.inBody}).
45384566
*/
45394567
function providedCollectionEntries(
45404568
stack: ObjectStackDefinition,
@@ -4545,25 +4573,26 @@ function providedCollectionEntries(
45454573
const entries: ProvidedCollectionEntry[] = [];
45464574
const seen = new Set<unknown>();
45474575
const input = stackLabel(stack, index);
4548-
const collect = (list: unknown, declaredIn: string, slot: string): void => {
4576+
const collect = (list: unknown, declaredIn: string, slot: string, inBody: boolean): void => {
45494577
if (!Array.isArray(list)) return;
45504578
for (const entry of list) {
45514579
if (seen.has(entry)) continue;
45524580
seen.add(entry);
4553-
entries.push({ entry, declaredIn, slot });
4581+
entries.push({ entry, declaredIn, slot, inBody });
45544582
}
45554583
};
45564584
const source = stack as Record<string, unknown>;
45574585
if (Array.isArray(source.packages)) {
45584586
for (const pkg of source.packages) {
45594587
if (!isRecord(pkg) || !isRecord(pkg.manifest)) continue;
45604588
const id = pkg.manifest.id ?? pkg.manifest.name;
4561-
if (typeof id === 'string') collect(pkg.manifest[key], `package '${id}' of ${input}`, `package:${id}`);
4562-
else collect(pkg.manifest[key], input, `input:${index}`);
4589+
if (typeof id === 'string') collect(pkg.manifest[key], `package '${id}' of ${input}`, `package:${id}`, true);
4590+
else collect(pkg.manifest[key], input, `input:${index}`, true);
45634591
}
45644592
}
45654593
const ownId = stack.manifest?.id ?? stack.manifest?.name;
4566-
collect(source[key], input, preserve && typeof ownId === 'string' ? `package:${ownId}` : 'artifact');
4594+
const ownSlot = preserve && typeof ownId === 'string' ? `package:${ownId}` : 'artifact';
4595+
collect(source[key], input, ownSlot, ownSlot !== 'artifact' && !Array.isArray(source.packages));
45674596
return entries;
45684597
}
45694598

@@ -4592,12 +4621,23 @@ function providedCollectionEntries(
45924621
* registry keeps ({@link SAME_STACK_ENTRY_IDENTITY}'s `connectors` row), so
45934622
* the kept entry is judged, and when it cannot lend but an earlier one in the
45944623
* slot could, the finding names both and prescribes the duplicate's fix. In
4595-
* DIFFERENT slots (two packages of the artifact) the registry keeps one entry
4596-
* per package, and the lender answers whichever registers first, so when the
4597-
* kept entries disagree on whether they can lend the borrow is refused as
4598-
* ambiguous in either declaration order: the build cannot know which one the
4599-
* datasource gets, and one name meaning one grant is what D7 asks for. When
4600-
* they agree, the verdict is the same whichever one lends.
4624+
* DIFFERENT slots the kept entries are refused as ambiguous, in either
4625+
* declaration order, when they disagree on whether they can lend. The build
4626+
* cannot know which one the datasource gets, and one name meaning one grant
4627+
* is what D7 asks for. Which mechanism makes it unknowable depends on where
4628+
* the entries sit, and the finding names it:
4629+
*
4630+
* - two package bodies: the registry keeps one entry per package, and the
4631+
* lender answers whichever registers first;
4632+
* - a package body and a top-level entry beside it: the boot does not
4633+
* register the top-level entry, so the body's lends, and a dev reload
4634+
* replaces the body's entry with the artifact's top-level entries of the
4635+
* name, the first of which lends ({@link ProvidedCollectionEntry.inBody});
4636+
* - top-level entries of two inputs, beside bodies that do not declare the
4637+
* name: no door registers either as a package body's entry, and a dev
4638+
* reload lends from the first top-level entry of the name.
4639+
*
4640+
* When the kept entries agree, the verdict is the same whichever one lends.
46014641
*/
46024642
function collectComposedDatasourceConnectorErrors(
46034643
stacks: readonly ObjectStackDefinition[],
@@ -4626,13 +4666,28 @@ function collectComposedDatasourceConnectorErrors(
46264666
const notLending = kept.filter((provided) => !lends(provided));
46274667
if (lending.length > 0 && notLending.length > 0) {
46284668
const sites = (list: ProvidedCollectionEntry[]): string => list.map((p) => p.declaredIn).join(', ');
4669+
const disagree =
4670+
`and they disagree: ${sites(lending)} declares an instance that can lend, and ` +
4671+
`${sites(notLending)} declares an entry that cannot.`;
4672+
const inBodies = kept.filter((provided) => provided.inBody).length;
4673+
const where =
4674+
inBodies === kept.length
4675+
? `which more than one package of the composed artifact declares, ${disagree} The runtime ` +
4676+
`keeps one entry per package and lends from whichever registers first, so the datasource ` +
4677+
`could boot with no credential.`
4678+
: inBodies > 0
4679+
? `which the composed artifact declares both in a package body and at its top level, ` +
4680+
`${disagree} The boot does not register a top-level entry whose name a package body ` +
4681+
`declares, so the body's entry lends, and a dev reload replaces it with the artifact's ` +
4682+
`top-level entries of the name, the first of which lends, so the entry the datasource ` +
4683+
`borrows depends on whether the artifact was booted or reloaded and on the order of its inputs.`
4684+
: `which more than one input declares at the top level of a composed artifact that ` +
4685+
`carries package bodies, ${disagree} No door registers either as a package body's ` +
4686+
`entry, and a dev reload lends from the first top-level entry of the name, so the build ` +
4687+
`cannot tell which one lends, and the datasource could boot with no credential.`;
46294688
ambiguities.set(
46304689
name,
4631-
`which more than one package of the composed artifact declares, and they disagree: ` +
4632-
`${sites(lending)} declares an instance that can lend, and ${sites(notLending)} declares an ` +
4633-
`entry that cannot. The runtime keeps one entry per package and lends from whichever ` +
4634-
`registers first, so the datasource could boot with no credential. Rename or remove the ` +
4635-
`entry that cannot lend, so that one connector name means one instance.`,
4690+
`${where} Rename or remove the entry that cannot lend, so that one connector name means one instance.`,
46364691
);
46374692
continue;
46384693
}

0 commit comments

Comments
 (0)