MCPcopy Create free account
hub / github.com/alibaba/open-code-review / makeFixture

Function makeFixture

scripts/github-actions/action-contract.test.js:224–274  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Tested by

no test coverage detected