fabro/apps/fabro-web/app/data/runs.test.ts
Bryan Helmkamp ab9b28875b
fix: close sandbox-native metadata gaps
Ensure local runs use the worktree checkpoint path by default, expose source and sandbox paths in API/web surfaces, and remove dead fork/rewind push controls. Update docs for clone-based sandboxes and durable checkpoint timelines.
2026-04-28 08:05:18 -07:00

143 lines
4.4 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import {
columnForStatus,
columnStatusDisplay,
isRunStatus,
mapRunListItem,
mapRunSummaryToRunItem,
runStatusDisplay,
} from "./runs";
describe("mapRunListItem", () => {
test("trusts shared server fields for board items", () => {
const summary = {
run_id: "01ABC",
goal: "## Fix the build",
title: "Server supplied title",
workflow_slug: "fix_build",
workflow_name: "Fix Build",
source_directory: "/home/user/myrepo",
repository: { name: "myrepo" },
status: { kind: "paused", prior_block: null },
labels: {},
column: "running",
elapsed_secs: 65,
duration_ms: 65000,
total_usd_micros: 500000,
created_at: "2026-04-08T12:00:00Z",
start_time: "2026-04-08T12:00:00Z",
pending_control: null,
} as const;
const item = mapRunListItem(summary);
expect(item.id).toBe("01ABC");
expect(item.title).toBe("Server supplied title");
expect(item.workflow).toBe("fix_build");
expect(item.repo).toBe("myrepo");
expect(item.sourceDirectory).toBe("/home/user/myrepo");
expect(item.elapsed).toBeDefined();
expect(item.column).toBe("running");
expect(item.lifecycleStatus).toBe("paused");
});
test("uses a fallback title when the server title is blank", () => {
const summary = {
run_id: "01EMPTY",
goal: "",
title: "",
workflow_slug: "fix_build",
workflow_name: "Fix Build",
source_directory: "/home/user/myrepo",
repository: { name: "myrepo" },
status: { kind: "running" },
labels: {},
column: "running",
elapsed_secs: null,
duration_ms: null,
total_usd_micros: null,
created_at: "2026-04-08T12:00:00Z",
start_time: null,
pending_control: null,
} as const;
expect(mapRunListItem(summary).title).toBe("Untitled run");
});
});
describe("mapRunSummaryToRunItem", () => {
test("maps canonical run summary to RunItem", () => {
const summary = {
run_id: "01ABC",
goal: "Fix the build",
title: "Fix the build",
workflow_slug: "fix_build",
workflow_name: "Fix Build",
source_directory: "/home/user/myrepo",
repository: { name: "myrepo" },
status: { kind: "running" },
duration_ms: 65000,
elapsed_secs: 65,
total_usd_micros: 500000,
labels: {},
created_at: "2026-04-08T12:00:00Z",
start_time: "2026-04-08T12:00:00Z",
pending_control: null,
};
const item = mapRunSummaryToRunItem(summary);
expect(item.id).toBe("01ABC");
expect(item.title).toBe("Fix the build");
expect(item.workflow).toBe("fix_build");
expect(item.repo).toBe("myrepo");
expect(item.sourceDirectory).toBe("/home/user/myrepo");
expect(item.elapsed).toBeDefined();
expect(item.lifecycleStatus).toBe("running");
});
test("handles missing optional fields", () => {
const summary = {
run_id: "01DEF",
goal: "",
title: "",
workflow_slug: null,
workflow_name: null,
source_directory: null,
repository: { name: "unknown" },
status: { kind: "submitted" },
duration_ms: null,
elapsed_secs: null,
total_usd_micros: null,
labels: {},
created_at: "2026-04-08T12:00:00Z",
start_time: null,
pending_control: null,
};
const item = mapRunSummaryToRunItem(summary);
expect(item.id).toBe("01DEF");
expect(item.title).toBe("Untitled run");
expect(item.workflow).toBe("unknown");
expect(item.repo).toBe("unknown");
expect(item.sourceDirectory).toBeUndefined();
});
test("recognizes canonical blocked and queued run statuses", () => {
expect(isRunStatus("queued")).toBe(true);
expect(isRunStatus("blocked")).toBe(true);
expect(runStatusDisplay).toHaveProperty("queued");
expect(runStatusDisplay).toHaveProperty("blocked");
});
test("recognizes archived as a terminal run status", () => {
expect(isRunStatus("archived")).toBe(true);
expect(runStatusDisplay).toHaveProperty("archived");
});
test("uses blocked board column instead of waiting", () => {
expect(columnStatusDisplay).toHaveProperty("blocked");
expect(columnStatusDisplay).not.toHaveProperty("waiting");
});
});
describe("columnForStatus", () => {
test("returns null for lifecycle states that do not map to a board column", () => {
expect(columnForStatus("removing")).toBeNull();
});
});