Skip to content
24 changes: 24 additions & 0 deletions .changeset/39441-validation-condition-option-label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/lint': minor
'@objectstack/spec': minor
---

fix(lint)!: a validation rule whose condition compares a choice field with an option label, where the record holds the option's value, is refused at validate, build and publish

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered validation-condition-option-label-refused -->

**BREAKING** accept-set narrowing. A `select`, `radio`, `multiselect` or `checkboxes` field stores the option's value (`urgent`), never its label (`Urgent`), and a validation rule's condition is evaluated against the stored record as written. So a rule comparing the field with a label never fired (`record.priority == 'Urgent'`, or `in [...]`), and its negated form refused every write, the records holding `urgent` included (`record.priority != 'Urgent'`, `!(record.priority in ['Urgent'])`). Both published with no finding.

- **Now:** `os validate`, `os build` and `os lint` report `validation-condition-option-label` as an error, and the metadata publish door refuses an `object` or `object_extension` publish carrying it with `422 INVALID_METADATA`. The finding names the field, the label written and the value to write. Judged in a rule's `condition` and in a conditional rule's `when`, its `then` / `otherwise` branches included, on the object's own rules and on the rules an object extension adds, for a field read as `record.FIELD` or `previous.FIELD`. The spellings reached: `FIELD == 'L'`, `FIELD != 'L'`, `'L' == FIELD`, `'L' != FIELD`, and each member of `FIELD in [...]` (negated or not).
- **Not refused:** the membership spelling `'L' in FIELD` on a `multiselect` or `checkboxes` field, a label that is also some option's value, a literal that is neither a label nor a value (a stored value may lie outside the options), a `readonly` field, a field bound to a shared picklist or declared by two object extensions, a label holding a quote or a backslash, a predicate in a dialect other than CEL, and a rule switched off with `active: false` (a different, active rule of the same name is still judged).
- **Stored metadata:** a stored object or extension carrying the shape still loads and its rule evaluates as before. Its next publish is refused until the condition is fixed or the rule is switched off.

| Before (refused now) | After |
|:--|:--|
| `condition: "record.priority == 'Urgent' && record.name == null"` | `condition: "record.priority == 'urgent' && record.name == null"` |
| `condition: "record.priority != 'Urgent'"` | `condition: "record.priority != 'urgent'"` |

Fix: write the option's value in place of its label, as the refusal names it; or set `active: false` on the rule.
2 changes: 1 addition & 1 deletion content/docs/deployment/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ os compile --json # JSON output for CI pipelines
→ Normalizing stack definition...
→ Lowering inline handlers...
→ Validating protocol compliance...
→ Running author-time rules (90)...
→ Running author-time rules (91)...
→ Checking that every required capability has a provider installable in this edition...
→ Collecting package docs (ADR-0046)... 0 collected
→ Writing artifact...
Expand Down
2 changes: 1 addition & 1 deletion content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ A clean run walks the registry and reports timing:
Config: /path/to/support-desk/objectstack.config.ts
Load time: 21ms
→ Validating against ObjectStack Protocol...
→ Running author-time rules (90)...
→ Running author-time rules (91)...
→ Checking that every required capability has a provider installable in this edition...
→ Checking package docs (ADR-0046)...
Expand Down
2 changes: 1 addition & 1 deletion content/docs/getting-started/build-with-claude-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ visible: 'status != "resolved"'
◆ Validate
────────────────────────────────────────
→ Validating against ObjectStack Protocol...
→ Running author-time rules (90)...
→ Running author-time rules (91)...
✗ Author-time rules failed (1 issue)
• stack · action 'resolve_ticket' visible: bare reference `status` — a
Expand Down
2 changes: 1 addition & 1 deletion content/docs/ui/react-pages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ objectstack validate
────────────────────────────────────────
→ Loading configuration...
→ Validating against ObjectStack Protocol...
→ Running author-time rules (90)...
→ Running author-time rules (91)...
→ Checking that every required capability has a provider installable in this edition...
→ Checking package docs (ADR-0046)...
Expand Down
25 changes: 25 additions & 0 deletions packages/lint/src/authoring-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ import { validateActionBodyCapabilities } from './validate-action-body-capabilit
import { validateSeedRecordKeys } from './validate-seed-record-keys.js';
import { validateHookAndJobBodyCompiles } from './validate-hook-body-compiles.js';
import { validateRuleSchemaFormats } from './validate-rule-schema-formats.js';
import { validateValidationRuleOptionLabels } from './validate-validation-rule-option-labels.js';
import { validateActionLocations } from './validate-action-locations.js';
import { validateObjectActionLayout } from './validate-object-action-layout.js';
import { validateActionObjectBinding } from './validate-action-object-binding.js';
Expand Down Expand Up @@ -3497,6 +3498,30 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
runtimeTypes: ['object', 'object_extension'],
run: (stack) => validateRuleSchemaFormats(stack),
},
// [#39441] A validation rule's `condition` / `when` that compares a choice
// field with one of its option LABELS where the record holds the VALUE: the
// rule never fires (`==`, `in`) or refuses every write (`!=`, a negated
// `in`). Refused under the sharing-rule sibling's ruling (record
// 7403149741, option A: the label comparand only, the value named), at the
// flow rule's tier for the same mistake (`flow-condition-option-label`,
// `error`), with that rule's label reading (`flow-select-options.ts`) and
// the compile rule's validation-rule walk, so neither is a second copy.
//
// Runtime publish gate on `object` and `object_extension`, as its walk's
// other readers: the door judges the rules the written object or entry
// carries, and the target's own rules the door's live objects carry are
// judged in the baseline too, so an extension write is charged with its
// entry's rules alone. A rule switched off (`active: false`) is not judged.
{
name: 'validateValidationRuleOptionLabels',
tier: 'gating',
input: 'parsed',
commands: ALL,
source: 'packages/lint/src/validate-validation-rule-option-labels.ts',
surfaces: CLI_AND_RUNTIME,
runtimeTypes: ['object', 'object_extension'],
run: (stack) => validateValidationRuleOptionLabels(stack),
},
// [#25189] The email half of #25082 (ruling `6335348115`, F1 A2): a hole an
// email template's `bodyHtml` places where the mail renderer cannot encode
// it for that placement is refused, naming the placement and the supported
Expand Down
9 changes: 9 additions & 0 deletions packages/lint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,15 @@ export type {
WalkedValidationRule,
} from './validate-rule-compilability.js';

