Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
/**
* ComputersView: the empty page explains itself; connecting needs only an
* address and a way in (tested before anything is saved); hosting accounts are
* an optional shortcut; a machine opens on tabs and its console runs a command.
*/
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { ComputersView } from "@/views/ComputersView";
import { loadLocaleChunk, setUiLanguage } from "@/i18n";
import type { Computer, PairedServer } from "@/lib/computersApi";
// Assembled from parts so the literal key header never appears in source;
// the pre-push credential scanner flags that header as a private key block.
const KEY_BEGIN = ["-----BEGIN OPENSSH", "PRIVATE KEY-----"].join(" ");
const KEY_END = ["-----END OPENSSH", "PRIVATE KEY-----"].join(" ");
interface Call {
url: string;
method: string;
body: unknown;
}
function installFetch(routes: Record<string, (body: unknown) => unknown>) {
routes = { "GET /api/computers/pairing/servers": () => ({ servers: [] }), ...routes };
const calls: Call[] = [];
const fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);
const method = (init?.method ?? "GET").toUpperCase();
const body = init?.body ? JSON.parse(String(init.body)) : undefined;
calls.push({ url, method, body });
const key = Object.keys(routes)
.sort((a, b) => b.length - a.length)
.find((k) => {
const [m, path] = k.split(" ");
return m === method && url === path;
});
if (!key) throw new Error(`unexpected fetch ${method} ${url}`);
const payload = routes[key](body);
return {
ok: true,
status: 200,
statusText: "OK",
json: async () => payload,
} as Response;
});
(globalThis as unknown as { fetch: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
return calls;
}
const IDENTITY = {
public_key: "ssh-ed25519 AAAAC3Nza personal-jarvis@desk",
fingerprint: "SHA256:abc",
algorithm: "ssh-ed25519",
install_command: "umask 077 && mkdir -p ~/.ssh && echo 'ssh-ed25519 AAAAC3Nza' >> ~/.ssh/authorized_keys",
};
const VPS: Computer = {
id: "c_1",
name: "Hostinger VPS",
kind: "server",
provider: "hostinger",
host: "203.0.113.15",
port: 22,
username: "root",
auth: "key",
provider_ref: "17923",
region: "Phoenix",
plan: "KVM 4",
host_key: "ssh-ed25519 AAAA",
host_fingerprint: "SHA256:server",
created_at: 1_700_000_000,
facts: {
hostname: "srv17923",
os_id: "ubuntu",
os_name: "Ubuntu 24.04.1 LTS",
kernel: "Linux 6.8.0",
arch: "x86_64",
cpu_count: 4,
mem_total_mb: 8192,
disk_total_gb: 50,
},
health: {
status: "online",
checked_at: Date.now() / 1000,
latency_ms: 42,
message: null,
load_1m: 0.5,
mem_used_pct: 30,
disk_used_pct: 25,
uptime_s: 90_000,
},
busy: false,
};
function renderView() {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(
<QueryClientProvider client={client}>
<ComputersView />
</QueryClientProvider>,
);
}
const PROVIDERS = [
{
id: "hostinger",
name: "Hostinger",
category: "hosting",
api: { connected: false, console_url: "https://hpanel.hostinger.com/profile/api", setup_hint: "hPanel -> Profile -> API", attaches_keys: true, token_label: "API token" },
ssh: { default_username: "root", ip_hint: "hPanel -> VPS -> Overview", key_hint: "hPanel -> VPS -> SSH keys", key_url: null, password_hint: "The root password you set" },
},
{
id: "ionos",
name: "IONOS",
category: "hosting",
api: null,
ssh: { default_username: "root", ip_hint: "IONOS Cloud Panel -> Server", key_hint: "Add the key under SSH keys", key_url: "https://my.ionos.de", password_hint: "Initial password from the panel" },
},
{
id: "raspberry_pi",
name: "Raspberry Pi",
category: "home",
api: null,
ssh: { default_username: "pi", ip_hint: "Look it up in your router", key_hint: "", key_url: null, password_hint: "" },
},
];
describe("ComputersView", () => {
beforeEach(async () => {
setUiLanguage("en");
await loadLocaleChunk("computers");
});
afterEach(() => cleanup());
it("explains the empty page with one primary action", async () => {
installFetch({ "GET /api/computers": () => ({ computers: [] }) });
renderView();
expect(await screen.findByTestId("computers-welcome")).toBeTruthy();
expect(screen.getByText("No computers yet")).toBeTruthy();
expect(screen.getByTestId("computers-add-first")).toBeTruthy();
});
it("connects a server from nothing but its address", async () => {
let rows: Computer[] = [];
const calls = installFetch({
"GET /api/computers": () => ({ computers: rows }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
"POST /api/computers/test": () => ({
ok: true,
kind: null,
message: null,
host_fingerprint: "SHA256:server",
facts: VPS.facts,
latency_ms: 42,
}),
"POST /api/computers": () => {
rows = [VPS];
return VPS;
},
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
const connect = await screen.findByTestId("cx-connect");
expect((connect as HTMLButtonElement).disabled).toBe(true);
// A whole "ssh user@host:port" line is understood.
fireEvent.change(screen.getByTestId("cx-address"), { target: { value: "ssh [email protected]:2222" } });
// No login question up front: this PC's SSH keys are tried first.
expect(screen.queryByTestId("cx-password")).toBeNull();
expect(screen.getByTestId("cx-auto")).toBeTruthy();
fireEvent.click(connect);
// The check is visible: every step resolves, the machine's facts prove it.
expect(await screen.findByTestId("cx-facts")).toBeTruthy();
for (const step of ["reach", "login", "probe", "save"]) {
expect(screen.getByTestId(`cx-step-${step}`).getAttribute("data-state")).toBe("ok");
}
expect(screen.getByText("srv17923")).toBeTruthy();
fireEvent.click(screen.getByTestId("cx-open"));
expect(await screen.findByTestId("computer-detail")).toBeTruthy();
const post = calls.find((c) => c.method === "POST" && c.url === "/api/computers");
expect(post?.body).toMatchObject({
host: "203.0.113.15",
port: 2222,
username: "admin",
auth: "auto",
});
});
it("asks for the password only when no key of this PC opens the server", async () => {
let rows: Computer[] = [];
const calls = installFetch({
"GET /api/computers": () => ({ computers: rows }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
"POST /api/computers/test": (body) =>
(body as { auth: string }).auth === "auto"
? { ok: false, kind: "needs_password", message: "x", host_fingerprint: null, facts: null, latency_ms: null }
: { ok: true, kind: null, message: null, host_fingerprint: "SHA256:s", facts: VPS.facts, latency_ms: 9 },
"POST /api/computers": () => {
rows = [VPS];
return VPS;
},
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.change(await screen.findByTestId("cx-address"), { target: { value: "203.0.113.15" } });
fireEvent.click(screen.getByTestId("cx-connect"));
// Back on the form, asking for exactly the one thing missing.
expect(await screen.findByTestId("cx-ask-password")).toBeTruthy();
const password = screen.getByTestId("cx-password");
await waitFor(() => expect(document.activeElement).toBe(password));
fireEvent.change(password, { target: { value: "hunter2" } });
fireEvent.click(screen.getByTestId("cx-connect"));
fireEvent.click(await screen.findByTestId("cx-open"));
const post = calls.find((c) => c.method === "POST" && c.url === "/api/computers");
expect(post?.body).toMatchObject({ host: "203.0.113.15", auth: "password", password: "hunter2" });
});
it("gives a keys-only server the one line to run, then tries again", async () => {
let rows: Computer[] = [];
let attempts = 0;
const calls = installFetch({
"GET /api/computers": () => ({ computers: rows }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
"POST /api/computers/test": () =>
++attempts === 1
? { ok: false, kind: "key_only", message: "x", host_fingerprint: null, facts: null, latency_ms: null }
: { ok: true, kind: null, message: null, host_fingerprint: "SHA256:s", facts: VPS.facts, latency_ms: 9 },
"POST /api/computers": () => {
rows = [VPS];
return VPS;
},
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.change(await screen.findByTestId("cx-address"), { target: { value: "203.0.113.15" } });
fireEvent.click(screen.getByTestId("cx-connect"));
const panel = await screen.findByTestId("cx-key-only");
expect(panel.textContent).toContain("authorized_keys");
expect(screen.queryByTestId("cx-password")).toBeNull();
const retry = screen.getByTestId("cx-connect");
expect(retry.textContent).toMatch(/Try again/);
fireEvent.click(retry);
fireEvent.click(await screen.findByTestId("cx-open"));
const post = calls.find((c) => c.method === "POST" && c.url === "/api/computers");
expect(post?.body).toMatchObject({ host: "203.0.113.15", auth: "auto" });
});
it("takes a pasted agent answer with a key and needs no password", async () => {
let rows: Computer[] = [];
const calls = installFetch({
"GET /api/computers": () => ({ computers: rows }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
"POST /api/computers/test": () => ({
ok: true, kind: null, message: null, host_fingerprint: "SHA256:x", facts: VPS.facts, latency_ms: 9,
}),
"POST /api/computers": () => {
rows = [VPS];
return VPS;
},
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
const answer = [
KEY_BEGIN,
"b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQ",
KEY_END,
"ssh -i ~/.ssh/id_ed25519 [email protected]",
].join("\n");
fireEvent.change(await screen.findByTestId("cx-address"), { target: { value: answer } });
expect(screen.queryByTestId("cx-password")).toBeNull();
expect(screen.getByTestId("cx-detected").textContent).toContain("[email protected]");
// A pasted key switches the login to "SSH key" by itself.
expect(screen.getByTestId("cx-method-key").getAttribute("aria-selected")).toBe("true");
fireEvent.click(screen.getByTestId("cx-connect"));
fireEvent.click(await screen.findByTestId("cx-open"));
expect(await screen.findByTestId("computer-detail")).toBeTruthy();
const post = calls.find((c) => c.method === "POST" && c.url === "/api/computers");
expect(post?.body).toMatchObject({ host: "192.0.2.10", username: "dev", auth: "private_key" });
expect((post?.body as { private_key: string }).private_key).toContain("BEGIN OPENSSH PRIVATE KEY");
});
it("offers hosting accounts as an optional shortcut", async () => {
installFetch({
"GET /api/computers": () => ({ computers: [] }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.click(await screen.findByTestId("cx-additional-options"));
fireEvent.click(await screen.findByTestId("cx-account-hostinger"));
expect(await screen.findByTestId("wz-token")).toBeTruthy();
});
it("says how to fix a failed connection and saves nothing", async () => {
const calls = installFetch({
"GET /api/computers": () => ({ computers: [] }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
"POST /api/computers/test": () => ({
ok: false,
kind: "auth",
message: null,
host_fingerprint: null,
facts: null,
latency_ms: null,
}),
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.change(await screen.findByTestId("cx-address"), { target: { value: "192.168.1.20" } });
fireEvent.click(screen.getByTestId("cx-other-ways"));
fireEvent.change(screen.getByTestId("cx-password"), { target: { value: "wrong" } });
fireEvent.click(screen.getByTestId("cx-connect"));
expect(await screen.findByText(/refused the login/)).toBeTruthy();
// The server was reached; the login step is the one that failed.
expect(screen.getByTestId("cx-step-reach").getAttribute("data-state")).toBe("ok");
expect(screen.getByTestId("cx-step-login").getAttribute("data-state")).toBe("fail");
expect(calls.some((c) => c.method === "POST" && c.url === "/api/computers")).toBe(false);
// "Change details" returns to the form with everything kept.
fireEvent.click(screen.getByTestId("cx-edit"));
expect((screen.getByTestId("cx-password") as HTMLInputElement).value).toBe("wrong");
});
it("keeps every other way in one click away", async () => {
installFetch({
"GET /api/computers": () => ({ computers: [] }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.change(await screen.findByTestId("cx-address"), { target: { value: "192.168.1.20" } });
fireEvent.click(screen.getByTestId("cx-other-ways"));
fireEvent.click(screen.getByTestId("cx-method-key"));
expect(screen.getByTestId("cx-private-key")).toBeTruthy();
fireEvent.click(screen.getByTestId("cx-key-assistant"));
expect((await screen.findByTestId("cx-assistant-key")).textContent).toContain(IDENTITY.public_key);
// The assistant's key needs nothing typed: Connect is ready.
expect((screen.getByTestId("cx-connect") as HTMLButtonElement).disabled).toBe(false);
fireEvent.click(screen.getByTestId("cx-method-agent"));
expect(screen.getByTestId("cx-copy-prompt")).toBeTruthy();
fireEvent.change(screen.getByTestId("cx-address"), {
target: { value: "Done.\nDODAIOS-CONNECT [email protected]:22" },
});
expect(screen.getByTestId("cx-agent").textContent).toMatch(/key is on that computer/);
// And back to the automatic way.
fireEvent.click(screen.getByTestId("cx-auto-back"));
expect(screen.getByTestId("cx-auto")).toBeTruthy();
});
it("switches connection forms without losing drafts or sending pairing data to SSH", async () => {
const calls = installFetch({
"GET /api/computers": () => ({ computers: [] }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.change(await screen.findByTestId("cx-address"), { target: { value: "192.0.2.10" } });
fireEvent.click(screen.getByRole("radio", { name: "Server address" }));
expect(screen.queryByRole("textbox", { name: "SSH host" })).toBeNull();
expect(screen.queryByTestId("cx-additional-options")).toBeNull();
fireEvent.paste(screen.getByRole("textbox", { name: "Host" }), {
clipboardData: { getData: () => "https://backend.example.com/pair?code=ExampleCode" },
});
expect((screen.getByTestId("cx-server-host") as HTMLInputElement).value).toBe("https://backend.example.com");
expect((screen.getByTestId("cx-pairing-code") as HTMLInputElement).value).toBe("ExampleCode");
expect((within(screen.getByTestId("cx-server-form")).getByRole("button", { name: "Add computer" }) as HTMLButtonElement).disabled).toBe(false);
expect(calls.some((call) => call.method === "POST")).toBe(false);
fireEvent.click(screen.getByRole("radio", { name: "SSH" }));
expect((screen.getByRole("textbox", { name: "SSH host" }) as HTMLInputElement).value).toBe("192.0.2.10");
expect(screen.queryByRole("textbox", { name: "Pairing code" })).toBeNull();
fireEvent.click(screen.getByRole("radio", { name: "Server address" }));
expect((screen.getByRole("textbox", { name: "Pairing code" }) as HTMLInputElement).value).toBe("ExampleCode");
});
it("pairs a server, opens its real launch URL, checks it and revokes the connection", async () => {
let servers: PairedServer[] = [];
const server: PairedServer = { id: "s_test", url: "https://backend.example.com", name: "Remote Jarvis", platform: "Linux", created_at: 1, checked_at: 1, online: true };
const calls = installFetch({
"GET /api/computers": () => ({ computers: [] }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
"GET /api/computers/pairing/servers": () => ({ servers }),
"POST /api/computers/pairing/servers": () => { servers = [server]; return server; },
"POST /api/computers/pairing/servers/s_test/open": () => ({ url: "https://backend.example.com/api/computers/pairing/enter#example-ticket" }),
"POST /api/settings/open-external": () => ({ opened: true }),
"POST /api/computers/pairing/servers/s_test/check": () => { servers = [{ ...server, online: false }]; return servers[0]; },
"DELETE /api/computers/pairing/servers/s_test": () => { servers = []; return { removed: true }; },
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.click(await screen.findByRole("radio", { name: "Server address" }));
fireEvent.paste(screen.getByTestId("cx-server-host"), { clipboardData: { getData: () => "https://backend.example.com/#pairing_code=ExampleCode" } });
fireEvent.submit(screen.getByTestId("cx-server-form"));
fireEvent.submit(screen.getByTestId("cx-server-form"));
expect(await screen.findByTestId("paired-servers")).toBeTruthy();
expect(screen.queryByTestId("computers-connect-dialog")).toBeNull();
expect(calls.filter((call) => call.method === "POST" && call.url === "/api/computers/pairing/servers")).toHaveLength(1);
expect(calls.find((call) => call.method === "POST" && call.url === "/api/computers/pairing/servers")?.body).toEqual({ host: "https://backend.example.com", code: "ExampleCode" });
expect(calls.some((call) => call.url === "/api/computers/test")).toBe(false);
fireEvent.click(screen.getByRole("button", { name: "Open server" }));
await waitFor(() => expect(calls.some((call) => call.url === "/api/settings/open-external")).toBe(true));
await waitFor(() => expect((screen.getByRole("button", { name: "Check again" }) as HTMLButtonElement).disabled).toBe(false));
fireEvent.click(screen.getByRole("button", { name: "Check again" }));
expect(await screen.findByText(/Connection unavailable/)).toBeTruthy();
fireEvent.click(screen.getByRole("button", { name: "Disconnect and revoke access" }));
await waitFor(() => expect(screen.queryByTestId("paired-servers")).toBeNull());
});
it("keeps pairing details after a failed connection and can retry", async () => {
const calls = installFetch({
"GET /api/computers": () => ({ computers: [] }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
"POST /api/computers/pairing/servers": () => { throw new Error("Pairing rejected"); },
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.click(await screen.findByRole("radio", { name: "Server address" }));
fireEvent.change(screen.getByTestId("cx-server-host"), { target: { value: "backend.example.com" } });
fireEvent.change(screen.getByTestId("cx-pairing-code"), { target: { value: "ExampleCode" } });
fireEvent.submit(screen.getByTestId("cx-server-form"));
expect(await screen.findByText("Pairing rejected")).toBeTruthy();
expect((screen.getByTestId("cx-pairing-code") as HTMLInputElement).value).toBe("ExampleCode");
fireEvent.submit(screen.getByTestId("cx-server-form"));
await waitFor(() => expect(calls.filter((call) => call.method === "POST")).toHaveLength(2));
});
it("creates a pairing code only on request and can revoke a paired client", async () => {
let clients = [{ id: "g_test", name: "Laptop", created_at: 1 }];
const calls = installFetch({
"GET /api/computers": () => ({ computers: [] }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
"GET /api/computers/pairing/clients": () => ({ clients }),
"POST /api/computers/pairing/code": () => ({ code: "ExampleCode", expires_at: Date.now() / 1000 + 300 }),
"DELETE /api/computers/pairing/clients/g_test": () => { clients = []; return { removed: true }; },
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.click(await screen.findByRole("radio", { name: "Server address" }));
expect(calls.some((call) => call.method === "POST")).toBe(false);
fireEvent.click(screen.getByRole("button", { name: "Allow another computer to connect to this Dodaios" }));
expect(await screen.findByText("Laptop")).toBeTruthy();
fireEvent.click(screen.getByRole("button", { name: "Generate pairing code" }));
expect(await screen.findByText("ExampleCode")).toBeTruthy();
fireEvent.click(screen.getByRole("button", { name: "Revoke access" }));
await waitFor(() => expect(screen.queryByText("Laptop")).toBeNull());
});
it("validates the visible SSH port and sends explicit login overrides", async () => {
const calls = installFetch({
"GET /api/computers": () => ({ computers: [] }),
"GET /api/computers/providers": () => ({ providers: PROVIDERS }),
"GET /api/computers/identity": () => IDENTITY,
"POST /api/computers/test": () => ({
ok: false, kind: "unreachable", message: null, facts: null,
host_fingerprint: null, latency_ms: null,
}),
});
renderView();
fireEvent.click(await screen.findByTestId("computers-add-first"));
fireEvent.change(await screen.findByLabelText("SSH host"), { target: { value: "ssh [email protected]:2222" } });
fireEvent.change(screen.getByTestId("cx-username"), { target: { value: "deploy" } });
const port = screen.getByTestId("cx-port");
for (const value of ["0", "65536", "1.5", "-1"]) {
fireEvent.change(port, { target: { value } });
expect((screen.getByTestId("cx-connect") as HTMLButtonElement).disabled).toBe(true);
expect(screen.getByRole("alert").textContent).toContain("between 1 and 65535");
}
expect(calls.some((call) => call.method === "POST")).toBe(false);
fireEvent.change(port, { target: { value: "2200" } });
fireEvent.click(screen.getByTestId("cx-connect"));
await screen.findByTestId("cx-edit");
expect(calls.find((call) => call.url === "/api/computers/test")?.body).toMatchObject({
host: "192.0.2.10", username: "deploy", port: 2200, auth: "auto",
});
});
it("lists a machine, opens it and runs a console command", async () => {
const calls = installFetch({
"GET /api/computers": () => ({ computers: [VPS] }),
"GET /api/computers/identity": () => IDENTITY,
"GET /api/agentic-ide/offload-on-quit": () => ({ computer_id: null }),
"POST /api/computers/c_1/run": () => ({
exit_status: 0,
stdout: " 12:00 up 1 day\n",
stderr: "",
duration_ms: 80,
truncated: false,
}),
});
renderView();
fireEvent.click(await screen.findByTestId("computer-row-c_1"));
expect(await screen.findByTestId("computer-detail")).toBeTruthy();
expect(screen.getByText("Ubuntu 24.04.1 LTS")).toBeTruthy();
fireEvent.click(screen.getByRole("tab", { name: "Console" }));
fireEvent.click(screen.getByRole("button", { name: "uptime" }));
await waitFor(() =>
expect(screen.getByTestId("computer-console-output").textContent).toContain("12:00 up 1 day"),
);
expect(
calls.some(
(c) => c.url === "/api/computers/c_1/run" && (c.body as { command: string }).command === "uptime",
),
).toBe(true);
});
});