-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathreference-integrity-suite.test.ts
More file actions
281 lines (271 loc) · 11.9 KB
/
Copy pathreference-integrity-suite.test.ts
File metadata and controls
281 lines (271 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
import { describe, it, expect } from 'vitest';
import {
validateReferenceIntegrity,
REFERENCE_INTEGRITY_RULES,
} from './reference-integrity-suite.js';
import { validateObjectReferences } from './validate-object-references.js';
import { validateTranslationReferences } from './validate-translation-references.js';
describe('reference-integrity suite — membership', () => {
// Deliberately a written-out list: adding a rule to the suite should be a
// conscious edit in two places (the suite and this test), not something that
// slips in unreviewed. The list is also the answer to "which rules run on
// `validate` / `lint` / `compile`?".
it('holds exactly the reference-resolution rules, in report order', () => {
expect(REFERENCE_INTEGRITY_RULES.map((r) => r.name)).toEqual([
'validateObjectReferences',
'validateSearchableFields',
'validateActionNameRefs',
'validatePageFieldBindings',
'validateChartBindings',
'validateNavAccess',
'validateNavTargetRefs',
'validateTranslationReferences',
'validateFlowTemplatePaths',
'validateAiSurfaceAffinity',
'validateAiToolReferences',
'validateAiAgentAuthoring',
'validateHookBodyWrites',
'validateActionBodyWrites',
'validateFlowNodeWrites',
'validateReadonlyFlowWrites',
'validateReactPageProps',
]);
});
it('wires the same function the package exports', () => {
const byName = new Map(REFERENCE_INTEGRITY_RULES.map((r) => [r.name, r.run]));
expect(byName.get('validateObjectReferences')).toBe(validateObjectReferences);
expect(byName.get('validateTranslationReferences')).toBe(validateTranslationReferences);
});
});
describe('reference-integrity suite — every member actually runs', () => {
/**
* One live instance per rule, so a member that silently stops being invoked
* (or is dropped from the list) fails here instead of quietly narrowing what
* the CLI checks. A suite that returns nothing is indistinguishable from a
* clean stack — which is exactly how the dead quick-actions check in #3684
* survived its own tests.
*/
const stack = {
objects: [
{
name: 'crm_lead',
fields: {
name: { type: 'text', label: 'Name' },
locked: { type: 'boolean', label: 'Locked', readonly: true },
},
// validateSearchableFields: `budget` is not a field on crm_lead, so the
// ADR-0061 declaration is stale — the engine drops it and searches a
// narrower set than the object declares.
searchableFields: ['name', 'budget'],
permissions: {},
},
],
actions: [
// validateObjectReferences: a param pointing at an object nothing declares.
{ name: 'assign', label: 'Assign', params: [{ name: 'owner', reference: 'user' }] },
// validateActionBodyWrites, both of its rule ids from one body:
// - the L2 body writes a field crm_lead does not declare — on SQL that
// fails the whole call at the driver, on a schemaless driver it
// persists a stray key (#4271);
// - and it assigns ctx.record, a snapshot the runtime never writes
// back, without ever passing it anywhere (#4345).
{
name: 'score_now',
label: 'Score Now',
objectName: 'crm_lead',
body: {
language: 'js',
source:
"ctx.record.name = 'scored'; await ctx.api.object('crm_lead').update({ lead_score: 100 });",
},
},
],
views: [
{
list: {
type: 'grid',
name: 'all_leads',
data: { provider: 'object', object: 'crm_lead' },
// validateActionNameRefs: no such action.
bulkActions: ['mass_update'],
},
},
],
pages: [
{
name: 'lead_detail',
object: 'crm_lead',
regions: [
{
components: [
// validatePageFieldBindings: `budget` is not a field on crm_lead.
{ type: 'record:highlights', properties: { fields: [{ name: 'budget' }] } },
],
},
],
},
// validateReactPageProps: the same component family one surface over,
// authored as JSX. `<ObjectForm>` with no `objectName` binds nothing, so
// this GATES — and it gated on `os validate` alone until this member
// joined the suite. A separate page from `lead_detail` on purpose: the
// metadata walk above must stay the only source of `page-field-unknown`
// here, or this member could go silent behind it.
{
name: 'lead_console',
kind: 'react',
source: 'function Page(){ return <ObjectForm mode="edit" />; }',
},
],
datasets: [
{
name: 'lead_metrics',
object: 'crm_lead',
dimensions: [{ name: 'source' }],
measures: [{ name: 'count_leads', aggregate: 'count' }],
},
],
reports: [
{
name: 'leads_by_source',
dataset: 'lead_metrics',
values: ['count_leads'],
// validateChartBindings: a raw field where a declared measure is required.
chart: { type: 'bar', xAxis: 'source', yAxis: 'lead_score' },
},
],
apps: [
{
name: 'crm_app',
navigation: [{ id: 'nav_leads', type: 'object', objectName: 'crm_lead' }],
},
],
// validateNavAccess: a declared permission set that grants nothing on the
// nav-exposed object.
permissions: [{ name: 'sales_user', label: 'Sales User', objects: {} }],
translations: [
// validateTranslationReferences: a field the object does not declare.
{ en: { objects: { crm_lead: { label: 'Lead', fields: { assigned_to: { label: 'Owner' } } } } } },
],
// validateAiSurfaceAffinity: an 'ask' agent binding a 'build' skill — the
// runtime throws on this at chat time (ADR-0064 §3).
// validateAiAgentAuthoring: declaring an agent at all is withdrawn
// (ADR-0063 §2) — one fixture, two rules.
agents: [{ name: 'helper', surface: 'ask', skills: ['metadata_authoring'] }],
// validateAiToolReferences: a tool name nothing declares, registers, or
// materialises (the HotCRM fictional-tool class).
skills: [{ name: 'metadata_authoring', surface: 'build', tools: ['forecast_revenue'] }],
hooks: [
// validateHookBodyWrites: the L2 body writes a field crm_lead does not
// declare — runs clean in the sandbox, then fails the whole write at a
// SQL driver / persists a stray key on a schemaless one (#4271).
{
name: 'score_lead',
object: 'crm_lead',
events: ['beforeInsert'],
body: { language: 'js', source: "ctx.input.lead_score = 100;" },
},
],
flows: [
{
name: 'lead_followup',
type: 'record_change',
// validateReadonlyFlowWrites: a runAs:'user' update_record writing a
// static-`readonly` field. The engine strips it and the step still
// reports success (#2948/#3425) — a certainty, so it GATES. Walks the
// same `config.fields` map validateFlowNodeWrites does, which is why
// the two must not diverge across commands again.
runAs: 'user',
nodes: [
{ id: 'start', type: 'start', config: { objectName: 'crm_lead', triggerType: 'record-created' } },
// validateFlowTemplatePaths: `budget` is not a field on crm_lead. In a
// FILTER position an erased condition widens the query rather than
// narrowing it, so the runtime refuses the node — gating, not advisory
// (#3810). This member is the suite's only source of `error` findings
// from a flow, so it also pins that both severities survive the suite.
{
id: 'fetch',
type: 'get_record',
config: { objectName: 'crm_lead', filter: { name: '{record.budget}' } },
},
// validateFlowNodeWrites: the node's structural write map names a
// field crm_lead does not declare — the third surface in the #4271
// family, and the only one whose finding is a certainty rather than
// an extraction (so it gates).
{
id: 'stamp',
type: 'update_record',
config: { objectName: 'crm_lead', fields: { lead_score: 100 } },
},
// validateReadonlyFlowWrites: the OTHER question about that same
// `config.fields` map — `locked` exists but is static-`readonly`, so
// under this flow's `runAs:'user'` the engine strips it and the step
// still reports success (#2948/#3425). A separate node from `stamp`
// on purpose: one node carrying both defects would let either rule
// go silent behind the other's finding.
{
id: 'lock',
type: 'update_record',
config: { objectName: 'crm_lead', fields: { locked: true } },
},
],
},
],
};
it('reports at least one finding from every member', () => {
const findings = validateReferenceIntegrity(stack);
const rules = new Set(findings.map((f) => f.rule));
expect(rules).toContain('object-reference-unknown');
expect(rules).toContain('searchable-field-unknown');
expect(rules).toContain('action-name-undefined');
expect(rules).toContain('page-field-unknown');
expect(rules).toContain('chart-measure-unknown');
expect(rules).toContain('nav-object-ungranted');
expect(rules).toContain('translation-target-unknown');
expect(rules).toContain('flow-template-unknown-field');
expect(rules).toContain('ai-skill-surface-mismatch');
expect(rules).toContain('ai-skill-tool-unresolved');
expect(rules).toContain('agent-authoring-withdrawn');
expect(rules).toContain('hook-body-write-unknown-field');
expect(rules).toContain('action-body-write-unknown-field');
// Members that emit a rule id beyond their resolution one — see the suite's
// comments on why these ride along instead of becoming their own entries.
expect(rules).toContain('action-record-write-discarded');
expect(rules).toContain('flow-node-write-unknown-field');
expect(rules).toContain('flow-update-readonly-field');
expect(rules).toContain('react-prop-missing-required');
});
it('carries a gating react-page-prop finding through the suite (#4340)', () => {
const findings = validateReferenceIntegrity(stack);
const react = findings.find((f) => f.rule === 'react-prop-missing-required');
// Must reach the CLI as an ERROR: `os lint` and `os compile` saw NOTHING
// from this rule until it joined the suite, so a react page binding nothing
// sailed through the build the way a readonly flow write did (#4394).
expect(react?.severity).toBe('error');
});
it('carries a gating flow-template finding through the suite (#3810)', () => {
const findings = validateReferenceIntegrity(stack);
const flow = findings.find((f) => f.rule === 'flow-template-unknown-field');
// A filter-position miss must reach the CLI as an ERROR, or `os lint` and
// `os compile` would print a yellow line and ship a flow that cannot run.
expect(flow?.severity).toBe('error');
});
it('concatenates in list order and carries the common finding shape', () => {
const findings = validateReferenceIntegrity(stack);
expect(findings.length).toBeGreaterThan(0);
for (const f of findings) {
expect(['error', 'warning']).toContain(f.severity);
expect(typeof f.rule).toBe('string');
expect(typeof f.where).toBe('string');
expect(typeof f.path).toBe('string');
expect(typeof f.message).toBe('string');
expect(typeof f.hint).toBe('string');
}
// Object references run first, react page props last.
expect(findings[0].rule).toBe('object-reference-unknown');
expect(findings[findings.length - 1].rule).toBe('react-prop-missing-required');
});
it('returns nothing for an empty stack', () => {
expect(validateReferenceIntegrity({})).toEqual([]);
});
});