Skip to content

Commit e6fa510

Browse files
feat(approvals): an escalation deadline can count working time on an org calendar (clock: working_time) (#35929)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D62xGLMbyWJaMEVnAMEjTK1)_ Fixes #35357 Clause-②: yes (widening) Metadata-protocol: added Skills-docs: follow-up #35931 — skills/objectstack-automation/references/state-machines-and-approvals.md (the escalation row), domain:skills sub-card, Blocked-by this PR ## 维护者速读 - 用户能看到什么变化:审批节点的超时升级可以选择「按工作时间计算」,按组织的工作日历跳过夜间、周末和节假日,并计入调休补班日;日历算不出时,审批收件箱在到期时间处显示「日历算不出」和原因。 - 为什么做:工作日历分期的第四张卡,让审批超时和工作日历一起发布,周五下午提交的审批不再在周五晚上就升级。 - 出错会怎样:只影响选了「工作时间」的审批节点;默认仍按自然小时,已在途的审批到期时间不变,可以直接撤回。 - 要你做什么:无。 ## What changes ADR-0157 D5, D9 and D12, on the approval escalation: - **Spec** (`ApprovalEscalationSchema`): two optional keys. `clock: 'wall_clock' | 'working_time'`, default `'wall_clock'` (a stored snapshot carries no `clock`, so every open request keeps its deadline), and `calendar`, a working-calendar code (`WORK_CALENDAR_CODE_PATTERN`). The `timeoutHours` describe text and comment no longer say the platform ships no calendar; they say the clock decides how the hours count. The describe first sentences stay in business words. - **Runtime** (`plugin-approvals`): one deadline function, `ApprovalService.slaDeadline`, serves both the escalation sweep and the request read projection (D12). `wall_clock` is the unchanged `slaDueAt` (`created_at + timeoutHours` elapsed). `working_time` counts `timeoutHours` working hours from `created_at` through the calendar service (`WORK_CALENDAR_SERVICE`, resolved lazily like the other providers), naming the request's own `organization_id` and `escalation.calendar`; the service resolves the named code, else the organization default, else refuses. It is recomputed on every sweep and every read, never stored. `slaDueAt` answers nothing for a `working_time` escalation, so no path can fall back to wall-clock hours (D2). Single-shot escalation (ADR-0042 §1) is untouched: the `escalate` audit row is still the only marker, and it does not record the due time. - **Cannot answer** (D9): a calendar refusal (`ERR_WORK_CALENDAR_UNRESOLVED`, `ERR_WORK_CALENDAR_NOT_MAINTAINED`, `ERR_WORK_CALENDAR_INVALID`) is not an escalation: the sweep skips the request, counts it in one `warn` per sweep, and asks again next sweep. A kernel with no calendar service refuses the same way. **New served field (additive): `sla_due_refusal`** on `ApprovalRequestRow` (`code`, `reason` on unresolved, `calendar`, `date` on not-maintained, `message`), present in place of `sla_due_at`. - **Lint** (`@objectstack/lint`): `approval-escalation-calendar-without-working-time` (error) refuses a `calendar` beside the wall clock, where nothing reads it. Static only: no check that the calendar exists (D9). - **Studio**: the approval inspector's escalation block gains "Count hours as" (wall-clock / working hours) and "Working calendar", which shows only under working time, from both descriptor sources (`SIBLING_GATES` in `json-schema-to-fields.ts` serves the hand-written table and the engine-published `configSchema`). zh overlay added; the `timeoutHours` zh help no longer says there is no calendar. - **Console inbox**: where the SLA countdown sits, a pending row with `sla_due_refusal` shows "Calendar can't compute" with the reason (no calendar "X" / no default calendar / not maintained for DATE / fix the calendar in Setup), in all eleven locale packs (zh-Hans: 「日历算不出」). The zh-Hant pack is generated from zh-Hans by `gen:zh-hant`, never hand-edited. - **Docs**: `content/docs/automation/approvals.mdx` (Timeouts and escalation) and the generated reference page. ADR anchor for the deadline function. Not released alone: ships in the same release as the calendar objects and service (#35355) and the working-day formula functions (#35356), ADR-0157 D4. ## Evals None: no agent-facing prompt or skill text changes here. The skills text is owed as a follow-up (the `Skills-docs:` line). ## Tests - `approval-service-sla-calendar-clock.test.ts`, a new top-level describe on the REAL `WorkCalendarService` over a read double: Friday 17:00 + 4 working hours with Monday a holiday fires Tuesday 12:00 and not at any earlier instant; before a make-up (调休) Saturday it fires that Saturday 12:00; a holiday entered later moves the deadline (D12); a missing calendar serves `sla_due_refusal` (`not_found`), escalates nothing past every deadline, and the next sweep escalates once the calendar exists; `no_default` and `ERR_WORK_CALENDAR_NOT_MAINTAINED` (with its date); no calendar service refuses; an explicit `wall_clock` equals the default. The four existing wall-clock pins are unchanged and green. - Lint: the finding fires on a calendar with no clock and with `wall_clock`; its control (`working_time` with a calendar that does not exist, and `working_time` with none) is clean. - Inspector: the calendar is hidden on the default and an explicit wall clock, shown under working time, and a typed code round-trips through `ApprovalNodeConfigSchema`, from both descriptor sources. Inbox: the reason renders in place of the countdown in English and zh-CN, and a served due time keeps its countdown. - Re-measured pins: the inspector's gated-field census 33 → 35, the declared-default surface ten → eleven (`escalation.clock`), the escalation round-trip now parses with `clock: 'wall_clock'` materialized, and the de quote-pairing pin 118 → 119 (the new `approvalsInbox.slaCalendarNotFound` adds one correctly paired „{{calendar}}“ span, U+201E … U+201C; ledger line added, assertion unchanged). <details><summary>Ablations (both red, both restored to HEAD by `scripts/ablation-replace.mjs`)</summary> - Working-time branch (`slaDeadline` answers wall-clock for every clock): 6 of 12 tests red, the six `working_time` cases; restore blob equals HEAD, `git diff HEAD` empty. - Cannot-answer guard (a refusal no longer `continue`s the sweep): 3 of 12 red, each `expected { scanned: 1, escalated: 1 } to match object { escalated: +0 }`; restored to HEAD. A first attempt whose replacement was a substring of its anchor was refused by the tool before running and is not counted. </details> ## Verification Read first: `packages/plugins/plugin-approvals/src/approval-service.ts` (`slaDeadline`, `projectWorkingTimeDue`, the `runEscalations` hunk), `packages/spec/src/automation/approval.zod.ts`, `ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx` (`slaRefusalLabel`). Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec vitest run src/approval-service-sla-calendar-clock.test.ts` shows 12 passed. <details><summary>Local readings</summary> Fix round on head `f079e34` (`origin/main` merged at `753091e`, `zh-Hant.ts` regenerated, de pin re-measured), in this container (shared box), through `scripts/pm/os-verify-lock.sh`: - `zh-hant-generated.test.ts` red before the regeneration (`src/locales/zh-Hant.ts is stale`, 1 failed | 10 passed), green after; `de-quote-pairing-3876.test.ts` red with the old pin (`expected 119 to be 118`, `{ open: 119, close: 119, rdq: 0 }` vs 118), green after. - `vitest run packages/i18n/` (ui root): Test Files 105 passed (105), Tests 1957 passed, 13 skipped. - `pnpm check:i18n`: OK, 10 packages, all bundles in sync. - `node scripts/pm/dispatch-gates.mjs --commands` (131 families) on `f079e34`, each with its exit code; `--ran`: 131 derived, 131 run, 0 NOT-MEASURED (a derived zero). Eight families first refused for missing builds (exit 3, and ui `scripts/` red for an unbuilt `@objectstack/client`) and are exit 0 after building `./packages/**`. - `overlap-check`: VERDICT clean. Earlier readings, on head `1d5c6fc`: - `pnpm --filter @objectstack/spec test`: Test Files 866 passed (866), Tests 27798 passed, 1 todo. - `pnpm --filter @objectstack/plugin-approvals exec vitest run`: Test Files 125 passed (125), Tests 1793 passed (one commit earlier; the later commits touch only this package's clock test file, rerun green: 12 passed). - `pnpm --filter @objectstack/lint exec vitest run`: Test Files 222 passed (222), Tests 9346 passed. - ui: `vitest run packages/app-shell/src/views/metadata-admin/inspectors/ apps/console/src/pages/system/ApprovalsInboxPage`: Test Files 256 passed (256), Tests 3254 passed, 1 skipped; `vitest run scripts/` (ui): 172 passed, 2 skipped. - Typecheck: `@objectstack/spec`, `@objectstack/lint`, `@objectstack/plugin-approvals` (incl. `check:test-typecheck`) green; `type-check` of `@object-ui/i18n`, `@object-ui/app-shell`, `@object-ui/console` green after building their closure. - `pnpm --filter @objectstack/spec check:generated --fix`: regenerated `content/docs/references/**` only; every other artifact current. - `pnpm check:i18n`: OK, 10 packages, all bundles in sync. - `node scripts/pm/dispatch-gates.mjs --commands` (131 families) run on this head, each exit 0; `--ran` reconciliation: 131 derived, 131 run, 0 NOT-MEASURED (a derived zero, every line carries its exit code). - `node scripts/pm/overlap-check.mjs --branch=claude/area-a4W-35357`: VERDICT clean (origin/main, #35789, #35909, #35910). - Size (on `f079e34`, against merged `origin/main`): +875 / -48 across 35 files, tests and generated files included. </details> ## Acceptance notes - The served shape is additive: `sla_due_refusal` is new and optional; `sla_due_at` keeps its meaning under `wall_clock`. - The `escalate` audit row does not record the due time it fired on (the ADR left this to this card); the deadline is never stored anywhere. - A deadline is computed once per row per read and sweep. A calendar the service answers is served from its 60-second cache; a refusal is never cached, so every read and sweep asks again; reads of decided requests compute it too, so the projection stays one function for every status. - The inbox reason is localized from the refusal's code; the server's English `message` is served but not shown. - `origin/main` is merged in (at `753091e`, a clean merge); `overlap-check` reports clean merges against `origin/main`, #35789, the open locale-pack PRs and the two open lint PRs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#4 · os-elon-musk · session_016WV4czKnDE6hsyXQzB9wB2 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent af566c2 commit e6fa510

35 files changed

Lines changed: 875 additions & 48 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/plugin-approvals': minor
4+
'@objectstack/lint': minor
5+
'@object-ui/console': minor
6+
'@object-ui/i18n': minor
7+
---
8+
9+
feat(approvals): an escalation deadline can count working time on an organization's working calendar (`escalation.clock: 'working_time'`)
10+
11+
Clause-②: yes (widening)
12+
Metadata-protocol: added
13+
Skills-docs: follow-up owed — skills/objectstack-automation/references/state-machines-and-approvals.md
14+
15+
An approval node's `escalation` gains two optional keys (ADR-0157 D5):
16+
17+
- **`clock`**: `'wall_clock'` (the default) or `'working_time'`. Under `wall_clock` nothing changes: `timeoutHours` counts elapsed hours from `created_at`, nights, weekends and holidays included, and every request already open keeps its deadline (a stored snapshot carries no `clock`). Under `working_time` the hours count only the working periods of a working calendar (`sys_work_calendar`), skipping its holidays and counting its make-up workdays: a request opened at 17:00 on a Friday with `timeoutHours: 4`, on 09:00-12:00 and 13:00-18:00 periods, escalates at 12:00 on the next working day.
18+
- **`calendar`**: the code of the working calendar to count on. Left out, the request organization's default calendar counts. There is never a fallback to wall-clock hours.
19+
20+
The approvals sweep and the request read share one deadline function. A `working_time` deadline is counted again on every sweep and every read and is never stored, so a holiday entered after a request opened moves its deadline; an escalation that already fired stays fired (single-shot, ADR-0042). When the calendar cannot count the deadline (no calendar has the code, the organization has no default, or the calendar is not maintained as far as the deadline needs), the request does not escalate, the next sweep tries again, and the request read carries a new additive field, `sla_due_refusal` (`code`, `reason` or `date`, `message`), in place of `sla_due_at`. The approvals inbox shows "Calendar can't compute" with the reason where the SLA countdown sits, in every console language.
21+
22+
`@objectstack/lint` refuses a `calendar` written beside the wall clock (`approval-escalation-calendar-without-working-time`, error): nothing would read it. Whether the named calendar exists is the organization's runtime data and is never checked at publish. The Studio approval inspector offers the clock and, under working time only, the calendar.
23+
24+
Not released alone: this ships in the same release as the working-calendar objects and service and the working-day formula functions (ADR-0157 D4).

‎content/docs/automation/approvals.mdx‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,10 +1147,44 @@ resumes exactly as if a human had clicked. Every escalation writes an audit row
11471147
of kind `escalate` naming the configured action; it, the auto decision that
11481148
follows it, and the escalation's notifications record no actor, because no
11491149
person acted (ADR-0118 D1).
1150-
`timeoutHours` counts **calendar (wall-clock) hours** — nights, weekends and
1151-
holidays included, because the platform ships no business-hours calendar — so a
1152-
request opened at 17:00 on a Friday with `timeoutHours: 4` escalates at 21:00
1153-
that same Friday.
1150+
`timeoutHours` counts from the moment the request was submitted, and
1151+
`clock` decides how its hours count (ADR-0157 D5):
1152+
1153+
- **`wall_clock`** (the default) counts every hour — nights, weekends and
1154+
holidays included — so a request opened at 17:00 on a Friday with
1155+
`timeoutHours: 4` escalates at 21:00 that same Friday.
1156+
- **`working_time`** counts only the working periods of a working calendar
1157+
(`sys_work_calendar`, kept by the organization's administrators in Setup),
1158+
skipping its holidays and counting its make-up workdays. With 09:00–12:00
1159+
and 13:00–18:00 working periods, the same Friday request escalates at 12:00
1160+
on the next working day: Monday, or Tuesday when Monday is a holiday, or the
1161+
Saturday itself when it is a make-up workday.
1162+
1163+
```ts
1164+
escalation: {
1165+
timeoutHours: 4,
1166+
clock: 'working_time',
1167+
calendar: 'cn_standard', // optional: the organization's default calendar when left out
1168+
action: 'notify',
1169+
escalateTo: 'approvals_supervisor',
1170+
}
1171+
```
1172+
1173+
The calendar is the one `calendar` names, else the organization's default
1174+
calendar; there is never a fallback to wall-clock hours. The deadline is
1175+
counted again on every sweep and every read, so a holiday entered after a
1176+
request opened moves its deadline (an escalation that already fired stays
1177+
fired). When the calendar cannot count the deadline — no calendar has that
1178+
code, the organization has no default, or the calendar is not maintained as
1179+
far as the deadline needs — the request does **not** escalate. Its read
1180+
carries no `sla_due_at` and a `sla_due_refusal` instead (the refusal `code`,
1181+
its `reason` or the `date` it needs, and a `message`), the approvals inbox
1182+
shows "Calendar can't compute" with the reason, and the next sweep tries
1183+
again, so fixing the calendar is the only step. Publishing checks only what is
1184+
written: a `calendar` beside the wall clock is refused
1185+
(`approval-escalation-calendar-without-working-time`), since nothing would read
1186+
it; whether the named calendar exists is the organization's data, checked when
1187+
the deadline is counted.
11541188

11551189
<Callout type="warn">
11561190
**Escalation needs the job service.** The plugin sweeps pending requests on an

‎content/docs/references/automation/approval.mdx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ const result = ApprovalDecision.parse(data);
3939
| Property | Type | Required | Description |
4040
| :--- | :--- | :--- | :--- |
4141
| **enabled** | `boolean` | optional (default: `true`) | Turns this step's deadline on or off. It is on by default once a deadline is set: switch it off to keep the settings without acting on them, or remove the escalation to drop the deadline altogether |
42-
| **timeoutHours** | `number` | ✅ | How many hours a request may wait before the escalation runs. These are calendar (wall-clock) hours — nights, weekends and holidays count. The platform ships no business-hours calendar: a request opened at 17:00 on a Friday with 4 hours escalates at 21:00 that same Friday |
42+
| **timeoutHours** | `number` | ✅ | How many hours a request may wait before the escalation runs, counted from when it was submitted. The clock decides how the hours count: wall-clock hours (the default) count nights, weekends and holidays, so a request opened at 17:00 on a Friday with 4 hours escalates at 21:00 that Friday; working hours count only the working periods of a working calendar |
43+
| **clock** | `Enum<'wall_clock' \| 'working_time'>` | optional (default: `"wall_clock"`) | How the timeout's hours count: every hour, or only working hours. Wall-clock hours ('wall_clock', the default) count nights, weekends and holidays. Working hours ('working_time') count only the working periods of the organization's working calendar, skipping its holidays and counting its make-up workdays; when the calendar cannot count the deadline (no such calendar, or not maintained that far) the request does not escalate and shows why, until the calendar is fixed |
44+
| **calendar** | `string` | optional | Which working calendar counts the hours under working time, by its code. Leave it empty to use the organization's default calendar |
4345
| **action** | `Enum<'reassign' \| 'auto_approve' \| 'auto_reject' \| 'notify'>` | optional (default: `"notify"`) | What happens when the deadline passes: hand the request to someone else, approve it, reject it, or notify someone (the default) |
4446
| **escalateTo** | `string` | optional | Who takes over or is notified when the deadline passes: usually a position, or a specific person. Write a position machine name or 'position:`<name>`', a user id or an email. A 'team:', 'department:', 'org_membership_level:' or 'role:' address is refused: no approver acts under one |
4547
| **notifySubmitter** | `boolean` | optional (default: `true`) | Tell the person who submitted the request when it escalates |
@@ -77,7 +79,7 @@ const result = ApprovalDecision.parse(data);
7779
| **onEmptyApprovers** | `Enum<'admin_rescue' \| 'fail' \| 'auto_approve' \| 'fallback'>` | optional (default: `"admin_rescue"`) | What happens when this step finds no one to approve: by default the organization's administrators decide; you can instead name backup approvers, fail the step, or approve it automatically. 'admin_rescue' (default) opens the request on the administrators; 'fallback' opens it on fallbackApprovers instead, naming who decides; 'fail' fails the step; 'auto_approve' approves it with no one deciding |
7880
| **fallbackApprovers** | `{ type: Enum<'manager' \| 'position' \| 'department' \| 'team' \| 'queue' \| 'field' \| …>; value?: string; resolveAs?: Enum<'user' \| 'department' \| 'position' \| 'team'>; group?: string; … }[]` | optional | Backup approvers who decide when this step finds no one else. Read only when onEmptyApprovers is 'fallback' |
7981
| **decisionOutputs** | `(string \| { key: string; label?: string; type?: Enum<'text' \| 'user' \| 'department' \| 'position' \| 'team'>; multiple?: boolean; … })[]` | optional | Extra answers the approver gives with the decision, such as who approves a later step; later steps read them. Each entry is a plain name (a text box) or `{ key, type, multiple }` to show a picker |
80-
| **escalation** | `{ enabled?: boolean; timeoutHours: number; action?: Enum<'reassign' \| 'auto_approve' \| 'auto_reject' \| 'notify'>; escalateTo?: string; … }` | optional | A deadline for this step, and what happens when it passes |
82+
| **escalation** | `{ enabled?: boolean; timeoutHours: number; clock?: Enum<'wall_clock' \| 'working_time'>; calendar?: string; … }` | optional | A deadline for this step, and what happens when it passes |
8183
| **maxRevisions** | `integer` | optional (default: `3`) | How many times a request can be sent back for changes before it is rejected automatically (0 turns send-back off) |
8284

8385
### Nested Shape: `ApprovalNodeConfig.approvers[number]`
@@ -115,7 +117,9 @@ const result = ApprovalDecision.parse(data);
115117
| Property | Type | Required | Description |
116118
| :--- | :--- | :--- | :--- |
117119
| **enabled** | `boolean` | optional (default: `true`) | Turns this step's deadline on or off. It is on by default once a deadline is set: switch it off to keep the settings without acting on them, or remove the escalation to drop the deadline altogether |
118-
| **timeoutHours** | `number` | ✅ | How many hours a request may wait before the escalation runs. These are calendar (wall-clock) hours — nights, weekends and holidays count. The platform ships no business-hours calendar: a request opened at 17:00 on a Friday with 4 hours escalates at 21:00 that same Friday |
120+
| **timeoutHours** | `number` | ✅ | How many hours a request may wait before the escalation runs, counted from when it was submitted. The clock decides how the hours count: wall-clock hours (the default) count nights, weekends and holidays, so a request opened at 17:00 on a Friday with 4 hours escalates at 21:00 that Friday; working hours count only the working periods of a working calendar |
121+
| **clock** | `Enum<'wall_clock' \| 'working_time'>` | optional (default: `"wall_clock"`) | How the timeout's hours count: every hour, or only working hours. Wall-clock hours ('wall_clock', the default) count nights, weekends and holidays. Working hours ('working_time') count only the working periods of the organization's working calendar, skipping its holidays and counting its make-up workdays; when the calendar cannot count the deadline (no such calendar, or not maintained that far) the request does not escalate and shows why, until the calendar is fixed |
122+
| **calendar** | `string` | optional | Which working calendar counts the hours under working time, by its code. Leave it empty to use the organization's default calendar |
119123
| **action** | `Enum<'reassign' \| 'auto_approve' \| 'auto_reject' \| 'notify'>` | optional (default: `"notify"`) | What happens when the deadline passes: hand the request to someone else, approve it, reject it, or notify someone (the default) |
120124
| **escalateTo** | `string` | optional | Who takes over or is notified when the deadline passes: usually a position, or a specific person. Write a position machine name or 'position:`<name>`', a user id or an email. A 'team:', 'department:', 'org_membership_level:' or 'role:' address is refused: no approver acts under one |
121125
| **notifySubmitter** | `boolean` | optional (default: `true`) | Tell the person who submitted the request when it escalates |

‎packages/lint/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ export {
345345
APPROVAL_APPROVER_TYPE_UNKNOWN,
346346
APPROVAL_APPROVER_TYPE_UNSUPPORTED,
347347
APPROVAL_ESCALATION_REASSIGN_NO_TARGET,
348+
APPROVAL_ESCALATION_CALENDAR_WITHOUT_WORKING_TIME,
348349
APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY,
349350
APPROVAL_EXPRESSION_INVALID,
350351
APPROVAL_EXPRESSION_NO_EMPTY_POLICY,

‎packages/lint/src/validate-approval-approvers.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
APPROVAL_APPROVER_TYPE_UNKNOWN,
1111
APPROVAL_APPROVER_TYPE_UNSUPPORTED,
1212
APPROVAL_ESCALATION_REASSIGN_NO_TARGET,
13+
APPROVAL_ESCALATION_CALENDAR_WITHOUT_WORKING_TIME,
1314
APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY,
1415
APPROVAL_EXPRESSION_INVALID,
1516
APPROVAL_EXPRESSION_NO_EMPTY_POLICY,
@@ -176,6 +177,30 @@ describe('validateApprovalApprovers', () => {
176177
expect(findings[0].hint).toContain('position');
177178
});
178179

180+
it("refuses an escalation.calendar beside the wall clock: nothing reads it (ADR-0157 D9)", () => {
181+
const stack = stackWithApprovers([{ type: 'user', value: 'u1' }]);
182+
const node = (stack.flows as any)[0].nodes[1];
183+
for (const clock of [undefined, 'wall_clock']) {
184+
node.config.escalation = { enabled: true, timeoutHours: 4, action: 'notify', calendar: 'cn_standard', ...(clock ? { clock } : {}) };
185+
const findings = validateApprovalApprovers(stack);
186+
expect(findings).toHaveLength(1);
187+
expect(findings[0]).toMatchObject({
188+
severity: 'error',
189+
rule: APPROVAL_ESCALATION_CALENDAR_WITHOUT_WORKING_TIME,
190+
path: 'flows[0].nodes[1].config.escalation.calendar',
191+
});
192+
}
193+
});
194+
195+
it("accepts a calendar on 'working_time', and 'working_time' with no calendar: whether a calendar exists is never judged here", () => {
196+
const stack = stackWithApprovers([{ type: 'user', value: 'u1' }]);
197+
const node = (stack.flows as any)[0].nodes[1];
198+
node.config.escalation = { enabled: true, timeoutHours: 4, action: 'notify', clock: 'working_time', calendar: 'no_such_calendar' };
199+
expect(validateApprovalApprovers(stack)).toEqual([]);
200+
node.config.escalation = { enabled: true, timeoutHours: 4, action: 'notify', clock: 'working_time' };
201+
expect(validateApprovalApprovers(stack)).toEqual([]);
202+
});
203+
179204
it('accepts reassign escalation with a target, and non-reassign actions without one', () => {
180205
const stack = stackWithApprovers([{ type: 'user', value: 'u1' }]);
181206
const node = (stack.flows as any)[0].nodes[1];

‎packages/lint/src/validate-approval-approvers.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* | approval-approver-type-deprecated | warning | ADR-0090 D3 (#3133) |
2222
* | approval-approver-type-unknown | warning | contract-first (PD #12) |
2323
* | approval-escalation-reassign-no-target | warning | silent notify degradation |
24+
* | approval-escalation-calendar-without-working-time | error | ADR-0157 D9 (static only) |
2425
* | approval-approvers-may-resolve-empty | info | empty-position dead-end (#3424) |
2526
* | approval-approvers-may-resolve-empty | info | unset-manager dead-end (#16748) |
2627
* | approval-expression-invalid | error/info | #3447 P2 closed-root expressions |
@@ -61,6 +62,7 @@ export const APPROVAL_APPROVER_TYPE_DEPRECATED = 'approval-approver-type-depreca
6162
export const APPROVAL_APPROVER_TYPE_UNKNOWN = 'approval-approver-type-unknown';
6263
export const APPROVAL_APPROVER_TYPE_UNSUPPORTED = 'approval-approver-type-unsupported';
6364
export const APPROVAL_ESCALATION_REASSIGN_NO_TARGET = 'approval-escalation-reassign-no-target';
65+
export const APPROVAL_ESCALATION_CALENDAR_WITHOUT_WORKING_TIME = 'approval-escalation-calendar-without-working-time';
6466
export const APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY = 'approval-approvers-may-resolve-empty';
6567
export const APPROVAL_EXPRESSION_INVALID = 'approval-expression-invalid';
6668
export const APPROVAL_EXPRESSION_NO_EMPTY_POLICY = 'approval-expression-no-empty-policy';
@@ -795,6 +797,27 @@ export function validateApprovalApprovers(
795797
});
796798
}
797799
}
800+
801+
// ADR-0157 D9, the static half of the working-time clock: a calendar
802+
// code beside the wall clock (written, or the default) names a calendar
803+
// nothing reads — the hours count on the wall clock, while the author
804+
// who named a calendar meant working time. Whether the named calendar
805+
// EXISTS is per-organization runtime data and is never judged here.
806+
const calendar = escalation && typeof escalation === 'object' && typeof escalation.calendar === 'string'
807+
? escalation.calendar.trim()
808+
: '';
809+
if (calendar && escalation!.clock !== 'working_time') {
810+
findings.push({
811+
severity: 'error',
812+
rule: APPROVAL_ESCALATION_CALENDAR_WITHOUT_WORKING_TIME,
813+
where,
814+
path: `${nodePath}.config.escalation.calendar`,
815+
message:
816+
`escalation.calendar '${calendar}' is set but escalation.clock is not 'working_time' — the ` +
817+
`wall clock counts the timeout and nothing reads the calendar.`,
818+
hint: `Set escalation.clock to 'working_time' to count working hours on that calendar, or remove escalation.calendar.`,
819+
});
820+
}
798821
}
799822
}
800823

0 commit comments

Comments
 (0)