Skip to content

Commit 7480f56

Browse files
authored
fix: better bisect handling (#15)
1 parent 4097790 commit 7480f56

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/runner.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,10 @@ export class Runner {
244244
);
245245

246246
// bisect through the releases
247-
let left = 0;
248-
let right = versions.length - 1;
247+
const LEFT_POS = 0;
248+
const RIGHT_POS = versions.length - 1;
249+
let left = LEFT_POS;
250+
let right = RIGHT_POS;
249251
let result: TestResult | undefined = undefined;
250252
const testOrder: (number | undefined)[] = [];
251253
const results = new Array<TestResult>(versions.length);
@@ -258,7 +260,6 @@ export class Runner {
258260
result = await this.run(ver.version, fiddle, opts);
259261
results[mid] = result;
260262
log(`${Runner.displayResult(result)} ${versions[mid].version}\n`);
261-
262263
if (result.status === 'test_passed') {
263264
left = mid;
264265
continue;
@@ -270,6 +271,19 @@ export class Runner {
270271
}
271272
}
272273

274+
// validates the status of the boundary versions if we've reached the end
275+
// of the bisect and one of our pointers is at a boundary.
276+
277+
const boundaries: Array<number> = [];
278+
if (left === LEFT_POS && !results[LEFT_POS]) boundaries.push(LEFT_POS);
279+
if (right === RIGHT_POS && !results[RIGHT_POS]) boundaries.push(RIGHT_POS);
280+
281+
for (const position of boundaries) {
282+
const result = await this.run(versions[position].version, fiddle, opts);
283+
results[position] = result;
284+
log(`${Runner.displayResult(result)} ${versions[position].version}\n`);
285+
}
286+
273287
log(`🏁 finished bisecting across ${versions.length} versions...`);
274288
versions.forEach((ver, i) => {
275289
const n = testOrder.indexOf(i);
@@ -297,19 +311,25 @@ export class Runner {
297311
`https://github.com/electron/electron/compare/v${good}...v${bad} ↔`,
298312
].join('\n'),
299313
);
300-
} else {
301-
// FIXME: log some failure
302-
}
303314

304-
if (success) {
305315
return {
306316
range: [versions[left].version, versions[right].version],
307317
status: 'bisect_succeeded',
308318
};
319+
} else {
320+
// FIXME: log some failure
321+
if (
322+
result?.status === 'test_error' ||
323+
result?.status === 'system_error'
324+
) {
325+
return { status: result.status };
326+
}
327+
328+
if (results[left].status === results[right].status) {
329+
return { status: 'test_error' };
330+
}
331+
332+
return { status: 'system_error' };
309333
}
310-
if (result?.status === 'test_error' || result?.status === 'system_error') {
311-
return { status: result.status };
312-
}
313-
return { status: 'system_error' };
314334
}
315335
}

tests/runner.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe('Runner', () => {
187187
});
188188

189189
describe('bisect()', () => {
190-
it.skip('can bisect a test (right side range)', async () => {
190+
it('can bisect a test (right side range)', async () => {
191191
const runner = await createFakeRunner({});
192192
const resultMap: Map<string, TestResult> = new Map([
193193
['12.0.0', { status: 'test_passed' }],
@@ -241,7 +241,7 @@ describe('Runner', () => {
241241
});
242242
});
243243

244-
it.skip('can handle the trivial case', async () => {
244+
it('can handle the trivial case', async () => {
245245
const runner = await createFakeRunner({});
246246
const resultMap: Map<string, TestResult> = new Map([
247247
['12.0.0', { status: 'test_passed' }],
@@ -275,7 +275,7 @@ describe('Runner', () => {
275275
).rejects.toEqual(new Error(`Invalid fiddle: "'invalid-fiddle'"`));
276276
});
277277

278-
it.skip.each([['test_error' as const], ['system_error' as const]])(
278+
it.each([['test_error' as const], ['system_error' as const]])(
279279
'returns %s status if encountered during a test',
280280
async (status) => {
281281
const runner = await createFakeRunner({});

0 commit comments

Comments
 (0)