Skip to content

Commit 986fb43

Browse files
committed
fix(metadata-protocol): report a seed column policy naming no column at error; llms.txt schema count
A columns key that names no column of the object leaves the column it was meant for at always, so every replay overwrites a job's write while the load reports success: the AGENTS.md degradation class that logs at error. The rows still load. The externalId create-only test now pins that both rows were updated, and packages/spec/llms.txt counts the new data schema module. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HE4VY52U3L5Bfzz51dsFv
1 parent ec70e1a commit 986fb43

6 files changed

Lines changed: 38 additions & 21 deletions

File tree

‎.changeset/25761-seed-column-apply-on.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ defineSeed(Instalment, {
2727
- **`applyOn: 'create'`** writes the column when the seed creates the row and leaves it out of every write to a row the seed matched by its `externalId`: an `upsert` replay over an existing row, and every row of an `update` dataset. The matched row keeps the value it holds, while the `always` columns are refreshed. A row whose only differences are create-only columns is not written at all. A create-only reference column on a matched row is not resolved and not deferred to pass 2, so nothing later in the load writes it back. A column of the `externalId` is the key the row was matched by and stays in its update. `insert`, `ignore` and `replace` never update a matched row, so nothing changes on those modes.
2828
- **`applyOn: 'always'`** (the default, and every column without a `columns` entry) is the behaviour before this change.
2929
- The values, the default and the meaning are those of the import door's `FieldMappingEntry.applyOn`. Both doors now read one enum, exported as `ColumnApplyOnSchema` from `@objectstack/spec/data`. `SeedColumnSchema` (with `SeedColumn` / `SeedColumnParsed`) is the per-column shape.
30-
- A `columns` key must name a column the object has: a declared field, or a system column the platform injects on it such as `owner_id`. `defineSeed` refuses one that does not when it runs (and at compile time for an object literal), naming the key with a near miss. The seed loader warns once per dataset when a seed that did not come through `defineSeed` names one.
30+
- A `columns` key must name a column the object has: a declared field, or a system column the platform injects on it such as `owner_id`. `defineSeed` refuses one that does not when it runs (and at compile time for an object literal), naming the key with a near miss. The seed loader logs an `error` naming the column, once per dataset, whenever it loads a seed that names one, since a stored seed never passes through `defineSeed`. The rows still load.
3131
- `SeedSchema` refuses an unknown key on a column (`unrecognized_keys`), and a dataset-level `applyOn` is pointed at `columns`.
3232

3333
`@objectstack/skills` only regenerates its schema reference indexes, which now list `SeedColumnSchema` and `ColumnApplyOnSchema`.

‎content/docs/data-modeling/seed-data.mdx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ defineSeed(Instalment, {
187187
`applyOn` takes the same values, with the same default and meaning, as an import
188188
mapping entry's [`applyOn`](/docs/data-modeling/import-mappings). A `columns` key
189189
must name a field of the object (or a system column the platform injects on it,
190-
such as `owner_id`): `defineSeed` refuses one that does not, and the loader warns
191-
when a stored seed names one.
190+
such as `owner_id`): `defineSeed` refuses one that does not, and the loader logs
191+
an error naming the column whenever it loads a seed that names one, since a
192+
stored seed never passes through `defineSeed`.
192193

193194
---
194195

‎packages/metadata-protocol/src/seed-loader-replay.test.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ describe('seed replay — a column declared applyOn: create is written on first
985985

986986
expect(replay.result.summary.totalInserted).toBe(0);
987987
expect(store[INSTALMENT.name]).toHaveLength(2);
988+
expect(updatesOf(engine, INSTALMENT)).toHaveLength(2);
988989
for (const data of updatesOf(engine, INSTALMENT)) {
989990
expect(Object.keys(data).sort()).toEqual(['amount', 'id', 'name']);
990991
}
@@ -1000,7 +1001,7 @@ describe('seed replay — a column declared applyOn: create is written on first
10001001
expect(engine.insert).not.toHaveBeenCalled();
10011002
});
10021003

1003-
it('a policy naming no column of the object is reported once, by name, and governs nothing', async () => {
1004+
it('a policy naming no column of the object is reported once, by name, at error, and governs nothing', async () => {
10041005
const { engine, store } = createFaithfulEngine();
10051006
const logger = createLogger();
10061007
const misspelt = { stauts: { applyOn: 'create' } };
@@ -1009,16 +1010,22 @@ describe('seed replay — a column declared applyOn: create is written on first
10091010

10101011
await load(engine, INSTALMENT, { columns: misspelt, logger });
10111012

1012-
const warnings = logger.warn.mock.calls.filter(([message]: any[]) => String(message).includes('stauts'));
1013-
expect(warnings).toHaveLength(2); // once per dataset per load
1014-
expect(warnings[0][1]).toMatchObject({ object: INSTALMENT.name, undeclaredColumns: ['stauts'] });
1013+
// `error`, not `warn`: the column it was meant for is overwritten on every
1014+
// replay while the load reports success, the AGENTS.md degradation class.
1015+
const reports = logger.error.mock.calls.filter(([message]: any[]) => String(message).includes('stauts'));
1016+
expect(reports).toHaveLength(2); // once per dataset per load
1017+
expect(reports[0][2]).toMatchObject({ object: INSTALMENT.name, undeclaredColumns: ['stauts'] });
1018+
expect(logger.warn.mock.calls.filter(([message]: any[]) => String(message).includes('stauts'))).toEqual([]);
10151019
expect(rowOf(store, INSTALMENT, 'inst-1').status).toBe('pending');
10161020
});
10171021

1018-
it('a policy on an injected system column is a column of the object: no warning', async () => {
1022+
it('a policy on an injected system column is a column of the object: no report', async () => {
10191023
const { engine } = createFaithfulEngine();
10201024
const logger = createLogger();
10211025
await load(engine, INSTALMENT, { columns: { owner_id: { applyOn: 'create' } }, logger });
1022-
expect(logger.warn.mock.calls.filter(([, meta]: any[]) => meta?.undeclaredColumns)).toEqual([]);
1026+
expect(
1027+
[...logger.warn.mock.calls, ...logger.error.mock.calls].filter((call: any[]) =>
1028+
call.some((arg) => (arg as { undeclaredColumns?: unknown } | undefined)?.undeclaredColumns)),
1029+
).toEqual([]);
10231030
});
10241031
});

‎packages/metadata-protocol/src/seed-loader.ts‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,11 +3228,17 @@ export class SeedLoaderService implements ISeedLoaderService {
32283228
* the named column, so the engine never refuses it the way it refuses an
32293229
* unknown record key. The column it was meant for (a misspelt `status`)
32303230
* keeps `always`, and every replay re-asserts it. `defineSeed` refuses the
3231-
* key when it runs; this is the same check for a seed that did not come
3232-
* through it (stored `seed` metadata, a package body). Judged against the
3233-
* set `defineSeed` uses — the declared fields plus the system columns the
3234-
* platform injects on this object — and only when the definition resolved
3235-
* with a field map: no opinion without one.
3231+
* key when it runs; this is the same check at load, where a stored `seed`
3232+
* or a package body arrives without passing through `defineSeed`. Judged
3233+
* against the set `defineSeed` uses — the declared fields plus the system
3234+
* columns the platform injects on this object — and only when the
3235+
* definition resolved with a field map: no opinion without one.
3236+
*
3237+
* `error`, not `warn` (AGENTS.md "Degradation log levels"): the load looks
3238+
* normal and reports success while a job's write to the column the policy
3239+
* was meant for is overwritten on every replay. The rows themselves are
3240+
* valid, so they still load: refusing them would turn a policy typo into
3241+
* missing seed data.
32363242
*/
32373243
private warnOnUndeclaredSeedColumns(dataset: Seed, definition: unknown): void {
32383244
const columns = Object.keys(dataset.columns ?? {});
@@ -3242,11 +3248,13 @@ export class SeedLoaderService implements ISeedLoaderService {
32423248
const known = new Set<string>([...Object.keys(fields), ...resolveInjectedSystemColumns(definition).names]);
32433249
const undeclared = columns.filter((column) => !known.has(column));
32443250
if (undeclared.length === 0) return;
3245-
this.logger.warn(
3251+
this.logger.error(
32463252
`[SeedLoader] The ${dataset.object} seed declares a write policy for ${undeclared.map((c) => `\`${c}\``).join(', ')}, ` +
32473253
`which ${undeclared.length === 1 ? 'is not a column' : 'are not columns'} of ${dataset.object}: the policy governs ` +
3248-
`nothing, and a column it was meant for keeps \`applyOn: 'always'\`, re-asserted on every replay. Name a ` +
3249-
`field ${dataset.object} declares, or a system column the platform injects on it, as the \`columns\` key.`,
3254+
`nothing, and a column it was meant for keeps \`applyOn: 'always'\`, so every replay overwrites what a job ` +
3255+
`wrote to it while this load still reports success. Name a field ${dataset.object} declares, or a system ` +
3256+
`column the platform injects on it, as the \`columns\` key.`,
3257+
undefined,
32503258
{ object: dataset.object, undeclaredColumns: undeclared },
32513259
);
32523260
}

‎packages/spec/llms.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const query = {
7777

7878
---
7979

80-
## 3. Schema Inventory by Domain (206 schemas)
80+
## 3. Schema Inventory by Domain (207 schemas)
8181

8282
Counted as `*.zod.ts` modules under `packages/spec/src/<domain>/` — the sources
8383
that ship in this tarball (`files` includes `src/**/*.zod.ts`), so every number
@@ -87,7 +87,7 @@ here is verifiable from the installed package.
8787
|--------|-------|-------------|
8888
| system | 36 | Auth, Cache, Dev Login, Email / SMS Config, Encryption, Fate Supplement (organization ownership), HTTP Server, License, Logging, Metrics |
8989
| kernel | 31 | Plugin, Manifest, Events (6 sub-modules), Feature, Context, Package Registry |
90-
| data | 30 | Object, Field, Picklist, Query, Filter, Driver (SQL/NoSQL/Memory/Mongo/Postgres), Cube |
90+
| data | 31 | Object, Field, Picklist, Query, Filter, Driver (SQL/NoSQL/Memory/Mongo/Postgres), Cube |
9191
| api | 31 | Endpoint, REST Server, Discovery, OData, Batch, WebSocket, Response Envelope, Package Lifecycle, Package API (assembled stage) |
9292
| ui | 18 | View, App, Action, Dashboard, Page, Chart, Component, Animation |
9393
| automation | 14 | Flow, Approval, BPMN Interop, Control Flow, Webhook, Schedule Organization |

‎packages/spec/src/data/seed.zod.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ export const SeedSchema = lazySchema(() => strictObject({
154154
*
155155
* Each key must name a column the target object has — a declared field or a
156156
* system column the platform injects on it. `defineSeed` refuses one that
157-
* does not when it runs, and the loader warns, naming the column, when it
158-
* loads a dataset whose map names one.
157+
* does not when it runs, and the loader logs an error naming the column
158+
* whenever it loads a dataset whose map names one (a stored seed never
159+
* passes through `defineSeed`).
159160
*/
160161
columns: z.record(z.string(), SeedColumnSchema).optional()
161162
.describe(

0 commit comments

Comments
 (0)