Skip to content
19 changes: 19 additions & 0 deletions .changeset/37864-capability-unavailable-languages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@objectstack/runtime': patch
'@objectstack/spec': patch
'@objectstack/types': patch
---

fix(runtime): the mounted-but-unimplemented `501` of `/ai`, `/automation`, `/notifications`, `/ui` and a custom flow endpoint answers in the request's language

Clause-②: yes (widening) — `@objectstack/spec` `BUILTIN_OPERATION_MESSAGES` gains `capability_unavailable_install`, `capability_unavailable_unshipped`, `capability_unavailable_ui`, `capability_unavailable_ai` and `capability_unavailable_search` in every locale; `@objectstack/runtime` `HttpDispatcherResult.response` gains the optional, never-written `faultLogMessage`
Metadata-protocol: none

When a dispatcher domain's route is mounted and nothing implements the capability behind it, it answers `501 NOT_IMPLEMENTED` with the remedy sentence discovery reports for the slot. That sentence was fixed English for every reader. It now follows the request's top `Accept-Language` tag, as the other domain `501`s already do, and carries `Vary: Accept-Language`, so a shared cache cannot hand one reader's language to the next. The same holds for a custom API endpoint whose flow target finds no automation service.

- The English sentence, the status and `error.code` are unchanged byte for byte. A request with no `Accept-Language`, or with a language the catalog does not carry, reads exactly the English it read before.
- Discovery's `services.<slot>.message` stays English: it is read by SDKs, codegen and AI clients, and a host-level `/discovery` has no request to read a language from. A pin holds the `501`'s English equal to `serviceUnavailableMessage(slot)` for every slot, so the two still name the same remedy.
- The operator's fault log stays English: the one line a declared capability absence earns per route per process prints the English sentence whatever language the first request asked for.
- zh-CN now says 「定制包」 for the customization package in the three operation sentences that said 「定制软件包」, the term the console uses.

Nothing to migrate.
32 changes: 32 additions & 0 deletions packages/runtime/src/declared-capability-absence-warn-once.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import { describe, it, expect, vi } from 'vitest';
// `sendError` read the same `@objectstack/types` registry.
import { createDispatcherPlugin } from './dispatcher-plugin.js';
import { sendError } from '@objectstack/types';
// [#37864] Paid at collection too: the dispatcher's reach loads `@objectstack/metadata` (check:test-source-alias).
import '@objectstack/metadata';

// [#21061] The analytics domain refuses an anonymous caller first (ADR-0056 D2),
// so every analytics boot below also registers an `auth` slot in the shape
Expand Down Expand Up @@ -349,3 +351,33 @@ describe('#14656 — the wire does not move', () => {
);
});
});

