Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/api/src/agents/files/processing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,35 @@ describe('worker lifecycle', () => {
}
});

it.each([false, true])(
'keeps timers running while a worker reply is pending, warm=%s',
async (warm) => {
const processor = createHostEditProcessor(fixture);
const controller = new AbortController();
try {
if (warm) await processor.apply('ready', [edit]);
let settled = false;
const pending = processor.apply('wait', [edit], undefined, controller.signal).then(
() => {
settled = true;
return 'completed';
},
(error: Error) => {
settled = true;
return error.name;
},
);
await new Promise<void>((resolve) => setTimeout(resolve, 0));
expect(settled).toBe(false);
controller.abort();
await expect(pending).resolves.toBe('AbortError');
} finally {
controller.abort();
await processor.close();
}
},
);

it('has no queue and releases capacity only after cancellation terminates the worker', async () => {
const processor = createHostEditProcessor(fixture);
const controller = new AbortController();
Expand Down
8 changes: 1 addition & 7 deletions packages/api/src/agents/handlers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5545,7 +5545,7 @@ describe('createToolExecuteHandler', () => {
];

it.each(['SKILL.md', 'references/a.md'])(
'rejects compact amplification atomically for %s without starving timers',
'rejects compact amplification atomically for %s',
async (file) => {
const updateSkill = jest.fn();
const saveSkillFileContent = jest.fn();
Expand All @@ -5570,21 +5570,15 @@ describe('createToolExecuteHandler', () => {
updateSkill,
saveSkillFileContent,
});
let timerFired = false;
const timer = setTimeout(() => {
timerFired = true;
}, 0);
const [result] = await invokeHandler(handler, [
{
id: 'amplification',
name: 'edit_file',
args: { path: `skills/bounded-skill/${file}`, edits: amplificationEdits() },
},
]);
clearTimeout(timer);
expect(result.status).toBe('error');
expect(result.errorMessage).toContain('budget exceeded');
expect(timerFired).toBe(true);
expect(updateSkill).not.toHaveBeenCalled();
expect(saveSkillFileContent).not.toHaveBeenCalled();
},
Expand Down
Loading