Skip to content

Commit 12ecd4f

Browse files
committed
test(metadata-protocol): pin the dashboard save door's duplicate global filter key refusal in every mode
PUT /api/v1/meta/dashboard answers 422 INVALID_METADATA at globalFilters.1.name with no mode, publish and draft, and stores nothing. Plus the patch changeset for the stored listing. Claude-Session: https://claude.ai/code/session_01ADHkmQfSq34mnnkWb6STfV Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2bb3512 commit 12ecd4f

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
fix(spec): `os migrate meta --stored` lists a stored dashboard that declares one global filter key twice
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- **Before.** `DashboardSchema` refuses a dashboard whose `globalFilters` repeats a filter key (its `name`, or its `field` when it has no `name`), and the dashboard save door answers 422 `INVALID_METADATA`. A dashboard already stored in that shape still loads with `_diagnostics` reading `valid: false`, but the v18 stored-row preview had no detector for it, so `os migrate meta --stored` named no such row before the upgrade.
11+
- **Now.** The preview lists each stored dashboard that repeats a key, under the TODO id `ui-dashboard-global-filter-duplicate-name-refused` (the refusal's upgrade guide entry), at the second declaration's `name` (or `field`) — the site the parse refuses — naming the key and every index. The detector calls the refinement's own predicate, so a row is listed exactly when the parse refuses it. Nothing rewrites it: which definition keeps the key only the author knows.
12+
- **Not changed.** What any door accepts or refuses. Distinct keys, and distinct names over one `field`, are not listed.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #29212 — the dashboard save door refuses a dashboard that declares one
5+
* global filter key twice (the #29023 refusal), in every save mode.
6+
*
7+
* The rule lives in the spec parse (`duplicateGlobalFilterNames`, the
8+
* `globalFilters` refinement of `DashboardSchema`), and `saveMetaItem` parses
9+
* with that schema, so `PUT /api/v1/meta/dashboard/X` answers
10+
* `422 INVALID_METADATA` at the second declaration's key and stores nothing,
11+
* with no mode, with `mode: 'publish'` and with `mode: 'draft'` alike. This
12+
* pins that the door keeps reading the refusal; the v18 stored listing
13+
* (`refused-shapes.ts`) names a row already stored in the shape.
14+
*/
15+
import { describe, expect, it } from 'vitest';
16+
import { assertEngineDeleteDispatch, assertEngineUpdateDispatch, assertEngineFindOnePredicate, type EngineFindOneQueryInput } from '@objectstack/metadata-core';
17+
import { ObjectStackProtocolImplementation } from './protocol.js';
18+
19+
/** The engine surface the repository write path touches (as the container-issue-descent harness). */
20+
function makeProtocol() {
21+
const rows = new Map<string, Record<string, unknown>>();
22+
let nextId = 0;
23+
const engine: any = {
24+
async findOne(object: string, query?: EngineFindOneQueryInput) {
25+
assertEngineFindOnePredicate(object, query); return null; },
26+
async find() { return []; },
27+
async insert(table: string, data: Record<string, unknown>) {
28+
nextId += 1;
29+
if (table === 'sys_metadata') rows.set(`${data.type}|${data.name}`, data);
30+
return { id: `r_${nextId}` };
31+
},
32+
async update(_t: string, data: Record<string, unknown>, opts?: Record<string, unknown>) {
33+
assertEngineUpdateDispatch(data, opts);
34+
return { id: null };
35+
},
36+
async delete(_t: string, opts?: Record<string, unknown>) {
37+
assertEngineDeleteDispatch(opts);
38+
return { deleted: 0 };
39+
},
40+
registry: { registerItem: () => {}, registerObject: () => {} },
41+
};
42+
const protocol: any = new ObjectStackProtocolImplementation(engine, () => new Map());
43+
return { protocol, rows };
44+
}
45+
46+
async function rejection(promise: Promise<unknown>): Promise<any> {
47+
try {
48+
await promise;
49+
} catch (err) {
50+
return err;
51+
}
52+
throw new Error('expected the save to be rejected, but it resolved');
53+
}
54+
55+
const MODES = [
56+
['no mode', {}],
57+
['publish', { mode: 'publish' }],
58+
['draft', { mode: 'draft' }],
59+
] as const;
60+
61+
const boardWith = (globalFilters: unknown[]) => ({
62+
name: 'dup_board',
63+
label: 'Dup Board',
64+
widgets: [],
65+
globalFilters,
66+
});
67+
68+
describe('#29212 the save door refuses a dashboard that declares one global filter key twice', () => {
69+
for (const [label, mode] of MODES) {
70+
it(`${label}: two filters named \`r\` answer 422 INVALID_METADATA at globalFilters.1.name, and nothing is stored`, async () => {
71+
const { protocol, rows } = makeProtocol();
72+
73+
const err = await rejection(protocol.saveMetaItem({
74+
type: 'dashboard', name: 'dup_board', ...mode, item: boardWith([
75+
{ name: 'r', field: 'region', type: 'text' },
76+
{ name: 'r', field: 'status', type: 'text' },
77+
]),
78+
}));
79+
80+
expect(err.code).toBe('INVALID_METADATA');
81+
expect(err.status).toBe(422);
82+
expect(err.issues).toEqual([expect.objectContaining({ path: 'globalFilters.1.name', code: 'custom' })]);
83+
expect(err.issues[0].message.startsWith(
84+
"This dashboard declares the global filter 'r' twice in globalFilters: globalFilters[0] and globalFilters[1].",
85+
)).toBe(true);
86+
expect(rows.size).toBe(0);
87+
});
88+
89+
it(`${label}: control, the same dashboard with distinct filter names saves`, async () => {
90+
const { protocol, rows } = makeProtocol();
91+
92+
const result = await protocol.saveMetaItem({
93+
type: 'dashboard', name: 'dup_board', ...mode, item: boardWith([
94+
{ name: 'r', field: 'region', type: 'text' },
95+
{ name: 's', field: 'status', type: 'text' },
96+
]),
97+
});
98+
99+
expect(result.success).toBe(true);
100+
expect(rows.size).toBe(1);
101+
});
102+
}
103+
});

0 commit comments

Comments
 (0)