test(agents): dedupe generic repeat loop fixtures

This commit is contained in:
Peter Steinberger
2026-02-19 08:33:49 +00:00
parent e4bb6e044d
commit 65cf56d482

View File

@@ -109,6 +109,18 @@ describe("before_tool_call loop detection behavior", () => {
}
}
}
function createGenericReadRepeatFixture() {
const execute = vi.fn().mockResolvedValue({
content: [{ type: "text", text: "same output" }],
details: { ok: true },
});
return {
tool: createWrappedTool("read", execute),
params: { path: "/tmp/file" },
};
}
it("blocks known poll loops when no progress repeats", async () => {
const execute = vi.fn().mockResolvedValue({
content: [{ type: "text", text: "(no new output)\n\nProcess still running." }],
@@ -160,12 +172,7 @@ describe("before_tool_call loop detection behavior", () => {
});
it("keeps generic repeated calls warn-only below global breaker", async () => {
const execute = vi.fn().mockResolvedValue({
content: [{ type: "text", text: "same output" }],
details: { ok: true },
});
const tool = createWrappedTool("read", execute);
const params = { path: "/tmp/file" };
const { tool, params } = createGenericReadRepeatFixture();
for (let i = 0; i < CRITICAL_THRESHOLD + 5; i += 1) {
await expect(tool.execute(`read-${i}`, params, undefined, undefined)).resolves.toBeDefined();
@@ -173,12 +180,7 @@ describe("before_tool_call loop detection behavior", () => {
});
it("blocks generic repeated no-progress calls at global breaker threshold", async () => {
const execute = vi.fn().mockResolvedValue({
content: [{ type: "text", text: "same output" }],
details: { ok: true },
});
const tool = createWrappedTool("read", execute);
const params = { path: "/tmp/file" };
const { tool, params } = createGenericReadRepeatFixture();
for (let i = 0; i < GLOBAL_CIRCUIT_BREAKER_THRESHOLD; i += 1) {
await expect(tool.execute(`read-${i}`, params, undefined, undefined)).resolves.toBeDefined();
@@ -192,12 +194,7 @@ describe("before_tool_call loop detection behavior", () => {
it("coalesces repeated generic warning events into threshold buckets", async () => {
await withToolLoopEvents(
async (emitted) => {
const execute = vi.fn().mockResolvedValue({
content: [{ type: "text", text: "same output" }],
details: { ok: true },
});
const tool = createWrappedTool("read", execute);
const params = { path: "/tmp/file" };
const { tool, params } = createGenericReadRepeatFixture();
for (let i = 0; i < 21; i += 1) {
await tool.execute(`read-bucket-${i}`, params, undefined, undefined);