File size: 2,916 Bytes
3201ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { describe, it, expect } from "vitest";
import {
  resolveAcpAuthDisplay,
  type AcpAuthDisplay,
} from "#/utils/acp-auth-display";

// Pure decision matrix for the ACP auth banner. The host-login probe
// (`status`) is only trustworthy on a native backend; inside a container it
// can't run and returns "unknown". `credentialsConfigured` is the separate,
// backend-truthful signal (a secret exists in the active backend's store) that
// works on Docker/cloud too. See issue #1244.
describe("resolveAcpAuthDisplay", () => {
  it("reports a probe-confirmed login ('signed-in') whenever the probe authenticated, regardless of other signals", () => {
    expect(
      resolveAcpAuthDisplay({
        status: "authenticated",
        isChecking: false,
        credentialsConfigured: false,
      }),
    ).toBe("signed-in");
    expect(
      resolveAcpAuthDisplay({
        status: "authenticated",
        isChecking: true,
        credentialsConfigured: true,
      }),
    ).toBe("signed-in");
  });

  it("reports 'checking' while the first probe is in flight and no login is confirmed yet", () => {
    expect(
      resolveAcpAuthDisplay({
        status: "unknown",
        isChecking: true,
        credentialsConfigured: false,
      }),
    ).toBe("checking");
    expect(
      resolveAcpAuthDisplay({
        status: "unauthenticated",
        isChecking: true,
        credentialsConfigured: true,
      }),
    ).toBe("checking");
  });

  it("reports 'configured' when the probe can't confirm a login but a credential exists in the secret store (the Docker/cloud case)", () => {
    // "unknown" == couldn't tell (e.g. a container with no interactive CLI);
    // a stored secret is still a real signal the agent will authenticate.
    expect(
      resolveAcpAuthDisplay({
        status: "unknown",
        isChecking: false,
        credentialsConfigured: true,
      }),
    ).toBe("configured");
    expect(
      resolveAcpAuthDisplay({
        status: "unauthenticated",
        isChecking: false,
        credentialsConfigured: true,
      }),
    ).toBe("configured");
  });

  it("reports 'none' when there is no confirmed login and no stored credential", () => {
    expect(
      resolveAcpAuthDisplay({
        status: "unknown",
        isChecking: false,
        credentialsConfigured: false,
      }),
    ).toBe("none");
    expect(
      resolveAcpAuthDisplay({
        status: "unauthenticated",
        isChecking: false,
        credentialsConfigured: false,
      }),
    ).toBe("none");
  });

  it("never reports 'signed-in' from a stored credential alone — only the probe confirms a host login (honesty guard)", () => {
    const display: AcpAuthDisplay = resolveAcpAuthDisplay({
      status: "unknown",
      isChecking: false,
      credentialsConfigured: true,
    });
    expect(display).not.toBe("signed-in");
    expect(display).toBe("configured");
  });
});