Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor(frontend): one reader for the stub, one factory for a run

zchpeter5d22e4dbbe45
diff --git a/docs/design/timestamp-display.md b/docs/design/timestamp-display.md
index 797f19025b..dbc14f11ad 100644
--- a/docs/design/timestamp-display.md
+++ b/docs/design/timestamp-display.md
@@ -333,7 +333,11 @@ no seconds per D5. Relative age may accompany it in the tooltip.
surfaces read is set from a real time or left unset. The container's empty form is a caller's
decision, and only absence reaches it: a value the domain rejects leaves the display rendering
nothing while its separator stays, which no proto-sourced timestamp can produce, since a
- `Timestamp` is range-checked to years 1–9999.
+ `Timestamp` is range-checked to years 1–9999. A caller guards a timestamp only to gate
+ something besides the display — a separator, a label, a pill, a "-" of its own. The display
+ renders nothing without an instant, so a guard that only repeats that is a second place for
+ the rule to live, and the second place is where it drifts: three rounds of this review each
+ found another spelling of it.
- Guarded by fake-timer tests and a sweep of render-time `Date.now()` over the touched surfaces
at implementation time — a review pass, not a lint: telling render scope from handlers and
effects statically would flag most legitimate uses.
diff --git a/frontend/src/components/release/ReleaseInfoCard.tsx b/frontend/src/components/release/ReleaseInfoCard.tsx
index 070b4bf9be..276e4d6844 100644
--- a/frontend/src/components/release/ReleaseInfoCard.tsx
+++ b/frontend/src/components/release/ReleaseInfoCard.tsx
@@ -96,7 +96,6 @@ function NotFoundBlock() {
function ReleaseBlock({ release }: Readonly<{ release: Release }>) {
const { t } = useTranslation();
const displayedFiles = release.files.slice(0, MAX_DISPLAYED_RELEASE_FILES);
- const createdTimeMs = getTimeForPbTimestampProtoEs(release.createTime);
return (
<div className="rounded-sm border border-control-border bg-control-bg/50 px-4 py-3">
@@ -169,7 +168,7 @@ function ReleaseBlock({ release }: Readonly<{ release: Release }>) {
<HumanizeTs
className="text-xs text-control-light"
- tsMs={createdTimeMs}
+ tsMs={getTimeForPbTimestampProtoEs(release.createTime)}
/>
</div>
</div>
diff --git a/frontend/src/lib/taskRun.ts b/frontend/src/lib/taskRun.ts
index cce089cd75..7db9773908 100644
--- a/frontend/src/lib/taskRun.ts
+++ b/frontend/src/lib/taskRun.ts
@@ -11,7 +11,7 @@ import { formatAbsoluteDateTime, humanizeDurationV1 } from "@/utils";
// Millisecond resolution so two runs created in the same wall-clock second
// (e.g. a quick double rerun) still sort by their real order.
const createTimeMs = (taskRun: TaskRun): number =>
- taskRun.createTime ? getTimeForPbTimestampProtoEs(taskRun.createTime) : 0;
+ getTimeForPbTimestampProtoEs(taskRun.createTime, 0);
export const sortTaskRunsNewestFirst = (taskRuns: TaskRun[]): TaskRun[] =>
[...taskRuns].sort((left, right) => createTimeMs(right) - createTimeMs(left));
@@ -62,10 +62,8 @@ export const getTaskRunWaitingMessage = (
t: TFunction
): string | undefined => {
if (taskRun.status === TaskRun_Status.PENDING) {
- const earliestAllowedTime = taskRun.runTime
- ? getTimeForPbTimestampProtoEs(taskRun.runTime)
- : null;
- if (earliestAllowedTime) {
+ const earliestAllowedTime = getTimeForPbTimestampProtoEs(taskRun.runTime);
+ if (earliestAllowedTime !== undefined) {
return t("task-run.status.enqueued-with-rollout-time", {
time: formatAbsoluteDateTime(earliestAllowedTime),
});
diff --git a/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx b/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx
index bc0f42427c..9d6e20c7d8 100644
--- a/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx
+++ b/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx
@@ -4,6 +4,7 @@ import type { ReactElement } from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { beforeEach, describe, expect, test, vi } from "vitest";
+import { shownTimestampModes } from "@/test-utils/humanizeTs";
import { ChangelogSchema } from "@/types/proto-es/v1/changelog_service_pb";
(
@@ -83,9 +84,7 @@ describe("DatabaseChangelogTable", () => {
// A row in a list orients the reader; the changelog's own page testifies.
expect(
- Array.from(
- container.querySelectorAll<HTMLElement>("[data-testid=humanize-ts]")
- ).map((node) => node.dataset.mode)
+ shownTimestampModes(container)
).toEqual(["compact"]);
unmount();
diff --git a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.test.tsx b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.test.tsx
index 571f34ad4a..93514b8253 100644
--- a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.test.tsx
+++ b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.test.tsx
@@ -1,9 +1,11 @@
import { create } from "@bufbuild/protobuf";
+import type { MessageInitShape } from "@bufbuild/protobuf";
import { TimestampSchema, timestampFromMs } from "@bufbuild/protobuf/wkt";
import type { ReactElement, ReactNode } from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { describe, expect, test, vi } from "vitest";
+import { shownTimestampInstants, shownTimestampModes } from "@/test-utils/humanizeTs";
import {
TaskRun_Status,
TaskRunSchema,
@@ -54,16 +56,25 @@ vi.mock("@/components/HumanizeTs", async () => ({
const taskName = "projects/p1/rollouts/r1/stages/s1/tasks/t1";
+const CREATED_AT_MS = 1_000_000;
+
+const makeTaskRun = (
+ overrides: MessageInitShape<typeof TaskRunSchema> = {}
+) =>
+ create(TaskRunSchema, {
+ createTime: timestampFromMs(CREATED_AT_MS),
+ creator: "users/[email protected]",
+ name: `${taskName}/taskRuns/1`,
+ status: TaskRun_Status.FAILED,
+ ...overrides,
+ });
+
const makeTaskRuns = (count: number) =>
// Newest first, matching the component contract.
Array.from({ length: count }, (_, index) =>
- create(TaskRunSchema, {
- createTime: create(TimestampSchema, {
- seconds: BigInt(1000 * (count - index)),
- }),
- creator: "users/[email protected]",
+ makeTaskRun({
+ createTime: timestampFromMs(CREATED_AT_MS * (count - index)),
name: `${taskName}/taskRuns/${count - index}`,
- status: TaskRun_Status.FAILED,
})
);
@@ -90,16 +101,6 @@ const renderSheet = (taskRuns: ReturnType<typeof makeTaskRuns>) => {
};
};
-const shownInstants = (container: HTMLElement) =>
- Array.from(
- container.querySelectorAll<HTMLElement>("[data-testid=humanize-ts]")
- ).map((node) => node.textContent);
-
-const timestampModes = (container: HTMLElement) =>
- Array.from(
- container.querySelectorAll<HTMLElement>("[data-testid=humanize-ts]")
- ).map((node) => node.dataset.mode);
-
const mountedLogNames = (container: HTMLElement) =>
Array.from(
container.querySelectorAll<HTMLElement>("[data-testid=log-viewer]")
@@ -111,8 +112,8 @@ describe("DeployTaskRunHistorySheet", () => {
// form and the instant are decisions this surface makes, and a run dated
// from the wrong one reads as plausibly as the right one.
const { container, cleanup } = renderSheet(makeTaskRuns(1));
- expect(timestampModes(container)).toEqual(["compact"]);
- expect(shownInstants(container)).toEqual([String(1000 * 1000)]);
+ expect(shownTimestampModes(container)).toEqual(["compact"]);
+ expect(shownTimestampInstants(container)).toEqual([String(CREATED_AT_MS)]);
cleanup();
});
@@ -120,15 +121,11 @@ describe("DeployTaskRunHistorySheet", () => {
// A run is created when it is queued and starts when it is picked up, so
// the queue time would date it earlier than it ran.
const startedMs = 5_000_000;
- const [queued] = makeTaskRuns(1);
const { container, cleanup } = renderSheet([
- create(TaskRunSchema, {
- ...queued,
- startTime: timestampFromMs(startedMs),
- }),
+ makeTaskRun({ startTime: timestampFromMs(startedMs) }),
]);
- expect(shownInstants(container)).toEqual([String(startedMs)]);
+ expect(shownTimestampInstants(container)).toEqual([String(startedMs)]);
cleanup();
});
@@ -154,13 +151,7 @@ describe("DeployTaskRunHistorySheet", () => {
test("remounts the log viewer when a run flips RUNNING -> DONE", () => {
viewerMounts.count = 0;
- const run = (status: TaskRun_Status) =>
- create(TaskRunSchema, {
- createTime: create(TimestampSchema, { seconds: 1000n }),
- creator: "users/[email protected]",
- name: `${taskName}/taskRuns/1`,
- status,
- });
+ const run = (status: TaskRun_Status) => makeTaskRun({ status });
const container = document.createElement("div");
document.body.appendChild(container);
const root = createRoot(container);
diff --git a/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx b/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx
index b71634888d..97731ecc68 100644
--- a/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx
+++ b/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx
@@ -3,6 +3,7 @@ import { timestampFromMs } from "@bufbuild/protobuf/wkt";
import { act, type ReactNode } from "react";
import { createRoot } from "react-dom/client";
import { describe, expect, test, vi } from "vitest";
+import { shownTimestampModes } from "@/test-utils/humanizeTs";
import {
IssueComment_ReviewSubmissionSchema,
IssueComment_ThreadState,
@@ -215,9 +216,7 @@ describe("ReviewActivityTimeline", () => {
});
expect(
- Array.from(
- container.querySelectorAll<HTMLElement>("[data-testid=humanize-ts]")
- ).map((node) => node.dataset.mode)
+ shownTimestampModes(container)
).toEqual(["queue"]);
act(() => root.unmount());
diff --git a/frontend/src/routes/project/plan-detail/components/threads/CommentThreadCard.test.tsx b/frontend/src/routes/project/plan-detail/components/threads/CommentThreadCard.test.tsx
index e09b675fce..1027bb522d 100644
--- a/frontend/src/routes/project/plan-detail/components/threads/CommentThreadCard.test.tsx
+++ b/frontend/src/routes/project/plan-detail/components/threads/CommentThreadCard.test.tsx
@@ -4,6 +4,7 @@ import { act, useState } from "react";
import { createRoot, type Root } from "react-dom/client";
import { MonacoViewZoneRevealContext } from "@/components/monaco/MonacoViewZone";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+import { shownTimestampInstants } from "@/test-utils/humanizeTs";
import {
IssueComment_ThreadState,
IssueCommentSchema,
@@ -245,9 +246,7 @@ describe("CommentThreadCard", () => {
<CommentThreadCard issueName={ISSUE} project={project} thread={thread} />
);
- const shown = Array.from(
- container.querySelectorAll("[data-testid='humanize-ts']")
- ).map((node) => node.textContent);
+ const shown = shownTimestampInstants(container);
expect(shown).toContain(String(writtenMs));
expect(shown).not.toContain(String(writtenMs + 60_000));
});
diff --git a/frontend/src/test-utils/humanizeTs.tsx b/frontend/src/test-utils/humanizeTs.tsx
index 3aa6846166..9bfded2edc 100644
--- a/frontend/src/test-utils/humanizeTs.tsx
+++ b/frontend/src/test-utils/humanizeTs.tsx
@@ -20,3 +20,14 @@ export const humanizeTsStub = () => ({
</span>
),
});
+
+const shown = (root: ParentNode) =>
+ Array.from(root.querySelectorAll<HTMLElement>("[data-testid=humanize-ts]"));
+
+/** The form each timestamp was asked for, in document order. */
+export const shownTimestampModes = (root: ParentNode) =>
+ shown(root).map((node) => node.dataset.mode);
+
+/** The instant each timestamp was given, in document order. */
+export const shownTimestampInstants = (root: ParentNode) =>
+ shown(root).map((node) => node.textContent);