Skip to content

Commit b9c7a8f

Browse files
fix(service-datasource)!: the datasource admin API refuses to make a datasource managed while objects bind it with external (#25431)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu4rqxAsaQ9Xbbbf3naZ1vaL)_ Fixes #25277 Clause-②: no (narrowing) Metadata-protocol: narrowed The datasource admin API (`POST /api/v1/datasources`, `PATCH /api/v1/datasources/NAME`) no longer stores a datasource that is managed while objects bind it with `external`. `createDatasource` and `updateDatasource` now judge the record they will persist against the objects bound to it, through the spec predicate `externalBindingDatasourceRefusal` (the one copy of the ADR-0015 §4.2 rule the metadata save door asks), before any secret or record write. ## The defect, measured on base `f0fdd45bb` - The metadata save door refuses a datasource saved as `managed` (or with no `schemaMode`, the spec default) while objects bind it with `external` (`externalBindingSaveRefusal`, `packages/metadata-protocol/src/protocol.ts:22675`, datasource half `:22692`). - `createDatasource` (`packages/services/service-datasource/src/datasource-admin-service.ts:608`) and `updateDatasource` (`:654`) write through `putDatasourceRecord` (`datasource-admin-plugin.ts:418`: `metadata.register` plus a direct `sys_metadata` insert/update). Neither enters `saveMetaItem`, so the pair the save door refuses was stored: on create (objects can name a datasource before it exists, and the save door gives no verdict on a binding whose datasource it cannot see) and on a `PATCH` that sets `schemaMode: 'managed'`. ## What changed - `DatasourceAdminService` (`datasource-admin-service.ts`): a private `boundExternalRefusal(record)` asks the predicate once per object that names the datasource, and counts only its `managed` verdict, exactly as the save door's datasource half does. One line per bound object, each `schemaMode: ` plus the predicate's own message, under the door's `Invalid datasource 'NAME'.` heading. It is thrown as the door's other record refusals are, so the route answers `400 DATASOURCE_ADMIN_ERROR` (the code this service already uses; no new error code). - `createDatasource`: judged right after the existing record judgement, before `writeSecret` and `putDatasourceRecord`. - `updateDatasource`: the merged record, under the condition the record judgement already uses (a supplied secret or a patched `driver` / `schemaMode` / `config` / `external` / `pool`). A `label` / `active`-only write is not judged, so a row that already pairs badly can still be renamed or taken out of service. - `DatasourceAdminServiceConfig` gains one **required** member, `listObjectsBoundTo(datasource)`: the objects that name the datasource, with their `external` binding. Required because it is the verdict's input; an optional seam would let a host store the very pair this closes. - `DatasourceAdminServicePlugin` (`datasource-admin-plugin.ts`) answers it from the engine's object registry (the `objectql` service's `registry`), the registry the save door writes through to, so an object saved through `PUT /api/v1/meta/object/NAME` or imported from a remote table counts at once. Not the metadata service's `listObjects()`, which holds a boot-time copy that a runtime save never reaches (the reading `plugin.ts` records for the federation service). - The existing `DatasourceAdminServiceConfig` fakes in this package's tests gain `listObjectsBoundTo: async () => []` (8 files, 10 fakes, no assertion moved). ## Contract Every input whose answer changes, old to new: 1. **`POST /datasources`, `schemaMode: 'managed'` or none, and an object in the engine registry names that datasource with `external`.** Old: `201`, the record stored and registered, a supplied secret minted, the pool registered. New: `400 DATASOURCE_ADMIN_ERROR` naming each such object; nothing stored, registered or minted. 2. **`PATCH /datasources/NAME` that sets `schemaMode: 'managed'` on a federated datasource such objects bind.** Old: `200`, the row flipped, the pool rebuilt. New: the same `400`; the row, its secret and its pool untouched. 3. **`PATCH` of a judged key (or with a secret) on a datasource that is already managed and already bound `external`.** Old: `200`. New: the same `400`. The fix it names: declare the datasource `external` / `validate-only`, or remove `external` from the objects. Unchanged: a federated datasource (`schemaMode: 'external'` or `'validate-only'`) and a datasource no object binds with `external` keep their answers (pinned on both doors); objects on the datasource with no `external` binding, and objects bound `external` to another datasource, are never in the verdict (pinned); a `label` / `active`-only `PATCH` is applied (pinned); `testConnection`, `removeDatasource` and `migrateCredential` are not touched (none of them changes `schemaMode`). ## Pins - `src/__tests__/datasource-admin-external-binding.test.ts` (new, 11 cases): through the real routes over the real service. Each refusal asserts status, `error.code`, the predicate's own message per bound object (derived from `externalBindingDatasourceRefusal`, never restated) and the store after (no record, no secret, no `put` / `registerPool` / `reregisterPool` call). Controls: no `external` binding, federated `external` and `validate-only` on create, `validate-only` on update, managed with no external binding, label/active-only. - `src/__tests__/datasource-admin-plugin.test.ts` (3 cases added): the plugin's seam reads the `objectql` registry while the metadata service's `listObjects()` is empty, so a runtime-saved object blocks create and the flip to managed; an object with no `external` binding does not. **Ablation** (`scripts/ablation-replace.mjs`, anchor `if (findings.length === 0) return undefined;` replaced by `return undefined;`, landed 1 to 0, restored to the HEAD blob `1c8772e150d7` with `git diff HEAD` empty): the two pin files went `7 failed | 35 passed`. The 7 red are exactly the refusal pins (5 door, 2 plugin); every control stayed green. ## Local verification On `ab44e1bd`, over `origin/main` `f0fdd45bb`. Heavy runs went through the verify lock; each line cites its `VERDICT`. - `pnpm exec turbo run build --filter='@objectstack/service-datasource^...'`: `VERDICT command-exit 0`. - `@objectstack/service-datasource` suite (`vitest run`): `VERDICT command-exit 0`; Test Files 56 passed (56); Tests 969 passed (969). - `pnpm --filter @objectstack/service-datasource typecheck`: `VERDICT command-exit 0`. - `eslint --no-inline-config` on the changed `.ts` files: exit 0. `check-nul-bytes`: exit 0. - `node scripts/pm/dispatch-gates.mjs --commands`: 68 families derived, each run, every one `exit 0` (`check:type-check-debt` under the lock; the build-reading families after the dogfood closure build). - `--ran` reconciliation: `68 derived famil(ies) accounted for — 68 run, 0 NOT-MEASURED (a DERIVED zero — all 68 recorded an exit code and none of them is 3)`. - `check-adr-0087-registration --base origin/main` (in the derived set, on the committed head): exit 0 with the changeset's `not-required (already-registered object-external-binding-managed-datasource-refused)` disposition. - The full dogfood battery is owed once on the final head (the `!` and the `(narrowing)` arm); its counts follow as a PR comment. ## Acceptance notes - **The bound-object count behind `removeDatasource` reads the boot-time copy.** `countBoundObjects` / `countBoundObjectsDiagnosed` (`datasource-admin-plugin.ts:461`, `:486`) count from `metadata.listObjects()`, the copy `plugin.ts` records as taken once at boot and never reached by a runtime save. So an object imported or saved at runtime is not counted, and the removal guard can read `0` for a datasource such an object binds until the next restart. Read from code and from that recorded reading; not reproduced at the public door here, so not filed. This PR leaves the count alone (its own card's scope); the new seam reads the registry. Carrier: none. - **Branch name.** This PR's branch is `claude/project-thread-29nfa9`, the name the session was given, not `claude/issue-25277-…`; the Duplicate Fix Guard may say so. The claim (comment 6365222748) names it. --- _Generated by [Claude Code](https://claude.ai/code/session_01AkGUa1szqpcew6SVTijZsv)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01AkGUa1szqpcew6SVTijZsv --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2b7c331 commit b9c7a8f

13 files changed

Lines changed: 426 additions & 2 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@objectstack/service-datasource': minor
3+
---
4+
5+
fix(service-datasource)!: the datasource admin API refuses to make a datasource managed while objects bind it with `external`, as the metadata save door does
6+
7+
Clause-②: no (narrowing)
8+
9+
Metadata-protocol: narrowed
10+
11+
<!-- adr-0087: not-required (already-registered object-external-binding-managed-datasource-refused) no rule is added or changed: the admin door now asks the save door's existing ADR-0015 §4.2 predicate, and that ledger entry already describes the refused shape and its fix -->
12+
13+
**BREAKING** (what the datasource admin API stores narrows), shipped as `minor` under the 18.x convention for breaking changes.
14+
15+
`POST /api/v1/datasources` (`createDatasource`) and `PATCH /api/v1/datasources/:name` (`updateDatasource`) write the datasource without entering the metadata save door. So they stored a datasource that is managed (`schemaMode: 'managed'`, or no `schemaMode`, the spec default) while objects bind it with `external`: the pair `PUT /api/v1/meta/datasource/:name` refuses (ADR-0015 §4.2). The runtime then skips those objects' DDL as federated while the boot validation and the write gate judge them as managed.
16+
17+
- **FROM:** the admin API created a managed datasource under objects that already name it with `external`, and a `PATCH` that set `schemaMode: 'managed'` (or edited another bound field of a datasource that is already managed) was stored.
18+
- **TO:** both refuse with `400 DATASOURCE_ADMIN_ERROR`, one line per bound object, each the spec predicate's own message (`externalBindingDatasourceRefusal`, `@objectstack/spec/data`). Nothing is stored or registered, no secret is minted and the live pool is untouched.
19+
- **Unchanged:** a federated datasource (`schemaMode: 'external'` or `'validate-only'`) and a datasource no object binds with `external` keep their answers. A `PATCH` that changes only `label` or `active` is not judged, so a datasource can still be renamed or taken out of service.
20+
- **For a host that builds `DatasourceAdminService` itself:** `DatasourceAdminServiceConfig` gains a required member, `listObjectsBoundTo(datasource)`, returning the objects that name the datasource with their `external` binding. `DatasourceAdminServicePlugin` answers it from the engine's object registry (the `objectql` service's `registry`, the one the save door writes through to), so an object saved or imported at runtime counts at once.
21+
- **The fix for an author:** declare the datasource `schemaMode: 'external'` (or `'validate-only'`) with its `external` settings, or remove `external` from the bound objects first, then make it managed.
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
import { describe, it, expect, vi } from 'vitest';
4+
import { externalBindingDatasourceRefusal } from '@objectstack/spec/data';
5+
import { HonoHttpServer } from '@objectstack/plugin-hono-server';
6+
import { registerDatasourceAdminRoutes } from '../admin-routes.js';
7+
import {
8+
DatasourceAdminService,
9+
type DatasourceAdminServiceConfig,
10+
type StoredDatasource,
11+
} from '../datasource-admin-service.js';
12+
import {
13+
ENTITLED_CREDENTIAL,
14+
createSessionAuthService,
15+
createGrantsEngine,
16+
} from './entitled-caller.fixture.js';
17+
18+
/**
19+
* #25277 — ADR-0015 §4.2 at the datasource admin door.
20+
*
21+
* The metadata save door refuses a datasource saved or changed to `managed`
22+
* (or with no `schemaMode`, the spec default) while objects bind it with
23+
* `external`. `POST /api/v1/datasources` and `PATCH /api/v1/datasources/:name`
24+
* write the datasource without entering that door, so they stored the pair
25+
* the save door refuses: the runtime then skips the bound objects' DDL as
26+
* federated while the boot validation and the write gate judge them managed.
27+
*
28+
* Driven through the REAL routes over the REAL service. Each refusal pin reads
29+
* the envelope a caller sees (status + `error.code`), the bound objects the
30+
* message names, and the store behind it: nothing stored, registered or
31+
* minted. The expected message is the spec predicate's own for the same pair,
32+
* derived here, never restated.
33+
*/
34+
35+
const authService = createSessionAuthService();
36+
const grantsEngine = createGrantsEngine();
37+
38+
interface BoundObject {
39+
name: string;
40+
datasource?: string;
41+
external?: unknown;
42+
}
43+
44+
/** In-memory datasource store, secret store and object set behind a real {@link DatasourceAdminService}. */
45+
function makeDoor(opts: { seed?: StoredDatasource[]; objects?: BoundObject[] } = {}) {
46+
const records = new Map<string, StoredDatasource>((opts.seed ?? []).map((r) => [r.name, structuredClone(r)]));
47+
const secrets = new Map<string, string>();
48+
const objects = opts.objects ?? [];
49+
let seq = 0;
50+
const ops: string[] = [];
51+
52+
const config: DatasourceAdminServiceConfig = {
53+
probe: async () => ({ ok: true, latencyMs: 1 }),
54+
listDatasourceRecords: async () => [...records.values()].map((r) => structuredClone(r)),
55+
getDatasourceRecord: async (name) => {
56+
const r = records.get(name);
57+
return r ? structuredClone(r) : undefined;
58+
},
59+
putDatasourceRecord: async (record) => {
60+
ops.push(`put:${record.name}`);
61+
records.set(record.name, structuredClone(record));
62+
},
63+
deleteDatasourceRecord: async (name) => {
64+
records.delete(name);
65+
},
66+
writeSecret: async (input, hint) => {
67+
ops.push('writeSecret');
68+
const ref = `sys_secret://datasource/${hint.name}#${++seq}`;
69+
secrets.set(ref, input.value);
70+
return ref;
71+
},
72+
removeSecret: async (ref) => {
73+
ops.push('removeSecret');
74+
secrets.delete(ref);
75+
},
76+
countBoundObjects: async (name) => objects.filter((o) => o.datasource === name).length,
77+
listObjectsBoundTo: async (name) =>
78+
objects.filter((o) => o.datasource === name).map((o) => ({ name: o.name, external: o.external })),
79+
registerPool: () => {
80+
ops.push('registerPool');
81+
},
82+
unregisterPool: () => {
83+
ops.push('unregisterPool');
84+
},
85+
reregisterPool: () => {
86+
ops.push('reregisterPool');
87+
},
88+
};
89+
90+
const service = new DatasourceAdminService(config);
91+
const server = new HonoHttpServer(0);
92+
const ctx = {
93+
getService: vi.fn((name: string) =>
94+
name === 'auth'
95+
? authService
96+
: name === 'objectql' || name === 'data'
97+
? grantsEngine
98+
: name === 'datasource-admin'
99+
? service
100+
: undefined,
101+
),
102+
} as any;
103+
registerDatasourceAdminRoutes(server, ctx, '/api/v1');
104+
const app = server.getRawApp();
105+
106+
const send = (method: string, path: string, body: unknown) =>
107+
app.fetch(
108+
new Request(`http://local/api/v1${path}`, {
109+
method,
110+
headers: { 'content-type': 'application/json', authorization: ENTITLED_CREDENTIAL },
111+
body: JSON.stringify(body),
112+
}),
113+
);
114+
115+
return { send, records, secrets, ops };
116+
}
117+
118+
/**
119+
* The spec predicate's message for `object` bound with `external` to a
120+
* datasource declared `declared`. Throws when the predicate makes no `managed`
121+
* refusal, so a pin can never pass on a premise the spec no longer holds.
122+
*/
123+
function predicateMessage(object: BoundObject, declared: { schemaMode?: unknown }): string {
124+
const refusal = externalBindingDatasourceRefusal(object.name, object.external, object.datasource, declared);
125+
if (refusal?.shape !== 'managed') throw new Error(`fixture premise broken: no managed refusal for '${object.name}'`);
126+
return `schemaMode: ${refusal.message}`;
127+
}
128+
129+
async function expectRefusal(res: Response, expected: string[]): Promise<string> {
130+
expect(res.status).toBe(400);
131+
const body = (await res.json()) as { success: boolean; error: { code: string; message: string } };
132+
expect(body.success).toBe(false);
133+
expect(body.error.code).toBe('DATASOURCE_ADMIN_ERROR');
134+
for (const line of expected) expect(body.error.message).toContain(line);
135+
return body.error.message;
136+
}
137+
138+
const PG = { database: 'analytics' };
139+
const ORDERS: BoundObject = { name: 'wh_orders', datasource: 'wh', external: { remoteName: 'orders' } };
140+
const ITEMS: BoundObject = { name: 'wh_items', datasource: 'wh', external: { remoteName: 'items' } };
141+
/** Names `wh` as its datasource with no `external` binding: a managed object on it. */
142+
const LOCAL: BoundObject = { name: 'wh_local', datasource: 'wh' };
143+
/** Bound `external` to ANOTHER datasource: never part of `wh`'s verdict. */
144+
const ELSEWHERE: BoundObject = { name: 'lake_events', datasource: 'lake', external: { remoteName: 'events' } };
145+
146+
describe('POST /api/v1/datasources refuses a managed datasource under objects bound external (#25277)', () => {
147+
it("refuses schemaMode 'managed' — nothing stored, registered or minted", async () => {
148+
const door = makeDoor({ objects: [ORDERS] });
149+
const res = await door.send('POST', '/datasources', {
150+
name: 'wh',
151+
driver: 'postgres',
152+
schemaMode: 'managed',
153+
config: PG,
154+
secret: 'any-secret',
155+
});
156+
157+
const message = await expectRefusal(res, [predicateMessage(ORDERS, { schemaMode: 'managed' })]);
158+
expect(message.startsWith("Invalid datasource 'wh'.")).toBe(true);
159+
expect(door.records.size).toBe(0);
160+
expect(door.secrets.size).toBe(0);
161+
expect(door.ops).toEqual([]);
162+
});
163+
164+
it('refuses no schemaMode (managed by the spec default)', async () => {
165+
const door = makeDoor({ objects: [ORDERS] });
166+
const res = await door.send('POST', '/datasources', { name: 'wh', driver: 'postgres', config: PG });
167+
168+
await expectRefusal(res, [predicateMessage(ORDERS, {})]);
169+
expect(door.records.size).toBe(0);
170+
expect(door.ops).toEqual([]);
171+
});
172+
173+
it('names every object bound external, and only those', async () => {
174+
const door = makeDoor({ objects: [ORDERS, ITEMS, LOCAL, ELSEWHERE] });
175+
const res = await door.send('POST', '/datasources', { name: 'wh', driver: 'postgres', config: PG });
176+
177+
const message = await expectRefusal(res, [
178+
predicateMessage(ORDERS, {}),
179+
predicateMessage(ITEMS, {}),
180+
]);
181+
expect(message).not.toContain("'wh_local'");
182+
expect(message).not.toContain("'lake_events'");
183+
expect(door.records.size).toBe(0);
184+
});
185+
186+
it('control: the same POST with no object bound external is created', async () => {
187+
const door = makeDoor({ objects: [LOCAL, ELSEWHERE] });
188+
const res = await door.send('POST', '/datasources', { name: 'wh', driver: 'postgres', config: PG });
189+
190+
expect(res.status).toBe(201);
191+
expect(door.records.get('wh')?.schemaMode).toBeUndefined();
192+
expect(door.ops).toEqual(['put:wh', 'registerPool']);
193+
});
194+
195+
it.each(['external', 'validate-only'] as const)(
196+
"control: a federated datasource (schemaMode '%s') under objects bound external is created",
197+
async (schemaMode) => {
198+
const door = makeDoor({ objects: [ORDERS] });
199+
const res = await door.send('POST', '/datasources', {
200+
name: 'wh',
201+
driver: 'postgres',
202+
schemaMode,
203+
config: PG,
204+
external: {},
205+
});
206+
207+
expect(res.status).toBe(201);
208+
expect(door.records.get('wh')?.schemaMode).toBe(schemaMode);
209+
},
210+
);
211+
});
212+
213+
describe('PATCH /api/v1/datasources/:name refuses making a bound datasource managed (#25277)', () => {
214+
const federated = (): StoredDatasource => ({
215+
name: 'wh',
216+
driver: 'postgres',
217+
origin: 'runtime',
218+
schemaMode: 'external',
219+
config: PG,
220+
external: {},
221+
});
222+
223+
it("refuses schemaMode 'managed' — record, pool and secrets untouched", async () => {
224+
const door = makeDoor({ seed: [federated()], objects: [ORDERS, ITEMS] });
225+
const before = structuredClone(door.records.get('wh'));
226+
227+
const res = await door.send('PATCH', '/datasources/wh', { schemaMode: 'managed', secret: 'rotated' });
228+
229+
await expectRefusal(res, [
230+
predicateMessage(ORDERS, { schemaMode: 'managed' }),
231+
predicateMessage(ITEMS, { schemaMode: 'managed' }),
232+
]);
233+
expect(door.records.get('wh')).toEqual(before);
234+
expect(door.secrets.size).toBe(0);
235+
expect(door.ops).toEqual([]);
236+
});
237+
238+
it('control: the same PATCH with no object bound external is applied', async () => {
239+
const door = makeDoor({ seed: [federated()], objects: [LOCAL, ELSEWHERE] });
240+
const res = await door.send('PATCH', '/datasources/wh', { schemaMode: 'managed' });
241+
242+
expect(res.status).toBe(200);
243+
expect(door.records.get('wh')?.schemaMode).toBe('managed');
244+
});
245+
246+
it("control: a federated PATCH (schemaMode 'validate-only') under objects bound external is applied", async () => {
247+
const door = makeDoor({ seed: [federated()], objects: [ORDERS] });
248+
const res = await door.send('PATCH', '/datasources/wh', { schemaMode: 'validate-only' });
249+
250+
expect(res.status).toBe(200);
251+
expect(door.records.get('wh')?.schemaMode).toBe('validate-only');
252+
});
253+
254+
it('refuses a config edit on a managed row that objects already bind external', async () => {
255+
const managed: StoredDatasource = { name: 'wh', driver: 'postgres', origin: 'runtime', config: PG };
256+
const door = makeDoor({ seed: [managed], objects: [ORDERS] });
257+
258+
const res = await door.send('PATCH', '/datasources/wh', { config: { database: 'warehouse' } });
259+
260+
await expectRefusal(res, [predicateMessage(ORDERS, {})]);
261+
expect(door.records.get('wh')).toEqual(managed);
262+
expect(door.ops).toEqual([]);
263+
});
264+
265+
it('control: a label/active-only PATCH on that row is applied, so it can still be taken out of service', async () => {
266+
const managed: StoredDatasource = { name: 'wh', driver: 'postgres', origin: 'runtime', config: PG };
267+
const door = makeDoor({ seed: [managed], objects: [ORDERS] });
268+
269+
const res = await door.send('PATCH', '/datasources/wh', { label: 'Warehouse', active: false });
270+
271+
expect(res.status).toBe(200);
272+
expect(door.records.get('wh')).toMatchObject({ label: 'Warehouse', active: false });
273+
});
274+
});

