|
8 | 8 | GithubEtagResponseStore, |
9 | 9 | } from "../dashboard/github-etag-cache.ts"; |
10 | 10 | import worker, { ExactReviewQueue, githubJsonForTest } from "../dashboard/worker.ts"; |
| 11 | +import { createGitHubRuntime } from "../dist/clawsweeper-github-runtime.js"; |
11 | 12 | import { |
12 | 13 | githubEtagCacheKey, |
13 | 14 | githubEtagCacheRequestBody, |
@@ -50,6 +51,58 @@ test("ETag keys fence credential pool, media type, query, and page", () => { |
50 | 51 | assert.equal(page2.route, "/repos/openclaw/openclaw/issues/42/comments?page=2&per_page=100"); |
51 | 52 | }); |
52 | 53 |
|
| 54 | +test("projected GitHub reads bypass the durable ETag broker", () => { |
| 55 | + const keys = ["EXACT_EVENT_PUBLICATION", "EXACT_REVIEW_QUEUE_URL", "CLAWSWEEPER_WEBHOOK_SECRET"]; |
| 56 | + const previous = Object.fromEntries(keys.map((key) => [key, process.env[key]])); |
| 57 | + Object.assign(process.env, { |
| 58 | + EXACT_EVENT_PUBLICATION: "true", |
| 59 | + EXACT_REVIEW_QUEUE_URL: "http://127.0.0.1:9", |
| 60 | + CLAWSWEEPER_WEBHOOK_SECRET: "etag-broker-secret-placeholder", |
| 61 | + }); |
| 62 | + const invocations: string[][] = []; |
| 63 | + const runtime = createGitHubRuntime({ |
| 64 | + ROOT: process.cwd(), |
| 65 | + targetRepo: () => "openclaw/openclaw", |
| 66 | + run: (_command, args) => { |
| 67 | + invocations.push(args); |
| 68 | + return JSON.stringify({ projected: true }); |
| 69 | + }, |
| 70 | + }); |
| 71 | + const route = "/repos/openclaw/openclaw/pulls/1234"; |
| 72 | + const projections = [ |
| 73 | + ["--jq", "{body}"], |
| 74 | + ["-q", "{requested_reviewers,requested_teams}"], |
| 75 | + ["--template", "{{.head.sha}}"], |
| 76 | + ["-t", "{{.state}}"], |
| 77 | + ["--jq={body}"], |
| 78 | + ["--template={{.head.sha}}"], |
| 79 | + ["-q={body}"], |
| 80 | + ["-q{body}"], |
| 81 | + ["-t={{.state}}"], |
| 82 | + ["-t{{.state}}"], |
| 83 | + ["-iq", "{body}"], |
| 84 | + ["-it", "{{.state}}"], |
| 85 | + ]; |
| 86 | + |
| 87 | + try { |
| 88 | + for (const projection of projections) { |
| 89 | + assert.equal( |
| 90 | + runtime.ghWithPreparedTimeout(["api", route, ...projection], 1_000), |
| 91 | + JSON.stringify({ projected: true }), |
| 92 | + ); |
| 93 | + } |
| 94 | + assert.deepEqual( |
| 95 | + invocations, |
| 96 | + projections.map((projection) => ["api", route, ...projection]), |
| 97 | + ); |
| 98 | + } finally { |
| 99 | + for (const [key, value] of Object.entries(previous)) { |
| 100 | + if (value === undefined) delete process.env[key]; |
| 101 | + else process.env[key] = value; |
| 102 | + } |
| 103 | + } |
| 104 | +}); |
| 105 | + |
53 | 106 | test("durable broker revalidates every read and keeps wire calls while avoiding quota charges", () => { |
54 | 107 | const entries = new Map<string, { etag: string; body: string; bodyDigest: string }>(); |
55 | 108 | const events: GithubEtagBrokerEvent[] = []; |
|
0 commit comments