bb36cb9e01
* refactor: move integrations to top-level settings with install-wide configs Jira and Linear configurations are now install-wide singletons rather than per-workspace duplicates, and the GitHub/Jira/Linear settings pages live under /settings/integrations instead of being nested inside each workspace. Issue and PR watchers stay per-workspace via a workspace switcher inside each integration page. Backend ships one-shot migrations that promote the most-recently-updated row and copy its secret onto the new global key. * fix: address review feedback on integrations refactor Fix migration crash on installs whose jira_configs predate the auth-health columns by selecting only guaranteed-present legacy columns and falling back to defaults for the rest. Cover the empty-legacy-table and pre-health-columns upgrade paths with new store tests. On the frontend, refactor useIntegrationEnabled to take string parameters instead of an inline options object so getSnapshot stays referentially stable across renders, and stop dispatching a misleading no-op sync event when localStorage.setItem fails in private mode. * fix: hydrate workspace list on integration settings pages The integration pages wrapped their content in a fresh StateProvider, which created a nested store scope with an empty initial state and shadowed the settings layout's hydrated workspace list. WorkspaceScopedSection then saw zero workspaces and rendered the "Create a workspace to configure this integration" empty state even when the user had workspaces. Drop the redundant StateProvider from the jira and linear pages so they share the layout's store. The github page switches to StateHydrator so it can still seed the GitHub OAuth status without resetting the rest of the store. * refactor(integrations): flatten watcher tables, pick workspace in create dialog Hiding watchers behind a workspace switcher made the list invisible at a glance — a user with multiple workspaces had to flip between each one to see what was configured. Replace the switcher with a flat table that lists every watch across every workspace, with a Workspace column for context, and move workspace selection into the create dialog so the user picks once when the watcher is born. Backend: jira list-issue-watches and github list-review-watches / list-issue-watches accept the workspace_id query param as optional; when omitted, the corresponding store ListAll* method returns rows across every workspace. Per-row mutations still require workspace_id as the IDOR guard. Frontend: useReviewWatches / useIssueWatches / useJiraIssueWatches gain a three-state contract — string for one workspace, undefined for all workspaces, null to skip fetching. Watch tables grow an optional showWorkspace column. Watch dialogs accept an optional workspaceId prop; when absent, the dialog renders a workspace dropdown for the create flow (disabled when editing existing rows so refs aren't orphaned). Github review-watch-dialog crossed the 600-line lint cap so the prompt editor moved to review-watch-prompt-field.tsx. * fix(integrations): make watcher step dropdown reactive across workspace switches Switching to a workspace whose workflows had to be fetched left the workflow step dropdown stuck — the user could pick a workflow but the step Select either showed the previous workflow's steps or appeared inert. The cause was the per-dialog useWorkflowSteps hook deferring its empty-state reset via Promise.resolve().then(() => setSteps([])) to dodge a setState-in-effect lint rule, which let stale steps survive into the next render and gave Radix nothing to anchor the popover to during the in-flight fetch. Hoist the hook into a shared useWorkflowSteps that resets via React's official setState-during-render pattern, exposes a loading flag, and returns a stepPlaceholder helper so the Select can render "Loading steps…" or "No steps in this workflow" instead of an empty popover. The Step Select is now also disabled while loading or when there are no steps, making the state of the dropdown unambiguous. * fix: address PR review feedback on integrations refactor Backend: - linear migration: add column-presence guard mirroring the Jira fix so installs that upgraded from the original Linear schema (without org_slug / last_checked_at / last_ok / last_error) don't crash startup with "no such column"; add TestStore_MigrateLegacyPerWorkspaceTable_PreHealthColumns - jira/handlers.go: drop the now-unused errMsgWorkspaceIDRequired constant that was failing golangci-lint - jira/mock_controller_test.go (new): cover setAuthHealth happy-path and invalid-JSON-rejection so the singleton-shaped payload is locked in Frontend: - useIntegrationAvailable: gate the auth-health probe on loaded && enabled so disabled integrations don't poll /config every 90s - use-workflow-steps: initialize loading to !!workflowId so edit-mode opens show "Loading steps…" instead of "No steps in this workflow" before the first fetch lands - use-workflow-steps.test.ts (new): cover the empty/non-empty workflowId, workflow switch, fetch error, and stepPlaceholder branches - use-linear-enabled.test: tighten the legacy-key migration assertion to pin the migrated value rather than just verifying key cleanup --------- Co-authored-by: Kandev Agent <agent@kandev.dev>
176 lines
5.6 KiB
TypeScript
176 lines
5.6 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
|
|
// Pin the backend config to a deterministic base so URL assertions don't
|
|
// depend on whatever environment the tests inherit.
|
|
vi.mock("@/lib/config", () => ({
|
|
getBackendConfig: () => ({ apiBaseUrl: "http://api.test" }),
|
|
}));
|
|
|
|
import {
|
|
deleteLinearConfig,
|
|
getLinearConfig,
|
|
getLinearIssue,
|
|
listLinearStates,
|
|
listLinearTeams,
|
|
searchLinearIssues,
|
|
setLinearConfig,
|
|
setLinearIssueState,
|
|
testLinearConnection,
|
|
} from "./linear-api";
|
|
|
|
const BASE = "http://api.test/api/v1/linear";
|
|
const CONFIG_URL = `${BASE}/config`;
|
|
const AUTH = "api_key" as const;
|
|
|
|
type FetchInput = Parameters<typeof fetch>[0];
|
|
type FetchInit = Parameters<typeof fetch>[1];
|
|
|
|
const fetchSpy = vi.fn<[FetchInput, FetchInit?], Promise<Response>>();
|
|
|
|
beforeEach(() => {
|
|
fetchSpy.mockReset();
|
|
vi.stubGlobal("fetch", fetchSpy);
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
function jsonResponse(body: unknown, init?: ResponseInit): Response {
|
|
return new Response(JSON.stringify(body), {
|
|
status: 200,
|
|
headers: { "Content-Type": "application/json" },
|
|
...init,
|
|
});
|
|
}
|
|
|
|
function noContent(): Response {
|
|
return new Response(null, { status: 204 });
|
|
}
|
|
|
|
function lastCall(): { url: string; init: FetchInit | undefined } {
|
|
const call = fetchSpy.mock.calls.at(-1);
|
|
if (!call) throw new Error("expected fetch to have been called");
|
|
return { url: String(call[0]), init: call[1] };
|
|
}
|
|
|
|
describe("getLinearConfig", () => {
|
|
it("returns null on 204 No Content (not configured yet)", async () => {
|
|
fetchSpy.mockResolvedValueOnce(noContent());
|
|
const cfg = await getLinearConfig();
|
|
expect(cfg).toBeNull();
|
|
});
|
|
|
|
it("hits the install-wide /config route with no query params", async () => {
|
|
fetchSpy.mockResolvedValueOnce(noContent());
|
|
await getLinearConfig();
|
|
expect(lastCall().url).toBe(CONFIG_URL);
|
|
});
|
|
|
|
it("returns the parsed config on 200", async () => {
|
|
fetchSpy.mockResolvedValueOnce(
|
|
jsonResponse({
|
|
authMethod: AUTH,
|
|
defaultTeamKey: "ENG",
|
|
hasSecret: true,
|
|
lastOk: true,
|
|
createdAt: "2026-01-01T00:00:00Z",
|
|
updatedAt: "2026-01-01T00:00:00Z",
|
|
}),
|
|
);
|
|
const cfg = await getLinearConfig();
|
|
expect(cfg?.defaultTeamKey).toBe("ENG");
|
|
});
|
|
});
|
|
|
|
describe("setLinearConfig", () => {
|
|
it("POSTs the payload to /api/v1/linear/config", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ authMethod: AUTH }));
|
|
await setLinearConfig({ authMethod: AUTH, secret: "tok" });
|
|
const { url, init } = lastCall();
|
|
expect(url).toBe(CONFIG_URL);
|
|
expect(init?.method).toBe("POST");
|
|
expect(JSON.parse(String(init?.body))).toMatchObject({
|
|
authMethod: AUTH,
|
|
secret: "tok",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("deleteLinearConfig", () => {
|
|
it("issues DELETE on /config", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ deleted: true }));
|
|
await deleteLinearConfig();
|
|
const { url, init } = lastCall();
|
|
expect(url).toBe(CONFIG_URL);
|
|
expect(init?.method).toBe("DELETE");
|
|
});
|
|
});
|
|
|
|
describe("testLinearConnection", () => {
|
|
it("POSTs to /api/v1/linear/config/test", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ ok: true }));
|
|
await testLinearConnection({ authMethod: AUTH, secret: "x" });
|
|
const { url, init } = lastCall();
|
|
expect(url).toBe(`${CONFIG_URL}/test`);
|
|
expect(init?.method).toBe("POST");
|
|
});
|
|
});
|
|
|
|
describe("listLinearTeams + listLinearStates", () => {
|
|
it("listLinearTeams targets /api/v1/linear/teams", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ teams: [] }));
|
|
await listLinearTeams();
|
|
expect(lastCall().url).toBe(`${BASE}/teams`);
|
|
});
|
|
|
|
it("listLinearStates includes the team_key", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ states: [] }));
|
|
await listLinearStates("ENG");
|
|
expect(lastCall().url).toBe(`${BASE}/states?team_key=ENG`);
|
|
});
|
|
});
|
|
|
|
describe("searchLinearIssues", () => {
|
|
it("joins stateIds as a CSV in the state_ids query param", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ issues: [], maxResults: 25, isLast: true }));
|
|
await searchLinearIssues({ stateIds: ["s1", "s2", "s3"] });
|
|
const { url } = lastCall();
|
|
expect(url).toContain("state_ids=s1%2Cs2%2Cs3");
|
|
});
|
|
|
|
it("omits empty optional filters from the URL", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ issues: [], maxResults: 25, isLast: true }));
|
|
await searchLinearIssues({});
|
|
const { url } = lastCall();
|
|
expect(url).toBe(`${BASE}/issues`);
|
|
});
|
|
|
|
it("encodes a multi-word query string", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ issues: [], maxResults: 25, isLast: true }));
|
|
await searchLinearIssues({ query: "fix login & signup" });
|
|
const { url } = lastCall();
|
|
// URLSearchParams uses + for spaces, %26 for & — both indicate proper encoding.
|
|
expect(url).toContain("query=fix+login+%26+signup");
|
|
});
|
|
});
|
|
|
|
describe("getLinearIssue", () => {
|
|
it("URL-encodes the identifier as a path segment", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ id: "i1", identifier: "ENG/1" }));
|
|
await getLinearIssue("ENG/1");
|
|
expect(lastCall().url).toBe(`${BASE}/issues/ENG%2F1`);
|
|
});
|
|
});
|
|
|
|
describe("setLinearIssueState", () => {
|
|
it("POSTs { stateId } in the body to the issue's /state route", async () => {
|
|
fetchSpy.mockResolvedValueOnce(jsonResponse({ transitioned: true }));
|
|
await setLinearIssueState("ENG-1", "state-id-123");
|
|
const { url, init } = lastCall();
|
|
expect(url).toBe(`${BASE}/issues/ENG-1/state`);
|
|
expect(init?.method).toBe("POST");
|
|
expect(JSON.parse(String(init?.body))).toEqual({ stateId: "state-id-123" });
|
|
});
|
|
});
|