Skip to content

Commit 9f762cf

Browse files
test(app-shell,console): approvals and inbox reads carry the console's UI language (#37543)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgTACWfLyuZEQ4gVESvk5YRQ)_ Part of #37483 ## What changes Test-only. Two pins hold every approvals reader and the notification inbox read to the console's authenticated fetch, which sends the active UI language as `Accept-Language`: - `ui/packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx`: the approval history read (`listApprovalActions`, `/approvals/requests/:id/actions`), `remindApprovalRequest`, `fetchPendingApprovalPage` (bell, home, full-page inbox), and the notification inbox: the real `AdapterProvider` mounted with `useSharedInboxFeed`, asserting the header on its `sys_inbox_message` read. - `ui/apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx`: the request page's history (`sys_approval_action` timeline) and request read (`process_label` / `step_label`) through `routeApprovalRecordReads(adapter)`, as `AppContent` wires it. Each pin sets `<html lang="en">` and asserts `Accept-Language: en`. The controls are on the stamp itself: an empty `<html lang>` adds no header rather than a guessed one. ## Why The card was measured on the 18.6.0 bundles. On `main` the shared helper the card suggests already does the job: `createAuthenticatedFetch` (`@object-ui/auth`) stamps `<html lang>` as `Accept-Language` on every `/api/` call, and the readers it names now go through it: - `useRecordApprovals` (`fetchJson`: request, actions, remind) and `sharedUserFeeds` (`fetchPendingApprovalPage`) moved from a bare `fetch` + `bearerAuthHeaders()` to it in #37185 (merged 2026-11-25, after 18.6.0). - `approvalsApi.ts` and `approvalRequestsDataSource.ts` have used it since #27040 / #28619. - The inbox (`sys_inbox_message`, `sys_notification_receipt`) reads through the console adapter, which `AdapterProvider` builds on the same fetch. So no source change is needed for approval history; what was missing is a pin that keeps these surfaces on that transport. Ablation: replacing the stamp in `createAuthenticatedFetch` with a no-op turns all six positive pins red, controls stay green; building `AdapterProvider`'s adapter on a bare `fetch` turns the inbox pin red. **Why `Part of`, not `Fixes`:** the inbox read already went through the stamped adapter at 18.6.0, so "fixed after 18.6.0" does not explain the inbox evidence in comment 7186322473. The card stays open until a header capture of `GET /api/v1/data/sys_inbox_message` on a `main` build settles it (reported on the card). ## Verification - `pnpm --dir ui exec vitest run packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx`: 9 passed. - Ablations above: 6 failed / 3 passed with the stamp removed; inbox pin red with the adapter on a bare `fetch`. - `eslint` on both files: clean. `check:commit-card-trailers`, `overlap-check`: clean. Publishes nothing (test files only), so `skip-changeset`. Clause-②: no Metadata-protocol: none ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CbGtuQD4c5iyX7mqpV <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CbGtuQD4c5iyX7mqpV --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4116465 commit 9f762cf

2 files changed

