mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:37:19 +01:00
* chore: add a formatter, matching the style this repo already writes singleQuote=false was chosen by counting this repo's own imports, not by fleet decree. The fleet is genuinely split and the two repos that already had a .prettierrc disagreed with each other, so there was no standard to restore. Quote style does not cross repo boundaries; having a gate does. Markdown is ignored for now — prettier rewraps prose, which would bury the real diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * style: format with prettier (1062 files) Mechanical. No behaviour change. This SHA is listed in .git-blame-ignore-revs so `git blame` skips it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * chore: teach git blame to skip the reformat Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(lint): reattach two guards the reformat detached Both effects were one-liners, so a trailing eslint-disable-line covered the setState call: useEffect(() => { setSelected(new Set()); }, [q.length]); // eslint-disable-line ... prettier expanded the block. The comment stayed on the closing line while the call moved above it, so the guard protected nothing and the rule its author had deliberately silenced failed the build. This is the second shape of the same defect — hirnli had the eslint-disable-NEXT-line variant. Both come from the same fact: an eslint directive binds to a line number, so reformatting can silently unbind it, which makes 'mechanical, no behaviour change' false for any bulk reformat. * chore(desktop): bump the runner version the reformat requires desktop-release-drift enforces that anything built into Fleet Runner which differs from the last released tag must carry a version ahead of that tag — main read 0.8.15 and fleet-runner-v0.8.15 already shipped. A whole-repo reformat changes bytes under desktop/, so the gate fires. The alternative was adding desktop/ to .prettierignore, which would buy a quiet PR by carving a permanent hole in the formatter's coverage — the precise shape of silent drift this test was written to catch. Bumping is what the rule asks for and costs one patch release whose only content is whitespace. * chore: merge main and re-format A whole-repo reformat conflicts with any concurrent commit, and a conflicting PR runs no checks at all while reporting nothing. Conflicts resolved to main, which is correct because this branch changes formatting and nothing else. * chore: leave desktop/ out of this reformat desktop-release-drift is right to refuse this. Everything under desktop/ is built into Fleet Runner, so changing it means shipping: bump the version AND add a FLEET_RUNNER_RELEASES entry, whose stated audience is 'person who installed Fleet Runner and wants to know what changed'. For a whitespace-only build the honest answer is 'nothing', so that release should not exist — and I should not write release notes claiming otherwise. I had bumped to 0.8.16 to get the gate green. That was the wrong direction: publishing a build to three OS runners to keep a formatting PR quiet. Reverted. desktop/ is excluded in .prettierignore with the reasoning recorded there, to be formatted alongside the next real runner change, where the bump and the notes are true anyway. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
148 lines
6.2 KiB
TypeScript
148 lines
6.2 KiB
TypeScript
/**
|
|
* One elapsed-time ladder, two renderings. These pin all three bugs that came
|
|
* from having had three ladders:
|
|
*
|
|
* 1. "Next (agent, 288h ago)" — timeAgo stopped scaling at hours, so a
|
|
* twelve-day-old handoff came out as a large meaningless number on a card
|
|
* whose whole claim is telling you how current its "Next" is.
|
|
* 2. "now ago" — `${shortTimeAgo(t)} ago` at call sites that appended the
|
|
* word by hand, during the first minute after a check, i.e. exactly when
|
|
* someone is looking.
|
|
* 3. A silent disagreement about when weeks begin.
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { timeAgo, shortTimeAgo, elapsedSince, compactRelativeDate } from "../../src/lib/dates";
|
|
|
|
const SEC = 1000,
|
|
MIN = 60 * SEC,
|
|
HOUR = 60 * MIN,
|
|
DAY = 24 * HOUR;
|
|
const ago = (delta: number) => timeAgo(Date.now() - delta);
|
|
const short = (delta: number) => shortTimeAgo(Date.now() - delta);
|
|
|
|
// --- the ladder --------------------------------------------------------
|
|
assert.deepEqual(elapsedSince(Date.now()), { value: 0, unit: "now" });
|
|
assert.deepEqual(elapsedSince(Date.now() - 5 * MIN), { value: 5, unit: "m" });
|
|
assert.deepEqual(elapsedSince(Date.now() - 288 * HOUR), { value: 12, unit: "d" });
|
|
|
|
// Floors, never rounds: a label must not claim more time has passed than has.
|
|
assert.equal(ago(59 * SEC), "just now", "59s is not a minute yet");
|
|
assert.equal(ago(90 * SEC), "1m ago", "90s is one minute, not two");
|
|
assert.equal(ago(119 * MIN), "1h ago", "119m is one hour, not two");
|
|
|
|
// Clock skew between the box and the browser must not produce a negative age.
|
|
assert.equal(ago(-10 * SEC), "just now", "a future timestamp clamps to just now");
|
|
assert.equal(short(-10 * SEC), "now");
|
|
|
|
// --- timeAgo: the only place the word "ago" is appended -----------------
|
|
assert.equal(ago(0), "just now", "under a minute reads as English, never 'now ago'");
|
|
assert.equal(ago(5 * MIN), "5m ago");
|
|
assert.equal(ago(3 * HOUR), "3h ago");
|
|
assert.equal(ago(23 * HOUR), "23h ago");
|
|
assert.equal(ago(2 * DAY), "2d ago");
|
|
assert.equal(ago(288 * HOUR), "12d ago", "THE regression: 288h is a fortnight");
|
|
|
|
// Days run to 30 before months: for a stale handoff "21d ago" is the
|
|
// actionable reading and "3w ago" throws away the precision that makes it so.
|
|
assert.equal(ago(21 * DAY), "21d ago");
|
|
assert.equal(ago(30 * DAY), "30d ago");
|
|
assert.equal(ago(31 * DAY), "1mo ago");
|
|
assert.equal(ago(200 * DAY), "6mo ago");
|
|
assert.equal(ago(400 * DAY), "1y ago");
|
|
|
|
// --- shortTimeAgo: same ladder, bare token ------------------------------
|
|
assert.equal(short(0), "now");
|
|
assert.equal(short(5 * MIN), "5m");
|
|
assert.equal(short(288 * HOUR), "12d");
|
|
assert.equal(short(31 * DAY), "1mo");
|
|
|
|
// The two renderers cannot drift, because they read one ladder.
|
|
for (const delta of [0, 30 * SEC, 5 * MIN, 3 * HOUR, 2 * DAY, 288 * HOUR, 31 * DAY, 400 * DAY]) {
|
|
const s = short(delta),
|
|
t = ago(delta);
|
|
assert.equal(
|
|
t,
|
|
s === "now" ? "just now" : `${s} ago`,
|
|
`timeAgo and shortTimeAgo disagree at ${delta}ms`,
|
|
);
|
|
}
|
|
|
|
// No age may ever render as a raw hour count again.
|
|
for (const days of [1, 2, 7, 12, 21, 29, 30, 45, 200, 900]) {
|
|
const out = ago(days * DAY);
|
|
assert.ok(/^\d+(d|mo|y) ago$/.test(out), `${days}d rendered as "${out}"`);
|
|
}
|
|
|
|
// --- compactRelativeDate: the ladder with calendar words at the near end ----
|
|
// It used to count days itself, with a weeks tier the ladder does not have, so
|
|
// one list row said "2w ago" while the card beside it said "14d ago" about the
|
|
// same instant. Both were on /control at once.
|
|
const daysAgo = (n: number) => new Date(Date.now() - n * DAY);
|
|
assert.equal(compactRelativeDate(daysAgo(0)), "today");
|
|
assert.equal(compactRelativeDate(daysAgo(1)), "yesterday");
|
|
assert.equal(compactRelativeDate(daysAgo(14)), "14d ago", "not '2w ago' — one ladder");
|
|
assert.equal(compactRelativeDate(daysAgo(21)), "21d ago");
|
|
assert.equal(compactRelativeDate(daysAgo(40)), "1mo ago");
|
|
assert.equal(
|
|
compactRelativeDate(new Date(Date.now() + 60 * 60 * 1000)),
|
|
"today",
|
|
"a future timestamp is today, not '-1d ago'",
|
|
);
|
|
|
|
// Past yesterday it must BE timeAgo, not merely resemble it.
|
|
for (const n of [2, 5, 14, 21, 30, 31, 200, 400]) {
|
|
const d = daysAgo(n);
|
|
assert.equal(
|
|
compactRelativeDate(d),
|
|
timeAgo(d.getTime()),
|
|
`compactRelativeDate diverges from the ladder at ${n}d`,
|
|
);
|
|
}
|
|
|
|
// --- the class, closed --------------------------------------------------
|
|
// Bug 2 was reintroduced three times by three different call sites appending
|
|
// the word themselves. A comment asking people not to did not stop it, so this
|
|
// is a gate: shortTimeAgo returns a bare token and "ago" belongs to timeAgo.
|
|
function sourceFiles(dir: string, out: string[] = []): string[] {
|
|
for (const name of readdirSync(dir)) {
|
|
const full = join(dir, name);
|
|
if (statSync(full).isDirectory()) sourceFiles(full, out);
|
|
else if (/\.tsx?$/.test(name)) out.push(full);
|
|
}
|
|
return out;
|
|
}
|
|
const DEFINITION = join("src", "lib", "dates.ts"); // quotes the bug in its own doc comment
|
|
|
|
// Per LINE, and deliberately not one clever regex over the whole call: the
|
|
// first version of this gate used `shortTimeAgo\([^)]*\)\s*ago` and silently
|
|
// passed, because [^)] cannot cross the parens in
|
|
// `shortTimeAgo(new Date(x).getTime())} ago`. It was a green check that proved
|
|
// nothing. Any line that both calls shortTimeAgo and says "ago" after it is
|
|
// the bug, whatever the argument looks like. Comment lines are skipped so
|
|
// prose about the bug is not itself an offence.
|
|
function offendingLines(file: string): string[] {
|
|
return readFileSync(file, "utf8")
|
|
.split("\n")
|
|
.filter((line) => {
|
|
const trimmed = line.trim();
|
|
if (trimmed.startsWith("//") || trimmed.startsWith("*")) return false;
|
|
const call = line.indexOf("shortTimeAgo(");
|
|
return call !== -1 && /\bago\b/.test(line.slice(call));
|
|
})
|
|
.map((line) => line.trim());
|
|
}
|
|
|
|
const offenders = sourceFiles(join(import.meta.dirname, "..", "..", "src"))
|
|
.filter((f) => !f.endsWith(DEFINITION))
|
|
.flatMap((f) => offendingLines(f).map((line) => `${f}: ${line}`));
|
|
|
|
assert.deepEqual(
|
|
offenders,
|
|
[],
|
|
`these append "ago" to shortTimeAgo — use timeAgo instead:\n${offenders.join("\n")}`,
|
|
);
|
|
|
|
console.log("✓ time-ago tests passed");
|