@@ -30,6 +30,16 @@ const state = vi.hoisted(() => ({
|
30 | 30 | runEmbeddedPiAgentMock: vi.fn(), |
31 | 31 | })); |
32 | 32 | |
| 33 | +function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number { |
| 34 | +let count = 0; |
| 35 | +for (const item of items) { |
| 36 | +if (predicate(item)) { |
| 37 | +count += 1; |
| 38 | +} |
| 39 | +} |
| 40 | +return count; |
| 41 | +} |
| 42 | + |
33 | 43 | let modelFallbackModule: typeof import("../../agents/model-fallback.js"); |
34 | 44 | let onAgentEvent: typeof import("../../infra/agent-events.js").onAgentEvent; |
35 | 45 | |
@@ -1000,8 +1010,8 @@ describe("runReplyAgent typing (heartbeat)", () => {
|
1000 | 1010 | expect(firstText).toContain("Model Fallback:"); |
1001 | 1011 | expect(secondText).toContain("Model Fallback cleared:"); |
1002 | 1012 | expect(thirdText).not.toContain("Model Fallback cleared:"); |
1003 | | -expect(phases.filter((phase) => phase === "fallback")).toHaveLength(1); |
1004 | | -expect(phases.filter((phase) => phase === "fallback_cleared")).toHaveLength(1); |
| 1013 | +expect(countMatching(phases, (phase) => phase === "fallback")).toBe(1); |
| 1014 | +expect(countMatching(phases, (phase) => phase === "fallback_cleared")).toBe(1); |
1005 | 1015 | } finally { |
1006 | 1016 | fallbackSpy.mockRestore(); |
1007 | 1017 | } |
@@ -1077,8 +1087,8 @@ describe("runReplyAgent typing (heartbeat)", () => {
|
1077 | 1087 | const secondText = Array.isArray(second) ? second[0]?.text : second?.text; |
1078 | 1088 | expect(firstText).not.toContain("Model Fallback:"); |
1079 | 1089 | expect(secondText).not.toContain("Model Fallback cleared:"); |
1080 | | -expect(phases.filter((phase) => phase === "fallback")).toHaveLength(1); |
1081 | | -expect(phases.filter((phase) => phase === "fallback_cleared")).toHaveLength(1); |
| 1090 | +expect(countMatching(phases, (phase) => phase === "fallback")).toBe(1); |
| 1091 | +expect(countMatching(phases, (phase) => phase === "fallback_cleared")).toBe(1); |
1082 | 1092 | } finally { |
1083 | 1093 | fallbackSpy.mockRestore(); |
1084 | 1094 | } |
|