Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { parseTanStackSourceAuthStatus } from "./tanStackSourceAuthStatus.ts";
4import { effectiveAccount } from "./TanStackSourceSourceControlProvider.ts";
5
6// Captured from src 0.6.2.
7const SIGNED_IN = `source.tanstack.com
8 ✓ Logged in to source.tanstack.com account alice (/home/alice/.config/src/hosts.json)
9 - Active account: true
10 - Git operations protocol: https
11 - Token: tsp_****************************************
12 ✓ Logged in to source.tanstack.com account bob (/home/alice/.config/src/hosts.json)
13 - Active account: false
14 - Git operations protocol: https
15 - Token: tsp_****************************************
16`;
17
18const REFUSED_ENV_TOKEN = `source.tanstack.com
19 X Failed to log in to source.tanstack.com using token (SRC_TOKEN)
20 - Active account: true
21 - The token in SRC_TOKEN is invalid.
22
23 ✓ Logged in to source.tanstack.com account alice (/home/alice/.config/src/hosts.json)
24 - Active account: false
25 - Git operations protocol: https
26 - Token: tsp_****************************************
27`;
28
29describe("parseTanStackSourceAuthStatus", () => {
30 it("reads every login with its active flag, and never a token line", () => {
31 const accounts = parseTanStackSourceAuthStatus(SIGNED_IN);
32 expect(accounts).toEqual([
33 {
34 host: "source.tanstack.com",
35 account: "alice",
36 authenticated: true,
37 active: true,
38 error: null,
39 environmentVariable: null,
40 },
41 {
42 host: "source.tanstack.com",
43 account: "bob",
44 authenticated: true,
45 active: false,
46 error: null,
47 environmentVariable: null,
48 },
49 ]);
50 expect(effectiveAccount(accounts, undefined)?.account).toBe("alice");
51 expect(effectiveAccount(accounts, "bob")?.account).toBe("bob");
52 expect(effectiveAccount(accounts, "carol")?.account).toBe("alice");
53 });
54
55 it("keeps a refused SRC_TOKEN's reason and falls back to the saved login", () => {
56 const accounts = parseTanStackSourceAuthStatus(REFUSED_ENV_TOKEN);
57 expect(accounts[0]).toEqual({
58 host: "source.tanstack.com",
59 account: "",
60 authenticated: false,
61 active: true,
62 error: "The token in SRC_TOKEN is invalid.",
63 environmentVariable: "SRC_TOKEN",
64 });
65 expect(effectiveAccount(accounts, undefined)?.account).toBe("alice");
66 });
67
68 it("reads no login from a signed-out CLI", () => {
69 expect(
70 parseTanStackSourceAuthStatus(
71 "You are not logged into any TanStack Source hosts. To log in, run: src auth login\n",
72 ),
73 ).toEqual([]);
74 });
75});