(binDir, behavior = "review-ok")
| 5 | import { writeExecutable } from "./helpers.mjs"; |
| 6 | |
| 7 | export 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 |
| 11 | const fs = require("node:fs"); |
| 12 | const crypto = require("node:crypto"); |
| 13 | const path = require("node:path"); |
| 14 | const 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 | |
| 27 | function saveState(state) { |
| 28 | fs.writeFileSync(STATE_PATH, JSON.stringify(state, null, 2)); |
| 29 | } |
| 30 | |
| 31 | function requiresExperimental(field, message, state) { |
| 32 | if (!(field in (message.params || {}))) { |
| 33 | return false; |
| 34 | } |
| 35 | return !state.capabilities || state.capabilities.experimentalApi !== true; |
| 36 | } |
| 37 | |
| 38 | function now() { |
| 39 | return Math.floor(Date.now() / 1000); |
| 40 | } |
| 41 | |
| 42 | function 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 | |
| 63 | function buildTurn(id, status = "inProgress", error = null) { |
| 64 | return { id, status, items: [], error }; |
no test coverage detected