import { renderReportHistory, reportHistoryStyles, reportHistoryScript } from "./report-history.js";
import { renderReportShell, reportNavigationStyles, reportShellScript } from "./report-navigation.js";
import { runnerMatrix } from "./catalog.js";
import { campaignSuiteSummaryStyles, renderCampaignSuiteSummary } from "./campaign-summary.js";
import type {
RunnerE2EHistoryCampaign,
RunnerE2EHistoryIndex,
} from "./types.js";
function html(value: unknown) {
return String(value ?? "")
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll('"', """)
.replaceAll("'", "'");
}
function number(value: number) {
return new Intl.NumberFormat("en-US").format(value);
}
function usd(value: number | null) {
if (value === null) return "Unknown";
return `$${value.toFixed(value < 0.01 ? 6 : 2)}`;
}
function duration(durationMs: number) {
const seconds = Math.round(durationMs / 1_000);
if (seconds < 60) return `${seconds}s`;
const minutes = Math.floor(seconds / 60);
if (minutes < 60) return `${minutes}m ${seconds % 60}s`;
return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
}
function date(value: string) {
return new Intl.DateTimeFormat("en-US", {
dateStyle: "medium",
timeStyle: "short",
timeZone: "UTC",
}).format(new Date(value));
}
function campaignStatus(campaign: RunnerE2EHistoryCampaign) {
if (campaign.failed === 0 && (campaign.incomplete ?? 0) > 0) return "incomplete";
return campaign.failed === 0 &&
campaign.passed === campaign.selected &&
campaign.executed === campaign.selected &&
campaign.cleanupPassed
? "passed"
: "failed";
}
function sourceCell(campaign: RunnerE2EHistoryCampaign) {
const sha = campaign.source.sha;
const shortSha = sha?.slice(0, 8) ?? "Unknown";
const shaLabel = /^[0-9a-f]{40}$/i.test(sha ?? "")
? `${html(shortSha)}`
: html(shortSha);
const workflow = campaign.source.workflowRunUrl
? `Workflow run`
: "";
return `${shaLabel}${html(campaign.source.ref ?? "Unknown ref")}${workflow}`;
}
function campaignRow(campaign: RunnerE2EHistoryCampaign) {
const status = campaignStatus(campaign);
const suites = campaign.suites
.map(
(suite) =>
`${html(suite.suiteId)} · ${suite.passed}/${suite.selected}`,
)
.join("");
const billing = campaign.billing;
return `
|
${html(campaign.campaignId)}
${html(date(campaign.generatedAt))} UTC
|
${status}
${campaign.passed}/${campaign.selected} passed · ${campaign.executed} executed
|
${sourceCell(campaign)} |
Open report →
Suites & billing
${suites}
${campaign.complete ? "Complete campaign" : "Partial campaign"} · ${campaign.retries} retries · cleanup ${campaign.cleanupPassed ? "passed" : "failed"}
${campaign.failed} failed${campaign.incomplete ? ` · ${campaign.incomplete} incomplete` : ""}
${html(number(billing.llm.totalTokens))} tokens · ${html(number(billing.llm.inputTokens))} in · ${html(number(billing.llm.outputTokens))} out · ${html(number(billing.llm.cachedInputTokens))} cached
${html(usd(billing.observedAndEstimatedCostUsd))} recorded cost · ${html(usd(billing.reportedLlmCostUsd))} LLM · ${html(usd(billing.estimatedRuntimeCostUsd))} runtime
${html(duration(billing.agentRunDurationMs))} agent · ${html(duration(billing.leaseDurationMs))} Daytona lease
|
`;
}
export function renderRunnerHistoryIndex(
history: RunnerE2EHistoryIndex,
) {
const campaigns = [...history.campaigns].sort((left, right) =>
right.generatedAt.localeCompare(left.generatedAt),
);
const passed = campaigns.filter(
(campaign) => campaignStatus(campaign) === "passed",
).length;
const latest = campaigns.find(
(campaign) => campaign.campaignId === history.latestCampaignId,
);
const latestGreen = campaigns.find(
(campaign) => campaign.campaignId === history.latestGreenCampaignId,
);
const totalCost = campaigns.some(c => c.billing.observedAndEstimatedCostUsd === null) ? null : campaigns.reduce(
(sum, campaign) => sum + (campaign.billing.observedAndEstimatedCostUsd ?? 0),
0,
);
const rows =
campaigns.length > 0
? campaigns.map(campaignRow).join("")
: `| No campaigns have been published yet. |
`;
return `
Runner E2E Campaigns · Paperclip
${renderReportShell({ history })}
Historical test reporting
Runner E2E campaigns
${campaigns.length} retained campaigns. Open a report for test outcomes, per-test billing, declared screenshots, and normalized results.
${campaigns.length}Campaigns
${passed}Passed
${html(usd(totalCost))}Recorded cost
Recent campaigns
| Campaign | Result | Source | |
${rows}
Trends and detailed history
${renderReportHistory(history)}
`;
}