|
| 1 | +// Secretless, fail-closed transport: all writes are local fixture state. |
| 2 | +const fs = require("node:fs"); |
| 3 | +const path = require("node:path"); |
| 4 | +const root = process.env.APPLY_MEMORY_CASE; |
| 5 | +const raw = process.argv.slice(2); |
| 6 | +const args = raw[0] === "--repo" ? raw.slice(2) : raw; |
| 7 | +const endpoint = args.includes("-i") ? args[args.indexOf("-i") + 1] : args[1] || ""; |
| 8 | +const method = args.includes("--method") ? args[args.indexOf("--method") + 1] : "GET"; |
| 9 | +fs.appendFileSync(path.join(root, "requests.jsonl"), `${JSON.stringify({ args, method })}\n`); |
| 10 | +const match = endpoint.match(/\/issues\/(\d+)(?:\/|$)/); |
| 11 | +const number = Number(match?.[1]); |
| 12 | +const commentPath = path.join(root, `comment-${number}.json`); |
| 13 | +const output = (value) => { |
| 14 | + if (args.includes("-i")) process.stdout.write("HTTP/2 200\n\n"); |
| 15 | + console.log(JSON.stringify(value)); |
| 16 | +}; |
| 17 | +if (number === 102 && process.env.APPLY_MEMORY_INTERRUPT) { |
| 18 | + if (process.env.APPLY_MEMORY_INTERRUPT === "budget") { |
| 19 | + Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10_000); |
| 20 | + } |
| 21 | + console.error("fixture interrupted second item (HTTP 422)"); |
| 22 | + process.exit(1); |
| 23 | +} |
| 24 | +if (args[0] === "api" && /\/issues\/\d+\/comments(?:\?|$)/.test(endpoint)) { |
| 25 | + if (method === "POST") { |
| 26 | + const payload = JSON.parse(fs.readFileSync(args[args.indexOf("--input") + 1], "utf8")); |
| 27 | + const comment = { |
| 28 | + id: 9000 + number, |
| 29 | + html_url: `https://github.com/openclaw/openclaw/issues/${number}#issuecomment-${9000 + number}`, |
| 30 | + created_at: "2026-08-02T00:00:00Z", |
| 31 | + updated_at: "2026-08-02T00:00:00Z", |
| 32 | + user: { login: "clawsweeper[bot]" }, |
| 33 | + body: payload.body, |
| 34 | + }; |
| 35 | + fs.writeFileSync(commentPath, JSON.stringify(comment)); |
| 36 | + output(comment); |
| 37 | + } else if (method === "GET") { |
| 38 | + output([fs.existsSync(commentPath) ? [JSON.parse(fs.readFileSync(commentPath, "utf8"))] : []]); |
| 39 | + } else throw new Error(`unexpected comment mutation: ${method}`); |
| 40 | +} else if (args[0] === "api" && /\/issues\/\d+\/timeline(?:\?|$)/.test(endpoint)) { |
| 41 | + output([[]]); |
| 42 | +} else if (args[0] === "api" && /\/issues\/\d+$/.test(endpoint) && method === "GET") { |
| 43 | + const isPull = process.env.APPLY_MEMORY_KIND === "pull_request"; |
| 44 | + output({ |
| 45 | + number, |
| 46 | + title: "Memory proof", |
| 47 | + body: "", |
| 48 | + html_url: `https://github.com/openclaw/openclaw/${isPull ? "pull" : "issues"}/${number}`, |
| 49 | + created_at: "2026-05-01T00:00:00Z", |
| 50 | + updated_at: |
| 51 | + process.env.APPLY_MEMORY_DRIFT && number >= 121 |
| 52 | + ? "2026-05-02T00:00:00Z" |
| 53 | + : "2026-05-01T00:00:00Z", |
| 54 | + closed_at: null, |
| 55 | + state: "open", |
| 56 | + locked: false, |
| 57 | + active_lock_reason: null, |
| 58 | + author_association: "CONTRIBUTOR", |
| 59 | + user: { login: "reporter" }, |
| 60 | + labels: isPull |
| 61 | + ? ["security"] |
| 62 | + : ["security", "issue-rating: 🦀 challenger crab", "clawsweeper:current-main-repro"], |
| 63 | + comments: fs.existsSync(commentPath) ? 1 : 0, |
| 64 | + pull_request: isPull |
| 65 | + ? { url: `https://api.github.com/repos/openclaw/openclaw/pulls/${number}` } |
| 66 | + : null, |
| 67 | + }); |
| 68 | +} else if (args[0] === "api" && /\/pulls\/\d+$/.test(endpoint) && method === "GET") { |
| 69 | + output({ head: { sha: "a".repeat(40) }, base: { ref: "main" }, merged: false, state: "open" }); |
| 70 | +} else if ( |
| 71 | + args[0] === "api" && |
| 72 | + /\/pulls\/\d+\/(files|commits|comments|reviews)(?:\?|$)/.test(endpoint) && |
| 73 | + method === "GET" |
| 74 | +) { |
| 75 | + output([[]]); |
| 76 | +} else if ( |
| 77 | + args[0] === "api" && |
| 78 | + endpoint === "graphql" && |
| 79 | + args.some((arg) => arg.includes("reviewThreads")) |
| 80 | +) { |
| 81 | + output({ |
| 82 | + data: { |
| 83 | + repository: { |
| 84 | + pullRequest: { |
| 85 | + reviewThreads: { nodes: [], pageInfo: { hasNextPage: false, endCursor: null } }, |
| 86 | + }, |
| 87 | + }, |
| 88 | + }, |
| 89 | + }); |
| 90 | +} else if (args[0] === "issue" && args[1] === "view") { |
| 91 | + output({ closedByPullRequestsReferences: [] }); |
| 92 | +} else if ( |
| 93 | + args[0] === "api" && |
| 94 | + /\/commits\/[a-f0-9]+\/check-runs\?/.test(endpoint) && |
| 95 | + method === "GET" |
| 96 | +) { |
| 97 | + output({ total_count: 0, check_runs: [] }); |
| 98 | +} else if ( |
| 99 | + args[0] === "api" && |
| 100 | + /\/commits\/[a-f0-9]+\/status(?:\?|$)/.test(endpoint) && |
| 101 | + method === "GET" |
| 102 | +) { |
| 103 | + output({ total_count: 0, statuses: [] }); |
| 104 | +} else if (args[0] === "api" && endpoint.startsWith("search/issues?") && method === "GET") { |
| 105 | + output({ items: [] }); |
| 106 | +} else if (args[0] === "label" || (args[0] === "issue" && args[1] === "edit")) { |
| 107 | + output({}); |
| 108 | +} else { |
| 109 | + throw new Error(`unexpected fixture request: ${JSON.stringify(args)}`); |
| 110 | +} |
0 commit comments