Skip to content

Commit f127667

Browse files
committed
fix(objectql, lint): synced objects are told to drop write verbs, not to open userActions
On a managedBy 'synced' object the parse refuses a userActions entry that opens a write (ADR-0153 D4), yet the registry's stripped-apiMethods warning and the object/managed-api-method-unaffordable finding both prescribed exactly that. Both now branch on MANAGED_BY_WRITE_LOCKED_BUCKETS: on synced they name the verbs to remove from enable.apiMethods and point writes at a declared action (ADR-0153 D5). Every other bucket keeps today's sentence. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5p6qE7Nt8wpjSGLqiC
1 parent f068cde commit f127667

6 files changed

Lines changed: 110 additions & 11 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/objectql': patch
3+
'@objectstack/lint': patch
4+
---
5+
6+
fix(objectql, lint): on a `managedBy: 'synced'` object, the stripped-`apiMethods` warning and the `object/managed-api-method-unaffordable` finding no longer tell the author to open a verb through `userActions`, which the parse refuses there (ADR-0153 D4, #32134)
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
- `reconcileManagedApiMethods` (`@objectstack/objectql`): on a write-locked bucket (`MANAGED_BY_WRITE_LOCKED_BUCKETS`, today `synced` alone) the warning's remedy now reads "userActions cannot open a write on this bucket (ADR-0153 D4): remove [VERBS] from enable.apiMethods and send writes through a declared action (ADR-0153 D5)." Every other bucket keeps "Declare userActions to open a verb the object legitimately takes from a user context." The strip itself is unchanged.
12+
- `object/managed-api-method-unaffordable` (`@objectstack/lint`): on `synced` the verdict says `userActions` cannot open a write there instead of "(needs userActions …)", and the fix line offers only the removal and a declared action. `os explain object/managed-api-method-unaffordable` gains a paragraph saying so. Every other bucket's verdict and fix line are unchanged, and the rule id, severity, `path` and what the rule refuses are unchanged.

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5516,6 +5516,9 @@ const MANAGED_API_METHOD_UNAFFORDABLE_EXPLANATION: RuleExplanation = {
55165516
'one edit. The fix line offers both ways out: drop the verbs, or open the affordance, and only ' +
55175517
'for a write a user context may really perform, once the guard that enforces it exists ' +
55185518
'(ADR-0092 D4: an affordance never ships ahead of its guard).',
5519+
'On a `synced` object `userActions` cannot open a write at all (ADR-0153 D4: the parse refuses ' +
5520+
'it), so the fix line offers only the removal, and a write goes through a declared action ' +
5521+
'(ADR-0153 D5).',
55195522
],
55205523
};
55215524

‎packages/lint/src/validate-managed-api-methods.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ describe('[#22161] one-line verdicts — object/managed-api-method-unaffordable'
129129
expect(f.message).not.toContain('sys_environment');
130130
});
131131

132+
// [ADR-0153 D4/D5] `userActions` cannot open a write on `synced` (the parse
133+
// refuses it), so the verdict does not prescribe it; the platform-bucket
134+
// case above is the control that keeps today's sentence.
135+
it('on a synced object, the verdict says userActions cannot open a write, never "needs userActions"', () => {
136+
const [f] = validateManagedApiMethods({
137+
objects: [{ name: 'erp_order_copy', managedBy: 'synced', enable: { apiMethods: ['get', 'create', 'update'] } }],
138+
});
139+
expect(f.message).toBe(
140+
"`enable.apiMethods` advertises [create, update], which `managedBy: 'synced'` refuses, and "
141+
+ '`userActions` cannot open a write there, so the registry strips them',
142+
);
143+
});
144+
132145
it('`os explain` carries what the verdict no longer says', () => {
133146
const entry = explainRule(MANAGED_API_METHOD_UNAFFORDABLE);
134147
expect(entry, 'no `os explain object/managed-api-method-unaffordable` entry').toBeDefined();
@@ -141,6 +154,8 @@ describe('[#22161] one-line verdicts — object/managed-api-method-unaffordable'
141154
'One finding per object, not per verb',
142155
'ADR-0092 D4',
143156
'Reads are never affordance-gated',
157+
'ADR-0153 D4',
158+
'ADR-0153 D5',
144159
]) {
145160
expect(text, `explanation names ${fact}`).toContain(fact);
146161
}
@@ -194,6 +209,16 @@ describe('[#22161] one-line fix — object/managed-api-method-unaffordable', ()
194209
);
195210
});
196211

