Skip to content
Merged
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
6 changes: 3 additions & 3 deletions packages/api-client/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ export interface paths {
};
/**
* List runs
* @description Returns tenant-authorized runs. When sort is supplied, ordering is applied before cursor pagination; statuses sort lexically by their persisted state, missing values sort last, and ties use run ID. Without sort, runs remain newest-created first.
* @description Returns tenant-authorized runs. Project, job, and state filters accept repeated values and match any selected value within each filter; filters are applied before cursor pagination. When sort is supplied, ordering is applied before cursor pagination; statuses sort lexically by their persisted state, missing values sort last, and ties use run ID. Without sort, runs remain newest-created first.
*
* Requires the runs:read scope.
*
Expand Down Expand Up @@ -5773,8 +5773,8 @@ export interface operations {
get_api_v1_runs: {
parameters: {
query?: {
projectId?: string;
jobId?: string;
projectId?: string | string[];
jobId?: string | string[];
state?: ("queued" | "reserved" | "starting" | "running" | "done" | "blocked" | "failed" | "ignored" | "succeeded" | "stopping" | "stopped") | ("queued" | "reserved" | "starting" | "running" | "done" | "blocked" | "failed" | "ignored" | "succeeded" | "stopping" | "stopped")[];
contextQuery?: string;
sort?: "job" | "run" | "status" | "created" | "agent";
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/api-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ export const API_ROUTES: RouteContract[] = [
"runs:read",
{
summary: "List runs",
description: "Returns tenant-authorized runs. When sort is supplied, ordering is applied before cursor pagination; statuses sort lexically by their persisted state, missing values sort last, and ties use run ID. Without sort, runs remain newest-created first.",
description: "Returns tenant-authorized runs. Project, job, and state filters accept repeated values and match any selected value within each filter; filters are applied before cursor pagination. When sort is supplied, ordering is applied before cursor pagination; statuses sort lexically by their persisted state, missing values sort last, and ties use run ID. Without sort, runs remain newest-created first.",
responses: {
"200": {
description: "Paginated runs",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/flow-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const matchRuleSchema = z.object({
targetId: z.string().min(1),
});
export const listRunsSchema = z.object({
projectId: z.string().min(1).optional(), jobId: z.string().min(1).optional(), state: z.union([runStateSchema, z.array(runStateSchema).min(1).max(10)]).optional(),
projectId: z.union([z.guid(), z.array(z.guid()).min(1).max(100)]).optional(), jobId: z.union([z.guid(), z.array(z.guid()).min(1).max(100)]).optional(), state: z.union([runStateSchema, z.array(runStateSchema).min(1).max(10)]).optional(),
contextQuery: z.string().min(1).max(50_000).optional(),
sort: z.enum(["job", "run", "status", "created", "agent"]).optional(),
direction: z.enum(["asc", "desc"]).optional(),
Expand Down
6 changes: 4 additions & 2 deletions packages/api/src/postgres/run-query-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export class RunQueryRepository {
constructor(private database: Database, private tenantId: string) { if (!tenantId) throw new Error("tenantId is required"); }
async list(query: URLSearchParams) {
const limit = Math.max(1, Math.min(100, Number(query.get("limit") ?? 50))), cursor = decodeCursor(query.get("cursor")), sortParam = query.get("sort"), sort = sortParam && Object.hasOwn(sortExpressions, sortParam) ? sortParam as RunSort : null, direction = sort ? (query.get("direction") === "desc" ? "DESC" : "ASC") : "DESC", values: unknown[] = [this.tenantId], clauses = ["r.tenant_id=$1"];
if (query.get("projectId")) { values.push(query.get("projectId")); clauses.push(`j.project_id=$${values.length}`); }
if (query.get("jobId")) { values.push(query.get("jobId")); clauses.push(`r.job_id=$${values.length}`); }
const projectIds = query.getAll("projectId");
if (projectIds.length) { values.push(projectIds); clauses.push(`j.project_id=ANY($${values.length}::uuid[])`); }
const jobIds = query.getAll("jobId");
if (jobIds.length) { values.push(jobIds); clauses.push(`r.job_id=ANY($${values.length}::uuid[])`); }
const states = query.getAll("state");
if (states.length) { values.push(states.flatMap(state => state === "done" ? ["done", "succeeded"] : [state])); clauses.push(`r.state=ANY($${values.length}::text[])`); }
if (query.get("contextQuery")) { values.push(`%${query.get("contextQuery")}%`); clauses.push(`i.context::text ILIKE $${values.length}`); }
Expand Down
9 changes: 9 additions & 0 deletions packages/api/test/postgres-run-query-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,13 @@ describe("run timing queries", () => {
expect(sql).toContain("r.state=ANY($2::text[])");
expect(values).toEqual(["tenant", ["failed", "stopped"], 11]);
});

it("applies independent project and job filters before cursor pagination", async () => {
const query = vi.fn(async () => ({ rows: [] }));
await new RunQueryRepository({ pool: { query } } as any, "tenant").list(new URLSearchParams([['projectId', 'project-a'], ['projectId', 'project-b'], ['jobId', 'job-a'], ['jobId', 'job-b'], ['limit', '10']]));
const [sql, values] = query.mock.calls[0] as unknown as [string, unknown[]];
expect(sql).toContain("j.project_id=ANY($2::uuid[])");
expect(sql).toContain("r.job_id=ANY($3::uuid[])");
expect(values).toEqual(["tenant", ["project-a", "project-b"], ["job-a", "job-b"], 11]);
});
});
Loading
Loading