Skip to content

Commit 0bd3677

Browse files
committed
wip(spec): the entry's closed nested shapes are published defs that prescribe; fixtures follow
The closed retryConfig and action shapes of an authored connector entry are exported as DeclarativeConnectorEntryRetryConfigSchema and DeclarativeConnectorEntryActionSchema. They are the shapes a metadata document is parsed against, so the authorable-surface gate judges a deletion from their shared declaration on them; the open RetryConfig and ConnectorAction are reached by no metadata root. A credential-shaped key inside either meets the entry's credential prescription, and an execution binding on an action meets ADR-0097 section 5's. Forced test edits: the authorable-surface gate fixtures move to the retry twin, the CLI package-union probe moves to apis[].objectParams; the door pins gain an inline openapi document case and its control. Claude-Session: https://claude.ai/code/session_01Q4EjjP1K353tLKWRMajLsE Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6f2a384 commit 0bd3677

6 files changed

Lines changed: 187 additions & 70 deletions

‎.changeset/connector-entry-nested-undeclared-key-refused.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Metadata-protocol: narrowed
1212
**BREAKING** accept-set narrowing on an authored connector entry (`DeclarativeConnectorEntrySchema`), at every door that parses it: `defineConnector()`, `defineStack({ connectors })`, `os validate` / `os compile`, the metadata plugin's artifact load at boot and on reload, and the metadata save door `PUT /api/v1/meta/connector/:name`.
1313

1414
- **Before.** The entry refused an undeclared top-level key, but its two nested shapes were plain objects: an undeclared key inside `retryConfig` or inside an `actions` element parsed green and meant nothing to the runtime.
15-
- **Now.** Each is refused by name, in one `unrecognized_keys` issue located at the container (`retryConfig`, `actions.N`) that lists every undeclared key; at the save door `422 INVALID_METADATA`, and nothing is stored. An execution binding on an action (`method`, `path`, `url`) is refused the same way: an action carries none (ADR-0097 §5).
15+
- **Now.** Each is refused by name, in one `unrecognized_keys` issue located at the container (`retryConfig`, `actions.N`) that lists every undeclared key; at the save door `422 INVALID_METADATA`, and nothing is stored. A credential-shaped key (`secret`, `token`, `apiKey`, `password`, `credentialRef`, …) meets the entry's own prescription (`auth.credentialRef`); an execution binding on an action (`method`, `path`, `url`) is refused with ADR-0097 §5's: an action carries none.
16+
- **New exports.** The closed shapes are published as `DeclarativeConnectorEntryRetryConfigSchema` and `DeclarativeConnectorEntryActionSchema`, the shapes a metadata document's `retryConfig` and `actions` elements are parsed against.
1617
- **Unchanged.** The published open shapes — `ConnectorSchema`, `RetryConfigSchema`, `ConnectorActionSchema` — keep their posture: the def a plugin hands to `registerConnector`, the actions a provider derives, and the retry policy the runtime parses at materialization. A row stored before this refusal keeps working: the runtime parses its policy with the open `RetryConfigSchema`, the read withholds the undeclared key, and a save of the served form keeps it at rest; a save that leaves `retryConfig` out removes it, the withheld keys with it.
1718

1819
## FROM → TO

