const test = require('node:test'); const assert = require('node:assert/strict'); const { EventEmitter } = require('node:events'); const { PassThrough } = require('node:stream'); const vm = require('node:vm'); const fs = require('node:fs'); const path = require('node:path'); test('unsolicited legacy drag messages cannot activate the radial menu', async () => { const child = new EventEmitter(); child.stdin = new PassThrough(); child.stdout = new PassThrough(); child.stderr = new PassThrough(); const module = { exports: {} }; vm.runInNewContext(fs.readFileSync(path.join(__dirname, '../src/main/windows.cjs'), 'utf8'), { module, setTimeout, clearTimeout, require: name => name === 'node:child_process' ? { spawn: () => child } : require(name), }); const bridge = new module.exports.WindowsBridge('C:/FileBow'); let activations = 0; // Old helpers may still emit these events; the bridge must ignore them. bridge.onDrag = () => { activations++; }; child.stdout.write('{"type":"ready"}\n'); await bridge.ready; for (const phase of ['start', 'drop', 'shortcut', 'end']) { child.stdout.write(JSON.stringify({ type: 'drag', phase, files: ['C:/selected.png'], x: 500, y: 500 }) + '\n'); } assert.equal(activations, 0); // Explicit requests, used by the real keyboard shortcuts, still work. const selection = bridge.getExplorerSelection(); await new Promise(resolve => setImmediate(resolve)); const request = JSON.parse(child.stdin.read().toString()); assert.equal(request.command, 'selection'); child.stdout.write(JSON.stringify({ id: request.id, result: ['C:/selected.png'] }) + '\n'); assert.equal((await selection)[0], 'C:/selected.png'); bridge.close(); });