Reformat src/*.mjs with Prettier; add format/format:check scripts
Every route handler was written as one dense semicolon-chained line (server.mjs's main handler was over 2000 characters wide) — real width, not a VSCode wrapping artifact. Ran Prettier to break statement structure into properly indented multi-line code; left template literal string contents untouched since Prettier doesn't reformat inside those, so the large HTML-generating return strings are still single long lines by nature, just no longer compounded by unformatted surrounding JS. Verified: tests pass, node --check passes, and the app renders identically before/after (screenshotted the diff). No devDependency added — npx prettier@3.9.5 pinned in the new scripts keeps the zero-runtime-dependency pledge intact; formatting is a dev- time concern only. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
cdcc3c7937
commit
4b7b5a42d3
+48
-3
@@ -1,3 +1,48 @@
|
||||
import test from'node:test';import assert from'node:assert/strict';import{scanGiteaCandidates}from'../src/gitea.mjs';
|
||||
test('finds subject fixes, paginates safely, and ignores body-only matches',async()=>{const calls=[],fetchImpl=async url=>{calls.push(url);if(url.includes('/git/commits/abc'))return new Response(JSON.stringify({files:[{filename:'web/verify.go'}]}));return new Response(JSON.stringify([{sha:'abc',commit:{message:'Fix DTLS verification\nDetailed body',committer:{date:'2026-07-20T00:00:00Z'}}},{sha:'def',commit:{message:'Add feature\nfix mentioned only in body',committer:{date:'2026-07-19T00:00:00Z'}}}]))};const out=await scanGiteaCandidates({baseUrl:'https://gitea.example',repositories:['explewd/flit'],fetchImpl});assert.equal(out.candidates.length,1);assert.equal(out.candidates[0].sha,'abc');assert.equal(out.candidates[0].paths,'web/verify.go');assert.equal(out.errors.length,0);assert.ok(calls[0].includes('limit=50&page=1'))});
|
||||
test('isolates invalid and failed repositories',async()=>{const out=await scanGiteaCandidates({baseUrl:'https://gitea.example',repositories:['bad','explewd/missing'],fetchImpl:async()=>new Response('',{status:404})});assert.equal(out.candidates.length,0);assert.equal(out.errors.length,2)});
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { scanGiteaCandidates } from '../src/gitea.mjs';
|
||||
test('finds subject fixes, paginates safely, and ignores body-only matches', async () => {
|
||||
const calls = [],
|
||||
fetchImpl = async (url) => {
|
||||
calls.push(url);
|
||||
if (url.includes('/git/commits/abc'))
|
||||
return new Response(JSON.stringify({ files: [{ filename: 'web/verify.go' }] }));
|
||||
return new Response(
|
||||
JSON.stringify([
|
||||
{
|
||||
sha: 'abc',
|
||||
commit: {
|
||||
message: 'Fix DTLS verification\nDetailed body',
|
||||
committer: { date: '2026-07-20T00:00:00Z' },
|
||||
},
|
||||
},
|
||||
{
|
||||
sha: 'def',
|
||||
commit: {
|
||||
message: 'Add feature\nfix mentioned only in body',
|
||||
committer: { date: '2026-07-19T00:00:00Z' },
|
||||
},
|
||||
},
|
||||
]),
|
||||
);
|
||||
};
|
||||
const out = await scanGiteaCandidates({
|
||||
baseUrl: 'https://gitea.example',
|
||||
repositories: ['explewd/flit'],
|
||||
fetchImpl,
|
||||
});
|
||||
assert.equal(out.candidates.length, 1);
|
||||
assert.equal(out.candidates[0].sha, 'abc');
|
||||
assert.equal(out.candidates[0].paths, 'web/verify.go');
|
||||
assert.equal(out.errors.length, 0);
|
||||
assert.ok(calls[0].includes('limit=50&page=1'));
|
||||
});
|
||||
test('isolates invalid and failed repositories', async () => {
|
||||
const out = await scanGiteaCandidates({
|
||||
baseUrl: 'https://gitea.example',
|
||||
repositories: ['bad', 'explewd/missing'],
|
||||
fetchImpl: async () => new Response('', { status: 404 }),
|
||||
});
|
||||
assert.equal(out.candidates.length, 0);
|
||||
assert.equal(out.errors.length, 2);
|
||||
});
|
||||
|
||||
+52
-4
@@ -1,4 +1,52 @@
|
||||
import test from 'node:test';import assert from 'node:assert/strict';import {DatabaseSync}from'node:sqlite';import{createReceiptStore,validateReceipt}from'../src/receipts.mjs';
|
||||
const valid={schemaVersion:1,eventType:'deployment',eventId:'goonk-prod-1',project:'goonk',occurredAt:'2026-07-20T20:00:00Z',result:'success',source:{commit:'577a62e'},verification:{health:'healthy'}};
|
||||
test('validates v1',()=>{assert.deepEqual(validateReceipt(valid),[]);assert.ok(validateReceipt({}).length)});
|
||||
test('is idempotent and public projection is allowlisted',async()=>{const db=new DatabaseSync(':memory:'),store=createReceiptStore(db,'goonk:secret');const req=()=>({method:'POST',headers:{authorization:'Bearer secret'},async *[Symbol.asyncIterator](){yield JSON.stringify(valid)}});const res=()=>{const x={status:0,body:''};x.writeHead=s=>{x.status=s;return x};x.end=b=>{x.body=b;return x};return x};let r=res();await store.handle(req(),r,'/api/v1/events');assert.equal(r.status,201);r=res();await store.handle(req(),r,'/api/v1/events');assert.equal(JSON.parse(r.body).duplicate,true);r=res();await store.handle({method:'GET',headers:{}},r,'/api/v1/public/projects/goonk/latest');const out=JSON.parse(r.body);assert.equal(out.deployment.commit,'577a62e');assert.equal(out.deployment.payload,undefined)});
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
import { createReceiptStore, validateReceipt } from '../src/receipts.mjs';
|
||||
const valid = {
|
||||
schemaVersion: 1,
|
||||
eventType: 'deployment',
|
||||
eventId: 'goonk-prod-1',
|
||||
project: 'goonk',
|
||||
occurredAt: '2026-07-20T20:00:00Z',
|
||||
result: 'success',
|
||||
source: { commit: '577a62e' },
|
||||
verification: { health: 'healthy' },
|
||||
};
|
||||
test('validates v1', () => {
|
||||
assert.deepEqual(validateReceipt(valid), []);
|
||||
assert.ok(validateReceipt({}).length);
|
||||
});
|
||||
test('is idempotent and public projection is allowlisted', async () => {
|
||||
const db = new DatabaseSync(':memory:'),
|
||||
store = createReceiptStore(db, 'goonk:secret');
|
||||
const req = () => ({
|
||||
method: 'POST',
|
||||
headers: { authorization: 'Bearer secret' },
|
||||
async *[Symbol.asyncIterator]() {
|
||||
yield JSON.stringify(valid);
|
||||
},
|
||||
});
|
||||
const res = () => {
|
||||
const x = { status: 0, body: '' };
|
||||
x.writeHead = (s) => {
|
||||
x.status = s;
|
||||
return x;
|
||||
};
|
||||
x.end = (b) => {
|
||||
x.body = b;
|
||||
return x;
|
||||
};
|
||||
return x;
|
||||
};
|
||||
let r = res();
|
||||
await store.handle(req(), r, '/api/v1/events');
|
||||
assert.equal(r.status, 201);
|
||||
r = res();
|
||||
await store.handle(req(), r, '/api/v1/events');
|
||||
assert.equal(JSON.parse(r.body).duplicate, true);
|
||||
r = res();
|
||||
await store.handle({ method: 'GET', headers: {} }, r, '/api/v1/public/projects/goonk/latest');
|
||||
const out = JSON.parse(r.body);
|
||||
assert.equal(out.deployment.commit, '577a62e');
|
||||
assert.equal(out.deployment.payload, undefined);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user