‎packages/cli/test/package-union-readers.test.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ const app = { name: 'unr_app', label: 'Union', navigation: [{ id: 'nav_tickets',
9595
const ticketZh = { 'zh-CN': { objects: { unr_ticket: { label: '工单', pluralLabel: '工单', fields: { title: { label: '标题' } } } },
9696
apps: { unr_app: { label: '联合', navigation: { nav_tickets: { label: '工单' } } } } } };
9797
const noteZh = { 'zh-CN': { objects: { unr_note: { label: '笔记', fields: { name: { label: '名称' } } } } } };
98-
const conn = { name: 'unr_conn', label: 'Conn', type: 'api', retryConfig: { zzzUnionProbeKey: 1 } };
98+
const api = { name: 'unr_notes_api', path: '/unr/notes', method: 'GET', type: 'object_operation',
99+
objectParams: { object: 'unr_note', operation: 'find', zzzUnionProbeKey: 1 } };
99100
`;
100101

101102
const CONFIGS: Record<string, string> = {
@@ -119,13 +120,15 @@ export default composeStacks([svc, appStack], { manifest: 'preserve' });
119120
i18nOne: `${PIECES}
120121
export default defineStack({ manifest: appManifest, objects: [ticket, note], apps: [app], i18n: I18N, translations: [ticketZh, noteZh] } as any);
121122
`,
122-
// An undeclared connector key. \`strict: false\` keeps it past the producer's
123+
// An undeclared authoring key. \`strict: false\` keeps it past the producer's
123124
// parse, so the doors' own pre-parse walk is the only carrier into \`--json\`.
124-
// It sits one level down, in \`retryConfig\` (a strip-mode shape the walk still
125-
// visits): the connector entry's own root is closed, so a top-level key there
126-
// is refused by the artifact load rather than warned about.
125+
// It sits one level down, in an API endpoint's \`objectParams\` (a strip-mode
126+
// shape the walk still visits): every collection root is closed, so a
127+
// top-level key is refused by the artifact load rather than warned about. It
128+
// was a connector's \`retryConfig\` until the authored connector entry closed
129+
// its nested shapes too, after which the load refuses that key instead.
127130
keyTwo: `${PIECES}
128-
const svc = defineStack({ manifest: svcManifest, objects: [note], connectors: [conn] } as any, { strict: false });
131+
const svc = defineStack({ manifest: svcManifest, objects: [note], apis: [api] } as any, { strict: false });
129132
const appStack = defineStack({ manifest: appManifest, objects: [ticket], apps: [app] } as any);
130133
export default composeStacks([svc, appStack], { manifest: 'preserve' });
131134
`,
@@ -262,6 +265,6 @@ describe('#22238 — the undeclared-authoring-key walk reads the package union',
262265
it('`os validate --json` carries the finding in `warnings` for a two-package app', () => {
263266
const run = r.validateTwo;
264267
expect(run.code, `${run.stdout}\n${run.stderr}`).toBe(0);
265-
expect(named(run)).toEqual([expect.stringContaining('connectors.unr_conn.retryConfig.zzzUnionProbeKey')]);
268+
expect(named(run)).toEqual([expect.stringContaining('apis.unr_notes_api.objectParams.zzzUnionProbeKey')]);
266269
});
267270
});

‎packages/qa/dogfood/test/connector-meta-door-url-and-nested-keys.dogfood.test.ts‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
// - WRITE: the save door refuses, with the `422 INVALID_METADATA` envelope
88
// located at the position, a URL holding a userinfo or a credential query
99
// parameter — under `providerConfig` (`baseUrl`, `transport.url`, a URL
10-
// `spec`) and under `auth` (`tokenUrl`, `authorizationUrl`) — and a key
11-
// `retryConfig` or an `actions` element does not declare. Nothing is
12-
// stored, and an existing row is left as it was.
13-
// - CONTROL: an instance with credential-free URLs that names its secret with
10+
// `spec`, a URL inside an inline `spec` document) and under `auth`
11+
// (`tokenUrl`, `authorizationUrl`) — and a key `retryConfig` or an
12+
// `actions` element does not declare. Nothing is stored, and an existing
13+
// row is left as it was.
14+
// - CONTROL: an inline `spec` document with credential-free URLs saves as
15+
// written; an instance with credential-free URLs that names its secret with
1416
// `credentialRef` saves, materializes and dispatches upstream with the
1517
// reference resolved; a descriptor with declared action and retry keys saves.
1618
// - READ: a stored row whose `auth` endpoints carry a userinfo (seeded through
@@ -101,6 +103,14 @@ describe('connector metadata doors: an authored connector keeps no credential in
101103
},
102104
});
103105

106+
/** A minimal inline OpenAPI document whose one server is `serverUrl`. */
107+
const inlineSpec = (serverUrl: string) => ({
108+
openapi: '3.0.3',
109+
info: { title: 'CUN inline', version: '1.0.0' },
110+
servers: [{ url: serverUrl }],
111+
paths: {},
112+
});
113+
104114
const descriptor = {
105115
name: DESCRIPTOR,
106116
label: 'CUN descriptor',
@@ -212,6 +222,10 @@ describe('connector metadata doors: an authored connector keeps no credential in
212222
() => ({ name: 'cun_w_openapi', label: 'CUN openapi', type: 'api', provider: 'openapi',
213223
providerConfig: { spec: `https://api.vendor.example.com/openapi.json?token=${PLACEHOLDERS.urlQuery}` },
214224
auth: { type: 'bearer', credentialRef: REF } }), 'providerConfig.spec'],
225+
['`token` in a URL inside an inline openapi `providerConfig.spec` document', 'cun_w_inline_spec',
226+
() => ({ name: 'cun_w_inline_spec', label: 'CUN inline spec', type: 'api', provider: 'openapi',
227+
providerConfig: { spec: inlineSpec(`https://api.vendor.example.com/v1?token=${PLACEHOLDERS.urlQuery}`) },
228+
auth: { type: 'bearer', credentialRef: REF } }), 'providerConfig.spec.servers.0.url'],
215229
['a userinfo password in `auth.tokenUrl`', 'cun_w_token_url',
216230
() => oauth2('cun_w_token_url', { tokenUrl: `https://c:${PLACEHOLDERS.authEndpoint}@auth.vendor.example.com/token` }), 'auth.tokenUrl'],
217231
['a userinfo in `auth.authorizationUrl`', 'cun_w_authz_url',
@@ -255,6 +269,18 @@ describe('connector metadata doors: an authored connector keeps no credential in
255269
expect(received[received.length - 1]).toMatch(/^\/v1\/probe/);
256270
});
257271

