Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions web/service/stovepipe/src/server/instrumentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { instrumentStovepipeWeb } from "./instrumentation";
function createHostFixture() {
const list = vi.fn().mockResolvedValue({ requests: [], nextPageToken: "" });
const listOpenIssues = vi.fn().mockResolvedValue({ issues: [], nextPageToken: "" });
const listIssueHistory = vi.fn().mockResolvedValue({ events: [], nextPageToken: "" });
const getRequestHistoryByID = vi.fn().mockRejectedValue(new Error("private failure"));
const getProjectStatusByID = vi.fn().mockRejectedValue(new Error("private failure"));
const getIssuesByRequestID = vi.fn().mockRejectedValue(new Error("private failure"));
const listRequestProjectsByIssue = vi.fn().mockRejectedValue(new Error("private failure"));
const listRequestIssuesByProject = vi.fn().mockRejectedValue(new Error("private failure"));
const web = createStovepipeWeb({ queues: [{ name: "demo" }], service: { list, listOpenIssues, getRequestHistoryByID, getProjectStatusByID, getIssuesByRequestID, listRequestProjectsByIssue, listRequestIssuesByProject } });
const web = createStovepipeWeb({ queues: [{ name: "demo" }], service: { list, listOpenIssues, listIssueHistory, getRequestHistoryByID, getProjectStatusByID, getIssuesByRequestID, listRequestProjectsByIssue, listRequestIssuesByProject } });
const record = vi.fn();
const add = vi.fn();
const span = { setAttribute: vi.fn(), setStatus: vi.fn(), recordException: vi.fn(), end: vi.fn() };
Expand All @@ -20,7 +21,7 @@ function createHostFixture() {
const host = instrumentStovepipeWeb(web,
{ createHistogram, createCounter } as unknown as Meter,
{ startSpan: () => span } as unknown as Tracer);
return { host, list, listOpenIssues, web, record, add, span, createHistogram, createCounter };
return { host, list, listOpenIssues, listIssueHistory, web, record, add, span, createHistogram, createCounter };
}

describe("Stovepipe host instrumentation", () => {
Expand Down Expand Up @@ -73,3 +74,13 @@ describe("Stovepipe host instrumentation", () => {
expect(fixture.record).toHaveBeenCalledWith(expect.any(Number), { outcome: "exception" });
});
});

it("records a failed issue-history section as a failed page load", async () => {
const fixture = createHostFixture();
fixture.listIssueHistory.mockRejectedValue(new Error("private history failure"));
const result = await fixture.host.handle({ path: "/demo", search: new URLSearchParams({ view: "issue-history", task: "test", unit: "" }) });
expect(result).toMatchObject({ kind: "render", model: { kind: "issue-history", issueHistory: { ok: false } } });
expect(fixture.add).toHaveBeenCalledWith(1, { outcome: "error" });
expect(fixture.span.setStatus).toHaveBeenCalledWith({ code: SpanStatusCode.ERROR });
expect(JSON.stringify(result)).not.toContain("private history failure");
});
3 changes: 2 additions & 1 deletion web/service/stovepipe/src/server/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function instrumentStovepipeWeb(
if (result.kind === "render") {
const sections = result.model.kind === "queue"
? [result.model.requests] : result.model.kind === "issues"
? [result.model.issues] : [result.model.history, result.model.projectStatus, result.model.requestIssues, result.model.issueProjects?.result, result.model.projectIssues?.result];
? [result.model.issues] : result.model.kind === "issue-history"
? [result.model.issueHistory] : [result.model.history, result.model.projectStatus, result.model.requestIssues, result.model.issueProjects?.result, result.model.projectIssues?.result];
if (sections.some((section) => section != null && !section.ok)) {
outcome = "error";
observeTelemetry(() => span?.setStatus({ code: SpanStatusCode.ERROR }));
Expand Down
3 changes: 2 additions & 1 deletion web/stovepipe/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Stovepipe web UI

A framework-neutral React UI for queue requests, open issues, and request details. The host supplies authentication, backend transport, routing adapters, and styling.
A framework-neutral React UI for queue requests, open issues, issue history, and request details. The host supplies authentication, backend transport, routing adapters, and styling.

## Host integration

Expand All @@ -15,3 +15,4 @@ See the [shared package contract](../README.md#layers) for bundling requirements

- Missing results are unknown, not green. Recording completion does not imply validation success.
- Paginated listings are live, not snapshots.
- Issue history shows retained openings, repeat reports, and closures across requests, in recorded timestamp order rather than request ingest order. Older coverage may be incomplete.
27 changes: 26 additions & 1 deletion web/stovepipe/controller/issues.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StovepipeService } from "../extension/service/index.js";
import type { StovepipePaths } from "../core/paths.js";
import type { OpenIssuesModel, RequestIssuesModel, IssueProjectsModel } from "../entity/index.js";
import type { OpenIssuesModel, RequestIssuesModel, IssueProjectsModel, IssueHistoryModel } from "../entity/index.js";

export async function loadOpenIssues(
service: StovepipeService,
Expand All @@ -20,6 +20,7 @@ export async function loadOpenIssues(
firstSeenAtMs: issue.changedAtMs.toString(),
requestId: issue.requestId,
requestHref: paths.request(queue, issue.requestId),
historyHref: paths.issueHistory(queue, issue.taskId, issue.unitId),
})),
nextHref: result.nextPageToken ? paths.openIssues(queue, result.nextPageToken) : null,
};
Expand All @@ -39,6 +40,7 @@ export async function loadRequestIssues(
return {
issues: result.issues.map(issue => ({
...issue,
historyHref: paths.issueHistory(queue, issue.taskId, issue.unitId),
projectsHref: issue.unitId && (issue.kind === "new" || issue.kind === "existing")
? paths.issueProjects(queue, requestId, issue.taskId, issue.unitId, pageToken) : null,
})),
Expand Down Expand Up @@ -70,3 +72,26 @@ export async function loadIssueProjects(
nextHref: result.nextPageToken ? paths.issueProjects(queue, requestId, taskId, unitId, issuesPage, result.nextPageToken) : null,
};
}

export async function loadIssueHistory(
service: StovepipeService,
paths: StovepipePaths,
queue: string,
taskId: string,
unitId: string,
pageToken: string,
signal?: AbortSignal,
): Promise<IssueHistoryModel> {
const result = await service.listIssueHistory(
{ queue, taskId, unitId, pageSize: 50, pageToken }, signal ? { signal } : {},
);
return {
taskId, unitId,
events: result.events.map(event => ({
...event, timestampMs: event.timestampMs.toString(),
requestHref: event.requestId ? paths.requestIssues(queue, event.requestId) : null,
})),
firstHref: pageToken ? paths.issueHistory(queue, taskId, unitId) : null,
nextHref: result.nextPageToken ? paths.issueHistory(queue, taskId, unitId, result.nextPageToken) : null,
};
}
5 changes: 5 additions & 0 deletions web/stovepipe/core/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export class StovepipePaths {
if (page) search.set("page", page);
return `${this.queue(queue)}?${search}`;
}
issueHistory(queue: string, taskId: string, unitId: string, page = ""): string {
const search = new URLSearchParams({ view: "issue-history", task: taskId, unit: unitId });
if (page) search.set("page", page);
return `${this.queue(queue)}?${search}`;
}
requestIssues(queue: string, requestId: string, page = ""): string {
const search = new URLSearchParams({ view: "issues" });
if (page) search.set("issues", page);
Expand Down
27 changes: 26 additions & 1 deletion web/stovepipe/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface OpenIssueModel {
taskId: string;
/** Validation unit; empty identifies a task-wide failure. */
unitId: string;
/** Retained cross-request history for this task and unit. */
historyHref: string;
/** Opening time in Unix milliseconds as a decimal string. */
firstSeenAtMs: string;
/** Request that established this opening. */
Expand All @@ -51,9 +53,28 @@ export interface OpenIssuesModel {
/** Opaque continuation URL; null when no further row was observed. */
nextHref: string | null;
}
export interface IssueHistoryModel {
/** Exact validation task selected for this history. */
taskId: string;
/** Exact unit; empty means a task-wide issue. */
unitId: string;
/** Retained occurrences in backend timestamp/build/event order. */
events: {
event: string;
buildId: string;
timestampMs: string;
firstSeenBuildId: string;
requestId: string;
requestHref: string | null;
}[];
/** First retained event page; null when already on it. */
firstHref: string | null;
/** Opaque continuation URL; null on the final page. */
nextHref: string | null;
}
export interface RequestIssuesModel {
/** Accepted issue updates on this page, not the queue's open-issue set. */
issues: { taskId: string; unitId: string; kind: string; buildId: string; firstSeenBuildId: string; projectsHref: string | null }[];
issues: { taskId: string; unitId: string; kind: string; buildId: string; firstSeenBuildId: string; projectsHref: string | null; historyHref: string }[];
/** Backend reconciliation status; completion does not imply a green build. */
status: string;
/** First issue page for this request; null when already on it. */
Expand Down Expand Up @@ -169,6 +190,10 @@ export type StovepipePageModel = PageBase &
kind: "issues";
issues: ReadResult<OpenIssuesModel>;
}
| {
kind: "issue-history";
issueHistory: ReadResult<IssueHistoryModel>;
}
| {
kind: "request";
requestId: string;
Expand Down
4 changes: 4 additions & 0 deletions web/stovepipe/extension/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export interface ProjectIssuePage {

/** Hosts supply a transport client; the library has no generated-binding dependency. */
export interface StovepipeService {
listIssueHistory(
request: { queue: string; taskId: string; unitId: string; pageSize: number; pageToken: string },
options?: { signal?: AbortSignal },
): Promise<{ events: { event: string; buildId: string; timestampMs: bigint; firstSeenBuildId: string; requestId: string }[]; nextPageToken: string }>;
listRequestIssuesByProject(
request: { queue: string; requestId: string; project: string; pageSize: number; pageToken: string },
options?: { signal?: AbortSignal },
Expand Down
48 changes: 47 additions & 1 deletion web/stovepipe/module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const summary: RequestSummary = {
};
function createPageTestContext(options: Pick<StovepipeWebOptions, "resolveBuildUrl"> = {}) {
const service: StovepipeService = {
listIssueHistory: vi.fn().mockResolvedValue({ events: [], nextPageToken: "" }),
listRequestIssuesByProject: vi.fn().mockResolvedValue({ attributions: [], attributionComplete: true, nextPageToken: "" }),
listRequestProjectsByIssue: vi.fn().mockResolvedValue({ attributions: [], attributionComplete: true, nextPageToken: "" }),
getIssuesByRequestID: vi.fn().mockResolvedValue({ issues: [], status: "complete", nextPageToken: "" }),
Expand Down Expand Up @@ -89,6 +90,7 @@ describe("Stovepipe page loading", () => {
issues: [{
taskId: "build/test", unitId: "", firstSeenAtMs: "9007199254740993",
requestId: summary.requestId, requestHref: paths.request("repo/main", summary.requestId),
historyHref: paths.issueHistory("repo/main", "build/test", ""),
}],
nextHref: paths.openIssues("repo/main", "next+/="),
} },
Expand Down Expand Up @@ -584,7 +586,7 @@ it("loads request issues only for their tab and preserves opaque continuation to
expect(result).toMatchObject({ kind: "render", model: { kind: "request", requestIssues: { ok: true, data: {
status: "in_progress", firstHref: paths.requestIssues("repo/main", summary.requestId),
nextHref: paths.requestIssues("repo/main", summary.requestId, "next+/="),
issues: [{ taskId: "build/test", unitId: "//pkg:a", kind: "new" }],
issues: [{ taskId: "build/test", unitId: "//pkg:a", kind: "new", historyHref: paths.issueHistory("repo/main", "build/test", "//pkg:a") }],
} } } });
});

Expand Down Expand Up @@ -664,3 +666,47 @@ it("rejects another project's association without hiding its recorded statuses",
const result = await app.handle({ path: paths.request("repo/main", summary.requestId), search: new URLSearchParams({ project: "p" }) });
expect(result).toMatchObject({ kind: "render", model: { projectStatus: { ok: true }, projectIssues: { result: { ok: false } } } });
});

it.each(["", "//pkg:a/b?x=1#hash+%"])("loads retained history for the exact issue (%s) without unrelated reads", async unitId => {
const { app, service, paths } = createPageTestContext();
const taskId = "build/test?variant=1";
vi.mocked(service.listIssueHistory).mockResolvedValue({ events: [
{ event: "reported", buildId: "runner/7", timestampMs: 9007199254740993n, firstSeenBuildId: "runner/1", requestId: "7" },
{ event: "future", buildId: "expired", timestampMs: 1000n, firstSeenBuildId: "", requestId: "" },
], nextPageToken: "next+/=" });
const url = new URL(paths.issueHistory("repo/main", taskId, unitId, "opaque+/="), "https://example.test");
const signal = new AbortController().signal;
const result = await app.handle({ path: url.pathname, search: url.searchParams, signal });
expect(service.listIssueHistory).toHaveBeenCalledWith(
{ queue: "repo/main", taskId, unitId, pageSize: 50, pageToken: "opaque+/=" }, { signal },
);
expect(service.list).not.toHaveBeenCalled();
expect(service.listOpenIssues).not.toHaveBeenCalled();
expect(service.getRequestHistoryByID).not.toHaveBeenCalled();
expect(service.getProjectStatusByID).not.toHaveBeenCalled();
expect(result).toMatchObject({ kind: "render", model: { kind: "issue-history", issueHistory: { ok: true, data: {
taskId, unitId, firstHref: paths.issueHistory("repo/main", taskId, unitId),
nextHref: paths.issueHistory("repo/main", taskId, unitId, "next+/="), events: [
{ timestampMs: "9007199254740993", requestHref: paths.requestIssues("repo/main", "7") },
{ event: "future", requestHref: null },
],
} } } });
expect(() => JSON.stringify(result)).not.toThrow();
});

it("sanitizes issue history failures", async () => {
const { app, service, paths } = createPageTestContext();
vi.mocked(service.listIssueHistory).mockRejectedValue(new Error("private history failure"));
const url = new URL(paths.issueHistory("repo/main", "task", ""), "https://example.test");
const result = await app.handle({ path: url.pathname, search: url.searchParams });
expect(result).toMatchObject({ kind: "render", model: { kind: "issue-history", issueHistory: { ok: false, error: expect.stringContaining("Unable to load issue history") } } });
expect(JSON.stringify(result)).not.toContain("private history failure");
});

it("requires a history task and authorizes the queue before reading history", async () => {
const { app, service, paths } = createPageTestContext();
expect(await app.handle({ path: paths.queue("repo/main"), search: new URLSearchParams({ view: "issue-history" }) })).toEqual({ kind: "not-found" });
const denied = createStovepipeWeb({ service, paths, queues: [{ name: "repo/main" }], authorize: () => false });
expect(await denied.handle({ path: paths.queue("repo/main"), search: new URLSearchParams({ view: "issue-history", task: "task" }) })).toEqual({ kind: "forbidden" });
expect(service.listIssueHistory).not.toHaveBeenCalled();
});
19 changes: 16 additions & 3 deletions web/stovepipe/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Queue, StovepipePageModel } from "./entity/index.js";
import { parseProjectPageSize, StovepipePaths } from "./core/paths.js";
import { readSection } from "./controller/page.js";
import { loadQueueRequests } from "./controller/queue.js";
import { loadOpenIssues, loadRequestIssues, loadIssueProjects } from "./controller/issues.js";
import { loadOpenIssues, loadRequestIssues, loadIssueProjects, loadIssueHistory } from "./controller/issues.js";
import { loadRequestHistory, type BuildUrlResolver } from "./controller/request.js";
import { loadProjectStatus, loadProjectIssues } from "./controller/projects.js";

Expand Down Expand Up @@ -51,6 +51,10 @@ export function createStovepipeWeb(options: StovepipeWebOptions) {
const route = parseStovepipeRoute(request.path, paths, options.queues);
if (!route) return { kind: "not-found" };
const { queue, requestId } = route;
const issueHistoryView = !requestId && request.search.get("view") === "issue-history";
const historyTask = request.search.get("task") ?? "";
const historyUnit = request.search.get("unit") ?? "";
if (issueHistoryView && !historyTask) return { kind: "not-found" };
const issuesView = !requestId && request.search.get("view") === "issues";
if (options.authorize && !(await options.authorize(request.principal, queue.name)))
return { kind: "forbidden" };
Expand All @@ -64,10 +68,19 @@ export function createStovepipeWeb(options: StovepipeWebOptions) {
href: issuesView ? paths.openIssues(queue.name) : paths.queue(queue.name),
})),
queueHref: paths.queue(queue.name),
latestHref: issuesView ? paths.openIssues(queue.name) : paths.queue(queue.name),
showLatestLink: Boolean(!requestId && request.search.get("page")),
latestHref: issueHistoryView ? paths.issueHistory(queue.name, historyTask, historyUnit)
: issuesView ? paths.openIssues(queue.name) : paths.queue(queue.name),
showLatestLink: Boolean(!requestId && !issueHistoryView && request.search.get("page")),
loadedAtMs: Date.now(),
};
if (issueHistoryView) {
const issueHistory = await readSection(
() => loadIssueHistory(service, paths, queue.name, historyTask, historyUnit,
request.search.get("page") ?? "", request.signal),
onLog, "issue history",
);
return { kind: "render", model: { ...common, kind: "issue-history", issueHistory } };
}
if (issuesView) {
const issues = await readSection(
() => loadOpenIssues(service, paths, queue.name, request.search.get("page") ?? "", request.signal),
Expand Down
Loading
Loading