// #39441 — a validation rule's predicate comparing a choice field with an
// option LABEL where the record holds the value (never fires, or refuses
// every write when negated).
export {
validateValidationRuleOptionLabels,
VALIDATION_CONDITION_OPTION_LABEL,
} from './validate-validation-rule-option-labels.js';
export type { ValidationRuleOptionLabelFinding } from './validate-validation-rule-option-labels.js';

// #5178 — the residual half #5029's `ajv-formats` registration does not close.
// Under `strict: false` an UNRECOGNISED format name is logged once and the
// keyword is DROPPED, so `format: 'emial'` leaves the rule declared, running on
Expand Down
2 changes: 2 additions & 0 deletions packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ import {
FLOW_APPROVAL_DECISION_UNROUTED_EXPLANATION,
FLOW_TRIGGER_OBJECT_MISSING_EXPLANATION,
FLOW_CONDITION_OPTION_LABEL_EXPLANATION,
VALIDATION_CONDITION_OPTION_LABEL_EXPLANATION,
FLOW_TIME_RELATIVE_SHADOWED_EXPLANATION,
FLOW_TIME_RELATIVE_KEY_MISPLACED_EXPLANATION,
FLOW_TIME_RELATIVE_DATE_FIELD_INVALID_EXPLANATION,
Expand Down Expand Up @@ -730,6 +731,7 @@ export const RULE_EXPLANATIONS: Readonly<Record<string, RuleExplanation>> = Obje
[FLOW_HTTP_TIMEOUT_MISSING_EXPLANATION.rule]: FLOW_HTTP_TIMEOUT_MISSING_EXPLANATION,
[FLOW_TRIGGER_OBJECT_MISSING_EXPLANATION.rule]: FLOW_TRIGGER_OBJECT_MISSING_EXPLANATION,
[FLOW_CONDITION_OPTION_LABEL_EXPLANATION.rule]: FLOW_CONDITION_OPTION_LABEL_EXPLANATION,
[VALIDATION_CONDITION_OPTION_LABEL_EXPLANATION.rule]: VALIDATION_CONDITION_OPTION_LABEL_EXPLANATION,
[FLOW_TIME_RELATIVE_SHADOWED_EXPLANATION.rule]: FLOW_TIME_RELATIVE_SHADOWED_EXPLANATION,
[FLOW_TIME_RELATIVE_KEY_MISPLACED_EXPLANATION.rule]: FLOW_TIME_RELATIVE_KEY_MISPLACED_EXPLANATION,
[FLOW_TIME_RELATIVE_DATE_FIELD_INVALID_EXPLANATION.rule]: FLOW_TIME_RELATIVE_DATE_FIELD_INVALID_EXPLANATION,
Expand Down
22 changes: 22 additions & 0 deletions packages/lint/src/rule-explanations/publish-time-inert-refusals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ export const FLOW_CONDITION_OPTION_LABEL_EXPLANATION: RuleExplanation = {
],
};

