fix(mobile): name the real reason a snooze was refused; share wake label
Addresses two Bugbot findings on the merge commit.
canSnooze refuses for two unrelated reasons — the agent is blocked on the
user, or a turn start is still queued — but the alert only described the
first. A user whose thread was mid-start went looking for a pending
request that didn't exist. Each branch now says what actually happened.
snoozeWakeLabel was duplicated almost line-for-line between web's
Sidebar.snooze.ts and mobile's threadListV2.ts, so the two platforms
could drift on the same thresholds. It now lives in client-runtime beside
canSnooze/effectiveSnoozed, which both platforms already import, and both
re-export it from where their callers expect. It takes `{ now: string }`
like every other function in that module — client-runtime's Effect lint
bans `new Date()` — which also makes a malformed clock degrade to "now"
rather than NaN. Its tests move to the owning package, keeping mobile's
sub-minute case that web's lacked.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
fb1a59e963
commit
cf2b02f8e9
10 files changed
+55
-68
No files matched your search
@@ -628,7 +628,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
snoozed={item.snoozed}
|
||||
snoozeWakeLabelText={
|
||||
item.snoozed && item.thread.snoozedUntil != null
|
||||
? snoozeWakeLabel(item.thread.snoozedUntil, new Date(`${nowMinute}:00.000Z`))
|
||||
? snoozeWakeLabel(item.thread.snoozedUntil, { now: `${nowMinute}:00.000Z` })
|
||||
: undefined
|
||||
}
|
||||
project={
|
||||
|
||||
@@ -229,9 +229,13 @@ export function useThreadListActions(): {
|
||||
return false;
|
||||
}
|
||||
if (!canSnooze(thread, { now: new Date().toISOString() })) {
|
||||
// canSnooze refuses for two unrelated reasons; naming the wrong one
|
||||
// sends the user looking for a request that isn't there.
|
||||
Alert.alert(
|
||||
"Could not snooze thread",
|
||||
"This thread is waiting on you. Respond to the pending request before snoozing it.",
|
||||
thread.hasPendingApprovals || thread.hasPendingUserInput
|
||||
? "This thread is waiting on you. Respond to the pending request before snoozing it."
|
||||
: "This thread is still starting a turn. Try again once it's running.",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -535,14 +535,14 @@ function ThreadNavigationSidebarPane(
|
||||
pendingTask,
|
||||
isLast: index === v2PendingTasks.length - 1,
|
||||
}));
|
||||
const snoozeLabelNow = new Date(`${nowMinute}:00.000Z`);
|
||||
const snoozeLabelNow = `${nowMinute}:00.000Z`;
|
||||
const threadRows: SidebarListItem[] = threadListV2Layout.items.map((item) => ({
|
||||
type: "v2-thread" as const,
|
||||
key: scopedThreadKey(item.thread.environmentId, item.thread.id),
|
||||
item,
|
||||
snoozeWakeLabelText:
|
||||
item.snoozed && item.thread.snoozedUntil != null
|
||||
? snoozeWakeLabel(item.thread.snoozedUntil, snoozeLabelNow)
|
||||
? snoozeWakeLabel(item.thread.snoozedUntil, { now: snoozeLabelNow })
|
||||
: undefined,
|
||||
}));
|
||||
// The shelf header is a row of its own: collapsed, it IS the shelf, so
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
resolveThreadListV2SnoozeGateExpiryMs,
|
||||
resolveThreadListV2SwipeActions,
|
||||
resolveThreadListV2Status,
|
||||
snoozeWakeLabel,
|
||||
sortThreadsForListV2,
|
||||
} from "./threadListV2";
|
||||
|
||||
@@ -134,21 +133,7 @@ describe("resolveThreadListV2SwipeActions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("snoozeWakeLabel", () => {
|
||||
const now = new Date("2026-06-02T00:00:00.000Z");
|
||||
|
||||
it("formats remaining time coarsely, rounding up", () => {
|
||||
expect(snoozeWakeLabel("2026-06-02T00:30:00.000Z", now)).toBe("30m");
|
||||
expect(snoozeWakeLabel("2026-06-02T01:30:00.000Z", now)).toBe("2h");
|
||||
expect(snoozeWakeLabel("2026-06-03T02:00:00.000Z", now)).toBe("2d");
|
||||
});
|
||||
|
||||
it("never reads zero or negative while still snoozed", () => {
|
||||
expect(snoozeWakeLabel("2026-06-02T00:00:30.000Z", now)).toBe("1m");
|
||||
expect(snoozeWakeLabel("2026-06-01T23:59:59.000Z", now)).toBe("now");
|
||||
expect(snoozeWakeLabel("not-a-date", now)).toBe("now");
|
||||
});
|
||||
});
|
||||
// snoozeWakeLabel itself is covered in client-runtime, where it lives.
|
||||
|
||||
describe("resolveThreadListV2SnoozeGateExpiryMs", () => {
|
||||
it("reports when an unadopted turn's grace window lapses", () => {
|
||||
|
||||
@@ -4,6 +4,10 @@ import {
|
||||
hasQueuedTurnStart,
|
||||
QUEUED_TURN_START_GRACE_MS,
|
||||
} from "@t3tools/client-runtime/state/thread-settled";
|
||||
|
||||
// Wake labels live with the rest of the snooze model so web and mobile can
|
||||
// never drift; re-exported here because this module is the list's one stop.
|
||||
export { snoozeWakeLabel } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
||||
import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
|
||||
|
||||
@@ -45,25 +49,6 @@ export function resolveThreadListV2SwipeActions(input: {
|
||||
};
|
||||
}
|
||||
|
||||
const HOUR_MS = 60 * 60 * 1_000;
|
||||
const DAY_MS = 24 * HOUR_MS;
|
||||
|
||||
/**
|
||||
* Compact "wakes in" label for snoozed rows: "2h", "18h", "3d". Minutes
|
||||
* round up so a snooze never reads "0m" while still hidden. Ported from
|
||||
* web's snoozeWakeLabel (apps/web/src/components/Sidebar.snooze.ts) so both
|
||||
* platforms describe a wake time identically.
|
||||
*/
|
||||
export function snoozeWakeLabel(snoozedUntil: string, now: Date): string {
|
||||
const wakeMs = Date.parse(snoozedUntil);
|
||||
if (Number.isNaN(wakeMs)) return "now";
|
||||
const remainingMs = wakeMs - now.getTime();
|
||||
if (remainingMs <= 0) return "now";
|
||||
if (remainingMs < HOUR_MS) return `${Math.max(1, Math.ceil(remainingMs / 60_000))}m`;
|
||||
if (remainingMs < DAY_MS) return `${Math.ceil(remainingMs / HOUR_MS)}h`;
|
||||
return `${Math.ceil(remainingMs / DAY_MS)}d`;
|
||||
}
|
||||
|
||||
/**
|
||||
* When a thread's snooze eligibility can flip on its own, as epoch ms — the
|
||||
* moment the queued-turn-start grace window expires and `canSnooze` starts
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { resolveSnoozePresets, snoozeWakeDescription, snoozeWakeLabel } from "./Sidebar.snooze";
|
||||
import { resolveSnoozePresets, snoozeWakeDescription } from "./Sidebar.snooze";
|
||||
|
||||
// Local-time constructor so preset math is timezone-stable in tests.
|
||||
function localDate(year: number, month: number, day: number, hour: number, minute = 0): Date {
|
||||
@@ -64,20 +64,7 @@ describe("resolveSnoozePresets", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("snoozeWakeLabel", () => {
|
||||
const now = localDate(2026, 4, 8, 10);
|
||||
|
||||
it("formats minutes, hours, and days, rounding up", () => {
|
||||
expect(snoozeWakeLabel(new Date(now.getTime() + 30 * 60_000).toISOString(), now)).toBe("30m");
|
||||
expect(snoozeWakeLabel(new Date(now.getTime() + 90 * 60_000).toISOString(), now)).toBe("2h");
|
||||
expect(snoozeWakeLabel(new Date(now.getTime() + 26 * 3_600_000).toISOString(), now)).toBe("2d");
|
||||
});
|
||||
|
||||
it("reports now for past and malformed wake times", () => {
|
||||
expect(snoozeWakeLabel(new Date(now.getTime() - 1000).toISOString(), now)).toBe("now");
|
||||
expect(snoozeWakeLabel("not-a-date", now)).toBe("now");
|
||||
});
|
||||
});
|
||||
// snoozeWakeLabel now lives in client-runtime and is tested there.
|
||||
|
||||
describe("snoozeWakeDescription", () => {
|
||||
const now = localDate(2026, 4, 8, 10);
|
||||
|
||||
@@ -93,19 +93,8 @@ export function resolveSnoozePresets(now: Date): ReadonlyArray<SnoozePreset> {
|
||||
return presets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compact "wakes in" label for snoozed rows: "2h", "18h", "3d". Minutes
|
||||
* round up so a snooze never reads "0m" while still hidden.
|
||||
*/
|
||||
export function snoozeWakeLabel(snoozedUntil: string, now: Date): string {
|
||||
const wake = parseTimestampDate(snoozedUntil);
|
||||
if (wake === null) return "now";
|
||||
const remainingMs = wake.getTime() - now.getTime();
|
||||
if (remainingMs <= 0) return "now";
|
||||
if (remainingMs < HOUR_MS) return `${Math.max(1, Math.ceil(remainingMs / 60_000))}m`;
|
||||
if (remainingMs < DAY_MS) return `${Math.ceil(remainingMs / HOUR_MS)}h`;
|
||||
return `${Math.ceil(remainingMs / DAY_MS)}d`;
|
||||
}
|
||||
/** Shared with mobile so a wake time never reads differently per platform. */
|
||||
export { snoozeWakeLabel } from "@t3tools/client-runtime/state/thread-settled";
|
||||
|
||||
/**
|
||||
* Human wake time for menus and toasts: "tomorrow 9:00", "Mon 9:00",
|
||||
|
||||
@@ -2417,7 +2417,7 @@ export default function SidebarV2() {
|
||||
}
|
||||
snoozeWakeLabelText={
|
||||
section === "snoozed" && thread.snoozedUntil != null
|
||||
? snoozeWakeLabel(thread.snoozedUntil, new Date())
|
||||
? snoozeWakeLabel(thread.snoozedUntil, { now: new Date().toISOString() })
|
||||
: null
|
||||
}
|
||||
// All sections: a woken thread can classify straight
|
||||
|
||||
@@ -295,3 +295,22 @@ export function effectiveSettled(
|
||||
Date.parse(lastActivityAt) < Date.parse(options.now) - options.autoSettleAfterDays * DAY_MS
|
||||
);
|
||||
}
|
||||
|
||||
const HOUR_MS = 60 * 60 * 1_000;
|
||||
|
||||
/**
|
||||
* Compact "wakes in" label for snoozed rows: "2h", "18h", "3d". Minutes
|
||||
* round up so a snooze never reads "0m" while still hidden. Shared by web's
|
||||
* sidebar and the mobile thread list so a wake time never reads differently
|
||||
* across platforms.
|
||||
*/
|
||||
export function snoozeWakeLabel(snoozedUntil: string, options: { readonly now: string }): string {
|
||||
const wakeMs = Date.parse(snoozedUntil);
|
||||
const nowMs = Date.parse(options.now);
|
||||
if (Number.isNaN(wakeMs) || Number.isNaN(nowMs)) return "now";
|
||||
const remainingMs = wakeMs - nowMs;
|
||||
if (remainingMs <= 0) return "now";
|
||||
if (remainingMs < HOUR_MS) return `${Math.max(1, Math.ceil(remainingMs / 60_000))}m`;
|
||||
if (remainingMs < DAY_MS) return `${Math.ceil(remainingMs / HOUR_MS)}h`;
|
||||
return `${Math.ceil(remainingMs / DAY_MS)}d`;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
import {
|
||||
canSnooze,
|
||||
effectiveSnoozed,
|
||||
snoozeWakeLabel,
|
||||
threadRaisedHandWhileSnoozed,
|
||||
threadWokeAt,
|
||||
type ThreadSnoozeShell,
|
||||
@@ -235,3 +236,20 @@ describe("threadWokeAt", () => {
|
||||
).toBe("2026-04-10T09:30:00.000Z");
|
||||
});
|
||||
});
|
||||
|
||||
describe("snoozeWakeLabel", () => {
|
||||
const now = "2026-06-02T00:00:00.000Z";
|
||||
|
||||
it("formats remaining time coarsely, rounding up", () => {
|
||||
expect(snoozeWakeLabel("2026-06-02T00:30:00.000Z", { now })).toBe("30m");
|
||||
expect(snoozeWakeLabel("2026-06-02T01:30:00.000Z", { now })).toBe("2h");
|
||||
expect(snoozeWakeLabel("2026-06-03T02:00:00.000Z", { now })).toBe("2d");
|
||||
});
|
||||
|
||||
it("never reads zero or negative while still snoozed", () => {
|
||||
expect(snoozeWakeLabel("2026-06-02T00:00:30.000Z", { now })).toBe("1m");
|
||||
expect(snoozeWakeLabel("2026-06-01T23:59:59.000Z", { now })).toBe("now");
|
||||
expect(snoozeWakeLabel("not-a-date", { now })).toBe("now");
|
||||
expect(snoozeWakeLabel("2026-06-02T09:00:00.000Z", { now: "bad" })).toBe("now");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user