-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlogout.test.js
More file actions
54 lines (46 loc) · 2.48 KB
/
Copy pathlogout.test.js
File metadata and controls
54 lines (46 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { describe, it, expect, beforeEach } from "vitest";
import { mkdtempSync, existsSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { softLogout, hardLogout } from "../src/logout.js";
import { Vault } from "../src/vault.js";
import { createProfile, getProfilePaths, getProfile } from "../src/profiles.js";
describe("logout", () => {
let configDir;
beforeEach(() => {
configDir = mkdtempSync(join(tmpdir(), "px-logout-"));
process.env.PERPLEXITY_CONFIG_DIR = configDir;
process.env.PERPLEXITY_VAULT_PASSPHRASE = "t-pass";
createProfile("default");
});
it("soft: clears vault cookies + meta.lastLogin, touches .reinit, keeps dir", async () => {
const vault = new Vault();
await vault.set("default", "cookies", JSON.stringify([{ name: "x", value: "y" }]));
await vault.set("default", "email", "a@b.co");
writeFileSync(getProfilePaths("default").meta, JSON.stringify({ name: "default", displayName: "default", loginMode: "manual", tier: "Pro", lastLogin: "2026-04-19T00:00:00Z" }));
await softLogout("default");
expect(await vault.get("default", "cookies")).toBeNull();
expect(await vault.get("default", "email")).toBe("a@b.co");
expect(getProfile("default").lastLogin).toBeUndefined();
expect(existsSync(getProfilePaths("default").reinit)).toBe(true);
expect(existsSync(getProfilePaths("default").dir)).toBe(true);
});
// Issue #13 / product review: models-cache.json surviving a soft logout kept
// the dashboard claiming the old tier (and loggedIn=true via `|| !!accountInfo`),
// and a stale daemon-status.json pinned an obsolete auth badge the same way.
it("soft: removes models-cache.json and daemon-status.json", async () => {
const paths = getProfilePaths("default");
writeFileSync(paths.modelsCache, JSON.stringify({ isPro: true, authenticated: true }));
writeFileSync(paths.daemonStatus, JSON.stringify({ authenticated: true, tier: "Pro" }));
await softLogout("default");
expect(existsSync(paths.modelsCache)).toBe(false);
expect(existsSync(paths.daemonStatus)).toBe(false);
// browser-data is deliberately NOT touched (daemon single-owner, issue #8).
});
it("hard: wipes entire profile dir including vault", async () => {
const vault = new Vault();
await vault.set("default", "cookies", JSON.stringify([{ name: "x", value: "y" }]));
await hardLogout("default");
expect(existsSync(getProfilePaths("default").dir)).toBe(false);
});
});