Files
loki/scripts/test/late-night.ts
CatoandClaude 6bf6142b63 feat: live-fix messages open "Watch the fix"; late at night Control says go to sleep, autopilot has it (#1078)
Fix walkthroughs:
- New /feedback/<id>/watch-fix mints a fresh owner tour ticket on every
  open and lands on the live page's walkthrough (inbox when there is no
  live page or no access). A ticket lasts a day; a Telegram message lasts
  forever, so messages carry this address, not a ticket.
- notifyFixShipped: push, Telegram and the in-app alert for a live fix now
  link the walkthrough ("▶ Watch the fix") instead of the bare page.
- getFeedbackWithProject returns the project's liveUrl.

Late night:
- lib/late-night: 23:00–05:00 local, one "night" key per evening, copy.
- LateNightAutopilot on Control: autopilot off → "Hand it to autopilot and
  go to sleep" with one tap to turn it on; on → "Autopilot is on — go to
  sleep". "Not tonight" hides it until the next evening.


Claude-Session: https://claude.ai/code/session_014d9r6dNr1vW789Q75hPcHF

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-07 11:40:54 -07:00

31 lines
1.1 KiB
TypeScript

import { isLateNight, lateNightCopy, nightKey } from "@/lib/late-night";
let failed = 0;
const check = (name: string, ok: boolean) => {
console.log(` ${ok ? "✓" : "✗"} ${name}`);
if (!ok) failed++;
};
const at = (h: number, m = 0) => new Date(2026, 9, 7, h, m);
check("22:59 is not late", !isLateNight(at(22, 59)));
check("23:00 is late", isLateNight(at(23)));
check("02:30 is late", isLateNight(at(2, 30)));
check("05:00 is morning", !isLateNight(at(5)));
check(
"one night from 23:10 to 01:30",
nightKey(at(23, 10)) === "2026-10-07" && nightKey(new Date(2026, 9, 8, 1, 30)) === "2026-10-07",
);
check("the next evening is a new night", nightKey(new Date(2026, 9, 8, 23)) === "2026-10-08");
check("night key across a month edge", nightKey(new Date(2026, 10, 1, 1)) === "2026-10-31");
check("autopilot off offers the one tap", lateNightCopy("off").action === "Turn on autopilot");
check(
"autopilot on just says sleep",
lateNightCopy("on").action === null && /sleep/.test(lateNightCopy("on").headline),
);
if (failed) {
console.error(`late-night: ${failed} failed`);
process.exit(1);
}
console.log("late-night: all passed");