From de69088ff1149deea1f1d90811ad404d14c07343 Mon Sep 17 00:00:00 2001 From: zoya-brd Date: Mon, 14 Sep 2026 15:49:15 +0400 Subject: [PATCH] feat(login): create agent account on --github login when none exists --- src/__tests__/utils/browser_auth.test.ts | 23 ++++++++++++++++++----- src/utils/browser_auth.ts | 7 ------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/__tests__/utils/browser_auth.test.ts b/src/__tests__/utils/browser_auth.test.ts index 8f5ccce..d29a6a2 100644 --- a/src/__tests__/utils/browser_auth.test.ts +++ b/src/__tests__/utils/browser_auth.test.ts @@ -153,14 +153,27 @@ describe('github_flow', ()=>{ await expect(github_flow({})).rejects.toThrow('--customer-id'); }); - it('throws with "No Bright Data account" on 404 user_not_found from init', async()=>{ - vi.spyOn(globalThis, 'fetch') - .mockResolvedValueOnce(gh_json(true, 200, GH_USER)) - .mockResolvedValueOnce(bd_resp(404, {error: 'user_not_found'})); + it('does not dead-end on a missing account; backend find-or-create mints a key', async()=>{ + // A brand-new GitHub identity (no prior BD account) reaches verify and is + // created server-side, returning a freshly minted key — no CLI "no account" failure. + const spy = vi.spyOn(globalThis, 'fetch'); + setup_full_flow(spy); - await expect(github_flow({})).rejects.toThrow('No Bright Data account'); + const result = await github_flow({}); + expect(result).toBe('test-api-key'); }); + it('surfaces a generic non-zero failure (no "No Bright Data account" dead-end) on init error', + async()=>{ + vi.spyOn(globalThis, 'fetch') + .mockResolvedValueOnce(gh_json(true, 200, GH_USER)) + .mockResolvedValueOnce(bd_resp(404, {error: 'user_not_found'})); + + const err = await github_flow({}).catch((e: Error)=>e); + expect(err).toBeInstanceOf(Error); + expect((err as Error).message).not.toContain('No Bright Data account'); + }); + it('passes customer_id to the init request body when provided', async()=>{ const spy = vi.spyOn(globalThis, 'fetch'); setup_full_flow(spy); diff --git a/src/utils/browser_auth.ts b/src/utils/browser_auth.ts index 9a7b81b..6a44c8a 100644 --- a/src/utils/browser_auth.ts +++ b/src/utils/browser_auth.ts @@ -135,13 +135,6 @@ const bd_error = ( const detail = desc ? desc : 'Multiple accounts found'; return new Error(`${detail} \u2014 use --customer-id to specify your account`); } - if (status == 404 && error == 'user_not_found') - { - return new Error( - 'No Bright Data account found for your GitHub email' - + (desc ? `: ${desc}` : '') - ); - } if (status == 429) return new Error('Rate limit exceeded, please try again in a moment'); if (status == 502)