Skip to content

Commit 4c5023a

Browse files
fix(ui-core): read a bare-string predicate as CEL shorthand, as the spec and server do (#27584)
domain:ui#1 · os-sales · session_01L6bhgXU26UBEjd1KKHgNEx <!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu7yHaRjPxrzzz1THaFZtY5c)_ Fixes #27457 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: follow-up #27587 ## 维护者速读 - 改了什么:控制台把「裸字符串」谓词(导航 `visible`、页面 `visibleWhen`、动作 `visible`/`disabled` 等)当作 CEL 求值,与 `{ dialect: 'cel' }` 信封走同一个引擎;只有 `${…}` 模板仍走旧 JS 求值器。 - 为什么改:spec 把裸字符串定义为 CEL 简写,服务端也按 CEL 读;控制台却按旧 JS 语法读,`'org_owner' in current_user.positions`、`size(page.items) > 0` 这类 CEL 写法在控制台报错,导航项对所有人隐藏、页面区块不渲染(ADR-0032:只有一种表达式语言)。 - 风险与回滚:只依赖 JS 语法的裸字符串谓词(`===`、`.includes()`、`.length`、读不存在的 `data.*` 键)现在会故障并按各入口原有故障策略处理(导航/显示门隐藏,`disabled` 置为禁用);仓内无此类已编写元数据(实测见下)。回滚即 revert 本 PR。 - 先看:`ui/packages/core/src/evaluator/ExpressionEvaluator.ts`(`if (!unwrappedEnvelope)` 分支)、`ui/packages/core/src/evaluator/predicateInput.ts`(字符串分支)、`ui/packages/core/src/evaluator/listConditional.ts`(行谓词路由)。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/providers/__tests__/navigationVisibility.bareCel-27457.test.ts packages/react/src/__tests__/SchemaRenderer.bareCelVisibleWhen-27457.test.tsx`,预期 8 个测试全绿。 - 需要你做的:无,席位落地。 ## What changes The spec defines a bare string in a predicate slot as shorthand for `{ dialect: 'cel', source }` (`ExpressionInputSchema` / `EvaluatedExpressionInputSchema`), and the server reads it that way. The console read it on the legacy JS grammar, so a CEL-only predicate faulted: a nav entry `visible: "'org_owner' in current_user.positions"` was withheld from everyone, and a page block `visibleWhen: "size(page.items) > 0"` never rendered, while the same source as an envelope worked. - `ExpressionEvaluator.evaluateCondition` (`@object-ui/core`): a bare string now takes the CEL route (`evaluateCelCondition`), the same one a `cel` envelope takes, with the same `onFault` / `throwOnError` policy. Only a `${…}` template and the `source` of an envelope whose dialect is not `cel` stay on the legacy path. - `toPredicateInput`: a bare string normalizes to `{ dialect: 'cel', source }` instead of being wrapped as `${…}`; an already-`${…}` string is returned untouched as before. - `evalRowPredicate` (`listConditional.ts`): only a `${…}` template is routed to the legacy engine; every other bare string is CEL. The one-time legacy-syntax warning still fires for any legacy marker. - Comment-only updates in `ExpressionProvider.tsx` and `SchemaRenderer.tsx` where they described the old bare-string route. Why this is the normalization point: `evaluateCondition` is the single funnel every console predicate reader reaches (SchemaRenderer, ExpressionProvider's nav and visibility gates, ActionEngine, the hooks), and several of them hand it the authored value without normalizing first. Reading the bare string there is the console's equivalent of the server's `normalizeExpression` input step; `toPredicateInput` emits the same envelope for the callers that normalize first, so both orders reach one engine. No legacy path remains for the shorthand. Branch name: this card was worked in a platform-assigned card-thread branch (`claude/project-thread-054wyf`), not the `claude/issue-27457-SLUG` shape; the claim names this branch. ## Tests - New acceptance tests: - `app-shell/src/providers/__tests__/navigationVisibility.bareCel-27457.test.ts`: the nav `visible` bare string `'org_owner' in current_user.positions` is true for the holder and false for the member, with no fault line; the envelope control reaches the same verdicts; `evaluateVisibility` agrees; a legacy-only `===` spelling is withheld with one report, and its `==` control is shown. - `react/src/__tests__/SchemaRenderer.bareCelVisibleWhen-27457.test.tsx`: page `visibleWhen` `size(page.items) > 0` is shown with items and hidden without, `'org_owner' in current_user.positions` shows the holder and hides the member, the envelope control agrees, and a legacy-only `===` spelling is withheld with one report. - Pin sweep: every pin of the "bare strings stay legacy" window was flipped to assert the CEL verdict substantively (fault reason text, report count, shown/hidden state): `ActionEngine.visibility`, `ActionRunner.disabledGate`, `declaredPredicate`, `predicateInput`, `listConditional`, `actionPredicate.parity`, `useExpression`, `record-alert.rowBinding`, `record-block-record-reach`, `SchemaRenderer.nodeGateDataPredicate`, `SchemaRenderer.productionPredicateFaultWarning`, `SchemaRenderer.disabledGateFaultDiagnostic`, `DeclaredActionsBar`. Legs that pinned the adapter-only `data.*` diagnostic keep their coverage through the `${…}` template spelling, which still reads on the legacy engine. ## Acceptance notes - Narrowing: a bare-string predicate that relies on JS-only syntax (`===`, `!==`, `?.`, `??`, `.includes(…)`, `.length`, or reading a `data.*` key the scope does not hold) now faults instead of evaluating. Measured over the repository: 1604 bare predicate literals, 127 do not parse as CEL; the 54 outside tests are i18n label strings, lint-script fixture prose, regex-escaped zod description examples and one className, none of them an authored predicate. The 73 in tests are fixtures, flipped above where they pinned the legacy reading. The changeset carries a BREAKING note that points authors to the CEL spelling and lists no FROM-to-TO rewrites (ADR-0087 disposition `not-required (no-migration-prescription)`); the per-spelling rewrite guidance lands in the skills under follow-up #27587. - The adapter-only `data.*` diagnostic (objectui#5687) fires only on a clean evaluation, so it is now reached only through `${…}` templates; a bare `data.*` miss reports on the fault leg instead (pinned). - On the `throwOnError` callers (dev-mode visibility gate, `DeclaredActionsBar`), a CEL fault reports the generic `CEL predicate failed to evaluate: SOURCE` line, while `onFault` callers report `[kind] message` (for example `No such key: status`). This split already existed for envelopes and is unchanged here. - In-place fix declared: `ui/packages/core/src/evaluator/listConditional.ts` is outside the claim's listed file surface. Same defect class (its row-predicate router sent bare strings with legacy markers to the JS engine), mechanical, no other claim on the file, same gate families; the ablation below shows its test turns red without it. - Out of scope, not changed: `ExpressionEvaluator.evaluatePlainCondition` still reads a bare string on the legacy path. ## Verification <details><summary>Ablations (each through scripts/ablation-replace.mjs under the verify lock, restored to HEAD after)</summary> - `ExpressionEvaluator.ts` anchor `if (!unwrappedEnvelope) {` replaced with `if (false) {` (legacy route restored): 6 failed, all in the two acceptance files (nav 3, page 3). - `predicateInput.ts` string branch replaced with `return wrapIfBare(value);`: 5 failed across `ActionEngine.visibility`, `declaredPredicate`, `predicateInput`, `useExpression`. - `listConditional.ts` router `source.includes('${')` replaced with `isLegacyDialectSource(source)`: 1 failed (the bare `===` CEL parse-fault report). </details> <details><summary>Local test runs</summary> - `@object-ui/core` plus every edited and new test file, one run under the verify lock: 227 files, 4326 passed, 27 skipped, 2 failed in `SchemaRenderer.nodeGateDataPredicate` (dev-line reason text); those two assertions were corrected and the file re-run: 24/24 passed. - Type-check (`type-check`) of `@object-ui/core`, `@object-ui/react`, `@object-ui/app-shell`, `@object-ui/plugin-detail`, `@object-ui/console`: exit 0. - eslint on changed files: 0 errors. </details> <details><summary>Gates</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 34 commands on this diff; each was run with its exit code recorded, plus `pnpm check:changeset-fixed` for the `.changeset` roster. All 35 exit 0. `--ran` reconciliation: 34 derived, 34 run, 0 NOT-MEASURED, 0 UNRUN. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgVn2m1FLfCPDLtAfE3)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgVn2m1FLfCPDLtAfE3 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent af515db commit 4c5023a

24 files changed

Lines changed: 614 additions & 147 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@object-ui/core': minor
3+
---
4+
5+
fix(core): a bare-string predicate is read as CEL, the way the spec defines it and the server reads it
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: narrowed
9+
10+
`@objectstack/spec` defines a bare string in a predicate slot as shorthand for `{ dialect: 'cel', source }`, and the server evaluates it on CEL. The console read the shorthand on its legacy JavaScript expression grammar instead, so a predicate using CEL-only syntax faulted there: a navigation entry with `visible: "'org_owner' in current_user.positions"` was hidden from everyone (the navigation gate withholds an entry whose predicate faults), and a page block with `visibleWhen: "size(page.items) > 0"` never rendered, while the same source written as an envelope worked.
11+
12+
- `ExpressionEvaluator.evaluateCondition` evaluates a bare string on the canonical `@objectstack/formula` CEL engine, the same route a `{ dialect: 'cel' }` envelope takes, with the same fault policy (`onFault`, `throwOnError`).
13+
- `toPredicateInput` normalizes a bare string into `{ dialect: 'cel', source }`, as the spec's input schema does, instead of wrapping it as a `${…}` template.
14+
- `evalRowPredicate` (list conditional formatting and row-action predicates) keeps only a `${…}` template on the legacy engine; any other bare string is evaluated on CEL. A string with legacy-only syntax still prints the one-time warning that prescribes the CEL spelling.
15+
- Unchanged: a `${…}` template still evaluates on the legacy engine, and so does the `source` of an envelope whose dialect is not `cel`.
16+
17+
**BREAKING**: a bare-string predicate is read on CEL only, as the spec defines it: a predicate that relied on syntax only the legacy JavaScript grammar reads (for example `===`, `.includes(…)`, `.length`, or a read of a `data.*` key the bound scope does not hold) now faults instead of evaluating, and each surface applies its existing fault policy (a navigation entry or a `visible` / `visibleWhen` gate is withheld, a `disabled` gate disables). The server already reads the shorthand as CEL and rejects those spellings, so the console was the only reader that accepted them; measured in this repository, 0 authored predicates outside tests used them. Write such a predicate in CEL, the one predicate language the spec and the server define (ADR-0032).
18+
19+
<!-- adr-0087: not-required (no-migration-prescription) the narrowed spellings were never valid under the protocol: the spec defines a bare string as CEL and the server already evaluated it on CEL and rejected them, so no stored metadata the server accepted changes meaning and there is nothing for objectstack migrate meta to rewrite -->

‎ui/apps/console/src/__tests__/record-block-record-reach.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const PROBE_OBJECT_SCHEMA = {
164164
label: 'Probe Action',
165165
type: 'url',
166166
locations: ['record_header'],
167-
visible: "record.stage === 'qualified'",
167+
visible: "record.stage == 'qualified'",
168168
},
169169
],
170170
};
@@ -254,7 +254,7 @@ const SAMPLE_BY_INPUT: Readonly<Record<string, unknown>> = {
254254
// reach this block" is even askable — an alert with no predicate is
255255
// unconditionally visible and identical for every record, which would be the
256256
// probe answering its own question with a shrug.
257-
visible: "record.stage === 'qualified'",
257+
visible: "record.stage == 'qualified'",
258258
title: 'Probe Alert',
259259
body: 'Probe alert body',
260260
// `record:related_list.add` — spec-valid minimum, i.e. `picker.object` present.

‎ui/packages/app-shell/src/providers/ExpressionProvider.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ function reportAppShellVisibleFault(
551551
* - `{ dialect: 'cel', source }` envelopes — the shape the spec's
552552
* `ExpressionInputSchema` normalizes every authored `visible` string into,
553553
* which is what nav/area items carry after the server serves the app schema
554-
* - bare expression strings (evaluated as one boolean expression)
554+
* - bare expression strings — CEL shorthand by the spec, evaluated on the
555+
* same CEL engine as the envelope (objectstack#27457)
555556
*
556557
* Everything non-literal is delegated to `evaluator.evaluateCondition`, which
557558
* routes CEL envelopes to the canonical `@objectstack/formula` engine. The
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#27457 — a navigation entry's `visible` written as a BARE string
11+
* is CEL, read on the same engine as its `{ dialect: 'cel', source }` envelope.
12+
*
13+
* `@objectstack/spec` declares the nav `visible` slot as
14+
* `EvaluatedExpressionInputSchema`, whose string arm is shorthand for the CEL
15+
* envelope, and its own example is ``'org_admin' in current_user.positions``.
16+
* The app metadata door serves the stored bare string as authored, and the
17+
* console used to read it on the legacy JS grammar, where `in` is not an
18+
* operator: the predicate faulted, and the navigation gate withholds on a fault
19+
* (objectui#12700), so the entry was hidden from everyone, its holder included.
20+
*
21+
* The evaluators are built through the shell's own builder, so the bag is the
22+
* one `ExpressionProvider` publishes.
23+
*/
24+
25+
import { describe, it, expect, vi, beforeEach, afterEach, type MockInstance } from 'vitest';
26+
import { __resetVisibilityPredicateWarnings } from '@object-ui/react';
27+
import {
28+
createExpressionEvaluator,
29+
evaluateNavigationVisibility,
30+
evaluateVisibility,
31+
} from '../ExpressionProvider';
32+
33+
const OWNER = createExpressionEvaluator({ user: { id: 'u1', positions: ['org_owner'] } });
34+
const MEMBER = createExpressionEvaluator({ user: { id: 'u2', positions: ['member'] } });
35+
36+
const SPEC_SHAPE = "'org_owner' in current_user.positions";
37+
38+
let warn: MockInstance<typeof console.warn>;
39+
beforeEach(() => {
40+
__resetVisibilityPredicateWarnings();
41+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
42+
});
43+
afterEach(() => warn.mockRestore());
44+
45+
const appShellLines = () =>
46+
warn.mock.calls.map((c) => String(c[0])).filter((l) => l.includes('app-shell:visible'));
47+
48+
describe('objectstack#27457 — a bare nav `visible` string is CEL', () => {
49+
it('shows the entry to the position holder and withholds it from the member, with no fault', () => {
50+
// The card's reproduction A. Before the fix BOTH answers were `false`:
51+
// `Unexpected token "i"` on the legacy grammar, withheld, and reported.
52+
expect(evaluateNavigationVisibility(SPEC_SHAPE, OWNER)).toBe(true);
53+
expect(evaluateNavigationVisibility(SPEC_SHAPE, MEMBER)).toBe(false);
54+
expect(appShellLines()).toHaveLength(0);
55+
});
56+
57+
it('CONTROL: the envelope spelling reaches the same two verdicts', () => {
58+
const env = { dialect: 'cel', source: SPEC_SHAPE };
59+
expect(evaluateNavigationVisibility(env, OWNER)).toBe(true);
60+
expect(evaluateNavigationVisibility(env, MEMBER)).toBe(false);
61+
});
62+
63+
it('the fail-open gate (`evaluateVisibility`) reads the bare string on CEL too', () => {
64+
// Fail-open answers `true` on a fault, so the MEMBER's `false` is the proof
65+
// that the predicate evaluated rather than faulted.
66+
expect(evaluateVisibility(SPEC_SHAPE, OWNER)).toBe(true);
67+
expect(evaluateVisibility(SPEC_SHAPE, MEMBER)).toBe(false);
68+
expect(appShellLines()).toHaveLength(0);
69+
});
70+
71+
it('a legacy-only bare spelling has no JS reading any more: it faults and is withheld, loudly', () => {
72+
// `===` is not CEL, so the holder no longer sees an entry spelled that way;
73+
// the report names the predicate. Its CEL spelling is the paired control.
74+
expect(evaluateNavigationVisibility("current_user.id === 'u1'", OWNER)).toBe(false);
75+
const lines = appShellLines();
76+
expect(lines).toHaveLength(1);
77+
expect(lines[0]).toContain("current_user.id === 'u1'");
78+
expect(lines[0]).toMatch(/WITHHELD/);
79+
expect(evaluateNavigationVisibility("current_user.id == 'u1'", OWNER)).toBe(true);
80+
});
81+
});

‎ui/packages/app-shell/src/views/__tests__/DeclaredActionsBar.test.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,10 @@ describe('DeclaredActionsBar — declared `visible` on a server-declared action
604604
// Phase 2 of the objectui#5330 canon: the row is bound as `record.*` only,
605605
// so `status` is an unknown variable. This leg opts into `throwOnError`, so
606606
// its EXISTING policy is fail-closed: the same verdict on the holding row
607-
// and the failing one, and one console line naming the variable. The
608-
// ungated companion proves the bar rendered.
607+
// and the failing one, and one console line naming the predicate. The
608+
// ungated companion proves the bar rendered. The bare string is CEL
609+
// (objectstack#27457), so the line is the CEL fail-closed probe's, which
610+
// names the predicate rather than the legacy grammar's `is not defined`.
609611
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
610612
try {
611613
const gated = { ...APPROVE, visible: 'status == "pending"' };
@@ -620,7 +622,7 @@ describe('DeclaredActionsBar — declared `visible` on a server-declared action
620622
.map((c) => String(c[0]))
621623
.filter((m) => m.includes('was hidden/disabled: its predicate threw'));
622624
expect(reports).toHaveLength(1);
623-
expect(reports[0]).toContain('status is not defined');
625+
expect(reports[0]).toContain('CEL predicate failed to evaluate: status == "pending"');
624626
expect(reports[0]).toContain('declared action "approval_approve" (visible)');
625627
} finally {
626628
warn.mockRestore();

‎ui/packages/components/src/__tests__/page-header-predicate-dialect.test.tsx‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
* Failed to evaluate expression 'record.f_date < today()':
2525
* "today" is not a function
2626
*
27-
* These tests pin the three families from the issue plus the fallback that
28-
* keeps the switch non-breaking: a legacy-dialect string (`${…}`, `===`,
29-
* `.includes()`) still routes to the old evaluator with its deprecation
27+
* These tests pin the three families from the issue plus the fallback: a
28+
* `${…}` template still routes to the old evaluator with its deprecation
3029
* warning, and a predicate that genuinely cannot be evaluated still fails
31-
* CLOSED, once, with the action named.
30+
* CLOSED, once, with the action named. A BARE string with legacy-only syntax
31+
* (`===`, `.includes()`) used to fall back too; it is CEL now, as the spec
32+
* defines the shorthand (objectstack#27457), so it faults and fails closed —
33+
* the deprecation warning still names the CEL spelling.
3234
*/
3335

3436
import { describe, it, expect, vi, beforeEach } from 'vitest';
@@ -247,7 +249,7 @@ describe('page:header — CEL-only constructs in action predicates (#3521)', ()
247249
});
248250
});
249251

250-
describe('page:header — legacy dialect still falls back (#3521)', () => {
252+
describe('page:header — only the `${…}` template falls back to the legacy dialect (#3521, objectstack#27457)', () => {
251253
let warn: ReturnType<typeof vi.spyOn>;
252254
beforeEach(() => {
253255
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
@@ -271,20 +273,34 @@ describe('page:header — legacy dialect still falls back (#3521)', () => {
271273
expect(shown()).toBe(false);
272274
});
273275

274-
it('evaluates a bare `===` predicate on the legacy engine', () => {
276+
it('a bare `===` predicate is CEL (objectstack#27457): it faults and fails closed, and still warns with the CEL spelling', () => {
275277
renderHeader({ name: 'zoo_legacy_strict_eq', visible: 'record.f_status === "open"' });
276-
expect(shown()).toBe(true);
278+
expect(shown()).toBe(false);
277279
expect(legacyWarnings().length).toBeGreaterThan(0);
280+
cleanup();
281+
// CONTROL: the CEL spelling of the same predicate holds on the same record.
282+
renderHeader({ name: 'zoo_cel_eq', visible: 'record.f_status == "open"' });
283+
expect(shown()).toBe(true);
278284
});
279285

280-
it('evaluates a JS-only method (`.includes()`) on the legacy engine', () => {
286+
it('a bare JS-only method (`.includes()`) is CEL too: no such method, so it faults and fails closed', () => {
281287
renderHeader({ name: 'zoo_legacy_includes', visible: 'record.f_textarea.includes("urgent")' });
288+
expect(shown()).toBe(false);
289+
cleanup();
290+
// CONTROL: CEL's `contains` reads the same field and holds.
291+
renderHeader({ name: 'zoo_cel_contains', visible: 'record.f_textarea.contains("urgent")' });
282292
expect(shown()).toBe(true);
283293
});
284294

285-
it('routes a legacy `disabled` predicate the same way', () => {
286-
renderHeader({ name: 'zoo_legacy_disabled', disabled: 'record.f_status === "open"' });
295+
it('a bare legacy `disabled` predicate faults the same way, and the disabled gate fails closed (disabled)', () => {
296+
renderHeader({ name: 'zoo_legacy_disabled', disabled: 'record.f_status === "closed"' });
297+
// `=== "closed"` is false on this record, so the legacy reading enabled the
298+
// button; the CEL fault disables it.
287299
expect(button()).toBeDisabled();
300+
cleanup();
301+
// CONTROL: the CEL spelling evaluates to false and leaves the button enabled.
302+
renderHeader({ name: 'zoo_cel_disabled', disabled: 'record.f_status == "closed"' });
303+
expect(button()).not.toBeDisabled();
288304
});
289305
});
290306

‎ui/packages/core/src/actions/__tests__/ActionEngine.visibility.test.ts‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,36 @@ describe('ActionEngine.getActionsForLocation — visibility filter', () => {
261261
}
262262
});
263263

264-
it('keeps the bare-string predicate on the legacy JS path (no regression)', () => {
265-
// The same predicate text as a bare string is NOT a CEL envelope, so it
266-
// stays on the legacy `${…}` path — `null < null` is `false` there, so
267-
// the action shows. This is the assertion that makes the case above a
268-
// real engine discriminator rather than a predicate that hides anyway.
264+
it('routes the bare-string spelling to CEL too — it is the envelope\'s shorthand (objectstack#27457)', () => {
265+
// The spec defines a bare string as `{ dialect: 'cel', source }`
266+
// shorthand, so the same text as a bare string reaches the SAME verdict
267+
// as its envelope above: the null comparison faults on CEL and the
268+
// fail-closed gate hides. It used to stay on the legacy `${…}` path,
269+
// where `null < null` is `false` and the action showed.
270+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
271+
try {
272+
const engine = new ActionEngine(NULLS);
273+
engine.registerAction(
274+
{ name: 'bare_nulls', type: 'api', visible: NULL_PRED } as any,
275+
{ locations: ['record_section'] },
276+
);
277+
expect(engine.getActionsForLocation('record_section')).toHaveLength(0);
278+
const hits = warn.mock.calls.filter(c => String(c[0]).includes('bare_nulls'));
279+
expect(hits).toHaveLength(1);
280+
expect(String(hits[0][0])).toContain(NULL_PRED);
281+
} finally {
282+
warn.mockRestore();
283+
}
284+
});
285+
286+
it('keeps a `${…}` template on the legacy JS path (the discriminator\'s control)', () => {
287+
// The template spelling is not CEL shorthand and still reads on the
288+
// legacy engine — `null < null` is `false` there, so the action shows.
289+
// This is what makes the two cases above a real engine discriminator
290+
// rather than a predicate that hides anyway.
269291
const engine = new ActionEngine(NULLS);
270292
engine.registerAction(
271-
{ name: 'js_nulls', type: 'api', visible: NULL_PRED } as any,
293+
{ name: 'js_nulls', type: 'api', visible: `\${${NULL_PRED}}` } as any,
272294
{ locations: ['record_section'] },
273295
);
274296
expect(engine.getActionsForLocation('record_section').map(a => a.name)).toEqual(['js_nulls']);

‎ui/packages/core/src/actions/__tests__/ActionRunner.disabledGate.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,14 @@ describe('why the gate cannot delegate "is there a condition?" to the verdict (o
328328
it('toPredicateInput collapses the EMPTY shapes and passes the BLANK ones through', () => {
329329
// Why the gate is not simply `toPredicateInput(x) !== undefined`: blank
330330
// predicate text survives normalization as an evaluable-looking value in both
331-
// its spellings — a wrapped template for the bare string, an intact envelope
332-
// for a blank `source` — so the shared definition names blankness explicitly
331+
// its spellings — a `cel` envelope for the bare string (objectstack#27457:
332+
// it is CEL shorthand), an intact envelope for a blank `source` — so the
333+
// shared definition names blankness explicitly
333334
// (objectui#3960; the same blank rule `evalRowPredicate` applies in
334335
// `evaluator/listConditional.ts`).
335336
expect(toPredicateInput('')).toBeUndefined();
336337
expect(toPredicateInput({ dialect: 'cel', source: '' })).toBeUndefined();
337-
expect(toPredicateInput(' ')).toBe('${ }');
338+
expect(toPredicateInput(' ')).toEqual({ dialect: 'cel', source: ' ' });
338339
expect(toPredicateInput({ dialect: 'cel', source: ' ' })).toEqual({ dialect: 'cel', source: ' ' });
339340
});
340341

‎ui/packages/core/src/evaluator/ExpressionEvaluator.ts‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ export class ExpressionEvaluator {
360360
// engine (the one `fieldRules` / list conditionals already use), NOT the legacy
361361
// JS evaluator below. This makes a component / action `visible` / `disabled`
362362
// predicate reach the SAME verdict as server enforcement — including CEL-only
363-
// behavior like `record.due_date == today()` (framework#3205). Bare strings and
364-
// `${…}` templates stay on the legacy path (back-compat deprecation window);
365-
// only an explicit `{ dialect: 'cel' }` envelope is rerouted.
363+
// behavior like `record.due_date == today()` (framework#3205). A BARE string
364+
// takes the same route further down (objectstack#27457); only a `${…}`
365+
// template, and an envelope of another dialect, stay on the legacy path.
366366
if (
367367
condition && typeof condition === 'object'
368368
&& (condition as { dialect?: string }).dialect === 'cel'
@@ -371,9 +371,14 @@ export class ExpressionEvaluator {
371371
return this.evaluateCelCondition((condition as { source: string }).source, options);
372372
}
373373

374-
// Unwrap Expression envelope (see `evaluate` for rationale).
374+
// Unwrap Expression envelope (see `evaluate` for rationale). Only an
375+
// envelope of a dialect other than `cel` gets here (a `cel` one with a
376+
// string `source` was routed above); its `source` keeps the legacy reading
377+
// below, which is why the unwrap is remembered.
378+
let unwrappedEnvelope = false;
375379
if (condition && typeof condition === 'object' && typeof (condition as any).source === 'string') {
376380
condition = (condition as any).source as string;
381+
unwrappedEnvelope = true;
377382
}
378383

379384
// A BLANK gate — `''`, whitespace-only text, or an envelope whose `source`
@@ -413,6 +418,26 @@ export class ExpressionEvaluator {
413418
if (trimmed.includes('${')) {
414419
return Boolean(this.evaluate(trimmed, options));
415420
}
421+
422+
// objectstack#27457 — a BARE string is CEL. `@objectstack/spec` defines it
423+
// as shorthand for `{ dialect: 'cel', source }` (the string arm of
424+
// `ExpressionInputSchema` / `EvaluatedExpressionInputSchema`), and the
425+
// server reads it that way, so the console reads it on the same engine
426+
// (ADR-0032, one CEL language) instead of keeping a second grammar for the
427+
// shorthand. Raw authored values reach this method unnormalized — a page
428+
// node's `visibleWhen` from `SchemaRenderer`, a nav entry's `visible` from
429+
// app-shell's `ExpressionProvider` — so the shorthand is resolved HERE, at
430+
// the one evaluator every predicate reaches, and `toPredicateInput` emits
431+
// the envelope for the callers that normalize first. Before, a CEL-only
432+
// predicate (`'org_owner' in current_user.positions`, `size(page.items) > 0`)
433+
// faulted on the legacy grammar and its gate failed closed for everyone.
434+
if (!unwrappedEnvelope) {
435+
return this.evaluateCelCondition(trimmed, options);
436+
}
437+
438+
// What is left is the `source` of an envelope whose dialect is not `cel`
439+
// (a `template` one, or one naming no dialect at all): neither is a CEL
440+
// predicate by the spec, so neither is moved by the line above.
416441
try {
417442
return Boolean(this.evaluateExpression(trimmed, { sanitize: options.sanitize !== false }));
418443
} catch (error) {

0 commit comments

Comments
 (0)