Repository navigation
Expand file tree
/
Copy pathauthoring-rule-command-parity.test.ts
More file actions
277 lines (265 loc) · 13.2 KB
/
Copy pathauthoring-rule-command-parity.test.ts
File metadata and controls
277 lines (265 loc) · 13.2 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
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
// test-budget: 20 — spawns the real producer once per single-cause fixture: three spawns of the source CLI (os lint, os validate, os build) over one planted-defect stack, every one a distinct triple whose exit code is the contract; the nine rule cases run in process; slowest CI reading 12.5 s (run 41271604267) of the five scheduled CI runs 41199450735, 41217827347, 41237094739, 41255489006, 41271604267, x 1.25, rounded up
/**
* The BEHAVIOURAL half of #4409, next to the structural ratchet in
* `src/commands/authoring-rule-wiring.test.ts`.
*
* The ratchet proves the three authoring commands are WIRED to the same rule
* table. This file proves the wiring produces the same VERDICT: one stack, one
* planted defect, three commands, three rejections. Wiring and verdict are
* genuinely different claims — a command can run a rule and still not gate on
* what it says, which is how #3782's four lints were "wired" into `os build`
* while `os validate` ran and then ignored the same class of finding.
*
* Every case below is a rule the issue MEASURED as running on a strict subset
* of the three, with the command it was blind to named. Each one could emit
* `error`, so each was a gate whose verdict depended on which command CI
* happened to run — nine coin flips. The end-to-end case at the bottom is the
* issue's own repro, run through the real CLI rather than the registry:
*
* os lint EXIT=1 ✗ approval-expression-invalid
* os validate EXIT=0
* os build EXIT=0 ← the artifact shipped anyway
*/
import { describe, expect, it } from 'vitest';
import { execFileSync } from 'node:child_process';
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { AUTHORING_COMMANDS, runAuthoringRules, type AuthoringCommand } from '@objectstack/lint';
import { childEnv } from './helpers/serve-process.js';
import { defineStackSource, linkSpec } from './helpers/define-stack-fixture.js';
const cliBin = join(fileURLToPath(new URL('.', import.meta.url)), '..', 'bin', 'run-dev.js');
/** A stack that satisfies the security linter, so only the planted defect gates. */
const withBaseline = (stack: Record<string, unknown>) => ({
manifest: { id: 'com.example.parity', namespace: 'parity', version: '1.0.0', name: 'Parity', type: 'app', engines: { protocol: '^18' } },
...stack,
});
const listView = (object: string) => ({ type: 'grid', label: 'All', columns: ['title'], data: { provider: 'object', object } });
const formView = (object: string) => ({ type: 'simple', data: { provider: 'object', object }, sections: [] });
/**
* One case per rule #4409 measured as partially covered, each planting the
* defect that rule exists to catch. `blindTo` records which command let it
* through before the registry — it is documentation, not an assertion, so the
* table still reads as the issue's matrix once every hole is closed.
*/
const CASES: ReadonlyArray<{ rule: string; blindTo: readonly AuthoringCommand[]; stack: Record<string, unknown> }> = [
// ── P1: gates `os build` did not run, so it PUBLISHED what the others refuse ──
{
rule: 'approval-expression-invalid',
blindTo: ['validate', 'build'],
stack: withBaseline({
objects: [{ name: 'parity_task', label: 'Task', sharingModel: 'private', fields: { name: { type: 'text', label: 'Name' } } }],
flows: [{
name: 'parity_flow', label: 'Parity', type: 'record_change', runAs: 'system', status: 'active',
nodes: [
// #6637 — was `triggerType: 'onCreate'`, which on a `type: 'record_change'`
// flow the engine routes to no trigger at all. This case's planted defect
// is the approver expression; the trigger token was incidental, and leaving
// a second (now gating) defect in the fixture would let the case pass on a
// finding it is not about.
{ id: 'start', type: 'start', label: 'Start', config: { objectName: 'parity_task', triggerType: 'record-after-create' } },
{ id: 'appr', type: 'approval', label: 'Approve', config: { approvers: [{ type: 'expression', value: 'record.owner ==' }] } },
{ id: 'end', type: 'end', label: 'End' },
],
edges: [
{ id: 'e1', source: 'start', target: 'appr', type: 'default' },
{ id: 'e2', source: 'appr', target: 'end', type: 'default' },
],
}],
}),
},
{
rule: 'list-view-filters-in-views-mode',
blindTo: ['build', 'lint'],
stack: withBaseline({
objects: [{ name: 'parity_task', label: 'Task', sharingModel: 'private', listViews: { tabular: { label: 'Tabular', userFilters: { element: 'tabs' } } }, fields: { name: { type: 'text', label: 'Name' } } }],
}),
},
{
rule: 'view-container-shape',
blindTo: ['build', 'lint'],
stack: withBaseline({
views: [{ name: 'all_tasks', label: 'All Tasks', type: 'grid', data: { provider: 'object', object: 'parity_task' }, columns: ['title'] }],
}),
},
// ── P2: gates `os lint` did not run, so the cheap pre-flight lied ──
{
rule: 'expression-invalid',
blindTo: ['lint'],
stack: withBaseline({
// The planted defect is the BARE `lead_score` (a record-scoped predicate
// binds fields under `record`, so this silently evaluates to null) — not
// the key it is written under. Spelled `condition`, which is the only key
// `validation.zod.ts` declares: `expression` is one of the four names it
// rejects outright, so a fixture using it planted TWO defects and let the
// rule under test read a stack `os validate` would never accept (#5017).
objects: [{ name: 'parity_lead', label: 'Lead', sharingModel: 'private', fields: { lead_score: { type: 'number', label: 'Score' } }, validations: [{ type: 'script', name: 'r', message: 'Score out of range', condition: 'lead_score > 100' }] }],
}),
},
{
rule: 'filter-token-unknown',
blindTo: ['lint'],
stack: withBaseline({
dashboards: [{ name: 'exec', label: 'Exec', widgets: [{ id: 'mine', type: 'metric', dataset: 'case_metrics', filter: { owner: '{current_user}', status: 'open' } }] }],
}),
},
{
rule: 'dashboard-action-target-undefined',
blindTo: ['lint'],
stack: withBaseline({
dashboards: [{ name: 'exec', label: 'Exec', header: { actions: [{ label: 'Export PDF', actionType: 'script', actionUrl: 'export_dashboard_pdf' }] }, widgets: [] }],
}),
},
{
rule: 'style-node-missing-id',
blindTo: ['lint'],
stack: withBaseline({
pages: [{ name: 'pricing', regions: [{ name: 'main', components: [{ type: 'flex', responsiveStyles: { large: { padding: 'var(--space-4)' } } }] }] }],
}),
},
{
rule: 'autonumber-references-unknown-field',
blindTo: ['lint'],
stack: withBaseline({
objects: [{ name: 'parity_task', label: 'Task', sharingModel: 'private', fields: { task_no: { type: 'autonumber', label: 'No', autonumberFormat: '{plan_no}{000}' } } }],
}),
},
{
rule: 'view-ref-form-target-kind',
blindTo: ['lint'],
stack: withBaseline({
views: [{ name: 'parity_task', list: listView('parity_task'), formViews: { default: formView('parity_task') } }],
actions: [{ name: 'log_time', type: 'form', target: 'parity_task.default' }],
}),
},
];
/**
* Checks `os validate` and `os build` gate on OUTSIDE the rule table, so
* `os lint`, which runs only the table, is blind to them. `blindTo` is the same
* documentation as above; the pin below asserts the blindness, so closing it
* (registering the check as an authoring rule) reds here and the case moves
* into `CASES`.
*
* - flow region shape (#28893): a `try_catch` region that is not single-exit.
* validate and build refuse it with the automation engine's own registration
* verdict (`utils/flow-region-shape.ts`, pinned by
* `validate-flow-region-shape.test.ts`); `os lint` passes it.
*/
const OUTSIDE_THE_TABLE: ReadonlyArray<{ check: string; marker: string; blindTo: readonly AuthoringCommand[]; stack: Record<string, unknown> }> = [
{
check: 'flow region shape (#28893)',
marker: 'single-exit',
blindTo: ['lint'],
stack: withBaseline({
objects: [{ name: 'parity_task', label: 'Task', sharingModel: 'private', fields: { name: { type: 'text', label: 'Name' } } }],
flows: [{
name: 'parity_region', label: 'Region', type: 'record_change', runAs: 'system', status: 'active',
nodes: [
{ id: 'start', type: 'start', label: 'Start', config: { objectName: 'parity_task', triggerType: 'record-after-create' } },
{
id: 'guard', type: 'try_catch', label: 'Guard',
config: {
try: { nodes: [{ id: 'work', type: 'assignment', label: 'Work' }], edges: [] },
catch: {
nodes: ['d', 'x', 'y'].map((id) => ({ id, type: 'assignment', label: id })),
edges: [
{ id: 'dx', source: 'd', target: 'x', type: 'default' },
{ id: 'dy', source: 'd', target: 'y', type: 'default' },
],
},
},
},
{ id: 'end', type: 'end', label: 'End' },
],
edges: [
{ id: 'e1', source: 'start', target: 'guard', type: 'default' },
{ id: 'e2', source: 'guard', target: 'end', type: 'default' },
],
}],
}),
},
];
describe('every authoring command reaches the same verdict (#4409)', () => {
it.each(CASES.map((c) => [c.rule, c] as const))('%s gates on all three commands', (_rule, testCase) => {
for (const command of AUTHORING_COMMANDS) {
// `os lint` never Zod-parses, so it hands the normalized stack to both
// tiers — modelled here exactly as the command does it.
const findings = runAuthoringRules(command, {
normalized: testCase.stack,
...(command === 'lint' ? {} : { parsed: testCase.stack }),
});
const gating = findings.filter((f) => f.severity === 'error').map((f) => f.rule);
expect(
gating,
`os ${command} does not gate on ${testCase.rule} — it did not before #4409 either ` +
`(blind: ${testCase.blindTo.join(', ')}), which is the drift this registry exists to end.`,
).toContain(testCase.rule);
}
});
it.each(OUTSIDE_THE_TABLE.map((c) => [c.check, c] as const))('%s: a known gap, os lint is still blind to it', (_check, testCase) => {
for (const command of testCase.blindTo) {
const findings = runAuthoringRules(command, {
normalized: testCase.stack,
...(command === 'lint' ? {} : { parsed: testCase.stack }),
});
expect(findings.filter((f) => f.message.includes(testCase.marker))).toEqual([]);
}
});
it('the case table still covers every command as a blind spot', () => {
// Guard the guard: if the table drifted to cover only one direction, the
// suite above would keep passing while testing half the problem. The issue
// found holes in BOTH — `os build` publishing what `os lint` refuses, and
// `os lint` passing what `os build` rejects.
const blind = new Set(CASES.flatMap((c) => c.blindTo));
expect([...blind].sort()).toEqual(['build', 'lint', 'validate']);
});
/**
* The issue's own repro, end to end through the real CLI: a flow whose
* expression approver does not parse used to exit 1 on `os lint` and 0 on
* both `os validate` and `os build` — so the build emitted an artifact for a
* flow the runtime refuses to run.
*
* Spawned rather than run in-process: the exit CODE is the contract CI reads,
* and only a real process produces it.
*/
it('the broken approval flow now exits non-zero on all three commands', () => {
const dir = mkdtempSync(join(tmpdir(), 'os-authoring-parity-'));
try {
// A `defineStack` config (#20367 ruling B: the doors refuse any other
// shape), `strict: false` so the rule under test is judged by each
// command rather than by the producer at load; spec is linked in.
writeFileSync(
join(dir, 'objectstack.config.mjs'),
defineStackSource(CASES[0].stack, { strict: false }),
);
linkSpec(dir);
for (const command of ['lint', 'validate', 'build']) {
let exitCode = 0;
let output = '';
try {
output = execFileSync(process.execPath, [cliBin, command], {
cwd: dir,
encoding: 'utf8',
stdio: 'pipe',
// Every spawned child under this directory declares its environment at the
// call site (#11595). An omitted `env` is the leak in its purest form: the
// child gets the vitest worker's environment verbatim, with nothing on the
// page to read.
env: childEnv(),
});
} catch (error: any) {
exitCode = error.status ?? 1;
output = `${error.stdout ?? ''}${error.stderr ?? ''}`;
}
expect(exitCode, `os ${command} exited 0 on a flow whose approver expression does not parse`).toBe(1);
expect(output, `os ${command} rejected the stack without naming the rule`).toContain(
'approval-expression-invalid',
);
}
} finally {
rmSync(dir, { recursive: true, force: true });
}
}, 120_000);
});