Repository Public
1// v7 perp live: every refusal code of the signer under a mandate (docs/v6/DERIVATIVE-MANDATE.md §2), every hold code of the live2// executor and every exit code has a French AND an English sentence in the `pl` block of i18n.ts.3import { readFileSync } from 'node:fs';4import { describe, expect, it } from 'vitest';56const read = (rel: string) => readFileSync(new URL(rel, import.meta.url), 'utf8');7const i18n = read('../src/i18n.ts'), screen = read('../src/screens/PerpAgentLive.tsx'), doc = read('../../../docs/v6/DERIVATIVE-MANDATE.md');8const list = (name: string): string[] => { const m = new RegExp(`export const ${name} = \\[([^\\]]*)\\]`).exec(screen); if (!m) throw new Error(`no ${name}`); return [...m[1]!.matchAll(/'([a-z_]+)'/g)].map((x) => x[1]!); };9const pair = (key: string): [string, string] | null => { const m = new RegExp(`\\b${key}: \\[\\s*'((?:[^'\\\\]|\\\\.)+)',\\s*'((?:[^'\\\\]|\\\\.)+)'\\]`).exec(i18n); return m ? [m[1]!, m[2]!] : null; };1011describe('perp live: codes have sentences in both languages', () => {12 it('the screen lists exactly the signer codes of the mandate document', () => {13 const m = /stable code:\s*\n\s*`([^`]+)`/.exec(doc);14 expect(m).not.toBeNull();15 const fromDoc = m![1]!.split(',').map((x) => x.trim()).filter(Boolean);16 expect(fromDoc.length).toBe(33);17 expect(list('SIGNER_CODES').sort()).toEqual([...fromDoc].sort());18 });19 it('every signer, executor and exit code has a French and an English sentence', () => {20 const keys = [...list('SIGNER_CODES').map((c) => `plR_signer_${c}`), ...list('EXECUTOR_CODES').map((c) => `plR_${c}`), ...list('EXIT_CODES').map((c) => `plX_${c}`),21 'plR_signer_other', 'plR_other', 'plX_other', 'plR_withdrawn', 'plR_not_signed', 'plR_rejected', 'plR_rejected_earlier', 'plR_mandate_floor_equity'];22 for (const k of keys) {23 const p = pair(k);24 expect(p, k).not.toBeNull();25 expect(p![0].length, k).toBeGreaterThan(40); expect(p![1].length, k).toBeGreaterThan(40);26 expect(p![0], k).not.toBe(p![1]);27 }28 });29 it('the block is contiguous and delimited', () => {30 const a = i18n.indexOf('// >>> v7 perp live'), b = i18n.indexOf('// <<< v7 perp live');31 expect(a).toBeGreaterThan(0); expect(b).toBeGreaterThan(a);32 const outside = i18n.slice(0, a) + i18n.slice(b);33 expect(/^\s*pl[A-Z][A-Za-z_0-9]*: \[/m.test(outside)).toBe(false);34 });35});36