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
61 changes: 61 additions & 0 deletions src/cli/operations/deploy/__tests__/post-deploy-ab-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,67 @@ describe('setupABTests', () => {

expect(mockCreateABTest.mock.calls[0]![0].evaluationConfig.onlineEvaluationConfigArn).toBe('arn:eval:resolved');
});

it('resolves target-based variant with project prefix (runtime === projectName)', async () => {
const targetBasedTest = {
...sampleABTest,
mode: 'target-based' as const,
variants: [
{
name: 'C' as const,
weight: 90,
variantConfiguration: { target: { targetName: 'MyAgent-prod' } },
},
{
name: 'T1' as const,
weight: 10,
variantConfiguration: { target: { targetName: 'MyAgent-staging' } },
},
],
};
mockCreateABTest.mockResolvedValue({ abTestId: 'abt-tgt-1', abTestArn: 'arn:abt:tgt1' });

await setupABTests({
region: 'us-east-1',
projectSpec: makeProjectSpec([targetBasedTest]),
});

const callArgs = mockCreateABTest.mock.calls[0]![0];
expect(callArgs.variants[0].variantConfiguration.target.name).toBe('TestProject-MyAgent-prod');
expect(callArgs.variants[1].variantConfiguration.target.name).toBe('TestProject-MyAgent-staging');
});

it('resolves target-based variant with project prefix (different project name)', async () => {
const targetBasedTest = {
...sampleABTest,
mode: 'target-based' as const,
variants: [
{
name: 'C' as const,
weight: 90,
variantConfiguration: { target: { targetName: 'Bar-prod' } },
},
{
name: 'T1' as const,
weight: 10,
variantConfiguration: { target: { targetName: 'Bar-staging' } },
},
],
};
mockCreateABTest.mockResolvedValue({ abTestId: 'abt-tgt-2', abTestArn: 'arn:abt:tgt2' });

const spec = makeProjectSpec([targetBasedTest]);
spec.name = 'Foo';

await setupABTests({
region: 'us-east-1',
projectSpec: spec,
});

const callArgs = mockCreateABTest.mock.calls[0]![0];
expect(callArgs.variants[0].variantConfiguration.target.name).toBe('Foo-Bar-prod');
expect(callArgs.variants[1].variantConfiguration.target.name).toBe('Foo-Bar-staging');
});
});

describe('deletion (reconciliation)', () => {
Expand Down
9 changes: 3 additions & 6 deletions src/cli/operations/deploy/post-deploy-ab-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,11 @@ function resolveConfigBundleVersion(
}

/**
* Resolve a variant target name, applying the project prefix if not already present.
* This handles legacy configs that were created before the prefix requirement.
* Resolve a variant target name by applying the project prefix unconditionally.
* post-deploy-http-gateways.ts always creates targets as `${projectName}-${tgt.name}`,
* so the AB test must reference the same prefixed name.
*/
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}`;
}
Comment thread
notgitika marked this conversation as resolved.

Expand Down
Loading