MCPcopy
hub / github.com/openai/codex-plugin-cc / installFakeCodex

Function installFakeCodex

tests/fake-codex-fixture.mjs:7–650  ·  view source on GitHub ↗
(binDir, behavior = "review-ok")

Source from the content-addressed store, hash-verified

5import { writeExecutable } from "./helpers.mjs";
6
7export function installFakeCodex(binDir, behavior = "review-ok") {
8 const statePath = path.join(binDir, "fake-codex-state.json");
9 const scriptPath = path.join(binDir, "codex");
10 const source = `#!/usr/bin/env node
11const fs = require("node:fs");
12const crypto = require("node:crypto");
13const path = require("node:path");
14const readline = require("node:readline");
15
16 const STATE_PATH = ${JSON.stringify(statePath)};
17 const BEHAVIOR = ${JSON.stringify(behavior)};
18 const interruptibleTurns = new Map();
19
20 function loadState() {
21 if (!fs.existsSync(STATE_PATH)) {
22 return { nextThreadId: 1, nextTurnId: 1, appServerStarts: 0, threads: [], capabilities: null, lastInterrupt: null };
23 }
24 return JSON.parse(fs.readFileSync(STATE_PATH, "utf8"));
25 }
26
27function saveState(state) {
28 fs.writeFileSync(STATE_PATH, JSON.stringify(state, null, 2));
29}
30
31function requiresExperimental(field, message, state) {
32 if (!(field in (message.params || {}))) {
33 return false;
34 }
35 return !state.capabilities || state.capabilities.experimentalApi !== true;
36}
37
38function now() {
39 return Math.floor(Date.now() / 1000);
40}
41
42function buildThread(thread) {
43 return {
44 id: thread.id,
45 preview: thread.preview || "",
46 ephemeral: Boolean(thread.ephemeral),
47 modelProvider: "openai",
48 createdAt: thread.createdAt,
49 updatedAt: thread.updatedAt,
50 status: { type: "idle" },
51 path: null,
52 cwd: thread.cwd,
53 cliVersion: "fake-codex",
54 source: "appServer",
55 agentNickname: null,
56 agentRole: null,
57 gitInfo: null,
58 name: thread.name || null,
59 turns: []
60 };
61}
62
63function buildTurn(id, status = "inProgress", error = null) {
64 return { id, status, items: [], error };

Callers 1

runtime.test.mjsFile · 0.90

Calls 1

writeExecutableFunction · 0.90

Tested by

no test coverage detected