From dab2f90051caefe29862e38c4ced7bfa5fea74f8 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Tue, 24 Feb 2026 21:43:52 +0900 Subject: [PATCH] test(run): make completion metadata timing assertion deterministic Avoid Date.now call-order flakiness by pinning the mocked current time and setting the message start time explicitly in the test setup. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- src/cli/run/event-handlers.test.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cli/run/event-handlers.test.ts b/src/cli/run/event-handlers.test.ts index 267b394c..b6687cf7 100644 --- a/src/cli/run/event-handlers.test.ts +++ b/src/cli/run/event-handlers.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, spyOn } from "bun:test" +const { describe, it, expect, spyOn } = require("bun:test") import type { RunContext } from "./types" import { createEventState } from "./events" import { handleSessionStatus, handleMessagePartUpdated, handleMessageUpdated, handleTuiToast } from "./event-handlers" @@ -235,9 +235,7 @@ describe("handleMessagePartUpdated", () => { it("prints completion metadata once when assistant text part is completed", () => { // given - const nowSpy = spyOn(Date, "now") - nowSpy.mockReturnValueOnce(1000) - nowSpy.mockReturnValueOnce(3400) + const nowSpy = spyOn(Date, "now").mockReturnValue(3400) const ctx = createMockContext("ses_main") const state = createEventState() @@ -259,6 +257,7 @@ describe("handleMessagePartUpdated", () => { } as any, state, ) + state.messageStartedAtById["msg_1"] = 1000 // when handleMessagePartUpdated(