huskies: merge 595_story_web_ui_settings_page_with_form_based_project_toml_editor

This commit is contained in:
dave
2026-04-17 13:33:19 +00:00
parent 982e65aec5
commit 43ca0cbc59
6 changed files with 1018 additions and 3 deletions
+71
View File
@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { ProjectSettings } from "./settings";
import { settingsApi } from "./settings";
const mockFetch = vi.fn();
@@ -22,7 +23,77 @@ function errorResponse(status: number, text: string) {
return new Response(text, { status });
}
const defaultProjectSettings: ProjectSettings = {
default_qa: "server",
default_coder_model: null,
max_coders: null,
max_retries: 2,
base_branch: null,
rate_limit_notifications: true,
timezone: null,
rendezvous: null,
watcher_sweep_interval_secs: 60,
watcher_done_retention_secs: 14400,
};
describe("settingsApi", () => {
describe("getProjectSettings", () => {
it("sends GET to /settings and returns project settings", async () => {
mockFetch.mockResolvedValueOnce(okResponse(defaultProjectSettings));
const result = await settingsApi.getProjectSettings();
expect(mockFetch).toHaveBeenCalledWith(
"/api/settings",
expect.objectContaining({
headers: expect.objectContaining({
"Content-Type": "application/json",
}),
}),
);
expect(result).toEqual(defaultProjectSettings);
});
it("uses custom baseUrl when provided", async () => {
mockFetch.mockResolvedValueOnce(okResponse(defaultProjectSettings));
await settingsApi.getProjectSettings("http://localhost:4000/api");
expect(mockFetch).toHaveBeenCalledWith(
"http://localhost:4000/api/settings",
expect.anything(),
);
});
});
describe("putProjectSettings", () => {
it("sends PUT to /settings with settings body", async () => {
const updated = { ...defaultProjectSettings, default_qa: "agent" };
mockFetch.mockResolvedValueOnce(okResponse(updated));
const result = await settingsApi.putProjectSettings(updated);
expect(mockFetch).toHaveBeenCalledWith(
"/api/settings",
expect.objectContaining({
method: "PUT",
body: JSON.stringify(updated),
}),
);
expect(result.default_qa).toBe("agent");
});
it("throws on validation error", async () => {
mockFetch.mockResolvedValueOnce(
errorResponse(400, "Invalid default_qa value"),
);
await expect(
settingsApi.putProjectSettings({
...defaultProjectSettings,
default_qa: "invalid",
}),
).rejects.toThrow("Invalid default_qa value");
});
});
describe("getEditorCommand", () => {
it("sends GET to /settings/editor and returns editor settings", async () => {
const expected = { editor_command: "zed" };
+28
View File
@@ -2,6 +2,19 @@ export interface EditorSettings {
editor_command: string | null;
}
export interface ProjectSettings {
default_qa: string;
default_coder_model: string | null;
max_coders: number | null;
max_retries: number;
base_branch: string | null;
rate_limit_notifications: boolean;
timezone: string | null;
rendezvous: string | null;
watcher_sweep_interval_secs: number;
watcher_done_retention_secs: number;
}
export interface OpenFileResult {
success: boolean;
}
@@ -34,6 +47,21 @@ async function requestJson<T>(
}
export const settingsApi = {
getProjectSettings(baseUrl?: string): Promise<ProjectSettings> {
return requestJson<ProjectSettings>("/settings", {}, baseUrl);
},
putProjectSettings(
settings: ProjectSettings,
baseUrl?: string,
): Promise<ProjectSettings> {
return requestJson<ProjectSettings>(
"/settings",
{ method: "PUT", body: JSON.stringify(settings) },
baseUrl,
);
},
getEditorCommand(baseUrl?: string): Promise<EditorSettings> {
return requestJson<EditorSettings>("/settings/editor", {}, baseUrl);
},