‎packages/services/service-datasource/src/__tests__/datasource-admin-plugin.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,3 +804,45 @@ describe('DatasourceAdminServicePlugin: runtime datasource durability', () => {
804804
});
805805
});
806806
});
807+
808+
describe('DatasourceAdminServicePlugin: objects bound external are read from the engine registry (#25277)', () => {
809+
/**
810+
* The `objectql` service's object registry, the one the metadata save door
811+
* writes through to. The metadata service's `listObjects()` (a boot-time copy)
812+
* is left empty on purpose: an object saved at runtime is in the registry only.
813+
*/
814+
const objectql = (objects: unknown[]) => ({ registry: { getAllObjects: () => objects } });
815+
const ORDERS = { name: 'wh_orders', datasource: 'wh', external: { remoteName: 'orders' } };
816+
817+
it('refuses creating a managed datasource that a runtime-saved object binds external — nothing persisted', async () => {
818+
const { service, registry } = await boot({ services: { objectql: objectql([ORDERS]) } });
819+
820+
await expect(
821+
service.createDatasource({ name: 'wh', driver: 'postgres', config: { database: 'analytics' } }),
822+
).rejects.toThrow(/Object 'wh_orders' declares `external` on datasource 'wh', whose `schemaMode` is 'managed'/);
823+
expect(registry.get('datasource')?.has('wh') ?? false).toBe(false);
824+
});
825+
826+
it('refuses flipping a federated datasource to managed under that object — the row keeps its schemaMode', async () => {
827+
const { service, registry } = await boot({ services: { objectql: objectql([ORDERS]) } });
828+
await service.createDatasource({
829+
name: 'wh',
830+
driver: 'postgres',
831+
schemaMode: 'external',
832+
config: { database: 'analytics' },
833+
external: {},
834+
});
835+
836+
await expect(service.updateDatasource('wh', { schemaMode: 'managed' })).rejects.toThrow(/'wh_orders'/);
837+
expect((registry.get('datasource')?.get('wh') as { schemaMode?: string }).schemaMode).toBe('external');
838+
});
839+
840+
it('control: an object on the datasource with no external binding does not block it', async () => {
841+
const { service, registry } = await boot({
842+
services: { objectql: objectql([{ name: 'wh_local', datasource: 'wh' }]) },
843+
});
844+
845+
await service.createDatasource({ name: 'wh', driver: 'postgres', config: { database: 'analytics' } });
846+
expect(registry.get('datasource')?.has('wh')).toBe(true);
847+
});
848+
});

