Skip to content

fix(agent/agentcontainers): treat customizations as array #18357

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2025

Conversation

DanielleMaywood
Copy link
Contributor

This PR fixes a mistake from the previous PR
#18342. Merged configuration results in the customization being an array not an object.

This PR also moves displayApps from being an array to being an object, like the terraform provider has.

{
        "name": "Sample Dev Container",
        "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
        "customizations": {
                "coder": {
                        "displayApps": {
                                "vscode": true,
                                "vscode_insiders": false,
                                "web_terminal": true
                        }
                }
        }
}

This PR fixes a mistake from the previous PR
#18342. Merged configuration results
in the customization being an array not an object.

This PR also moves `displayApps` from being an array to being an object,
like the terraform provider has.
Copy link
Contributor

@Copilot Copilot AI left a 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 fixes the configuration merging behavior for agent customizations by treating customizations as arrays and updating the DisplayApps type from an array to a map. Key changes include:

  • Changing CoderCustomization from a pointer to a slice in the configuration.
  • Updating DisplayApps from an array to a map in both the configuration and tests.
  • Refactoring related merging logic in the API to accommodate the new configuration structure.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

File Description
agent/agentcontainers/devcontainercli_test.go Updated test expectations to reflect changes from a single customization to a slice.
agent/agentcontainers/devcontainercli.go Updated type definitions for CoderCustomization and DisplayApps to match desired schema.
agent/agentcontainers/api_test.go Modified test cases to use a slice for customization and updated DisplayApps assertions.
agent/agentcontainers/api.go Refactored merging logic for DisplayApps using a map and then converting to a slice.
Comments suppressed due to low confidence (1)

agent/agentcontainers/api.go:1109

  • Document the merging behavior here since later customizations override earlier ones when populating the 'displayAppsMap', so future maintainers are aware of this design choice.
for _, customization := range coderCustomization {

Comment on lines +1116 to +1119
displayApps := make([]codersdk.DisplayApp, 0, len(displayAppsMap))
for app, enabled := range displayAppsMap {
if enabled {
displayApps = append(displayApps, app)
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider renaming the 'displayApps' slice (e.g. to 'enabledDisplayApps') to avoid possible confusion with other similarly named variables and improve code clarity.

Suggested change
displayApps := make([]codersdk.DisplayApp, 0, len(displayAppsMap))
for app, enabled := range displayAppsMap {
if enabled {
displayApps = append(displayApps, app)
enabledDisplayApps := make([]codersdk.DisplayApp, 0, len(displayAppsMap))
for app, enabled := range displayAppsMap {
if enabled {
enabledDisplayApps = append(enabledDisplayApps, app)

Copilot uses AI. Check for mistakes.

@DanielleMaywood DanielleMaywood requested a review from mafredri June 13, 2025 10:44
@DanielleMaywood DanielleMaywood marked this pull request as ready for review June 13, 2025 10:44
@@ -1099,14 +1099,24 @@ func (api *API) injectSubAgentIntoContainerLocked(ctx context.Context, dc coders
directory = DevcontainerDefaultContainerWorkspaceFolder
}

var displayApps []codersdk.DisplayApp
displayAppsMap := make(map[codersdk.DisplayApp]bool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll add the same defaults here then.

@DanielleMaywood DanielleMaywood merged commit 0ef6226 into main Jun 13, 2025
34 checks passed
@DanielleMaywood DanielleMaywood deleted the dm-sub-agent-display-apps-fix branch June 13, 2025 13:48
@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants