Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 1bd79c8

Browse files
claude[bot]claude
andauthored
fix(core): declare the field-rule fault directions, and stop a blank predicate defaulting in silence (objectui#8069) (#8904)
* docs(core): name the three field-rule FAULT directions and the four other fallback policies (objectui#8069) `resolveFieldRuleState` handed `evalFieldPredicate` three bare positional booleans — `true` / `false` / `false` — and answered the adjacent "no rule declared" case with the SAME literal, so each permissive value was written twice and nothing in the source said which of the two questions either copy answered. Zero behaviour change, and the values are untouched. Six module-private constants now spell the two questions apart (`*_WHEN_FAULTED` vs `*_WHEN_ABSENT`) and carry, in one place, what the direction is, that the three faults compose rather than cancel, and what the history does and does not record about why they point that way (objectui#1578 and ADR-0036 record a per-key "a fault is safe" rationale; no commit puts the case where all three faults arrive from one typo). `evalFieldPredicate`'s docblock gains the call-site policy table: five distinct fault policies share this one helper, two of which — `evalCel` and `ExpressionEvaluator.evaluateCelCondition` under `throwOnError` — detect a fault by calling it twice with OPPOSITE fallbacks, and therefore depend on `fallback` staying freely specifiable. Part of objectui#8069. Q2 (does the direction belong in the authored contract) and Q3 (a loud-but-safe middle) stay undecided; no fallback value moves here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01611D6ZaRaMmwTNQmSbk8MH * fix(core): a declared-but-blank field-rule predicate is no longer silent (objectui#8069) `''` and `' '` are authorable — `ExpressionWireSchema` is a bare `z.string()` with no `.min(1)`, and `resolveFieldRuleState`'s guard is `!= null`, so a blank predicate passes both. `evalFieldPredicate` then returned the caller's permissive fallback on its first line, BEFORE `warnPredicateFailure` or `onFault` could fire. That is a third state, not a spelling of either neighbour: the key is present (so it is not "the author wrote no rule") and nothing evaluates (so no engine fault is raised). The one state an author reaches by starting a rule and not finishing it was the one state that said nothing at all — the exact silence objectui#4051 / objectstack#5149 ruled out for every other fault. Both spellings now report `[blank] the predicate is declared but empty — nothing to evaluate` through the same single reporting site as every other fault, on both channels (the built-in warning and the `onFault` passback, so the fault-probing callers that pass `warn: false` are not silenced either). Every verdict is unchanged, the envelope spelling included: `{ source: '' }` used to reach the engine and come back "AST-only evaluation not yet supported; persist `source`" and `{ source: ' ' }` "Unexpected token: EOF" — two misleading reasons for one author mistake, both already resolving to the same fallback this keeps. Blankness is decided by `isBlankPredicateText` (`evaluator/declaredPredicate.ts`), the repo's one definition of that question since objectui#3960, exported for this second consumer rather than copied — a fourth local `trim()` here is the drift it was consolidated to stop. For this one fault class the once-per-predicate dedupe key joins the caller's LOCATOR: a blank predicate has no distinguishing text, so every blank rule in an app shares the key `""` and the first would silence every other author's. Non-blank keys are unchanged. Part of objectui#8069. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01611D6ZaRaMmwTNQmSbk8MH * fix(core): the blank dedupe key reads an OPTIONAL `Expression['source']` (objectui#8069) `tsc --noEmit` on a built workspace: `expr.source` is `string | undefined` in the spec, so calling `.trim()` on it is TS18048. The absent case is blank by the same rule as a whitespace-only one and lands in the same locator-joined key shape. Part of objectui#8069. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01611D6ZaRaMmwTNQmSbk8MH --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5b6deed commit 1bd79c8

4 files changed

Lines changed: 437 additions & 31 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
'@object-ui/core': minor
3+
---
4+
5+
A field-rule predicate the author **declared and left blank** is no longer silent, and the
6+
three fault directions in `resolveFieldRuleState` are now named and documented instead of
7+
being bare positional booleans (objectui#8069). **No fallback value moves.**
8+
9+
**The blank hole.** `''` and `' '` are authorable — `ExpressionWireSchema` is a bare
10+
`z.string()` with no `.min(1)`, and `resolveFieldRuleState`'s own guard is `!= null`, so a
11+
blank predicate passes both. `evalFieldPredicate` then returned the caller's fallback on its
12+
first line, *before* `warnPredicateFailure` or `onFault` could fire. That is a third state,
13+
not a spelling of either neighbour: the key is present (so it is not "the author wrote no
14+
rule") and nothing evaluates (so no engine fault is raised). The one state an author reaches
15+
by *starting* a rule and not finishing it was the one state that said nothing at all — which
16+
is exactly what objectui#4051 / objectstack#5149 ruled out for every other fault.
17+
18+
Both spellings now report `[blank] the predicate is declared but empty — nothing to evaluate`
19+
through the same single reporting site as every other fault, on both channels (the built-in
20+
`console.warn` and the `onFault` passback, so the fault-probing callers that pass
21+
`warn: false` are not silenced either). **Every verdict is unchanged**, including the
22+
envelope spelling: `{ source: '' }` used to reach the engine and come back
23+
"AST-only evaluation not yet supported; persist `source`" and `{ source: ' ' }`
24+
"Unexpected token: EOF" — two misleading reasons for one author mistake, both already
25+
resolving to the same fallback this change keeps. Blankness is decided by
26+
`isBlankPredicateText` (`evaluator/declaredPredicate.ts`), the repo's one definition of that
27+
question since objectui#3960, now exported for this second consumer rather than copied.
28+
29+
For this one fault class the once-per-predicate dedupe key joins the caller's **locator**: a
30+
blank predicate has no distinguishing text, so every blank rule in an app shares the key
31+
`""` and the first one would silence every other author's. Non-blank keys are unchanged.
32+
33+
**The named directions.** `resolveFieldRuleState` passed `true` / `false` / `false` as bare
34+
third arguments and answered the adjacent "no rule declared" case with the *same* literal —
35+
so every permissive value was written twice, and the "the rule broke" answer was chosen by
36+
aligning it with the "the rule is absent" answer beside it. Six module-private constants now
37+
spell the two questions apart (`*_WHEN_FAULTED` / `*_WHEN_ABSENT`), with one docblock
38+
recording the direction, the fact that all three point the permissive way so a single
39+
mistyped column yields a form that shows more, locks less and demands less at once, and what
40+
the history does and does not record about why (objectui#1578 and ADR-0036 both carry a
41+
per-key "a fault is safe" rationale; no commit puts the case where all three faults arrive
42+
from one typo). `evalFieldPredicate`'s docblock gains the call-site policy table — five
43+
distinct fault policies share this one helper, two of which detect a fault by calling it
44+
twice with *opposite* fallbacks and therefore depend on `fallback` staying freely
45+
specifiable.
46+
47+
Whether the direction belongs in the authored contract, and whether a loud-but-safe middle
48+
should exist, remain open on objectui#8069.

‎packages/core/src/evaluator/__tests__/fieldRules.test.ts‎

Lines changed: 190 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,15 @@ describe('failure diagnostics — loud fail-open (objectstack#5149, appeal 2)',
248248
expect(String(warn.mock.calls[0][0])).toContain(JSON.stringify(pred));
249249
});
250250

251-
it('does not warn for a healthy, absent, or blank predicate', () => {
251+
// A BLANK predicate used to be listed here too — it was the negative
252+
// baseline objectui#8069 measured, and it is now loud; the case moved to the
253+
// blank-predicate describe below rather than being edited in place, because
254+
// what it pinned is the branch that card removes. An ABSENT predicate keeps
255+
// its silence: nothing was authored, so there is nothing to report.
256+
it('does not warn for a healthy or absent predicate', () => {
252257
expect(evalFieldPredicate("record.ok_5149 == 'y'", { ok_5149: 'y' }, false)).toBe(true);
253258
expect(evalFieldPredicate(undefined, {}, true)).toBe(true);
254259
expect(evalFieldPredicate(null, {}, false)).toBe(false);
255-
expect(evalFieldPredicate(' ', {}, true)).toBe(true);
256260
expect(warn).not.toHaveBeenCalled();
257261
});
258262

@@ -356,3 +360,187 @@ describe('failure diagnostics — loud fail-open (objectstack#5149, appeal 2)',
356360
expect(String(warn.mock.calls[0][0])).toContain('[throw] engine exploded');
357361
});
358362
});
363+
364+
/**
365+
* objectui#8069, deliverable 1. The three fault directions are now named
366+
* constants; these pin the VALUES through the public surface, so a future edit
367+
* that moves one goes red here instead of shipping. ⛔ They are not an
368+
* endorsement of the direction — that is the card's open question. Each case
369+
* pairs the FAULTED verdict with the ABSENT one to keep visible the fact the
370+
* card turns on: the two questions have equal answers today, and only because
371+
* one was copied from the other.
372+
*/
373+
describe('fault directions — what a BROKEN rule decides (objectui#8069)', () => {
374+
let warn: ReturnType<typeof vi.spyOn>;
375+
beforeEach(() => {
376+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
377+
});
378+
afterEach(() => warn.mockRestore());
379+
380+
const broken = 'unbound_direction_8069 ==';
381+
382+
it('a faulted visibleWhen SHOWS the field — same verdict as no visibleWhen at all', () => {
383+
expect(resolveFieldRuleState({ visibleWhen: broken }, {}, {}).visible).toBe(true);
384+
expect(resolveFieldRuleState({}, {}, {}).visible).toBe(true);
385+
});
386+
387+
it('a faulted readonlyWhen leaves the field EDITABLE — same verdict as no readonlyWhen', () => {
388+
expect(resolveFieldRuleState({ readonlyWhen: broken }, {}, {}).readonly).toBe(false);
389+
expect(resolveFieldRuleState({}, {}, {}).readonly).toBe(false);
390+
});
391+
392+
it('a faulted requiredWhen demands NOTHING — same verdict as no requiredWhen', () => {
393+
expect(resolveFieldRuleState({ requiredWhen: broken }, {}, {}).required).toBe(false);
394+
expect(resolveFieldRuleState({}, {}, {}).required).toBe(false);
395+
});
396+
397+
it('all three compose from ONE broken predicate: shows more, locks less, demands less', () => {
398+
// The card's thesis in one assertion — the three faults do not cancel.
399+
expect(
400+
resolveFieldRuleState(
401+
{ visibleWhen: broken, readonlyWhen: broken, requiredWhen: broken },
402+
{},
403+
{},
404+
),
405+
).toEqual({ visible: true, readonly: false, required: false });
406+
});
407+
});
408+
409+
/**
410+
* objectui#8069, deliverable 2. A predicate the author DECLARED and left blank
411+
* is a third state: the key is present, so it is not "no rule", and nothing
412+
* evaluates, so no engine fault is raised. It used to return the permissive
413+
* fallback before any warning could fire — silent, which is the one thing
414+
* objectui#4051 / objectstack#5149 ruled out. The VERDICT is deliberately
415+
* unchanged; only the silence is.
416+
*
417+
* Every case below uses a UNIQUE context locator: for this class the locator
418+
* joins the once-per-predicate dedupe key (a blank predicate has no
419+
* distinguishing text), so a reused locator would spend its warning earlier.
420+
*/
421+
describe('blank predicate — declared but empty (objectui#8069)', () => {
422+
let warn: ReturnType<typeof vi.spyOn>;
423+
beforeEach(() => {
424+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
425+
});
426+
afterEach(() => warn.mockRestore());
427+
428+
it('a whitespace-only bare string warns instead of defaulting in silence', () => {
429+
expect(
430+
evalFieldPredicate(' ', {}, true, undefined, undefined, { context: 'blank_ws_8069' }),
431+
).toBe(true);
432+
expect(warn).toHaveBeenCalledTimes(1);
433+
const msg = String(warn.mock.calls[0][0]);
434+
expect(msg).toContain('[blank]');
435+
expect(msg).toContain('blank_ws_8069');
436+
});
437+
438+
it('the empty-string spelling warns too', () => {
439+
expect(evalFieldPredicate('', {}, true, undefined, undefined, { context: 'blank_empty_8069' })).toBe(
440+
true,
441+
);
442+
expect(warn).toHaveBeenCalledTimes(1);
443+
expect(String(warn.mock.calls[0][0])).toContain('[blank]');
444+
});
445+
446+
it('the ENVELOPE spelling reports the same reason, not the engine parse fault it used to', () => {
447+
// Before: `{ source: '' }` reached the engine and came back
448+
// "AST-only evaluation not yet supported; persist `source`", and
449+
// `{ source: ' ' }` came back "Unexpected token: EOF" — two different
450+
// reasons for one author mistake, neither of them naming it.
451+
expect(
452+
evalFieldPredicate({ dialect: 'cel', source: ' ' }, {}, true, undefined, undefined, {
453+
context: 'blank_envelope_8069',
454+
}),
455+
).toBe(true);
456+
const msg = String(warn.mock.calls[0][0]);
457+
expect(msg).toContain('[blank]');
458+
expect(msg).not.toContain('AST-only');
459+
expect(msg).not.toContain('Unexpected token');
460+
});
461+
462+
it('the VERDICT is unchanged — a blank predicate still returns the caller\'s fallback either way', () => {
463+
expect(
464+
evalFieldPredicate(' ', {}, true, undefined, undefined, { context: 'blank_verdict_t_8069' }),
465+
).toBe(true);
466+
expect(
467+
evalFieldPredicate(' ', {}, false, undefined, undefined, { context: 'blank_verdict_f_8069' }),
468+
).toBe(false);
469+
});
470+
471+
it('`onFault` carries the blank reason, so a caller that silenced the warning is not silenced', () => {
472+
// The fault-probing callers (`evalCel`, `ExpressionEvaluator` under
473+
// `throwOnError`) pass `warn: false` and print their own line; without the
474+
// passback a blank predicate would stay silent for exactly those surfaces.
475+
const reasons: string[] = [];
476+
evalFieldPredicate(' ', {}, true, undefined, undefined, {
477+
warn: false,
478+
onFault: (r) => reasons.push(r),
479+
});
480+
expect(warn).not.toHaveBeenCalled();
481+
expect(reasons).toHaveLength(1);
482+
expect(reasons[0]).toContain('[blank]');
483+
});
484+
485+
it('two blank predicates at DIFFERENT locators each warn — text alone would silence the second', () => {
486+
evalFieldPredicate('', {}, true, undefined, undefined, { context: 'blank_site_A_8069' });
487+
evalFieldPredicate('', {}, true, undefined, undefined, { context: 'blank_site_B_8069' });
488+
expect(warn).toHaveBeenCalledTimes(2);
489+
});
490+
491+
it('the SAME blank predicate at the same locator still warns once across re-renders', () => {
492+
const diag = { context: 'blank_rerender_8069' };
493+
evalFieldPredicate(' ', {}, true, undefined, undefined, diag);
494+
evalFieldPredicate(' ', {}, true, undefined, undefined, diag);
495+
evalFieldPredicate(' ', {}, true, undefined, undefined, diag);
496+
expect(warn).toHaveBeenCalledTimes(1);
497+
});
498+
499+
// ── controls: a control that reds when the subject reds is not a control ──
500+
501+
it('control — an ABSENT predicate stays silent and keeps its verdict', () => {
502+
expect(evalFieldPredicate(undefined, {}, true, undefined, undefined, { context: 'absent_8069' })).toBe(
503+
true,
504+
);
505+
expect(evalFieldPredicate(null, {}, false, undefined, undefined, { context: 'absent_8069' })).toBe(
506+
false,
507+
);
508+
expect(warn).not.toHaveBeenCalled();
509+
});
510+
511+
it('control — a HEALTHY predicate is silent and its verdict ignores the fallback', () => {
512+
const pred = "record.state_8069 == 'paid'";
513+
expect(evalFieldPredicate(pred, { state_8069: 'paid' }, false)).toBe(true);
514+
expect(evalFieldPredicate(pred, { state_8069: 'paid' }, true)).toBe(true);
515+
expect(evalFieldPredicate(pred, { state_8069: 'draft' }, true)).toBe(false);
516+
expect(evalFieldPredicate(pred, { state_8069: 'draft' }, false)).toBe(false);
517+
expect(warn).not.toHaveBeenCalled();
518+
});
519+
520+
it('control — a genuinely BROKEN predicate still warns with the engine reason, not [blank]', () => {
521+
const pred = 'still_faults_8069 ==';
522+
expect(evalFieldPredicate(pred, {}, true)).toBe(true);
523+
expect(warn).toHaveBeenCalledTimes(1);
524+
const msg = String(warn.mock.calls[0][0]);
525+
expect(msg).toContain('Reason: [');
526+
expect(msg).not.toContain('[blank]');
527+
});
528+
529+
it('resolveFieldRuleState: a blank visibleWhen is reported with its field locator, verdict unchanged', () => {
530+
const state = resolveFieldRuleState(
531+
{ visibleWhen: ' ' },
532+
{ status: 'x' },
533+
{},
534+
undefined,
535+
undefined,
536+
"field 'amount_8069'",
537+
);
538+
// The `!= null` guard lets `''` / `' '` through — that is how the blank
539+
// reached the permissive fallback in the first place.
540+
expect(state.visible).toBe(true);
541+
expect(warn).toHaveBeenCalledTimes(1);
542+
const msg = String(warn.mock.calls[0][0]);
543+
expect(msg).toContain("visibleWhen of field 'amount_8069'");
544+
expect(msg).toContain('[blank]');
545+
});
546+
});

‎packages/core/src/evaluator/declaredPredicate.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ import { toPredicateInput } from './predicateInput.js';
2525
* return true`), `evalRowPredicate` (`listConditional.ts`) — brought to the one
2626
* place that answers "is there a condition at all?", so the two halves cannot
2727
* disagree about the same blank.
28+
*
29+
* Exported since objectui#8069 for its second consumer, `evalFieldPredicate`
30+
* (`evaluator/fieldRules.ts`), which is the entry this docblock's list did NOT
31+
* name because it did not apply the rule: it trimmed the STRING spelling only,
32+
* so `{ dialect: 'cel', source: ' ' }` went to the engine and came back as a
33+
* parse fault while `' '` returned the caller's fallback in silence. Reusing
34+
* this definition rather than writing a fourth `trim()` is the whole point of
35+
* the paragraph above.
2836
*/
29-
function isBlankPredicateText(value: unknown): boolean {
37+
export function isBlankPredicateText(value: unknown): boolean {
3038
if (typeof value === 'string') return value.trim() === '';
3139
if (value !== null && typeof value === 'object') {
3240
const source = (value as { source?: unknown }).source;

0 commit comments

Comments
 (0)