Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/35480-seeds-load-and-save-refusals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@objectstack/skills': patch
---

docs(skills): the data skill says a seed record with a blank key field is refused at load, and a saved seed naming an unknown object is refused 422

Clause-②: no
Metadata-protocol: none

objectstack-data's `references/seeds.md`:

- "`externalId` selection" says every record carries a value for each `externalId` field (each field of a list, or `name` when the seed names none), and that a record leaving one blank (no value, `null` or `''`; whitespace is a value) is refused at load in every mode: the load result names the object, the record index, the field and the fix, and the other records still load. The `externalId` row of the field table points at it.
- The note under the field table says a `seed` saved at runtime names its `object` itself, and that one resolving to nothing is refused with `422 INVALID_METADATA` at `object` ("which is not defined"). The fix is the object's full name (`crm_lead`, not `lead`) or creating the object first: a draft of it is enough for a draft seed, a live seed needs it published. The `object` row points at the note.
- Three restatements in the same file were removed to pay for part of the new text: the `columns` row's shape literal, the one-row best-practices table (now a sentence) and the second telling of what a refused seed value leaves behind.

`evals/hooks-security-seeds-datasources.json` gains one case on each refusal.
19 changes: 18 additions & 1 deletion scripts/check-skills-token-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,24 @@ export const CEILINGS = new Map([
// 6984 -> 6570 after the cuts (-414); the teaching nets +466 -> 7036 ->
// ceil(7036 / 4) = 1759; headroom was 0, so the ceiling moves +13, the
// measured remainder only. Pinned AT the measurement.
['skills/objectstack-data/references/seeds.md', 1759],
// 1759 -> 1812: `### externalId selection` says every record carries a value
// for each `externalId` field and that a blank one is refused at load, and the
// `externalId` row points at it. Raise path the standing ruling
// 「A:先削重复,余额按实测提高」 (ruling record 6513306068, letter B). PAID DOWN
// FIRST — restatement cut in the same file: the `columns` row's shape literal
// (its own section shows it), the one-row best-practices table (a sentence
// now) and the second telling of what a refused seed value leaves behind.
// Arithmetic in bytes: 7033 -> 6905 after the cuts (-128); the teaching nets
// +340 -> 7245 -> ceil(7245 / 4) = 1812; headroom was 0, so the ceiling moves
// +53, the measured remainder only. Pinned AT the measurement.
// 1812 -> 1898: the note under the field table says a `seed` saved at runtime
// names an object that exists or the save answers `422 INVALID_METADATA` at
// `object`, and that a draft object is enough for a draft seed; the `object`
// row points at it in place of "never write manually". Same raise path and
// the same paydown as the step above (one PR, the cuts are its deletion):
// 7245 -> 7590 bytes (+345) -> ceil(7590 / 4) = 1898; headroom was 0, so the
// ceiling moves +86, the measured remainder only. Pinned AT the measurement.
['skills/objectstack-data/references/seeds.md', 1898],
// 1351 -> 1343: the body-pin values left the count (#31115, ruling B; see
// BODY_PIN_REPIN); the file's count fell by the same 8, headroom unchanged.
['skills/objectstack-platform/references/bootstrap.md', 1343],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@
"must_not_contain": []
}
},
{
"id": 34,
"prompt": "Our `sales_team` seed is `upsert`, keyed on `externalId: 'code'`. Two of its ten records have no `code` yet; we want to load all ten now and fill those two codes in later. Write the seed.",
"expected_output": "Redirects: the two records cannot load without a `code`. Every record carries a value for each `externalId` field, and a record that leaves one blank (no value, `null` or `''`) is refused at load: the load result names the object, the record index, the blank field and the fix, and the other eight records still load. So the answer gives those two records a real `code` now (`defineSeed(SalesTeam, { externalId: 'code', mode: 'upsert', records })` with ten codes), or keys the seed on a field every record carries. It does not write `code: ''` or `code: null`, does not pad the key with whitespace to pass, and does not switch the mode: `ignore`, `upsert` and `update` all refuse the record.",
"files": [],
"assertions": {
"must_contain": ["defineSeed", "externalId", "refused"],
"must_not_contain": ["code: ''", "code: null"]
}
},
{
"id": 35,
"prompt": "In the running app I saved a draft `seed` item with `object: 'lead'` and three records, through the metadata save. The save answered 422. Our lead object is `crm_lead`, still a draft in the same package. What is wrong, and what do I save instead?",
"expected_output": "The seed names an object that does not exist: the save door refuses a `seed` whose `object` resolves to nothing with `422 INVALID_METADATA`, one finding at `object` saying the seed loads its records into object 'lead', which is not defined, so publishing it would load no record. The fix is the object's full name: save the seed with `object: 'crm_lead'`. The draft `crm_lead` is enough for a draft seed, so nothing has to be published first; a live (published) seed needs the object published. Does not create a second `lead` object to satisfy the save and does not retry the same body.",
"files": [],
"assertions": {
"must_contain": ["422", "crm_lead", "not defined"],
"must_not_contain": []
}
},
{
"id": 5,
"prompt": "Finance may edit a contract's legal terms (`governing_law`, `liability_cap`) while it is a draft, not once approved, signing or active; legal still edits them.",
Expand Down
24 changes: 16 additions & 8 deletions skills/objectstack-data/references/seeds.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export const SeedData = [statusSeed, categorySeed];

| Field | Default | Purpose |
|:------|:--------|:--------|
| `object` | derived | Auto-set from `objectDef.name` — never write manually |
| `externalId` | `'name'` | Stable business key (or field list) every mode matches on |
| `object` | derived | Auto-set from `objectDef.name`; hand-written only in a runtime save (below) |
| `externalId` | `'name'` | Stable business key (or field list) every mode matches on; required in every record (below) |
| `mode` | `'ignore'` | Import strategy (see below) |
| `columns` | — | Per-column write policy, keyed by field: `{ FIELD: { applyOn: 'create' } }` (below) |
| `columns` | — | Per-column write policy, keyed by field (below) |
| `env` | `['prod','dev','test']` | Environments where the seed loads |
| `locale` | — (every locale) | BCP-47 tags it loads for; a locale no set of the object names gets none |
| `fallback` | — | `true` on ONE `locale` set per object: also loads for a locale no set names |
Expand All @@ -56,6 +56,12 @@ export const SeedData = [statusSeed, categorySeed];

Full Zod shape: `node_modules/@objectstack/spec/src/data/seed.zod.ts`.

A `seed` saved at runtime names its `object` itself. One that resolves to
nothing is refused: `422 INVALID_METADATA` at `object`, "which is not defined".
Correct the name to the object's full name (`crm_lead`, not `lead`) or create
the object first: a draft of it is enough for a draft seed; a live seed needs
it published.

### Import modes

| Mode | Behavior | Use for |
Expand Down Expand Up @@ -95,6 +101,11 @@ defineSeed(Invoice, {
**Never use `id`** for generated UUIDs — they
differ across environments.

Every record carries a value for each `externalId` field (each field of a
list; `name` when the seed names none). One left blank (no value, `null` or
`''`; whitespace is a value) is refused at load in every mode: the result names
the object, record index, field and fix, and the other records still load.

| Scenario | Key |
|:---------|:----|
| Named entities (country, currency) | `'code'` / `'slug'` |
Expand Down Expand Up @@ -165,13 +176,10 @@ produce byte-identical `dist/objectstack.json`.

### Seed best practices

| Practice | Why |
|:---------|:----|
| TypeScript: `defineSeed()`, never `SeedSchema.parse()` | Lose compile-time field checks otherwise |
In TypeScript use `defineSeed()`, never `SeedSchema.parse()`: it loses compile-time field checks.

**Fictional is fine; malformed is not.** A seed row passes the same field
validation as a user's insert; a refused value leaves the table short or empty
while sibling rows point at records that do not exist.
validation as a user's insert; a refused value drops the row its siblings point at.
`os validate` / `os build` refuse such a value first, at the
record's field — run them before trusting the load. So never mask or
placeholder a sample value: no `138****4207`,
Expand Down
Loading