From 77f3963d8338b4c2b742945cbf70dc2d1920ee12 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 22 Oct 2026 00:49:27 +0200 Subject: [PATCH] Test that the gitea bundle's import resolves while its binds are refused (issue 1793) --- modules/gitea/test/bundle-import.test.ts | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 modules/gitea/test/bundle-import.test.ts diff --git a/modules/gitea/test/bundle-import.test.ts b/modules/gitea/test/bundle-import.test.ts new file mode 100644 index 00000000..d7b24e35 --- /dev/null +++ b/modules/gitea/test/bundle-import.test.ts @@ -0,0 +1,38 @@ +// **The bundle's import ends while a bind is refused** (novox/hq issue 1793). The launcher imports index.js and then answers +// node-tools' handshake, which has 10 s before the bundle is killed and never started again. A bind awaited at the top +// of index.ts, refused for longer, ended the bundle at 00:28:37 on 2026-10-22. Run in a child: the polls' timers keep a +// process alive, and the child says "imported" and exits as soon as the import resolves. + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { spawn } from "node:child_process"; +import { dirname, join } from "node:path"; +import { fileURLToPath, pathToFileURL } from "node:url"; + +const here = dirname(fileURLToPath(import.meta.url)); + +test("importing the bundle resolves while the broker keeps refusing the binds", async () => { + const index = pathToFileURL(join(here, "..", "dist", "index.js")).href; + const script = ` + const { useBroker } = await import("@novox/mesh-sdk/messaging"); + useBroker(() => ({ + subscribe: async () => { throw new Error("binding gitea's consumer novox_gitea: nats: no responders available for request"); }, + publish: async () => {}, request: async () => { throw new Error("no responders"); }, + handle: async () => () => {}, close: async () => {}, + })); + await import(${JSON.stringify(index)}); + console.log("imported"); + process.exit(0);`; + const env = { ...process.env, MESH_GITEA_TOKEN: "x", MESH_GITEA_URL: "http://127.0.0.1:1" }; + for (const k of ["MESH_GITEA_STATE_DIR", "MESH_GITEA_ADMIN_USER", "MESH_GITEA_ADMIN_PASSWORD", "MESH_SERVED_MODULE"]) delete env[k]; + const child = spawn(process.execPath, ["--input-type=module", "-e", script], { cwd: join(here, ".."), env, stdio: ["ignore", "pipe", "pipe"] }); + let out = ""; + let err = ""; + child.stdout.on("data", (d) => (out += d)); + child.stderr.on("data", (d) => (err += d)); + const ended = new Promise((r) => child.on("exit", () => r())); + const timer = setTimeout(() => child.kill("SIGKILL"), 3000); + await ended; + clearTimeout(timer); + assert.match(out, /imported/, `the import did not resolve within 3 s while a bind was refused; stderr: ${err.slice(0, 600)}`); +});