Skip to content

Commit a9a90f3

Browse files
committed
Merge remote-tracking branch 'origin/claude/o5-data-approvals-trunk' into claude/project-thread-wug0sh
2 parents a3b666c + d313098 commit a9a90f3

6 files changed

Lines changed: 150 additions & 5 deletions

File tree

‎.changeset/37766-opening-lead.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/plugin-approvals': patch
3+
---
4+
5+
fix(approvals): the opening refusal no longer says the object closes on its approval field when its only gaps are the host's or an unreadable flow
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
Widened: the plugin's message catalog gains the sentence `approvalOpeningRefusedClosedStatesLead` in all 11 locale packs.
11+
12+
An approval's first request is refused when an object it can act on declares `closedStates` and the host runs no job service, or when a flow it runs cannot be read. Those gaps are raised whatever field the object closes on. The refusal's lead used to say "the object closes on its approval field" in every case, which is false for an object that closes on another field. Where every gap is one of those two, the lead now says only what is true: the approval can act on an object that declares `closedStates`. The sentences per gap are unchanged.

‎packages/plugins/plugin-approvals/src/approval-opening-check-37766.integration.test.ts‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('[ADR-0162 item 7] the check when an approval opens', () => {
9292
try { await kernel?.shutdown(); } catch { /* noop */ }
9393
});
9494

