- Notifications
You must be signed in to change notification settings - Fork918
fix(agent/agentcontainers): ensure agent name env var is correct#18457
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Previously, `CODER_WORKSPACE_AGENT_NAME` would always be passed as thedev container name.This is invalid for the following scenarios:- The dev container is specified in terraform- The dev container has a name customizationThis change now runs `ReadConfig` twice. The first read is to extract aname (if present), from the `devcontainer.json`. The second read willthen use the name we have stored for the dev container (so this could beeither the customization, terraform resource name, or container name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Pull Request Overview
This PR ensures the agent’s custom name fromdevcontainer.json
is correctly applied to theCODER_WORKSPACE_AGENT_NAME
environment variable by reading the config twice and updated tests to verify both reads.
- Changed
readConfigErrC
channel capacity and added assertions for the first “empty” read. - Added a new subtest (
CreateReadsConfigTwice
) to cover custom-name override. - Updated
api.go
to runReadConfig
once to extract the name and again to pass the proper env var.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
agent/agentcontainers/api_test.go | IncreasereadConfigErrC capacity; assert empty vs. populated envs on two reads; new custom-name subtest |
agent/agentcontainers/api.go | CallReadConfig twice: first to pick upCoder.Name , second to inject it into the env |
Comments suppressed due to low confidence (4)
agent/agentcontainers/api.go:1172
- [nitpick] If
subAgentConfig.Name
is empty (no customization), this injects an emptyCODER_WORKSPACE_AGENT_NAME
; consider defaulting explicitly to the container’s name (dc.Name
) to avoid passing a blank value.
fmt.Sprintf("CODER_WORKSPACE_AGENT_NAME=%s", subAgentConfig.Name),
agent/agentcontainers/api_test.go:1896
- There is no test covering the branch where the customization name is invalid; add a case that supplies an invalid
Coder.Name
and asserts that the warning path is triggered.
t.Run("CreateReadsConfigTwice", func(t *testing.T) {
agent/agentcontainers/api_test.go:1264
- [nitpick] The variable name
fakeDCCLI
differs fromfDCCLI
used in the new subtest; consider unifying the naming for clarity and consistency across tests.
fakeDCCLI = &fakeDevcontainerCLI{
agent/agentcontainers/api.go:1163
- The local variable
logger
is undefined here; useapi.logger.Warn
to correctly reference the API’s logger instance.
logger.Warn(ctx, "invalid agent name in devcontainer customization, ignoring", slog.F("name", name))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Minor nit about log message but otherwise all good 👍🏻
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Optimization looks good 💪🏻
b49e62f
intomainUh oh!
There was an error while loading.Please reload this page.
Previously,
CODER_WORKSPACE_AGENT_NAME
would always be passed as the dev container name.This is invalid for the following scenarios:
This change now runs
ReadConfig
twice. The first read is to extract a name (if present), from thedevcontainer.json
. The second read will then use the name we have stored for the dev container (so this could be either the customization, terraform resource name, or container name).