test(review): prove fail-open status contract

This commit is contained in:
Claude
2026-08-30 14:11:03 -04:00
parent a12f94f459
commit 2099a16a1f
3 changed files with 49 additions and 4 deletions
+45
View File
@@ -0,0 +1,45 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { openDb } from '../src/lib/db.js';
import { runReview } from '../src/lib/review.js';
const HEAD = 'a'.repeat(40);
test('an unavailable review posts success without hiding the failure', async () => {
const statuses = [];
const db = openDb(':memory:');
const gitea = {
postStatus: async (_owner, _repo, _sha, body) => statuses.push(body),
getCommitDiff: async () => { throw new Error('review service unavailable'); }
};
const job = {
owner: 'o', repo: 'r', sha: HEAD, before: null, prIndex: null,
event: 'push', pusher: 'tester', authors: [], commitMessages: []
};
const result = await runReview({
cfg: {
publicBaseUrl: 'https://reviews.example.test',
maxDiffBytes: 1024,
model: 'claude-cli/claude-sonnet-4-6',
botUsername: 'reviewer'
},
gitea,
adminGitea: null,
db,
job,
withGlobal: async (fn) => fn(),
log: () => {}
});
assert.equal(result.ok, false);
assert.deepEqual(statuses.map(({ state }) => state), ['pending', 'success']);
assert.equal(statuses[1].context, 'granthi-review');
assert.equal(statuses[1].description, 'review unavailable — diff fetch failed (not blocking)');
const persisted = db.prepare(
'SELECT status_state, error FROM reviews WHERE repo = ? AND sha = ?'
).get('o/r', HEAD);
assert.equal(persisted.status_state, 'success');
assert.match(persisted.error, /review service unavailable/);
});