diff --git a/apps/mobile/src/features/agent-awareness/updatedAtLabel.test.ts b/apps/mobile/src/features/agent-awareness/updatedAtLabel.test.ts deleted file mode 100644 index 25d234e451..0000000000 --- a/apps/mobile/src/features/agent-awareness/updatedAtLabel.test.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { describe, expect, it } from "@effect/vitest"; - -import { formatAgentActivityUpdatedAtLabel } from "./updatedAtLabel"; - -describe("formatAgentActivityUpdatedAtLabel", () => { - it("formats ISO timestamps without using ambient time APIs", () => { - expect(formatAgentActivityUpdatedAtLabel("2026-05-25T00:03:00.000Z")).toBe("12:03"); - expect(formatAgentActivityUpdatedAtLabel("2026-05-25T09:45:00.000Z")).toBe("9:45"); - expect(formatAgentActivityUpdatedAtLabel("2026-05-25T13:07:00.000Z")).toBe("1:07"); - }); - - it("uses now for malformed timestamps", () => { - expect(formatAgentActivityUpdatedAtLabel("not-a-date")).toBe("now"); - expect(formatAgentActivityUpdatedAtLabel("2026-05-25T24:00:00.000Z")).toBe("now"); - }); -}); diff --git a/apps/mobile/src/features/agent-awareness/updatedAtLabel.ts b/apps/mobile/src/features/agent-awareness/updatedAtLabel.ts deleted file mode 100644 index c721c98f4f..0000000000 --- a/apps/mobile/src/features/agent-awareness/updatedAtLabel.ts +++ /dev/null @@ -1,12 +0,0 @@ -const ISO_TIME_PATTERN = /^\d{4}-\d{2}-\d{2}T(?\d{2}):(?\d{2}):/; - -export function formatAgentActivityUpdatedAtLabel(updatedAt: string): string { - const match = ISO_TIME_PATTERN.exec(updatedAt); - const hours24 = Number(match?.groups?.hours); - const minutes = match?.groups?.minutes; - if (!Number.isInteger(hours24) || hours24 < 0 || hours24 > 23 || !minutes) { - return "now"; - } - - return `${hours24 % 12 || 12}:${minutes}`; -} diff --git a/apps/mobile/src/widgets/AgentActivity.test.ts b/apps/mobile/src/widgets/AgentActivity.test.ts new file mode 100644 index 0000000000..03ba05283c --- /dev/null +++ b/apps/mobile/src/widgets/AgentActivity.test.ts @@ -0,0 +1,49 @@ +import { describe, expect, it, vi } from "vitest"; + +vi.mock("@expo/ui/swift-ui", () => ({ + HStack: "HStack", + Spacer: "Spacer", + Text: "Text", + VStack: "VStack", +})); + +vi.mock("@expo/ui/swift-ui/modifiers", () => ({ + font: (value: unknown) => value, + foregroundStyle: (value: unknown) => value, + lineLimit: (value: unknown) => value, + padding: (value: unknown) => value, +})); + +vi.mock("expo-widgets", () => ({ + createLiveActivity: vi.fn((name: string, layout: unknown) => ({ layout, name })), +})); + +import { AgentActivity, type AgentActivityProps } from "./AgentActivity"; + +const props = { + title: "T3 Code", + subtitle: "Agent work in progress", + activeCount: 1, + updatedAt: "2026-05-25T13:07:00.000Z", + activities: [], +} satisfies AgentActivityProps; + +const environment = { + colorScheme: "dark", + isLuminanceReduced: false, +} as const; + +describe("AgentActivity widget layout", () => { + it("formats its updated-at label without app-runtime helper references", () => { + expect(JSON.stringify(AgentActivity(props, environment as never))).toContain( + '"children":["Updated ","1:07"]', + ); + expect(AgentActivity.toString()).not.toContain("formatAgentActivityUpdatedAtLabel"); + }); + + it("uses now when the updated-at timestamp is malformed", () => { + expect( + JSON.stringify(AgentActivity({ ...props, updatedAt: "not-a-date" }, environment as never)), + ).toContain('"children":["Updated ","now"]'); + }); +}); diff --git a/apps/mobile/src/widgets/AgentActivity.tsx b/apps/mobile/src/widgets/AgentActivity.tsx index 58c65bef2b..5cbd6c442f 100644 --- a/apps/mobile/src/widgets/AgentActivity.tsx +++ b/apps/mobile/src/widgets/AgentActivity.tsx @@ -5,7 +5,6 @@ import { type LiveActivityComponent, type LiveActivityLayout, } from "expo-widgets"; -import { formatAgentActivityUpdatedAtLabel } from "../features/agent-awareness/updatedAtLabel"; type LiveActivityEnvironment = Parameters>[1]; @@ -38,7 +37,7 @@ export interface AgentActivityProps { readonly activities: ReadonlyArray; } -function AgentActivity( +export function AgentActivity( props: AgentActivityProps, environment: LiveActivityEnvironment, ): LiveActivityLayout { @@ -47,7 +46,16 @@ function AgentActivity( const row0 = props.activities[0]; const row1 = props.activities[1]; const row2 = props.activities[2]; - const updatedAt = formatAgentActivityUpdatedAtLabel(props.updatedAt); + const updatedAtMatch = /^\d{4}-\d{2}-\d{2}T(\d{2}):(\d{2}):/.exec(props.updatedAt); + const updatedAtHours24 = Number(updatedAtMatch?.[1]); + const updatedAtMinutes = updatedAtMatch?.[2]; + const updatedAt = + Number.isInteger(updatedAtHours24) && + updatedAtHours24 >= 0 && + updatedAtHours24 <= 23 && + updatedAtMinutes + ? `${updatedAtHours24 % 12 || 12}:${updatedAtMinutes}` + : "now"; const activeLabel = `${props.activeCount} active`; const isLight = environment.colorScheme === "light"; const primaryForeground = isLight ? "#0f172a" : "#ffffff";