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
7 changes: 6 additions & 1 deletion packages/cli/src/lib/api/seer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
* which returns blocks instead of steps.
*/

import type { AutofixResponse, AutofixState } from "../../types/seer.js";
import {
type AutofixResponse,
AutofixResponseSchema,
type AutofixState,
} from "../../types/seer.js";

import { resolveOrgRegion } from "../region.js";

Expand Down Expand Up @@ -96,6 +100,7 @@ export async function getAutofixState(
`/organizations/${orgSlug}/issues/${issueId}/autofix/`,
{
params: EXPLORER_MODE_PARAMS,
schema: AutofixResponseSchema,
}
);

Expand Down
63 changes: 46 additions & 17 deletions packages/cli/test/lib/api-client.seer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "../../src/lib/api-client.js";
import { setAuthToken } from "../../src/lib/db/auth.js";
import { setOrgRegion } from "../../src/lib/db/regions.js";
import { ApiError } from "../../src/lib/errors.js";
import { useTestConfigDir } from "../helpers.js";

useTestConfigDir("test-seer-api-");
Expand Down Expand Up @@ -231,31 +232,58 @@ describe("getAutofixState", () => {
expect(result).toBeNull();
});

test.each([
{ name: "a null response", payload: null },
{ name: "a missing status", payload: { autofix: { run_id: 1 } } },
{
name: "a non-string status",
payload: { autofix: { run_id: 1, status: 123 } },
},
])("throws a validation ApiError for $name", async ({ payload }) => {
globalThis.fetch = async () =>
new Response(JSON.stringify(payload), {
status: 200,
headers: { "Content-Type": "application/json" },
});

const request = getAutofixState("test-org", "123456789");

await expect(request).rejects.toBeInstanceOf(ApiError);
await expect(request).rejects.toMatchObject({
message:
"Unexpected response format from /organizations/test-org/issues/123456789/autofix/",
status: 200,
detail: expect.any(String),
});
});

test("returns completed state with blocks", async () => {
const blocks = [
{
id: "block-1",
message: { role: "assistant", content: "Found the root cause" },
timestamp: "2025-01-01T00:00:00Z",
artifacts: [
{
key: "root_cause",
data: {
one_line_description: "Test cause",
five_whys: ["Why 1"],
},
reason: "",
},
],
},
];

globalThis.fetch = async () =>
new Response(
JSON.stringify({
autofix: {
run_id: 12_345,
status: "completed",
updated_at: "2025-01-01T00:00:00Z",
blocks: [
{
id: "block-1",
message: { role: "assistant", content: "Found the root cause" },
timestamp: "2025-01-01T00:00:00Z",
artifacts: [
{
key: "root_cause",
data: {
one_line_description: "Test cause",
five_whys: ["Why 1"],
},
reason: "",
},
],
},
],
blocks,
},
}),
{
Expand All @@ -266,6 +294,7 @@ describe("getAutofixState", () => {

const result = await getAutofixState("test-org", "123456789");
expect(result?.status).toBe("COMPLETED");
expect(result?.blocks).toEqual(blocks);
});
});

Expand Down
Loading