





















@@ -111,6 +111,21 @@ function requireFirstMockCallArg(mock: unknown, label: string) {
111111return requireRecord(call[0], `${label} argument`);
112112}
113113114+function loggerMessages(spy: unknown): string[] {
115+const calls = (spy as { mock?: { calls?: unknown[][] } }).mock?.calls ?? [];
116+return calls
117+.map((call) => call[0])
118+.filter((message): message is string => typeof message === "string");
119+}
120+121+function expectLoggerMessageContaining(spy: unknown, text: string): void {
122+expect(loggerMessages(spy).some((message) => message.includes(text))).toBe(true);
123+}
124+125+function expectNoLoggerMessageContaining(spy: unknown, text: string): void {
126+expect(loggerMessages(spy).some((message) => message.includes(text))).toBe(false);
127+}
128+114129function expectRecoveryCall(
115130recoverStuckSession: unknown,
116131fields: Record<string, unknown>,
@@ -434,10 +449,8 @@ describe("stuck session diagnostics threshold", () => {
434449reason: "active_work_without_progress",
435450activeWorkKind: "embedded_run",
436451});
437-expect(warnSpy).toHaveBeenCalledWith(
438-expect.stringContaining("lastProgress=embedded_run:started"),
439-);
440-expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("lastProgressAge=60s"));
452+expectLoggerMessageContaining(warnSpy, "lastProgress=embedded_run:started");
453+expectLoggerMessageContaining(warnSpy, "lastProgressAge=60s");
441454expect(recoverStuckSession).not.toHaveBeenCalled();
442455});
443456@@ -467,7 +480,7 @@ describe("stuck session diagnostics threshold", () => {
467480unsubscribe();
468481}
469482470-expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("terminalProgressStale=true"));
483+expectLoggerMessageContaining(warnSpy, "terminalProgressStale=true");
471484expectRecordFields(
472485requireRecord(
473486events.findLast((event) => event.type === "session.stalled"),
@@ -554,13 +567,19 @@ describe("stuck session diagnostics threshold", () => {
554567}
555568556569expect(recoverStuckSession).not.toHaveBeenCalled();
557-expect(events.findLast((event) => event.type === "session.stalled")).toMatchObject({
558-classification: "blocked_tool_call",
559-reason: "blocked_tool_call",
560-activeWorkKind: "tool_call",
561-activeToolName: "bash",
562-activeToolCallId: "cmd-1",
563-});
570+expectRecordFields(
571+requireRecord(
572+events.findLast((event) => event.type === "session.stalled"),
573+"stalled event",
574+),
575+{
576+classification: "blocked_tool_call",
577+reason: "blocked_tool_call",
578+activeWorkKind: "tool_call",
579+activeToolName: "bash",
580+activeToolCallId: "cmd-1",
581+},
582+);
564583});
565584566585it("uses diagnostics.stuckSessionAbortMs for stalled active-work recovery", () => {
@@ -773,7 +792,7 @@ describe("stuck session diagnostics threshold", () => {
773792reason: "active_work",
774793activeWorkKind: "embedded_run",
775794});
776-expect(warnSpy).not.toHaveBeenCalledWith(expect.stringContaining("long-running session:"));
795+expectNoLoggerMessageContaining(warnSpy, "long-running session:");
777796expect(recoverStuckSession).not.toHaveBeenCalled();
778797});
779798@@ -950,7 +969,7 @@ describe("stuck session diagnostics threshold", () => {
950969}
951970952971expect(events).toContain("diagnostic.liveness.warning");
953-expect(warnSpy).not.toHaveBeenCalledWith(expect.stringContaining("liveness warning:"));
972+expectNoLoggerMessageContaining(warnSpy, "liveness warning:");
954973expect(emitMemorySample).toHaveBeenLastCalledWith({ emitSample: true });
955974requireMatchingRecord(
956975getDiagnosticStabilitySnapshot({ limit: 10 }).events,
@@ -995,7 +1014,7 @@ describe("stuck session diagnostics threshold", () => {
9951014logMessageQueued({ sessionId: "s1", sessionKey: "main", source: "test" });
9961015vi.advanceTimersByTime(30_000);
9971016998-expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("liveness warning:"));
1017+expectLoggerMessageContaining(warnSpy, "liveness warning:");
9991018requireMatchingRecord(
10001019getDiagnosticStabilitySnapshot({ limit: 10 }).events,
10011020{
@@ -1052,8 +1071,8 @@ describe("stuck session diagnostics threshold", () => {
10521071unsubscribe();
10531072}
105410731055-expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("phase=startup.plugins.load"));
1056-expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("work=[queued=main("));
1074+expectLoggerMessageContaining(warnSpy, "phase=startup.plugins.load");
1075+expectLoggerMessageContaining(warnSpy, "work=[queued=main(");
10571076const warning = requireRecord(
10581077events.findLast((event) => event.type === "diagnostic.liveness.warning"),
10591078"liveness warning event",
@@ -1092,7 +1111,7 @@ describe("stuck session diagnostics threshold", () => {
10921111logSessionStateChange({ sessionId: "s1", sessionKey: "main", state: "processing" });
10931112vi.advanceTimersByTime(30_000);
109411131095-expect(warnSpy).not.toHaveBeenCalledWith(expect.stringContaining("liveness warning:"));
1114+expectNoLoggerMessageContaining(warnSpy, "liveness warning:");
10961115requireMatchingRecord(
10971116getDiagnosticStabilitySnapshot({ limit: 10 }).events,
10981117{
@@ -1132,7 +1151,7 @@ describe("stuck session diagnostics threshold", () => {
11321151logMessageQueued({ sessionId: "s1", sessionKey: "main", source: "test" });
11331152vi.advanceTimersByTime(30_000);
113411531135-expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("liveness warning:"));
1154+expectLoggerMessageContaining(warnSpy, "liveness warning:");
11361155});
1137115611381157it("throttles repeated liveness warnings", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。