fix: stabilize gateway config tests + tool schema
This commit is contained in:
@@ -119,7 +119,7 @@ export const agentHandlers: GatewayRequestHandlers = {
|
||||
undefined,
|
||||
errorShape(
|
||||
ErrorCodes.INVALID_REQUEST,
|
||||
`invalid agent params: unknown channel: ${normalized}`,
|
||||
`invalid agent params: unknown channel: ${String(normalized)}`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { connectOk, installGatewayTestHooks, onceMessage, startServerWithClient } from "./test-helpers.js";
|
||||
import {
|
||||
connectOk,
|
||||
installGatewayTestHooks,
|
||||
onceMessage,
|
||||
startServerWithClient,
|
||||
} from "./test-helpers.js";
|
||||
|
||||
installGatewayTestHooks();
|
||||
|
||||
|
||||
@@ -68,6 +68,17 @@ const hoisted = vi.hoisted(() => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const testConfigRoot = {
|
||||
value: path.join(
|
||||
os.tmpdir(),
|
||||
`clawdbot-gateway-test-${process.pid}-${crypto.randomUUID()}`,
|
||||
),
|
||||
};
|
||||
|
||||
export const setTestConfigRoot = (root: string) => {
|
||||
testConfigRoot.value = root;
|
||||
};
|
||||
|
||||
export const bridgeStartCalls = hoisted.bridgeStartCalls;
|
||||
export const bridgeInvoke = hoisted.bridgeInvoke;
|
||||
export const bridgeListConnected = hoisted.bridgeListConnected;
|
||||
@@ -157,7 +168,7 @@ vi.mock("../config/sessions.js", async () => {
|
||||
|
||||
vi.mock("../config/config.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../config/config.js")>("../config/config.js");
|
||||
const resolveConfigPath = () => path.join(os.homedir(), ".clawdbot", "clawdbot.json");
|
||||
const resolveConfigPath = () => path.join(testConfigRoot.value, "clawdbot.json");
|
||||
const hashConfigRaw = (raw: string | null) =>
|
||||
crypto.createHash("sha256").update(raw ?? "").digest("hex");
|
||||
|
||||
@@ -233,8 +244,12 @@ vi.mock("../config/config.js", async () => {
|
||||
|
||||
return {
|
||||
...actual,
|
||||
CONFIG_PATH_CLAWDBOT: resolveConfigPath(),
|
||||
STATE_DIR_CLAWDBOT: path.dirname(resolveConfigPath()),
|
||||
get CONFIG_PATH_CLAWDBOT() {
|
||||
return resolveConfigPath();
|
||||
},
|
||||
get STATE_DIR_CLAWDBOT() {
|
||||
return path.dirname(resolveConfigPath());
|
||||
},
|
||||
get isNixMode() {
|
||||
return testIsNixMode.value;
|
||||
},
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
embeddedRunMock,
|
||||
piSdkMock,
|
||||
sessionStoreSaveDelayMs,
|
||||
setTestConfigRoot,
|
||||
testIsNixMode,
|
||||
testState,
|
||||
testTailnetIPv4,
|
||||
@@ -28,6 +29,7 @@ import {
|
||||
|
||||
let previousHome: string | undefined;
|
||||
let tempHome: string | undefined;
|
||||
let tempConfigRoot: string | undefined;
|
||||
|
||||
export function installGatewayTestHooks() {
|
||||
beforeEach(async () => {
|
||||
@@ -35,6 +37,8 @@ export function installGatewayTestHooks() {
|
||||
previousHome = process.env.HOME;
|
||||
tempHome = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-gateway-home-"));
|
||||
process.env.HOME = tempHome;
|
||||
tempConfigRoot = path.join(tempHome, ".clawdbot-test");
|
||||
setTestConfigRoot(tempConfigRoot);
|
||||
sessionStoreSaveDelayMs.value = 0;
|
||||
testTailnetIPv4.value = undefined;
|
||||
testState.gatewayBind = undefined;
|
||||
@@ -81,6 +85,7 @@ export function installGatewayTestHooks() {
|
||||
});
|
||||
tempHome = undefined;
|
||||
}
|
||||
tempConfigRoot = undefined;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user