Skip to content

Commit e435882

Browse files
SiddarthAAclaude
andcommitted
[config-account-login] Report the kept connection when a new login's key can't be used
Logging in again on a connected machine, with the key claimed but refused on both streams, made connectToCloud write nothing, so the previous connection stayed on disk and working. `keptOld` tested `!token`, though, so the summary and configure_applied reported the machine as open source. Test `!connected` instead. A refused saved key still counts as kept (mode cloud, decision D4), with its own message. (CodeRabbit) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 25770c9 commit e435882

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The stable release of logging in to FailproofAI Cloud from `config` in your brow
1111
### Fixes
1212

1313
- `config` on a machine with no saved connection, whose browser login was approved but whose key could not be claimed, no longer says "This machine keeps its previous connection." and reports cloud mode with no key on disk; it finishes set up as open source (#920)
14+
- `config`, logging in again on a connected machine where the new key is created but can't be used, says the machine keeps its previous connection (which it does: nothing was written) instead of finishing as if it were open source (#920)
1415
- `config` on a machine whose saved key was refused, when logging in again creates no key, says the kept connection's key no longer works and to run `config` again, instead of reporting the old connection as if it were fine (#920)
1516
- `config` no longer sends the saved key to a saved cloud address it would refuse if typed (plain `http://` to another host) when checking that key (#920)
1617
- `config`'s browser login takes an expired or refused link off the screen when it prints a new one, so only the live link can be opened; and a cloud that answers the login route with a web page is treated as one without browser login (paste a key) instead of an error (#920)

‎__tests__/hooks/configure-wizard.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,31 @@ describe("browser login", () => {
16751675
expect(printed(io.stdout)).not.toContain("no longer works");
16761676
});
16771677

1678+
it("keeps reporting the previous connection when the new key is created but can't be used", async () => {
1679+
writeIngestCredential({ url: "https://app.befailproof.ai/v1/events", key: "saved-key-3f2a" });
1680+
connectPick = "login";
1681+
vi.mocked(claimLogin).mockResolvedValueOnce({
1682+
kind: "ok",
1683+
key: "k".repeat(64),
1684+
keyName: "failproofai · box",
1685+
org: { slug: "acme", name: "Acme" },
1686+
permissions: ["events:add", "policies:pull"],
1687+
} as never);
1688+
// Refused on both streams: connectToCloud writes nothing, so the saved key stays.
1689+
vi.mocked(connectToCloud).mockResolvedValueOnce({
1690+
policy: { ok: false, reason: "refused" },
1691+
ingest: { ok: false, reason: "refused" },
1692+
anyConfigured: false,
1693+
} as never);
1694+
const io = ttyIO();
1695+
const result = await runConfigureWizard(io);
1696+
expect(result).toMatchObject({ applied: true, connected: false, mode: "cloud" });
1697+
expect(printed(io.stdout)).toContain("This machine keeps its previous connection.");
1698+
expect(printed(io.stdout)).toContain('The key "failproofai · box" was created but isn\'t in use here; revoke it');
1699+
const props = vi.mocked(trackHookEvent).mock.calls.find((call) => call[1] === "configure_applied")![2];
1700+
expect(props).toMatchObject({ connected: false, mode: "cloud" });
1701+
});
1702+
16781703
it("does not report a refused saved key as a working connection when the new login creates no key", async () => {
16791704
writeIngestCredential({ url: "https://app.befailproof.ai/v1/events", key: "saved-key-3f2a" });
16801705
vi.mocked(validateIngestKey).mockResolvedValueOnce({ ok: false, reason: "the server rejected that key (401)" });

‎src/hooks/configure-wizard.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,11 +1563,12 @@ export async function runConfigureWizard(
15631563
updateConfig({ mode: "cloud" });
15641564
}
15651565

1566-
// Logging in again on a connected machine, with no key at the end of it,
1567-
// changed nothing about the connection: the previous one is still there
1568-
// (never removed from this step, decision D4) — but not as if it worked when
1569-
// its key was refused.
1570-
const keptOld = cloud.kind === "login" && !token && Boolean(saved);
1566+
// Logging in again on a connected machine, with nothing connected at the end
1567+
// of it — no key, or a key `connectToCloud` could not use, which writes
1568+
// nothing — changed nothing about the connection: the previous one is still
1569+
// there (never removed from this step, decision D4) — but not as if it worked
1570+
// when its key was refused.
1571+
const keptOld = cloud.kind === "login" && !connected && Boolean(saved);
15711572
if (keptOld) {
15721573
done.push(
15731574
savedRefused

0 commit comments

Comments
 (0)