Fixes from the second contributor report

- Static gate: a file main already holds may grow 128 KB beyond its size on
  main (Unit_C.cpp is 796 KB, Player_C.cpp 491 KB: no edit to them could
  pass the 256 KB limit); only what a submission adds counts toward the total.
- A peer-confirmed function in another unit may move closer to the original
  (a header layout fix); only moving away from it is a regression.
- A function main no longer annotates anywhere (fn_07162, removed from stpl.h
  in 0f9ebdb4 while its record still said exact) is not "removed" by every
  later submission of the unit it was recorded at.
- A library function main already annotates in a file (fn_25851 in
  BSNEncodeInterface.h) no longer refuses every edit of that file; adding
  such an annotation still is refused.
- td_withdraw / td withdraw <attemptId>: the author takes back a function
  waiting for review; it returns to their claim.
- td_submit says when held functions have no changed code in the working
  tree, instead of "you hold no tasks".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Saty 2026-10-22 12:37:10 +02:00
commit f542ad5cb2
14 changed files with 165 additions and 14 deletions

View file

@ -94,6 +94,15 @@ test('large numeric initializers are rejected', () => {
assert.ok(lintSubmission({ 'src/player.cpp': blob }, allowed).some((e) => e.message.includes('initializer')));
});
test('a file main already holds may be larger than the limit, and grow a little', () => {
const big = (kb) => 'int x;\n'.repeat(Math.ceil((kb * 1024) / 7));
const tooLarge = (files, sizes) => lintSubmission(files, { ...allowed, baseSize: (f) => sizes[f] ?? null }).filter((e) => /too large/.test(e.message));
assert.equal(tooLarge({ 'src/unit.cpp': big(300) }, {}).length, 1, 'a new 300 KB file');
assert.equal(tooLarge({ 'src/unit.cpp': big(820) }, { 'src/unit.cpp': 800 * 1024 }).length, 0, 'Unit_C.cpp with an edit');
assert.equal(tooLarge({ 'src/unit.cpp': big(1000) }, { 'src/unit.cpp': 800 * 1024 }).length, 1, 'grows by 200 KB');
assert.equal(tooLarge({ 'src/unit.cpp': big(800), 'src/player.cpp': big(500) }, { 'src/unit.cpp': 800 * 1024, 'src/player.cpp': 500 * 1024 }).length, 0, 'two big files count only what they add');
});
test('preprocessed output catches asm hidden behind macros, ignoring compiler headers', () => {
const pre = ['#line 1 "C:\\\\vc\\\\include\\\\intrin.h"', 'void sys() { __asm int 3 }', '#line 1 "z:\\\\job\\\\src\\\\player.cpp"', 'void f() { __asm { nop } }'].join('\n');
const errors = lintPreprocessed(pre, (f) => f.includes('/src/'));

View file

@ -58,3 +58,31 @@ test('a stale baseline is measured again on main before it counts as a regressio
assert.equal(compiles, 1);
assert.equal(events.length, 1);
});
// A header layout fix that moves a peer-confirmed function in another unit closer to the original
// is progress; moving it away is a regression its reviewers never saw.
test('a peer-confirmed function may move closer to the original, not away from it', () => {
const v = Object.create(Verifier.prototype);
v.repo = { git: () => '' };
v.store = { all: () => [{ symbol_id: 'fn_19918', file: 'WoW/Missile_C.cpp', status: 'mismatch', score: 0.9, confirmed: 1 }] };
const at = (score) => ({ units: [{ file: 'WoW/Missile_C.cpp', compiled: true, functions: [{ id: 'fn_19918', status: 'mismatch', score }] }] });
assert.deepEqual(v.regressions(at(0.905)), []);
assert.deepEqual(v.regressions(at(0.9)), []);
assert.deepEqual(v.regressions(at(0.895)).map((r) => r.was), ['peer-confirmed']);
});
// A function whose annotation an older merge removed from main (its record still says exact)
// is not "removed" by every later submission of the unit it was recorded at.
test('a function main no longer annotates is no regression', () => {
const v = Object.create(Verifier.prototype);
const found = [
{ id: 'fn_07162', file: 'Engine/SE3.cpp', was: 'exact', now: 'removed' },
{ id: 'fn_00009', file: 'Engine/SE3.cpp', was: 'exact', now: 'removed' },
];
v.repo = { git: () => 'HEAD:Engine/SE3.cpp:FUNCTION: fn_00009\n' };
assert.deepEqual(v.withoutHeaderCopies(found, new Map(), {}).map((r) => r.id), ['fn_00009'], 'still on main: removing it counts');
v.repo = { git: () => { throw Object.assign(new Error('git grep'), { status: 1 }); } };
assert.deepEqual(v.withoutHeaderCopies(found, new Map(), {}), []);
v.repo = { git: () => { throw Object.assign(new Error('git broke'), { status: 128 }); } };
assert.equal(v.withoutHeaderCopies(found, new Map(), {}).length, 2, 'main unknown: strict');
});

View file

@ -1415,3 +1415,26 @@ test('four "same" accept a function nobody objected to; five once someone did',
assert.equal(ctx.peers.submit(revs[4], disputed, 'same', why, null).state, 'peer_review', 'four "same" against one "different": not yet');
ctx.store.run(`UPDATE attempts SET state = 'superseded' WHERE id IN (?, ?)`, clean, disputed);
});
test('an author withdraws a function waiting for review: it leaves the queue and is theirs again', async () => {
const token = await activeUser('withdrawer');
const author = ctx.accounts.userByApiToken(token);
const other = ctx.accounts.userByApiToken(await activeUser('withdrawpeer'));
const saved = ctx.store.get(`SELECT id, state, lease_user, lease_expires FROM tasks WHERE state != 'done' ORDER BY id DESC LIMIT 1`);
const task = saved.id;
const head = ctx.repo.head();
const batch = Number(ctx.store.run(`INSERT INTO batches (user_id, base_commit, files_json, state, created_at) VALUES (?, ?, '{}', 'open', ?)`, author.id, head, now()).lastInsertRowid);
const attempt = Number(ctx.store.run(`INSERT INTO attempts (task_id, user_id, base_commit, files_json, state, batch_id, created_at) VALUES (?, ?, ?, '{}', 'peer_review', ?, ?)`, task, author.id, head, batch, now()).lastInsertRowid);
ctx.store.run(`UPDATE tasks SET state = 'peer_review' WHERE id = ?`, task);
ctx.store.run('INSERT INTO peer_leases (attempt_id, reviewer_id, expires_at) VALUES (?, ?, ?)', attempt, other.id, now() + 60_000);
assert.equal((await call('POST', `/api/attempts/${attempt}/withdraw`, {}, await activeUser('notauthor'))).status, 404, 'only the author');
const r = await call('POST', `/api/attempts/${attempt}/withdraw`, {}, token);
assert.equal(r.status, 200, JSON.stringify(r.body));
assert.equal(ctx.store.get('SELECT state FROM attempts WHERE id = ?', attempt).state, 'withdrawn');
assert.deepEqual({ ...ctx.store.get('SELECT state, lease_user FROM tasks WHERE id = ?', task) }, { state: 'leased', lease_user: author.id });
assert.equal(ctx.store.get('SELECT COUNT(*) AS n FROM peer_leases WHERE attempt_id = ?', attempt).n, 0);
assert.equal(ctx.store.get('SELECT state FROM batches WHERE id = ?', batch).state, 'returned', 'nothing else on its way');
assert.equal((await call('POST', `/api/attempts/${attempt}/withdraw`, {}, token)).status, 409, 'once');
ctx.store.run('UPDATE tasks SET state = ?, lease_user = ?, lease_expires = ? WHERE id = ?', saved.state, saved.lease_user, saved.lease_expires, task);
});