forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodex-app-server-protocol-source.test.ts
More file actions
58 lines (51 loc) 路 2.21 KB
/
Copy pathcodex-app-server-protocol-source.test.ts
File metadata and controls
58 lines (51 loc) 路 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import fs from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { resolveCodexAppServerProtocolSource } from "../../scripts/lib/codex-app-server-protocol-source.js";
import { createScriptTestHarness } from "./test-helpers.js";
const { createTempDir } = createScriptTestHarness();
const originalOpenClawCodexRepo = process.env.OPENCLAW_CODEX_REPO;
afterEach(() => {
if (originalOpenClawCodexRepo === undefined) {
delete process.env.OPENCLAW_CODEX_REPO;
} else {
process.env.OPENCLAW_CODEX_REPO = originalOpenClawCodexRepo;
}
});
describe("codex app-server protocol source resolver", () => {
it("uses OPENCLAW_CODEX_REPO when provided", async () => {
const root = createTempDir("openclaw-protocol-source-root-");
const codexRepo = createTempDir("openclaw-protocol-source-codex-");
createProtocolSchema(codexRepo);
process.env.OPENCLAW_CODEX_REPO = codexRepo;
await expect(resolveCodexAppServerProtocolSource(root)).resolves.toEqual({
codexRepo,
sourceRoot: path.join(codexRepo, "codex-rs/app-server-protocol/schema"),
});
});
it("finds the primary checkout sibling from a git worktree", async () => {
const parentDir = createTempDir("openclaw-protocol-source-parent-");
const primaryOpenClaw = path.join(parentDir, "openclaw");
const codexRepo = path.join(parentDir, "codex");
const worktreeRoot = createTempDir("openclaw-protocol-source-worktree-");
fs.mkdirSync(path.join(primaryOpenClaw, ".git", "worktrees", "codex-harness"), {
recursive: true,
});
fs.mkdirSync(worktreeRoot, { recursive: true });
fs.writeFileSync(
path.join(worktreeRoot, ".git"),
`gitdir: ${path.join(primaryOpenClaw, ".git", "worktrees", "codex-harness")}\n`,
);
createProtocolSchema(codexRepo);
delete process.env.OPENCLAW_CODEX_REPO;
await expect(resolveCodexAppServerProtocolSource(worktreeRoot)).resolves.toEqual({
codexRepo,
sourceRoot: path.join(codexRepo, "codex-rs/app-server-protocol/schema"),
});
});
});
function createProtocolSchema(codexRepo: string): void {
fs.mkdirSync(path.join(codexRepo, "codex-rs/app-server-protocol/schema/typescript"), {
recursive: true,
});
}