diff --git a/uploads-route.test.js b/uploads-route.test.js index 7d30b0e..7fbee51 100644 --- a/uploads-route.test.js +++ b/uploads-route.test.js @@ -6,6 +6,7 @@ const test = require("node:test"); const assert = require("node:assert/strict"); const fs = require("node:fs"); const path = require("node:path"); +const os = require("node:os"); const { spawn } = require("node:child_process"); const http = require("node:http"); @@ -37,9 +38,22 @@ function waitForServer(url, timeoutMs = 10000) { } let child; +let cwd; test.before(async () => { + // server.js resolves uploads/ relative to its own __dirname, not PORT — + // a past version of this test spawned server.js with cwd: __dirname + // (the real repo) and then rm -rf'd the whole uploads/ directory in + // test.after as "cleanup", which wiped real uploaded content on every + // `node --test` run. Spawn from an isolated tmpdir copy instead, same + // pattern as dressup-generate.test.js / dance-channel.test.js, so this + // test can never touch the real repo's uploads/. + cwd = fs.mkdtempSync(path.join(os.tmpdir(), "uploads-route-test-")); + for (const f of ["server.js", "ingest.js", "uploads.js", "store.js", "dressup-store.js", "prompt-template.js"]) { + fs.copyFileSync(path.join(__dirname, f), path.join(cwd, f)); + } + child = spawn(process.execPath, ["server.js"], { - cwd: __dirname, + cwd, // H3_CONSOLE_BASE cleared: this test only exercises the upload route, // no need for the spawned copy to also hit the real H3 Console / // race the live pm2 instance on library.json's periodic sync. @@ -58,10 +72,7 @@ test.before(async () => { test.after(() => { child.kill(); - // uploads/ written by this test run lands under the real repo path - // (server.js resolves it relative to __dirname, not PORT) — clean it up. - const dir = path.join(__dirname, "uploads"); - fs.rmSync(dir, { recursive: true, force: true }); + fs.rmSync(cwd, { recursive: true, force: true }); }); test("uploading a real mp4 via /api/admin/upload-video returns a URL that GET /uploads/* serves back as video/mp4", async () => {