Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 88
fix: prefix HTTP gateway names with project name to prevent cross-project collisions#1105
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
92b1fe5
fix: prefix HTTP gateway names with project name to prevent cross-pro…
jariy17 8452ac4
chore: remove NODE_OPTIONS test script changes from gateway fix
jariy17 5c178e6
fix: update ABTestPrimitive to use project-prefixed target names
jariy17 232a284
fix: add pre-migration gateway name fallback for state-loss recovery …
jariy17 1807d98
test: add unit test for pre-migration gateway name fallback (Comment 3)
jariy17 9fa3c6f
fix: avoid double-prefixing variant target names in resolveVariants
jariy17 b2cae6f
fix: remove standalone gateway name max(24) guard; add target preflig…
jariy17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
39 changes: 36 additions & 3 deletions
39 src/cli/operations/deploy/__tests__/post-deploy-http-gateways.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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -142,7 +142,7 @@ export async function setupABTests(options: SetupABTestsOptions): Promise<SetupA | ||
| const existingTest = existingABTests?.[testSpec.name]; | ||
| // Resolve ARN references from deployed state | ||
| const resolvedVariants = resolveVariants(testSpec.variants, deployedResources); | ||
| const resolvedVariants = resolveVariants(testSpec.variants, projectSpec.name, deployedResources); | ||
| const resolvedGatewayArn = resolveGatewayArn(testSpec.gatewayRef, deployedResources); | ||
| if (!resolvedGatewayArn.startsWith('arn:') || resolvedGatewayArn.split(':').length < 6) { | ||
| results.push({ | ||
| @@ -409,7 +409,8 @@ async function findABTestByName( | ||
| /** | ||
| * Resolve variant config bundle references. | ||
| * If bundleArn is a name (not an ARN), look it up in deployed config bundles. | ||
| * Target-based variants are passed through as-is. | ||
| * Target-based variants have their target name prefixed with projectName to match | ||
| * what post-deploy-http-gateways.ts creates on AWS (e.g. `${projectName}-${tgt.name}`). | ||
jariy17 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| */ | ||
| function resolveVariants( | ||
| variants: { | ||
| @@ -420,6 +421,7 @@ function resolveVariants( | ||
| target?: { targetName: string }; | ||
| }; | ||
| }[], | ||
| projectName: string, | ||
| deployedResources?: DeployedResourceState | ||
| ): ABTestVariant[] { | ||
| return variants.map(v => { | ||
| @@ -436,12 +438,15 @@ function resolveVariants( | ||
| }, | ||
| }; | ||
| } | ||
| // Target-based variant — pass through | ||
| // Target-based variant — prepend projectName to match the AWS-side name created by | ||
| // post-deploy-http-gateways.ts: `${projectName}-${tgt.name}` | ||
| return { | ||
| name: v.name, | ||
| weight: v.weight, | ||
| variantConfiguration: { | ||
| ...(v.variantConfiguration.target && { target: { name: v.variantConfiguration.target.targetName } }), | ||
| ...(v.variantConfiguration.target && { | ||
| target: { name: resolveTargetName(v.variantConfiguration.target.targetName, projectName) }, | ||
| }), | ||
| }, | ||
| }; | ||
| }); | ||
| @@ -475,6 +480,18 @@ function resolveConfigBundleVersion( | ||
| return versionRef; | ||
| } | ||
| /** | ||
| * Resolve a variant target name, applying the project prefix if not already present. | ||
| * This handles legacy configs that were created before the prefix requirement. | ||
| */ | ||
| function resolveTargetName(targetName: string, projectName: string): string { | ||
| // If the target name already starts with the project prefix, use as-is to avoid double-prefixing | ||
| if (targetName.startsWith(`${projectName}-`)) { | ||
| return targetName; | ||
| } | ||
| return `${projectName}-${targetName}`; | ||
| } | ||
| function resolveGatewayArn(ref: string, deployedResources?: DeployedResourceState): string { | ||
| if (ref.startsWith('arn:')) return ref; | ||
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
12 changes: 6 additions & 6 deletions
12 src/schema/schemas/primitives/__tests__/http-gateway.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
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 |
|---|---|---|
| @@ -7,10 +7,9 @@ import { z } from 'zod'; | ||
| export const HttpGatewayNameSchema = z | ||
| .string() | ||
| .min(1, 'Name is required') | ||
| .max(48) | ||
| .regex( | ||
| /^[a-zA-Z][a-zA-Z0-9-]{0,47}$/, | ||
| 'Must begin with a letter and contain only alphanumeric characters and hyphens (max 48 chars)' | ||
jariy17 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /^[a-zA-Z][a-zA-Z0-9-]*$/, | ||
| 'Gateway name must start with a letter and contain only alphanumeric characters or hyphens (combined with project name must fit 48-char AWS limit)' | ||
| ); | ||
| export const HttpGatewayTargetSchema = z.object({ | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.