import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import vm from 'node:vm'; import { test } from 'node:test'; const scope = vm.createContext({ TextDecoder, Uint8Array }); vm.runInContext(readFileSync(new URL('../cloud/functions/fmode-file-read.js', import.meta.url), 'utf8'), scope); test('keeps UTF-8 text readable', () => { const bytes = new TextEncoder().encode('转录日志'); assert.equal(scope._decodeText(bytes.buffer), '转录日志'); }); test('falls back to GB18030 for legacy Chinese text', () => { const bytes = Uint8Array.from([0xcc, 0xec, 0xc6, 0xf8]); // 天气 in GB18030 assert.equal(scope._decodeText(bytes.buffer), '天气'); }); test('rejects bytes that cannot be decoded as supported text', () => { assert.equal(scope._decodeText(Uint8Array.from([0x81]).buffer), null); });