Skip to content

Commit 8f6f008

Browse files
committed
fix(dashboard-agent): error instead of an empty list_projects when organizationId is missing
An empty list read as a proven absence the sweep rule would act on; now it's an explicit error, and the fixture asserts that shape.
1 parent 88d0977 commit 8f6f008

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

internal-packages/dashboard-agent/src/tool-api-cross-project.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,16 @@ describe("list_projects org scoping", () => {
167167
]);
168168
});
169169

170-
it("fails closed to an empty list when the turn has no organizationId", async () => {
170+
it("errors rather than returning an empty list when the turn has no organizationId", async () => {
171171
vi.stubGlobal("fetch", stubProjectsFetch());
172172
const t = tools();
173173

174174
const result = await (t.list_projects as any).execute({}, {} as any);
175175

176-
expect(result.projects).toEqual([]);
176+
expect(result.projects).toBeUndefined();
177+
expect(result.error).toBe(
178+
"Couldn't determine this conversation's organization, so the project list is unavailable."
179+
);
177180
});
178181
});
179182

internal-packages/dashboard-agent/src/tool-api-transport.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ORIGIN = "https://api.example.com";
1313
const CTX = {
1414
userActorToken: "uat",
1515
apiOrigin: ORIGIN,
16+
organizationId: "org_1",
1617
projectRef: "proj_ref",
1718
environmentName: "prod",
1819
};

internal-packages/dashboard-agent/src/tool-api.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ export function buildApiTools(args: {
240240
...listProjectsSchema,
241241
execute: async () => {
242242
if (!hasAuth) return NO_AUTH;
243+
// An empty `projects` here would read as "this org has no other projects" —
244+
// a proven absence the sweep rule would then act on. Say the scope is
245+
// unknown instead of silently narrowing it to nothing.
246+
if (!organizationId) {
247+
return {
248+
error:
249+
"Couldn't determine this conversation's organization, so the project list is unavailable.",
250+
};
251+
}
243252
const result = await apiGet(origin, "/api/v1/projects", userActorToken!);
244253
if (!result.ok) return { error: `Couldn't list projects${fetchReason(result)}.` };
245254
return curateProjects(result.data, organizationId);

0 commit comments

Comments
 (0)