Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/claude-login.test.mjs
iris f6a0bb4bb3 swarm-ui: the three toasts that didn't match read like the rest
Two toasts started with a capital and ended with a full stop (the stored login
dialog's and the login delete's), and the API key removal had no tone. They are
short lowercase phrases with the ok tone now, and the design guide says so.
2026-11-28 09:48:07 +01:00

84 lines
3 KiB
JavaScript

// The claude login dialog's step logic. Run by `npm test`, which Node runs
// with its built-in test runner and type stripping, so the `.ts` module is
// imported as it is.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
afterCode,
afterStart,
beginStart,
claudeLoginPath,
isLatestStart,
leavesLoginRunning,
pastedCode,
startOutlivedDialog,
storedMessage,
} from "../src/agent/claude-login/ClaudeLoginSteps.ts";
test("the routes name the agent, escaped", () => {
assert.equal(claudeLoginPath("atlas"), "/api/agents/atlas/claude-login");
assert.equal(
claudeLoginPath("atlas", true),
"/api/agents/atlas/claude-login/code",
);
assert.equal(claudeLoginPath("a/b"), "/api/agents/a%2Fb/claude-login");
});
test("a started login asks for the code at its URL", () => {
assert.deepEqual(afterStart({ url: "https://claude.ai/oauth/x" }), {
step: "code",
url: "https://claude.ai/oauth/x",
});
});
test("a start that failed shows why and has no URL", () => {
const problem = { detail: "no claude login minter is listening" };
assert.deepEqual(afterStart({ problem }), { step: "failed", problem });
});
test("an accepted code is stored; a refused one is a failure", () => {
assert.deepEqual(afterCode(null), { step: "stored" });
const problem = { detail: "OAuth error: invalid code" };
assert.deepEqual(afterCode(problem), { step: "failed", problem });
});
test("only a login waiting for its code is stopped on close", () => {
assert.equal(leavesLoginRunning({ step: "code", url: "https://u" }), true);
assert.equal(leavesLoginRunning({ step: "starting" }), false);
assert.equal(
leavesLoginRunning({ step: "submitting", url: "https://u" }),
false,
);
assert.equal(leavesLoginRunning({ step: "stored" }), false);
});
test("a start that answers after the dialog closed is stopped, unless it failed or was replaced", () => {
assert.equal(startOutlivedDialog(false, null, true), true);
assert.equal(startOutlivedDialog(true, null, true), false);
assert.equal(
startOutlivedDialog(false, { detail: "no minter" }, true),
false,
);
assert.equal(startOutlivedDialog(false, null, false), false);
});
test("only an agent's newest start counts as the latest", () => {
const first = beginStart("login-test-a");
assert.equal(isLatestStart("login-test-a", first), true);
const second = beginStart("login-test-a");
assert.equal(isLatestStart("login-test-a", first), false);
assert.equal(isLatestStart("login-test-a", second), true);
// Another agent's starts are counted on their own.
const other = beginStart("login-test-b");
assert.equal(isLatestStart("login-test-a", second), true);
assert.equal(isLatestStart("login-test-b", other), true);
});
test("a pasted code is trimmed, and a blank one is nothing", () => {
assert.equal(pastedCode(" abc-def \n"), "abc-def");
assert.equal(pastedCode(" \n "), null);
});
test("the stored toast names the agent", () => {
assert.match(storedMessage("atlas"), /^login stored: atlas /);
});