Skip to content

Commit c6c0908

Browse files
committed
fix: keep projected GitHub reads out of ETag cache
1 parent ed20a56 commit c6c0908

2 files changed

Lines changed: 72 additions & 4 deletions

File tree

‎src/clawsweeper-github-runtime.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,25 @@ export function createGitHubRuntime(dependencies: CreateGitHubRuntimeDependencie
400400
) {
401401
if (process.env.EXACT_EVENT_PUBLICATION !== "true" || args[0] !== "api") return null;
402402
if (
403-
args.some((arg) =>
404-
["-i", "--include", "--paginate", "--slurp", "-f", "--raw-field", "-F", "--field"].includes(
405-
arg,
406-
),
403+
args.some(
404+
(arg) =>
405+
[
406+
"-i",
407+
"--include",
408+
"--paginate",
409+
"--slurp",
410+
"-f",
411+
"--raw-field",
412+
"-F",
413+
"--field",
414+
"-q",
415+
"--jq",
416+
"-t",
417+
"--template",
418+
].includes(arg) ||
419+
arg.startsWith("--jq=") ||
420+
arg.startsWith("--template=") ||
421+
/^-i*[qt]/.test(arg),
407422
)
408423
) {
409424
return null;

‎test/github-etag-read-broker.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
GithubEtagResponseStore,
99
} from "../dashboard/github-etag-cache.ts";
1010
import worker, { ExactReviewQueue, githubJsonForTest } from "../dashboard/worker.ts";
11+
import { createGitHubRuntime } from "../dist/clawsweeper-github-runtime.js";
1112
import {
1213
githubEtagCacheKey,
1314
githubEtagCacheRequestBody,
@@ -50,6 +51,58 @@ test("ETag keys fence credential pool, media type, query, and page", () => {
5051
assert.equal(page2.route, "/repos/openclaw/openclaw/issues/42/comments?page=2&per_page=100");
5152
});
5253

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+
53106
test("durable broker revalidates every read and keeps wire calls while avoiding quota charges", () => {
54107
const entries = new Map<string, { etag: string; body: string; bodyDigest: string }>();
55108
const events: GithubEtagBrokerEvent[] = [];

0 commit comments

Comments
 (0)