()
| 209 | } |
| 210 | |
| 211 | function makeFixture() { |
| 212 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), "open-code-review-action-contract-")); |
| 213 | const bin = path.join(dir, "bin"); |
| 214 | fs.mkdirSync(bin); |
| 215 | const callsPath = path.join(dir, "calls.jsonl"); |
| 216 | const npmCallsPath = path.join(dir, "npm-calls.jsonl"); |
| 217 | const configPath = path.join(dir, "config.jsonl"); |
| 218 | const resultPath = path.join(dir, "ocr-result.json"); |
| 219 | const stderrPath = path.join(dir, "ocr-stderr.log"); |
| 220 | |
| 221 | const ocrScript = `#!/usr/bin/env node |
| 222 | const fs = require("fs"); |
| 223 | const args = process.argv.slice(2); |
| 224 | const env = {}; |
| 225 | for (const name of ["OCR_LLM_TIMEOUT", "OCR_LLM_EXTRA_HEADERS", "REVIEW_TASK_TIMEOUT", "OCR_TIMEOUT"]) { |
| 226 | if (process.env[name] !== undefined) env[name] = process.env[name]; |
| 227 | } |
| 228 | const record = { args, env }; |
| 229 | fs.appendFileSync(process.env.OCR_CALLS, JSON.stringify(record) + "\\n"); |
| 230 | if (args[0] === "config" && args[1] === "set") { |
| 231 | fs.appendFileSync(process.env.OCR_CONFIG, JSON.stringify(args) + "\\n"); |
| 232 | process.stdout.write("ocr config set " + args.slice(2).join(" ") + "\\n"); |
| 233 | } else if (args[0] === "config" && args[1] === "unset") { |
| 234 | fs.appendFileSync(process.env.OCR_CONFIG, JSON.stringify(args) + "\\n"); |
| 235 | process.stdout.write("ocr config unset " + args.slice(2).join(" ") + "\\n"); |
| 236 | } else if (args[0] === "version") { |
| 237 | const output = Object.prototype.hasOwnProperty.call(process.env, "OCR_FAKE_VERSION_OUTPUT") |
| 238 | ? process.env.OCR_FAKE_VERSION_OUTPUT |
| 239 | : "open-code-review 1.9.10 contract-test/fixture"; |
| 240 | process.stdout.write(output); |
| 241 | if (output && !output.endsWith("\\n")) process.stdout.write("\\n"); |
| 242 | process.exit(Number(process.env.OCR_FAKE_VERSION_STATUS || 0)); |
| 243 | } else if (args[0] === "review") { |
| 244 | process.stdout.write(JSON.stringify({ comments: [], warnings: [] })); |
| 245 | } else { |
| 246 | process.stdout.write("ocr " + args.join(" ") + "\\n"); |
| 247 | } |
| 248 | `; |
| 249 | const npmScript = `#!/usr/bin/env node |
| 250 | const fs = require("fs"); |
| 251 | const args = process.argv.slice(2); |
| 252 | fs.appendFileSync(process.env.OCR_NPM_CALLS, JSON.stringify(args) + "\\n"); |
| 253 | process.stdout.write("npm " + args.join(" ") + "\\n"); |
| 254 | `; |
| 255 | for (const [name, body] of [["ocr", ocrScript], ["npm", npmScript]]) { |
| 256 | const file = path.join(bin, name); |
| 257 | fs.writeFileSync(file, body, { mode: 0o755 }); |
| 258 | } |
| 259 | |
| 260 | return { dir, bin, callsPath, npmCallsPath, configPath, resultPath, stderrPath }; |
| 261 | } |
| 262 | |
| 263 | function removeFixture(fixture) { |
| 264 | fs.rmSync(fixture.dir, { recursive: true, force: true }); |
no outgoing calls
no test coverage detected