Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
65dfdb7
docs: add plan for server-side runs grouping (#568)
cedricvidal Apr 11, 2026
260a8bd
docs: revise plan — single endpoint with groupBy param, server-side a…
cedricvidal Apr 11, 2026
db42ad9
feat: add shared grouping types and schemas (#568)
cedricvidal Apr 11, 2026
9809df8
feat: add groupBy param to list endpoint with aggregation pipeline (#…
cedricvidal Apr 11, 2026
ac10a3e
feat: add RunGroup types and api.listRunGroups() in portal (#568)
cedricvidal Apr 11, 2026
9c78ef3
feat: use server-side groups in RunsList, fetch runs on expand (#568)
cedricvidal Apr 11, 2026
2f8d208
test: add grouping pipeline unit tests and endpoint tests (#568)
cedricvidal Apr 11, 2026
410f74b
fix: remove unused submissionId/taskPromptId props from GroupRows
cedricvidal Apr 11, 2026
27f7cf0
fix: disable flat runs query when groupBy is active
cedricvidal Apr 11, 2026
7f94214
fix: restore status/outcome progress bars in group rows
cedricvidal Apr 11, 2026
2d7bec7
fix: restore group-level checkbox for selecting all runs in expanded …
cedricvidal Apr 11, 2026
8e31e08
fix: restore report progress bar in group rows with per-group summary…
cedricvidal Apr 11, 2026
90c7612
feat: include runIds in RunGroup for report/checkbox without expanding
cedricvidal Apr 11, 2026
b5aa3b4
feat: sort groups by label for deterministic ordering
cedricvidal Apr 11, 2026
c5797c1
fix: remove duplicate runIds declarations
cedricvidal Apr 11, 2026
488462e
fix: remove duplicate runIds in portal types
cedricvidal Apr 11, 2026
4b331d7
fix: sort groups by key instead of label for deterministic ordering
cedricvidal Apr 11, 2026
5416301
feat: move status/outcome/task filtering server-side
cedricvidal Apr 11, 2026
5cf0ee0
fix: pass status/outcome filters to expanded group runs query
cedricvidal Apr 11, 2026
2e82f10
refactor: remove dead client-side grouping code from portal
cedricvidal Apr 11, 2026
0fafd74
Merge remote-tracking branch 'origin/main' into feat/server-side-grou…
cedricvidal Apr 11, 2026
65c2e85
refactor: remove unused computeStats from server-side grouping
cedricvidal Apr 11, 2026
27a2678
chore: remove plan.md from version control
cedricvidal Apr 11, 2026
9780643
feat: add single-field indexes for requests filter/group fields
cedricvidal Apr 12, 2026
6f5bb69
docs: add database schema & indexes doc, update migrations table
cedricvidal Apr 12, 2026
98cc909
chore: rename database.md to db.md for consistency
cedricvidal Apr 12, 2026
c41c12b
docs: fix CI/CD section — migrations run automatically via K8s Job
cedricvidal Apr 12, 2026
f84beda
docs: mention Docker Compose also runs migrations automatically
cedricvidal Apr 12, 2026
8f72dd6
fix: add extensions to GroupUniformValues and fix portal shared import
cedricvidal Apr 12, 2026
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
111 changes: 111 additions & 0 deletions apps/api/src/endpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,117 @@ describe("API Endpoints", () => {
expect(Array.isArray(res.body)).toBe(true);
expect(res.body[0]).toHaveProperty("id", "r1");
});

it("returns grouped results when groupBy=task", async () => {
const groupedDocs = [
{ key: "tp-1", label: "Build a calculator", aggregates: { count: 3, turns: { min: 1, max: 3, mean: 2, stdDev: 0.8 }, duration: null, promptTokens: null, completionTokens: null }, uniform: { workerType: "coder-acp-copilot" } },
];
(mocks.collection.aggregate as any).mockReturnValue({
toArray: vi.fn().mockResolvedValue(groupedDocs),
});

const res = await request(app).get("/api/v1/requests?groupBy=task");
expect(res.status).toBe(200);
expect(Array.isArray(res.body)).toBe(true);
expect(res.body[0]).toHaveProperty("key", "tp-1");
expect(res.body[0]).toHaveProperty("aggregates");
expect(res.body[0].aggregates).toHaveProperty("count", 3);
expect(res.body[0]).toHaveProperty("uniform");
});

it("returns grouped results when groupBy=submissionId", async () => {
const groupedDocs = [
{ key: "sub-1", label: "sub-1", aggregates: { count: 2, turns: null, duration: null, promptTokens: null, completionTokens: null }, uniform: {} },
];
(mocks.collection.aggregate as any).mockReturnValue({
toArray: vi.fn().mockResolvedValue(groupedDocs),
});

const res = await request(app).get("/api/v1/requests?groupBy=submissionId");
expect(res.status).toBe(200);
expect(res.body[0]).toHaveProperty("key", "sub-1");
});

it("calls aggregate pipeline when groupBy is provided", async () => {
(mocks.collection.aggregate as any).mockReturnValue({
toArray: vi.fn().mockResolvedValue([]),
});

await request(app).get("/api/v1/requests?groupBy=task");
expect(mocks.collection.aggregate).toHaveBeenCalled();
const pipeline = (mocks.collection.aggregate as any).mock.calls[0][0];
expect(pipeline[0]).toHaveProperty("$match");
// buildGroupingPipeline adds 4 stages ($addFields, $group, $project, $sort)
expect(pipeline).toHaveLength(5); // $match + 4 from buildGroupingPipeline
});

it("does not call aggregate when groupBy is absent", async () => {
(mocks.collection.find as any).mockReturnValue({
sort: vi.fn().mockReturnValue({
toArray: vi.fn().mockResolvedValue([]),
}),
});

await request(app).get("/api/v1/requests");
expect(mocks.collection.aggregate).not.toHaveBeenCalled();
});

it("passes status filter to find query", async () => {
(mocks.collection.find as any).mockReturnValue({
sort: vi.fn().mockReturnValue({
toArray: vi.fn().mockResolvedValue([]),
}),
});

await request(app).get("/api/v1/requests?status=done");
expect(mocks.collection.find).toHaveBeenCalledWith(
expect.objectContaining({ status: "done" }),
);
});

it("passes outcome filter to find query", async () => {
(mocks.collection.find as any).mockReturnValue({
sort: vi.fn().mockReturnValue({
toArray: vi.fn().mockResolvedValue([]),
}),
});

await request(app).get("/api/v1/requests?outcome=succeeded");
expect(mocks.collection.find).toHaveBeenCalledWith(
expect.objectContaining({ outcome: "succeeded" }),
);
});

it("passes status and outcome filters to aggregate pipeline $match", async () => {
(mocks.collection.aggregate as any).mockReturnValue({
toArray: vi.fn().mockResolvedValue([]),
});

await request(app).get("/api/v1/requests?groupBy=task&status=done&outcome=failed");
const pipeline = (mocks.collection.aggregate as any).mock.calls[0][0];
expect(pipeline[0]).toEqual(
expect.objectContaining({
$match: expect.objectContaining({ status: "done", outcome: "failed" }),
}),
);
});

it("combines status, outcome, and worker filters", async () => {
(mocks.collection.find as any).mockReturnValue({
sort: vi.fn().mockReturnValue({
toArray: vi.fn().mockResolvedValue([]),
}),
});

await request(app).get("/api/v1/requests?status=processing&outcome=succeeded&worker=coder-acp-copilot");
expect(mocks.collection.find).toHaveBeenCalledWith(
expect.objectContaining({
status: "processing",
outcome: "succeeded",
workerType: "coder-acp-copilot",
}),
);
});
});

describe("GET /api/v1/requests/:id", () => {
Expand Down
105 changes: 105 additions & 0 deletions apps/api/src/grouping.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { describe, it, expect } from "vitest";
import { buildGroupingPipeline } from "./grouping.js";

describe("buildGroupingPipeline", () => {
it("returns 4 pipeline stages for task grouping", () => {
const pipeline = buildGroupingPipeline("task");
expect(pipeline).toHaveLength(4);
expect(pipeline[0]).toHaveProperty("$addFields");
expect(pipeline[1]).toHaveProperty("$group");
expect(pipeline[2]).toHaveProperty("$project");
expect(pipeline[3]).toHaveProperty("$sort");
});

it("returns 4 pipeline stages for submissionId grouping", () => {
const pipeline = buildGroupingPipeline("submissionId");
expect(pipeline).toHaveLength(4);
});

it("$sort stage orders by key ascending", () => {
const pipeline = buildGroupingPipeline("task");
expect(pipeline[3]).toEqual({ $sort: { key: 1 } });
});

it("groups by taskPromptId for task grouping", () => {
const pipeline = buildGroupingPipeline("task");
const addFields = pipeline[0].$addFields as Record<string, unknown>;
// _groupKey should reference $taskPromptId with fallback to scenario.task
expect(addFields._groupKey).toBeDefined();
});

it("groups by submissionId for submissionId grouping", () => {
const pipeline = buildGroupingPipeline("submissionId");
const addFields = pipeline[0].$addFields as Record<string, unknown>;
expect(addFields._groupKey).toBeDefined();
});

it("$group stage uses _groupKey as _id", () => {
const pipeline = buildGroupingPipeline("task");
const group = pipeline[1].$group as Record<string, unknown>;
expect(group._id).toBe("$_groupKey");
});

it("$group stage accumulates count and stat arrays", () => {
const pipeline = buildGroupingPipeline("task");
const group = pipeline[1].$group as Record<string, unknown>;
expect(group.count).toEqual({ $sum: 1 });
expect(group._turnCounts).toBeDefined();
expect(group._durations).toBeDefined();
expect(group._promptTokensList).toBeDefined();
expect(group._completionTokensList).toBeDefined();
});

it("$group stage accumulates status and outcome counts", () => {
const pipeline = buildGroupingPipeline("task");
const group = pipeline[1].$group as Record<string, unknown>;
expect(group._statusPending).toBeDefined();
expect(group._statusProcessing).toBeDefined();
expect(group._statusDone).toBeDefined();
expect(group._outcomeSucceeded).toBeDefined();
expect(group._outcomeFailed).toBeDefined();
expect(group._outcomeFinished).toBeDefined();
});

it("$group stage collects distinct values for uniform detection", () => {
const pipeline = buildGroupingPipeline("task");
const group = pipeline[1].$group as Record<string, unknown>;
expect(group._workerTypes).toBeDefined();
expect(group._models).toBeDefined();
expect(group._agentVersions).toBeDefined();
expect(group._platforms).toBeDefined();
expect(group._statuses).toBeDefined();
expect(group._submissionIds).toBeDefined();
expect(group._tasks).toBeDefined();
expect(group._mcpKeys).toBeDefined();
expect(group._skillKeys).toBeDefined();
});

it("$group stage collects run IDs", () => {
const pipeline = buildGroupingPipeline("task");
const group = pipeline[1].$group as Record<string, unknown>;
expect(group._runIds).toEqual({ $push: "$_id" });
});

it("$project stage outputs key, label, runIds, aggregates, uniform", () => {
const pipeline = buildGroupingPipeline("task");
const project = (pipeline[2] as { $project: Record<string, unknown> }).$project;
expect(project._id).toBe(0);
expect(project.key).toBeDefined();
expect(project.runIds).toBe("$_runIds");
expect(project.label).toBeDefined();
expect(project.aggregates).toBeDefined();
expect(project.uniform).toBeDefined();
});

it("$project aggregates include statusCounts and outcomeCounts", () => {
const pipeline = buildGroupingPipeline("task");
const project = pipeline[2].$project as Record<string, unknown>;
const aggregates = project.aggregates as Record<string, unknown>;
expect(aggregates.statusCounts).toEqual({ pending: "$_statusPending", processing: "$_statusProcessing", done: "$_statusDone" });
expect(aggregates.outcomeCounts).toEqual({ succeeded: "$_outcomeSucceeded", failed: "$_outcomeFailed", finished: "$_outcomeFinished" });
});
});
Loading