mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-19 06:34:43 +01:00
Two owner-answer adds at once no longer collide, and three flaky tests get real fixes (GST-3084) (#4490)
Recording the same owner answer from two processes at once no longer fails about one time in ten; the second add waits for the first to finish writing. Why: this was a daily flaky-test repair, and the owner-answers "two processes adding at once" failure turned out to be a real race, not a flaky test. Nothing to do: tests only change, except the 11 lines in `lib/owner-answers.ts`. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing
This commit is contained in:
1 parent
bf2c126b55
commit
782f4595ed
6 files changed
+39
-6
No files matched your search
@@ -5,7 +5,7 @@
|
||||
* floor, named patch-id refusal and branch-touched walk; the digit-bounded
|
||||
* stamp replacement.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
@@ -19,6 +19,7 @@ import { gitArgvIn } from './helpers/scratch-repo';
|
||||
const repos: FixtureRepo[] = [];
|
||||
const fixture = (opts: Parameters<typeof makeFixtureRepo>[0] = {}) => { const r = makeFixtureRepo({ prefix: 'ship-receipt-2-', ...opts }); repos.push(r); return r; };
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
setDefaultTimeout(30_000);
|
||||
|
||||
/** A repository with no VERSION, no package.json, no CHANGELOG and no policy: the shape E18 names. */
|
||||
function bareRepo(): FixtureRepo {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* a PR (RECEIPT_MISSING / RECEIPT_INVALID); `census` computes the P7 adoption
|
||||
* number over merged PRs, deduplicated by run and thread, against a cohort.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
@@ -15,6 +15,7 @@ import { cleanup, ghShim, makeFixtureRepo, makePr, recordAndBundle, restamp, run
|
||||
const repos: FixtureRepo[] = [];
|
||||
const fixture = () => { const r = makeFixtureRepo({ prefix: 'ship-receipt-' }); repos.push(r); return r; };
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
setDefaultTimeout(30_000);
|
||||
|
||||
const HEAD = 'a'.repeat(40);
|
||||
const block = (receipt: Record<string, unknown>) => renderReceiptBlock(receipt as any);
|
||||
|
||||
@@ -237,6 +237,27 @@ describe('fail closed', () => {
|
||||
expect((addAnswer(s, twin) as any).code).toBe('OWNER_ANSWERS_CONFLICT');
|
||||
expect(readStore(s).rows.map(r => r.words)).toEqual(['yes merge when green']);
|
||||
});
|
||||
test('an add that finds its row created but not yet written waits for the other add, then reports it present', async () => {
|
||||
const s = store();
|
||||
const row = buildAnswer(s, MERGE) as OwnerAnswer;
|
||||
const file = path.join(s.dir, 'rows', `${row.id}.json`);
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true });
|
||||
fs.writeFileSync(file, '');
|
||||
const writer = spawn('bun', [...bunIsolationArgs(), '-e', 'console.log("ready"); setTimeout(() => require("fs").writeFileSync(process.env.F, process.env.J), 200)'], { env: { ...process.env, F: file, J: JSON.stringify(row) }, timeout: 60_000 });
|
||||
const closed = new Promise(resolve => writer.on('close', resolve));
|
||||
await new Promise(resolve => writer.stdout.once('data', resolve));
|
||||
expect(addAnswer(s, row)).toBe('present');
|
||||
await closed;
|
||||
expect(readStore(s).rows.map(r => r.id)).toEqual([row.id]);
|
||||
}, 120_000);
|
||||
test('a row file that stays empty is still a conflict once the wait runs out', () => {
|
||||
const s = store();
|
||||
const row = buildAnswer(s, MERGE) as OwnerAnswer;
|
||||
const file = path.join(s.dir, 'rows', `${row.id}.json`);
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true });
|
||||
fs.writeFileSync(file, '');
|
||||
expect((addAnswer(s, row) as any).code).toBe('OWNER_ANSWERS_CONFLICT');
|
||||
});
|
||||
test('supersede through the API refuses a missing row', () => {
|
||||
const s = store();
|
||||
const row = buildAnswer(s, { ...MERGE, supersedes: 'oa-ffffffffffffffff' }) as OwnerAnswer;
|
||||
|
||||
@@ -56,11 +56,13 @@ function repo() {
|
||||
return { dir, git, run, write };
|
||||
}
|
||||
|
||||
// ---- The pre-fix buffered path (lib/sealed-guard.ts at 0ead11c), verbatim but for the injectable maxBuffer. ----
|
||||
// ---- The pre-fix buffered path (lib/sealed-guard.ts at 0ead11c), verbatim but for the injectable maxBuffer and one
|
||||
// change in oldGit: a spawn error counts as a failure. When git exits before the overflow kill lands, Bun reports
|
||||
// status 0 with error ENOBUFS and a truncated stdout, so a status-only check let a loaded runner read part of the diff. ----
|
||||
const HEX = /^[0-9a-f]{40,64}$/;
|
||||
function oldGit(repoRoot: string, args: string[], maxBuffer: number, input?: string, encoding: BufferEncoding = 'utf8') {
|
||||
const r = spawnSync('git', args, { cwd: repoRoot, encoding, input, timeout: 120_000, maxBuffer });
|
||||
return { ok: r.status === 0, out: r.stdout ?? '', err: (r.stderr ?? '').trim() };
|
||||
return { ok: r.status === 0 && !r.error, out: r.stdout ?? '', err: (r.stderr ?? '').trim() };
|
||||
}
|
||||
function oldTextFindings(repoRoot: string, commits: string[], p: SealedPolicy, maxBuffer: number): SealedFinding[] {
|
||||
const rules: Array<[SealedFinding['rule'], RegExp]> = [
|
||||
|
||||
Reference in new issue
Block a user