Skip to content

Commit e27387e

Browse files
committed
test(lint): pin every field-path rule on extension-added fields
One artifact for all fourteen rules: a module package adds fields to the app package's object. Each existence rule passes the extension-added field, refuses it without the extension, and still refuses a field nothing adds under the same rule id; the type arms judge the served definition; the two retired readers keep one entry per package per target. Adds the changeset. Claude-Session: https://claude.ai/code/session_01WGufzg3UmwhpAtL969c7YG Co-authored-by: Claude <noreply@anthropic.com>
1 parent fdf882b commit e27387e

3 files changed

Lines changed: 191 additions & 12 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@objectstack/lint': patch
3+
---
4+
5+
fix(lint): the field-path rules judge an object as the registry serves it, so a view, report, dataset, page, widget, mapping, related list or row policy naming a field that an `objectExtensions` entry adds is no longer refused (#30383)
6+
7+
Clause-②: yes (widening: field-path rules accept fields a sibling package adds through `objectExtensions`, which the runtime already serves; any rule that deliberately stays on declared fields says why in its header)
8+
Metadata-protocol: none (lint judgements, no authorable key)
9+
10+
- **Before.** Twelve rules resolved a field path against the objects' declared `fields` only: dataset fields and filters, report runtime filters, dashboard widget filters, list view columns and keys, an object's own field lists, page bindings, filter preset comparands, RLS predicates, sharing-rule criteria, thank-you panels, measure aggregates and the field-consumer credit for dataset paths. On a multi-package artifact, where a module package adds fields to an app package's object through `objectExtensions`, a path naming one of those fields read as unknown (for example `dataset-field-unknown`, `list-view-field-unknown`, `rls-predicate-unknown-field`) although the runtime serves the field. Two rules folded extensions through readers of their own: `related-list-ref-unknown` read only the stack's top-level `objectExtensions`, so an inbound lookup a sibling package adds was not seen, and `mapping-target-field-unknown` kept every entry, where the registry keeps one per package per object.
11+
- **Now.** Every one of them reads the one shared fold in `object-graph.ts`: the object's declared fields plus every field an `objectExtensions` entry of any body of the artifact adds, one entry per package per object, a later entry replacing an earlier one. A field no body declares or adds keeps the same refusal, with the same rule id, severity and message. The rules that judge a field's type (measure aggregates, preset comparands, sharing-rule criteria, thank-you panels) judge an extension-added field on its served definition, as they judge a declared one.

‎packages/lint/src/object-graph.test.ts‎

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ import {
2020
RELATIONSHIP_FIELD_TYPES,
2121
} from './object-graph.js';
2222
import { walkFilterFieldKeys, type FilterFieldKey } from './filter-walk.js';
23+
import { DATASET_FIELD_UNKNOWN, validateDatasetReferences } from './validate-dataset-references.js';
24+
import { MEASURE_AGGREGATE_FIELD_TYPE_REFUSED, validateDatasetMeasureAggregates } from './validate-dataset-measure-aggregates.js';
25+
import { FIELD_NO_CONSUMERS, validateFieldConsumers } from './validate-field-consumers.js';
26+
import { LIST_VIEW_FIELD_UNKNOWN, validateListViewFieldRefs } from './validate-list-view-field-refs.js';
27+
import { MAPPING_TARGET_FIELD_UNKNOWN, validateMappingTargetFields } from './validate-mapping-target-fields.js';
28+
import { OBJECT_FIELD_REF_UNKNOWN, validateObjectFieldRefs } from './validate-object-field-refs.js';
29+
import { PAGE_FIELD_UNKNOWN, validatePageFieldBindings } from './validate-page-field-bindings.js';
30+
import { FILTER_PRESET_COMPARAND, validatePresetComparands } from './validate-preset-comparands.js';
31+
import { RELATED_LIST_REF_UNKNOWN, validateRelatedListRefs } from './validate-related-list-refs.js';
32+
import { REPORT_FILTER_FIELD_UNKNOWN, validateReportRuntimeFilters } from './validate-report-runtime-filter.js';
33+
import { RLS_PREDICATE_UNKNOWN_FIELD, validateRlsPredicateEnforceability } from './validate-rls-predicate-enforceability.js';
34+
import { SHARING_RULE_UNLOWERABLE_CONDITION, validateSharingRuleEnforceability } from './validate-sharing-rule-enforceability.js';
35+
import { THANK_YOU_RECORD_FIELD, validateThankYouRecordFields } from './validate-thank-you-record-fields.js';
36+
import { WIDGET_FILTER_FIELD_UNKNOWN, validateWidgetBindings } from './validate-widget-bindings.js';
2337
// [#16340] Read back the registry's OWN definition table to assert the graph
2438
// derives its injected types rather than carrying a second copy of them.
2539
import { injectedSystemColumnDefs } from '@objectstack/spec/data';
@@ -532,3 +546,148 @@ describe('[#19289] object-graph — a `user` field takes its target from the TYP
532546
expect(() => indexObjectGraph(broken)).toThrow(/`reference` is an object/);
533547
});
534548
});
549+
550+
// [#30383] The field-path rules resolve through the fold above. One artifact
551+
// for all of them: a module package (`mod`) adds fields to the app package's
552+
// `xs_deal` through `objectExtensions`, the HotCRM shape. Per rule: a path
553+
// naming an extension-added field passes, the same stack without the
554+
// extension still refuses it (the pin is not vacuous), and a field no body
555+
// declares or extends is refused under the same rule id as before.
556+
describe('[#30383] the field-path rules read the objects as served', () => {
557+
type Rec = Record<string, unknown>;
558+
type Run = (stack: Rec) => ReadonlyArray<{ rule: string }>;
559+
const deal = { name: 'xs_deal', fields: { name: { type: 'text' }, account: { type: 'lookup', reference: 'xs_account' } } };
560+
const account = { name: 'xs_account', fields: { name: { type: 'text' }, tier: { type: 'text' } } };
561+
const note = { name: 'xs_note', fields: { body: { type: 'text' } } };
562+
const added = {
563+
region: { type: 'text' },
564+
score: { type: 'number' },
565+
closed_on: { type: 'date' },
566+
ref_no: { type: 'autonumber' },
567+
partner: { type: 'lookup', reference: 'xs_account' },
568+
};
569+
const extensions = [
570+
{ extend: 'xs_deal', fields: added },
571+
{ extend: 'xs_note', fields: { deal_id: { type: 'lookup', reference: 'xs_deal' } } },
572+
];
573+
const artifact = (extra: Rec, objectExtensions: unknown[] = extensions): Rec => ({
574+
objects: [deal, account, note],
575+
packages: [
576+
{ manifest: { id: 'app', objects: [deal, account, note] } },
577+
{ manifest: { id: 'mod', objectExtensions } },
578+
],
579+
...extra,
580+
});
581+
const ids = (run: Run, stack: Rec) => run(stack).map((f) => f.rule);
582+
const dataset = (field: string) => ({
583+
name: 'deals', object: 'xs_deal', include: ['partner'],
584+
dimensions: [{ name: 'd', field }], measures: [{ name: 'n', aggregate: 'count' }],
585+
});
586+
const widget = (filter: Rec) => ({
587+
datasets: [dataset('name')],
588+
dashboards: [{ name: 'b', widgets: [{ id: 'w', type: 'metric', dataset: 'deals', values: ['n'], filter }] }],
589+
});
590+
591+
// rule · its unknown-field id · the stack naming FIELD
592+
const existence: Array<[string, string, Run, (field: string) => Rec]> = [
593+
['validate-dataset-references', DATASET_FIELD_UNKNOWN, validateDatasetReferences, (f) => ({ datasets: [dataset(f)] })],
594+
['validate-report-runtime-filter', REPORT_FILTER_FIELD_UNKNOWN, validateReportRuntimeFilters, (f) => ({
595+
datasets: [dataset('name')],
596+
reports: [{ name: 'r', label: 'R', type: 'summary', dataset: 'deals', values: ['n'], rows: ['d'], runtimeFilter: { [f]: 'x' } }],
597+
})],
598+
['validate-widget-bindings', WIDGET_FILTER_FIELD_UNKNOWN, validateWidgetBindings, (f) => widget({ [f]: 'x' })],
599+
['validate-list-view-field-refs', LIST_VIEW_FIELD_UNKNOWN, validateListViewFieldRefs, (f) => ({
600+
views: [{ name: 'v', object: 'xs_deal', list: { type: 'grid', columns: ['name', f] } }],
601+
})],
602+
['validate-object-field-refs', OBJECT_FIELD_REF_UNKNOWN, validateObjectFieldRefs, (f) => ({
603+
objects: [{ ...deal, highlightFields: ['name', f] }, account, note],
604+
})],
605+
['validate-page-field-bindings', PAGE_FIELD_UNKNOWN, validatePageFieldBindings, (f) => ({
606+
pages: [{
607+
name: 'p', object: 'xs_deal',
608+
regions: [{ name: 'main', components: [{ type: 'record:highlights', properties: { fields: ['name', f] } }] }],
609+
}],
610+
})],
611+
['validate-rls-predicate-enforceability', RLS_PREDICATE_UNKNOWN_FIELD, validateRlsPredicateEnforceability, (f) => ({
612+
permissions: [{ name: 's', label: 'S', rowLevelSecurity: [{ name: 'p', object: 'xs_deal', operation: 'select', using: `record.${f} == 'x'` }] }],
613+
})],
614+
['validate-thank-you-record-fields', THANK_YOU_RECORD_FIELD, validateThankYouRecordFields, (f) => ({
615+
views: [{
616+
name: 'vv',
617+
form: {
618+
type: 'simple', data: { provider: 'object', object: 'xs_deal' }, sections: [{ name: 'a', fields: ['name'] }],
619+
submitBehavior: { kind: 'thank-you', title: 'T', message: `Ref {{record.${f}}}` },
620+
},
621+
}],
622+
})],
623+
['validate-mapping-target-fields', MAPPING_TARGET_FIELD_UNKNOWN, validateMappingTargetFields, (f) => ({
624+
mappings: [{ name: 'm', targetObject: 'xs_deal', fieldMapping: [{ source: 'R', target: f }] }],
625+
})],
626+
];
627+
it.each(existence)('%s: an extension-added field passes; a field nothing adds is still %s', (_rule, id, run, naming) => {
628+
// `ref_no` (an autonumber) is the one name every member admits, the
629+
// thank-you panel included.
630+
expect(ids(run, artifact(naming('ref_no')))).not.toContain(id);
631+
expect(ids(run, artifact(naming('ref_no'), []))).toContain(id);
632+
expect(ids(run, artifact(naming('nowhere')))).toContain(id);
633+
});
634+
635+
it('validate-dataset-references: a path through an extension-added relationship resolves', () => {
636+
expect(ids(validateDatasetReferences, artifact({ datasets: [dataset('partner.tier')] }))).toEqual([]);
637+
expect(ids(validateDatasetReferences, artifact({ datasets: [dataset('partner.nowhere')] }))).toEqual([DATASET_FIELD_UNKNOWN]);
638+
});
639+
640+
// The type arms judge an extension-added field on its served definition,
641+
// as they judge a declared one; a name nothing adds stays the existence
642+
// rules' finding, not theirs.
643+
it('validate-dataset-measure-aggregates: SUM over an extension-added field is judged on its served type', () => {
644+
const sum = (field: string) => ({ datasets: [{ name: 'deals', object: 'xs_deal', measures: [{ name: 's', aggregate: 'sum', field }] }] });
645+
expect(ids(validateDatasetMeasureAggregates, artifact(sum('score')))).toEqual([]);
646+
expect(ids(validateDatasetMeasureAggregates, artifact(sum('region')))).toEqual([MEASURE_AGGREGATE_FIELD_TYPE_REFUSED]);
647+
expect(ids(validateDatasetMeasureAggregates, artifact(sum('nowhere')))).toEqual([]);
648+
});
649+
650+
it('validate-preset-comparands: a preset compared with an extension-added date field is judged as on a declared one', () => {
651+
expect(ids(validatePresetComparands, artifact(widget({ closed_on: 'last_30_days' })))).toEqual([FILTER_PRESET_COMPARAND]);
652+
expect(ids(validatePresetComparands, artifact(widget({ region: 'last_30_days' })))).toEqual([]);
653+
});
654+
655+
it('validate-sharing-rule-enforceability: a criterion on an extension-added field is judged on its served type', () => {
656+
const rule = (condition: string) => ({ sharingRules: [{ name: 'sr', object: 'xs_deal', condition, sharedWith: { type: 'role', value: 'r' }, accessLevel: 'read' }] });
657+
expect(ids(validateSharingRuleEnforceability, artifact(rule('record.region == record.name')))).toEqual([]);
658+
expect(ids(validateSharingRuleEnforceability, artifact(rule('record.closed_on == record.name')))).toEqual([SHARING_RULE_UNLOWERABLE_CONDITION]);
659+
});
660+
661+
it('validate-field-consumers: a dataset path through an extension-added lookup credits the field it reaches', () => {
662+
const tierFindings = (stack: Rec) =>
663+
validateFieldConsumers(stack).filter((f) => f.object === 'xs_account' && f.field === 'tier').map((f) => f.rule);
664+
expect(tierFindings(artifact({ datasets: [dataset('partner.tier')] }))).toEqual([]);
665+
expect(tierFindings(artifact({ datasets: [dataset('name')] }))).toEqual([FIELD_NO_CONSUMERS]);
666+
// Extension-added fields are still not judged themselves (the header).
667+
expect(validateFieldConsumers(artifact({ datasets: [dataset('name')] })).filter((f) => f.field in added)).toEqual([]);
668+
});
669+
670+
it('validate-related-list-refs: an FK a sibling package adds is an inbound relationship', () => {
671+
const lists = (relatedLists: string[]) => ({ objects: [{ ...deal, relatedLists }, account, note] });
672+
expect(ids(validateRelatedListRefs, artifact(lists(['xs_note', 'xs_note.deal_id'])))).toEqual([]);
673+
expect(ids(validateRelatedListRefs, artifact(lists(['xs_note']), []))).toEqual([RELATED_LIST_REF_UNKNOWN]);
674+
expect(ids(validateRelatedListRefs, artifact(lists(['xs_note.nowhere'])))).toEqual([RELATED_LIST_REF_UNKNOWN]);
675+
});
676+
677+
// The two retired private readers folded every entry additively; the shared
678+
// fold keeps the registry's one entry per package per target, so a later
679+
// entry of the same package replaces an earlier one whole.
680+
it('both retired readers now keep one entry per package per target, as the registry does', () => {
681+
const replaced = [
682+
{ extend: 'xs_note', fields: { deal_id: { type: 'lookup', reference: 'xs_deal' } } },
683+
{ extend: 'xs_note', fields: { body_html: { type: 'html' } } },
684+
{ extend: 'xs_deal', fields: { region: { type: 'text' } } },
685+
{ extend: 'xs_deal', fields: { score: { type: 'number' } } },
686+
];
687+
const lists = { objects: [{ ...deal, relatedLists: ['xs_note'] }, account, note] };
688+
expect(ids(validateRelatedListRefs, artifact(lists, replaced))).toEqual([RELATED_LIST_REF_UNKNOWN]);
689+
const mapping = (target: string) => ({ mappings: [{ name: 'm', targetObject: 'xs_deal', fieldMapping: [{ source: 'R', target }] }] });
690+
expect(ids(validateMappingTargetFields, artifact(mapping('score'), replaced))).toEqual([]);
691+
expect(ids(validateMappingTargetFields, artifact(mapping('region'), replaced))).toEqual([MAPPING_TARGET_FIELD_UNKNOWN]);
692+
});
693+
});

