Skip to content

Commit ba875d2

Browse files
fix(studio): a renamed validation rule keeps the server verdict's hold on its guard (#31549)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbVq7nzkk5jEoQes96mHQY8d)_ Fixes #27482 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:Studio 数据支柱「验证规则」页里,规则改名后(用「新建」建出的规则,名称会随错误提示语自动变化;或直接改 API 名称),服务器对该规则条件的拒绝判定会跟着新名称走,下一次自动保存照样被拦住,并显示「尚未保存」提示行。权限集和钩子面板的拦截提示语从「请先修复 CEL 语法错误再保存」改成「请先修复表达式错误再保存」,因为它也拦服务器的非语法拒绝。 - **为什么改**:#27612 / #28027 已让服务器判定能拦自动保存,但面板按规则名称记判定数,改名后数字留在旧名下被清掉,条件编辑器只在数字变化时才重报,于是「新建」出来的规则在服务器标红后每次编辑仍然 PUT 200,直到发布被拒(QA #29672、#29893 实测,本卡在 `main` 上实测复现)。 - **风险与回滚**:只改 `ObjectValidationsPanel.tsx` 里的计数归属(约 20 行)和 studio 词条 en/zh 各一行;不动 spec、lint、服务端,不在客户端复制发布规则。首次保存仍会发出(服务器只评判已保存的草稿);改条件文本本身仍会发出以换取新判定。回滚即 revert。 - **先看**:`ui/packages/app-shell/src/views/studio-design/ObjectValidationsPanel.tsx` 的 `renameCel` / `renamedTo` / `reportCel` 与 `patchRule` 第一行。 - **两分钟验证**:`cd ui && pnpm exec vitest run packages/app-shell/src/views/studio-design/DataPillar.validationVerdictHold-27644.test.tsx`,预期 9 个用例全绿。 - **需要你做的**:无,席位落地。 ## What changes - **`ObjectValidationsPanel.tsx`: a rule's verdict follows its name.** The panel keeps each rule's blocking CEL count by rule name (`reportCel(sel.name!, count)`) and prunes names no longer in the draft. A rule the panel minted takes its name from its message (`patchMessage`), and the name input renames too. The guard's `ConditionBuilder` reports only when its count changes, so a rename left the count under the old name, it was pruned, and the new name never got one: the served verdict stayed on screen while every later edit autosaved. Now: - `patchRule` calls `renameCel(old, new)` whenever a patch carries a `name`, which moves the kept count to the new name. - `renameCel` also records the rename in `renamedTo`, and `reportCel` resolves a name through it. A report still in flight under the old name (the editor's effect ran on the render before the rename) lands on the rule's current name instead of being stranded. Without this, the new test's minted-rule case was red in 3 of 4 runs. - `placeNewRule` drops a `renamedTo` entry for the name it places, so a new rule that reuses a name a rename left reports as itself. - **`perm.cel.saveBlocked` copy** (studio namespace, `en.ts` and `zh.ts`, the only two packs that carry it): "Fix the CEL syntax errors before saving." → "Fix the expression errors before saving."; zh 「请先修复 CEL 语法错误再保存。」 → 「请先修复表达式错误再保存。」. The line holds server refusals too (`rls-predicate-unenforceable` measured live), not only syntax errors. Read by the permission set editor's held line and Save title and by `ObjectHooksPanel`'s held line. The two `metadata-admin` pins of the old sentence are updated. - No change to `CelPredicateField`, `ConditionBuilder` or `draftVerdict.ts`. No client copy of any publish rule (#26858), no `packages/lint`, `packages/spec` or server change. ## Acceptance reading (seat ruling on the step-1 report) The server judges only a saved draft, and no metadata validate-only door exists, so the first save of a refused guard goes out: it is the save whose re-read brings the verdict. Once the verdict shows, the next save is held and the held line is drawn while the guard still shows the judged text, a rename of the rule included. An edit of the guard text itself goes out, to be judged again (#27612's design, `serverHoldAt`). ## Tests New top-level `describe` in the shared harness `ui/packages/app-shell/src/views/studio-design/DataPillar.validationVerdictHold-27644.test.tsx` (real `DataPillar`, a fake door whose draft read refuses `record.amount > 100` at `validations.N.condition`): - **(a) the minted rule:** New → "Reject the save when…", guard `record.amount > 100`, message "Over the cap". The first save goes out (rule `over_the_cap` at index 2) and the verdict shows. The message edit renames it to `over_the_cap_now`: the held line names the rule and no second PUT goes out. - **(b)** a rename through the name input is held the same way. - **control:** renaming a rule the verdict does not judge saves. - **CONTROL** (existing, unchanged): the five #27644 cases and its control in the same file, and the #27612 / #28027 pins in the nearby sweep below. **Ablations** (fix committed first, mutated through `scripts/ablation-replace.mjs`, restored blob == HEAD `00af991baf66`, `git diff HEAD` empty): 1. The rename carry removed (the `renameCel` call in `patchRule` deleted): (a) and (b) red, the control and the #27644 cases green. 2. The in-flight resolution removed (the `renamedTo` walk in `reportCel` made a no-op): (a) red in 1 of 2 runs, as expected for a timing race. Before that half was written, the same case was red in 3 of 4 runs. ## Acceptance notes - **Live, before and after** (fresh showcase, Console Vite over it, Playwright, my own writable package; the probe and its readings are in the project files under `issue-27482/live/`). On `main` `58f66b93`: a rule made through New → "Reject the save when…" saved on every edit under the red verdict (message, label and guard edits, 4 PUTs, no held line). The same guard on a rule with an authored name was held. RLS USING on a formula field was held after the first save, under "Fix the CEL syntax errors before saving.". After this change: the message edit that renames the rule and the label edit are held (1 PUT in all, held line names `qty_too_big_now`), the guard edit goes out, and the RLS held line reads "Fix the expression errors before saving.". - **The 11-03 RLS reading "first PUT answers 200"** is the expected first save above, not a defect: after it, an edit beside the USING was held live. ## Verification <details><summary>Tests at the final head c1768bd (main a3ac7fb merged, no overlap with the touched files)</summary> - `pnpm --dir ui exec vitest run` over 39 files: every test file naming `ObjectValidationsPanel`, the Validations tab, `perm.cel.saveBlocked` or the permission / hooks held lines, plus `studio-namespace.test.ts`, `draftVerdict.test.ts`, `ConditionBuilder.serverHold-27644.test.tsx` and `PermissionMatrixEditor.serverVerdictHold-27482.test.tsx` (the #27612 / #28027 / #27644 / #27629 pins): Test Files 39 passed, Tests 275 passed, lock VERDICT command-exit 0. - The harness file alone, 4 consecutive runs before the merge: 9/9 each. - `turbo run type-check --filter=@object-ui/app-shell --filter=@object-ui/i18n`: 68/68 tasks, exit 0 (before the merge; the merge touched no app-shell or i18n file this diff touches). - `node scripts/check-i18n-en-drift.mjs` (from `ui/`): exit 0, "Every changed designer-table en value was followed by its zh row." - `pnpm check:new-line-citations` (from `ui/`): 0 new citations. </details> <details><summary>Derived gate union (dispatch-gates --commands): 36 of 36 exit 0</summary> 36 of 36 exit 0 at `c1768bdc`; `dispatch-gates --ran`: 36 derived, 36 run, 0 NOT-MEASURED. `node scripts/check-sdui-manifest.mjs` exit 0. `pnpm --dir ui exec vitest run scripts/`: 170 files passed, 2 skipped. `pnpm check:test-source-alias` first asked for module-top preloads of the lazily loaded `@objectstack/formula`, `@objectstack/lint` and `@objectstack/spec/identity` in the three edited test files; they were added (`d2fd8a4c`) and it is green. CI families: read from this PR's check-runs by the seat. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jSGK8zPYdrSzXgFLDf)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1ebe0c5 commit ba875d2

