Files
oh-my-opencode/src/openclaw/__tests__/client.test.ts
T
YeonGyu-Kim 2c8813e95d fix: rename OMX_OPENCLAW env vars to OMO_OPENCLAW
Renames all environment variable gates from the old oh-my-codex (OMX) prefix
to the correct oh-my-openagent (OMO) prefix:

- OMX_OPENCLAW -> OMO_OPENCLAW
- OMX_OPENCLAW_COMMAND -> OMO_OPENCLAW_COMMAND
- OMX_OPENCLAW_DEBUG -> OMO_OPENCLAW_DEBUG
- OMX_OPENCLAW_COMMAND_TIMEOUT_MS -> OMO_OPENCLAW_COMMAND_TIMEOUT_MS

Adds TDD tests verifying:
- OMO_OPENCLAW=1 is required for activation
- Old OMX_OPENCLAW env var is not accepted
2026-03-16 18:45:34 +09:00

99 lines
3.1 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from "bun:test";
import { resolveGateway, wakeOpenClaw } from "../client";
import { type OpenClawConfig } from "../types";
describe("OpenClaw Client", () => {
describe("resolveGateway", () => {
const config: OpenClawConfig = {
enabled: true,
gateways: {
foo: { type: "command", command: "echo foo" },
bar: { type: "http", url: "https://example.com" },
},
hooks: {
"session-start": {
gateway: "foo",
instruction: "start",
enabled: true,
},
"session-end": { gateway: "bar", instruction: "end", enabled: true },
stop: { gateway: "foo", instruction: "stop", enabled: false },
},
};
it("resolves valid mapping", () => {
const result = resolveGateway(config, "session-start");
expect(result).not.toBeNull();
expect(result?.gatewayName).toBe("foo");
expect(result?.instruction).toBe("start");
});
it("returns null for disabled hook", () => {
const result = resolveGateway(config, "stop");
expect(result).toBeNull();
});
it("returns null for unmapped event", () => {
const result = resolveGateway(config, "ask-user-question");
expect(result).toBeNull();
});
});
describe("wakeOpenClaw env gate", () => {
let oldEnv: string | undefined;
beforeEach(() => {
oldEnv = process.env.OMO_OPENCLAW;
});
afterEach(() => {
if (oldEnv === undefined) {
delete process.env.OMO_OPENCLAW;
} else {
process.env.OMO_OPENCLAW = oldEnv;
}
});
it("returns null when OMO_OPENCLAW is not set", async () => {
delete process.env.OMO_OPENCLAW;
const config: OpenClawConfig = {
enabled: true,
gateways: { gw: { type: "command", command: "echo test" } },
hooks: {
"session-start": { gateway: "gw", instruction: "hi", enabled: true },
},
};
const result = await wakeOpenClaw("session-start", { projectPath: "/tmp" }, config);
expect(result).toBeNull();
});
it("returns null when OMO_OPENCLAW is not '1'", async () => {
process.env.OMO_OPENCLAW = "0";
const config: OpenClawConfig = {
enabled: true,
gateways: { gw: { type: "command", command: "echo test" } },
hooks: {
"session-start": { gateway: "gw", instruction: "hi", enabled: true },
},
};
const result = await wakeOpenClaw("session-start", { projectPath: "/tmp" }, config);
expect(result).toBeNull();
});
it("does not use OMX_OPENCLAW (old env var)", async () => {
delete process.env.OMO_OPENCLAW;
process.env.OMX_OPENCLAW = "1";
const config: OpenClawConfig = {
enabled: true,
gateways: { gw: { type: "command", command: "echo test" } },
hooks: {
"session-start": { gateway: "gw", instruction: "hi", enabled: true },
},
};
const result = await wakeOpenClaw("session-start", { projectPath: "/tmp" }, config);
expect(result).toBeNull();
delete process.env.OMX_OPENCLAW;
});
});
});