|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | +// |
| 3 | +// Bundle-ownership guard (#2834 ⑤ / ADR-0029 D8): this package's generated |
| 4 | +// object-translation bundles must carry ONLY objects this package's extract |
| 5 | +// config actually imports. When an object moves to another package (audit, |
| 6 | +// realtime, …), its translations move to that package's own bundles — a |
| 7 | +// leftover copy here silently DIES on the next `os i18n extract` run, taking |
| 8 | +// curated translations with it (the sys_audit_log incident). This test turns |
| 9 | +// that silent loss into a red build: an object present in the bundle but not |
| 10 | +// in the ownership list below means either (a) the extract config gained an |
| 11 | +// object — add it here — or (b) a moved object's keys were left behind — |
| 12 | +// migrate them to the owning package's bundles, then regenerate. |
| 13 | + |
| 14 | +import { describe, it, expect } from 'vitest'; |
| 15 | +import { enObjects } from './en.objects.generated.js'; |
| 16 | + |
| 17 | +// Objects the extract config (scripts/i18n-extract.config.ts) imports — |
| 18 | +// keep the two lists in sync when adding/moving platform objects. |
| 19 | +const OWNED_OBJECTS = new Set([ |
| 20 | + // identity |
| 21 | + 'sys_user', 'sys_session', 'sys_account', 'sys_verification', 'sys_organization', |
| 22 | + 'sys_member', 'sys_invitation', 'sys_team', 'sys_team_member', 'sys_business_unit', |
| 23 | + 'sys_business_unit_member', 'sys_api_key', 'sys_two_factor', 'sys_device_code', |
| 24 | + 'sys_user_preference', 'sys_oauth_application', 'sys_oauth_access_token', |
| 25 | + 'sys_oauth_refresh_token', 'sys_oauth_consent', 'sys_jwks', |
| 26 | + // audit / messaging-adjacent (still owned here) |
| 27 | + 'sys_notification', 'sys_attachment', 'sys_email', 'sys_email_template', |
| 28 | + 'sys_saved_report', 'sys_report_schedule', 'sys_job', 'sys_job_run', 'sys_job_queue', |
| 29 | + // metadata |
| 30 | + 'sys_metadata', 'sys_metadata_history', 'sys_view_definition', 'sys_metadata_audit', |
| 31 | + // system |
| 32 | + 'sys_setting', 'sys_secret', 'sys_setting_audit', |
| 33 | +]); |
| 34 | + |
| 35 | +describe('objects translation bundle ownership (ADR-0029 D8)', () => { |
| 36 | + it('the en bundle contains no objects owned by other packages', () => { |
| 37 | + const strays = Object.keys(enObjects).filter((o) => !OWNED_OBJECTS.has(o)); |
| 38 | + expect( |
| 39 | + strays, |
| 40 | + `bundle carries objects this package's extract config does not own: ${strays.join(', ')} — ` + |
| 41 | + 'their curated translations would be silently deleted on the next `os i18n extract`. ' + |
| 42 | + 'Migrate them to the owning package (cf. plugin-audit / service-realtime translations) or add them to the extract config + this list.', |
| 43 | + ).toEqual([]); |
| 44 | + }); |
| 45 | + |
| 46 | + it('every owned object is present in the bundle (extract config regression)', () => { |
| 47 | + const missing = [...OWNED_OBJECTS].filter((o) => !(o in enObjects)); |
| 48 | + expect( |
| 49 | + missing, |
| 50 | + `objects the extract config should emit are missing from the bundle: ${missing.join(', ')} — was an import dropped from scripts/i18n-extract.config.ts?`, |
| 51 | + ).toEqual([]); |
| 52 | + }); |
| 53 | +}); |
0 commit comments