diff --git a/.changeset/32872-validate-expression-gate-parity.md b/.changeset/32872-validate-expression-gate-parity.md new file mode 100644 index 00000000000..b210d2c1833 --- /dev/null +++ b/.changeset/32872-validate-expression-gate-parity.md @@ -0,0 +1,28 @@ +--- +'@objectstack/mcp': patch +'@objectstack/lint': patch +'@objectstack/runtime': patch +'@object-ui/console': patch +--- + +fix(mcp): `validate_expression` gives the publish gate's own verdict at a `validation` or `formula` site, every pass the gate runs there included + +Clause-②: no (narrowing) — the MCP `validate_expression` tool now answers `ok: false` (or a warning) for a validation rule or formula field the publish gate already refuses (or warns on). The gate's acceptance set does not change, and no existing exported type or signature changes. +Metadata-protocol: none + + + +**BREAKING** verdict narrowing of the MCP `validate_expression` tool (`@objectstack/mcp`), at `site: 'validation'` and `site: 'formula'`. + +The tool promises the verdict the publish gate gives the rule, but it ran the shared expression validator and nothing else, so it answered `ok: true` for rules the gate then refused at publish, and the refusal first met a person there. It now also runs the gate's own passes at those two sites, through `judgeAuthoredSiteExpression` (`@objectstack/lint`), which runs the gate's walk itself over the object definitions the caller is served: + +- at both sites: a read through a reference to a field the target object does not declare (`record.balance.nope`), and a read through a reference into a stored-metadata table; +- at a `validation` site: a nullable field used without a null guard (`record.days > 3` with `days` neither required nor defaulted), and a read of `parent`, which a `validations[]` rule never binds; +- a warning at both sites: a read of an injected system column an external object has no storage behind (`record.owner_id` on an ADR-0015 `external` object). + +Each finding is the gate's sentence, at the gate's severity. A rule the gate accepts answers exactly as before. A hop target follows the same system-object fence as `describe_object`. A `flow_condition` and a `template` are not judged by this change: the tool's verdict there is unchanged. A sentence that names the rule names it `this rule`, since the tool is handed the condition and not the rule it will sit on. + +- `@objectstack/mcp`: `McpDataBridge` gains the optional `servedObjectDefinitionOf(name)`, the object definition as the caller is served it (the read `describeObject` projects), handed to the gate and rendered to nobody. A bridge without it answers the shared validator's verdict alone, as before. The served `SKILL.md` line and the tool description name what the tool now refuses. `@objectstack/lint` moves from a development dependency to a dependency, loaded on the first call that judges a rule or formula field, never at module load. +- `@objectstack/lint`: exports `judgeAuthoredSiteExpression` and `authoredExpressionHopTargets`. The gate's verdicts are unchanged: its walk gains one internal option, off its package entries, that only this entry passes. +- `@objectstack/runtime`: the HTTP MCP bridge serves `servedObjectDefinitionOf`, the same caller's object `describeObject` reads (ADR-0106 D1). +- `@object-ui/console`: the downloadable `SKILL.md` mirror carries the same line. diff --git a/packages/core/src/security/second-object-read-exposure.pin.test.ts b/packages/core/src/security/second-object-read-exposure.pin.test.ts index b2bb319fd93..05ab6963d08 100644 --- a/packages/core/src/security/second-object-read-exposure.pin.test.ts +++ b/packages/core/src/security/second-object-read-exposure.pin.test.ts @@ -337,6 +337,18 @@ const CALLERS: Record = { "ADDRESSED object, whose record is `getData` behind the route's own `get` exposure gate, and the related rows " + "are the child's `findData` behind the child's `list` exposure. Pinned by `packages/rest/src/record-page-routes.test.ts`", }, + // [#32872] MCP `validate_expression`'s run of the publish gate's own passes. + 'packages/lint/src/authored-site-expression.ts': { + kind: 'not-a-served-read', + reason: + "`authoredExpressionHopTargets` names the object each `record.REF.FIELD` hop of the caller's expression points " + + "at, so the MCP tool can hand the gate that object's DEFINITION: the bridge's `servedObjectDefinitionOf`, the " + + "caller's ADR-0106 view of the same declaration `describe_object` serves (an `enable.apiEnabled: false` object " + + "is described on every MCP transport, `mcp-server-runtime.merged-object-resources.test.ts`). The gate then " + + "judges whether FIELD is declared there. It reads no record of the target and serves none of its values. " + + "Pinned by `packages/mcp/src/mcp-validate-expression.test.ts` (a target the data API does not serve is judged " + + "on its described schema with no record read; a system-object target is not read at all)", + }, // [#30379] The package disable door's dependent-rule scan. 'packages/runtime/src/domains/packages.ts': { kind: 'not-a-served-read', diff --git a/packages/lint/src/authored-site-expression.test.ts b/packages/lint/src/authored-site-expression.test.ts new file mode 100644 index 00000000000..2bc8c3bc6dc --- /dev/null +++ b/packages/lint/src/authored-site-expression.test.ts @@ -0,0 +1,411 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { readdirSync, readFileSync } from 'node:fs'; +import { applyInjectedSystemColumns } from '@objectstack/metadata-core'; +import { describe, expect, it } from 'vitest'; + +// The repo's one code/prose separator, so a call spelled in a comment or a +// string is not read as a call the gate makes. The `.mjs` is the module, and +// `scripts/js-comment-mask.d.mts` beside it is the hand-written declaration +// that gives `maskCommentsAndLiterals` its type, so this test's typecheck +// verdict reads that file too. +import { maskComments, maskCommentsAndLiterals } from '../../../scripts/js-comment-mask.mjs'; + +import { + AUTHORED_FORMULA_FIELD_NAME, + AUTHORED_RULE_NAME, + authoredExpressionHopTargets, + judgeAuthoredSiteExpression, + type AuthoredExpressionSite, +} from './authored-site-expression.js'; +import { validateStackExpressions } from './validate-expressions.js'; + +/** + * [#32872] `judgeAuthoredSiteExpression` is the publish gate's verdict on one + * validation rule or formula field beyond the shared validator's — the half + * of `validate_expression` the MCP tool did not run. Two halves here: + * + * 1. The ENUMERATION: every call the gate makes at each site, read off its + * source, is classified below as a pass (with a fixture that trips it), + * the shared validator the tool runs itself, or plumbing. A call added to + * either site fails here until it is classified, and a pass is classified + * only with a fixture this entry refuses as the gate does. + * 2. Per pass: the entry's findings on the fixture are the gate's findings + * on the same rule or field, whole, and name the subject the pass judges. + * A CONTROL rule and field answer nothing. + * + * What the enumeration READS, and so what it reds on: + * - inside each site's regions (`SITE_REGIONS`): every call by bare name + * (`fn(`, `...fn(`), and every member call by its method name (`x.fn(`); + * - across the whole walk (`runStackExpressionPasses`): every pass that + * hands its findings to the walk as `issues.push(fn(` or + * `issues.push(...fn(`, member names included (`WALK_PUSHES`) — the + * shape of the walk's whole-stack passes at its tail. + * What it does NOT see: a pass outside the regions that pushes its findings + * by any other shape (an inline `issues.push({ … })`, a loop over a + * helper's result, a helper that pushes into `issues` itself), and a pass + * handed by reference (`.map(fn)`). Such a pass is still carried by + * construction when it locates its finding on the judged rule's key path + * (`objects[0].validations[0].`) or the judged field's `where`, since the + * entry runs the whole walk and keeps exactly those; what no pin here + * catches is a pass located elsewhere, or one needing an input the tool is + * not handed. Read the gate when merging a change to the walk. + */ + +const GATE_SOURCE = readFileSync(new URL('./validate-expressions.ts', import.meta.url), 'utf8'); +/** The same source with comments and literal bodies blanked, at the same offsets. */ +const GATE_CODE = maskCommentsAndLiterals(GATE_SOURCE); + +/** The gate's code between two markers (found in the source), comments and literal bodies blanked. */ +function region(start: string, end: string): string { + const from = GATE_SOURCE.indexOf(start); + expect(from, `marker moved — update this pin: ${start}`).toBeGreaterThanOrEqual(0); + const to = GATE_SOURCE.indexOf(end, from + start.length); + expect(to, `marker moved — update this pin: ${end}`).toBeGreaterThan(from); + return GATE_CODE.slice(from + start.length, to); +} + +/** The functions a region calls by bare name (a spread call counts; a member call does not). */ +function bareCalls(code: string): string[] { + const KEYWORDS = new Set(['if', 'for', 'while', 'return', 'switch', 'catch', 'function', 'typeof']); + const names = [...code.matchAll(/(? m[1]!); + return [...new Set(names)].filter((n) => !KEYWORDS.has(n)).sort(); +} + +/** The method names a region calls on a receiver (`x.fn(`, `a.b.fn(`). */ +function memberCalls(code: string): string[] { + const names = [...code.matchAll(/(? m[1]!); + return [...new Set(names)].sort(); +} + +/** The gate's whole walk, comments and literal bodies blanked. */ +function walk(): string { + return region('export function runStackExpressionPasses(', '\n}\n'); +} + +/** The passes the walk pushes whole into its findings: `issues.push(fn(` / `issues.push(...fn(`, member names whole. */ +function walkPushes(code: string): string[] { + const names = [...code.matchAll(/(? m[1]!); + return [...new Set(names)].sort(); +} + +/** The method names called on a receiver at each site, each plumbing: none of them judges an expression. */ +const SITE_MEMBER_CALLS: Record> = { + validation: { + get: 'a Map read (the object index, the field definitions)', + indexOf: 'a string offset, reading the slot key', + isArray: '`Array.isArray`', + push: "appends a finding to the walk's list", + }, + formula: { + get: 'a Map read (the object index, the field definitions)', + push: "appends a finding to the walk's list", + }, +}; + +/** + * The passes the walk hands its findings whole, outside both sites' regions, + * and why none of them can judge the tool's rule or field. A new one reds + * here until it is classified: one that judges a validation rule or a + * formula field belongs in a site's regions or in this entry's filter. + */ +const WALK_PUSHES: Record = { + bulkConfirmTextIssues: "a list view's bulk `confirmText` template slots: no rule or field expression", + actionCopyTemplateIssues: "an action's copy template slots: no rule or field expression", +}; + +/** The passes the walk pushes whole from INSIDE a site's regions: classified with that site's calls, in `SITE_CALLS`. */ +const WALK_PUSHES_IN_REGION: Record = { + formulaCycleIssues: 'formula', +}; + +/** An object whose own formulas read each other: a cycle the gate refuses on each of its members. */ +const CYCLE = { + name: 'obj', + fields: { + f_x: { type: 'formula', label: 'X', expression: 'record.f_y + 1' }, + f_y: { type: 'formula', label: 'Y', expression: 'record.f_x + 1' }, + days: { type: 'number', label: 'Days', required: true }, + }, +}; + +/** Where each site's calls are read: the rule loop and the `check` helper it calls; the field-formula pass and what follows the fields loop. */ +const SITE_REGIONS: Record> = { + validation: [ + [' const check = (', ' const fieldRuleRootVerdict = ('], + [' for (const rule of recordsOf(validations)) {', ' // Field-level formulas'], + ], + formula: [ + [' const judgeFieldFormula = (', ' // ── Object validation-rule'], + [ + ' judgeFieldFormula(fname, f, { objectName, optionFields: optionFieldNames, fieldDefs });\n }', + " // [#26646] A field group's section predicate", + ], + ], +}; + +type Fixture = { + /** The stack's objects; the judged object is the first, named `obj`. */ + objects: Array>; + expression: string; + severity: 'error' | 'warning'; + /** The subject the pass names in its finding (a field, a table, a root). */ + names: string; +}; + +type Classified = + | { kind: 'pass'; fixture: Fixture } + /** A pass the gate runs that has nothing to judge at the tool's site; judged anyway, through the entry, and pinned to answer nothing. */ + | { kind: 'pass-silent-here'; why: string; fixture: Omit } + | { kind: 'validator'; why: string } + | { kind: 'plumbing'; why: string }; + +const REQ = { + name: 'obj', + fields: { + days: { type: 'number', label: 'Days' }, + title: { type: 'text', label: 'Title', required: true }, + balance: { type: 'lookup', label: 'Balance', reference: 'bal' }, + meta: { type: 'lookup', label: 'Meta', reference: 'sys_metadata' }, + header: { type: 'master_detail', label: 'Header', reference: 'bal' }, + }, +}; +const BAL = { name: 'bal', fields: { remaining: { type: 'number', label: 'Remaining', required: true } } }; +const EXT = { + name: 'obj', + external: { remoteName: 'customers' }, + fields: { email: { type: 'text', label: 'Email', required: true } }, +}; + +const VALIDATOR = { kind: 'validator', why: 'the shared validator: the tool runs `validateExpression` itself' } as const; +const HOP_FIELD: Fixture = { objects: [REQ, BAL], expression: 'record.balance.nope > 1', severity: 'error', names: 'nope' }; +const BODY_HOP: Fixture = { objects: [REQ, BAL], expression: "record.meta.name == 'x'", severity: 'error', names: 'sys_metadata' }; +const ANCHOR: Fixture = { objects: [EXT], expression: "record.owner_id == 'u1'", severity: 'warning', names: 'owner_id' }; +const asValue = (f: Fixture): Fixture => ({ ...f, expression: `${f.expression} ? 1 : 0` }); + +const SITE_CALLS: Record> = { + validation: { + validateExpression: VALIDATOR, + withAttachedBlocks: { kind: 'plumbing', why: 'the field list handed to the shared validator' }, + isBareReferenceToAny: { kind: 'plumbing', why: "filters the shared validator's findings on a field-rule slot" }, + refuseStoredMetadataBodyHop: { kind: 'pass', fixture: BODY_HOP }, + refuseUndeclaredHopField: { kind: 'pass', fixture: HOP_FIELD }, + warnUnprovisionedAnchors: { kind: 'pass', fixture: ANCHOR }, + atSlot: { kind: 'plumbing', why: "sets the judged slot's key path on the findings" }, + celSourceOf: { kind: 'plumbing', why: 'reads the CEL source off the slot' }, + rulePredicates: { kind: 'plumbing', why: "lists the rule's predicates" }, + faultOutcomeOf: { kind: 'plumbing', why: "the rule's fault outcome, from its severity" }, + check: { kind: 'plumbing', why: 'the helper whose calls are the first region of this site' }, + validationRuleParentIssue: { + kind: 'pass', + fixture: { objects: [REQ, BAL], expression: 'parent.remaining > 1', severity: 'error', names: 'parent' }, + }, + checkNullGuards: { + kind: 'pass', + fixture: { objects: [REQ, BAL], expression: 'record.days > 3', severity: 'error', names: 'days' }, + }, + }, + formula: { + validateExpression: VALIDATOR, + celSourceOf: { kind: 'plumbing', why: 'reads the CEL source off the field' }, + refuseStoredMetadataBodyHop: { kind: 'pass', fixture: asValue(BODY_HOP) }, + refuseUndeclaredHopField: { kind: 'pass', fixture: asValue(HOP_FIELD) }, + warnUnprovisionedAnchors: { kind: 'pass', fixture: asValue(ANCHOR) }, + // [#33100] The formula-cycle pass, after the fields loop. It locates each + // finding on a cycle member's own `expression`; the probe is named + // `__validate_expression__`, which no authored formula can read, so the + // probe is never on a cycle and nothing is located on it, at the gate or + // through the entry. The cycle verdict on the formula being authored + // needs that field's own name, which `validate_expression` is not handed: + // the tool cannot give it (a follow-up, not this pin's to hide). + formulaCycleIssues: { + kind: 'pass-silent-here', + why: "locates each finding on a cycle member's own `expression`; the probe is on no cycle", + fixture: { objects: [CYCLE], expression: 'record.f_x + record.days' }, + }, + storedExpressionInputIssues: { + kind: 'pass-silent-here', + why: 'judges a STORED field\'s `expression` (any type but `formula`); the tool\'s formula site is a `formula` field', + fixture: { objects: [REQ, BAL], expression: 'record.balance.remaining > 1 ? now() : now()' }, + }, + }, +}; + +/** The full gate's findings on the same rule or field, named as the entry names it. */ +function gateOn(site: AuthoredExpressionSite, objects: Array>, expression: string) { + const [subject, ...others] = objects as [Record, ...Array>]; + const judged = site === 'validation' + ? { ...subject, validations: [{ name: AUTHORED_RULE_NAME, type: 'script', condition: expression, message: 'm' }] } + : { + ...subject, + fields: { ...subject.fields, [AUTHORED_FORMULA_FIELD_NAME]: { type: 'formula', label: 'F', expression } }, + }; + const at = site === 'validation' + ? (where: string) => where.includes(`'${AUTHORED_RULE_NAME}'`) + : (where: string) => where.includes(`'${AUTHORED_FORMULA_FIELD_NAME}'`); + return validateStackExpressions({ objects: [judged, ...others] }) + .filter((i) => at(i.where)) + .map((i) => [i.severity ?? 'error', i.message]); +} + +function entryOn(site: AuthoredExpressionSite, objects: Array>, expression: string) { + return judgeAuthoredSiteExpression({ site, objectName: 'obj', expression, objects }) + .map((i) => [i.severity ?? 'error', i.message]); +} + +describe('judgeAuthoredSiteExpression — every gate pass at each site is listed (#32872)', () => { + for (const site of ['validation', 'formula'] as const) { + it(`site ${site}: every call the gate makes there is classified`, () => { + const calls = bareCalls(SITE_REGIONS[site].map(([start, end]) => region(start, end)).join('\n')); + expect(calls.length, 'the scan read nothing — the regions are vacuous').toBeGreaterThan(3); + expect(calls).toEqual(Object.keys(SITE_CALLS[site]).sort()); + }); + + it(`site ${site}: every member call the gate makes there is classified`, () => { + const calls = memberCalls(SITE_REGIONS[site].map(([start, end]) => region(start, end)).join('\n')); + expect(calls).toEqual(Object.keys(SITE_MEMBER_CALLS[site]).sort()); + }); + + for (const [name, classified] of Object.entries(SITE_CALLS[site])) { + if (classified.kind === 'pass') { + const { objects, expression, severity, names } = classified.fixture; + it(`site ${site}: ${name} refuses through the entry as the gate does`, () => { + const gate = gateOn(site, objects, expression); + expect(gate.length, 'the fixture trips the gate').toBeGreaterThan(0); + const entry = entryOn(site, objects, expression); + expect(entry).toEqual(gate); + expect(entry.map(([level]) => level)).toEqual(gate.map(() => severity)); + expect(entry.some(([, message]) => message!.includes(names))).toBe(true); + }); + } + if (classified.kind === 'pass-silent-here') { + const { objects, expression } = classified.fixture; + it(`site ${site}: ${name} has nothing to say at this site, at the gate and through the entry`, () => { + expect(gateOn(site, objects, expression)).toEqual([]); + expect(entryOn(site, objects, expression)).toEqual([]); + }); + } + } + + it(`site ${site}: CONTROL — a clean ${site === 'validation' ? 'rule' : 'formula'} answers nothing`, () => { + const expression = site === 'validation' + ? "record.title == 'x' && record.balance.remaining > 1" + : "record.title == 'x' && record.balance.remaining > 1 ? 1 : 0"; + expect(gateOn(site, [REQ, BAL], expression)).toEqual([]); + expect(entryOn(site, [REQ, BAL], expression)).toEqual([]); + }); + } + + it('every pass the whole walk pushes as a whole is classified', () => { + const pushes = walkPushes(walk()); + expect(pushes.length, 'the scan read nothing — the walk marker moved').toBeGreaterThan(0); + expect(pushes).toEqual([...Object.keys(WALK_PUSHES), ...Object.keys(WALK_PUSHES_IN_REGION)].sort()); + for (const [name, site] of Object.entries(WALK_PUSHES_IN_REGION)) { + expect(Object.keys(SITE_CALLS[site]), `${name} is classified with the ${site} site's calls`).toContain(name); + } + }); + + it("formulaCycleIssues: the gate refuses the object's own cycle, and locates nothing on the probe", () => { + // Non-vacuous: on this stack the pass speaks, on the cycle's members. + const cycle = validateStackExpressions({ objects: [CYCLE] }).filter((i) => /f_x|f_y/.test(i.where)); + expect(cycle.length).toBeGreaterThan(0); + // ...and neither the gate nor the entry puts a finding on the probe. + expect(gateOn('formula', [CYCLE], 'record.f_x + record.days')).toEqual([]); + expect(entryOn('formula', [CYCLE], 'record.f_x + record.days')).toEqual([]); + }); + + it("leaves the shared validator's findings to the caller", () => { + // An unknown field is the validator's verdict: the gate gives it, the entry does not. + expect(gateOn('validation', [REQ, BAL], 'record.nope > 1').length).toBeGreaterThan(0); + expect(entryOn('validation', [REQ, BAL], 'record.nope > 1')).toEqual([]); + }); + + it("judges the caller's rule only, never the object's own rules or fields", () => { + const withOwn = { + ...REQ, + validations: [{ name: 'own', type: 'script', condition: 'record.days > 3', message: 'm' }], + fields: { ...REQ.fields, own_formula: { type: 'formula', label: 'Own', expression: 'record.balance.nope' } }, + }; + expect(entryOn('validation', [withOwn, BAL], "record.title == 'x'")).toEqual([]); + expect(entryOn('formula', [withOwn, BAL], "record.title == 'x' ? 1 : 0")).toEqual([]); + }); + + // The registry serves each object with the system columns it injects as + // declared fields; the gate judges the authored body. Served or authored, + // the entry's verdict is the same. + it('judges a served definition (injected columns declared) as the authored body', () => { + const servedReq = applyInjectedSystemColumns(REQ); + const servedExt = applyInjectedSystemColumns(EXT); + expect(Object.keys(servedReq.fields)).toContain('created_at'); + // `created_at` is not a field the author declared nullable: no null-guard verdict. + expect(entryOn('validation', [servedReq, BAL], "record.created_at > timestamp('2020-01-01T00:00:00Z')")).toEqual([]); + expect(entryOn('validation', [servedReq, BAL], 'record.days > 3')) + .toEqual(entryOn('validation', [REQ, BAL], 'record.days > 3')); + // An external object's anchor is still the platform's, unprovisioned. + expect(entryOn('validation', [servedExt], "record.owner_id == 'u1'")) + .toEqual(entryOn('validation', [EXT], "record.owner_id == 'u1'")); + expect(entryOn('validation', [servedExt], "record.owner_id == 'u1'").map(([level]) => level)).toEqual(['warning']); + }); + + it('answers nothing when the object is not among the definitions', () => { + expect(judgeAuthoredSiteExpression({ site: 'validation', objectName: 'nope', expression: 'record.days > 3', objects: [REQ] })) + .toEqual([]); + }); +}); + +// The gate's option that skips the shared validator must reach no gate run. +// `runStackExpressionPasses` and its options type are on none of the +// package's entries, so only this package's own source can pass it: read +// every source file of it (tests aside), comments and literals blanked, and +// hold the option's spellings to the declaration, the one read, and the one +// passer. +describe('sharedValidatorRunByCaller reaches no gate run (#32872)', () => { + const SRC = new URL('./', import.meta.url); + const sources = (dir: URL, rel = ''): string[] => + readdirSync(dir, { withFileTypes: true }).flatMap((e) => + e.isDirectory() + ? sources(new URL(`${e.name}/`, dir), `${rel}${e.name}/`) + : /\.tsx?$/.test(e.name) && !/\.test\.tsx?$/.test(e.name) ? [`${rel}${e.name}`] : [], + ); + + it('is spelled in code only where it is declared, read, and passed by this entry', () => { + const spelled: Record = {}; + for (const file of sources(SRC)) { + const code = maskCommentsAndLiterals(readFileSync(new URL(file, SRC), 'utf8')); + const n = code.match(/(? 0) spelled[file] = n; + } + expect(spelled).toEqual({ + // The option's declaration, and the walk's one read of it. + 'validate-expressions.ts': 2, + // The one passer. + 'authored-site-expression.ts': 1, + }); + }); + + it('is on none of the package entries: the walk and its options type are not exported', () => { + // Comments blanked, literals kept: a module specifier is a literal. + const entries = Object.fromEntries(['index.ts', 'runtime.ts', 'rule-explanations.ts'] + .map((entry) => [entry, maskComments(readFileSync(new URL(entry, SRC), 'utf8'))])); + // The scan reads what it means to: the root entry re-exports from the walk's module by name. + expect(entries['index.ts']).toMatch(/export \{[^}]*validateStackExpressions[^}]*\} from '\.\/validate-expressions\.js'/); + for (const [entry, code] of Object.entries(entries)) { + expect(code, entry).not.toMatch(/(? { + it('names the target of each reference the expression reads through', () => { + expect(authoredExpressionHopTargets(REQ, 'record.balance.remaining > 1 && record.meta.name == "x"')) + .toEqual(['bal', 'sys_metadata']); + }); + + it('names nothing for a plain read, an unparsable source or a non-reference field', () => { + expect(authoredExpressionHopTargets(REQ, 'record.balance != null && record.days > 1')).toEqual([]); + expect(authoredExpressionHopTargets(REQ, 'record.days >')).toEqual([]); + expect(authoredExpressionHopTargets(REQ, 'record.title.size() > 1')).toEqual([]); + }); +}); diff --git a/packages/lint/src/authored-site-expression.ts b/packages/lint/src/authored-site-expression.ts new file mode 100644 index 00000000000..6221993d1dd --- /dev/null +++ b/packages/lint/src/authored-site-expression.ts @@ -0,0 +1,147 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#32872] The publish gate's verdict on ONE authored expression, at the two + * sites the gate judges with passes of its own beyond the shared validator: a + * validation rule's `condition` and a formula field's `expression`. + * + * The MCP `validate_expression` tool promises "the verdict is the one the + * publish gate gives that rule". It runs the shared validator + * (`@objectstack/formula`'s `validateExpression`) itself, and before this + * entry it ran nothing else, so it answered `ok: true` for rules the gate then + * refused: the null-guard gate, a hop to a field the reference's target does + * not declare, a hop into a stored-metadata table, a validation rule reading + * `parent`, and (a warning) a read of an external object's unprovisioned + * anchor. Each of those lives inside the gate's walk + * ({@link runStackExpressionPasses}), closed over the stack's indexes. + * + * ⛔ Nothing here re-implements a pass. The entry builds the stack the gate + * would judge, the subject object carrying the one rule or formula field the + * caller describes, and runs the gate's OWN walk over it, as the object save + * door does (`runtimeWriteType: 'object'`), with the one call the caller has + * already made left out (`sharedValidatorRunByCaller`). What comes back is + * every finding the gate locates on that rule or field and nothing else: a + * pass added to the gate at either site is carried by construction, and + * `authored-site-expression.test.ts` lists each one so its refusal through + * this entry is pinned. + */ + +import { analyzeRelationshipTraversals } from '@objectstack/formula'; +import { stripInjectedSystemColumns } from '@objectstack/metadata-core'; +import { referenceTargetOf } from '@objectstack/spec/data'; + +import { recordsOf } from './object-graph.js'; +import { runStackExpressionPasses, type ExprIssue } from './validate-expressions.js'; + +type AnyRec = Record; + +/** The two sites the gate judges with passes of its own, as `validate_expression` names them. */ +export type AuthoredExpressionSite = 'validation' | 'formula'; + +/** What {@link judgeAuthoredSiteExpression} judges. */ +export interface AuthoredSiteExpression { + site: AuthoredExpressionSite; + /** The object the rule or formula field is authored on. */ + objectName: string; + /** The CEL source: the rule's `condition`, or the formula field's `expression`. */ + expression: string; + /** site `validation` only: the rule's `severity` (the spec default is `error`). */ + severity?: 'error' | 'warning' | 'info'; + /** + * The object definitions as the registry serves them: the subject's, and + * those of the objects its references name that the expression reads + * through ({@link authoredExpressionHopTargets}). A target left out is not + * judged, as the gate does not judge a target outside the stack it reads. + * + * Served, a definition carries the system columns the registry injects as + * declared fields; the gate judges the body as authored, so each is read + * through `stripInjectedSystemColumns` (`@objectstack/metadata-core`, the + * write path's own strip of exactly those) and the walk re-derives the + * injected columns itself. Unstripped, the null-guard gate would judge + * `created_at` as a declared nullable field and an external object's + * anchors would read as columns its author vouches for. + */ + objects: readonly AnyRec[]; +} + +/** + * The name the judged rule carries. The gate's sentences that name a rule + * (the null-guard and `parent` verdicts) name this one, since the tool is + * handed the condition and not the rule it will sit on. + */ +export const AUTHORED_RULE_NAME = 'this rule'; + +/** + * The name the judged formula field carries. No sentence of the formula + * site names it; it is spelled so that no authored field can be it. + */ +export const AUTHORED_FORMULA_FIELD_NAME = '__validate_expression__'; + +/** + * The objects whose definitions {@link judgeAuthoredSiteExpression} needs + * beyond the subject: the target of each reference field of `subject` that + * `expression` reads through (`record.FIELD.MEMBER`), read with the analysis + * and the target accessor the gate's hop passes use. Empty when the source + * does not parse (the shared validator reports that) or reads no hop. + */ +export function authoredExpressionHopTargets(subject: AnyRec, expression: string): string[] { + const traversals = analyzeRelationshipTraversals(expression, 'record')?.traversals; + if (!traversals || traversals.size === 0) return []; + const targets = new Set(); + for (const field of recordsOf(subject.fields)) { + if (typeof field.name !== 'string' || !traversals.has(field.name)) continue; + const target = referenceTargetOf(field)?.trim(); + if (target) targets.add(target); + } + return [...targets].sort(); +} + +/** + * The gate's findings on the one rule or formula field described, beyond the + * shared validator's: each the gate's own pass, in the gate's words, at the + * gate's severity. Empty when `objects` carries no definition of + * `objectName`. + */ +export function judgeAuthoredSiteExpression({ + site, + objectName, + expression, + severity, + objects, +}: AuthoredSiteExpression): ExprIssue[] { + const authored = objects.map((o) => stripInjectedSystemColumns(o)); + const served = authored.find((o) => o?.name === objectName); + if (!served) return []; + const others = authored.filter((o) => o !== served && o?.name !== objectName); + const { validations: _servedRules, ...body } = served; + const subject = site === 'validation' + ? { + ...body, + validations: [{ + name: AUTHORED_RULE_NAME, + type: 'script', + condition: expression, + message: AUTHORED_RULE_NAME, + ...(severity ? { severity } : {}), + }], + } + : { ...body, fields: withAuthoredFormulaField(body.fields, expression) }; + const issues = runStackExpressionPasses( + { objects: [subject, ...others] }, + { runtimeWriteType: 'object', sharedValidatorRunByCaller: true }, + ); + // Every finding of the validation-rule pass carries the judged slot's key + // path; the field-formula pass locates its findings on the field's key. + const rulePath = 'objects[0].validations[0].'; + const formulaWhere = `object '${objectName}' · field '${AUTHORED_FORMULA_FIELD_NAME}' expression`; + return issues.filter((issue) => + site === 'validation' ? issue.path?.startsWith(rulePath) === true : issue.where === formulaWhere, + ); +} + +/** The served `fields`, in the shape they came in, with the judged formula field added. */ +function withAuthoredFormulaField(fields: unknown, expression: string): unknown { + const field = { type: 'formula', label: AUTHORED_FORMULA_FIELD_NAME, expression }; + if (Array.isArray(fields)) return [...fields, { name: AUTHORED_FORMULA_FIELD_NAME, ...field }]; + return { ...(fields && typeof fields === 'object' ? fields : {}), [AUTHORED_FORMULA_FIELD_NAME]: field }; +} diff --git a/packages/lint/src/index.ts b/packages/lint/src/index.ts index bf3370f25fc..036c2e3269d 100644 --- a/packages/lint/src/index.ts +++ b/packages/lint/src/index.ts @@ -75,6 +75,15 @@ export type { DatasetMeasureAggregateFinding, GroupKeyClass } from './validate-d export { validateStackExpressions, fieldRuleRootIssue, FIELD_RULE_BOUND_ROOTS } from './validate-expressions.js'; export type { ExprIssue } from './validate-expressions.js'; +// [#32872] The gate's verdict on one validation rule or formula field, the +// MCP `validate_expression` tool's second half (the shared validator is its first). +export { + judgeAuthoredSiteExpression, + authoredExpressionHopTargets, + AUTHORED_RULE_NAME, + AUTHORED_FORMULA_FIELD_NAME, +} from './authored-site-expression.js'; +export type { AuthoredSiteExpression, AuthoredExpressionSite } from './authored-site-expression.js'; export { STORED_EXPRESSION_CROSS_RECORD_INPUT, STORED_EXPRESSION_VOLATILE_INPUT } from './stored-expression-inputs.js'; // #4763 — `has(x)` reads as a null guard and is not one. The decision procedure diff --git a/packages/lint/src/validate-expressions.ts b/packages/lint/src/validate-expressions.ts index dd715ce0414..7ccfb057ef5 100644 --- a/packages/lint/src/validate-expressions.ts +++ b/packages/lint/src/validate-expressions.ts @@ -2264,8 +2264,29 @@ export interface StackExpressionOptions { * holds by construction rather than by the snapshot's shape. */ runtimeWriteType?: string; + /** + * [#32872] Set only by `judgeAuthoredSiteExpression` + * (`authored-site-expression.ts`), the entry the MCP `validate_expression` + * tool asks for the gate's verdict on one validation rule or formula field. + * That caller has already run the shared validator (`validateExpression`) + * on the same source and answers its findings, codes included, so this walk + * leaves out that one call at {@link check} and at the field-formula pass + * and reports every OTHER pass the gate runs there, each its own judge. + * Absent on every gate run: the walk is byte for byte what it was. + */ + sharedValidatorRunByCaller?: boolean; } +/** + * [#32872] What {@link StackExpressionOptions.sharedValidatorRunByCaller} + * puts in place of the shared validator's answer: no finding, so the walk's + * own passes are all that is reported. + */ +const VALIDATOR_RUN_BY_CALLER: Pick, 'errors' | 'warnings'> = { + errors: [], + warnings: [], +}; + /** * Validate every predicate in the stack. Returns the list of issues (empty = * clean). Caller decides how to surface / whether to fail the build. @@ -2300,6 +2321,8 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression // an empty list under it, so the claim holds by construction rather than by // the shape of the snapshot the gate happens to build today. const objectWrite = options.runtimeWriteType === 'object'; + // [#32872] See {@link StackExpressionOptions.sharedValidatorRunByCaller}. + const validatorRunByCaller = options.sharedValidatorRunByCaller === true; // [#24798] On a `view` write exactly ONE pass judges — the bulk `confirmText` // pass over the written view's own list containers ({@link bulkConfirmTextIssues}); // every other pass reads a collection a view write does not carry, so it @@ -2621,7 +2644,7 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression const fieldTypes = objectName ? fieldTypeIndex.get(objectName) : undefined; // Spread only when given, so every other site's hint is unchanged. const roots = extraRoots ? { roots: extraRoots } : {}; - const res = validateExpression('predicate', raw as string | { dialect?: string; source?: string }, + const res = validatorRunByCaller ? VALIDATOR_RUN_BY_CALLER : validateExpression('predicate', raw as string | { dialect?: string; source?: string }, objectName ? { objectName, fields, attachedOnRead, fieldTypes, scope, traversalHydration, ...roots, @@ -3466,7 +3489,7 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression // `optionFieldNames` in the object walk below). A `label(record.)` naming any other // declared field faults on every row and reads null, so it is refused // here, in the evaluator's own words. - const res = validateExpression('value', f.expression as string | { dialect?: string; source?: string }, + const res = validatorRunByCaller ? VALIDATOR_RUN_BY_CALLER : validateExpression('value', f.expression as string | { dialect?: string; source?: string }, objectName ? { objectName, diff --git a/packages/mcp/package.json b/packages/mcp/package.json index 39586f993b1..71714fad20b 100644 --- a/packages/mcp/package.json +++ b/packages/mcp/package.json @@ -30,6 +30,7 @@ "@modelcontextprotocol/sdk": "^1.30.1", "@objectstack/core": "workspace:*", "@objectstack/formula": "workspace:*", + "@objectstack/lint": "workspace:*", "@objectstack/metadata-core": "workspace:*", "@objectstack/spec": "workspace:*", "@objectstack/types": "workspace:*", @@ -37,7 +38,6 @@ "zod": "^4.6.6" }, "devDependencies": { - "@objectstack/lint": "workspace:*", "@types/node": "^26.6.5", "typescript": "^6.0.3", "vitest": "^4.1.11" diff --git a/packages/mcp/src/mcp-http-tools.ts b/packages/mcp/src/mcp-http-tools.ts index 777a202873a..37dab2a6465 100644 --- a/packages/mcp/src/mcp-http-tools.ts +++ b/packages/mcp/src/mcp-http-tools.ts @@ -87,6 +87,10 @@ import { type ExprFaultOutcome, type FieldRole, } from '@objectstack/formula'; +// [#32872] The publish gate's own passes at a validation rule and a formula +// field, run over the served definitions (see `VALIDATE_SITE_MAP.gatePasses`). +// [#32872] Types only: the entry itself is loaded lazily, in `gatePassFindings`. +import type { AuthoredExpressionSite } from '@objectstack/lint'; // [#16913] The unknown-key error map every `strictToolInput` shape below is // built with. Imported, never re-implemented: #4001 is this repo's ruling on // silent key stripping and its explicit instruction is that the parts already @@ -159,6 +163,22 @@ export interface McpDataBridge { * no `label()` target check, exactly as before (the validator's opt-in). */ optionFieldsOf?(name: string): Promise; + /** + * [#32872] The object definition of `name` whole, as this caller is served + * it — the same read {@link describeObject} projects — or `null` when no + * such object is served. `validate_expression` hands it, with the + * definitions of the objects the expression reads through, to + * `@objectstack/lint`'s `judgeAuthoredSiteExpression`, so the tool gives + * the publish gate's verdict at a `validation` / `formula` site: the passes + * that judge what a field declares (`required`, `defaultValue`, a + * `reference`'s target, an external binding) read the definition, which + * `describeObject`'s projection does not carry. Never rendered to the + * caller: only the gate's findings are. + * + * OPTIONAL, like {@link optionFieldsOf}: a bridge that omits it gets the + * shared validator's verdict alone, exactly as before. + */ + servedObjectDefinitionOf?(name: string): Promise | null>; query( object: string, opts: { @@ -1689,6 +1709,18 @@ function jsonText(value: unknown): string { * through the relationship and as a plain value, and a second hop, in the * gate's words; nothing hydrates a flow condition or a template, so the gate * does not ask there and neither does the tool. + * + * [#32872] `gatePasses`: the sites where the gate judges with passes of its + * own beyond the shared validator — the null-guard gate, the hop to a field + * the target does not declare, the hop into a stored-metadata table, a rule + * reading `parent`, the unprovisioned-anchor warning — each private to + * `@objectstack/lint`'s walk. There the tool asks the gate itself + * (`judgeAuthoredSiteExpression`) over the served definitions + * (`McpDataBridge.servedObjectDefinitionOf`) and adds its findings to the + * validator's. A flow condition and a template are not judged by this: the + * gate's own passes there (the unprovisioned-anchor warning on an + * object-bound flow predicate, the null-guard gate on a record-triggered + * flow's conditions) are not run by the tool. */ const VALIDATE_SITE_MAP: Record< string, @@ -1698,6 +1730,7 @@ const VALIDATE_SITE_MAP: Record< slot: z.ZodType; optionLabels?: true; traversalHydration?: true; + gatePasses?: AuthoredExpressionSite; /** * [#29904, #29926, #29959] What the gate's runtime does on a fault at this * site, from the caller's optional `severity` / `triggerKind` — the two @@ -1715,6 +1748,7 @@ const VALIDATE_SITE_MAP: Record< > = { formula: { role: 'value', scope: 'record', slot: EvaluatedExpressionInputSchema, optionLabels: true, traversalHydration: true, + gatePasses: 'formula', }, // [#29904, #29926] A `severity: 'error'` rule (the default) fails closed: a // fault refuses the write. An advisory rule (`warning` / `info`) fails open: @@ -1723,6 +1757,7 @@ const VALIDATE_SITE_MAP: Record< // the gate will for the severity it is told. validation: { role: 'predicate', scope: 'record', slot: EvaluatedExpressionInputSchema, traversalHydration: true, + gatePasses: 'validation', faultOutcome: ({ severity }) => (severity === 'warning' || severity === 'info' ? 'fail-open' : 'fail-closed'), }, // [#29926, #29959] A record-triggered flow's start, edge or `decision` @@ -1742,6 +1777,64 @@ const VALIDATE_SITE_MAP: Record< template: { role: 'template', scope: 'record', slot: TemplateExpressionInputSchema }, }; +/** [#32872] A gate pass's finding, as the tool answers it: the source it reads and the gate's sentence. */ +interface GatePassFinding { + source: string; + message: string; +} + +const NO_GATE_PASS_FINDINGS: { errors: GatePassFinding[]; warnings: GatePassFinding[] } = { errors: [], warnings: [] }; + +/** + * [#32872] The publish gate's findings at a `validation` / `formula` site + * beyond the shared validator's, judged by `@objectstack/lint`'s + * `judgeAuthoredSiteExpression` over the definitions the caller is served: + * the subject's, and each object the expression reads through. A bridge + * without `servedObjectDefinitionOf`, or an object it does not serve, adds + * none; a target it does not serve is not judged, as at the gate. + * + * A hop target follows the same system-object fence as `describe_object`: + * `exposed` is the tool's object-name guard, and a target it refuses is + * neither read nor judged, so a hop into a system object is judged only + * where the server exposes system objects (`allowSystemObjects`). + * + * `@objectstack/lint`'s root entry is loaded here, on the first call that + * needs it, never at module load: the boot path reaches lint only through + * its `/runtime` entry, as every other server-side consumer does. + */ +async function gatePassFindings( + bridge: McpDataBridge, + exposed: (objectName: string) => boolean, + site: AuthoredExpressionSite, + objectName: string, + expression: string, + severity: ValidationSeverity | undefined, +): Promise<{ errors: GatePassFinding[]; warnings: GatePassFinding[] }> { + if (!bridge.servedObjectDefinitionOf) return NO_GATE_PASS_FINDINGS; + const subject = await bridge.servedObjectDefinitionOf(objectName); + if (!subject) return NO_GATE_PASS_FINDINGS; + const { authoredExpressionHopTargets, judgeAuthoredSiteExpression } = await import('@objectstack/lint'); + const targets: Array> = []; + for (const target of authoredExpressionHopTargets(subject, expression)) { + if (target === objectName || !exposed(target)) continue; + const def = await bridge.servedObjectDefinitionOf(target); + if (def) targets.push(def); + } + const findings = judgeAuthoredSiteExpression({ + site, + objectName, + expression, + ...(severity ? { severity } : {}), + objects: [subject, ...targets], + }); + const errors: GatePassFinding[] = []; + const warnings: GatePassFinding[] = []; + for (const { severity: level, source, message } of findings) { + (level === 'warning' ? warnings : errors).push({ source, message }); + } + return { errors, warnings }; +} + /** [#29959] A validation rule's `severity`, as `ValidationRuleSchema` spells it. */ type ValidationSeverity = 'error' | 'warning' | 'info'; const VALIDATION_SEVERITIES = ['error', 'warning', 'info'] as const satisfies readonly ValidationSeverity[]; @@ -2283,12 +2376,16 @@ export function registerObjectTools( { description: 'Validate a CEL expression against an object\'s schema before authoring it into metadata. Returns ' + - 'build-time errors (bare field refs, unknown fields, unknown functions; at a `formula` or `validation` site, a ' + - 'reference field read both through the relationship and as a plain value, or more than one hop) and advisory warnings ' + + 'build-time errors (bare field refs, unknown fields, unknown functions; at a `formula` or `validation` site, every ' + + 'other refusal the publish gate gives there: a reference field read both through the relationship and as a plain ' + + 'value, more than one hop, a hop to a field the target does not declare or into a stored-metadata table, and at a ' + + '`validation` site an unguarded nullable field or a read of `parent`) and advisory warnings ' + '(text/boolean fields misused in arithmetic, an error at a `validation` site, worded for the rule\'s ' + '`severity`, and at a `flow_condition` of a record-triggered or time-relative flow, where it fails the run; ' + - 'a warning on any other flow; date-equality pitfalls), plus the fields and stdlib ' + - 'functions in scope so you can self-correct. `site` says where the expression will live: a `formula` ' + + 'a warning on any other flow; date-equality pitfalls; at a `formula` or `validation` site, a read of an ' + + 'external object\'s unprovisioned system column), plus the fields and stdlib ' + + 'functions in scope so you can self-correct. A hop target follows the same system-object fence as ' + + '`describe_object`. `site` says where the expression will live: a `formula` ' + 'field, a `validation`/predicate, or a `flow_condition` (fields are bound bare in flow conditions). ' + 'Pass the rule\'s `severity` (validation) or the flow\'s `triggerKind` (flow_condition), so the verdict is ' + 'the one the publish gate gives that rule or flow. A time-relative flow\'s conditions read a row of the object ' + @@ -2373,7 +2470,7 @@ export function registerObjectTools( fields.push(f.name); if (typeof f?.type === 'string') fieldTypes[f.name] = f.type; } - const { role, scope, slot, optionLabels, traversalHydration, faultOutcome: outcomeOf } = + const { role, scope, slot, optionLabels, traversalHydration, gatePasses, faultOutcome: outcomeOf } = VALIDATE_SITE_MAP[site ?? 'formula']; const faultOutcome = outcomeOf?.({ severity: severity ?? 'error', @@ -2415,13 +2512,18 @@ export function registerObjectTools( })), warnings: [], }; + // [#32872] …and, at a validation rule or a formula field, every other + // pass the gate runs there, in the gate's own words. + const gate = slotParse.success && gatePasses + ? await gatePassFindings(bridge, (name) => guard(name) === undefined, gatePasses, objectName, expression, severity) + : NO_GATE_PASS_FINDINGS; const inScope = introspectScope(role, hint); const inferredType = slotParse.success && role === 'value' ? inferExpressionType(expression, hint) : undefined; return textResult({ - ok: result.ok, - errors: result.errors, - warnings: result.warnings, + ok: result.ok && gate.errors.length === 0, + errors: [...result.errors, ...gate.errors], + warnings: [...result.warnings, ...gate.warnings], ...(inferredType ? { inferredType } : {}), inScope: { dialect: inScope.dialect, diff --git a/packages/mcp/src/mcp-validate-expression.test.ts b/packages/mcp/src/mcp-validate-expression.test.ts index 99309ea771b..ab0d3d141d1 100644 --- a/packages/mcp/src/mcp-validate-expression.test.ts +++ b/packages/mcp/src/mcp-validate-expression.test.ts @@ -7,7 +7,9 @@ import { TYPED_EXPRESSION_SOURCE_REQUIRED, } from '@objectstack/spec/shared'; -import { validateStackExpressions } from '@objectstack/lint'; +import { AUTHORED_FORMULA_FIELD_NAME, AUTHORED_RULE_NAME, validateStackExpressions } from '@objectstack/lint'; + +import { applyInjectedSystemColumns } from '@objectstack/metadata-core'; import { MCPServerRuntime } from './mcp-server-runtime.js'; import type { McpDataBridge } from './mcp-http-tools.js'; @@ -52,8 +54,12 @@ function mcpRequest(body: unknown): Request { }); } -async function call(runtime: MCPServerRuntime, body: unknown, bridge?: unknown) { - const res = await runtime.handleHttpRequest(mcpRequest(body), { bridge, parsedBody: body } as never); +async function call(runtime: MCPServerRuntime, body: unknown, bridge?: unknown, allowSystemObjects?: boolean) { + const res = await runtime.handleHttpRequest(mcpRequest(body), { + bridge, + parsedBody: body, + ...(allowSystemObjects !== undefined ? { toolOptions: { allowSystemObjects } } : {}), + } as never); const json = res.status === 202 ? null : await res.json(); return { status: res.status, json }; } @@ -62,8 +68,13 @@ const toolsCall = (id: number, name: string, args: Record) => ( jsonrpc: '2.0', id, method: 'tools/call', params: { name, arguments: args }, }); -async function validate(runtime: MCPServerRuntime, bridge: McpDataBridge, args: Record) { - const { json } = await call(runtime, toolsCall(1, 'validate_expression', args), bridge); +async function validate( + runtime: MCPServerRuntime, + bridge: McpDataBridge, + args: Record, + allowSystemObjects?: boolean, +) { + const { json } = await call(runtime, toolsCall(1, 'validate_expression', args), bridge, allowSystemObjects); return JSON.parse(json.result.content[0].text); } @@ -302,8 +313,10 @@ describe('validate_expression MCP tool (#1928)', () => { describe('validate_expression answers the gate on relationship traversal (#32640)', () => { const REQ = 'rtbw_leave_req'; const BAL = 'rtbw_leave_bal'; - // Required, so the gate's null-guard pass (which the tool does not run) - // has nothing to say and the two verdicts compare whole. + // Required, so the gate's null-guard pass has nothing to say and the two + // verdicts compare whole. (This bridge serves no definition, so the tool + // runs the shared validator alone: the gate's other passes are pinned in + // the #32872 block below.) const reqFields = { leave_type: { type: 'text', label: 'Leave type', required: true }, days: { type: 'number', label: 'Days', required: true }, @@ -418,3 +431,198 @@ describe('validate_expression answers the gate on relationship traversal (#32640 expect(verdicts(r).filter(([, m]) => /read BOTH through the relationship/.test(m!))).toEqual([]); }); }); + +// [#32872] At a validation rule and a formula field the publish gate judges +// with passes of its own beyond the shared validator, each private to +// `@objectstack/lint`'s walk. The tool asks the gate itself for them +// (`judgeAuthoredSiteExpression`) over the definitions the bridge serves +// (`servedObjectDefinitionOf`), so for each member below the tool refuses +// (or warns) where it answered `ok: true` before, in the gate's words, read +// off `validateStackExpressions` on the same rule or field. The list of the +// gate's passes at each site, and the pin that a new one cannot be added +// without this entry, is `packages/lint/src/authored-site-expression.test.ts`. +describe("validate_expression answers the gate's own passes at validation and formula sites (#32872)", () => { + const OBJECTS: Record> = { + gp_req: { + name: 'gp_req', + fields: { + days: { type: 'number', label: 'Days' }, + title: { type: 'text', label: 'Title', required: true }, + balance: { type: 'lookup', label: 'Balance', reference: 'gp_bal' }, + meta: { type: 'lookup', label: 'Meta', reference: 'sys_metadata' }, + header: { type: 'master_detail', label: 'Header', reference: 'gp_bal' }, + approver: { type: 'lookup', label: 'Approver', reference: 'sys_user' }, + gated: { type: 'lookup', label: 'Gated', reference: 'gp_gated' }, + }, + // The object's own rule is the gate's business at its own door, never this call's. + validations: [{ name: 'own', type: 'script', condition: 'record.days > 3', message: 'm' }], + }, + gp_bal: { name: 'gp_bal', fields: { remaining: { type: 'number', label: 'Remaining', required: true } } }, + // A system object the bridge serves, which the tool's object-name guard + // does not expose unless the server sets `allowSystemObjects`. + sys_user: { name: 'sys_user', fields: { email: { type: 'text', label: 'Email', required: true } } }, + // An object the data API does not serve (`enable.apiEnabled: false`): + // `describe_object` still describes it, as every MCP transport does. + gp_gated: { + name: 'gp_gated', + enable: { apiEnabled: false }, + fields: { code: { type: 'text', label: 'Code', required: true } }, + }, + gp_ext: { + name: 'gp_ext', + external: { remoteName: 'customers' }, + fields: { email: { type: 'text', label: 'Email', required: true } }, + }, + }; + /** As the registry serves it: the injected system columns are declared fields; `describeObject` projects them. */ + const served = (name: string) => (OBJECTS[name] ? applyInjectedSystemColumns(OBJECTS[name]) : null); + const reads: string[] = []; + /** Every record read or write the tool asks the bridge for: none, on every call below. */ + const recordCalls: string[] = []; + const gateBridge = (withDefinitions = true): McpDataBridge => ({ + ...makeBridge(), + async query(object: string) { + recordCalls.push(`query ${object}`); + return { records: [] }; + }, + async get(object: string) { + recordCalls.push(`get ${object}`); + return null; + }, + async listObjects() { + return Object.keys(OBJECTS).map((name) => ({ name })); + }, + async describeObject(name: string) { + const def = served(name); + if (!def) return null; + return { name, fields: Object.entries(def.fields).map(([n, f]) => ({ name: n, ...(f as object) })) }; + }, + ...(withDefinitions + ? { + async servedObjectDefinitionOf(name: string) { + reads.push(name); + return served(name); + }, + } + : {}), + }); + const verdicts = (r: { errors: { message: string }[]; warnings: { message: string }[] }) => [ + ...r.errors.map((e) => ['error', e.message]), + ...r.warnings.map((w) => ['warning', w.message]), + ]; + /** The gate's verdicts on the same rule or field, the object's own rules left out as the tool leaves them. */ + const gateOn = (site: 'validation' | 'formula', objectName: string, expression: string) => { + const { validations: _own, ...subject } = OBJECTS[objectName]!; + const judged = site === 'validation' + ? { ...subject, validations: [{ name: AUTHORED_RULE_NAME, type: 'script', condition: expression, message: 'm' }] } + : { ...subject, fields: { ...subject.fields, [AUTHORED_FORMULA_FIELD_NAME]: { type: 'formula', label: 'F', expression } } }; + const others = Object.keys(OBJECTS).filter((n) => n !== objectName).map((n) => OBJECTS[n]!); + const name = site === 'validation' ? AUTHORED_RULE_NAME : AUTHORED_FORMULA_FIELD_NAME; + return validateStackExpressions({ objects: [judged, ...others] }) + .filter((i) => i.where.includes(`'${name}'`)) + .map((i) => [i.severity ?? 'error', i.message]); + }; + const sorted = (v: unknown[][]) => [...v].sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b))); + + let runtime: MCPServerRuntime; + beforeEach(() => { + runtime = new MCPServerRuntime({ name: 'objectstack-test', version: '9.9.9' }); + reads.length = 0; + recordCalls.length = 0; + }); + + // [member, site, object, expression, severity, the subject the finding names] + const MEMBERS: Array<[string, 'validation' | 'formula', string, string, 'error' | 'warning', string]> = [ + ['null-guard gate', 'validation', 'gp_req', 'record.days > 3', 'error', 'days'], + ['undeclared field one hop away', 'validation', 'gp_req', 'record.balance.nope > 1', 'error', 'nope'], + ['undeclared field one hop away', 'formula', 'gp_req', 'record.balance.nope > 1 ? 1 : 0', 'error', 'nope'], + ['hop into a stored-metadata table', 'validation', 'gp_req', "record.meta.name == 'x'", 'error', 'sys_metadata'], + ['hop into a stored-metadata table', 'formula', 'gp_req', "record.meta.name == 'x' ? 1 : 0", 'error', 'sys_metadata'], + ['a validation rule reading `parent`', 'validation', 'gp_req', 'parent.remaining > 1', 'error', 'parent'], + ['unprovisioned anchor (warning)', 'validation', 'gp_ext', "record.owner_id == 'u1'", 'warning', 'owner_id'], + ['unprovisioned anchor (warning)', 'formula', 'gp_ext', "record.owner_id == 'u1' ? 1 : 0", 'warning', 'owner_id'], + ]; + + it('judges the authored body: an injected column is no declared nullable field', async () => { + const expression = "record.created_at > timestamp('2020-01-01T00:00:00Z')"; + expect(gateOn('validation', 'gp_req', expression)).toEqual([]); + const r = await validate(runtime, gateBridge(), { objectName: 'gp_req', expression, site: 'validation' }); + expect([r.ok, r.errors, r.warnings]).toEqual([true, [], []]); + }); + + for (const [member, site, objectName, expression, severity, names] of MEMBERS) { + it(`site ${site}: ${member} — the tool gives the gate's verdict`, async () => { + const gate = gateOn(site, objectName, expression); + expect(gate.map(([level]) => level)).toEqual([severity]); + const r = await validate(runtime, gateBridge(), { objectName, expression, site }); + expect(r.ok).toBe(severity !== 'error'); + expect(sorted(verdicts(r))).toEqual(sorted(gate)); + expect(verdicts(r).some(([, message]) => message!.includes(names))).toBe(true); + }); + } + + it('reads the definition of each object the expression reads through, and no other', async () => { + await validate(runtime, gateBridge(), { objectName: 'gp_req', expression: 'record.balance.nope > 1', site: 'validation' }); + expect(reads).toEqual(['gp_req', 'gp_bal']); + }); + + it('CONTROL — a clean rule and formula answer ok with the shape they always had', async () => { + const expression = "record.title == 'x' && record.balance.remaining > 1"; + for (const [site, source] of [['validation', expression], ['formula', `${expression} ? 1 : 0`]] as const) { + expect(gateOn(site, 'gp_req', source)).toEqual([]); + const withGate = await validate(runtime, gateBridge(), { objectName: 'gp_req', expression: source, site }); + const before = await validate(runtime, gateBridge(false), { objectName: 'gp_req', expression: source, site }); + expect(withGate.ok).toBe(true); + expect([withGate.errors, withGate.warnings]).toEqual([[], []]); + expect(withGate).toEqual(before); + } + }); + + it('a bridge that serves no definition answers the shared validator alone, as before', async () => { + const r = await validate(runtime, gateBridge(false), { objectName: 'gp_req', expression: 'record.days > 3', site: 'validation' }); + expect([r.ok, r.errors, r.warnings]).toEqual([true, [], []]); + }); + + it('a hop target follows the same system-object fence as describe_object', async () => { + const args = { objectName: 'gp_req', expression: 'record.approver.nope > 1', site: 'validation' }; + // The gate refuses the hop; a server that exposes system objects says so. + expect(gateOn('validation', 'gp_req', args.expression).map(([level]) => level)).toEqual(['error']); + const exposed = await validate(runtime, gateBridge(), args, true); + expect(exposed.ok).toBe(false); + expect(verdicts(exposed).some(([, message]) => message!.includes('nope'))).toBe(true); + expect(reads).toEqual(['gp_req', 'sys_user']); + // By default the target is neither read nor judged: the answer is the one + // a bridge serving no definition gives, as `describe_object` refuses it. + reads.length = 0; + const fenced = await validate(runtime, gateBridge(), args); + expect(reads).toEqual(['gp_req']); + expect(fenced).toEqual(await validate(runtime, gateBridge(false), args)); + expect(verdicts(fenced).some(([, message]) => message!.includes('nope'))).toBe(false); + }); + + // [#22661] The hop target's DEFINITION is read, never a record of it: the + // target's declared fields, which `describe_object` serves for the same + // object whatever its `enable` block says. So a target the data API does + // not serve is judged on the schema the caller can already describe, and + // no row of it is read or served. + it('judges a hop target the data API does not serve on its described schema, reading no record', async () => { + const args = { objectName: 'gp_req', expression: 'record.gated.nope > 1', site: 'validation' }; + expect(gateOn('validation', 'gp_req', args.expression).map(([level]) => level)).toEqual(['error']); + const r = await validate(runtime, gateBridge(), args); + expect(r.ok).toBe(false); + expect(verdicts(r).some(([, message]) => message!.includes('nope'))).toBe(true); + expect(reads).toEqual(['gp_req', 'gp_gated']); + // …a schema `describe_object` serves to the same caller… + const { json } = await call(runtime, toolsCall(2, 'describe_object', { objectName: 'gp_gated' }), gateBridge()); + const described = JSON.parse((json as { result: { content: Array<{ text: string }> } }).result.content[0]!.text); + expect(described.fields.map((f: { name: string }) => f.name)).toContain('code'); + // …and nothing of any record, of the target or of the subject. + expect(recordCalls).toEqual([]); + }); + + it('does not judge a flow condition or a template: no definition is read there', async () => { + await validate(runtime, gateBridge(), { objectName: 'gp_req', expression: 'days > 3', site: 'flow_condition' }); + await validate(runtime, gateBridge(), { objectName: 'gp_req', expression: '{{record.title}}', site: 'template' }); + expect(reads).toEqual([]); + }); +}); diff --git a/packages/mcp/src/mcp-write-response-internal-fields.tripwire.test.ts b/packages/mcp/src/mcp-write-response-internal-fields.tripwire.test.ts index 7943913908e..c8e25073c31 100644 --- a/packages/mcp/src/mcp-write-response-internal-fields.tripwire.test.ts +++ b/packages/mcp/src/mcp-write-response-internal-fields.tripwire.test.ts @@ -156,6 +156,9 @@ const RECIPES: Record = { // [#28715] Field NAMES off the object definition `describeObject` reads: no // engine read, no record, so nothing stored can ride this answer. optionFieldsOf: { invoke: (b) => b.optionFieldsOf('vault'), writesRecords: false }, + // [#32872] The object definition `describeObject` reads, handed to the + // publish gate's passes and rendered to nobody: no engine read, no record. + servedObjectDefinitionOf: { invoke: (b) => b.servedObjectDefinitionOf('vault'), writesRecords: false }, query: { invoke: (b) => b.query('vault', {}), writesRecords: false }, get: { invoke: (b) => b.get('vault', 'row-1'), writesRecords: false }, aggregate: { invoke: (b) => b.aggregate('vault', {}), writesRecords: false }, diff --git a/packages/mcp/src/skill-md.ts b/packages/mcp/src/skill-md.ts index 20f890459b2..040382577c8 100644 --- a/packages/mcp/src/skill-md.ts +++ b/packages/mcp/src/skill-md.ts @@ -405,11 +405,18 @@ create/update payload. - **validate_expression({ objectName, expression, site?, severity?, triggerKind?, sweepObject? })** — check a CEL expression against an object's schema *before* you author it into a formula, validation, or flow condition. Returns build-time errors (bare field refs, - unknown fields/functions) and advisory warnings (text/boolean fields misused - in arithmetic; an error at a \`validation\` site, worded for the rule's - \`severity\`, and at a \`flow_condition\` of a record-triggered or - time-relative flow, where it fails the run; a warning on any other flow), plus the fields and - stdlib functions in scope. \`site\` is \`formula\` | \`validation\` | + unknown fields/functions; at a \`formula\` or \`validation\` site, every other + refusal the publish gate gives there: a reference read both through the + relationship and as a value, more than one hop, a hop to a field the target + does not declare or into a stored-metadata table, and at a \`validation\` site + an unguarded nullable field or a read of \`parent\`) and advisory warnings + (text/boolean fields misused in arithmetic; an error at a \`validation\` site, + worded for the rule's \`severity\`, and at a \`flow_condition\` of a + record-triggered or time-relative flow, where it fails the run; a warning on + any other flow; at a \`formula\` or \`validation\` site, a read of an + external object's unprovisioned system column), plus the fields and stdlib + functions in scope. A hop target follows the same system-object fence as + \`describe_object\`. \`site\` is \`formula\` | \`validation\` | \`flow_condition\` | \`template\` (default \`formula\`). Pass the rule's \`severity\` or the flow's \`triggerKind\` (\`record_change\` by default) to get the verdict the publish gate gives that rule or flow; for a diff --git a/packages/mcp/src/stdio-data-bridge.stored-metadata-body.test.ts b/packages/mcp/src/stdio-data-bridge.stored-metadata-body.test.ts index 3e30be9e62b..3b9201178a1 100644 --- a/packages/mcp/src/stdio-data-bridge.stored-metadata-body.test.ts +++ b/packages/mcp/src/stdio-data-bridge.stored-metadata-body.test.ts @@ -467,6 +467,7 @@ const BRIDGE_MEMBERS: Record = { listObjectsDiagnosed: 'no row body — object definitions from the metadata service', describeObject: 'no row body — one object definition from the metadata service', optionFieldsOf: 'no row body — field names from the same object definition describeObject reads', + servedObjectDefinitionOf: 'no row body — the same object definition describeObject reads, judged by the gate and rendered to nobody', query: 'seam — serveStoredMetadataRows; filter / sort on the body column refused', get: 'seam — serveStoredMetadataRow', aggregate: 'refuses — group / filter / aggregate member on the body column', diff --git a/packages/mcp/src/stdio-data-bridge.ts b/packages/mcp/src/stdio-data-bridge.ts index 02a9bb2b8a5..3944e7919da 100644 --- a/packages/mcp/src/stdio-data-bridge.ts +++ b/packages/mcp/src/stdio-data-bridge.ts @@ -1184,6 +1184,16 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge .map(([key]) => key); }, + // [#32872] The object `describeObject` reads, whole: what + // `validate_expression` hands the publish gate's own passes at a + // validation rule or a formula field. Rendered to nobody; the tool answers + // the gate's findings only. + // [ADR-0106 D1] …the principal's object, so no field it cannot read is judged. + async servedObjectDefinitionOf(name: string): Promise | null> { + const def = (await servedView.getObject(name)) as Record | undefined; + return def ?? null; + }, + async query(object, opts) { const context = await resolvePrincipal(); await enforceApiExposure(reads, object, GATED_ACTIONS.query, context); diff --git a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts index 026d2c76300..41bd3d2b243 100644 --- a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts +++ b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts @@ -3,8 +3,9 @@ /** * [ADR-0106 D1/D5] The HTTP MCP bridge's object-schema reads answer a caller * the field set the `/meta` object door answers that caller: `describeObject` - * (behind `describe_object` and `validate_expression`), `optionFieldsOf` and - * `listObjects`' `fieldCount` go through the door's own masker and projection + * (behind `describe_object` and `validate_expression`), `optionFieldsOf`, + * `servedObjectDefinitionOf` (#32872, the definition `validate_expression` + * hands the publish gate's passes) and `listObjects`' `fieldCount` go through the door's own masker and projection * (`resolveObjectMasker` / `maskObjectSchema`, `domains/meta.ts`). * * Two halves: @@ -122,9 +123,11 @@ describe('[ADR-0106] HTTP MCP bridge object-schema reads — the shared case tab described: await settle(() => bridge.describeObject(OBJECT)), listed: await settle(() => bridge.listObjects()), options: await settle(() => bridge.optionFieldsOf(OBJECT)), + definition: await settle(() => bridge.servedObjectDefinitionOf(OBJECT)), // The same caller's answers for a name nothing declares. unknownDescribed: await settle(() => bridge.describeObject('no_such_object')), unknownOptions: await settle(() => bridge.optionFieldsOf('no_such_object')), + unknownDefinition: await settle(() => bridge.servedObjectDefinitionOf('no_such_object')), }; } @@ -143,12 +146,13 @@ describe('[ADR-0106] HTTP MCP bridge object-schema reads — the shared case tab // declares, and left out of the listing. expect(reads.described).toEqual(reads.unknownDescribed); expect(reads.options).toEqual(reads.unknownOptions); + expect(reads.definition).toEqual(reads.unknownDefinition); expect(reads.described.value).toBeNull(); expect((reads.listed.value as any[]).map((o) => o.name)).not.toContain(OBJECT); return; } if (expected.kind === 'fault') { - for (const read of [reads.described, reads.listed, reads.options]) { + for (const read of [reads.described, reads.listed, reads.options, reads.definition]) { expect(read.error, `${testCase.id}: refused, never served`).toBeDefined(); expect({ code: read.error.code, status: read.error.status }).toEqual(REFUSED); } @@ -159,14 +163,18 @@ describe('[ADR-0106] HTTP MCP bridge object-schema reads — the shared case tab expect(JSON.stringify(reads.described.value)).toBe(JSON.stringify(baseline.described.value)); expect(JSON.stringify(reads.listed.value)).toBe(JSON.stringify(baseline.listed.value)); expect(JSON.stringify(reads.options.value)).toBe(JSON.stringify(baseline.options.value)); + expect(JSON.stringify(reads.definition.value)).toBe(JSON.stringify(baseline.definition.value)); return; } const described: any = reads.described.value; expect(described.fields.map((f: any) => f.name)) .toEqual(FLS_CONTRACT_ALL_FIELDS.filter((name) => expected.present.includes(name))); expect((reads.listed.value as any[]).find((o) => o.name === OBJECT)?.fieldCount).toBe(expected.present.length); + // [#32872] The definition the gate's passes judge is the same caller's object. + expect(Object.keys((reads.definition.value as any).fields).sort()) + .toEqual(FLS_CONTRACT_ALL_FIELDS.filter((name) => expected.present.includes(name)).sort()); for (const name of expected.absent) { - for (const read of [reads.described, reads.listed, reads.options]) { + for (const read of [reads.described, reads.listed, reads.options, reads.definition]) { expect(JSON.stringify(read.value), `${testCase.id}: '${name}' must not exist for this caller`) .not.toMatch(new RegExp(`\\b${name}\\b`)); } diff --git a/packages/runtime/src/domains/mcp-option-fields-read.test.ts b/packages/runtime/src/domains/mcp-option-fields-read.test.ts index fcdefc45836..befab0a0755 100644 --- a/packages/runtime/src/domains/mcp-option-fields-read.test.ts +++ b/packages/runtime/src/domains/mcp-option-fields-read.test.ts @@ -101,3 +101,31 @@ describe('buildMcpBridge.optionFieldsOf reads the served object describeObject r }); } }); + +// [#32872] `servedObjectDefinitionOf(name)`: the object `describeObject` +// projects, whole — what `validate_expression` hands the publish gate's own +// passes at a validation rule or a formula field (a field's `required`, a +// reference's target, the object's rules), rendered to nobody. Its masking +// for each ADR-0106 tier is pinned in `mcp-object-schema-mask.test.ts`. +describe('buildMcpBridge.servedObjectDefinitionOf reads the object describeObject reads (#32872)', () => { + const prev = process.env.OS_MCP_SERVER_ENABLED; + beforeEach(() => { + process.env.OS_MCP_SERVER_ENABLED = 'true'; + }); + afterEach(() => { + if (prev === undefined) delete process.env.OS_MCP_SERVER_ENABLED; + else process.env.OS_MCP_SERVER_ENABLED = prev; + }); + + for (const withProtocol of [true, false]) { + const read = withProtocol ? 'the merged listing' : 'the metadata service (no merged read)'; + it(`answers the served definition whole from ${read}, and null for a name nothing serves`, async () => { + const bridge = await bridgeFor(makeKernel({ withProtocol })); + const def = await bridge.servedObjectDefinitionOf('qaformula_p4'); + expect(def).toEqual(SERVED); + const described = await bridge.describeObject('qaformula_p4'); + expect(Object.keys(def.fields)).toEqual(described.fields.map((f: any) => f.name)); + expect(await bridge.servedObjectDefinitionOf('qa_absent')).toBeNull(); + }); + } +}); diff --git a/packages/runtime/src/domains/mcp.ts b/packages/runtime/src/domains/mcp.ts index 0ab4d2977d6..12958f6f076 100644 --- a/packages/runtime/src/domains/mcp.ts +++ b/packages/runtime/src/domains/mcp.ts @@ -947,6 +947,15 @@ export function buildMcpBridge( .filter(([, f]) => declaresOptions(f)) .map(([k]) => k); }, + // [#32872] The object `describeObject` reads, whole: what + // `validate_expression` hands the publish gate's own passes at a + // validation rule or a formula field. Rendered to nobody; the tool + // answers the gate's findings only. + // [ADR-0106 D1] …the same caller's object, so no field it cannot read is judged. + servedObjectDefinitionOf: async (name: string): Promise | null> => { + const def: any = await readObjectForCaller(name); + return def ?? null; + }, query: async (object: string, o: any) => { const query: any = {}; if (o?.where) query.where = o.where; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index af7ac8c04c8..d5f776b1ffe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1421,6 +1421,9 @@ importers: '@objectstack/formula': specifier: workspace:* version: link:../formula + '@objectstack/lint': + specifier: workspace:* + version: link:../lint '@objectstack/metadata-core': specifier: workspace:* version: link:../metadata-core @@ -1437,9 +1440,6 @@ importers: specifier: ^4.6.6 version: 4.6.7 devDependencies: - '@objectstack/lint': - specifier: workspace:* - version: link:../lint '@types/node': specifier: ^26.6.5 version: 26.6.5 diff --git a/scripts/cross-package-test-inputs.mjs b/scripts/cross-package-test-inputs.mjs index 0b5174700ec..ad90fd874f9 100644 --- a/scripts/cross-package-test-inputs.mjs +++ b/scripts/cross-package-test-inputs.mjs @@ -1013,6 +1013,12 @@ export const CROSS_PACKAGE_TEST_INPUTS = { 'examples/app-showcase/src/data/objects/task.object.ts', 'examples/app-showcase/src/ui/views/task.view.ts', 'sdui.manifest.json', + // src/authored-site-expression.test.ts (#32872) IMPORTS the tree's one + // code/prose separator to list the calls the gate's walk makes at a + // validation or formula site without counting the comments that name + // them. A real read: the enumeration changes if the mask does. + 'scripts/js-comment-mask.mjs', + 'scripts/js-comment-mask.d.mts', ], heldBy: { // `const commandsDir = join(repoRoot, 'packages/cli/src/commands')` diff --git a/turbo.json b/turbo.json index d3385846342..0ed76a8a7e1 100644 --- a/turbo.json +++ b/turbo.json @@ -375,7 +375,9 @@ "$TURBO_ROOT$/examples/app-showcase/src/ui/pages/task-visualizations.pages.ts", "$TURBO_ROOT$/examples/app-showcase/src/data/objects/task.object.ts", "$TURBO_ROOT$/examples/app-showcase/src/ui/views/task.view.ts", - "$TURBO_ROOT$/sdui.manifest.json" + "$TURBO_ROOT$/sdui.manifest.json", + "$TURBO_ROOT$/scripts/js-comment-mask.mjs", + "$TURBO_ROOT$/scripts/js-comment-mask.d.mts" ] }, "@objectstack/cloud-connection#test": { diff --git a/ui/apps/console/src/pages/developer/objectstack-skill.ts b/ui/apps/console/src/pages/developer/objectstack-skill.ts index 1db1761dfe4..9425e4316b8 100644 --- a/ui/apps/console/src/pages/developer/objectstack-skill.ts +++ b/ui/apps/console/src/pages/developer/objectstack-skill.ts @@ -133,11 +133,18 @@ create/update payload. - **validate_expression({ objectName, expression, site?, severity?, triggerKind?, sweepObject? })** — check a CEL expression against an object's schema *before* you author it into a formula, validation, or flow condition. Returns build-time errors (bare field refs, - unknown fields/functions) and advisory warnings (text/boolean fields misused - in arithmetic; an error at a \`validation\` site, worded for the rule's - \`severity\`, and at a \`flow_condition\` of a record-triggered or - time-relative flow, where it fails the run; a warning on any other flow), plus the fields and - stdlib functions in scope. \`site\` is \`formula\` | \`validation\` | + unknown fields/functions; at a \`formula\` or \`validation\` site, every other + refusal the publish gate gives there: a reference read both through the + relationship and as a value, more than one hop, a hop to a field the target + does not declare or into a stored-metadata table, and at a \`validation\` site + an unguarded nullable field or a read of \`parent\`) and advisory warnings + (text/boolean fields misused in arithmetic; an error at a \`validation\` site, + worded for the rule's \`severity\`, and at a \`flow_condition\` of a + record-triggered or time-relative flow, where it fails the run; a warning on + any other flow; at a \`formula\` or \`validation\` site, a read of an + external object's unprovisioned system column), plus the fields and stdlib + functions in scope. A hop target follows the same system-object fence as + \`describe_object\`. \`site\` is \`formula\` | \`validation\` | \`flow_condition\` | \`template\` (default \`formula\`). Pass the rule's \`severity\` or the flow's \`triggerKind\` (\`record_change\` by default) to get the verdict the publish gate gives that rule or flow; for a