Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
@@ -0,0 +1,86 @@
|
||||
"use strict";
|
||||
|
||||
// Regression tests for the node-proxy create asyncSetup fix (round 4).
|
||||
//
|
||||
// The admin node-proxy create relay (POST /api/nodes/:id/servers/create,
|
||||
// nodes.js nodeProxyCreateHandler) must forward the daemon's asyncSetup flag
|
||||
// exactly like the main create flow (POST /api/servers/create, index.js).
|
||||
// Without asyncSetup the daemon takes the SYNCHRONOUS setup path in
|
||||
// handleCreateServer — inline jar resolution, a 30-minute-context jar download,
|
||||
// a synchronous archive extract and the container start all precede the first
|
||||
// response byte — so a create that outlives the relay's LONG_NODE_TIMEOUT_MS
|
||||
// (120s) completes daemon-side while the admin's relay reports a failure and a
|
||||
// retry collides with the finished create ("server already exists"). With it
|
||||
// the daemon responds after its synchronous prepare phase and runs the rest of
|
||||
// the setup in the background; nodeProxyCreateHandler's serverEntry commit and
|
||||
// forwarded response already carry the async shape (status "installing",
|
||||
// setupStatus), mirroring index.js's main-flow handling.
|
||||
//
|
||||
// index.js cannot be required in-process (it boots servers on require), so —
|
||||
// same technique as node-relay-timeout-parity.test.js — these are source-level
|
||||
// assertions pinning the payload field on BOTH create flows.
|
||||
//
|
||||
// Wave 1 Step 1 of the server-create consolidation moved the main flow's
|
||||
// payload construction out of the index.js route body into the shared service
|
||||
// (services/server-create.js); the third assertion below follows it there so
|
||||
// the same invariant — the panel flow's asyncSetup flag sits inside its
|
||||
// /v1/servers/create payload construction — stays pinned at its new home.
|
||||
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const ROOT = path.join(__dirname, "..");
|
||||
const NODES_JS = path.join(ROOT, "nodes.js");
|
||||
const SERVICE_JS = path.join(ROOT, "services", "server-create.js");
|
||||
|
||||
// Strip full-line comments so prose mentioning "asyncSetup" cannot satisfy the
|
||||
// assertions.
|
||||
function stripFullLineComments(src) {
|
||||
return src
|
||||
.split("\n")
|
||||
.filter((line) => !/^\s*\/\//.test(line))
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
const nodesSrc = stripFullLineComments(fs.readFileSync(NODES_JS, "utf8"));
|
||||
const serviceSrc = stripFullLineComments(fs.readFileSync(SERVICE_JS, "utf8"));
|
||||
|
||||
test("nodes.js admin node-proxy create relay forwards asyncSetup: true", () => {
|
||||
const at = nodesSrc.indexOf('"/v1/servers/create", "POST"');
|
||||
assert.notStrictEqual(at, -1, "expected the admin create relay's daemon call in nodes.js");
|
||||
const window = nodesSrc.slice(at, at + 600);
|
||||
assert.match(
|
||||
window,
|
||||
/asyncSetup:\s*true/,
|
||||
"the admin create relay must forward asyncSetup: true like the main create flow — without it the daemon runs the whole setup inline before its first response byte and the 120s relay reports a failure for a create that completed"
|
||||
);
|
||||
});
|
||||
|
||||
test("nodes.js admin create relay handles the async response shape", () => {
|
||||
// The relay's serverEntry commit must keep deriving status/setupStatus from
|
||||
// the daemon's asyncSetup response (parity with index.js's main-flow
|
||||
// handling); dropping the branch would commit "installing" rows as undefined.
|
||||
const at = nodesSrc.indexOf("const setupStatusRaw = json && json.meta");
|
||||
assert.notStrictEqual(at, -1, "expected the async setup-status extraction in nodes.js");
|
||||
const window = nodesSrc.slice(at, at + 1400);
|
||||
assert.match(
|
||||
window,
|
||||
/json\.asyncSetup/,
|
||||
"the admin create relay must keep keying the committed row's status off the daemon's asyncSetup response"
|
||||
);
|
||||
});
|
||||
|
||||
test("panel main create flow keeps asyncSetup: true in its daemon payload (services/server-create.js)", () => {
|
||||
// The payload moved from the index.js route body into the shared service in
|
||||
// the server-create consolidation; the invariant is unchanged.
|
||||
const at = serviceSrc.indexOf("asyncSetup: true");
|
||||
assert.notStrictEqual(at, -1, "expected the main create flow's asyncSetup flag in services/server-create.js");
|
||||
const window = serviceSrc.slice(Math.max(0, at - 600), at);
|
||||
assert.match(
|
||||
window,
|
||||
/const payload = \{/,
|
||||
"the main flow's asyncSetup flag must stay inside the /v1/servers/create payload construction — both create flows request async setup together"
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user