Skip to content

Commit 6fa608a

Browse files
authored
fix(webapp): accept injected clock in staleNote and buildExitSaveRequest (#359)
1 parent 7a800bc commit 6fa608a

12 files changed

Lines changed: 36 additions & 30 deletions

‎internal/webapp/frontend/src/lib/editbeacon.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export type ExitSaveRequest = {
163163
export function buildExitSaveRequest(
164164
state: ExitWorkerState,
165165
patches: ReadonlyArray<ExitPatch>,
166+
now = Date.now(),
166167
): ExitSaveRequest | null {
167168
const renderedWant = applyRenderPatches(state.renderText, state.renderLen, state.allowedRanges, patches);
168169
if (renderedWant === null) return null;
@@ -232,7 +233,7 @@ export function buildExitSaveRequest(
232233
url:
233234
state.apiBase +
234235
"upload/content?path=" +
235-
encodeURIComponent(conflictName(state.path, state.who || "browser", new Date())),
236+
encodeURIComponent(conflictName(state.path, state.who || "browser", new Date(now))),
236237
method: "PUT",
237238
headers: { "Content-Type": text, "If-None-Match": "*", "X-Bdrive-Park-On-Conflict": "1" },
238239
body: renderedWant,

‎internal/webapp/frontend/src/lib/heat.test.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,16 @@ test("staleNote flags only hot-and-stale files, and says how long", () => {
254254
const hot = { agent: 14 };
255255
const cold = { agent: 2 };
256256

257-
assert.match(staleNote(hot, jan), /^stale · last changed \d+ months ago$/);
258-
assert.equal(staleNote(hot, yesterday), ""); // hot but fresh
259-
assert.equal(staleNote(cold, jan), ""); // stale but cold
257+
assert.equal(staleNote(hot, jan, now), "stale · last changed 7 months ago");
258+
assert.equal(staleNote(hot, yesterday, now), ""); // hot but fresh
259+
assert.equal(staleNote(cold, jan, now), ""); // stale but cold
260+
const beforeStale = new Date(now - (STALE_DAYS - 1) * 86400000).toISOString();
261+
const exactlyStale = new Date(now - STALE_DAYS * 86400000).toISOString();
262+
assert.equal(staleNote(hot, beforeStale, now), "");
263+
assert.equal(staleNote(hot, exactlyStale, now), "stale · last changed 1 month ago");
260264
// Telemetry off (heatFor returns null) and a file with no mtime: no mark,
261265
// no throw — the surfaces call this unconditionally.
262-
assert.equal(staleNote(null, jan), "");
263-
assert.equal(staleNote(hot, undefined), "");
264-
assert.equal(staleNote(FIXTURE["notes/untouched.md"], jan), "");
266+
assert.equal(staleNote(null, jan, now), "");
267+
assert.equal(staleNote(hot, undefined, now), "");
268+
assert.equal(staleNote(FIXTURE["notes/untouched.md"], jan, now), "");
265269
});

‎internal/webapp/frontend/src/lib/heat.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ export function agoLabel(days: number): string {
213213
string rather than a boolean keeps the badge pure, so it survives whichever
214214
component ends up owning the meta line. Callers add the ⚠ glyph in markup,
215215
where it can carry its own aria-label. */
216-
export function staleNote(e: HeatEntry | null, time: string | undefined): string {
217-
const days = daysSince(time);
216+
export function staleNote(e: HeatEntry | null, time: string | undefined, now = Date.now()): string {
217+
const days = daysSince(time, now);
218218
if (!e || days === null || !isDanger(heatTotal(e), days)) return "";
219219
return `stale · last changed ${agoLabel(days)}`;
220220
}

‎internal/webapp/frontend/src/lib/sharedfile_restore.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,9 +2983,10 @@ test("buildExitSaveRequest: hub checkpoint, plain-folder save after an autosave,
29832983
// The same words changed outside: the frame's document goes beside the file.
29842984
const outside = v0.replace("Title", "Other");
29852985
const mine = { ...h1, html: "Mine" };
2986-
const clash = buildExitSaveRequest({ ...state, savedText: outside, docText: outside }, [mine]);
2986+
const now = Date.parse("2026-08-18T12:34:56Z");
2987+
const clash = buildExitSaveRequest({ ...state, savedText: outside, docText: outside }, [mine], now);
29872988
assert.ok(clash);
2988-
assert.ok(clash.url.startsWith("/api/upload/content?path=page.html.bdrive-conflict-tester-"));
2989+
assert.equal(clash.url, "/api/upload/content?path=page.html.bdrive-conflict-tester-20260818T123456Z");
29892990
assert.equal(clash.headers["If-None-Match"], "*");
29902991
assert.equal(clash.body, v0.replace("Title", "Mine"));
29912992

internal/webapp/static/assets/Editor-ByyE979e.js renamed to internal/webapp/static/assets/Editor-D7tbLsaZ.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/webapp/static/assets/VisualEdit-BPmdAq1n.js‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)