Skip to content

Commit 74157e4

Browse files
committed
fix: add format validation to non-interactive VPC path, consolidate VpcOptions type
- validateVpcOptions now calls validateSubnetIds/validateSecurityGroupIds so the non-interactive CLI path gives friendly format errors instead of falling through to Zod regex failures - CreateOptions, AddAgentOptions, and AgentPrimitive.AddAgentOptions now extend VpcOptions instead of redeclaring networkMode/subnets/securityGroups
1 parent 892ee85 commit 74157e4

5 files changed

Lines changed: 44 additions & 13 deletions

File tree

src/cli/commands/add/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { GatewayAuthorizerType, ModelProvider, SDKFramework, TargetLanguage } from '../../../schema';
22
import type { MemoryOption } from '../../tui/screens/generate/types';
3+
import type { VpcOptions } from '../shared/vpc-utils';
34

45
// Agent types
5-
export interface AddAgentOptions {
6+
export interface AddAgentOptions extends VpcOptions {
67
name?: string;
78
type?: 'create' | 'byo';
89
build?: string;
@@ -11,9 +12,6 @@ export interface AddAgentOptions {
1112
modelProvider?: ModelProvider;
1213
apiKey?: string;
1314
memory?: MemoryOption;
14-
networkMode?: string;
15-
subnets?: string;
16-
securityGroups?: string;
1715
codeLocation?: string;
1816
entrypoint?: string;
1917
json?: boolean;

src/cli/commands/create/types.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export interface CreateOptions {
1+
import type { VpcOptions } from '../shared/vpc-utils';
2+
3+
export interface CreateOptions extends VpcOptions {
24
name?: string;
35
agent?: boolean;
46
defaults?: boolean;
@@ -8,9 +10,6 @@ export interface CreateOptions {
810
modelProvider?: string;
911
apiKey?: string;
1012
memory?: string;
11-
networkMode?: string;
12-
subnets?: string;
13-
securityGroups?: string;
1413
outputDir?: string;
1514
skipGit?: boolean;
1615
skipPythonSetup?: boolean;

src/cli/commands/shared/__tests__/vpc-utils.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseCommaSeparatedList, validateSecurityGroupIds, validateSubnetIds } from '../vpc-utils';
1+
import { parseCommaSeparatedList, validateSecurityGroupIds, validateSubnetIds, validateVpcOptions } from '../vpc-utils';
22
import { describe, expect, it } from 'vitest';
33

44
describe('parseCommaSeparatedList', () => {
@@ -79,3 +79,34 @@ describe('validateSecurityGroupIds', () => {
7979
expect(result).toContain('Invalid security group ID format');
8080
});
8181
});
82+
83+
describe('validateVpcOptions - format validation', () => {
84+
it('rejects VPC mode with invalid subnet format', () => {
85+
const result = validateVpcOptions({
86+
networkMode: 'VPC',
87+
subnets: 'not-a-subnet',
88+
securityGroups: 'sg-12345678',
89+
});
90+
expect(result.valid).toBe(false);
91+
expect(result.error).toContain('Invalid subnet ID format');
92+
});
93+
94+
it('rejects VPC mode with invalid security group format', () => {
95+
const result = validateVpcOptions({
96+
networkMode: 'VPC',
97+
subnets: 'subnet-12345678',
98+
securityGroups: 'not-a-sg',
99+
});
100+
expect(result.valid).toBe(false);
101+
expect(result.error).toContain('Invalid security group ID format');
102+
});
103+
104+
it('accepts VPC mode with valid subnet and security group formats', () => {
105+
const result = validateVpcOptions({
106+
networkMode: 'VPC',
107+
subnets: 'subnet-12345678, subnet-abcdef12',
108+
securityGroups: 'sg-12345678',
109+
});
110+
expect(result.valid).toBe(true);
111+
});
112+
});

src/cli/commands/shared/vpc-utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export function validateVpcOptions(options: VpcOptions): VpcValidationResult {
6969
if (!options.securityGroups) {
7070
return { valid: false, error: '--security-groups is required when network mode is VPC' };
7171
}
72+
73+
const subnetResult = validateSubnetIds(options.subnets);
74+
if (subnetResult !== true) return { valid: false, error: subnetResult };
75+
const sgResult = validateSecurityGroupIds(options.securityGroups);
76+
if (sgResult !== true) return { valid: false, error: sgResult };
7277
}
7378

7479
if (options.networkMode !== 'VPC' && (options.subnets || options.securityGroups)) {

src/cli/primitives/AgentPrimitive.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
import { AgentEnvSpecSchema, CREDENTIAL_PROVIDERS } from '../../schema';
1313
import type { AddAgentOptions as CLIAddAgentOptions } from '../commands/add/types';
1414
import { validateAddAgentOptions } from '../commands/add/validate';
15+
import type { VpcOptions } from '../commands/shared/vpc-utils';
1516
import { VPC_ENDPOINT_WARNING, parseCommaSeparatedList } from '../commands/shared/vpc-utils';
1617
import { getErrorMessage } from '../errors';
1718
import {
@@ -35,7 +36,7 @@ import { dirname, join } from 'path';
3536
/**
3637
* Options for adding an agent resource.
3738
*/
38-
export interface AddAgentOptions {
39+
export interface AddAgentOptions extends VpcOptions {
3940
name: string;
4041
type: 'create' | 'byo';
4142
buildType: BuildType;
@@ -44,9 +45,6 @@ export interface AddAgentOptions {
4445
modelProvider: ModelProvider;
4546
apiKey?: string;
4647
memory?: MemoryOption;
47-
networkMode?: string;
48-
subnets?: string;
49-
securityGroups?: string;
5048
codeLocation?: string;
5149
entrypoint?: string;
5250
}

0 commit comments

Comments
 (0)