### Motivation - Tests that resolve the test gateway config directory were failing on Windows-style paths because the code always used the POSIX `path` module, producing mismatched separators. - Preserve Windows path semantics when `rootDir` or an explicit config path uses Windows syntax while leaving POSIX behavior unchanged. ### Description - Add `usesWindowsPathSyntax` and `pathForInputs` helpers to detect Windows-style paths and select `path.win32` when needed. - Use the selected `pathModule` in `resolveConfigDirectory` to call `resolve`/`join` so Windows roots or explicit Windows dirs keep correct separators. - Change is confined to `scripts/test-gateway.mjs` and does not alter other runtime behavior. ### Testing - Ran `node --test scripts/*.test.mjs` which initially showed one failing path test and after the fix completed with all tests passing (`14` passed, `0` failed). - Ran `npm test` in `services/edge-agent` and `services/edge-broker`, both suites passed (`18` and `23` tests respectively). - Ran `node scripts/sync-ai-workflow.mjs --check` and `git diff --check` which both succeeded.
116 lines
3.9 KiB
JavaScript
116 lines
3.9 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
DEFAULT_CONTAINER_NAME,
|
|
DEFAULT_CONTAINER_API_URL,
|
|
DEFAULT_CONTAINER_BROKER_URL,
|
|
DEFAULT_HEARTBEAT_INTERVAL_SECONDS,
|
|
buildGatewayConfig,
|
|
parseArgs,
|
|
resolveComposeNetworkName,
|
|
resolveComposeProjectName,
|
|
resolveConfigDirectory,
|
|
shouldClaimGateway,
|
|
} from "./test-gateway.mjs";
|
|
|
|
test("resolveComposeProjectName prefers COMPOSE_PROJECT_NAME", () => {
|
|
assert.equal(
|
|
resolveComposeProjectName("C:/Users/test/backend-php", { COMPOSE_PROJECT_NAME: "custom-stack" }),
|
|
"custom-stack"
|
|
);
|
|
});
|
|
|
|
test("resolveComposeProjectName falls back to backend directory name", () => {
|
|
assert.equal(resolveComposeProjectName("C:/Users/test/backend-php", {}), "backend-php");
|
|
});
|
|
|
|
test("resolveComposeProjectName supports Windows backslash paths", () => {
|
|
assert.equal(resolveComposeProjectName("C:\\Users\\test\\backend-php", {}), "backend-php");
|
|
});
|
|
|
|
test("resolveComposeNetworkName derives the default compose network", () => {
|
|
assert.equal(
|
|
resolveComposeNetworkName("C:/Users/test/backend-php", { COMPOSE_PROJECT_NAME: "custom-stack" }),
|
|
"custom-stack_default"
|
|
);
|
|
});
|
|
|
|
test("resolveConfigDirectory uses the default temp folder when none is provided", () => {
|
|
assert.equal(
|
|
resolveConfigDirectory("C:/Users/test/backend-php"),
|
|
"C:\\Users\\test\\backend-php\\.tmp\\test-gateway"
|
|
);
|
|
});
|
|
|
|
test("resolveConfigDirectory supports Windows backslash paths", () => {
|
|
assert.equal(
|
|
resolveConfigDirectory("C:\\Users\\test\\backend-php"),
|
|
"C:\\Users\\test\\backend-php\\.tmp\\test-gateway"
|
|
);
|
|
});
|
|
|
|
test("resolveConfigDirectory supports explicit Windows absolute paths", () => {
|
|
assert.equal(
|
|
resolveConfigDirectory("/workspace/api", "C:\\Users\\test\\gateway-config"),
|
|
"C:\\Users\\test\\gateway-config"
|
|
);
|
|
});
|
|
|
|
test("shouldClaimGateway requires a token when no credentials are present", () => {
|
|
assert.equal(shouldClaimGateway({}, ""), true);
|
|
assert.equal(shouldClaimGateway({ gatewayId: 12, agentToken: "secret" }, ""), false);
|
|
assert.equal(shouldClaimGateway({ gatewayId: 12, agentToken: "secret" }, "fresh-token"), true);
|
|
});
|
|
|
|
test("parseArgs accepts help without an explicit action", () => {
|
|
const options = parseArgs(["--help"]);
|
|
|
|
assert.equal(options.action, "start");
|
|
assert.equal(options.help, true);
|
|
});
|
|
|
|
test("parseArgs accepts copy config mode", () => {
|
|
const options = parseArgs(["start", "--copy-config"]);
|
|
|
|
assert.equal(options.copyConfig, true);
|
|
});
|
|
|
|
test("buildGatewayConfig applies defaults for a dockerized gateway", () => {
|
|
const config = buildGatewayConfig({});
|
|
|
|
assert.equal(config.apiUrl, DEFAULT_CONTAINER_API_URL);
|
|
assert.equal(config.brokerUrl, DEFAULT_CONTAINER_BROKER_URL);
|
|
assert.equal(config.hostname, DEFAULT_CONTAINER_NAME);
|
|
assert.equal(config.restartMode, "spawn");
|
|
assert.equal(config.heartbeatIntervalSeconds, DEFAULT_HEARTBEAT_INTERVAL_SECONDS);
|
|
assert.equal(config.installDir, "/opt/truckwash-edge-agent");
|
|
assert.equal(config.agentPath, "/opt/truckwash-edge-agent/agent.php");
|
|
assert.equal(config.serviceUnitPath, "/opt/truckwash-edge-agent/truckwash-edge-agent.service");
|
|
assert.equal(config.serviceName, DEFAULT_CONTAINER_NAME);
|
|
});
|
|
|
|
test("buildGatewayConfig folds claim response into the generated config", () => {
|
|
const config = buildGatewayConfig({
|
|
existingConfig: {
|
|
installedVersion: "0.9.0",
|
|
targetVersion: "0.9.1",
|
|
},
|
|
hostname: "gw-docker-1",
|
|
claim: {
|
|
gateway: { id: 44 },
|
|
agent_token: "agent-secret",
|
|
release_channel: "stable",
|
|
},
|
|
heartbeatIntervalSeconds: 7,
|
|
});
|
|
|
|
assert.equal(config.gatewayId, 44);
|
|
assert.equal(config.agentToken, "agent-secret");
|
|
assert.equal(config.releaseChannel, "stable");
|
|
assert.equal(config.hostname, "gw-docker-1");
|
|
assert.equal(config.installedVersion, "0.9.0");
|
|
assert.equal(config.targetVersion, "0.9.1");
|
|
assert.equal(config.heartbeatIntervalSeconds, 7);
|
|
});
|