95-
async function boot(opts: { sweeps?: boolean; invoiceDef?: Record<string, unknown> } = {}) {
95+
async function boot(opts: { sweeps?: boolean; invoiceDef?: Record<string, unknown>; warns?: string[] } = {}) {
9696
kernel = new ObjectKernel({ logger: { level: 'silent' } } as any);
9797
await kernel.use(new ObjectQLPlugin());
9898
await kernel.use(new AutomationServicePlugin());
@@ -118,7 +118,9 @@ describe('[ADR-0162 item 7] the check when an approval opens', () => {
118118
await ql.insert('sys_member', { id: `mem_${id}`, user_id: id, organization_id: ORG, role: 'member' }, { context: SYS });
119119
}
120120
const quiet = { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} };
121-
svc = new ApprovalService({ engine: ql, logger: quiet as any });
121+
const sink = opts.warns;
122+
const serviceLogger = sink ? { ...quiet, warn: (message: string) => { sink.push(message); } } : quiet;
123+
svc = new ApprovalService({ engine: ql, logger: serviceLogger as any });
122124
if (opts.sweeps !== false) svc.noteSweepClockScheduled();
123125
svc.attachAutomation(automation as any);
124126
registerApprovalNode(automation as any, svc, quiet as any);
@@ -229,4 +231,30 @@ describe('[ADR-0162 item 7] the check when an approval opens', () => {
229231
await seed('crm_memo', 'm_host');
230232
expect((await start('two_step', 'crm_memo', 'm_host')).status).toBe('paused');
231233
});
234+
235+
describe('the log line at a refusal says the object closes on its approval field only where a gap is about it', () => {
236+
const FIELD_CLAIM = 'closes on its approval field';
237+
const refusalWarns = (warns: string[]) => warns.filter((w) => w.includes('was refused at its first request'));
238+
239+
it('does not say it where the host\'s gap is the only one', async () => {
240+
const warns: string[] = [];
241+
await boot({ sweeps: false, warns });
242+
await seed('crm_invoice', 'i_host_log');
243+
expect((await start('two_step', 'crm_invoice', 'i_host_log')).status).toBe('failed');
244+
const logged = refusalWarns(warns);
245+
expect(logged).toHaveLength(1);
246+
expect(logged[0]).not.toContain(FIELD_CLAIM);
247+
expect(logged[0]).toContain('declares closedStates');
248+
});
249+
250+
it('says it where a gap is about the field (control)', async () => {
251+
const warns: string[] = [];
252+
await boot({ warns });
253+
await seed('crm_invoice', 'i_wait_log');
254+
expect((await start('wait_between', 'crm_invoice', 'i_wait_log')).status).toBe('failed');
255+
const logged = refusalWarns(warns);
256+
expect(logged).toHaveLength(1);
257+
expect(logged[0]).toContain(FIELD_CLAIM);
258+
});
259+
});
232260
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [ADR-0162 Execution item 7] The lead of the refusal at an approval's first
5+
* request says the object closes on its approval field only where a gap is
6+
* about that field. The host's gap (`no_job_service`) and a flow that could
7+
* not be read (`unreadable_flow`) are raised on an object that declares
8+
* `closedStates` on any field, so where they are the only gaps the lead says
9+
* what is true in every case: the approval can act on an object that declares
10+
* `closedStates`.
11+
*
12+
* The expected sentences are read from the catalog, not written out here: what
13+
* these tests hold is WHICH lead is chosen, and in which pack; the wording is
14+
* the catalog's, and `approval-notification-keyed-text.integration.test.ts` holds every locale
15+
* to the same ids and holes.
16+
*/
17+
18+
import { describe, expect, it } from 'vitest';
19+
import { interpolate } from './approval-notification-text.js';
20+
import type { OpeningGap } from './approval-opening-check.js';
21+
import { openingRefusalText } from './approval-opening-refusal.js';
22+
import { approvalMessages } from './translations/messages.js';
23+
24+
const subject = { object: 'crm_deal', record: 'd1' };
25+
type Locale = keyof typeof approvalMessages;
26+
const fieldLead = (locale: Locale) => interpolate(approvalMessages[locale].approvalOpeningRefusedLead, subject);
27+
const neutralLead = (locale: Locale) => interpolate(approvalMessages[locale].approvalOpeningRefusedClosedStatesLead, subject);
28+
const sentence = (gap: OpeningGap, id: 'approvalOpeningNoJobService' | 'approvalOpeningUnreadableFlow') => {
29+
const { kind: _kind, ...params } = gap;
30+
return interpolate(approvalMessages.en[id], params as Record<string, string>);
31+
};
32+
33+
const host: OpeningGap = { kind: 'no_job_service', object: 'crm_deal' };
34+
const unreadable: OpeningGap = { kind: 'unreadable_flow', flow: 'deal_sub' };
35+
const pause: OpeningGap = { kind: 'pause_between_steps', flow: 'deal_flow', node: 'hold', type: 'wait', object: 'crm_deal' };
36+
37+
describe('the opening refusal: its lead', () => {
38+
it('the two leads are two sentences, in every pack', () => {
39+
for (const locale of Object.keys(approvalMessages) as Locale[]) {
40+
expect(neutralLead(locale), locale).not.toBe(fieldLead(locale));
41+
}
42+
});
43+
44+
it('does not say the object closes on its approval field where the host\'s gap is the only one', () => {
45+
const text = openingRefusalText([host], subject, 'en');
46+
expect(text).toBe(`${neutralLead('en')} ${sentence(host, 'approvalOpeningNoJobService')}`);
47+
});
48+
49+
it('does not say it where a flow that could not be read is the only gap', () => {
50+
const text = openingRefusalText([unreadable], subject, 'en');
51+
expect(text).toBe(`${neutralLead('en')} ${sentence(unreadable, 'approvalOpeningUnreadableFlow')}`);
52+
});
53+
54+
it('does not say it where the host\'s gap and an unreadable flow are the only gaps', () => {
55+
const text = openingRefusalText([unreadable, host], subject, 'en');
56+
expect(text.startsWith(`${neutralLead('en')} `)).toBe(true);
57+
expect(text).not.toContain(fieldLead('en'));
58+
});
59+
60+
it('says it where a gap is about the field, alone or beside the host\'s', () => {
61+
expect(openingRefusalText([pause], subject, 'en').startsWith(`${fieldLead('en')} `)).toBe(true);
62+
expect(openingRefusalText([pause, host], subject, 'en').startsWith(`${fieldLead('en')} `)).toBe(true);
63+
expect(openingRefusalText([host, pause], subject, 'en').startsWith(`${fieldLead('en')} `)).toBe(true);
64+
});
65+
66+
it('words the lead that says nothing about the field in the run\'s locale', () => {
67+
const text = openingRefusalText([host], subject, 'zh-CN');
68+
expect(text.startsWith(`${neutralLead('zh-CN')} `)).toBe(true);
69+
expect(text).not.toContain(fieldLead('zh-CN'));
70+
expect(neutralLead('zh-CN')).not.toBe(neutralLead('en'));
71+
});
72+
});

‎packages/plugins/plugin-approvals/src/approval-opening-refusal.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,34 @@ export function openingRefusalPack(locale: string | undefined): Pack {
4444
return same ? packs[same]! : approvalMessages.en;
4545
}
4646

47+
/**
48+
* The gaps that say nothing about the approval field: the host's, and a flow
49+
* that could not be read. Where every gap is one of these, the lead does not
50+
* say the object closes on its approval field, which may be false: an object
51+
* can declare `closedStates` on another field.
52+
*/
53+
const NOT_ABOUT_THE_FIELD: ReadonlySet<OpeningGap['kind']> = new Set(['no_job_service', 'unreadable_flow']);
54+
55+
/**
56+
* Whether any of `gaps` is about the approval field, so that "the object
57+
* closes on its approval field" is true of the refusal. The one rule for every
58+
* text that says so: the refusal's lead here, and the service's log line.
59+
*/
60+
export function gapsAreAboutTheField(gaps: readonly OpeningGap[]): boolean {
61+
return gaps.some((gap) => !NOT_ABOUT_THE_FIELD.has(gap.kind));
62+
}
63+
4764
/** The refusal text for `gaps`, on the record `subject`, in `locale`. */
4865
export function openingRefusalText(
4966
gaps: readonly OpeningGap[],
5067
subject: { object: string; record: string },
5168
locale?: string,
5269
): string {
5370
const pack = openingRefusalPack(locale);
54-
const lead = interpolate(pack.approvalOpeningRefusedLead, { object: subject.object, record: subject.record });
71+
const lead = interpolate(
72+
gapsAreAboutTheField(gaps) ? pack.approvalOpeningRefusedLead : pack.approvalOpeningRefusedClosedStatesLead,
73+
{ object: subject.object, record: subject.record },
74+
);
5575
const sentences = gaps.map((gap) => {
5676
const { kind, ...params } = gap;
5777
return interpolate(pack[GAP_SENTENCE[kind]], params as Record<string, string>);

‎packages/plugins/plugin-approvals/src/approval-service.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ import { consolePageLink, type ConsolePageComposer } from './public-base-url.js'
180180
import { APPROVAL_EMAIL_CHANNELS, EMAILED_APPROVAL_TOPICS } from './approval-email-templates.js';
181181
import { enMessages } from './translations/messages.js';
182182
import { closedValuesOf, judgeApprovalOpening, type OpeningFlow } from './approval-opening-check.js';
183-
import { openingRefusalText } from './approval-opening-refusal.js';
183+
import { gapsAreAboutTheField, openingRefusalText } from './approval-opening-refusal.js';
184184
import {
185185
approvalMessageKey,
186186
approvalNotificationText,
@@ -5873,7 +5873,9 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
58735873
});
58745874
if (judgement.gaps.length > 0) {
58755875
const locale = input.locale ?? (context as { locale?: string } | undefined)?.locale;
5876-
this.logger?.warn?.('[approvals] an approval was refused at its first request: the record\'s object closes on its approval field and the approval cannot show it in progress (ADR-0162 D5)', {
5876+
this.logger?.warn?.(gapsAreAboutTheField(judgement.gaps)
5877+
? '[approvals] an approval was refused at its first request: the record\'s object closes on its approval field and the approval cannot show it in progress (ADR-0162 D5)'
5878+
: '[approvals] an approval was refused at its first request: it can act on an object that declares closedStates, and this host runs no job service or a flow it runs could not be read (ADR-0162 D5)', {
58775879
object: input.object, record: input.recordId, run: input.runId, rootRun: rootRun.runId,
58785880
gaps: judgement.gaps.map((g) => g.kind),
58795881
});

0 commit comments

Comments
 (0)