Skip to content
11 changes: 5 additions & 6 deletions integration-tests/interactive/file-system-interactive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,18 @@ describe('Interactive file system', () => {

// The tool call is logged once the model issues it, but the turn may
// still be settling (a failed edit can be retried) and the model may
// append a trailing newline. Poll the file until it reflects the new
// version instead of reading it once.
// write more than just '1.0.1'. Poll the file until it contains the new
// version, matching the lenient assertion used by the non-interactive
// sibling test (file-system.test.ts uses .toContain('1.0.1')).
const updated = await rig.poll(
() => rig.readFile(fileName).trimEnd() === '1.0.1',
() => rig.readFile(fileName).includes('1.0.1'),
rig.getDefaultTimeout(),
200,
);
if (!updated) {
printDebugInfo(rig, rig._interactiveOutput, { toolCall });
}
expect(updated, 'Expected file content to be updated to 1.0.1').toBe(
true,
);
expect(updated, 'Expected file content to contain 1.0.1').toBe(true);
},
);
});
31 changes: 22 additions & 9 deletions integration-tests/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,20 +544,33 @@ export class TestRig {
): Promise<boolean> {
const startTime = Date.now();
let attempts = 0;
let lastError: unknown;
while (Date.now() - startTime < timeout) {
attempts++;
const result = predicate();
if (env['VERBOSE'] === 'true' && attempts % 5 === 0) {
console.log(
`Poll attempt ${attempts}: ${result ? 'success' : 'waiting...'}`,
);
}
if (result) {
return true;
try {
const result = predicate();
lastError = undefined;
if (env['VERBOSE'] === 'true' && attempts % 5 === 0) {
console.log(
`Poll attempt ${attempts}: ${result ? 'success' : 'waiting...'}`,
);
}
if (result) {
return true;
}
} catch (err) {
lastError = err;
if (env['VERBOSE'] === 'true') {
console.log(`Poll attempt ${attempts}: predicate threw: ${err}`);
}
}
await new Promise((resolve) => setTimeout(resolve, interval));
}
if (env['VERBOSE'] === 'true') {
if (lastError) {
console.log(
`Poll timed out after ${attempts} attempts. Last error: ${lastError}`,
);
} else if (env['VERBOSE'] === 'true') {
console.log(`Poll timed out after ${attempts} attempts`);
}
return false;
Expand Down
Loading