const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const test = require('node:test'); const source = fs.readFileSync(path.join(__dirname, '..', 'client', 'local-ai.js'), 'utf8'); test('local AI runtime rejects assets outside the same-origin static service', () => { assert.match(source, /parsed\.origin !== location\.origin/); assert.match(source, /parsed\.pathname\.startsWith\('\/static\/'\)/); assert.match(source, /\/static\/wllama-gemma3-v1\//); assert.doesNotMatch(source, /huggingface\.co|registry\.npmjs\.org/); }); test('local assistance includes preflight, bounded continuity, and unsaved offline guidance', () => { assert.match(source, /async function assist\(/); assert.match(source, /async function offline\(/); assert.match(source, /slice\(-12\)/); assert.match(source, /Lokalt, osparat förslag/); }); test('local diagnostics are opt-in, stored in IndexedDB, exportable, and deletable', () => { assert.match(source, /ai-spel-local-ai-logs/); assert.match(source, /indexedDB\.open/); assert.match(source, /lokal ai exportera loggar/); assert.match(source, /lokal ai radera loggar/); assert.match(source, /30 \* 24 \* 60 \* 60 \* 1000/); }); test('Gemma model use is blocked until per-account acceptance of the exact terms revision', () => { assert.match(source, /async function start\(currentAccountId\)/); assert.match(source, /localStorage\.getItem\(key\) !== manifest\.license\.acceptance_id/); assert.match(source, /lokal ai godkänn villkor/); assert.match(source, /lokal ai avvisa villkor/); assert.match(source, /rättslig behörighet att ingå avtalet/); assert.match(source, /termsPresentedForAccount !== accountId/); assert.match(source, /localStorage\.setItem\(acceptanceKey\(manifest\), manifest\.license\.acceptance_id\)/); assert.match(source, /async function assist\([\s\S]*?!await isAccepted\(\)/); assert.match(source, /async function offline\([\s\S]*?!await isAccepted\(\)/); assert.match(source, /function stop\(\)/); });