Files
loki/scripts/test/away.ts
T
CatoandClaude Fable 5.1 a508c1ed16 feat(away): "back in 30 minutes" — the next screen says what happened; fewer things thrown together (#1126)
* feat(away): "back in 30 minutes" — the next screen says what happened; fewer things thrown together

"Back in 30 minutes"
- Say it to Loki and set_away records when you left and when you said
  you would be back (user_preferences.away_since/away_until, migration
  0086). Nothing is recorded during the absence.
- On return, Control and the chat's start screen lead with one card:
  what needs you, what went live, what finished (ok / failed, on which
  projects), what still runs, what arrived — each line a link to where
  it is acted on, gone in one tap. While still away, one quiet line.
  Derived at read time from the runs and the feedback that moved
  (lib/away.ts); the rules and the lines are pure and tested
  (lib/away-rules.ts, scripts/test/away.ts). GET/POST/DELETE /api/away.

Fewer things thrown together (owner's screenshots, 2026-10-10)
- A feedback row's context is one sentence that wraps like one: the
  project link wrapped onto its own line above "· home · today".
- The pickers under the lens strip are words with a chevron, not a third
  bordered box between the bordered strip and the bordered list.
- "Pointed at “Welcome to Kestrel”" instead of a mono tag beside a quote.
- The thumbs-down form in the chat is part of the thread: no second box
  with its own border and fill, no filled call to action.
- A review files the mobile screenshot it judged with its first finding,
  so the owner reads the finding beside the picture it came from.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011L2dmcydDLYAiNQwK4XcF4

* chore(demo): classify /api/away for the demo sandbox

Own-tenant data only: two timestamps on the caller's preferences and a
summary derived from their own runs and feedback.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011L2dmcydDLYAiNQwK4XcF4

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-10 01:52:13 -07:00

60 lines
2.0 KiB
TypeScript

/**
* "Back in 30 minutes": the status from two timestamps, and the card's lines.
* Run: npx tsx scripts/test/away.ts
*/
import assert from "node:assert/strict";
import { awayDuration, awayLines, awayStatus, type AwaySummary } from "@/lib/away-rules";
const NOW = Date.parse("2026-10-10T10:00:00Z");
const iso = (minFromNow: number) => new Date(NOW + minFromNow * 60_000).toISOString();
assert.deepEqual(awayStatus({ awaySince: null, awayUntil: null }, NOW), { state: "none" });
assert.equal(awayStatus({ awaySince: iso(-10), awayUntil: iso(20) }, NOW).state, "away");
assert.equal(awayStatus({ awaySince: iso(-40), awayUntil: iso(-10) }, NOW).state, "back");
assert.equal(
awayStatus({ awaySince: iso(-4 * 24 * 60), awayUntil: iso(-4 * 24 * 60 + 30) }, NOW).state,
"none",
"an absence nobody came back from expires",
);
assert.equal(awayStatus({ awaySince: "garbage", awayUntil: iso(5) }, NOW).state, "none");
assert.equal(awayDuration(0), "a moment");
assert.equal(awayDuration(32), "32 min");
assert.equal(awayDuration(65), "1 h 05 min");
assert.equal(awayDuration(120), "2 h");
assert.equal(awayDuration(49 * 60), "2 days");
const base: AwaySummary = {
since: iso(-30),
until: iso(0),
minutes: 30,
runs: { started: 0, finished: 0, ok: 0, failed: 0, running: 0 },
projects: [],
reports: { arrived: 0, live: 0 },
needsYou: 0,
};
assert.deepEqual(awayLines(base), [
{ text: "Nothing moved. Nothing needs you.", href: "/control" },
]);
const busy = awayLines({
...base,
runs: { started: 4, finished: 3, ok: 2, failed: 1, running: 1 },
projects: ["kestrel", "harbourlight"],
reports: { arrived: 2, live: 1 },
needsYou: 2,
});
assert.deepEqual(
busy.map((l) => l.text),
[
"2 things need you",
"1 fix is live — check it",
"3 runs finished (2 ok, 1 failed) on kestrel, harbourlight",
"1 still runs",
"2 new reports arrived",
],
);
assert.equal(busy[0].href, "/feedback", "what needs you leads, and links to where it is acted on");
console.log("✓ away tests passed");