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
11 changes: 11 additions & 0 deletions src/cli/operations/agent/generate/__tests__/schema-mapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { computeManagedOAuthCredentialName } from '../../../../primitives/credential-utils.js';
import type { GenerateConfig } from '../../../../tui/screens/generate/types.js';
import {
mapGenerateConfigToAgent,
Expand Down Expand Up @@ -190,3 +191,13 @@ describe('mapGenerateConfigToRenderConfig', () => {
expect(result.memoryProviders[0]!.strategies).toEqual(['SEMANTIC', 'USER_PREFERENCE', 'SUMMARIZATION']);
});
});

describe('gateway credential provider name mapping', () => {
it('computeManagedOAuthCredentialName produces the correct suffix', () => {
// Regression test: the managed credential name must use '-oauth' suffix.
// GatewayPrimitive creates it, schema-mapper looks it up, AddGatewayScreen displays it.
// All three now use computeManagedOAuthCredentialName to stay in sync.
expect(computeManagedOAuthCredentialName('my-gateway')).toBe('my-gateway-oauth');
expect(computeManagedOAuthCredentialName('test')).toBe('test-oauth');
});
});
7 changes: 5 additions & 2 deletions src/cli/operations/agent/generate/schema-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type {
} from '../../../../schema';
import { DEFAULT_STRATEGY_NAMESPACES } from '../../../../schema';
import { GatewayPrimitive } from '../../../primitives/GatewayPrimitive';
import { computeDefaultCredentialEnvVarName } from '../../../primitives/credential-utils';
import {
computeDefaultCredentialEnvVarName,
computeManagedOAuthCredentialName,
} from '../../../primitives/credential-utils';
import type {
AgentRenderConfig,
GatewayProviderRenderConfig,
Expand Down Expand Up @@ -199,7 +202,7 @@ async function mapGatewaysToGatewayProviders(): Promise<GatewayProviderRenderCon

if (gateway.authorizerType === 'CUSTOM_JWT' && gateway.authorizerConfiguration?.customJwtAuthorizer) {
const jwtConfig = gateway.authorizerConfiguration.customJwtAuthorizer;
const credName = `${gateway.name}-agent-oauth`;
const credName = computeManagedOAuthCredentialName(gateway.name);
const credential = project.credentials.find(c => c.name === credName);

if (credential) {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/primitives/GatewayPrimitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { RemovalPreview, RemovalResult, SchemaChange } from '../operations/
import type { AddGatewayConfig } from '../tui/screens/mcp/types';
import { BasePrimitive } from './BasePrimitive';
import { SOURCE_CODE_NOTE } from './constants';
import { computeDefaultCredentialEnvVarName } from './credential-utils';
import { computeDefaultCredentialEnvVarName, computeManagedOAuthCredentialName } from './credential-utils';
import type { AddResult, AddScreenComponent, RemovableResource } from './types';
import type { Command } from '@commander-js/extra-typings';

Expand Down Expand Up @@ -379,7 +379,7 @@ export class GatewayPrimitive extends BasePrimitive<AddGatewayOptions, Removable
gatewayName: string,
jwtConfig: NonNullable<AddGatewayConfig['jwtConfig']>
): Promise<void> {
const credentialName = `${gatewayName}-oauth`;
const credentialName = computeManagedOAuthCredentialName(gatewayName);
const project = await this.readProjectSpec();

// Skip if credential already exists
Expand Down
9 changes: 9 additions & 0 deletions src/cli/primitives/credential-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@
export function computeDefaultCredentialEnvVarName(credentialName: string): string {
return `AGENTCORE_CREDENTIAL_${credentialName.replace(/-/g, '_').toUpperCase()}`;
}

/**
* Compute the managed OAuth credential name for a gateway.
* Used when creating the credential (GatewayPrimitive) and when
* looking it up for code generation (schema-mapper).
*/
export function computeManagedOAuthCredentialName(gatewayName: string): string {
return `${gatewayName}-oauth`;
}
3 changes: 2 additions & 1 deletion src/cli/tui/screens/mcp/AddGatewayScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { GatewayAuthorizerType } from '../../../../schema';
import { GatewayNameSchema } from '../../../../schema';
import { computeManagedOAuthCredentialName } from '../../../primitives/credential-utils';
import {
ConfirmReview,
Panel,
Expand Down Expand Up @@ -272,7 +273,7 @@ export function AddGatewayScreen({ onComplete, onExit, existingGateways, unassig
? [{ label: 'Allowed Scopes', value: wizard.config.jwtConfig.allowedScopes.join(', ') }]
: []),
...(wizard.config.jwtConfig.agentClientId
? [{ label: 'Agent Credential', value: `${wizard.config.name}-agent-oauth` }]
? [{ label: 'Agent Credential', value: computeManagedOAuthCredentialName(wizard.config.name) }]
: []),
]
: []),
Expand Down
Loading