fix(create): resolve user-supplied Dockerfile path from CLI invocation cwd, not project root#1154
Closed
aidandaly24 wants to merge 2 commits into
Closed
fix(create): resolve user-supplied Dockerfile path from CLI invocation cwd, not project root#1154aidandaly24 wants to merge 2 commits into
aidandaly24 wants to merge 2 commits into
Conversation
added 2 commits
May 7, 2026 16:49
… root - GenerateWizardUI: stop calling basename() on user-entered path before passing it to handleCreatePath, which previously discarded the directory component and silently no-oped the copy. - AddAgentScreen (BYO flow): same fix; also change PathInput basePath from <projectRoot>/<codeLocation> to process.cwd() so completion + validation match where the user invoked the CLI. - useAddAgent: resolve Dockerfile sourcePath against process.cwd() instead of projectRoot, and trigger the copy when the value is anything other than its own basename (covers ./Dockerfile, subdir/Dockerfile.dev, absolute paths, and Windows separators). - Persisted spec value remains a basename (CDK schema invariant).
Extract the cwd-relative dockerfile resolution into a small pure helper (resolveUserDockerfile) so handleCreatePath and handleByoPath share one implementation, and add targeted tests covering: - undefined / empty input → no-op - bare filename → preserved, never touches fs - relative path → resolved against cwd - nested relative path → basename extracted correctly - absolute path → honored as-is - missing file → ok:false, error mentions cwd-resolved path - regression for the bug → does NOT resolve under projectRoot/codeLocation Also extend useGenerateWizard tests to assert the wizard preserves the user-supplied directory components (no premature basename stripping).
Contributor
Coverage Report
|
agentcore-cli-automation
approved these changes
May 7, 2026
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Nice, focused bug fix. The root-cause analysis in the PR description matches what I see on main — both wizards' onSubmit handlers were pre-stripping the directory before it reached handleCreatePath/handleByoPath, so the includes('/') branch was effectively dead code. Extracting resolveUserDockerfile into a pure helper and driving it off process.cwd() is the right shape.
I traced the flow end-to-end and I don't see anything that needs to change before merging:
- Empty-string handling is safe: the BYO
onSubmitstores'',resolveUserDockerfile('')returns{ copy: false }, andmapByoConfigToAgent/mapAddAgentConfigToGenerateConfigboth omit falsydockerfilefrom the spec (schema rejects'', so this matters). - The
basename()-based "bare filename" check correctly handles\on Windows viapath.win32.basename, fixing the latent bug called out in the description. - The renderer's
exclude = new Set(['Dockerfile'])branch inBaseRenderer.tsmeans that when the user supplies a path like./Dockerfile.dev, the template's defaultDockerfileis correctly excluded and the copied file takes its place. No duplicateDockerfileends up in the agent dir. - Paths like
../Dockerfileend up persisted as the basename, which satisfies the strict schema regex inagent-env.ts. PathInputalready does upfrontexistsSyncvalidation against the samebasePath(process.cwd()), so theok: falsebranch inresolveUserDockerfileis mostly a defensive double-check — the "half-rendered agent on missing file" concern is not a practical regression.
No blocking comments — approving.
Contributor
Author
|
Closing: duplicate from batch test run |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes a bug in the
agentcore createwizard where a user-supplied Dockerfile path was resolved relative to the discovered project root (or<projectRoot>/<codeLocation>for BYO) instead of the directory the user invoked the CLI from. Per the issue reporter, this gave confusing "not found" errors like:…when the user expected the path to be resolved relative to their actual
cwd(e.g./workplace/.../.github/).Root cause
Two compounding problems in the TUI:
GenerateWizardUI.tsxandAddAgentScreen.tsxboth calledbasename(value)inside thePathInput.onSubmithandler, which silently discarded the directory component of the path before it ever reached the resolution logic inuseAddAgent.ts. As a result, theif (dockerfile?.includes('/'))branch inhandleCreatePathwas effectively dead code — no user-entered path was ever copied.PathInputset itsbasePathtoresolve(project.projectRoot, byoConfig.codeLocation), so completion + validation operated relative to<projectRoot>/<codeLocation>(e.g.…/.github/harnesses/), which is exactly the bogus path the user saw in the error.useAddAgent.handleCreatePathandhandleByoPathresolved the source path withresolve(projectRoot, dockerfile), ignoring the user's actual cwd.Fix
basename()in both wizardonSubmithandlers — pass the raw user input through.PathInputbasePathtoprocess.cwd()so completion + validation match where the user invoked the CLI (consistent with theGenerateWizardUIDockerfile prompt and the existing policy--sourceflow).resolveUserDockerfile(value, cwd, fileExists?)inuseAddAgent.tsthat:undefined/empty.process.cwd(), validates withexistsSync, and instructs the caller to copy it into the agent / BYO code directory under just the basename.handleCreatePathandhandleByoPathto call the new helper, eliminating duplication.The detection condition
value !== basename(value)also fixes a latent Windows bug where the previousvalue.includes('/')would miss\separators.The persisted spec value remains a basename, so the CDK constructs and downstream renderers/packagers/config-bundle generation are unaffected.
Related Issue
Closes #1128
Documentation PR
N/A — purely a CLI bug fix; no public API or documented behavior changes.
Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integnpm run typechecknpm run lintsrc/assets/, I rannpm run test:update-snapshotsand committed the updated snapshotsTargeted test runs
src/cli/tui/screens/agent/__tests__/useAddAgent.test.ts(new) — 8/8 pass. Covers:fscwdok: false, error mentions cwd-resolved pathagentcorecommand was run #1128: does NOT resolve underprojectRoot/codeLocationsrc/cli/tui/screens/generate/__tests__/useGenerateWizard.test.tsx— 37/37 pass (added a regression test thatsetDockerfile('./subdir/Dockerfile.dev')preserves the directory components).src/cli/tui/screens/agent/__tests__/computeByoSteps.test.ts— 4/4 pass (sanity check, unaffected).Manual verification
<projectRoot>/.github/), runagentcore create, choose a Container build, supply./Dockerfile.dev→ file is copied into the agent directory and the spec recordsdockerfile: "Dockerfile.dev".subdir/Dockerfile.gpuand an absolute/tmp/Dockerfile.Dockerfileinput still falls through to the template default (no copy), preserving existing UX.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.