‎packages/services/service-datasource/src/__tests__/datasource-admin-record-judgement.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function makeDoor(seed: StoredDatasource[] = []) {
7575
secrets.delete(ref);
7676
},
7777
countBoundObjects: async () => 0,
78+
listObjectsBoundTo: async () => [],
7879
registerPool: () => {
7980
ops.push('registerPool');
8081
},

‎packages/services/service-datasource/src/__tests__/datasource-admin-service.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function makeHarness(opts?: {
8686
},
8787
}),
8888
countBoundObjects: async (n) => opts?.boundCounts?.[n] ?? 0,
89+
listObjectsBoundTo: async () => [],
8990
registerPool: (record) => {
9091
registered.push(record.name);
9192
},
@@ -440,6 +441,7 @@ describe('listDatasources — status reflects the last connect verdict (framewor
440441
deleteDatasourceRecord: async () => {},
441442
writeSecret: async () => 'ref',
442443
countBoundObjects: async () => 0,
444+
listObjectsBoundTo: async () => [],
443445
connectionStates: () => states,
444446
};
445447
return new DatasourceAdminService(config);
@@ -493,6 +495,7 @@ describe('listDatasources — status reflects the last connect verdict (framewor
493495
deleteDatasourceRecord: async () => {},
494496
writeSecret: async () => 'ref',
495497
countBoundObjects: async () => 0,
498+
listObjectsBoundTo: async () => [],
496499
// no `connectionStates`
497500
};
498501
const list = await new DatasourceAdminService(config).listDatasources();

‎packages/services/service-datasource/src/__tests__/datasource-cluster-convergence.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ describe('[#13805] the attach seam — loopback, idempotency, the missing conver
583583
deleteDatasourceRecord: async () => {},
584584
writeSecret: async () => 'ref',
585585
countBoundObjects: async () => 0,
586+
listObjectsBoundTo: async () => [],
586587
logger,
587588
...over,
588589
};

‎packages/services/service-datasource/src/__tests__/datasource-config-redaction.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function makeService(seed: StoredDatasource[]) {
8282
deleteDatasourceRecord: async () => {},
8383
writeSecret: async () => 'sys_secret:new',
8484
countBoundObjects: async () => 0,
85+
listObjectsBoundTo: async () => [],
8586
};
8687
return { records, service: new DatasourceAdminService(cfg) };
8788
}

‎packages/services/service-datasource/src/__tests__/datasource-pool-support.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ function adminHarness(seed: StoredDatasource[] = []) {
506506
deleteDatasourceRecord: async () => {},
507507
writeSecret: async () => 'sys_secret://x#1',
508508
countBoundObjects: async () => 0,
509+
listObjectsBoundTo: async () => [],
509510
registerPool: (record) => { registered.push(record.name); },
510511
});
511512
return { service, records, registered };

0 commit comments

Comments
 (0)