From 3312d68bbf201e97f1b00c425629be8e2acc5210 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 12:26:03 +0000 Subject: [PATCH 1/2] test(app-shell,console): approvals and inbox reads carry the console's UI language Pins that every approvals reader (approval history, request labels, remind, the pending-approvals page) and the notification inbox read send the active UI language as Accept-Language through the console's authenticated fetch, with a control: no UI language chosen leaves the header to the browser. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01Utp6CbGtuQD4c5iyX7mqpV --- ...RequestsDataSource.uiLocale-37483.test.tsx | 75 ++++++++++++ .../approvalsUiLocale-37483.test.tsx | 110 ++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 ui/apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx create mode 100644 ui/packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx diff --git a/ui/apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx b/ui/apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx new file mode 100644 index 00000000000..c4eeef1583f --- /dev/null +++ b/ui/apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx @@ -0,0 +1,75 @@ +/** + * objectstack#37483 — the request page's approvals reads carry the console's + * UI language, not the browser's. + * + * The approval history (`/approvals/requests/:id/actions`) holds a system note + * the server renders in the request's locale, and the request + * (`/approvals/requests/:id`) carries `process_label` / `step_label` the same + * way. With no `fetch` passed, the source reads through the console's + * authenticated fetch, which stamps the active UI language (``) as + * `Accept-Language`. Control: no UI language chosen leaves the header unset, + * so the browser's own language applies as before. + */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import type { DataSource } from '@object-ui/types'; +import { + APPROVAL_ACTION_OBJECT, + APPROVAL_REQUEST_OBJECT, + createApprovalRequestsDataSource, +} from './approvalRequestsDataSource'; + +const BASE = 'http://test.local/api/v1'; + +let fetchSpy: ReturnType; +let originalLang: string; + +function acceptLanguageOf(match: RegExp): string | null { + const call = fetchSpy.mock.calls.find(([input]) => { + const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url; + return match.test(url); + }); + expect(call, `no request matched ${match}`).toBeDefined(); + const [input, init] = call!; + const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined)); + return headers.get('Accept-Language'); +} + +function source(): DataSource { + const host = { find: vi.fn(), findOne: vi.fn() } as unknown as DataSource; + return createApprovalRequestsDataSource({ host, scope: { kind: 'all' }, baseUrl: BASE }); +} + +beforeEach(() => { + originalLang = document.documentElement.lang; + fetchSpy = vi.fn(async (input: RequestInfo | URL) => { + const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url; + const body = /\/actions/.test(url) ? { data: [] } : { data: { id: 'req_1', status: 'pending' } }; + return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } }); + }); + vi.stubGlobal('fetch', fetchSpy); +}); + +afterEach(() => { + document.documentElement.lang = originalLang; + vi.unstubAllGlobals(); +}); + +describe('approvals request page reads carry the UI language (objectstack#37483)', () => { + it('an English console sends Accept-Language: en on the approval history read', async () => { + document.documentElement.lang = 'en'; + await source().find(APPROVAL_ACTION_OBJECT, { $filter: { request_id: 'req_1' } } as never); + expect(acceptLanguageOf(/\/approvals\/requests\/req_1\/actions/)).toBe('en'); + }); + + it('an English console sends Accept-Language: en on the request read (process and step labels)', async () => { + document.documentElement.lang = 'en'; + await source().findOne(APPROVAL_REQUEST_OBJECT, 'req_1').catch(() => undefined); + expect(acceptLanguageOf(/\/approvals\/requests\/req_1(\?|$)/)).toBe('en'); + }); + + it('control: no UI language chosen leaves the header to the browser', async () => { + document.documentElement.lang = ''; + await source().find(APPROVAL_ACTION_OBJECT, { $filter: { request_id: 'req_1' } } as never); + expect(acceptLanguageOf(/\/approvals\/requests\/req_1\/actions/)).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx b/ui/packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx new file mode 100644 index 00000000000..86f505fd55a --- /dev/null +++ b/ui/packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx @@ -0,0 +1,110 @@ +/** + * objectstack#37483 — the approvals and notification-inbox reads carry the + * console's UI language, not the browser's. + * + * The server renders approval history notes (`approvalSubmitterExcluded*`), + * `process_label` / `step_label` and the inbox's `keyed_text` titles in the + * request's locale. A read that names no language falls back to the browser's + * own `Accept-Language`, so an English console on a zh-CN browser read those + * strings in Chinese. Every reader here goes through the console's + * authenticated fetch (`createAuthenticatedFetch`), which stamps the active UI + * language — ``, kept in sync by the i18n provider — as + * `Accept-Language`. These pins hold each reader to that transport, with a + * control: no UI language chosen leaves the header unset, so the browser's + * language still applies as before. + */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { createAuthenticatedFetch } from '@object-ui/auth'; +import { ObjectStackAdapter } from '@object-ui/data-objectstack'; +import { + __resetRecordApprovalsStore, + listApprovalActions, + remindApprovalRequest, +} from '../useRecordApprovals'; +import { fetchPendingApprovalPage } from '../sharedUserFeeds'; + +const json = (body: unknown) => + new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } }); + +let fetchSpy: ReturnType; +let originalLang: string; + +function acceptLanguageOf(match: RegExp): string | null { + const call = fetchSpy.mock.calls.find(([input]) => { + const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url; + return match.test(url); + }); + expect(call, `no request matched ${match}`).toBeDefined(); + const [input, init] = call!; + const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined)); + return headers.get('Accept-Language'); +} + +beforeEach(() => { + originalLang = document.documentElement.lang; + __resetRecordApprovalsStore(); + fetchSpy = vi.fn(async (input: RequestInfo | URL) => { + const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url; + if (/\/approvals\/requests\?/.test(url)) return json({ data: [], total: 0 }); + if (/\/remind$/.test(url)) return json({ notified: 1 }); + if (/\/approvals\/requests\//.test(url)) return json({ data: [] }); + return json({ data: [], records: [], value: [], total: 0 }); + }); + vi.stubGlobal('fetch', fetchSpy); +}); + +afterEach(() => { + document.documentElement.lang = originalLang; + vi.unstubAllGlobals(); +}); + +describe('approvals reads carry the UI language (objectstack#37483)', () => { + it('an English console sends Accept-Language: en on the approval history read', async () => { + document.documentElement.lang = 'en'; + await listApprovalActions('req-1'); + expect(acceptLanguageOf(/\/approvals\/requests\/req-1\/actions$/)).toBe('en'); + }); + + it('the remind write carries it too', async () => { + document.documentElement.lang = 'en'; + await remindApprovalRequest('req-1'); + expect(acceptLanguageOf(/\/approvals\/requests\/req-1\/remind$/)).toBe('en'); + }); + + it('the pending-approvals page (bell, home, full-page inbox) carries it', async () => { + document.documentElement.lang = 'en'; + await fetchPendingApprovalPage(['user-1'], 10); + expect(acceptLanguageOf(/\/approvals\/requests\?/)).toBe('en'); + }); + + it('control: no UI language chosen leaves the header to the browser', async () => { + document.documentElement.lang = ''; + await listApprovalActions('req-1'); + expect(acceptLanguageOf(/\/approvals\/requests\/req-1\/actions$/)).toBeNull(); + }); +}); + +describe('notification inbox reads carry the UI language (objectstack#37483 comment 7186322473)', () => { + // The inbox (`sys_inbox_message`, `sys_notification_receipt`) is read + // through the console's adapter, built by `AdapterProvider` on this same + // authenticated fetch. + function consoleAdapter() { + return new ObjectStackAdapter({ baseUrl: 'http://localhost', fetch: createAuthenticatedFetch() }); + } + + it('an English console sends Accept-Language: en on the sys_inbox_message read', async () => { + document.documentElement.lang = 'en'; + await consoleAdapter() + .find('sys_inbox_message', { $top: 20, $orderby: { created_at: 'desc' } } as never) + .catch(() => undefined); + expect(acceptLanguageOf(/sys_inbox_message/)).toBe('en'); + }); + + it('control: no UI language chosen leaves the header to the browser', async () => { + document.documentElement.lang = ''; + await consoleAdapter() + .find('sys_inbox_message', { $top: 20 } as never) + .catch(() => undefined); + expect(acceptLanguageOf(/sys_inbox_message/)).toBeNull(); + }); +}); From 812ae05d84dbe1ad295e7a82055842d9290af492 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 13:01:19 +0000 Subject: [PATCH 2/2] test(app-shell,console): pin the inbox read through the console's own wiring The inbox pin now mounts the real AdapterProvider and useSharedInboxFeed instead of a hand-built adapter, and the request-page pin goes through routeApprovalRecordReads as AppContent wires it. Controls are reworded as controls on the stamp itself. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01Utp6CbGtuQD4c5iyX7mqpV --- ...RequestsDataSource.uiLocale-37483.test.tsx | 20 +++--- .../approvalsUiLocale-37483.test.tsx | 65 +++++++++++++------ 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/ui/apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx b/ui/apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx index c4eeef1583f..77d096c10f6 100644 --- a/ui/apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx +++ b/ui/apps/console/src/services/approvalRequestsDataSource.uiLocale-37483.test.tsx @@ -5,21 +5,22 @@ * The approval history (`/approvals/requests/:id/actions`) holds a system note * the server renders in the request's locale, and the request * (`/approvals/requests/:id`) carries `process_label` / `step_label` the same - * way. With no `fetch` passed, the source reads through the console's - * authenticated fetch, which stamps the active UI language (``) as - * `Accept-Language`. Control: no UI language chosen leaves the header unset, - * so the browser's own language applies as before. + * way. `AppContent` routes the console adapter's record-page reads through + * `routeApprovalRecordReads(adapter)` with no `fetch` of its own, so they + * read through the console's authenticated fetch, which stamps the active UI + * language (``) as `Accept-Language`. The control is on the stamp + * itself: an empty `` adds no header, rather than a guessed one. + * (In the console it is never empty: `index.html` ships `lang="en"` and the + * i18n provider always writes the chosen language.) */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import type { DataSource } from '@object-ui/types'; import { APPROVAL_ACTION_OBJECT, APPROVAL_REQUEST_OBJECT, - createApprovalRequestsDataSource, + routeApprovalRecordReads, } from './approvalRequestsDataSource'; -const BASE = 'http://test.local/api/v1'; - let fetchSpy: ReturnType; let originalLang: string; @@ -34,9 +35,10 @@ function acceptLanguageOf(match: RegExp): string | null { return headers.get('Accept-Language'); } +/** As `AppContent` wires it: the console adapter, routed, with no `fetch` of its own. */ function source(): DataSource { const host = { find: vi.fn(), findOne: vi.fn() } as unknown as DataSource; - return createApprovalRequestsDataSource({ host, scope: { kind: 'all' }, baseUrl: BASE }); + return routeApprovalRecordReads(host); } beforeEach(() => { @@ -67,7 +69,7 @@ describe('approvals request page reads carry the UI language (objectstack#37483) expect(acceptLanguageOf(/\/approvals\/requests\/req_1(\?|$)/)).toBe('en'); }); - it('control: no UI language chosen leaves the header to the browser', async () => { + it('control: an empty adds no header', async () => { document.documentElement.lang = ''; await source().find(APPROVAL_ACTION_OBJECT, { $filter: { request_id: 'req_1' } } as never); expect(acceptLanguageOf(/\/approvals\/requests\/req_1\/actions/)).toBeNull(); diff --git a/ui/packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx b/ui/packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx index 86f505fd55a..0da140622d9 100644 --- a/ui/packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx +++ b/ui/packages/app-shell/src/hooks/__tests__/approvalsUiLocale-37483.test.tsx @@ -9,19 +9,31 @@ * strings in Chinese. Every reader here goes through the console's * authenticated fetch (`createAuthenticatedFetch`), which stamps the active UI * language — ``, kept in sync by the i18n provider — as - * `Accept-Language`. These pins hold each reader to that transport, with a - * control: no UI language chosen leaves the header unset, so the browser's - * language still applies as before. + * `Accept-Language`. These pins hold each reader to that transport. The + * controls are on the stamp itself: an empty `` adds no header, + * rather than a guessed one. (In the console it is never empty: `index.html` + * ships `lang="en"` and the i18n provider always writes the chosen language.) */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { createAuthenticatedFetch } from '@object-ui/auth'; -import { ObjectStackAdapter } from '@object-ui/data-objectstack'; +import { render, waitFor, cleanup } from '@testing-library/react'; +import { AdapterProvider } from '../../providers/AdapterProvider'; import { __resetRecordApprovalsStore, listApprovalActions, remindApprovalRequest, } from '../useRecordApprovals'; -import { fetchPendingApprovalPage } from '../sharedUserFeeds'; +import { + __markFirstPainted, + __resetSharedUserFeeds, + fetchPendingApprovalPage, + useSharedInboxFeed, +} from '../sharedUserFeeds'; + +/** One signed-in user: the inbox feed reads nothing without one. */ +vi.mock('@object-ui/auth', async (importOriginal) => ({ + ...(await importOriginal>()), + useAuth: () => ({ user: { id: 'u1' } }), +})); const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } }); @@ -54,6 +66,8 @@ beforeEach(() => { }); afterEach(() => { + cleanup(); + __resetSharedUserFeeds(); document.documentElement.lang = originalLang; vi.unstubAllGlobals(); }); @@ -77,7 +91,7 @@ describe('approvals reads carry the UI language (objectstack#37483)', () => { expect(acceptLanguageOf(/\/approvals\/requests\?/)).toBe('en'); }); - it('control: no UI language chosen leaves the header to the browser', async () => { + it('control: an empty adds no header', async () => { document.documentElement.lang = ''; await listApprovalActions('req-1'); expect(acceptLanguageOf(/\/approvals\/requests\/req-1\/actions$/)).toBeNull(); @@ -85,26 +99,39 @@ describe('approvals reads carry the UI language (objectstack#37483)', () => { }); describe('notification inbox reads carry the UI language (objectstack#37483 comment 7186322473)', () => { - // The inbox (`sys_inbox_message`, `sys_notification_receipt`) is read - // through the console's adapter, built by `AdapterProvider` on this same - // authenticated fetch. - function consoleAdapter() { - return new ObjectStackAdapter({ baseUrl: 'http://localhost', fetch: createAuthenticatedFetch() }); + // Mounted as the console mounts it: the real `AdapterProvider` builds its + // own adapter, and `useSharedInboxFeed` reads `sys_inbox_message` / + // `sys_notification_receipt` through it. So the pin follows the console's + // wiring, not a hand-built adapter. + function InboxReader() { + useSharedInboxFeed(); + return null; + } + + async function mountInbox() { + __resetSharedUserFeeds(); + __markFirstPainted(); + render( + + + , + ); + await waitFor(() => + expect( + fetchSpy.mock.calls.some(([input]) => /sys_inbox_message/.test(String(input instanceof Request ? input.url : input))), + ).toBe(true), + ); } it('an English console sends Accept-Language: en on the sys_inbox_message read', async () => { document.documentElement.lang = 'en'; - await consoleAdapter() - .find('sys_inbox_message', { $top: 20, $orderby: { created_at: 'desc' } } as never) - .catch(() => undefined); + await mountInbox(); expect(acceptLanguageOf(/sys_inbox_message/)).toBe('en'); }); - it('control: no UI language chosen leaves the header to the browser', async () => { + it('control: an empty adds no header', async () => { document.documentElement.lang = ''; - await consoleAdapter() - .find('sys_inbox_message', { $top: 20 } as never) - .catch(() => undefined); + await mountInbox(); expect(acceptLanguageOf(/sys_inbox_message/)).toBeNull(); }); });