Fix test gateway Windows config paths
### 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.
This commit is contained in:
@@ -25,6 +25,16 @@ function composeArgs(projectName, args) {
|
||||
return ["compose", "-p", projectName, ...args];
|
||||
}
|
||||
|
||||
function usesWindowsPathSyntax(filePath) {
|
||||
return /^[A-Za-z]:($|[\\/])/.test(filePath) || filePath.startsWith("\\\\") || filePath.includes("\\");
|
||||
}
|
||||
|
||||
function pathForInputs(...filePaths) {
|
||||
const hasWindowsPath = filePaths.some((filePath) => usesWindowsPathSyntax(String(filePath || "")));
|
||||
|
||||
return hasWindowsPath ? path.win32 : path;
|
||||
}
|
||||
|
||||
async function resolveRootDir(scriptPath) {
|
||||
const cwd = process.cwd();
|
||||
|
||||
@@ -66,21 +76,13 @@ export function resolveComposeProjectName(rootDir, env = process.env) {
|
||||
return explicit;
|
||||
}
|
||||
|
||||
return path.basename(rootDir);
|
||||
return pathForInputs(rootDir).basename(rootDir);
|
||||
}
|
||||
|
||||
export function resolveComposeNetworkName(rootDir, env = process.env) {
|
||||
return `${resolveComposeProjectName(rootDir, env)}_default`;
|
||||
}
|
||||
|
||||
function usesWindowsPathSyntax(filePath) {
|
||||
return /^[A-Za-z]:[\\/]/.test(filePath) || filePath.startsWith("\\\\");
|
||||
}
|
||||
|
||||
function pathForInputs(...filePaths) {
|
||||
return filePaths.some((filePath) => usesWindowsPathSyntax(String(filePath || ""))) ? path.win32 : path;
|
||||
}
|
||||
|
||||
export function resolveConfigDirectory(rootDir, explicitDir = null) {
|
||||
const pathModule = pathForInputs(rootDir, explicitDir);
|
||||
|
||||
|
||||
@@ -25,6 +25,10 @@ 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" }),
|
||||
@@ -39,6 +43,20 @@ test("resolveConfigDirectory uses the default temp folder when none is provided"
|
||||
);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user