Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ The unsigned installer is for internal verification. If WebView2 is absent, its

Choose **Connect an existing service** on Home or in **Services & Agents**. Enter the service address and choose its authentication mode. Use HTTPS for remote services and a literal loopback address for local HTTP. Choose a [verified compatibility profile](src-tauri/src/connections/compatibility.json) that matches the Server deployment. Bearer credentials can stay in the system vault or be limited to the current session.

For a new HTTPS connection to a service that uses a private CA, open **Advanced settings** and paste the PEM CA certificate from your administrator. Desktop trusts the certificate alongside system certificates for this connection and still verifies the hostname. Leave the field empty to use the system trust store alone.

Confirm the connection, then use the space menu in the top bar to select an authorized space. The Desktop application verifies the target and credentials before enabling qualified operations.

## Save, search, and read a memory
Expand Down
2 changes: 2 additions & 0 deletions desktop/README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pnpm --dir desktop desktop:dev

从首页选择「已有服务」,或在「服务与 Agent」打开连接对话框。填写服务地址并选择认证方式。远程服务使用 HTTPS,本机 HTTP 使用字面回环地址。选择与部署匹配的[已验证兼容配置](src-tauri/src/connections/compatibility.json)。Bearer 凭据可保存在系统凭据库,也可仅用于本次会话。

如果要新建 HTTPS 连接,且服务使用私有 CA,请打开「高级设置」并粘贴管理员提供的 PEM 格式 CA 证书。Desktop 仅在此连接中额外信任该证书,并继续校验主机名。留空时仅使用系统信任库。

确认连接后,在顶部空间菜单选择可访问的空间。桌面端核对目标和凭据,通过对应资格校验的操作才可使用。

