-
Notifications
You must be signed in to change notification settings - Fork 727
feat: add pypi ecosystem to blast (CM-1358) #4449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
services/apps/packages_worker/src/blast-radius/agent/__tests__/agentAuth.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import { afterEach, describe, expect, it } from 'vitest' | ||
|
|
||
| import { resolveAgentAuth } from '@crowd/common' | ||
|
ulemons marked this conversation as resolved.
|
||
|
|
||
| const AKRITES_BEDROCK_ENV_VAR_NAMES = { | ||
| accessKeyId: 'AKRITES_AWS_BEDROCK_ACCESS_KEY_ID', | ||
| secretAccessKey: 'AKRITES_AWS_BEDROCK_SECRET_ACCESS_KEY', | ||
| region: 'AKRITES_AWS_BEDROCK_REGION', | ||
| } | ||
|
|
||
| const ALL_ENV_VARS = [ | ||
| 'CROWD_AWS_BEDROCK_ACCESS_KEY_ID', | ||
| 'CROWD_AWS_BEDROCK_SECRET_ACCESS_KEY', | ||
| 'CROWD_AWS_BEDROCK_REGION', | ||
| 'AKRITES_AWS_BEDROCK_ACCESS_KEY_ID', | ||
| 'AKRITES_AWS_BEDROCK_SECRET_ACCESS_KEY', | ||
| 'AKRITES_AWS_BEDROCK_REGION', | ||
| 'BLAST_RADIUS_ANTHROPIC_API_KEY', | ||
| 'BLAST_RADIUS_ANTHROPIC_BASE_URL', | ||
| 'ANTHROPIC_API_KEY', | ||
| ] | ||
|
|
||
| function clearAuthEnv() { | ||
| for (const key of ALL_ENV_VARS) { | ||
| delete process.env[key] | ||
| } | ||
| } | ||
|
|
||
| describe('resolveAgentAuth', () => { | ||
| afterEach(() => { | ||
| clearAuthEnv() | ||
| }) | ||
|
|
||
| it('resolves bedrock mode using the default (CROWD_AWS_BEDROCK_*) env vars', () => { | ||
| clearAuthEnv() | ||
| process.env.CROWD_AWS_BEDROCK_ACCESS_KEY_ID = 'AKIA_TEST' | ||
| process.env.CROWD_AWS_BEDROCK_SECRET_ACCESS_KEY = 'secret' | ||
| process.env.ANTHROPIC_API_KEY = 'sk-ant-should-not-survive' | ||
|
|
||
| const auth = resolveAgentAuth() | ||
|
|
||
| expect(auth.mode).toBe('bedrock') | ||
| expect(auth.env.CLAUDE_CODE_USE_BEDROCK).toBe('1') | ||
| expect(auth.env.AWS_ACCESS_KEY_ID).toBe('AKIA_TEST') | ||
| expect(auth.env.AWS_SECRET_ACCESS_KEY).toBe('secret') | ||
| expect(auth.env.AWS_REGION).toBe('us-east-1') | ||
| expect(auth.env.ANTHROPIC_API_KEY).toBeUndefined() | ||
| }) | ||
|
|
||
| it('resolves bedrock mode using a caller-supplied bedrockEnvVarNames (e.g. Akrites)', () => { | ||
| clearAuthEnv() | ||
| process.env.AKRITES_AWS_BEDROCK_ACCESS_KEY_ID = 'AKIA_AKRITES' | ||
| process.env.AKRITES_AWS_BEDROCK_SECRET_ACCESS_KEY = 'akrites-secret' | ||
| // A CROWD_AWS_BEDROCK_* credential being set for an unrelated consumer must not | ||
| // leak into an Akrites-scoped caller. | ||
| process.env.CROWD_AWS_BEDROCK_ACCESS_KEY_ID = 'AKIA_UNRELATED' | ||
| process.env.CROWD_AWS_BEDROCK_SECRET_ACCESS_KEY = 'unrelated-secret' | ||
|
|
||
| const auth = resolveAgentAuth({ bedrockEnvVarNames: AKRITES_BEDROCK_ENV_VAR_NAMES }) | ||
|
|
||
| expect(auth.mode).toBe('bedrock') | ||
| expect(auth.env.AWS_ACCESS_KEY_ID).toBe('AKIA_AKRITES') | ||
| expect(auth.env.AWS_SECRET_ACCESS_KEY).toBe('akrites-secret') | ||
| }) | ||
|
|
||
| it('uses the region env var named by bedrockEnvVarNames when set', () => { | ||
| clearAuthEnv() | ||
| process.env.AKRITES_AWS_BEDROCK_ACCESS_KEY_ID = 'AKIA_AKRITES' | ||
| process.env.AKRITES_AWS_BEDROCK_SECRET_ACCESS_KEY = 'akrites-secret' | ||
| process.env.AKRITES_AWS_BEDROCK_REGION = 'us-west-2' | ||
|
|
||
| const auth = resolveAgentAuth({ bedrockEnvVarNames: AKRITES_BEDROCK_ENV_VAR_NAMES }) | ||
|
|
||
| expect(auth.env.AWS_REGION).toBe('us-west-2') | ||
| }) | ||
|
|
||
| it('does not fall into bedrock mode with only one of the two credentials', () => { | ||
| clearAuthEnv() | ||
| process.env.AKRITES_AWS_BEDROCK_ACCESS_KEY_ID = 'AKIA_AKRITES' | ||
| process.env.BLAST_RADIUS_ANTHROPIC_API_KEY = 'sk-ant-fallback' | ||
|
|
||
| const auth = resolveAgentAuth({ bedrockEnvVarNames: AKRITES_BEDROCK_ENV_VAR_NAMES }) | ||
|
|
||
| expect(auth.mode).toBe('anthropic-api-key') | ||
| }) | ||
|
|
||
| it('resolves anthropic-api-key mode when no bedrock credentials are set', () => { | ||
| clearAuthEnv() | ||
| process.env.BLAST_RADIUS_ANTHROPIC_API_KEY = 'sk-ant-test' | ||
| process.env.BLAST_RADIUS_ANTHROPIC_BASE_URL = 'https://litellm.internal' | ||
|
|
||
| const auth = resolveAgentAuth({ bedrockEnvVarNames: AKRITES_BEDROCK_ENV_VAR_NAMES }) | ||
|
|
||
| expect(auth.mode).toBe('anthropic-api-key') | ||
| expect(auth.env.ANTHROPIC_API_KEY).toBe('sk-ant-test') | ||
| expect(auth.env.ANTHROPIC_BASE_URL).toBe('https://litellm.internal') | ||
| expect(auth.resolveModel('claude-opus-4-8')).toBe('claude-opus-4-8') | ||
| }) | ||
|
|
||
| it('supports a custom api key env var name', () => { | ||
| clearAuthEnv() | ||
| process.env.CUSTOM_ANTHROPIC_API_KEY = 'sk-ant-custom' | ||
|
|
||
| const auth = resolveAgentAuth({ apiKeyEnvVar: 'CUSTOM_ANTHROPIC_API_KEY' }) | ||
|
|
||
| expect(auth.mode).toBe('anthropic-api-key') | ||
| expect(auth.env.ANTHROPIC_API_KEY).toBe('sk-ant-custom') | ||
|
|
||
| delete process.env.CUSTOM_ANTHROPIC_API_KEY | ||
| }) | ||
|
|
||
| it('falls back to cli auth when nothing is configured', () => { | ||
| clearAuthEnv() | ||
|
|
||
| const auth = resolveAgentAuth({ bedrockEnvVarNames: AKRITES_BEDROCK_ENV_VAR_NAMES }) | ||
|
|
||
| expect(auth.mode).toBe('cli-fallback') | ||
| expect(auth.env).toBeUndefined() | ||
| expect(auth.resolveModel('claude-sonnet-5')).toBe('claude-sonnet-5') | ||
| }) | ||
|
|
||
| it('translates model IDs via modelBedrockMap in bedrock mode', () => { | ||
| clearAuthEnv() | ||
| process.env.AKRITES_AWS_BEDROCK_ACCESS_KEY_ID = 'AKIA_AKRITES' | ||
| process.env.AKRITES_AWS_BEDROCK_SECRET_ACCESS_KEY = 'akrites-secret' | ||
|
|
||
| const auth = resolveAgentAuth({ | ||
| bedrockEnvVarNames: AKRITES_BEDROCK_ENV_VAR_NAMES, | ||
| modelBedrockMap: { 'claude-opus-4-8': 'us.anthropic.claude-opus-4-8-v1:0' }, | ||
| }) | ||
|
|
||
| expect(auth.resolveModel('claude-opus-4-8')).toBe('us.anthropic.claude-opus-4-8-v1:0') | ||
| }) | ||
|
|
||
| it('throws on an unmapped model when a modelBedrockMap is provided', () => { | ||
| clearAuthEnv() | ||
| process.env.AKRITES_AWS_BEDROCK_ACCESS_KEY_ID = 'AKIA_AKRITES' | ||
| process.env.AKRITES_AWS_BEDROCK_SECRET_ACCESS_KEY = 'akrites-secret' | ||
|
|
||
| const auth = resolveAgentAuth({ | ||
| bedrockEnvVarNames: AKRITES_BEDROCK_ENV_VAR_NAMES, | ||
| modelBedrockMap: { 'claude-opus-4-8': 'us.anthropic.claude-opus-4-8-v1:0' }, | ||
| }) | ||
|
|
||
| expect(() => auth.resolveModel('claude-haiku-9000')).toThrow() | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.