export const VALIDATION_CONDITION_OPTION_LABEL_EXPLANATION: RuleExplanation = {
rule: 'validation-condition-option-label',
covers: 'why validation rule conditions use option values',
paragraphs: [
'A select, radio, multiselect or checkboxes field stores the option\'s `value`, never its `label`, and a ' +
'validation rule\'s condition is evaluated against the stored record as written. A rule that compares the ' +
'field with a quoted label (`record.priority == \'Urgent\'` where the option is ' +
'`{ value: \'urgent\', label: \'Urgent\' }`) is false on every record, so the rule never refuses a write. ' +
'Written with `!=` or a negated `in`, it is true on every record, so the rule refuses every write.',
'Reported in a rule\'s `condition` and in a conditional rule\'s `when`, its `then` and `otherwise` branches ' +
'included, on the object\'s own rules and on the rules an object extension adds. Only when the label is ' +
'the comparand of that field: `F == \'L\'`, `F != \'L\'`, `\'L\' == F`, `\'L\' != F`, or a member of ' +
'`F in [...]`, with `F` read as `record.F` or `previous.F`. The membership spelling `\'L\' in F` on a ' +
'multiselect or checkboxes field is not read.',
'Not reported: a label that is also some option\'s value, a literal that is neither a label nor a value ' +
'(a stored value may lie outside the options), a readonly field, a field whose options come from a shared ' +
'picklist or that two object extensions both declare, a label holding a quote or a backslash, a predicate ' +
'in a dialect other than CEL, and a rule switched off with `active: false`. Write the option\'s value in ' +
'place of the label.',
],
};

export const FLOW_TIME_RELATIVE_SHADOWED_EXPLANATION: RuleExplanation = {
rule: 'flow-time-relative-shadowed',
covers: 'which trigger wins on a start with both',
Expand Down
4 changes: 2 additions & 2 deletions packages/lint/src/runtime-gate.object-formula-writes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe('#33072 — the object_extension door judges an extension field\'s form
it('`validateStackExpressions` is on the object_extension door, beside the vocabulary freeze', () => {
// [#33217] And the two validation-rule artifact checks (regex, JSON schema).
expect(runtimeAuthoringRulesFor('object_extension').map((r) => r.name))
.toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats']);
.toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats', 'validateValidationRuleOptionLabels']);
});

it('⭐ LIT — an extension formula calling an unregistered function (`sqrt`) is REFUSED, at the entry the build names', () => {
Expand Down Expand Up @@ -422,7 +422,7 @@ describe('#33072 — the object_extension door judges an extension field\'s form
const result = gateExtension(item);
expect(result.errors, dump(result)).toEqual([]);
expect(result.advisories, dump(result)).toEqual([]);
expect(result.rulesRun).toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats']);
expect(result.rulesRun).toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats', 'validateValidationRuleOptionLabels']);
}
});

Expand Down
5 changes: 5 additions & 0 deletions packages/lint/src/runtime-gate.object-writes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ describe('the object write door dispatches at the adjudicated scope (#4716)', ()
// `validate-action-body-capabilities.test.ts`.
'validateActionBodyCapabilities',
'validateRuleSchemaFormats',
// [#39441] A validation rule's predicate comparing a choice field with an
// option label: the object write carries the rules it judges. Door cases
// in `validate-validation-rule-option-labels.test.ts`.
'validateValidationRuleOptionLabels',
]);
});

Expand Down Expand Up @@ -600,6 +604,7 @@ describe('the object write door dispatches at the adjudicated scope (#4716)', ()
'validateActionBodyCompiles', // see the roster pin above
'validateActionBodyCapabilities', // [#35143] — see the roster pin above
'validateRuleSchemaFormats',
'validateValidationRuleOptionLabels', // [#39441] — see the roster pin above
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ describe('validateSecurityPosture at the runtime publish surface (#7576 → #830
expect(stackKeyForType('object_extension')).toBe('objectExtensions');
// [#33217] The validation-rule artifact checks (regex, JSON schema) cross on it too.
expect(runtimeAuthoringRulesFor('object_extension').map((r) => r.name))
.toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats']);
.toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats', 'validateValidationRuleOptionLabels']);

const roleSelect = { type: 'select', label: 'Group Function', options: [{ value: 'l1', label: 'Tier 1' }] };
const refused = runRuntimeAuthoringRules({
Expand All @@ -600,7 +600,7 @@ describe('validateSecurityPosture at the runtime publish surface (#7576 → #830
// positional and names it.
expect(refused.errors[0].path).toBe('objectExtensions[0].fields.role.name');
expect(refused.errors[0].where).toBe('field "sd_agent.role"');
expect(refused.rulesRun).toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats']);
expect(refused.rulesRun).toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats', 'validateValidationRuleOptionLabels']);

// The two labels the entry serves, at the same door.
const labelled = runRuntimeAuthoringRules({
Expand All @@ -620,7 +620,7 @@ describe('validateSecurityPosture at the runtime publish surface (#7576 → #830
});
expect(clean.errors).toEqual([]);
expect(clean.advisories).toEqual([]);
expect(clean.rulesRun).toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats']);
expect(clean.rulesRun).toEqual(['validateStackExpressions', 'lintFieldReferenceShapes', 'lintOptionColors', 'lintDuplicateFieldLabels', 'validateSecurityRoleWord', 'validateRuleCompilability', 'validateRuleSchemaFormats', 'validateValidationRuleOptionLabels']);

// Not a context row: the baseline carries no `objectExtensions`, and the
// candidate holds exactly the written item.
Expand Down
Loading
Loading