Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283import { describe, expect, it } from "vitest";import { judgeSession } from "../../runner/sessionCheck";
const base = { profile: "test-qian", expected: "qian.pds.malldao.xyz" };
describe("judgeSession (P5-3.a)", () => { it("passes when the page shows the expected account", () => { expect(judgeSession({ ...base, pageText: "Mallbucks Signed in as @qian.pds.malldao.xyz Balance 12" })).toEqual({ ok: true }); }); it("matches the handle with or without the @, in any case, and not as part of a longer handle", () => { expect(judgeSession({ ...base, pageText: "QIAN.PDS.MALLDAO.XYZ" })).toEqual({ ok: true }); expect(judgeSession({ ...base, pageText: "signed in as notqian.pds.malldao.xyz" }).ok).toBe(false); expect(judgeSession({ ...base, pageText: "signed in as qian.pds.malldao.xyz.evil.example" }).ok).toBe(false); expect(judgeSession({ ...base, pageText: "signed in as @qian.pds.malldao.xyz!" })).toEqual({ ok: true }); }); it("fails naming both when the page shows another account", () => { const r = judgeSession({ ...base, pageText: "Signed in as @buster.pds.malldao.xyz" }); expect(r.ok).toBe(false); if (!r.ok) { expect(r.message).toContain("qian.pds.malldao.xyz"); expect(r.message).toContain("buster.pds.malldao.xyz"); expect(r.expected).toBe("qian.pds.malldao.xyz"); expect(r.found).toBe("buster.pds.malldao.xyz"); expect(r.message).toMatch(/wrong account/i); } }); it("fails with the renewal instructions when the page is signed out, and says which profile to renew", () => { for (const pageText of ["Welcome. Sign in to continue", "Log in with Bluesky", "Please sign-in", "Connect your account"]) { const r = judgeSession({ ...base, pageText }); expect(r.ok, pageText).toBe(false); if (!r.ok) { expect(r.message).toMatch(/signed out|session has expired/i); expect(r.message).toContain("aite profile open test-qian"); expect(r.message).toContain("qian.pds.malldao.xyz"); expect(r.message).toContain("docs/runbook-sessions.md"); expect(r.found).toBe("signed out"); } } }); it("a signed-out page that also mentions the expected handle in its text (a sign-in form that remembers it) is still signed out", () => { const r = judgeSession({ ...base, pageText: "Sign in as qian.pds.malldao.xyz? Sign in" }); expect(r.ok).toBe(false); }); it("a page with no account and no sign-in prompt says it cannot find who is signed in", () => { const r = judgeSession({ ...base, pageText: "Loading..." }); expect(r.ok).toBe(false); if (!r.ok) expect(r.message).toMatch(/cannot find which account/i); }); it("an empty page is not a session", () => { expect(judgeSession({ ...base, pageText: "" }).ok).toBe(false); }); it("with no expected account it refuses instead of passing anything", () => { const r = judgeSession({ profile: "test-qian", expected: "", pageText: "Signed in as someone.example" }); expect(r.ok).toBe(false); if (!r.ok) expect(r.message).toMatch(/no account to expect/i); }); it("a long page is read to the end for the handle, and a hostile page cannot make the message unbounded", () => { const long = `${"word ".repeat(20000)} signed in as qian.pds.malldao.xyz`; expect(judgeSession({ ...base, pageText: long })).toEqual({ ok: true }); const r = judgeSession({ ...base, pageText: `Sign in ${"x".repeat(100000)}` }); expect(r.ok === false && r.message.length < 2000).toBe(true); const odd = judgeSession({ ...base, pageText: `signed in as ${"a".repeat(5000)}.example.com` }); expect(odd.ok === false && odd.message.length < 2000).toBe(true); });});
describe("judgeSession kinds (#70): what is a disagreement and what is not knowing", () => { const kind = (pageText: string, expected = base.expected) => { const r = judgeSession({ ...base, expected, pageText }); return r.ok ? "ok" : r.kind; }; it("is signed-out for a sign-in page and for an empty page, wrong-account for another marked account, and unknown for a page that does not say", () => { expect(kind("Welcome. Sign in to continue")).toBe("signed-out"); expect(kind("")).toBe("signed-out"); expect(kind("Signed in as @buster.pds.malldao.xyz")).toBe("wrong-account"); expect(kind("Loading...")).toBe("unknown"); expect(kind("Signed in as @qian.pds.malldao.xyz")).toBe("ok"); }); it("having no account to compare with is unknown, not a disagreement", () => { expect(kind("Signed in as someone.example", "")).toBe("unknown"); });});