Open History to see the last commit
1import { assert, describe, it } from "@effect/vitest";
2import * as Schema from "effect/Schema";
3
4import { KiroSettings } from "../settings.ts";
5import { buildKiroAcpSpawnInput } from "./acpSupport.ts";
6import { kiroAuthFromWhoami } from "./status.ts";
7
8const decodeSettings = Schema.decodeUnknownSync(KiroSettings);
9
10describe("KiroDriver", () => {
11 it("launches the V3 ACP engine with CLI-owned auth from the configured binary", () => {
12 assert.deepEqual(buildKiroAcpSpawnInput(decodeSettings({}), "/work"), {
13 command: "kiro-cli",
14 args: ["acp", "--agent-engine=v3", "--auth-method=cli"],
15 cwd: "/work",
16 });
17 const custom = buildKiroAcpSpawnInput(
18 decodeSettings({ binaryPath: "/opt/kiro/bin/kiro-cli" }),
19 "/work",
20 { KIRO_API_KEY: "ksk_test" },
21 );
22 assert.equal(custom.command, "/opt/kiro/bin/kiro-cli");
23 assert.deepEqual(custom.args, ["acp", "--agent-engine=v3", "--auth-method=cli"]);
24 assert.deepEqual(custom.env, { KIRO_API_KEY: "ksk_test" });
25 });
26
27 // Outputs recorded from `kiro-cli whoami --format json` on Kiro CLI 2.27.0.
28 it("reads the sign-in state from kiro-cli whoami", () => {
29 assert.deepEqual(kiroAuthFromWhoami({ code: 1, stdout: '{"account":null}\n' }, {}), {
30 status: "unauthenticated",
31 });
32 assert.deepEqual(
33 kiroAuthFromWhoami({ code: 0, stdout: '{"accountType":"ApiKey","email":null}\n' }, {}),
34 { status: "authenticated", type: "api_key", label: "Kiro API key" },
35 );
36 assert.deepEqual(
37 kiroAuthFromWhoami(
38 { code: 0, stdout: '{"accountType":"BuilderId","email":"dev@example.com"}\n' },
39 {},
40 ),
41 { status: "authenticated", label: "Kiro account", email: "dev@example.com" },
42 );
43 assert.deepEqual(kiroAuthFromWhoami({ code: 2, stdout: "error: service error" }, {}), {
44 status: "unknown",
45 });
46 assert.deepEqual(kiroAuthFromWhoami(undefined, {}), { status: "unknown" });
47 });
48
49 // Reported from Kiro CLI 2.27.1 with an IAM Identity Center login (exit 0;
50 // values are placeholders, layout unchanged).
51 it("keeps the account email when whoami appends an Identity Center profile", () => {
52 const stdout = [
53 '{"accountType":"IamIdentityCenter","email":"jane.doe@example.com","region":"us-east-1","startUrl":"https://d-0123456789.awsapps.com/start"}',
54 "",
55 "Profile:",
56 "KiroProfile-us-east-1",
57 "arn:aws:codewhisperer:us-east-1:111122223333:profile/EXAMPLE12345",
58 "",
59 ].join("\n");
60 assert.deepEqual(kiroAuthFromWhoami({ code: 0, stdout }, {}), {
61 status: "authenticated",
62 label: "Kiro account",
63 email: "jane.doe@example.com",
64 });
65 });
66});