fix(linear): refresh setup UI and preserve channel lifecycle state
This commit is contained in:
1 parent
e9414da243
commit
3c7ebd6cd8
31 files changed
+699
-245
No files matched your search
@@ -51,6 +51,7 @@ export function ChannelQrConnectFlow({
|
||||
renderPending,
|
||||
resolveMessage,
|
||||
suppressSucceeded = false,
|
||||
onActiveChange,
|
||||
}: {
|
||||
token: string;
|
||||
channelName: string;
|
||||
@@ -66,6 +67,7 @@ export function ChannelQrConnectFlow({
|
||||
renderPending?: (context: ChannelQrConnectPendingContext) => ReactNode;
|
||||
resolveMessage?: (payload: ChannelConnectPayload) => string | undefined;
|
||||
suppressSucceeded?: boolean;
|
||||
onActiveChange?: (active: boolean) => void;
|
||||
}) {
|
||||
const { client } = useClient();
|
||||
const pageVisible = usePageVisibility();
|
||||
@@ -82,6 +84,9 @@ export function ChannelQrConnectFlow({
|
||||
const pending = connect?.status === "pending";
|
||||
const succeeded = connect?.status === "succeeded";
|
||||
const canStart = !pending && !busy;
|
||||
useEffect(() => {
|
||||
onActiveChange?.(pending || busy);
|
||||
}, [pending, busy, onActiveChange]);
|
||||
const pollingPaused = Boolean(connect && pausePolling?.(connect));
|
||||
const displayMessage = connect
|
||||
? resolveMessage?.(connect) ?? (connect.message ? channelValidationMessage(connect.message, t) : undefined)
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
describe("channel UI contributions", () => {
|
||||
it("selects channel-owned UI only through the backend manifest entry", () => {
|
||||
expect(channelUiContribution("feishu", "webui/index.tsx")?.Panel).toBeDefined();
|
||||
expect(channelUiContribution("linear", "webui/index.tsx")?.Panel).toBeDefined();
|
||||
expect(channelUiContribution("weixin", "webui/index.tsx")?.ConnectFlow).toBeDefined();
|
||||
expect(channelUiContribution("feishu", undefined)).toBeUndefined();
|
||||
expect(channelUiContribution("feishu", "webui/missing.tsx")).toBeUndefined();
|
||||
@@ -20,7 +21,7 @@ describe("channel UI contributions", () => {
|
||||
|
||||
const registrations = registeredChannelUiContributions();
|
||||
const channels = registrations.map((entry) => entry.channel);
|
||||
expect(channels).toEqual(expect.arrayContaining(["feishu", "weixin"]));
|
||||
expect(channels).toEqual(expect.arrayContaining(["feishu", "linear", "weixin"]));
|
||||
expect(new Set(channels).size).toBe(channels.length);
|
||||
expect(registrations.every((entry) => /^webui\/index\.tsx?$/.test(entry.webui))).toBe(true);
|
||||
expect(channelUiContribution("slack", "webui/index.ts")?.presentation.displayName).toBe("Slack");
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { linearManifestUrl } from "../../../nanobot/channels/linear/webui/LinearConnectFlow";
|
||||
|
||||
describe("Linear channel UI", () => {
|
||||
it("creates a private mention-only Agent app manifest with exact callback routes", () => {
|
||||
const url = new URL(
|
||||
linearManifestUrl(
|
||||
"https://nanobot.example.com",
|
||||
"/linear/webhook",
|
||||
"/linear/oauth/callback",
|
||||
),
|
||||
);
|
||||
const manifest = JSON.parse(url.searchParams.get("manifest") ?? "{}") as {
|
||||
distribution?: string;
|
||||
oauth?: { redirect_uris?: string[] };
|
||||
webhook?: { url?: string; resourceTypes?: string[] };
|
||||
};
|
||||
|
||||
expect(url.origin + url.pathname).toBe(
|
||||
"https://linear.app/settings/api/applications/new",
|
||||
);
|
||||
expect(manifest.distribution).toBe("private");
|
||||
expect(manifest.oauth?.redirect_uris).toEqual([
|
||||
"https://nanobot.example.com/linear/oauth/callback",
|
||||
]);
|
||||
expect(manifest.webhook?.url).toBe(
|
||||
"https://nanobot.example.com/linear/webhook",
|
||||
);
|
||||
expect(manifest.webhook?.resourceTypes).toEqual([
|
||||
"AgentSessionEvent",
|
||||
"PermissionChange",
|
||||
"OAuthAuthorization",
|
||||
]);
|
||||
expect(manifest.webhook?.resourceTypes).not.toContain("Comment");
|
||||
});
|
||||
});
|
||||
@@ -31,7 +31,7 @@ function channelSetupField(
|
||||
}
|
||||
|
||||
function channelSetupContract(
|
||||
channel: "discord" | "email" | "feishu" | "linear" | "matrix" | "qq",
|
||||
channel: "discord" | "email" | "feishu" | "matrix" | "qq",
|
||||
): ChannelSetupContract {
|
||||
const field = (
|
||||
name: string,
|
||||
@@ -108,22 +108,6 @@ function channelSetupContract(
|
||||
{ alternatives: [["channels.feishu.appSecret"]] },
|
||||
],
|
||||
};
|
||||
case "linear":
|
||||
return {
|
||||
fields: [
|
||||
field("clientId", "string", { required: true }),
|
||||
field("clientSecret", "secret", { required: true }),
|
||||
field("webhookSigningSecret", "secret", { required: true }),
|
||||
field("publicBaseUrl", "string", { required: true }),
|
||||
field("host", "string", { defaultValue: "0.0.0.0" }),
|
||||
field("port", "int", { defaultValue: "3979" }),
|
||||
field("webhookPath", "string", { defaultValue: "/linear/webhook" }),
|
||||
field("oauthCallbackPath", "string", {
|
||||
defaultValue: "/linear/oauth/callback",
|
||||
}),
|
||||
field("allowFrom", "list"),
|
||||
],
|
||||
};
|
||||
case "matrix":
|
||||
return {
|
||||
official_url: "https://matrix.org/ecosystem/clients/",
|
||||
@@ -875,103 +859,6 @@ describe("Settings channels", () => {
|
||||
expect(await screen.findByText("Scan with Feishu")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("saves a Linear public URL before OAuth credentials and reveals the app manifest", async () => {
|
||||
const linearFeature = {
|
||||
name: "linear",
|
||||
display_name: "Linear",
|
||||
webui: "webui/index.tsx",
|
||||
type: "channel",
|
||||
enabled: false,
|
||||
configured: false,
|
||||
installed: true,
|
||||
ready: false,
|
||||
status: "not_enabled",
|
||||
install_supported: true,
|
||||
requires_restart: false,
|
||||
setup: channelSetupContract("linear"),
|
||||
};
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/settings") return jsonResponse(settingsPayload());
|
||||
if (url === "/api/settings/cli-apps") {
|
||||
return jsonResponse({ apps: [], installed_count: 0 });
|
||||
}
|
||||
if (url === "/api/settings/mcp-presets") {
|
||||
return jsonResponse({ presets: [], installed_count: 0 });
|
||||
}
|
||||
if (url === "/api/settings/nanobot-features") {
|
||||
return jsonResponse({ features: [linearFeature], enabled_count: 0 });
|
||||
}
|
||||
return { ok: false, status: 404, json: async () => ({}) } as Response;
|
||||
}),
|
||||
);
|
||||
requestMutationMock
|
||||
.mockResolvedValueOnce({
|
||||
name: "linear",
|
||||
status: "needs_setup",
|
||||
checks: [],
|
||||
missing_fields: [
|
||||
"channels.linear.clientId",
|
||||
"channels.linear.clientSecret",
|
||||
"channels.linear.webhookSigningSecret",
|
||||
],
|
||||
can_enable: false,
|
||||
requires_restart: false,
|
||||
message: "Missing Linear credentials.",
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
name: "linear",
|
||||
saved: true,
|
||||
saved_keys: ["channels.linear.publicBaseUrl"],
|
||||
nanobot_features: {
|
||||
features: [{
|
||||
...linearFeature,
|
||||
config_values: {
|
||||
"channels.linear.publicBaseUrl": "https://nanobot.example.com",
|
||||
"channels.linear.host": "0.0.0.0",
|
||||
"channels.linear.port": "3979",
|
||||
"channels.linear.webhookPath": "/linear/webhook",
|
||||
"channels.linear.oauthCallbackPath": "/linear/oauth/callback",
|
||||
},
|
||||
configured_fields: ["channels.linear.publicBaseUrl"],
|
||||
}],
|
||||
enabled_count: 0,
|
||||
requires_restart: false,
|
||||
},
|
||||
});
|
||||
|
||||
renderSettingsView({ initialSection: "channels" });
|
||||
|
||||
expect(await screen.findByRole("button", { name: "View Linear settings" })).toBeInTheDocument();
|
||||
fireEvent.change(screen.getByPlaceholderText("https://nanobot.example.com"), {
|
||||
target: { value: "https://nanobot.example.com" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.channel.configure",
|
||||
expect.objectContaining({
|
||||
name: "linear",
|
||||
values: expect.objectContaining({
|
||||
"channels.linear.publicBaseUrl": "https://nanobot.example.com",
|
||||
}),
|
||||
}),
|
||||
150_000,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
await screen.findByText(
|
||||
"Partial settings saved. Complete the required fields before connecting.",
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
await screen.findByRole("button", { name: "Create prefilled Linear app" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("enables configured Feishu assistant without starting a new connect flow", async () => {
|
||||
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
|
||||
@@ -5,6 +5,8 @@ import { SettingsView } from "@/components/settings/SettingsView";
|
||||
import { ClientProvider } from "@/providers/ClientProvider";
|
||||
import type { SettingsPayload } from "@/lib/types";
|
||||
|
||||
export { fireEvent, screen, waitFor } from "@testing-library/react";
|
||||
|
||||
export const requestMutationMock = vi.fn();
|
||||
|
||||
export function jsonResponse(body: unknown): Response {
|
||||
|
||||
Reference in new issue
Block a user