// [#37864] The wire answers in the caller's language; the operator's one line
// does not. Under the once-per-route dedupe, the FIRST request decides what the
// log holds for the life of the process, so the line is the English whatever
// that request asked for: `serviceUnavailableMessage('notification')`, which is
// also the sentence discovery publishes for the slot.
describe('#37864 — a localized 501 still logs its English', () => {
it('a ja-JP first request answers Japanese and leaves the English line', async () => {
const { route, logger } = await boot({ auth: SIGNED_IN_AUTH });

const ja = makeRes();
await route('GET /notifications')({ ...REQ, headers: { 'accept-language': 'ja-JP,ja;q=0.9' } }, ja);
const en = makeRes();
await route('GET /notifications')({ ...REQ }, en);

expect(ja.statusCode).toBe(501);
expect(ja.body.error.code).toBe('NOT_IMPLEMENTED');
expect(ja.body.error.message).not.toBe(en.body.error.message);
expect(ja.body.error.message).toContain('@objectstack/service-messaging');
expect(en.body.error.message).toBe('Install @objectstack/service-messaging to enable');
// `faultLogMessage` is the log's, never the wire's.
expect(JSON.stringify(ja.body)).not.toContain('faultLogMessage');

const warned = lines(logger.warn);
expect(warned, 'two requests, one line').toHaveLength(1);
expect(String(warned[0][0])).toContain('Install @objectstack/service-messaging to enable');
expect(String(warned[0][0])).not.toContain(ja.body.error.message);
expect(lines(logger.error)).toHaveLength(0);
});
});
8 changes: 7 additions & 1 deletion packages/runtime/src/dispatcher-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,17 @@ function sendResultBase(
// exit's, one function up.
if (result.handled && result.response) {
const body = result.response.body as { error?: { code?: unknown; message?: unknown } } | undefined;
// [#37864] An answer whose body is in the caller's language names the
// English its log line prints (`faultLogMessage`): the operator's line
// keeps one language whoever asked first.
const logMessage = typeof result.response.faultLogMessage === 'string'
? result.response.faultLogMessage
: body?.error?.message;
logServerFault(
{
status: result.response.status,
...(typeof body?.error?.code === 'string' ? { code: body.error.code } : {}),
...(typeof body?.error?.message === 'string' ? { message: body.error.message } : {}),
...(typeof logMessage === 'string' ? { message: logMessage } : {}),
request: describeFaultRequest(fault?.req ?? (res as any)?.__obsRequest),
},
fault?.logger,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/domains/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function handleAIRequest(deps: DomainHandlerDeps, subPath: string,
// which is false for a Cloud/Enterprise deployment. The shared table
// says the accurate thing now (REMEDY_DETAIL), so the override is gone
// and this answer matches what discovery reports for the slot.
return capabilityUnavailable(deps, 'ai');
return capabilityUnavailable(deps, context, 'ai');
};

// [#4058] A slot filled by a self-declared non-handler (`handlerReady:
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/domains/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3787,7 +3787,7 @@ async function respondToRecordUpdateStarts(
}
const { object, recordId, changes } = parsed.data;
const svc = automationService as Pick<IAutomationService, 'listRecordUpdateStarts'>;
if (typeof svc.listRecordUpdateStarts !== 'function') return capabilityUnavailable(deps, 'automation');
if (typeof svc.listRecordUpdateStarts !== 'function') return capabilityUnavailable(deps, context, 'automation');
let stored: Record<string, unknown>;
try {
const read = await callData(
Expand Down Expand Up @@ -4144,7 +4144,7 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str
// 501, not the `handled: false` this used to return: `/automation` IS
// mounted, so the dispatcher's ROUTE_NOT_FOUND exit ("No handler matched
// this request") described neither half truthfully. See ./unavailable.ts.
if (!isServiceServeable(automationService)) return capabilityUnavailable(deps, 'automation');
if (!isServiceServeable(automationService)) return capabilityUnavailable(deps, context, 'automation');

// [ADR-0150 D5, epic child G1] THE ADDRESS, judged: an addressed path is
// served when its qualifier names the one holder the bare name resolves
Expand Down
57 changes: 57 additions & 0 deletions packages/runtime/src/domains/catalog-activation-door.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1164,3 +1164,60 @@ describe('[#37811] the no-ledger 501 follows the request\'s language, its noun i
}
});
});

// [#37864] Every type the door accepts names its noun through the catalog, in
// every catalog locale. The type list is read off the door's own shape refusal
// (it enumerates `CatalogActivationType`), so a type added there without a
// `catalog_activation_noun_<type>` key, or without a row here, fails.
describe('[#37864] the no-ledger 501 names every activation type\'s noun in the request\'s language', () => {
const RULE = 'share_red_projects';
const HOOK = 'crm_contact_changed';
const QUEUE = 'support_intake';
const ASSIGN = 'route_new_cases';
const declared = (name: string) => ({ name, packageId: 'crm' });
const TYPES: ReadonlyArray<readonly [string, string, EngineOptions, Record<string, unknown>]> = [
['position', POSITION, {}, {}],
['permission', SET, {}, {}],
['sharing_rule', RULE, {}, { sharingRules: { async declaredRuleNamed(n: string) { return n === RULE ? declared(n) : null; } } }],
['webhook', HOOK, {}, {
declaredWebhooks: {
async declaredWebhookNamed(n: string) { return n === HOOK ? { webhook: { name: n }, active: true, packageId: 'crm' } : null; },
},
}],
['queue', QUEUE, {}, { 'ownership-queue': { async declaredQueueNamed(n: string) { return n === QUEUE ? declared(n) : null; } } }],
['assignment_rule', ASSIGN, { registryItems: { assignment_rule: [{ name: ASSIGN, object: 'crm_case', _packageId: 'crm' }] } }, {}],
];
const LANGS = [
['en', {}],
['ja-JP', { request: { headers: { 'accept-language': 'ja-JP,ja;q=0.9' } } }],
['zh-CN', { request: { headers: { 'accept-language': 'zh-CN' } } }],
['es-ES', { request: { headers: { 'accept-language': 'es-ES' } } }],
] as const;
const fill = (locale: string, key: string, params: Record<string, string> = {}): string =>
BUILTIN_OPERATION_MESSAGES[locale][key].replace(/\{\{(\w+)\}\}/g, (_m, name: string) => params[name] ?? '');

it('the rows here are exactly the types the door accepts', async () => {
const refusal = await flip(boot('single'), TENANT_ADMIN(), '/_activation/no_such_type/x');
expect(statusOf(refusal)).toBe(400);
const accepted = [...String(messageOf(refusal)).matchAll(/`([a-z_]+)`/g)].map((m) => m[1]);
expect(accepted.sort()).toEqual(TYPES.map(([type]) => type).sort());
});

it.each(TYPES)('%s: the catalog defines its noun in every locale, and the door renders it in the request\'s', async (type, name, opts, services) => {
for (const locale of Object.keys(BUILTIN_OPERATION_MESSAGES)) {
expect(BUILTIN_OPERATION_MESSAGES[locale][`catalog_activation_noun_${type}`], `${locale} ${type}`).toBeTruthy();
}
for (const [locale, extra] of LANGS) {
const h = boot('single', { ...opts, omitLedger: true }, services);
const res = await flip(h, { ...TENANT_ADMIN(), ...extra } as HttpProtocolContext, `/_activation/${type}/${name}`, { enabled: false });
expect(statusOf(res), `${locale} ${type}`).toBe(501);
expect(messageOf(res), `${locale} ${type}`).toBe(fill(locale, 'catalog_activation_ledger_missing_off', {
table: METADATA_ACTIVATION_TABLE,
noun: fill(locale, `catalog_activation_noun_${type}`),
name,
}));
expect(vary37811(res.response), `${locale} ${type}`).toBe('Accept-Language');
expect(h.writes).toEqual([]);
}
});
});
Loading
Loading