Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/cli/src/ui/utils/clipboardUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ describe('clipboardUtils', () => {
});

it('should return null if tool is not yet detected', async () => {
// Unset session type to ensure no tool is detected automatically
delete process.env['XDG_SESSION_TYPE'];

// Don't prime the tool
const result = await clipboardUtils.saveClipboardImage(mockTargetDir);
expect(result).toBe(null);
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/code_assist/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,32 @@ describe('setupUser for new user', () => {
userTierName: 'paid',
});
});

it('should throw ineligible tier error when onboarding fails and ineligible tiers exist', async () => {
vi.stubEnv('GOOGLE_CLOUD_PROJECT', '');
mockLoad.mockResolvedValue({
allowedTiers: [mockPaidTier],
ineligibleTiers: [
{
reasonCode: 'UNSUPPORTED_LOCATION',
reasonMessage:
'Your current account is not eligible for Gemini Code Assist for individuals because it is not currently available in your location.',
tierId: 'free-tier',
tierName: 'Gemini Code Assist for individuals',
},
],
});
mockOnboardUser.mockResolvedValue({
done: true,
response: {
cloudaicompanionProject: {},
},
});

await expect(setupUser({} as OAuth2Client)).rejects.toThrow(
'Your current account is not eligible for Gemini Code Assist for individuals because it is not currently available in your location.',
);
});
});

describe('setupUser validation', () => {
Expand Down
29 changes: 21 additions & 8 deletions packages/core/src/code_assist/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import type {
ClientMetadata,
GeminiUserTier,
IneligibleTier,
LoadCodeAssistResponse,
OnboardUserRequest,
} from './types.js';
Expand Down Expand Up @@ -35,6 +36,16 @@ export class ValidationCancelledError extends Error {
}
}

export class IneligibleTierError extends Error {
readonly ineligibleTiers: IneligibleTier[];

constructor(ineligibleTiers: IneligibleTier[]) {
const reasons = ineligibleTiers.map((t) => t.reasonMessage).join(', ');
super(reasons);
this.ineligibleTiers = ineligibleTiers;
}
}

export interface UserData {
projectId: string;
userTier: UserTierId;
Expand Down Expand Up @@ -127,13 +138,7 @@ export async function setupUser(
}

// If user is not setup for standard tier, inform them about all other tiers they are ineligible for.
if (loadRes.ineligibleTiers && loadRes.ineligibleTiers.length > 0) {
const reasons = loadRes.ineligibleTiers
.map((t) => t.reasonMessage)
.join(', ');
throw new Error(reasons);
}
throw new ProjectIdRequiredError();
throwIneligibleOrProjectIdError(loadRes);
}
return {
projectId: loadRes.cloudaicompanionProject,
Expand Down Expand Up @@ -180,7 +185,8 @@ export async function setupUser(
userTierName: tier.name,
};
}
throw new ProjectIdRequiredError();

throwIneligibleOrProjectIdError(loadRes);
}

return {
Expand All @@ -190,6 +196,13 @@ export async function setupUser(
};
}

function throwIneligibleOrProjectIdError(res: LoadCodeAssistResponse): never {
if (res.ineligibleTiers && res.ineligibleTiers.length > 0) {
throw new IneligibleTierError(res.ineligibleTiers);
}
throw new ProjectIdRequiredError();
}

function getOnboardTier(res: LoadCodeAssistResponse): GeminiUserTier {
for (const tier of res.allowedTiers || []) {
if (tier.isDefault) {
Expand Down
Loading