Skip to content

Commit 8dea377

Browse files
committed
test(metadata-protocol,objectql): pin the seedApplied.landed projection directly and the empty-seed receipt; state the ids' record order
- seed-applied-landed.test.ts pins seedAppliedLanded without an engine: junk entries skipped, [] for no results, exactly 200 vs 201 through the cap (per list), and the cross-dataset inserted-then-matched merge. - A seed with `records: []` publishes one landed entry with two empty lists, as the description promises. - SeedAppliedIdListSchema.ids says the loader's record order (datasets in load order, records as authored), not "first-landed first". Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzi6PCniByMTFP6RQ6P
1 parent c438aed commit 8dea377

6 files changed

Lines changed: 136 additions & 8 deletions

File tree

‎.changeset/30348-seed-receipt-landed-ids.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ feat(spec,metadata-protocol): the publish receipt's `seedApplied.landed` names t
99
Clause-②: yes (widening)
1010
Metadata-protocol: added
1111

12-
- **`@objectstack/spec`: `seedApplied.landed`** on both publish responses (`PublishMetaItemResponseSchema`, `PublishPackageDraftsResponseSchema`), one shared schema `SeedAppliedLandedSchema`: per object, `inserted` (the rows this publish created) and `matched` (pre-existing rows a seed record's key matched: updated, left as they were, or refused an update), each a `SeedAppliedIdListSchema` `{ ids, total, truncated }`. `ids` carries at most `SEED_APPLIED_LANDED_IDS_CAP` (200) ids, first landed first; past it `truncated` is `true` and `total` is the uncut count. Absent `landed` means "not reported" (a load that threw, or a producer that reports no ids), never "nothing landed". Only `inserted` names rows the seed created: a `matched` row may be a customer's own record that shares the seed's natural key, and under `ignore` (the default) such a row is matched without being written.
12+
- **`@objectstack/spec`: `seedApplied.landed`** on both publish responses (`PublishMetaItemResponseSchema`, `PublishPackageDraftsResponseSchema`), one shared schema `SeedAppliedLandedSchema`: per object, `inserted` (the rows this publish created) and `matched` (pre-existing rows a seed record's key matched: updated, left as they were, or refused an update), each a `SeedAppliedIdListSchema` `{ ids, total, truncated }`. `ids` carries at most `SEED_APPLIED_LANDED_IDS_CAP` (200) ids, in the loader's record order (datasets in load order, records as authored); past it `truncated` is `true` and `total` is the uncut count. Absent `landed` means "not reported" (a load that threw, or a producer that reports no ids), never "nothing landed". Only `inserted` names rows the seed created: a `matched` row may be a customer's own record that shares the seed's natural key, and under `ignore` (the default) such a row is matched without being written.
1313
- **`@objectstack/spec`: `SeedLoadResult.insertedIds`**, the ids among `landedIds` whose row the load created. Per load: a row an earlier load inserted is matched on a replay, so a reader tracking a seed's rows across publishes accumulates `insertedIds` over every load. `landedIds`' TSDoc now says what each seed mode puts in it.
1414
- **`@objectstack/metadata-protocol`**: `applySeedBodies` returns `landed`, so `publishPackageDrafts` and `publishMetaItem` both carry it; the loader records which landed rows it inserted. `seedAppliedLanded(results)` is exported, the one projection both receipt producers fold the loader's ids through.
1515
- **`@objectstack/runtime`**: the package-publish door's fallback seed apply (for protocols that do not self-apply) reports the same `landed`.

‎content/docs/references/api/protocol.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,7 @@ Answer to a device registration: the device id the client keeps
29752975

29762976
| Property | Type | Required | Description |
29772977
| :--- | :--- | :--- | :--- |
2978-
| **ids** | `string[]` | ✅ | Row ids, first-landed first, each once — at most `SEED_APPLIED_LANDED_IDS_CAP` (200). |
2978+
| **ids** | `string[]` | ✅ | Row ids in the loader's record order (datasets in load order, records as authored), each once — at most `SEED_APPLIED_LANDED_IDS_CAP` (200). |
29792979
| **total** | `integer` | ✅ | How many ids the list holds before the cap. Equals `ids.length` unless `truncated`. |
29802980
| **truncated** | `boolean` | ✅ | True when the cap cut the list: `total` ids exist and only the first `ids.length` are carried. |
29812981

@@ -2996,15 +2996,15 @@ Answer to a device registration: the device id the client keeps
29962996

29972997
| Property | Type | Required | Description |
29982998
| :--- | :--- | :--- | :--- |
2999-
| **ids** | `string[]` | ✅ | Row ids, first-landed first, each once — at most `SEED_APPLIED_LANDED_IDS_CAP` (200). |
2999+
| **ids** | `string[]` | ✅ | Row ids in the loader's record order (datasets in load order, records as authored), each once — at most `SEED_APPLIED_LANDED_IDS_CAP` (200). |
30003000
| **total** | `integer` | ✅ | How many ids the list holds before the cap. Equals `ids.length` unless `truncated`. |
30013001
| **truncated** | `boolean` | ✅ | True when the cap cut the list: `total` ids exist and only the first `ids.length` are carried. |
30023002

30033003
### Nested Shape: `SeedAppliedLanded.matched`
30043004

30053005
| Property | Type | Required | Description |
30063006
| :--- | :--- | :--- | :--- |
3007-
| **ids** | `string[]` | ✅ | Row ids, first-landed first, each once — at most `SEED_APPLIED_LANDED_IDS_CAP` (200). |
3007+
| **ids** | `string[]` | ✅ | Row ids in the loader's record order (datasets in load order, records as authored), each once — at most `SEED_APPLIED_LANDED_IDS_CAP` (200). |
30083008
| **total** | `integer` | ✅ | How many ids the list holds before the cap. Equals `ids.length` unless `truncated`. |
30093009
| **truncated** | `boolean` | ✅ | True when the cap cut the list: `total` ids exist and only the first `ids.length` are carried. |
30103010

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
import { describe, it, expect } from 'vitest';
4+
import { SEED_APPLIED_LANDED_IDS_CAP, SeedAppliedLandedSchema } from '@objectstack/spec/api';
5+
import { seedAppliedLanded, type SeedLandingResult } from './seed-applied-landed.js';
6+
7+
/**
8+
* [#30348] `seedAppliedLanded` — the one projection both `seedApplied`
9+
* producers fold the loader's per-dataset results through, pinned on its own,
10+
* without an engine: the junk it skips, the empty answer, the cap boundary, and
11+
* the cross-dataset merge that keeps a row this batch created out of
12+
* `matched`. The publish doors' pins (`@objectstack/objectql`'s
13+
* `publish-seed-receipt-landed-ids.test.ts`) read the same answer off a real
14+
* engine; these pin the cases a door cannot stage cleanly.
15+
*/
16+
17+
const ids = (prefix: string, n: number) => Array.from({ length: n }, (_, i) => `${prefix}${i}`);
18+
const list = (xs: string[], total = xs.length) => ({ ids: xs, total, truncated: total > xs.length });
19+
const NONE = list([]);
20+
21+
describe('seedAppliedLanded (#30348)', () => {
22+
it('no results: an empty list, never undefined', () => {
23+
expect(seedAppliedLanded([])).toEqual([]);
24+
});
25+
26+
it('skips junk entries — a null, a missing or non-string object — and keeps the real ones', () => {
27+
const junk = [
28+
null,
29+
undefined,
30+
{},
31+
{ object: 42, landedIds: ['x'] },
32+
{ landedIds: ['y'], insertedIds: ['y'] },
33+
{ object: 'account', landedIds: ['a1'], insertedIds: ['a1'] },
34+
] as unknown as SeedLandingResult[];
35+
36+
expect(seedAppliedLanded(junk)).toEqual([{ object: 'account', inserted: list(['a1']), matched: NONE }]);
37+
});
38+
39+
it('a dataset that landed nothing still reports its object, with two empty lists', () => {
40+
expect(seedAppliedLanded([{ object: 'account', landedIds: [], insertedIds: [] }]))
41+
.toEqual([{ object: 'account', inserted: NONE, matched: NONE }]);
42+
// A result predating `insertedIds` (both keys absent) reads the same.
43+
expect(seedAppliedLanded([{ object: 'account' }])).toEqual([{ object: 'account', inserted: NONE, matched: NONE }]);
44+
});
45+
46+
it('splits one dataset: inserted ids under `inserted`, every other landed id under `matched`', () => {
47+
expect(seedAppliedLanded([{ object: 'account', landedIds: ['c9', 'a1', 'a2'], insertedIds: ['a1', 'a2'] }]))
48+
.toEqual([{ object: 'account', inserted: list(['a1', 'a2']), matched: list(['c9']) }]);
49+
});
50+
51+
it('the cap: exactly 200 is carried whole and not truncated; 201 carries the first 200 and says so', () => {
52+
expect(SEED_APPLIED_LANDED_IDS_CAP).toBe(200);
53+
const exact = ids('r', SEED_APPLIED_LANDED_IDS_CAP);
54+
const over = ids('r', SEED_APPLIED_LANDED_IDS_CAP + 1);
55+
56+
const [atCap] = seedAppliedLanded([{ object: 'account', landedIds: exact, insertedIds: exact }]);
57+
expect(atCap.inserted).toEqual({ ids: exact, total: 200, truncated: false });
58+
59+
const [cut] = seedAppliedLanded([{ object: 'account', landedIds: over, insertedIds: [] }]);
60+
expect(cut.matched).toEqual({ ids: over.slice(0, 200), total: 201, truncated: true });
61+
expect(cut.inserted).toEqual(NONE);
62+
63+
// What the projection emits is what the spec schema carries.
64+
expect(SeedAppliedLandedSchema.parse(cut)).toEqual(cut);
65+
expect(SeedAppliedLandedSchema.parse(atCap)).toEqual(atCap);
66+
});
67+
68+
it('the cap is per list: 201 inserted and 201 matched cut each list on its own', () => {
69+
const ins = ids('i', 201);
70+
const mat = ids('m', 201);
71+
const [entry] = seedAppliedLanded([{ object: 'account', landedIds: [...ins, ...mat], insertedIds: ins }]);
72+
expect(entry.inserted).toEqual({ ids: ins.slice(0, 200), total: 201, truncated: true });
73+
expect(entry.matched).toEqual({ ids: mat.slice(0, 200), total: 201, truncated: true });
74+
});
75+
76+
it('two datasets of one object: a row the first inserted and the second matched stays `inserted` only', () => {
77+
const results: SeedLandingResult[] = [
78+
{ object: 'account', landedIds: ['a1', 'a2'], insertedIds: ['a1', 'a2'] },
79+
// Its key matched `a1`, the row the first dataset just created, and a customer row `c9`.
80+
{ object: 'account', landedIds: ['a1', 'c9', 'a3'], insertedIds: ['a3'] },
81+
];
82+
83+
expect(seedAppliedLanded(results)).toEqual([
84+
{ object: 'account', inserted: list(['a1', 'a2', 'a3']), matched: list(['c9']) },
85+
]);
86+
});
87+
88+
it('a row an EARLIER dataset matched and a later one inserted is `inserted`, never both', () => {
89+
// The rule is order-free: membership in any dataset's `insertedIds` decides.
90+
const [entry] = seedAppliedLanded([
91+
{ object: 'account', landedIds: ['x'], insertedIds: [] },
92+
{ object: 'account', landedIds: ['x'], insertedIds: ['x'] },
93+
]);
94+
expect(entry).toEqual({ object: 'account', inserted: list(['x']), matched: NONE });
95+
});
96+
97+
it('objects keep the order they first loaded in; ids dedupe, first occurrence kept', () => {
98+
const out = seedAppliedLanded([
99+
{ object: 'contact', landedIds: ['k1'], insertedIds: ['k1'] },
100+
{ object: 'account', landedIds: ['a1', 'a1'], insertedIds: ['a1', 'a1'] },
101+
{ object: 'contact', landedIds: ['k2', 'k1'], insertedIds: ['k2'] },
102+
]);
103+
expect(out.map((e) => e.object)).toEqual(['contact', 'account']);
104+
expect(out[0]).toEqual({ object: 'contact', inserted: list(['k1', 'k2']), matched: NONE });
105+
expect(out[1]).toEqual({ object: 'account', inserted: list(['a1']), matched: NONE });
106+
});
107+
});

‎packages/metadata-protocol/src/seed-applied-landed.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ function cappedList(ids: readonly string[]): SeedAppliedIdListParsed {
3737

3838
/**
3939
* Fold the loader's per-dataset results into one entry per object, in the
40-
* order the objects first loaded. Several datasets of one object merge; an
40+
* order the objects first loaded; ids keep the loader's record order (dataset
41+
* order, then each dataset's own `landedIds` / `insertedIds` order), first
42+
* occurrence kept. Several datasets of one object merge; an
4143
* id is listed once; an id some dataset of the object INSERTED is never also
4244
* listed as matched (a second dataset's key matching the row the first one
4345
* just created does not make it a customer's row). An object whose datasets

‎packages/objectql/src/publish-seed-receipt-landed-ids.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,20 @@ describe('seedApplied.landed — the rows a published seed landed on (#30348)',
257257
expect(res.seedApplied.landed[0].matched).toEqual(NONE);
258258
});
259259

260+
it('a seed with no records: the loader ran and reported, so one entry with two empty lists', async () => {
261+
const { p, engine } = await makeProtocol();
262+
await stage(p, [{ type: 'seed', name: 'l_empty', item: seed([]) }]);
263+
264+
const res: any = await p.publishPackageDrafts({ packageId: PKG });
265+
266+
expect(await rowsOf(engine)).toEqual([]);
267+
expect(res.seedApplied.success).toBe(true);
268+
expect(res.seedApplied.inserted).toBe(0);
269+
// Reported-and-empty, which is a different answer from an absent key.
270+
expect(res.seedApplied.landed).toEqual([{ object: ITEM, inserted: NONE, matched: NONE }]);
271+
expect(PublishPackageDraftsResponseSchema.parse(res).seedApplied?.landed).toEqual(res.seedApplied.landed);
272+
});
273+
260274
it('a publish with no seed carries no `seedApplied` at all, so no `landed`', async () => {
261275
const { p } = await makeProtocol();
262276
await stage(p, [{ type: 'object', name: ITEM, item: {

‎packages/spec/src/api/protocol.zod.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,14 +1424,19 @@ export const SEED_APPLIED_LANDED_IDS_CAP = 200;
14241424
/**
14251425
* [#30348] One capped list of row ids on a `seedApplied` receipt.
14261426
*
1427-
* `ids` is the first {@link SEED_APPLIED_LANDED_IDS_CAP} ids in the order the
1428-
* loader landed them, each once; `total` is how many ids the list holds before
1427+
* `ids` is the first {@link SEED_APPLIED_LANDED_IDS_CAP} ids in the loader's
1428+
* record order, each once (its first occurrence): datasets in the order the
1429+
* loader ran them, and within a dataset the order its records are authored
1430+
* (`SeedLoadResult.landedIds` / `insertedIds`). It is NOT the order the writes
1431+
* completed, since the loader buffers inserts and flushes them after the
1432+
* skips that follow them. `total` is how many ids the list holds before
14291433
* the cap, and `truncated` is `true` exactly when `total` exceeds `ids.length`
14301434
* — the receipt states a cut instead of making a reader count.
14311435
*/
14321436
export const SeedAppliedIdListSchema = lazySchema(() => z.object({
14331437
ids: z.array(z.string()).max(SEED_APPLIED_LANDED_IDS_CAP).describe(
1434-
'Row ids, first-landed first, each once — at most `SEED_APPLIED_LANDED_IDS_CAP` (200).',
1438+
'Row ids in the loader\'s record order (datasets in load order, records as authored), each once '
1439+
+ '— at most `SEED_APPLIED_LANDED_IDS_CAP` (200).',
14351440
),
14361441
total: z.number().int().min(0).describe(
14371442
'How many ids the list holds before the cap. Equals `ids.length` unless `truncated`.',

0 commit comments

Comments
 (0)