okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
52ba0b781
main
1/** Chat card wording: no "Demo" labels, "Ran" for a tool nobody was asked about, "Approved" only when someone approved. */ 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { readFileSync } from 'node:fs' ; 5import { resolve } from 'node:path' ; 6 7const root = resolve ( import . meta. dirname , '..' ); 8const languages = [ 'en' , 'de' , 'es' , 'fr' , 'ja' , 'ko' , 'pt' , 'ru' , 'zh' ]; 9const catalog = Object . fromEntries ( languages . map ( l => [ l , JSON . parse ( readFileSync ( resolve ( root , 'src/locales' , ` ${ l } .json` ), 'utf8' ))])); 10const idOf = text => Object . entries ( catalog . en ). find (([, v ]) => v === text )?.[ 0 ]; 11 12test ( 'no catalog string, in any language, calls anything a demo' , () => { 13const word = / demo | デモ | 데모 | Демо | Демонстр | 演示 | demonstr | demostr / i ; 14for ( const l of languages ) { 15const hits = Object . entries ( catalog [ l ]). filter (([ k , v ]) => word . test ( v ) && ! /^s0171$ / . test ( k )); 16assert . deepEqual ( hits , [], ` ${ l } : ${ JSON . stringify ( hits )} ` ); 17} 18}); 19 20test ( 'the approval and result texts of a chat card exist in every language, translated' , () => { 21for ( const text of [ 'Needs your approval' , 'Denied. Nothing ran.' , 'Approval recorded. Nothing was executed.' , 'Ran' , 'Not allowed in this mode. Nothing ran.' ]) { 22const id = idOf ( text ); 23assert . ok ( id , ` ${ text } has a catalog id` ); 24for ( const l of languages . filter ( l => l !== 'en' )) assert . notEqual ( catalog [ l ][ id ], text , ` ${ l } translates " ${ text } "` ); 25} 26}); 27 28test ( 'the card shows "Ran" unless the person approved, and never "Demo approval"' , () => { 29const chat = readFileSync ( resolve ( root , 'src/screens/Chat.tsx' ), 'utf8' ); 30assert . ok ( ! /Demo approval / i . test ( chat )); 31assert . match ( chat , / t\.live && t\.state === 'done' && t\.approved \? 'Approved' : 'Done' / ); 32const store = readFileSync ( resolve ( root , 'src/lib/store.ts' ), 'utf8' ); 33assert . ok ( ! /Demo approval / i . test ( store )); 34assert . match ( store , / mode:state\.sessions\.find\(s=>s\.id===sessionId\)\?\.preferences\?\.mode\?\?'manual' / , 'the Mode menu choice travels with the turn' ); 35}); 36 37test ( 'every language has the same keys' , () => { 38const keys = Object . keys ( catalog . en ). sort (); 39for ( const l of languages ) assert . deepEqual ( Object . keys ( catalog [ l ]). sort (), keys , l ); 40});