7 files changed

Lines changed: 120 additions & 5 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(studio): a renamed validation rule keeps the hold of the server's verdict on its guard
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
In Studio's Validations tab a rule made from New takes its name from its error message, so editing the message renames it. The panel kept each rule's verdict by name and the condition editor reports only when its count changes, so a rename stranded the verdict under the old name: a guard the publish refuses (a nullable field compared without a null check) went on autosaving after the server had said so. The verdict now moves with the rule's name, through the message and through the name input: once the verdict shows, the next save is held and the held line names the rule. The first save of a refused guard still goes out, since only a saved draft is judged, and an edit of the guard itself still goes out to be judged again.
12+
13+
The held line the permission set editor and the hooks panel show reads "Fix the expression errors before saving." (zh 「请先修复表达式错误再保存。」) instead of naming CEL syntax errors, since it also holds the server's refusals.

‎ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.fieldWhen-25866.test.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import '@testing-library/jest-dom/vitest';
1414
import { afterEach, describe, expect, it, vi } from 'vitest';
1515
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
1616
import { MemoryRouter } from 'react-router-dom';
17+
// The CEL authoring and catalog code loads these lazily; warmed here so the
18+
// first load is paid at import, not inside a test's clock.
19+
import '@objectstack/formula';
20+
import '@objectstack/lint';
21+
import '@objectstack/spec/identity';
1722