Lines changed: 214 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* objectstack#37483 — the request page's approvals reads carry the console's
3+
* UI language, not the browser's.
4+
*
5+
* The approval history (`/approvals/requests/:id/actions`) holds a system note
6+
* the server renders in the request's locale, and the request
7+
* (`/approvals/requests/:id`) carries `process_label` / `step_label` the same
8+
* way. `AppContent` routes the console adapter's record-page reads through
9+
* `routeApprovalRecordReads(adapter)` with no `fetch` of its own, so they
10+
* read through the console's authenticated fetch, which stamps the active UI
11+
* language (`<html lang>`) as `Accept-Language`. The control is on the stamp
12+
* itself: an empty `<html lang>` adds no header, rather than a guessed one.
13+
* (In the console it is never empty: `index.html` ships `lang="en"` and the
14+
* i18n provider always writes the chosen language.)
15+
*/
16+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
17+
import type { DataSource } from '@object-ui/types';
18+
import {
19+
APPROVAL_ACTION_OBJECT,
20+
APPROVAL_REQUEST_OBJECT,
21+
routeApprovalRecordReads,
22+
} from './approvalRequestsDataSource';
23+
24+
let fetchSpy: ReturnType<typeof vi.fn>;
25+
let originalLang: string;
26+
27+
function acceptLanguageOf(match: RegExp): string | null {
28+
const call = fetchSpy.mock.calls.find(([input]) => {
29+
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
30+
return match.test(url);
31+
});
32+
expect(call, `no request matched ${match}`).toBeDefined();
33+
const [input, init] = call!;
34+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
35+
return headers.get('Accept-Language');
36+
}
37+
38+
/** As `AppContent` wires it: the console adapter, routed, with no `fetch` of its own. */
39+
function source(): DataSource {
40+
const host = { find: vi.fn(), findOne: vi.fn() } as unknown as DataSource;
41+
return routeApprovalRecordReads(host);
42+
}
43+
44+
beforeEach(() => {
45+
originalLang = document.documentElement.lang;
46+
fetchSpy = vi.fn(async (input: RequestInfo | URL) => {
47+
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
48+
const body = /\/actions/.test(url) ? { data: [] } : { data: { id: 'req_1', status: 'pending' } };
49+
return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
50+
});
51+
vi.stubGlobal('fetch', fetchSpy);
52+
});
53+
54+
afterEach(() => {
55+
document.documentElement.lang = originalLang;
56+
vi.unstubAllGlobals();
57+
});
58+
59+
describe('approvals request page reads carry the UI language (objectstack#37483)', () => {
60+
it('an English console sends Accept-Language: en on the approval history read', async () => {
61+
document.documentElement.lang = 'en';
62+
await source().find(APPROVAL_ACTION_OBJECT, { $filter: { request_id: 'req_1' } } as never);
63+
expect(acceptLanguageOf(/\/approvals\/requests\/req_1\/actions/)).toBe('en');
64+
});
65+
66+
it('an English console sends Accept-Language: en on the request read (process and step labels)', async () => {
67+
document.documentElement.lang = 'en';
68+
await source().findOne(APPROVAL_REQUEST_OBJECT, 'req_1').catch(() => undefined);
69+
expect(acceptLanguageOf(/\/approvals\/requests\/req_1(\?|$)/)).toBe('en');
70+
});
71+
72+
it('control: an empty <html lang> adds no header', async () => {
73+
document.documentElement.lang = '';
74+
await source().find(APPROVAL_ACTION_OBJECT, { $filter: { request_id: 'req_1' } } as never);
75+
expect(acceptLanguageOf(/\/approvals\/requests\/req_1\/actions/)).toBeNull();
76+
});
77+
});
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/**
2+
* objectstack#37483 — the approvals and notification-inbox reads carry the
3+
* console's UI language, not the browser's.
4+
*
5+
* The server renders approval history notes (`approvalSubmitterExcluded*`),
6+
* `process_label` / `step_label` and the inbox's `keyed_text` titles in the
7+
* request's locale. A read that names no language falls back to the browser's
8+
* own `Accept-Language`, so an English console on a zh-CN browser read those
9+
* strings in Chinese. Every reader here goes through the console's
10+
* authenticated fetch (`createAuthenticatedFetch`), which stamps the active UI
11+
* language — `<html lang>`, kept in sync by the i18n provider — as
12+
* `Accept-Language`. These pins hold each reader to that transport. The
13+
* controls are on the stamp itself: an empty `<html lang>` adds no header,
14+
* rather than a guessed one. (In the console it is never empty: `index.html`
15+
* ships `lang="en"` and the i18n provider always writes the chosen language.)
16+
*/
17+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
18+
import { render, waitFor, cleanup } from '@testing-library/react';
19+
import { AdapterProvider } from '../../providers/AdapterProvider';
20+
import {
21+
__resetRecordApprovalsStore,
22+
listApprovalActions,
23+
remindApprovalRequest,
24+
} from '../useRecordApprovals';
25+
import {
26+
__markFirstPainted,
27+
__resetSharedUserFeeds,
28+
fetchPendingApprovalPage,
29+
useSharedInboxFeed,
30+
} from '../sharedUserFeeds';
31+
32+
/** One signed-in user: the inbox feed reads nothing without one. */
33+
vi.mock('@object-ui/auth', async (importOriginal) => ({
34+
...(await importOriginal<Record<string, unknown>>()),
35+
useAuth: () => ({ user: { id: 'u1' } }),
36+
}));
37+
38+
const json = (body: unknown) =>
39+
new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } });
40+
41+
let fetchSpy: ReturnType<typeof vi.fn>;
42+
let originalLang: string;
43+
44+
function acceptLanguageOf(match: RegExp): string | null {
45+
const call = fetchSpy.mock.calls.find(([input]) => {
46+
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
47+
return match.test(url);
48+
});
49+
expect(call, `no request matched ${match}`).toBeDefined();
50+
const [input, init] = call!;
51+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
52+
return headers.get('Accept-Language');
53+
}
54+
55+
beforeEach(() => {
56+
originalLang = document.documentElement.lang;
57+
__resetRecordApprovalsStore();
58+
fetchSpy = vi.fn(async (input: RequestInfo | URL) => {
59+
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
60+
if (/\/approvals\/requests\?/.test(url)) return json({ data: [], total: 0 });
61+
if (/\/remind$/.test(url)) return json({ notified: 1 });
62+
if (/\/approvals\/requests\//.test(url)) return json({ data: [] });
63+
return json({ data: [], records: [], value: [], total: 0 });
64+
});
65+
vi.stubGlobal('fetch', fetchSpy);
66+
});
67+
68+
afterEach(() => {
69+
cleanup();
70+
__resetSharedUserFeeds();
71+
document.documentElement.lang = originalLang;
72+
vi.unstubAllGlobals();
73+
});
74+
75+
describe('approvals reads carry the UI language (objectstack#37483)', () => {
76+
it('an English console sends Accept-Language: en on the approval history read', async () => {
77+
document.documentElement.lang = 'en';
78+
await listApprovalActions('req-1');
79+
expect(acceptLanguageOf(/\/approvals\/requests\/req-1\/actions$/)).toBe('en');
80+
});
81+
82+
it('the remind write carries it too', async () => {
83+
document.documentElement.lang = 'en';
84+
await remindApprovalRequest('req-1');
85+
expect(acceptLanguageOf(/\/approvals\/requests\/req-1\/remind$/)).toBe('en');
86+
});
87+
88+
it('the pending-approvals page (bell, home, full-page inbox) carries it', async () => {
89+
document.documentElement.lang = 'en';
90+
await fetchPendingApprovalPage(['user-1'], 10);
91+
expect(acceptLanguageOf(/\/approvals\/requests\?/)).toBe('en');
92+
});
93+
94+
it('control: an empty <html lang> adds no header', async () => {
95+
document.documentElement.lang = '';
96+
await listApprovalActions('req-1');
97+
expect(acceptLanguageOf(/\/approvals\/requests\/req-1\/actions$/)).toBeNull();
98+
});
99+
});
100+
101+
describe('notification inbox reads carry the UI language (objectstack#37483 comment 7186322473)', () => {
102+
// Mounted as the console mounts it: the real `AdapterProvider` builds its
103+
// own adapter, and `useSharedInboxFeed` reads `sys_inbox_message` /
104+
// `sys_notification_receipt` through it. So the pin follows the console's
105+
// wiring, not a hand-built adapter.
106+
function InboxReader() {
107+
useSharedInboxFeed();
108+
return null;
109+
}
110+
111+
async function mountInbox() {
112+
__resetSharedUserFeeds();
113+
__markFirstPainted();
114+
render(
115+
<AdapterProvider>
116+
<InboxReader />
117+
</AdapterProvider>,
118+
);
119+
await waitFor(() =>
120+
expect(
121+
fetchSpy.mock.calls.some(([input]) => /sys_inbox_message/.test(String(input instanceof Request ? input.url : input))),
122+
).toBe(true),
123+
);
124+
}
125+
126+
it('an English console sends Accept-Language: en on the sys_inbox_message read', async () => {
127+
document.documentElement.lang = 'en';
128+
await mountInbox();
129+
expect(acceptLanguageOf(/sys_inbox_message/)).toBe('en');
130+
});
131+
132+
it('control: an empty <html lang> adds no header', async () => {
133+
document.documentElement.lang = '';
134+
await mountInbox();
135+
expect(acceptLanguageOf(/sys_inbox_message/)).toBeNull();
136+
});
137+
});

0 commit comments

Comments
 (0)