fix: production hardening for merge races, timeouts, and webhook ops
Pin merge SHA, lock conflict repair, bound subprocess/proxy output, fail-fast incomplete R2/webhook config, redact validation/stderr secrets, and document that webhook 202 is best-effort after ACK. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d6f33a71c3
commit
039acabd96
29 files changed
+1163
-240
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
function loadConfigWith(overrides: Record<string, string | undefined>) {
|
||||
const env = { ...process.env };
|
||||
for (const [key, value] of Object.entries(overrides)) {
|
||||
if (value === undefined) {
|
||||
delete env[key];
|
||||
} else {
|
||||
env[key] = value;
|
||||
}
|
||||
}
|
||||
return spawnSync(process.execPath, ["--import", "tsx", "--eval", "import('./src/config.ts')"], {
|
||||
cwd: path.resolve(process.cwd()),
|
||||
env,
|
||||
encoding: "utf8"
|
||||
});
|
||||
}
|
||||
|
||||
test("config rejects enabled webhook without a secret", () => {
|
||||
const result = loadConfigWith({ WEBHOOK_ENABLED: "true", WEBHOOK_SECRET: "" });
|
||||
assert.notEqual(result.status, 0);
|
||||
assert.match(`${result.stdout}${result.stderr}`, /WEBHOOK_SECRET/);
|
||||
});
|
||||
|
||||
test("config rejects partially configured R2 settings", () => {
|
||||
const result = loadConfigWith({
|
||||
WEBHOOK_ENABLED: "false",
|
||||
R2_ENDPOINT: "https://example.r2.cloudflarestorage.com",
|
||||
R2_BUCKET_NAME: "bucket",
|
||||
R2_ACCESS_KEY_ID: "",
|
||||
R2_SECRET_ACCESS_KEY: ""
|
||||
});
|
||||
assert.notEqual(result.status, 0);
|
||||
assert.match(`${result.stdout}${result.stderr}`, /R2_ENDPOINT/);
|
||||
});
|
||||
|
||||
test("config defaults the provider base URL explicitly", () => {
|
||||
const result = loadConfigWith({
|
||||
WEBHOOK_ENABLED: "false",
|
||||
GOOSE_BASE_URL: ""
|
||||
});
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { acquireConflictLock } from "../src/review/conflictResolver.js";
|
||||
|
||||
test("conflict lock rejects overlapping runs for the same pull request", async () => {
|
||||
const release = await acquireConflictLock("acme/demo#7");
|
||||
await assert.rejects(() => acquireConflictLock("acme/demo#7"), /already active/);
|
||||
release();
|
||||
const releaseAgain = await acquireConflictLock("acme/demo#7");
|
||||
releaseAgain();
|
||||
});
|
||||
|
||||
test("conflict lock allows concurrent runs for different pull requests", async () => {
|
||||
const first = await acquireConflictLock("acme/demo#8");
|
||||
const second = await acquireConflictLock("acme/demo#9");
|
||||
first();
|
||||
second();
|
||||
});
|
||||
@@ -1,7 +1,9 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { formatValidationLogOutput } from "../src/review/conflictResolver.js";
|
||||
import { redactSecrets } from "../src/security/secrets.js";
|
||||
import {
|
||||
formatValidationLogOutput,
|
||||
formatValidationResult
|
||||
} from "../src/review/conflictResolver.js";
|
||||
|
||||
test("validation log output keeps the useful tail within bounds", () => {
|
||||
const longOutput = "x".repeat(30_000) + "\nfinal error line";
|
||||
@@ -16,9 +18,12 @@ test("validation log output strips ANSI escapes and normalizes newlines", () =>
|
||||
assert.equal(formatted, "error\nline2");
|
||||
});
|
||||
|
||||
test("redaction is applied to command failure text before exposure", () => {
|
||||
// The conflict resolver wraps commandFailureOutput with redactSecrets; this
|
||||
// asserts the composition contract at the module boundary.
|
||||
const leaked = "push failed: https://user:ghp_ABCDEFGHIJKLMNOPQRSTUVWXYZ123456@github.com/x";
|
||||
assert.equal(redactSecrets(leaked).includes("ghp_"), false);
|
||||
test("validation result redacts credentials before prompt or log exposure", () => {
|
||||
const formatted = formatValidationResult("npm test", {
|
||||
code: 1,
|
||||
stdout: "",
|
||||
stderr: "fatal: https://user:ghp_ABCDEFGHIJKLMNOPQRSTUVWXYZ123456@github.com/x"
|
||||
});
|
||||
assert.equal(formatted.includes("ghp_"), false);
|
||||
assert.match(formatted, /REDACTED|Exit code: 1/);
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { createEventLogger } from "../src/logger.js";
|
||||
|
||||
test("event logger child bindings include owner/repo/eventName", () => {
|
||||
const child = createEventLogger({
|
||||
eventName: "issue_comment",
|
||||
owner: "acme",
|
||||
repo: "demo",
|
||||
pullNumber: 7
|
||||
});
|
||||
assert.equal(typeof child.info, "function");
|
||||
assert.equal(typeof child.error, "function");
|
||||
});
|
||||
Reference in new issue
Block a user