Skip to content

fix(unit-only): Replace the harness-only --logs success-return block in... (#1406)#51

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1406
Draft

fix(unit-only): Replace the harness-only --logs success-return block in... (#1406)#51
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1406

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1406

Issues

  • dev --logs on harness-only project exits 0 instead of failing aws/agentcore-cli#1406 — In a preview build (@preview / BUILD_PREVIEW=1), running agentcore dev --logs on a harness-only project prints informational guidance and exits 0 instead of exiting 1 with a validation error. This breaks scripts/CI that rely on the exit code to detect no dev server started. It does NOT affect any GA (@latest) release: the harness branch is preview-gated and dead-code-eliminated from the GA bundle, and harness projects can only be created in preview builds anyway.

Root cause

At command.tsx:363 the branch if (isPreviewEnabled() && supportedAgents.length === 0 && hasHarnesses) optionally deploys then prints invoke guidance and ends with return { success: true as const, blockingPromise: Promise.resolve() } (line 376). That success result flows out of withCommandRunTelemetry to lines 552-554 (if (!serverResult.success) throw ...; await serverResult.blockingPromise; process.exit(0)), so the process exits 0. Sibling validation failures in the same command correctly throw new ValidationError(...) (e.g. 327-331, 343-347, 379-384, 392-394) which the outer try/catch at 555-558 turns into process.exit(1). Decisive context the brief understated: the branch is gated on isPreviewEnabled() (line 363) and hasHarnesses is itself isPreviewEnabled() && ... (line 325). __PREVIEW__ is a compile-time esbuild define (esbuild.config.mjs:56, process.env.BUILD_PREVIEW === '1' ? 'true' : 'false'). The GA publish job publish-main runs npm run build with NO BUILD_PREVIEW (release-main-and-preview.yml:309), so __PREVIEW__ is literal false and the branch is dead-code-eliminated under minify: true. Harness creation is also preview-only (create command.tsx:516), so the issue's repro only produces a harness project in a preview build. Bug is real and present at v0.20.2 HEAD (commit e92c79a) but exercisable only in preview builds.

The fix

Replace the success return at command.tsx:376 (and collapse the surrounding deploy+guidance block 363-377) with throw new ValidationError('Harness projects do not support local dev. Use \agentcore invoke --harness ` instead.'). ValidationError is already imported (line 5) and is caught by the outer try/catch at 555-558 which calls process.exit(1). This is exactly what closed PR #1450 did. One design decision to settle with maintainers before re-landing: whether the pre-throw runCliDeploy()` (lines 365-367) served a purpose — Hweinstock raised this in the PR review and it was taken to DM, so confirm fail-fast vs deploy-then-fail semantics before applying. Note this fix only changes preview behavior; GA is unaffected either way.

Files touched: /local/home/aidandal/workplace/issues/agentcore-cli/src/cli/commands/dev/command.tsx — harness-only --logs branch at lines 361-377 (specifically the return { success: true ... } at line 376). Owner repo: agentcore-cli (CLI). No CDK/SDK/service handoff.

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

BEFORE (buggy source restored via git stash of the fix, regression test kept): running the dev handler with opts.logs=true on a harness-only project (runtimes:[], harnesses:[{name:'my-harness'}], getDevSupportedAgents=[]) hit the harness-only branch's return { success: true as const, blockingPromise: Promise.resolve() } and printed informational invoke guidance. Test observed exitCodes=[0] (success-return flowed to process.exit(0)) and stderr did NOT contain 'agentcore invoke --harness'. Both regression assertions FAILED (expected [+0] to include 1; expected '' to contain 'agentcore invoke --harness my-harness'). This is exactly the original symptom: --logs silently a no-op with exit 0. AFTER (fix restored, verified byte-identical): the harness-only --logs branch now throws ValidationError('Harness projects do not support local dev. Use agentcore invoke --harness my-harness instead.'), caught by outer try/catch at command.tsx:557-559 -> process.exit(1). Regression test passed: exitCodes contains 1, does NOT contain 0, and stderr contains 'agentcore invoke --harness my-harness'. The success-return path is no longer reached for harness-only --logs.

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

Harness-only projects have no local dev server to tail logs from. The
--logs branch previously deployed, printed informational invoke guidance,
and returned a success result that flowed to process.exit(0), making the
flag a silent no-op. Throw a ValidationError instead so the outer
try/catch exits 1, matching sibling validation failures in the command.

Fixes aws#1406
@github-actions github-actions Bot added the size/s PR size: S label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 37.26% 13628 / 36569
🔵 Statements 36.52% 14487 / 39658
🔵 Functions 31.83% 2335 / 7335
🔵 Branches 31.2% 9029 / 28930
Generated in workflow #105 for commit da38261 by the Vitest Coverage Report Action

@github-actions github-actions Bot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant