Skip to content

Commit 188a500

Browse files
committed
fix(gateway): route artifact task lookup through task access
1 parent 1ac5dec commit 188a500

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/gateway/server-methods/artifacts.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
22
import { artifactsHandlers, collectArtifactsFromMessages } from "./artifacts.js";
33

44
const hoisted = vi.hoisted(() => ({
5-
getTaskById: vi.fn(),
5+
getTaskSessionLookupByIdForStatus: vi.fn(),
66
loadSessionEntry: vi.fn(),
77
readSessionMessages: vi.fn(),
88
resolveSessionKeyForRun: vi.fn(),
99
}));
1010

11-
vi.mock("../../tasks/task-registry.js", () => ({
12-
getTaskById: hoisted.getTaskById,
11+
vi.mock("../../tasks/task-status-access.js", () => ({
12+
getTaskSessionLookupByIdForStatus: hoisted.getTaskSessionLookupByIdForStatus,
1313
}));
1414

1515
vi.mock("../session-utils.js", async () => {
@@ -44,7 +44,7 @@ function createResponder() {
4444
describe("artifacts RPC handlers", () => {
4545
beforeEach(() => {
4646
vi.clearAllMocks();
47-
hoisted.getTaskById.mockReturnValue(undefined);
47+
hoisted.getTaskSessionLookupByIdForStatus.mockReturnValue(undefined);
4848
hoisted.loadSessionEntry.mockReturnValue({
4949
storePath: "/tmp/sessions.json",
5050
entry: { sessionId: "sess-main", sessionFile: "/tmp/sess-main.jsonl" },
@@ -161,9 +161,8 @@ describe("artifacts RPC handlers", () => {
161161
expect(payload.artifacts?.[0]).toMatchObject({ runId: "run-1" });
162162
});
163163

164-
it("resolves taskId queries through the task registry and filters artifacts by messageTaskId", async () => {
165-
hoisted.getTaskById.mockReturnValue({
166-
taskId: "task-1",
164+
it("resolves taskId queries through task status access and filters artifacts by messageTaskId", async () => {
165+
hoisted.getTaskSessionLookupByIdForStatus.mockReturnValue({
167166
requesterSessionKey: "agent:main:main",
168167
runId: "run-for-task-1",
169168
});
@@ -196,7 +195,7 @@ describe("artifacts RPC handlers", () => {
196195
});
197196

198197
expect(list.calls[0]?.ok).toBe(true);
199-
expect(hoisted.getTaskById).toHaveBeenCalledWith("task-1");
198+
expect(hoisted.getTaskSessionLookupByIdForStatus).toHaveBeenCalledWith("task-1");
200199
expect(hoisted.resolveSessionKeyForRun).not.toHaveBeenCalled();
201200
expect(hoisted.loadSessionEntry).toHaveBeenCalledWith("agent:main:main");
202201
const listPayload = list.calls[0]?.payload as { artifacts?: Array<Record<string, unknown>> };

src/gateway/server-methods/artifacts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createHash } from "node:crypto";
2-
import { getTaskById } from "../../tasks/task-registry.js";
2+
import { getTaskSessionLookupByIdForStatus } from "../../tasks/task-status-access.js";
33
import {
44
ErrorCodes,
55
errorShape,
@@ -278,7 +278,7 @@ function resolveQuerySessionKey(query: ArtifactQuery): string | undefined {
278278
return resolveSessionKeyForRun(query.runId);
279279
}
280280
if (query.taskId) {
281-
const task = getTaskById(query.taskId);
281+
const task = getTaskSessionLookupByIdForStatus(query.taskId);
282282
const requesterSessionKey = asNonEmptyString(task?.requesterSessionKey);
283283
if (requesterSessionKey) {
284284
return requesterSessionKey;

src/tasks/task-status-access.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
import { listTasksForAgentId, listTasksForSessionKey } from "./task-registry.js";
1+
import { getTaskById, listTasksForAgentId, listTasksForSessionKey } from "./task-registry.js";
22
import type { TaskRecord } from "./task-registry.types.js";
33

4+
export function getTaskSessionLookupByIdForStatus(
5+
taskId: string,
6+
): Pick<TaskRecord, "requesterSessionKey" | "runId"> | undefined {
7+
const task = getTaskById(taskId);
8+
return task
9+
? {
10+
requesterSessionKey: task.requesterSessionKey,
11+
...(task.runId ? { runId: task.runId } : {}),
12+
}
13+
: undefined;
14+
}
15+
416
export function listTasksForSessionKeyForStatus(sessionKey: string): TaskRecord[] {
517
return listTasksForSessionKey(sessionKey);
618
}

0 commit comments

Comments
 (0)