‎packages/lint/src/validate-mapping-target-fields.test.ts‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,31 @@ describe('validateMappingTargetFields', () => {
181181
});
182182

183183
it('folds fields an objectExtensions entry merges into the object — from the stack and from a sibling package', () => {
184-
const stack = {
184+
const mappings = [mapping([
185+
{ source: 'Tier', target: 'sla_tier' },
186+
{ source: 'Region', target: 'region' },
187+
])];
188+
// [#30383] Read through the shared fold, as the registry registers them:
189+
// the stack's own entries when it carries no `packages[]`, and every
190+
// body's when it does (an artifact's top level repeats its bodies).
191+
expect(validateMappingTargetFields({
185192
objects: [contact],
186-
objectExtensions: [{ extend: 'crm_contact', fields: { sla_tier: { type: 'text' } } }],
187-
packages: [{ manifest: { objectExtensions: [{ extend: 'crm_contact', fields: { region: { type: 'text' } } }] } }],
188-
mappings: [mapping([
189-
{ source: 'Tier', target: 'sla_tier' },
190-
{ source: 'Region', target: 'region' },
191-
])],
192-
};
193-
expect(validateMappingTargetFields(stack)).toEqual([]);
193+
objectExtensions: [{ extend: 'crm_contact', fields: { sla_tier: { type: 'text' }, region: { type: 'text' } } }],
194+
mappings,
195+
})).toEqual([]);
196+
expect(validateMappingTargetFields({
197+
objects: [contact],
198+
packages: [
199+
{ manifest: { objects: [contact], objectExtensions: [{ extend: 'crm_contact', fields: { sla_tier: { type: 'text' } } }] } },
200+
{ manifest: { objectExtensions: [{ extend: 'crm_contact', fields: { region: { type: 'text' } } }] } },
201+
],
202+
mappings,
203+
})).toEqual([]);
194204
});
195205

196206
it('CONTROL — `packages: undefined` (absent) stays silent — the only value this reader treats as absent', () => {
197-
// `full_name`, not `sla_tier`: `sla_tier` resolves via the STACK's own
198-
// top-level `objectExtensions` (the test above, :173) — `region` is the
199-
// one that needs a package (:174). Either way, with `packages` genuinely
207+
// `full_name`, not `sla_tier`: `sla_tier` resolves only through an
208+
// `objectExtensions` entry (the test above). With `packages` genuinely
200209
// absent this control needs a field `contact` declares on its own, so a
201210
// real finding can't masquerade as the reader silently accepting the
202211
// shape.

0 commit comments

Comments
 (0)