import test from 'node:test'; import assert from 'node:assert/strict'; import { createServer } from 'node:http'; import { mkdtempSync,rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { bindTesterSocket, testerSocketPath, TESTER_ORIGIN } from '../../webui/src/tester-socket.mjs'; import { testerRequest } from '../src/tester-http.mjs'; test('tester HTTP helper uses instance socket, logical origin and JSON without retrying',async t=>{ const root=mkdtempSync(join(tmpdir(),'g196-h-'));let hits=0; const server=await bindTesterSocket(createServer((q,r)=>{hits++;assert.equal(q.headers.host,new URL(TESTER_ORIGIN).host);assert.equal(q.headers.origin,TESTER_ORIGIN);r.setHeader('content-type','application/json');r.end('{"ok":true}');}),testerSocketPath(root)); t.after(async()=>{await new Promise(r=>server.close(r));rmSync(root,{recursive:true,force:true});}); assert.equal((await testerRequest({dataRoot:root,path:'/fixture',method:'POST',body:{x:1}})).body.ok,true); assert.equal(hits,1); for(const path of ['//remote','bad','/a\n'])await assert.rejects(testerRequest({dataRoot:root,path}),/tester-http-path/); await assert.rejects(testerRequest({dataRoot:root,body:{x:'x'.repeat(16385)}}),/tester-http-size/); }); test('tester HTTP timeout closes the socket and does not retry',async t=>{ const root=mkdtempSync(join(tmpdir(),'g196-h-'));let hits=0; const server=await bindTesterSocket(createServer(()=>{hits++;}),testerSocketPath(root)); t.after(async()=>{server.closeAllConnections();await new Promise(r=>server.close(r));rmSync(root,{recursive:true,force:true});}); await assert.rejects(testerRequest({dataRoot:root,timeout:20}),/tester-http-timeout/); assert.equal(hits,1); });