'use strict'; const test=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path'),vm=require('node:vm'); const D=require('../domain/model.js'); const root=path.resolve(__dirname,'..'); function readModel(){const context={window:{},GlemoResale:D,Intl};vm.createContext(context);vm.runInContext(fs.readFileSync(path.join(root,'public/view.js'),'utf8'),context);return context.window.GlemoPilot;} test('frontend input normalization preserves explicit decimal meaning and never strips grouping',()=>{ const view=readModel(); for(const [lang,value,expected]of [['pt','105,50','105.50'],['es','105,50','105.50'],['fr','105,50','105.50'],['ar','١٠٥٫٥٠','105.50'],['en','105.50','105.50'],['zh','105.50','105.50'],['pt','105.50','105.50']])assert.equal(view.normalizeDecimal(value,lang),expected); for(const [lang,value]of [['pt','1.000,00'],['en','1,000.00'],['fr','1 000,00'],['ar','١٬٠٠٠٫٠٠']])assert.throws(()=>D.cents(view.normalizeDecimal(value,lang))); }); test('all six UI languages have every shared and inherited runtime key',()=>{ const context={window:{},Intl};vm.createContext(context); for(const name of ['copy-base.js','copy-pilot.js','copy-shared.js'])vm.runInContext(fs.readFileSync(path.join(root,'public',name),'utf8'),context); for(const lang of ['en','pt','es','fr','ar','zh'])for(const key of [...context.window.PilotCopyKeys,...context.window.SharedCopyKeys])assert.equal(typeof context.window.PilotCopy[lang][key],'string',lang+':'+key); assert.match(context.window.PilotCopy.en.disclaimer,/Separate accounts/); }); test('financial formatting preserves cents for aggregate strings and fractional negative amounts',()=>{ const view=readModel();assert.equal(view.formatMoney('9007199254740993','en'),'$90,071,992,547,409.93');assert.equal(view.formatMoney(50,'en'),'$0.50');assert.equal(view.formatMoney(-50,'en'),'-$0.50');assert.equal(view.formatMoney(2600000,'en'),'$26,000');assert.throws(()=>view.formatMoney(Number.MAX_SAFE_INTEGER+1,'en'));assert.throws(()=>view.formatMoney(null,'en')); }); test('public files do not include credential or database artifacts',()=>{ function walk(dir){for(const e of fs.readdirSync(dir,{withFileTypes:true})){const p=path.join(dir,e.name);if(e.isDirectory())walk(p);else assert(!/\.sqlite|\.env$|server\.log|server\.lock|launch\.json/.test(e.name),p);}} walk(path.join(root,'public')); });