## 显式就绪探测与连接身份
Expand Down
94 changes: 83 additions & 11 deletions desktop/ui/src/app/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import { contractSha256 } from "../generated/operations";
import { desktopApi } from "../shared/ipc";
import { messages, type Language } from "./messages";
import { activeCheckReport, refreshConnectionState } from "./context";
import { connectionError, connectionMessages } from "./connection-messages";
import {
connectionError,
connectionErrorCode,
connectionMessages,
} from "./connection-messages";
import { PageFeedback } from "@/components/ui/feedback";
import {
Dialog,
Expand All @@ -57,6 +61,7 @@ import { Button } from "@/components/ui/button";
import { PageActionButton } from "@/components/ui/page-action-button";
import { ActionNotification } from "@/components/ui/action-notification";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import {
Select,
SelectContent,
Expand All @@ -68,6 +73,7 @@ import {
Bot,
CircleCheck,
Check,
ChevronDown,
Copy,
Eye,
EyeOff,
Expand Down Expand Up @@ -801,10 +807,18 @@ export function QuickConnectDialog({
const [storage, setStorage] = useState<StorageChoice>("persistent");
const [savedProfile, setSavedProfile] = useState<ProfileView | null>(null);
const [credentialVisible, setCredentialVisible] = useState(false);
const [advancedOpen, setAdvancedOpen] = useState(false);
const [caPem, setCaPem] = useState("");
const [submitted, setSubmitted] = useState(false);
const zh = language === "zh";
const t = connectionMessages[language];
const dialogTitle = title ?? (zh ? "连接服务" : "Connect service");
const supportsCustomCa =
!preview && endpoint.trim().toLowerCase().startsWith("https://");
const certificateError =
supportsCustomCa &&
advancedOpen &&
connectionErrorCode(error) === "invalid_certificate";
const duplicate = state?.profiles.some(
(profile) =>
profile.id !== savedProfile?.id && profile.name.trim() === name.trim(),
Expand Down Expand Up @@ -863,7 +877,7 @@ export function QuickConnectDialog({
name: name.trim(),
endpoint: endpoint.trim(),
authentication,
caPem: null,
caPem: supportsCustomCa && caPem.trim() ? caPem : null,
compatibility,
keepCredential: false,
credential: requiresCredential ? { secret: credential, storage } : null,
Expand All @@ -874,21 +888,26 @@ export function QuickConnectDialog({
if (!profile) throw { code: "not_found" };
setSavedProfile(profile);
const checked = await desktopApi.check(profile.id, true);
if (
checked.active?.connectionId !== profile.id ||
!checked.active.report.compatibilityVerified
)
const active = checked.active;
if (active?.connectionId !== profile.id)
throw { code: "compatibility_unverified" };
const defaultScope = await desktopApi.defaultScope(
checked.active.generation,
);
if (!active.report.compatibilityVerified) {
const failure = active.report.liveness.error;
throw failure?.code === "tls"
? failure
: { code: "compatibility_unverified" };
}
Comment on lines +901 to +909

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Surface TLS failures from discovery and connectionIdentity as well (non-blocking)

In native session.rs, compatibilityVerified is determined by discovery and connection_identity, whereas liveness is an independent HTTP request that does not gate compatibilityVerified. If discovery or connection_identity fails with code: "tls" while liveness succeeds (e.g. mixed edge TLS config or cert rotation), this branch discards the TLS error and asks the user to select a verified compatibility profile instead.

Required outcome: inspect [active.report.discovery?.error, active.report.connectionIdentity?.error, active.report.liveness.error] for a tls error before falling back to compatibility_unverified.

const defaultScope = await desktopApi.defaultScope(active.generation);
const selected = await desktopApi.selectScope(
checked.active.generation,
active.generation,
defaultScope.scope_id,
);
onState(selected);
onConnected();
} catch (cause) {
if (connectionErrorCode(cause) === "invalid_certificate") {
setAdvancedOpen(true);
}
setError(cause);
if (!preview) await refreshConnectionState(onState);
} finally {
Expand All @@ -911,7 +930,7 @@ export function QuickConnectDialog({
<DialogCloseButton label={zh ? "关闭弹窗" : "Close dialog"} />
</DialogHeader>
<DialogBody>
{error != null && (
{error != null && !certificateError && (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep invalid CA feedback visible in the dialog viewport on rejection (non-blocking)

When an invalid PEM is submitted after collapsing Advanced settings (or after scrolling back to the top of the dialog) at the default 1280×800 window size, setAdvancedOpen(true) expands the section and !certificateError suppresses the top PageFeedback, leaving the field error below the scrollable DialogBody viewport with zero visible height.

Required outcome: scroll the CA field/error into view and focus the CA input when invalid_certificate is returned (or retain a visible summary in view).

<PageFeedback
compact
kind="error"
Expand Down Expand Up @@ -1112,6 +1131,59 @@ export function QuickConnectDialog({
</Select>
</Field>
)}
{supportsCustomCa && (
<div className="grid gap-2">
<Button
variant="text"
size="sm"
type="button"
className="justify-self-start"
aria-controls="quick-connection-advanced"
aria-expanded={advancedOpen}
onClick={() => setAdvancedOpen((open) => !open)}
>
{zh ? "高级设置" : "Advanced settings"}
<ChevronDown
aria-hidden="true"
className={advancedOpen ? "rotate-180" : undefined}
/>
</Button>
<div id="quick-connection-advanced" hidden={!advancedOpen}>
<Field>
<FieldLabel htmlFor="quick-connection-ca-pem">
{zh
? "CA 证书(PEM,可选)"
: "CA certificate (PEM, optional)"}
</FieldLabel>
<Textarea
id="quick-connection-ca-pem"
value={caPem}
spellCheck={false}
aria-invalid={certificateError || undefined}
aria-describedby={
certificateError
? "quick-connection-ca-help quick-connection-ca-error"
: "quick-connection-ca-help"
}
onChange={(event) => {
setCaPem(event.target.value);
setError(null);
}}
/>
<FieldDescription id="quick-connection-ca-help">
{zh
? "粘贴管理员提供的 CA 证书。Desktop 仅在此连接中额外信任该证书。"
: "Paste the CA certificate from your administrator. Desktop trusts it alongside system certificates for this connection."}
</FieldDescription>
{certificateError && (
<FieldError id="quick-connection-ca-error" role="alert">
{t.invalid_certificate}
</FieldError>
)}
</Field>
</div>
</div>
)}
</fieldset>
</DialogBody>
<DialogFooter>
Expand Down
146 changes: 146 additions & 0 deletions desktop/ui/tests/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ test.each(["success", "failure"] as const)(
await user.click(
within(dialog).getByRole("button", { name: "Confirm and connect" }),
);
expect(desktopApi.save).toHaveBeenCalledWith(
expect.objectContaining({ caPem: null }),
);
expect(
within(dialog).getByRole("button", { name: /Connecting/ }),
).toBeTruthy();
Expand Down Expand Up @@ -503,6 +506,149 @@ test.each(["success", "failure"] as const)(
},
);

test.each(["https", "http"] as const)(
"keeps rejected CA input for correction and submits the right trust settings on %s retry",
async (retryScheme) => {
globalThis.localStorage.setItem("desktop-language", "en");
const connected = connectedMemoryState();
connected.compatibilityProfiles = [
{
id: "qualified",
serverCommit: "fixture",
contractSha256,
artifactSha256: "fixture",
operations: [],
},
];
const disconnected = {
...connected,
generation: 0,
profiles: [],
reports: [],
active: null,
};
const httpsEndpoint = "https://memory.example.com";
const retryEndpoint =
retryScheme === "https" ? httpsEndpoint : "http://127.0.0.1:8000";
const certificate =
"-----BEGIN CERTIFICATE-----\nfixture\n-----END CERTIFICATE-----";
vi.mocked(desktopApi.state).mockResolvedValue(disconnected);
vi.mocked(desktopApi.save)
.mockRejectedValueOnce({ code: "invalid_certificate" })
.mockResolvedValue({ ...connected, active: null });
if (retryScheme === "https") {
const active = connected.active!;
vi.mocked(desktopApi.check).mockResolvedValueOnce({
...connected,
active: {
...active,
scope: null,
report: {
...active.report,
compatibilityVerified: false,
liveness: {
value: null,
error: { code: "tls", requestId: null, dispatched: false },
},
},
},
});
}
vi.mocked(desktopApi.check).mockResolvedValueOnce(connected);
vi.mocked(desktopApi.defaultScope).mockResolvedValueOnce(
connected.active!.scope!,
);
vi.mocked(desktopApi.selectScope).mockResolvedValueOnce(connected);
const user = userEvent.setup();
render(<App />);
await user.click(
await screen.findByRole("button", {
name: /Connect an existing service/,
}),
);
const dialog = within(
screen.getByRole("dialog", { name: "Connect service" }),
);
const address = dialog.getByLabelText("Server address");
expect(
dialog.queryByRole("button", { name: "Advanced settings" }),
).toBeNull();
await user.type(dialog.getByLabelText("Connection name"), "Memory service");
fireEvent.change(address, { target: { value: httpsEndpoint } });
await user.type(dialog.getByLabelText("Credential"), "fixture-token");
await user.selectOptions(
dialog.getByRole("combobox", { name: "Verified compatibility profile" }),
"qualified",
);
const advanced = dialog.getByRole("button", { name: "Advanced settings" });
expect(advanced.getAttribute("aria-expanded")).toBe("false");
expect(
dialog.queryByRole("textbox", { name: "CA certificate (PEM, optional)" }),
).toBeNull();
await user.click(advanced);
const caField = dialog.getByRole<HTMLTextAreaElement>("textbox", {
name: "CA certificate (PEM, optional)",
});
await user.type(caField, "invalid certificate");
await user.click(advanced);
const connect = dialog.getByRole("button", { name: "Confirm and connect" });
await user.click(connect);

expect(desktopApi.save).toHaveBeenNthCalledWith(
1,
expect.objectContaining({ caPem: "invalid certificate" }),
);
expect(desktopApi.check).not.toHaveBeenCalled();
expect(await dialog.findByRole("alert")).toHaveProperty(
"textContent",
"The CA certificate is invalid or contains a private key.",
);
expect(advanced.getAttribute("aria-expanded")).toBe("true");
expect(caField.getAttribute("aria-invalid")).toBe("true");
expect(caField.value).toBe("invalid certificate");

fireEvent.change(caField, { target: { value: certificate } });
if (retryScheme === "http") {
fireEvent.change(address, { target: { value: retryEndpoint } });
expect(
dialog.queryByRole("button", { name: "Advanced settings" }),
).toBeNull();
}
await user.click(connect);

expect(desktopApi.save).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
endpoint: retryEndpoint,
caPem: retryScheme === "https" ? certificate : null,
}),
);
expect(desktopApi.check).toHaveBeenCalledWith("memory-service", true);
if (retryScheme === "https") {
expect(
await dialog.findByText("Certificate or hostname verification failed."),
).toBeTruthy();
expect(desktopApi.defaultScope).not.toHaveBeenCalled();
expect(caField.value).toBe(certificate);
await user.clear(caField);
await user.click(connect);
expect(desktopApi.save).toHaveBeenNthCalledWith(
3,
expect.objectContaining({
id: "memory-service",
revision: 1,
caPem: null,
}),
);
}
expect(
await screen.findByRole("button", {
name: /Current memory space: Original space/,
}),
).toBeTruthy();
},
);

test("closing the existing-service dialog restores focus without scrolling the page", async () => {
const user = userEvent.setup();
const connected = connectedMemoryState();
Expand Down
Loading