import assert from 'node:assert/strict'; import {readFile} from 'node:fs/promises'; import vm from 'node:vm'; import test from 'node:test'; import {transformSync} from 'esbuild'; const source = await readFile(new URL('../service/server/update/plugins.ts', import.meta.url), 'utf8'); const code = transformSync(source.replace(/^import .*;\n/gm, '') .replace('export async function', 'async function'), {loader: 'ts'}).code; test('late plugin scan never reports through a replacement authenticated session', async () => { let finish_scan; let current = true; const reports = []; const socket = {connected: true, timeout() { return this; }, async emitWithAck(...args) { reports.push(args); return {status: 'success', data: 0}; }}; const context = {socket, is_current: () => current, get_plugin_list: () => new Promise(resolve => { finish_scan = resolve; }), console_print: {log() {}, success() {}}}; const task = vm.runInNewContext(`${code}\nupdate_plugins(socket, 1, is_current);`, context); current = false; finish_scan([]); await task; assert.equal(reports.length, 0); });