refactor(test): dedupe channel and monitor action suites

This commit is contained in:
Peter Steinberger
2026-02-18 04:48:51 +00:00
parent 31f83c86b2
commit a69e7682c1
11 changed files with 506 additions and 789 deletions

View File

@@ -71,36 +71,48 @@ async function runRepair(cfg: OpenClawConfig) {
await maybeRepairGatewayServiceConfig(cfg, "local", makeDoctorIo(), makeDoctorPrompts());
}
const gatewayProgramArguments = [
"/usr/bin/node",
"/usr/local/bin/openclaw",
"gateway",
"--port",
"18789",
];
function setupGatewayTokenRepairScenario(expectedToken: string) {
mocks.readCommand.mockResolvedValue({
programArguments: gatewayProgramArguments,
environment: {
OPENCLAW_GATEWAY_TOKEN: "stale-token",
},
});
mocks.auditGatewayServiceConfig.mockResolvedValue({
ok: false,
issues: [
{
code: "gateway-token-mismatch",
message: "Gateway service OPENCLAW_GATEWAY_TOKEN does not match gateway.auth.token",
level: "recommended",
},
],
});
mocks.buildGatewayInstallPlan.mockResolvedValue({
programArguments: gatewayProgramArguments,
workingDirectory: "/tmp",
environment: {
OPENCLAW_GATEWAY_TOKEN: expectedToken,
},
});
mocks.install.mockResolvedValue(undefined);
}
describe("maybeRepairGatewayServiceConfig", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("treats gateway.auth.token as source of truth for service token repairs", async () => {
mocks.readCommand.mockResolvedValue({
programArguments: ["/usr/bin/node", "/usr/local/bin/openclaw", "gateway", "--port", "18789"],
environment: {
OPENCLAW_GATEWAY_TOKEN: "stale-token",
},
});
mocks.auditGatewayServiceConfig.mockResolvedValue({
ok: false,
issues: [
{
code: "gateway-token-mismatch",
message: "Gateway service OPENCLAW_GATEWAY_TOKEN does not match gateway.auth.token",
level: "recommended",
},
],
});
mocks.buildGatewayInstallPlan.mockResolvedValue({
programArguments: ["/usr/bin/node", "/usr/local/bin/openclaw", "gateway", "--port", "18789"],
workingDirectory: "/tmp",
environment: {
OPENCLAW_GATEWAY_TOKEN: "config-token",
},
});
mocks.install.mockResolvedValue(undefined);
setupGatewayTokenRepairScenario("config-token");
const cfg: OpenClawConfig = {
gateway: {
@@ -130,42 +142,7 @@ describe("maybeRepairGatewayServiceConfig", () => {
const previousToken = process.env.OPENCLAW_GATEWAY_TOKEN;
process.env.OPENCLAW_GATEWAY_TOKEN = "env-token";
try {
mocks.readCommand.mockResolvedValue({
programArguments: [
"/usr/bin/node",
"/usr/local/bin/openclaw",
"gateway",
"--port",
"18789",
],
environment: {
OPENCLAW_GATEWAY_TOKEN: "stale-token",
},
});
mocks.auditGatewayServiceConfig.mockResolvedValue({
ok: false,
issues: [
{
code: "gateway-token-mismatch",
message: "Gateway service OPENCLAW_GATEWAY_TOKEN does not match gateway.auth.token",
level: "recommended",
},
],
});
mocks.buildGatewayInstallPlan.mockResolvedValue({
programArguments: [
"/usr/bin/node",
"/usr/local/bin/openclaw",
"gateway",
"--port",
"18789",
],
workingDirectory: "/tmp",
environment: {
OPENCLAW_GATEWAY_TOKEN: "env-token",
},
});
mocks.install.mockResolvedValue(undefined);
setupGatewayTokenRepairScenario("env-token");
const cfg: OpenClawConfig = {
gateway: {},