272+
it('an inline openapi document whose URLs carry no credential part saves as written', async () => {
273+
// Saved disabled: the pin is the door's answer, not a materialization.
274+
const body = {
275+
name: 'cun_inline_spec_clean', label: 'CUN inline spec (clean)', type: 'api', provider: 'openapi', enabled: false,
276+
providerConfig: { spec: inlineSpec('https://api.vendor.example.com/v1?region=eu') },
277+
auth: { type: 'bearer', credentialRef: REF },
278+
};
279+
const res = await stack.apiAs(admin, 'PUT', '/meta/connector/cun_inline_spec_clean', body);
280+
expect(res.status, await res.clone().text()).toBe(200);
281+
expect(bodyOf((await stored('cun_inline_spec_clean'))[0]).providerConfig).toEqual(body.providerConfig);
282+
});
283+
258284
it('a descriptor with declared action keys, and an oauth2 instance with credential-free endpoints, save', async () => {
259285
const desc = await stack.apiAs(admin, 'PUT', `/meta/connector/${DESCRIPTOR}`, descriptor);
260286
expect(desc.status, await desc.clone().text()).toBe(200);

‎packages/spec/scripts/build-schemas-check-mode.deleted-baseline.test.ts‎

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ const DELETED_UNREACHABLE = 'api/SessionResponse:zzOverCollected4650';
9595

9696
/** #17356's pin. A def whose ONLY root is an UNREGISTERED KIND — `connector`,
9797
* bound in `UNREGISTERED_KIND_SCHEMAS` by #6245 and deliberately absent from
98-
* `listMetadataTypeSchemaTypes()`. `integration/RetryConfig` sits two hops
99-
* from that root (`connector.retryConfig`, unwrapped once through `optional`),
100-
* and `stack.connectors[]` / `PUT /api/v1/meta/connector/:name` both parse a
101-
* real metadata document through it. (The def was `integration/DataSyncConfig`,
102-
* the measured specimen below, until protocol 18 retired it whole with
103-
* `connector.syncConfig` — ADR-0049; `RetryConfig` is the connector's other
104-
* open block on the same root at the same depth.)
98+
* `listMetadataTypeSchemaTypes()`. `integration/DeclarativeConnectorEntryRetryConfig`
99+
* sits two hops from that root (`connector.retryConfig`, unwrapped once through
100+
* `optional`), and `stack.connectors[]` / `PUT /api/v1/meta/connector/:name`
101+
* both parse a real metadata document through it. (The def was
102+
* `integration/DataSyncConfig`, the measured specimen below, until protocol 18
103+
* retired it whole with `connector.syncConfig` — ADR-0049; then
104+
* `integration/RetryConfig`, the connector's other block on the same root at
105+
* the same depth, until the authored entry closed that block through its own
106+
* exported twin: the open `RetryConfig` is reached by no metadata root since,
107+
* and its twin is the def a metadata document's `retryConfig` is parsed
108+
* against.)
105109
*
106110
* Until #17356 the gate built its roots from `listMetadataTypeSchemaTypes()`
107111
* alone, so this def read `null` and check (c) proof 2 WAIVED a bare deletion
@@ -115,7 +119,7 @@ const DELETED_UNREACHABLE = 'api/SessionResponse:zzOverCollected4650';
115119
* ever sees a key the build STOPPED emitting, and the def is judged by its
116120
* DEF half (`key.slice(0, key.indexOf(':'))`), so a synthetic leaf under the
117121
* real def runs the identical code path as the real deletion did. */
118-
const DELETED_VIA_UNREGISTERED_KIND_DEF = 'integration/RetryConfig';
122+
const DELETED_VIA_UNREGISTERED_KIND_DEF = 'integration/DeclarativeConnectorEntryRetryConfig';
119123

120124
const DELETED_VIA_UNREGISTERED_KIND = `${DELETED_VIA_UNREGISTERED_KIND_DEF}:zzOnlyRootIsAnUnregisteredKind17356`;
121125

@@ -166,16 +170,18 @@ const DELETED_GUIDANCE_UNNAMED = `${GUIDANCE_ROUTE_DEF}:zzNotPrescribed18301`;
166170

167171
/** The SHAPE of a maintainer ruling (2026-09-10, #16320) that retired a key while
168172
* DELIBERATELY withholding the tombstone: a bare deletion from a reachable def
169-
* that is a plain `z.object`, not a `strictObject`, so nothing declares a
170-
* prescription for it and proof 4 has no route to it — which is what keeps this
171-
* card an ADDED proof rather than a reversal of that ruling. The ruling's own
172-
* key, `integration/DataSyncConfig:schedule`, was this fixture until protocol 18
173-
* retired `DataSyncConfig` whole (ADR-0049), after which a line under it rides
174-
* the vanished-def proof instead and would pin nothing here. So the fixture
175-
* keeps the ruling's shape — the same `schedule` leaf on the connector's other
176-
* open block, same root, same depth. If someone later writes a `guidance` entry
177-
* that reaches it, this assertion flips, and it SHOULD. */
178-
const WITHHELD_TOMBSTONE = 'integration/RetryConfig:schedule';
173+
* where nothing declares a prescription for the key, so proof 4 has no route to
174+
* it — which is what keeps this card an ADDED proof rather than a reversal of
175+
* that ruling. The ruling's own key, `integration/DataSyncConfig:schedule`, was
176+
* this fixture until protocol 18 retired `DataSyncConfig` whole (ADR-0049),
177+
* after which a line under it rides the vanished-def proof instead and would pin
178+
* nothing here. So the fixture keeps the ruling's shape — the same `schedule`
179+
* leaf on the connector's other block, same root, same depth: the open
180+
* `integration/RetryConfig` until the authored entry closed that block, and its
181+
* exported closed twin since, whose `guidance` names credential-shaped keys and
182+
* not `schedule`. If someone later writes a `guidance` entry that reaches it,
183+
* this assertion flips, and it SHOULD. */
184+
const WITHHELD_TOMBSTONE = 'integration/DeclarativeConnectorEntryRetryConfig:schedule';
179185

180186
const DELETED_SHARED_TWIN = `${SHARED_TWIN_DEF}:${TWIN_LEAF}`;
181187

@@ -491,7 +497,8 @@ describe('build-schemas.ts — deleted baseline lines must prove themselves (#46
491497
// `listMetadataTypeSchemaTypes()`, which per #6245 deliberately does not
492498
// enumerate `UNREGISTERED_KIND_SCHEMAS`. `connector` lives there, so the
493499
// BFS never started from it, `integration/DataSyncConfig` (then this
494-
// fixture's def; `integration/RetryConfig` since protocol 18) read `null`,
500+
// fixture's def; then `integration/RetryConfig`, now the entry's closed
501+
// retry twin `integration/DeclarativeConnectorEntryRetryConfig`) read `null`,
495502
// and a bare deletion of one of its baseline lines was waived as
496503
// over-collection — for a def `stack.connectors[]` parses on every boot.
497504
// The gate now enumerates its own reachability root union; the KIND

‎packages/spec/src/integration/connector-entry-nested-keys.test.ts‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { ZodError } from 'zod';
1818
import {
1919
ConnectorActionSchema,
2020
ConnectorSchema,
21+
DeclarativeConnectorEntryActionSchema,
22+
DeclarativeConnectorEntryRetryConfigSchema,
2123
DeclarativeConnectorEntrySchema,
2224
RetryConfigSchema,
2325
defineConnector,
@@ -106,11 +108,49 @@ describe('an authored connector entry refuses a key its nested shapes do not dec
106108
expect(ConnectorActionSchema.safeParse({ ...ACTION, token: PLACEHOLDER }).success).toBe(true);
107109
});
108110

109-
it('the closed nested shapes declare exactly the open shapes\' keys', () => {
111+
describe('the prescription each refusal carries', () => {
112+
const CREDENTIAL = ['connector metadata never holds a credential', 'auth: { type, credentialRef }'];
113+
const BINDING = ['an action carries no execution binding (ADR-0097 §5)', 'derives its actions from the upstream'];
114+
115+
it.each(['secret', 'token', 'apiKey', 'key', 'password', 'credentials', 'credentialRef'])(
116+
'a credential-shaped `%s` inside `retryConfig` meets the entry\'s credential prescription',
117+
(name) => {
118+
const { located, message } = refusal({ ...INSTANCE, retryConfig: { ...RETRY, [name]: PLACEHOLDER } });
119+
expect(located).toEqual(['unrecognized_keys', 'retryConfig', [name]]);
120+
for (const needle of CREDENTIAL) expect(message).toContain(needle);
121+
expect(message).not.toContain(PLACEHOLDER);
122+
},
123+
);
124+
125+
it.each(['secret', 'token', 'apiKey', 'password', 'credentialRef'])(
126+
'a credential-shaped `%s` inside an `actions` element meets the entry\'s credential prescription',
127+
(name) => {
128+
const { located, message } = refusal({ ...DESCRIPTOR, actions: [{ ...ACTION, [name]: PLACEHOLDER }] });
129+
expect(located).toEqual(['unrecognized_keys', 'actions.0', [name]]);
130+
for (const needle of CREDENTIAL) expect(message).toContain(needle);
131+
expect(message).not.toContain(PLACEHOLDER);
132+
},
133+
);
134+
135+
it.each(['method', 'path', 'url'])('an execution binding `%s` on an action meets ADR-0097 §5\'s prescription', (name) => {
136+
const { located, message } = refusal({ ...DESCRIPTOR, actions: [{ ...ACTION, [name]: 'x' }] });
137+
expect(located).toEqual(['unrecognized_keys', 'actions.0', [name]]);
138+
for (const needle of BINDING) expect(message).toContain(needle);
139+
});
140+
141+
it('CONTROL: an action\'s own `key` is its declared machine name, never a misplaced credential', () => {
142+
expect(DeclarativeConnectorEntrySchema.safeParse({ ...DESCRIPTOR, actions: [ACTION] }).success).toBe(true);
143+
});
144+
});
145+
146+
it('the closed nested shapes are the published twins, declaring exactly the open shapes\' keys', () => {
110147
const entry = DeclarativeConnectorEntrySchema.safeParse({ ...INSTANCE, retryConfig: RETRY });
111148
expect(entry.success).toBe(true);
112-
const retryKeys = Object.keys((RetryConfigSchema as unknown as { shape: Record<string, unknown> }).shape).sort();
113-
const actionKeys = Object.keys((ConnectorActionSchema as unknown as { shape: Record<string, unknown> }).shape).sort();
149+
const keysOf = (schema: unknown) => Object.keys((schema as { shape: Record<string, unknown> }).shape).sort();
150+
const retryKeys = keysOf(RetryConfigSchema);
151+
const actionKeys = keysOf(ConnectorActionSchema);
152+
expect(keysOf(DeclarativeConnectorEntryRetryConfigSchema)).toEqual(retryKeys);
153+
expect(keysOf(DeclarativeConnectorEntryActionSchema)).toEqual(actionKeys);
114154
// Every declared key is accepted by the closed entry …
115155
const everyRetry = Object.fromEntries(retryKeys.map((k) => [k, (RetryConfigSchema.parse({}) as Record<string, unknown>)[k]]));
116156
expect(DeclarativeConnectorEntrySchema.safeParse({ ...INSTANCE, retryConfig: everyRetry }).success).toBe(true);

0 commit comments

Comments
 (0)