import { test } from "node:test"; import assert from "node:assert/strict"; import { mkdtempSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { readIdentity } from "../dist/identity.js"; test("the account is read from the agent's state file", () => { const p = join(mkdtempSync(join(tmpdir(), "cc-id-")), ".claude.json"); writeFileSync(p, JSON.stringify({ oauthAccount: { accountUuid: "u-1", emailAddress: "a@example.org" }, other: 2 })); assert.deepEqual(readIdentity(p), { accountUuid: "u-1", emailAddress: "a@example.org", organizationUuid: undefined }); }); test("no state file, or no account in it, is no identity rather than a guess", () => { assert.equal(readIdentity("/nonexistent/.claude.json"), null); const p = join(mkdtempSync(join(tmpdir(), "cc-id-")), ".claude.json"); writeFileSync(p, "{}"); assert.equal(readIdentity(p), null); });