fix: resolve target-based AB test target name mismatch#1188
Conversation
The resolveTargetName() function had a false-positive in its startsWith
check that prevented it from applying the project prefix. When the
runtime name equals the project name (the default case), target names
like "Foo-prod" already start with "Foo-" so the guard incorrectly
assumed they were already prefixed and returned them unchanged.
However, post-deploy-http-gateways.ts unconditionally creates targets
as `${projectName}-${tgt.name}` (e.g., "Foo-Foo-prod"), so the AB test
referenced a non-existent target and stayed in NOT_STARTED forever.
The fix removes the startsWith heuristic and always applies the prefix,
matching what post-deploy-http-gateways.ts does.
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Fix itself looks correct and the root-cause analysis matches what I see in the code: post-deploy-http-gateways.ts (lines 104, 146, 315) unconditionally writes targets as ${projectName}-${tgt.name}, and createTargetBasedABTest (ABTestPrimitive.ts line 634-635) stores the variant targetName as ${runtime}-${endpoint} — i.e., always the unprefixed logical name. So unconditional prefixing in resolveTargetName is the right call. The old startsWith check only misfired when runtime === projectName, which is the common default and is exactly what the e2e test was hitting.
One thing worth addressing before merge — see the inline comment on the test file.
Coverage Report
|
Covers the resolveTargetName fix with two cases: - runtime === projectName (the false-positive case that caused the bug) - different project/runtime names (standard prefixing)
Package TarballHow to installnpm install https://github.com/aws/agentcore-cli/releases/download/pr-1188-tarball/aws-agentcore-0.13.1.tgz |
Empirical verificationReproduced the e2e test flow manually against my account:
Result with the fix: {
"executionStatus": "RUNNING",
"variants": [
{"name": "C", "variantConfiguration": {"target": {"name": "TestABFix-TestABFix-prod"}}, "weight": 90},
{"name": "T1", "variantConfiguration": {"target": {"name": "TestABFix-TestABFix-staging"}}, "weight": 10}
]
}The AB test transitions to Without the fix, |
Summary
resolveTargetName()inpost-deploy-ab-tests.tswhich had a false-positivestartsWithcheck that prevented the project prefix from being applied to target names"ProjectName-prod"while the actual AWS gateway target was created as"ProjectName-ProjectName-prod"bypost-deploy-http-gateways.ts, causing the AB test to stay inNOT_STARTEDforevere2e-tests-full.ymlworkflow to fail on every run since the feature was introducedCloses #1179
Closes #1091
Root Cause
post-deploy-http-gateways.ts(lines 104, 146, 315) unconditionally writes targets as${projectName}-${tgt.name}.ABTestPrimitive.createTargetBasedABTest()(line 634-635) stores the varianttargetNameas${runtime}-${endpoint}— i.e., always the unprefixed logical name.The old
resolveTargetName()had astartsWithguard that misfired whenruntime === projectName(the common default):"MyAgent-prod".startsWith("MyAgent-")→ true, so it skipped prefixing. The AB test then referenced"MyAgent-prod"while the actual AWS target was"MyAgent-MyAgent-prod".Unconditional prefixing is the right call since the config always stores the unprefixed logical name.
Changes
post-deploy-ab-tests.ts: Remove thestartsWithheuristic, always apply the project prefixpost-deploy-ab-tests.test.ts: Add two unit tests covering target-based variant resolution:runtime === projectName(the case the old check broke)Test plan
post-deploy-ab-tests.test.ts, including 2 new)ab-test-target-based.test.ts)