Skip to content

Commit e78d705

Browse files
test(dogfood): pin five more records-forms checklist items at the REST door (slice 3) (#26865)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8EZuqRp2sWT5mEbwB3fUdmh)_ Refs #26573 (slice 3, items: `field-type-matrix`, `field-unique-enforcement`, `import-wizard-encoding-and-hints`, `master-detail-atomic-save`, `object-hook-lifecycle`) Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:records-forms 区按卡片顺序的下 5 个清单项,新增 6 个 dogfood 测试文件(object-hook-lifecycle 分 showcase 与 scratch 两个),在真实启动的栈上经 REST 门(以及服务端日志)断言它们的 api/log 条款,5 项 `automated.ref` 指向新钉测,revision 各加 1,history 引本卡。 - 为什么改:18.2.0 Tier 1 扫描把这些条款判为 PARTIAL 或无钉测;钉在 oracle 层之后每次发版可直接复跑。 - 风险与回滚:只加测试和清单文字,不动产品代码、不加 CI 车道;新文件落在 dogfood 现有的 isolated 项目。回滚即 revert 本 PR。 - 先看:`field-unique-rest-refusal.dogfood.test.ts`(实测:global 单列索引时面向用户的 `error` 用 API 键名 gsku,developerMessage 用标签,见 Acceptance notes);`object-hook-lifecycle-*.dogfood.test.ts`(日志经 stdout/stderr 截取读回)。 - 两分钟验证:先建依赖闭包,再 `pnpm --filter @objectstack/dogfood exec vitest run --maxWorkers=2 test/field-type-matrix-server-refusals.dogfood.test.ts test/field-unique-rest-refusal.dogfood.test.ts test/import-lands-readable-rows.dogfood.test.ts test/master-detail-batch-atomic.dogfood.test.ts test/object-hook-lifecycle-showcase.dogfood.test.ts test/object-hook-lifecycle-scratch.dogfood.test.ts`,预期 6 个文件 23 个用例全绿;`node scripts/check-platform-checklist.mjs` 预期 OK。 - 需要你做的:无,席位落地。 ## What changes Six new dogfood files drive the REST doors of a booted stack (the showcase as shipped, or a scratch app where the item prescribes one), and two read the server log off stdout/stderr for the item's `log` oracles: | Item (rev → new) | Clauses now pinned | Pin | |---|---|---| | `field-type-matrix` (6 → 7) | acceptance[2], acceptance[5] refusal half, acceptance[6], negative[0]–[1] | `field-type-matrix-server-refusals.dogfood.test.ts`: zoo refusals (invalid_option, required, reference_not_found on f_lookup / f_master_detail / f_tree) with the row count read back; invoice totals vs their lines; EXP-2001's two roll-ups | | `field-unique-enforcement` (10 → 11, kind unit → dogfood) | acceptance[0]–[3], negative[0]–[2] | `field-unique-rest-refusal.dogfood.test.ts`: the item's scratch object on the SQL family | | `import-wizard-encoding-and-hints` (7 → 8) | acceptance[3] server half, negative[1] | `import-lands-readable-rows.dogfood.test.ts`: `POST /data/showcase_contact/import`, created count vs a filtered GET, CJK values byte-identical | | `master-detail-atomic-save` (8 → 9) | acceptance[1], [2], [3], acceptance[5] persisted half, negative[0] | `master-detail-batch-atomic.dogfood.test.ts`: the cross-object `POST /batch` with `{$ref: 0}` children, server amount and total roll-up across add/delete, the whole-batch abort | | `object-hook-lifecycle` (10 → 11) | acceptance[0]–[9], negative[0]–[4] | `object-hook-lifecycle-showcase.dogfood.test.ts` (the seeded hooks: stamp, trim, transition audit, over-budget warn) + `object-hook-lifecycle-scratch.dogfood.test.ts` (abort, async log, fail-closed condition, priority order) | Each item's `automated.ref` keeps the pins it already named (as evidence of their own layer where they sit below the oracle) and adds the new ones with what they score. One history row per item, citing #26573. No clause text, fixture, step or `knownGaps` line was edited (the claim's file surface). **Skipped, by the slice-3 order:** - `record-discussion-mentions`: waits on #26625. - `form-dirty-guard`: next in card order, but its only api clause (acceptance[1]) reads the row after a browser exit (discard or save through the guard), so every clause needs a browser. - Not taken yet, in card order: `related-list-server-pagination`, `v18-semantic-defaults`, `view-type-gallery`. `v18-semantic-defaults` has browser clauses only (a1–a3 dom/screenshot, a0 the spec pins). - Browser legs inside the five items, left unpinned: `field-type-matrix` acceptance[1]; `import-wizard-encoding-and-hints` the wizard's decode/preview (negative[0]); `master-detail-atomic-save` acceptance[0], [4], negative[1] and acceptance[5]'s live recompute. `field-unique-enforcement` acceptance[4]–[5] and negative[3] stay the driver pins', as the item says. ## Why The 18.2.0 release-candidate Tier 1 run scored these clauses PARTIAL (pins below the oracle layer: driver-level, in-process engine, or objectui unit) or unpinned. The triage ruling allows ~5-item slices and no new CI lane; the new files fall under the dogfood package's existing `isolated` vitest project and run where the dogfood legs run today. ## Tests Measured answers the pins now hold (all first read live, then pinned exactly): - zoo: out-of-set `f_select` → `400 VALIDATION_FAILED` `[[f_select, invalid_option]]`; no `name` → `[[name, required]]`; a fabricated id in each relational field → `[[<field>, reference_not_found]]`; row count unchanged each time. - unique, bare `unique: true` (tenant-scoped, composite index) → `409 {error: 'A record with this value already exists', code: UNIQUE_VIOLATION, developerMessage: "Duplicate record refused on 'Unique Item': a unique constraint already holds these values. No record was written.", object}`; `unique: 'global'` (single column) → `error: 'A record with this gsku already exists'`, `field: 'gsku'`, and the developerMessage names `'Global SKU'`. No `[driver-`, no `UNIQUE constraint failed`, no bound value. - unique, atomic `updateMany` stamping one sku on two rows → `200 {success: false, total: 2, succeeded: 0, failed: 2}`, results `ROLLED_BACK` then `UNIQUE_VIOLATION`; both rows re-read unchanged. - import: 3 CJK rows → `{total: 3, ok: 3, errors: 0, created: 3}`; the filtered GET finds those 3, values identical. - batch: invoice + 2 lines → `200`; a client-sent `amount: 1` stores as `2 × 29.99`; total tracks the line sum after create, add and delete. A line with no product → `400 VALIDATION_FAILED [[product, required]]`, and neither the invoice nor the valid sibling exists. - hooks: the showcase logs `task completed: <title>` once per transition and `project over budget: <name> (1100 / 1000)` on the spent-only PATCH. Scratch: abort → `400` with the hook's sentence; async throw → PATCH kept plus `[hook] handler failed (onError=log; suppressing)` naming the hook; `int(record.name) > 0` on a non-numeric name → `400 VALIDATION_ERROR` "Hook 'ohl_unevaluable_guard' could not evaluate its condition … operation aborted", no source echoed, no `[REST] Unhandled error`; priority 10 logs before 90 although declared after it. <details><summary>Runs</summary> - Dependency closure on `3c2187f4` (the restarted branch) under `os-verify-lock.sh`, then the six files: `Tests 21 passed | 2 failed (23)`, both in the unique file. The global index's `error` names the field (`A record with this gsku already exists`), and the atomic `updateMany` answers `200` with a per-row refusal report, not a 4xx. Both re-pinned to the measured bodies. Then the six files → `Test Files 6 passed (6)`, `Tests 23 passed (23)`, plus the dogfood typecheck, VERDICT command-exit 0. - Final head `ea357b54` (after merging `origin/main` `e9e344a9`, which brought an objectql engine refactor and metadata-protocol changes): the closure rebuilt (`Tasks: 67 successful, 67 total`), then the six files → `Test Files 6 passed (6)`, `Tests 23 passed (23)`, then `pnpm typecheck` in `packages/qa/dogfood`, one locked command, VERDICT command-exit 0. </details> No ablation was run: this diff adds tests and changes no behaviour they pin. Each refusal assertion has a same-door admitted control beside it, and the two ordering/transition log pins are built so the wrong semantics would fail them (the priority hooks are declared in the opposite order; a bare state condition would log a second audit line). ## Acceptance notes - `field-unique-enforcement` acceptance[0] says the user-facing `error` "stays generic". On the tenant-scoped (composite) index it does; on the single-column global index the wire `error` names the field by its API key (`A record with this gsku already exists`) while `developerMessage` names it by its label (`'Global SKU'`). The pin holds both bodies as measured. That is the opposite split from the engine envelope's own rule (labels in the user-facing message, API names for diagnostics, #24951), so it is noted here as a possible finding, not filed and not changed: product code is outside this card. - `field-unique-enforcement` acceptance[3]: REST has no predicate-update door. The REST door that stamps one value onto two rows in one request is `POST /data/:object/updateMany` with `options.atomic`, so the pin drives that, and the engine's predicate `updateMany` stays the memory driver pin's (named in the ref). - `master-detail-atomic-save` acceptance[1]: the product pick's auto-fill is client-side (the grid copies `description` / `unit_price` from the chosen product). The pin sends the catalog values and asserts they persist; the copy itself stays a browser leg. - `import-wizard-encoding-and-hints` acceptance[3]: the console decodes the file and posts JSON rows to `/data/:object/import`; the pin sends the decoded strings, so it scores the server half only. ## Verification - `node scripts/check-platform-checklist.mjs` → exit 0, `OK — 16 areas, 329 items (324 active, 1 planned)`, on the commit `e945fc15` and on the final head. - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` → 55 commands on `e945fc15`, each run and reconciled with `--ran`: `55 derived famil(ies) accounted for — 55 run, 0 NOT-MEASURED`, all exit 0. - CI families are read from this PR's check-runs, not re-run locally. `Dogfood Regression Gate` does not run on pull_request, so the local runs above are this PR's evidence for the new pins. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (CI-owned run) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset — nothing publishes here (`@objectstack/dogfood` is private; `docs/qa/**` ships in no package), so `skip-changeset`; both declaration lines are filled in above. - [x] 6. `packages/spec` not touched. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English (the maintainer brief above is Chinese by the repo's communication rule). --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbZ3oTCkvGGTMNd5XYU)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1a8b7eb commit e78d705

7 files changed

Lines changed: 836 additions & 11 deletions

‎docs/qa/platform-checklist/areas/records-forms.json‎

Lines changed: 41 additions & 11 deletions
Large diffs are not rendered by default.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// Checklist item `records-forms.field-type-matrix` (#26573): the api clauses
4+
// `field-zoo-roundtrip.dogfood.test.ts` does not assert, at the REST data door
5+
// of the booted showcase, as shipped.
6+
//
7+
// acceptance[2], negative[0] — constrained types refuse invalid input with a
8+
// named error: an out-of-set `f_select` is 400 VALIDATION_FAILED naming
9+
// f_select with invalid_option; a create with no `name` names name with
10+
// required; the zoo's row count does not grow.
11+
// acceptance[5], negative[1] — the REFUSAL half of the relational types: a
12+
// fabricated id in f_lookup, f_master_detail or f_tree is refused naming
13+
// that field with reference_not_found, and nothing is stored. The
14+
// round-trip suite seeds real ids only, so this half was the run's.
15+
// acceptance[6] — summary on its real carriers (fixtures.knownGaps[0]): every
16+
// seeded invoice's `total` equals the sum of its lines' amounts, and the
17+
// seeded EXP-2001 reads total_amount 1500.5 and the summaryOperations.filter
18+
// variant approved_amount 960.
19+
//
20+
// The widget clause (acceptance[1]) stays a browser leg.
21+
22+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
23+
import { type VerifyStack } from '@objectstack/verify';
24+
import { bootShowcase } from './showcase-boot.js';
25+
26+
const ZOO = 'showcase_field_zoo';
27+
28+
type Answer = { status: number; json: any };
29+
30+
describe('records-forms.field-type-matrix — the server refusals and the summary carriers over REST', () => {
31+
let stack: VerifyStack;
32+
let token = '';
33+
let projectId = '';
34+
35+
const call = async (method: string, path: string, body?: unknown): Promise<Answer> => {
36+
const res = await stack.apiAs(token, method, path, body);
37+
return { status: res.status, json: await res.json().catch(() => ({})) };
38+
};
39+
const uniq = (prefix: string) => `${prefix}-${Math.random().toString(36).slice(2, 8)}`;
40+
const fieldCodes = (json: any) => (json?.fields ?? []).map((f: any) => [f.field, f.code]);
41+
const zooCount = async () => (await stack.rows(ZOO, {})).length;
42+
const listOf = async (object: string, filter: unknown[]): Promise<any[]> => {
43+
const res = await call('GET', `/data/${object}?$filter=${encodeURIComponent(JSON.stringify(filter))}&$top=200`);
44+
expect(res.status, JSON.stringify(res.json)).toBe(200);
45+
return res.json.records ?? res.json.data ?? res.json.value ?? res.json;
46+
};
47+
48+
beforeAll(async () => {
49+
stack = await bootShowcase();
50+
token = await stack.signIn();
51+
const [project] = await stack.rows('showcase_project', {});
52+
projectId = String(project.id);
53+
}, 180_000);
54+
55+
afterAll(async () => {
56+
await stack?.stop();
57+
});
58+
59+
it('acceptance[2], negative[0]: an out-of-set select is refused invalid_option, and the row count does not grow', async () => {
60+
const before = await zooCount();
61+
const res = await call('POST', `/data/${ZOO}`, { name: uniq('ftm-select'), f_master_detail: projectId, f_select: 'not_an_option' });
62+
expect(res.status, JSON.stringify(res.json)).toBe(400);
63+
expect(res.json.code).toBe('VALIDATION_FAILED');
64+
expect(fieldCodes(res.json)).toEqual([['f_select', 'invalid_option']]);
65+
expect(await zooCount()).toBe(before);
66+
67+
// Control: the in-set value is admitted on the same door.
68+
const ok = await call('POST', `/data/${ZOO}`, { name: uniq('ftm-select-ok'), f_master_detail: projectId, f_select: 'high' });
69+
expect(ok.status, JSON.stringify(ok.json)).toBe(201);
70+
});
71+
72+
it('acceptance[2]: a create with no name is refused naming name with required, and the row count does not grow', async () => {
73+
const before = await zooCount();
74+
const res = await call('POST', `/data/${ZOO}`, { f_master_detail: projectId });
75+
expect(res.status, JSON.stringify(res.json)).toBe(400);
76+
expect(res.json.code).toBe('VALIDATION_FAILED');
77+
expect(fieldCodes(res.json)).toEqual([['name', 'required']]);
78+
expect(await zooCount()).toBe(before);
79+
});
80+
81+
it.each([
82+
['f_lookup', { f_lookup: 'no_such_account_26573' }],
83+
['f_master_detail', { f_master_detail: 'no_such_project_26573' }],
84+
['f_tree', { f_tree: 'no_such_zoo_row_26573' }],
85+
])('acceptance[5], negative[1]: a dangling %s is refused reference_not_found, and nothing is stored', async (field, bad) => {
86+
const name = uniq(`ftm-${field}`);
87+
const res = await call('POST', `/data/${ZOO}`, { name, f_master_detail: projectId, ...bad });
88+
expect(res.status, JSON.stringify(res.json)).toBe(400);
89+
expect(fieldCodes(res.json)).toEqual([[field, 'reference_not_found']]);
90+
expect(await stack.rows(ZOO, { name })).toHaveLength(0);
91+
});
92+
93+
it('acceptance[6]: every seeded invoice total is the server-side sum of its lines', async () => {
94+
const invoices = await listOf('showcase_invoice', [['name', 'startswith', 'INV-']]);
95+
expect(invoices.length, 'the showcase seed carries invoices').toBeGreaterThan(0);
96+
for (const invoice of invoices) {
97+
const lines = await listOf('showcase_invoice_line', [['invoice', '=', invoice.id]]);
98+
const sum = lines.reduce((acc: number, l: any) => acc + Number(l.amount ?? 0), 0);
99+
expect(Number(invoice.total ?? 0), `${invoice.name}: ${lines.length} line(s)`).toBeCloseTo(sum, 2);
100+
}
101+
});
102+
103+
it('acceptance[6]: EXP-2001 reads total 1500.5 and the filtered approved roll-up 960', async () => {
104+
const [report] = await listOf('showcase_expense_report', [['name', '=', 'EXP-2001']]);
105+
expect(report, 'the showcase seed carries EXP-2001').toBeTruthy();
106+
expect(Number(report.total_amount)).toBeCloseTo(1500.5, 2);
107+
expect(Number(report.approved_amount)).toBeCloseTo(960, 2);
108+
});
109+
});
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// Checklist item `records-forms.field-unique-enforcement` (#26573): its four
4+
// api clauses at the REST data doors of a booted stack on the stock SQL family
5+
// (`bootStack`'s default SQLite datasource). No showcase object declares a
6+
// field-level `unique` (fixtures.knownGaps[0]), so this file authors the
7+
// item's own scratch object inline, as its fixtures prescribe: `sku` bare
8+
// `unique: true`, `gsku` `unique: 'global'`, `nick` with no unique.
9+
//
10+
// acceptance[0], negative[0], negative[1] — a colliding create is 409
11+
// UNIQUE_VIOLATION; the developerMessage names the object by its declared
12+
// label and says no record was written; on the tenant-scoped (composite)
13+
// index the user-facing `error` is the generic sentence, and on the
14+
// single-column global index it names the field; neither carries a driver
15+
// prefix, the driver's statement or the bound value; the row count is
16+
// unchanged.
17+
// acceptance[1] — NULL-distinct: two rows with no sku both land.
18+
// acceptance[2] — an update onto a taken value is refused and the row keeps
19+
// its old value; an update leaving the unique field alone (or re-sending
20+
// its own value) passes.
21+
// acceptance[3], negative[2] — the REST door that stamps one value onto two
22+
// rows in one request is `POST /data/:object/updateMany` with
23+
// `options.atomic`; its per-row report refuses both (ROLLED_BACK for the
24+
// row written first, UNIQUE_VIOLATION for the causal one) and BOTH rows
25+
// re-read unchanged. REST
26+
// has no predicate-update door, so the engine's predicate `updateMany`
27+
// stays the driver pins' (memory-unique-constraint.test.ts).
28+
//
29+
// The scope matrix (acceptance[4]) and the autonumber converge (acceptance[5])
30+
// stay unit-pinned, as the item says.
31+
32+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
33+
import { bootStack, type VerifyStack } from '@objectstack/verify';
34+
import { defineStack } from '@objectstack/spec';
35+
import { ObjectSchema, Field } from '@objectstack/spec/data';
36+
37+
const OBJ = 'fue_item';
38+
const LABEL = 'Unique Item';
39+
40+
const fueStack = defineStack({
41+
manifest: {
42+
id: 'com.dogfood.field-unique-rest-refusal', namespace: 'fue', version: '0.0.0', type: 'app',
43+
name: 'Field unique REST fixture', description: 'One object with an org-scoped and a global unique field.',
44+
},
45+
objects: [
46+
ObjectSchema.create({
47+
name: OBJ, label: LABEL, pluralLabel: 'Unique Items', sharingModel: 'public_read_write',
48+
fields: {
49+
name: Field.text({ label: 'Name', required: true }),
50+
sku: Field.text({ label: 'SKU', unique: true }),
51+
gsku: Field.text({ label: 'Global SKU', unique: 'global' }),
52+
nick: Field.text({ label: 'Nickname' }),
53+
},
54+
}),
55+
],
56+
} as never);
57+
58+
type Answer = { status: number; json: any; text: string };
59+
60+
describe('records-forms.field-unique-enforcement — the unique refusal at the REST doors', () => {
61+
let stack: VerifyStack;
62+
let token = '';
63+
64+
const call = async (method: string, path: string, body?: unknown): Promise<Answer> => {
65+
const res = await stack.apiAs(token, method, path, body);
66+
const text = await res.text();
67+
let json: any = {};
68+
try { json = JSON.parse(text); } catch { /* not JSON */ }
69+
return { status: res.status, json, text };
70+
};
71+
const create = async (data: Record<string, unknown>): Promise<string> => {
72+
const res = await call('POST', `/data/${OBJ}`, data);
73+
expect(res.status, res.text).toBe(201);
74+
const [row] = await stack.rows(OBJ, { name: data.name });
75+
return String(row.id);
76+
};
77+
const read = async (id: string) => (await stack.rows(OBJ, { id }))[0];
78+
/** The driver-anonymous contract: no driver prefix, no statement text, no bound value. */
79+
const expectDriverAnonymous = (text: string, value: string) => {
80+
expect(text).not.toMatch(/\[driver-/);
81+
expect(text).not.toMatch(/UNIQUE constraint failed/i);
82+
expect(text).not.toContain(value);
83+
};
84+
85+
beforeAll(async () => {
86+
stack = await bootStack(fueStack);
87+
token = await stack.signIn();
88+
}, 180_000);
89+
90+
afterAll(async () => {
91+
await stack?.stop();
92+
});
93+
94+
// The measured bodies. Bare `unique: true` is tenant-scoped, so its SQLite
95+
// index is composite and no single column is named; the global index is
96+
// single-column, so the field is named (by its API key in `error` and
97+
// `field`, by its label in `developerMessage`).
98+
it.each([
99+
['sku', 'FUE-SKU-0001', {
100+
error: 'A record with this value already exists',
101+
code: 'UNIQUE_VIOLATION',
102+
developerMessage: `Duplicate record refused on '${LABEL}': a unique constraint already holds these values. No record was written.`,
103+
object: OBJ,
104+
}],
105+
['gsku', 'FUE-GSKU-0001', {
106+
error: 'A record with this gsku already exists',
107+
code: 'UNIQUE_VIOLATION',
108+
developerMessage: `Duplicate record refused on '${LABEL}': a unique constraint on 'Global SKU' already holds this value. No record was written.`,
109+
field: 'gsku',
110+
object: OBJ,
111+
}],
112+
])('acceptance[0], negative[0], negative[1]: a colliding create on %s is 409 UNIQUE_VIOLATION, driver-anonymous, and nothing lands', async (field, value, body) => {
113+
await create({ name: `fue-first-${field}`, [field]: value });
114+
const refused = await call('POST', `/data/${OBJ}`, { name: `fue-second-${field}`, [field]: value });
115+
expect(refused.status, refused.text).toBe(409);
116+
expect(refused.json).toEqual(body);
117+
expectDriverAnonymous(refused.text, value);
118+
expect(await stack.rows(OBJ, { [field]: value })).toHaveLength(1);
119+
expect(await stack.rows(OBJ, { name: `fue-second-${field}` })).toHaveLength(0);
120+
});
121+
122+
it('acceptance[1]: two rows with no sku both land (NULL-distinct)', async () => {
123+
const a = await create({ name: 'fue-null-a' });
124+
const b = await create({ name: 'fue-null-b' });
125+
expect(a).not.toBe(b);
126+
expect((await read(a))?.sku ?? null).toBeNull();
127+
expect((await read(b))?.sku ?? null).toBeNull();
128+
});
129+
130+
it('acceptance[2]: an update onto a taken value is refused and the row keeps its old value; a self-update passes', async () => {
131+
await create({ name: 'fue-upd-taken', sku: 'FUE-UPD-1' });
132+
const id = await create({ name: 'fue-upd-mover', sku: 'FUE-UPD-2' });
133+
134+
const refused = await call('PATCH', `/data/${OBJ}/${id}`, { sku: 'FUE-UPD-1' });
135+
expect(refused.status, refused.text).toBe(409);
136+
expect(refused.json.code).toBe('UNIQUE_VIOLATION');
137+
expectDriverAnonymous(refused.text, 'FUE-UPD-1');
138+
expect((await read(id)).sku).toBe('FUE-UPD-2');
139+
140+
// A row never collides with itself: leaving sku alone, or re-sending its own value, passes.
141+
const other = await call('PATCH', `/data/${OBJ}/${id}`, { nick: 'moved-nothing' });
142+
expect(other.status, other.text).toBe(200);
143+
const same = await call('PATCH', `/data/${OBJ}/${id}`, { sku: 'FUE-UPD-2' });
144+
expect(same.status, same.text).toBe(200);
145+
expect(await read(id)).toMatchObject({ sku: 'FUE-UPD-2', nick: 'moved-nothing' });
146+
});
147+
148+
it('acceptance[3], negative[2]: an atomic updateMany stamping one value onto two rows is refused, and neither row changes', async () => {
149+
const c = await create({ name: 'fue-many-c', sku: 'FUE-MANY-C', nick: 'c' });
150+
const d = await create({ name: 'fue-many-d', sku: 'FUE-MANY-D', nick: 'd' });
151+
const before = [await read(c), await read(d)];
152+
153+
const res = await call('POST', `/data/${OBJ}/updateMany`, {
154+
records: [{ id: c, data: { sku: 'FUE-MANY-X', nick: 'c2' } }, { id: d, data: { sku: 'FUE-MANY-X', nick: 'd2' } }],
155+
options: { atomic: true },
156+
});
157+
// The per-row report: the causal row keeps its own code, the row written
158+
// before it is marked rolled back, and nothing succeeded.
159+
expect(res.status, res.text).toBe(200);
160+
expect(res.json).toMatchObject({ success: false, total: 2, succeeded: 0, failed: 2 });
161+
expect(res.json.results.map((r: any) => [r.id, r.success, r.errors?.[0]?.code])).toEqual([
162+
[c, false, 'ROLLED_BACK'],
163+
[d, false, 'UNIQUE_VIOLATION'],
164+
]);
165+
expect([await read(c), await read(d)]).toEqual(before);
166+
expect(await stack.rows(OBJ, { sku: 'FUE-MANY-X' })).toHaveLength(0);
167+
});
168+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// Checklist item `records-forms.import-wizard-encoding-and-hints` (#26573):
4+
// the server half of its api clause, at the door the wizard's end state is
5+
// written through — `POST /api/v1/data/showcase_contact/import`, the route the
6+
// console's `importRecords` forwards the parsed rows to verbatim — on the
7+
// showcase as shipped.
8+
//
9+
// acceptance[3], negative[1] — a completed import lands rows the API reads
10+
// back: the answer's `created` count equals the rows a filtered
11+
// `GET /data/showcase_contact` then finds for the import's marker, and every
12+
// CJK value (the strings a GBK file decodes to) re-reads byte-for-byte.
13+
// A success answer whose filtered read finds fewer rows is the silent drop
14+
// negative[1] names.
15+
//
16+
// The GBK decode itself (acceptance[0]) and the wizard's preview (negative[0])
17+
// stay the objectui parser pins' and a browser leg: the console decodes the
18+
// file client-side and sends strings, which is exactly what this file sends.
19+
20+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
21+
import { type VerifyStack } from '@objectstack/verify';
22+
import { bootShowcase } from './showcase-boot.js';
23+
24+
const CONTACT = 'showcase_contact';
25+
26+
describe('records-forms.import-wizard-encoding-and-hints — an import lands rows the API reads back', () => {
27+
let stack: VerifyStack;
28+
let token = '';
29+
30+
beforeAll(async () => {
31+
stack = await bootShowcase();
32+
token = await stack.signIn();
33+
}, 180_000);
34+
35+
afterAll(async () => {
36+
await stack?.stop();
37+
});
38+
39+
it('acceptance[3], negative[1]: the created count equals the filtered read, and the decoded values re-read intact', async () => {
40+
const marker = `iwe-${Math.random().toString(36).slice(2, 8)}`;
41+
const rows = [
42+
{ name: '张伟', email: `${marker}-1@verify.test`, company: '北京数据科技有限公司', notes: `${marker} 第一行:中文备注` },
43+
{ name: '李娜', email: `${marker}-2@verify.test`, company: '上海云端信息', notes: `${marker} 第二行,含全角标点!` },
44+
{ name: '王芳', email: `${marker}-3@verify.test`, company: '深圳市创新工场', notes: `${marker} 第三行` },
45+
];
46+
47+
const res = await stack.apiAs(token, 'POST', `/data/${CONTACT}/import`, { format: 'json', rows });
48+
const answer: any = await res.json();
49+
expect(res.status, JSON.stringify(answer)).toBe(200);
50+
expect(answer).toMatchObject({ total: 3, ok: 3, errors: 0, created: 3 });
51+
52+
const filter = encodeURIComponent(JSON.stringify([['email', 'contains', marker]]));
53+
const read = await stack.apiAs(token, 'GET', `/data/${CONTACT}?$filter=${filter}&$top=50`);
54+
expect(read.status).toBe(200);
55+
const body: any = await read.json();
56+
const found: any[] = body.records ?? body.data ?? body.value ?? body;
57+
expect(found, 'the filtered read finds every row the answer counted as created').toHaveLength(answer.created);
58+
59+
const byEmail = new Map(found.map((r) => [r.email, r]));
60+
for (const row of rows) {
61+
expect(byEmail.get(row.email), row.email).toMatchObject(row);
62+
}
63+
});
64+
});

0 commit comments

Comments
 (0)