212+
it('on a synced object, the fix line offers only the removal and a declared action', () => {
213+
const [f] = validateManagedApiMethods({
214+
objects: [{ name: 'erp_order_copy', managedBy: 'synced', enable: { apiMethods: Object.keys(MANAGED_WRITE_VERB_AFFORDANCE) } }],
215+
});
216+
expect(f!.hint).toBe(
217+
'Remove [create, update, upsert, delete, purge] from `enable.apiMethods`, and send writes through a declared action',
218+
);
219+
expect(f!.hint).not.toContain('userActions');
220+
});
221+
197222
it('every `fix:` line the cases in this file fired is one line of at most 200 characters', () => {
198223
const converted = fired.filter((f) => f.rule === MANAGED_API_METHOD_UNAFFORDABLE);
199224
// Coverage control: one verb, several verbs and every verb fired.

‎packages/lint/src/validate-managed-api-methods.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// error would stop the parse, and the predicate reads only authored keys
3535
// (`managedBy`, `userActions`, `enable.apiMethods`) — no parse-time defaults.
3636

37-
import { checkManagedApiMethodAffordances } from '@objectstack/spec/data';
37+
import { checkManagedApiMethodAffordances, MANAGED_BY_WRITE_LOCKED_BUCKETS } from '@objectstack/spec/data';
3838

3939
/**
4040
* Stable diagnostic id. Named for the CONTRADICTION rather than for the strip,
@@ -96,6 +96,12 @@ export function validateManagedApiMethods(stack: unknown): ManagedApiMethodFindi
9696

9797
const verbs = conflicts.map((c) => c.verb).join(', ');
9898
const flags = [...new Set(conflicts.map((c) => c.needs))];
99+
const bucket = String(obj.def.managedBy);
100+
// [ADR-0153 D4] On a write-locked bucket (`synced`) `userActions` cannot
101+
// open a write — the parse refuses it — so the only way out is removal,
102+
// and writes go through a declared action (D5). Every other bucket keeps
103+
// both ways out.
104+
const writeLocked = MANAGED_BY_WRITE_LOCKED_BUCKETS.has(bucket);
99105
out.push({
100106
severity: 'error',
101107
rule: MANAGED_API_METHOD_UNAFFORDABLE,
@@ -106,12 +112,15 @@ export function validateManagedApiMethods(stack: unknown): ManagedApiMethodFindi
106112
// why this refuses, and that an affordance opens only for a write a user
107113
// context may really perform (ADR-0092 D4) are
108114
// `os explain object/managed-api-method-unaffordable`.
109-
message:
110-
`\`enable.apiMethods\` advertises [${verbs}], which \`managedBy: '${String(obj.def.managedBy)}'\` ` +
111-
`affordances refuse (needs userActions ${flags.join('/')}), so the registry strips them`,
112-
hint:
113-
`Remove [${verbs}] from \`enable.apiMethods\`, or add ` +
114-
`\`userActions: { ${flags.map((f) => `${f}: true`).join(', ')} }\` once a guard enforces the write`,
115+
message: writeLocked
116+
? `\`enable.apiMethods\` advertises [${verbs}], which \`managedBy: '${bucket}'\` refuses, and ` +
117+
`\`userActions\` cannot open a write there, so the registry strips them`
118+
: `\`enable.apiMethods\` advertises [${verbs}], which \`managedBy: '${bucket}'\` ` +
119+
`affordances refuse (needs userActions ${flags.join('/')}), so the registry strips them`,
120+
hint: writeLocked
121+
? `Remove [${verbs}] from \`enable.apiMethods\`, and send writes through a declared action`
122+
: `Remove [${verbs}] from \`enable.apiMethods\`, or add ` +
123+
`\`userActions: { ${flags.map((f) => `${f}: true`).join(', ')} }\` once a guard enforces the write`,
115124
});
116125
}
117126

‎packages/objectql/src/registry.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,49 @@ describe('reconcileManagedApiMethods', () => {
11621162
}
11631163
});
11641164

1165+
// [ADR-0153 D4/D5] The remedy branches on the bucket: `userActions` cannot
1166+
// open a write on `synced` (the parse refuses it), so the warning names the
1167+
// verbs to drop and points writes at a declared action instead.
1168+
it('on a synced object, the warning names the verbs to drop and a declared action, never userActions', () => {
1169+
const warn = vi.fn<(msg: string) => void>();
1170+
reconcileManagedApiMethods(
1171+
{
1172+
name: 'erp_order_copy',
1173+
managedBy: 'synced',
1174+
enable: { apiEnabled: true, apiMethods: ['get', 'list', 'create', 'update'] },
1175+
} as ServiceObject,
1176+
{ warn },
1177+
);
1178+
expect(warn).toHaveBeenCalledTimes(1);
1179+
expect(warn.mock.calls[0][0]).toBe(
1180+
`[Registry] Object "erp_order_copy" is managedBy:'synced' but advertised generic write verb(s) ` +
1181+
`[create, update] in enable.apiMethods its resolved affordances do not permit — stripping them ` +
1182+
`(ADR-0092/ADR-0103). userActions cannot open a write on this bucket (ADR-0153 D4): remove ` +
1183+
`[create, update] from enable.apiMethods and send writes through a declared action (ADR-0153 D5). ` +
1184+
`Kept: [get, list]. \`os lint\` reports the same contradiction as ` +
1185+
`\`object/managed-api-method-unaffordable\` with full authoring context.`,
1186+
);
1187+
});
1188+
1189+
it('control: every other bucket keeps the userActions sentence unchanged', () => {
1190+
const warn = vi.fn<(msg: string) => void>();
1191+
reconcileManagedApiMethods(
1192+
{
1193+
name: 'sys_automation_run',
1194+
managedBy: 'engine-owned',
1195+
enable: { apiEnabled: true, apiMethods: ['get', 'list', 'create', 'update'] },
1196+
} as ServiceObject,
1197+
{ warn },
1198+
);
1199+
expect(warn.mock.calls[0][0]).toBe(
1200+
`[Registry] Object "sys_automation_run" is managedBy:'engine-owned' but advertised generic write verb(s) ` +
1201+
`[create, update] in enable.apiMethods its resolved affordances do not permit — stripping them ` +
1202+
`(ADR-0092/ADR-0103). Declare userActions to open a verb the object legitimately takes from a ` +
1203+
`user context. Kept: [get, list]. \`os lint\` reports the same contradiction as ` +
1204+
`\`object/managed-api-method-unaffordable\` with full authoring context.`,
1205+
);
1206+
});
1207+
11651208
it('twin: a synced object advertising reads only is left as it is', () => {
11661209
const warn = vi.fn();
11671210
const readOnly: any = {

‎packages/objectql/src/registry.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

3-
import { ServiceObject, ObjectSchema, ObjectOwnership, provisionPrimary, resolveInjectedSystemColumns, resolveInjectedColumnProvenance as injectedColumnProvenance, isInjectedColumnDefinition, isTenancyDisabled, checkManagedApiMethodAffordances, LEGACY_API_METHODS, AUDIT_PROVENANCE_FIELDS, materializeTreeSelfReferences, BASE_FIELD_DISPLAY_WHITELIST, type ObjectExtensionParsed } from '@objectstack/spec/data';
3+
import { ServiceObject, ObjectSchema, ObjectOwnership, provisionPrimary, resolveInjectedSystemColumns, resolveInjectedColumnProvenance as injectedColumnProvenance, isInjectedColumnDefinition, isTenancyDisabled, checkManagedApiMethodAffordances, MANAGED_BY_WRITE_LOCKED_BUCKETS, LEGACY_API_METHODS, AUDIT_PROVENANCE_FIELDS, materializeTreeSelfReferences, BASE_FIELD_DISPLAY_WHITELIST, type ObjectExtensionParsed } from '@objectstack/spec/data';
44
// [#4513] The audit-family governance table, and [#6562] the injected-column
55
// DEFINITION tables it governs — see the re-exports below for why both live in a
66
// package `objectql` and `metadata-protocol` both depend on.
@@ -2011,12 +2011,19 @@ export function reconcileManagedApiMethods(
20112011
const kept = methods.filter((_m, i) => !strippedIndexes.has(i));
20122012
const stripped = conflicts.map((c) => c.verb);
20132013

2014+
const managedBy = (schema as any).managedBy;
2015+
// [ADR-0153 D4] On a write-locked bucket (`synced`) `userActions` cannot open
2016+
// a write — the parse refuses it — so the remedy is to drop the verbs and
2017+
// write through a declared action (D5). Every other bucket keeps its sentence.
2018+
const remedy = MANAGED_BY_WRITE_LOCKED_BUCKETS.has(managedBy)
2019+
? `userActions cannot open a write on this bucket (ADR-0153 D4): remove [${stripped.join(', ')}] ` +
2020+
`from enable.apiMethods and send writes through a declared action (ADR-0153 D5).`
2021+
: `Declare userActions to open a verb the object legitimately takes from a user context.`;
20142022
const warn = opts?.warn ?? ((msg: string) => console.warn(msg));
20152023
warn(
2016-
`[Registry] Object "${schema.name}" is managedBy:'${(schema as any).managedBy}' but advertised ` +
2024+
`[Registry] Object "${schema.name}" is managedBy:'${managedBy}' but advertised ` +
20172025
`generic write verb(s) [${stripped.join(', ')}] in enable.apiMethods its resolved affordances ` +
2018-
`do not permit — stripping them (ADR-0092/ADR-0103). Declare userActions to open a verb the ` +
2019-
`object legitimately takes from a user context. Kept: [${kept.join(', ')}]. ` +
2026+
`do not permit — stripping them (ADR-0092/ADR-0103). ${remedy} Kept: [${kept.join(', ')}]. ` +
20202027
`\`os lint\` reports the same contradiction as \`object/managed-api-method-unaffordable\` ` +
20212028
`with full authoring context.`,
20222029
);

0 commit comments

Comments
 (0)