1823
interface FieldEntry {
1924
readable?: boolean;
@@ -185,7 +190,7 @@ describe('a field row offers a row condition on its edit vote (objectstack#25866
185190

186191
fireEvent.change(screen.getByLabelText(WHEN_LABEL), { target: { value: 'status ==' } });
187192
const held = await screen.findByTestId('perm-autosave-held', {}, { timeout: 3000 });
188-
expect(held).toHaveTextContent('Fix the CEL syntax errors before saving.');
193+
expect(held).toHaveTextContent('Fix the expression errors before saving.');
189194
// Longer than the autosave's pause: the held edit does not land.
190195
await new Promise((r) => setTimeout(r, 2000));
191196
expect(saved).toHaveLength(1);

‎ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.rlsAddPolicyHold-13113.test.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import '@testing-library/jest-dom/vitest';
2424
import { afterEach, describe, expect, it, vi } from 'vitest';
2525
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
2626
import { MemoryRouter } from 'react-router-dom';
27+
// The CEL authoring and catalog code loads these lazily; warmed here so the
28+
// first load is paid at import, not inside a test's clock.
29+
import '@objectstack/formula';
30+
import '@objectstack/lint';
31+
import '@objectstack/spec/identity';
2732

2833
const PUBLISHED = {
2934
name: 'sales_perms',
@@ -192,7 +197,7 @@ describe('controls: what held, saved and read before still does (objectui#13113)
192197
typeUsing('organization_id ==');
193198

194199
await waitFor(() =>
195-
expect(screen.getByTestId('perm-autosave-held')).toHaveTextContent('Fix the CEL syntax errors before saving.'),
200+
expect(screen.getByTestId('perm-autosave-held')).toHaveTextContent('Fix the expression errors before saving.'),
196201
);
197202
await pause(PAST_THE_PAUSE);
198203
expect(server.sent).toHaveLength(0);

‎ui/packages/app-shell/src/views/studio-design/DataPillar.validationVerdictHold-27644.test.tsx‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import * as React from 'react';
2020
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
2121
import { render, screen, fireEvent, cleanup, waitFor } from '@testing-library/react';
2222
import { MemoryRouter } from 'react-router-dom';
23+
// The CEL authoring code loads `@objectstack/lint` lazily; warmed here so its
24+
// first load is paid at import, not inside a test's clock.
25+
import '@objectstack/lint';
2326

2427
const REFUSED = 'record.amount > 100';
2528
const ACCEPTED = 'record.amount != null && record.amount > 100';
@@ -274,3 +277,67 @@ describe('a server error at a validation rule\'s path holds the Data pillar auto
274277
expect(screen.queryByText(REFUSAL)).toBeNull();
275278
});
276279
});
280+
281+
/**
282+
* objectstack#27482 — a rule the panel minted takes its name from its message
283+
* (`patchMessage`), so editing the message renames it. The panel keeps each
284+
* rule's verdict by name and the guard's editor reports only when its count
285+
* changes, so the verdict has to move with the name: left behind, it was
286+
* pruned with the old name and the refused guard autosaved on every edit.
287+
*/
288+
describe('a rename keeps the served verdict\'s hold on the rule (objectstack#27482)', () => {
289+
/** New → "Reject the save when…": a minted rule whose name follows its message. */
290+
async function newRejectWhenRule() {
291+
fireEvent.click(await screen.findByTestId('data-tab-flat-rules'));
292+
await screen.findByText('Amount cap');
293+
fireEvent.click(screen.getByText('New'));
294+
fireEvent.click(await screen.findByTestId('rule-preset-reject_when'));
295+
}
296+
297+
it('(a) the minted rule: its first save goes out, and the message edit that renames it is held', async () => {
298+
mount(objectWith(ACCEPTED));
299+
await newRejectWhenRule();
300+
// The card's flow: the guard first, then the message, which settles the rule into the draft.
301+
fireEvent.change(await rawGuard(), { target: { value: REFUSED } });
302+
editMessage('Over the cap');
303+
304+
// No client copy of the rule: the first save goes out and its re-read brings the verdict.
305+
await waitFor(() => expect(server.sent).toHaveLength(1), AUTOSAVE);
306+
const first = server.sent[0]!.validations as Array<{ name?: string; condition?: string }>;
307+
expect(first[2]).toMatchObject({ name: 'over_the_cap', condition: REFUSED });
308+
expect(await screen.findByText(REFUSAL, {}, AUTOSAVE)).toBeInTheDocument();
309+
310+
// The next message edit renames the rule; the guard still shows the judged text.
311+
editMessage('Over the cap now');
312+
expect(screen.getByDisplayValue('over_the_cap_now')).toBeInTheDocument();
313+
await waitFor(() => expect(screen.getByTestId('studio-held-message')).toHaveTextContent('over_the_cap_now'), AUTOSAVE);
314+
await pause();
315+
expect(server.sent).toHaveLength(1);
316+
});
317+
318+
it('(b) a rename through the name input is held the same way', async () => {
319+
mount(objectWith(REFUSED));
320+
await openRule();
321+
await screen.findByText(REFUSAL);
322+
323+
fireEvent.change(screen.getByDisplayValue('amount_cap'), { target: { value: 'amount_limit' } });
324+
325+
await waitFor(() => expect(screen.getByTestId('studio-held-message')).toHaveTextContent('Amount cap'), AUTOSAVE);
326+
await pause();
327+
expect(server.sent).toHaveLength(0);
328+
});
329+
330+
it('control: a rename does not hold a rule the verdict does not judge', async () => {
331+
mount(objectWith(REFUSED));
332+
fireEvent.click(await screen.findByTestId('data-tab-flat-rules'));
333+
fireEvent.click(await screen.findByText('Status set'));
334+
await screen.findByDisplayValue('x');
335+
336+
fireEvent.change(screen.getByDisplayValue('status_set'), { target: { value: 'status_needed' } });
337+
338+
// The refused rule beside it was never opened, so nothing holds this edit.
339+
await waitFor(() => expect(server.sent).toHaveLength(1), AUTOSAVE);
340+
const sent = server.sent[0]!.validations as Array<{ name?: string }>;
341+
expect(sent[0]!.name).toBe('status_needed');
342+
});
343+
});

‎ui/packages/app-shell/src/views/studio-design/ObjectValidationsPanel.tsx‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,30 @@ export function ObjectValidationsPanel({
992992
* never opens is never counted. Strictly better than no gate, and the
993993
* mechanical scope the #4527 phase-2 ruling asked for. */
994994
const [celErrors, setCelErrors] = React.useState<Record<string, number>>({});
995+
// objectstack#27482 — a rename moves the rule's verdict to its new name. The
996+
// guard's editor reports only when its count CHANGES, so a verdict left under
997+
// the old name is pruned below and never reported again: a rule whose name
998+
// follows its message would autosave a guard the server refuses. A report
999+
// still in flight under the old name (the editor's effect ran on the render
1000+
// before the rename) follows the rename too.
1001+
const renamedTo = React.useRef(new Map<string, string>());
9951002
const reportCel = React.useCallback((ruleName: string, count: number) => {
996-
setCelErrors((prev) => (prev[ruleName] === count ? prev : { ...prev, [ruleName]: count }));
1003+
let name = ruleName;
1004+
for (const seen = new Set<string>(); renamedTo.current.has(name) && !seen.has(name); ) {
1005+
seen.add(name);
1006+
name = renamedTo.current.get(name)!;
1007+
}
1008+
setCelErrors((prev) => (prev[name] === count ? prev : { ...prev, [name]: count }));
1009+
}, []);
1010+
const renameCel = React.useCallback((from: string, to: string) => {
1011+
if (from === to) return;
1012+
renamedTo.current.delete(to);
1013+
renamedTo.current.set(from, to);
1014+
setCelErrors((prev) => {
1015+
if (!Object.prototype.hasOwnProperty.call(prev, from)) return prev;
1016+
const { [from]: count, ...rest } = prev;
1017+
return { ...rest, [to]: count };
1018+
});
9971019
}, []);
9981020
const liveRuleNames = React.useMemo(
9991021
() => new Set(rules.map((r) => r.name ?? '')),
@@ -1059,6 +1081,7 @@ export function ObjectValidationsPanel({
10591081
};
10601082

10611083
const patchRule = (name: string, patch: Partial<ValidationRuleDraft>) => {
1084+
if (typeof patch.name === 'string') renameCel(name, patch.name);
10621085
const pending = unsaved.find((r) => r.name === name);
10631086
if (pending) {
10641087
settleUnsaved(name, { ...pending, ...patch });
@@ -1069,6 +1092,8 @@ export function ObjectValidationsPanel({
10691092

10701093
/** Put a new rule in place: written when it lacks nothing, held otherwise (objectui#11820, objectstack#26731). */
10711094
const placeNewRule = (rule: ValidationRuleDraft) => {
1095+
// A new rule may take a name a rename left: its reports are its own.
1096+
if (rule.name) renamedTo.current.delete(rule.name);
10721097
if (rule.name) derivedNames.current.add(rule.name);
10731098
if (missingPart(rule) === null) commit([...rules, rule]);
10741099
else setUnsaved((prev) => [...prev, rule]);

‎ui/packages/i18n/src/namespaces/studio/en.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const STUDIO_EN: Record<string, string> = {
146146
'perm.cel.type.unknown': 'Unknown',
147147
'perm.cel.type.unknownHint':
148148
'the engine cannot prove a single type. Wrap operands in double() / int() / string() to pin it — only proven-Number formulas are offered as dataset measures.',
149-
'perm.cel.saveBlocked': 'Fix the CEL syntax errors before saving.',
149+
'perm.cel.saveBlocked': 'Fix the expression errors before saving.',
150150
// The editor's inspector-blocked Save title (objectui#6900, ruling 5831744213):
151151
// that channel carries more than CEL faults, so its copy names no one kind.
152152
'perm.inspector.saveBlocked': 'Fix the issues shown in the inspector before saving.',

‎ui/packages/i18n/src/namespaces/studio/zh.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const STUDIO_ZH: Record<string, string> = {
133133
'perm.cel.type.unknown': '未知',
134134
'perm.cel.type.unknownHint':
135135
'引擎无法证明唯一类型。用 double() / int() / string() 包裹操作数以固定类型——只有可证明为数字的公式才能作为数据集度量。',
136-
'perm.cel.saveBlocked': '请先修复 CEL 语法错误再保存。',
136+
'perm.cel.saveBlocked': '请先修复表达式错误再保存。',
137137
// objectui#6900 — 见英文表同名条目。
138138
'perm.inspector.saveBlocked': '请先修复检查器中列出的问题再保存。',
139139
'perm.cel.test.title': '测试策略',

0 commit comments

Comments
 (0)