Skip to content

Commit 5d34fa0

Browse files
committed
feat(cli)!: os build refuses a field the __c extension-field reservation refuses, as os validate does
compile.ts makes the call validate.ts makes (findExtensionFieldSuffixRefusals, over metadata-protocol's judgeExtensionFieldSuffix), beside the override gate and ahead of every artifact write, with validate's refusal text and exit 1 in both output modes. The parity ledger's VALIDATE_ONLY_GATES row moves to the shared set and the ledger is empty again. Claude-Session: https://claude.ai/code/session_01FEkQ5oPz5wWFMzWjTGyVUb Co-Authored-By: Claude <noreply@anthropic.com>
1 parent db357f6 commit 5d34fa0

3 files changed

Lines changed: 229 additions & 16 deletions

File tree

‎packages/cli/src/commands/compile.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ import { judgePicklistReferences, picklistRefusalHeading, printPicklistReference
7979
// [ADR-0146 D2, #28643] The override write gate — the walk `os validate` step
8080
// 3a-iii runs, over the publish door's own judge (`judgeOverrideWrite`).
8181
import { findOverrideDeclarationRefusals } from '../utils/override-declarations.js';
82+
// [ADR-0146 D10, #28727] The `__c` extension-field reservation — the walk
83+
// `os validate` step 3a-iv runs, over the save and install doors' own judge
84+
// (`judgeExtensionFieldSuffix`).
85+
import { findExtensionFieldSuffixRefusals } from '../utils/extension-field-suffix.js';
8286

8387
export default class Compile extends Command {
8488
static override description = 'Compile ObjectStack configuration to JSON artifact';
@@ -802,6 +806,37 @@ export default class Compile extends Command {
802806
this.exit(1);
803807
}
804808

809+
// 3b-iii-bis. [ADR-0146 D10, #28727] The `__c` extension-field
810+
// reservation, at build time — the SAME call `os validate` makes at
811+
// its step 3a-iv, over the walk `utils/extension-field-suffix.ts`
812+
// takes and the save and install doors' own judge
813+
// (`judgeExtensionFieldSuffix`): a field spelled `__c` only in a
814+
// base's paired `.custom` package, and every
815+
// `objectExtensions[].fields` key of a `.custom` pair suffixed. Before
816+
// this the build emitted such an artifact and the marketplace install
817+
// or a save or publish door refused it later with the same judge; now
818+
// the door that ships refuses it and writes no artifact.
819+
//
820+
// Beside the override gate above, ahead of every artifact write, with
821+
// the same two faces: this command's failure envelope under `--json`
822+
// (`errors`, the rows `os validate --json` carries), `os validate`'s
823+
// text otherwise.
824+
const suffixRefusals = findExtensionFieldSuffixRefusals(result.data as Record<string, unknown>);
825+
if (suffixRefusals.length > 0) {
826+
if (flags.json) {
827+
await emitJson({ success: false, errors: suffixRefusals, warnings: warningsSoFar(), conversions: conversionNotices }, 0, { compact: true });
828+
this.exit(1);
829+
}
830+
const n = suffixRefusals.length;
831+
console.log('');
832+
printError(`${n} field${n > 1 ? 's break' : ' breaks'} the \`__c\` extension-field reservation (ADR-0146 D10)`);
833+
printBulletList(
834+
suffixRefusals.map((r) => `${r.path} [${r.code}] ${r.message}`),
835+
{ noun: 'extension-field refusal(s)', remedy: JSON_FULL_LIST_REMEDY },
836+
);
837+
this.exit(1);
838+
}
839+
805840
// 3b-quater. ADR-0141 D2, author side — every `manifest.dependencies`
806841
// range of the packages one install act would deliver, judged by the
807842
// install's own predicate (`utils/dependency-range-check.ts`).
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [ADR-0146 D10, #28727] `os build` asks the `__c` extension-field
5+
* reservation that `os validate`, the save, restore and publish doors and the
6+
* marketplace install ask, and refuses the build with the rows `os validate`
7+
* prints: same rows, same exit code, and NOTHING written to `dist/`.
8+
*
9+
* ## The defect, measured before the fix
10+
*
11+
* On a plain package declaring a field `x__c` on its own object (case (a)),
12+
* and on a base's paired `.custom` extending a base object with a field
13+
* `region` that lacks the suffix (case (b)), `os build --json` exited 0 and
14+
* wrote `dist/objectstack.json`, while `os validate --json` exited 1 with one
15+
* `VALIDATION_ERROR` row each. The marketplace install and the save and
16+
* publish doors refused that artifact later with the same judge.
17+
*
18+
* ## One judge, one walk
19+
*
20+
* `compile.ts` makes the call `validate.ts` makes
21+
* (`findExtensionFieldSuffixRefusals`, over `judgeExtensionFieldSuffix`), so
22+
* the pins below assert EQUALITY with what `os validate` answers for the same
23+
* config, run in the same process, rather than a copy of the judge's words.
24+
* Which packages the walk judges is pinned by its own file
25+
* (`src/utils/extension-field-suffix.test.ts`). Both commands run in-process
26+
* (`Command.run`), not as spawned CLIs.
27+
*/
28+
29+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
30+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
31+
import { tmpdir } from 'node:os';
32+
import { join, resolve } from 'node:path';
33+
import { fileURLToPath } from 'node:url';
34+
import Compile from '../src/commands/compile';
35+
import Validate from '../src/commands/validate';
36+
import { defineStackSource, linkSpec } from './helpers/define-stack-fixture.js';
37+
38+
const CLI_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..');
39+
const BASE = 'com.acme.crm';
40+
41+
interface Run {
42+
/** The exit code `this.exit(n)` threw, or 0 when the command returned. */
43+
code: number;
44+
stdout: string;
45+
}
46+
47+
/** Runs one command in-process; stdout captured ANSI-free, the write callback honoured. */
48+
async function run(command: typeof Compile | typeof Validate, argv: string[]): Promise<Run> {
49+
const chunks: string[] = [];
50+
const spy = vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown, ...rest: unknown[]) => {
51+
chunks.push(String(chunk));
52+
const done = rest.find((a) => typeof a === 'function') as ((e?: Error | null) => void) | undefined;
53+
done?.(null);
54+
return true;
55+
}) as never);
56+
const exitCodeBefore = process.exitCode;
57+
let code = 0;
58+
try {
59+
await command.run(argv, { root: CLI_ROOT });
60+
} catch (error) {
61+
const exit = (error as { oclif?: { exit?: unknown } }).oclif?.exit;
62+
if (typeof exit !== 'number') throw error;
63+
code = exit;
64+
} finally {
65+
spy.mockRestore();
66+
process.exitCode = exitCodeBefore;
67+
}
68+
// eslint-disable-next-line no-control-regex
69+
return { code, stdout: chunks.join('').replace(/\u001b\[[0-9;]*m/g, '') };
70+
}
71+
72+
const json = (r: Run, label: string): Record<string, any> => {
73+
try {
74+
return JSON.parse(r.stdout) as Record<string, any>;
75+
} catch {
76+
throw new Error(`${label}: stdout was not one JSON document (exit ${r.code})\n${r.stdout}`);
77+
}
78+
};
79+
80+
/** Case (a): a plain package declaring `x__c` on its own object. */
81+
const plainOwnField = (): Record<string, unknown> => ({
82+
manifest: { id: 'com.acme.partner', name: 'partner', version: '1.0.0', type: 'app', namespace: 'partner' },
83+
objects: [
84+
{
85+
name: 'partner_ticket',
86+
label: 'Ticket',
87+
fields: { title: { type: 'text', label: 'Title' }, x__c: { type: 'text', label: 'X' } },
88+
},
89+
],
90+
});
91+
92+
/** The base's paired `.custom` extending the base's `crm_account` with one field named `field`. */
93+
const pairExtension = (field: string): Record<string, unknown> => ({
94+
manifest: {
95+
id: `${BASE}.custom`, name: 'ext', version: '1.0.0', type: 'app', namespace: 'crm_custom',
96+
dependencies: { [BASE]: '^1.0.0' },
97+
},
98+
objectExtensions: [{ extend: 'crm_account', fields: { [field]: { type: 'text', label: 'Region' } } }],
99+
});
100+
101+
let root = '';
102+
const fixtures: Record<string, { config: string; dist: string; artifact: string }> = {};
103+
104+
beforeAll(() => {
105+
root = mkdtempSync(join(tmpdir(), 'os-build-extension-field-suffix-'));
106+
const make = (label: string, s: Record<string, unknown>) => {
107+
const dir = join(root, label);
108+
mkdirSync(dir, { recursive: true });
109+
// `strict: false`: the content is the door's to judge, not the producer's.
110+
writeFileSync(join(dir, 'objectstack.config.ts'), defineStackSource(s, { strict: false }));
111+
linkSpec(dir);
112+
fixtures[label] = {
113+
config: join(dir, 'objectstack.config.ts'),
114+
dist: join(dir, 'dist'),
115+
artifact: join(dir, 'dist', 'objectstack.json'),
116+
};
117+
};
118+
make('plainOwnField', plainOwnField());
119+
make('pairPlain', pairExtension('region'));
120+
make('pairSuffixed', pairExtension('region__c'));
121+
});
122+
123+
afterAll(() => {
124+
if (root) rmSync(root, { recursive: true, force: true });
125+
});
126+
127+
const build = (label: string, ...flags: string[]) =>
128+
run(Compile, [fixtures[label].config, '--output', fixtures[label].artifact, ...flags]);
129+
const validate = (label: string, ...flags: string[]) => run(Validate, [fixtures[label].config, ...flags]);
130+
131+
describe('#28727 — os build refuses what os validate refuses under the `__c` reservation, and writes nothing', () => {
132+
it.each([
133+
['plainOwnField', 'reserved_outside_pair', 'objects'],
134+
['pairPlain', 'unsuffixed_in_pair', 'objectExtensions'],
135+
])('THE PIN (%s): --json exits as validate does, with validate\'s rows, and dist/ stays empty', async (label, rule, at) => {
136+
const validated = await validate(label, '--json');
137+
expect(validated.code, validated.stdout).toBe(1);
138+
const expected = json(validated, `validate ${label}`).errors as Array<Record<string, unknown>>;
139+
// Anti-vacuity: the judge refuses this config, under the case it names.
140+
expect(expected.map((e) => [e.code, e.rule])).toEqual([['VALIDATION_ERROR', rule]]);
141+
expect(String(expected[0]!.path).startsWith(at)).toBe(true);
142+
143+
const built = await build(label, '--json');
144+
const payload = json(built, `build ${label}`);
145+
expect(built.code).toBe(validated.code);
146+
expect(payload.success).toBe(false);
147+
expect(payload.errors).toEqual(expected);
148+
expect(existsSync(fixtures[label].dist), 'os build wrote into dist/ for an artifact the doors refuse').toBe(false);
149+
}, 60_000);
150+
151+
it('the text face exits 1 and prints the refusal block os validate prints', async () => {
152+
const validated = await validate('pairPlain');
153+
expect(validated.code).toBe(1);
154+
const block = validated.stdout.slice(validated.stdout.indexOf('✗ 1 field breaks the')).trimEnd();
155+
expect(block).toContain('objectExtensions[0].fields.region [VALIDATION_ERROR]');
156+
157+
const built = await build('pairPlain');
158+
expect(built.code).toBe(1);
159+
expect(built.stdout).toContain(block);
160+
expect(built.stdout).not.toContain('Build complete');
161+
expect(existsSync(fixtures.pairPlain.dist)).toBe(false);
162+
}, 60_000);
163+
164+
it('CONTROL: the base\'s paired .custom extending with `region__c` builds, and validates clean', async () => {
165+
expect((await validate('pairSuffixed', '--json')).code).toBe(0);
166+
const built = await build('pairSuffixed', '--json');
167+
const payload = json(built, 'build pairSuffixed');
168+
expect(payload.success, JSON.stringify(payload.errors ?? payload.error)).toBe(true);
169+
expect(built.code).toBe(0);
170+
const artifact = JSON.parse(readFileSync(fixtures.pairSuffixed.artifact, 'utf8')) as Record<string, any>;
171+
expect(Object.keys(artifact.objectExtensions[0].fields)).toEqual(['region__c']);
172+
}, 60_000);
173+
});

‎packages/cli/test/validate-build-gate-parity.test.ts‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ const SHARED_NON_REGISTRY_GATES: readonly string[] = [
197197
// here — deleted there rather than reworded, for the reason the
198198
// `runPerPackageAuthoringRules` row above gives.
199199
'findOverrideDeclarationRefusals',
200+
// [ADR-0146 D10, #28564, #28727] The `__c` extension-field reservation: a
201+
// field spelled `__c` only in a base's paired `.custom` package, and every
202+
// `objectExtensions[].fields` key of a `.custom` pair suffixed, judged by
203+
// the save and install doors' own `judgeExtensionFieldSuffix`. Not a
204+
// registry rule: the WALK decides which package each field is declared in —
205+
// each `packages[]` entry under its own id, or the stack under
206+
// `manifest.id` — and the verdict turns on that package's id, which the
207+
// union stack a registry rule is handed does not carry.
208+
//
209+
// ⭐ This row is the #28564 VALIDATE_ONLY_GATES entry CLOSED. That entry read
210+
// "os build is a further point it did not name", and it was right: the
211+
// build emitted an artifact the marketplace install and the save and
212+
// publish doors refused later. `compile.ts` now makes the same call
213+
// (#28727), so the row moved here — deleted there rather than reworded, for
214+
// the reason the `runPerPackageAuthoringRules` row above gives.
215+
'findExtensionFieldSuffixRefusals',
200216
];
201217

202218
/**
@@ -235,23 +251,12 @@ const BUILD_ONLY_GATES: Readonly<Record<string, string>> = {
235251
* SHARED_NON_REGISTRY_GATES instead.
236252
*
237253
* EMPTY is this ledger's steady state: every row is a gap the build carries.
238-
* Two rows it has held moved to SHARED_NON_REGISTRY_GATES when `compile.ts`
239-
* gained the call: `findViewContainerNameRefusals` (#20331 → #20393) and
240-
* `findOverrideDeclarationRefusals` (#28410 → #28643). It holds one today,
241-
* `findExtensionFieldSuffixRefusals` (#28564), whose card did not name the
242-
* build.
254+
* Three rows it has held moved to SHARED_NON_REGISTRY_GATES when `compile.ts`
255+
* gained the call: `findViewContainerNameRefusals` (#20331 → #20393),
256+
* `findOverrideDeclarationRefusals` (#28410 → #28643) and
257+
* `findExtensionFieldSuffixRefusals` (#28564 → #28727). It holds none today.
243258
*/
244-
const VALIDATE_ONLY_GATES: Readonly<Record<string, string>> = {
245-
// [#28564] A real gap in the build's direction, reported and not closed —
246-
// the shape `findOverrideDeclarationRefusals` held until #28643 closed it.
247-
// Card #28564 (ADR-0146 D10, decided item 7) named the `__c` reservation's
248-
// doors — the save, restore and publish doors, `os validate`, the install
249-
// doors and the duplicate — and `os build` is not one of them. The artifact
250-
// a build emits is still judged where it lands: the marketplace install and
251-
// the save and publish doors refuse the same fields with the same judge.
252-
findExtensionFieldSuffixRefusals:
253-
'card #28564 placed the __c reservation at the save/restore/publish doors, os validate, the install doors and duplicate; os build is a further point it did not name (as #28410 left the override gate until #28643). The install and publish doors refuse the same fields with the same judge.',
254-
};
259+
const VALIDATE_ONLY_GATES: Readonly<Record<string, string>> = {};
255260

256261
/**
257262
* Everything else the two commands call, and the reason each one is NOT an

0 commit comments

Comments
 (0)