10000 fix(agent): fix unexpanded devcontainer paths for agentcontainers · coder/coder@82d5bae · GitHub
[go: up one dir, main page]

Skip to content

Commit 82d5bae

Browse files
committed
fix(agent): fix unexpanded devcontainer paths for agentcontainers
Updates #16424
1 parent 58adc62 commit 82d5bae

File tree

3 files changed

+15
-5
lines changed
  • agentcontainers
  • 3 files changed

    +15
    -5
    lines changed

    agent/agent.go

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1085,6 +1085,8 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
    10851085
    if err != nil {
    10861086
    return xerrors.Errorf("expand directory: %w", err)
    10871087
    }
    1088+
    // Normalize all devcontainer paths by making them absolute.
    1089+
    manifest.Devcontainers = agentcontainers.ExpandAllDevcontainerPaths(a.logger, expandPathToAbs, manifest.Devcontainers)
    10881090
    subsys, err := agentsdk.ProtoFromSubsystems(a.subsystems)
    10891091
    if err != nil {
    10901092
    a.logger.Critical(ctx, "failed to convert subsystems", slog.Error(err))
    @@ -1127,7 +1129,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
    11271129
    )
    11281130
    if a.experimentalDevcontainersEnabled {
    11291131
    var dcScripts []codersdk.WorkspaceAgentScript
    1130-
    scripts, dcScripts = agentcontainers.ExtractAndInitializeDevcontainerScripts(a.logger, expandPathToAbs, manifest.Devcontainers, scripts)
    1132+
    scripts, dcScripts = agentcontainers.ExtractAndInitializeDevcontainerScripts(a.logger, manifest.Devcontainers, scripts)
    11311133
    // See ExtractAndInitializeDevcontainerScripts for motivation
    11321134
    // behind running dcScripts as post start scripts.
    11331135
    scriptRunnerOpts = append(scriptRunnerOpts, agentscripts.WithPostStartScripts(dcScripts...))

    agent/agentcontainers/devcontainer.go

    Lines changed: 11 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -37,7 +37,6 @@ devcontainer up %s
    3737
    // important if e.g. a Coder module to install @devcontainer/cli is used.
    3838
    func ExtractAndInitializeDevcontainerScripts(
    3939
    logger slog.Logger,
    40-
    expandPath func(string) (string, error),
    4140
    devcontainers []codersdk.WorkspaceAgentDevcontainer,
    4241
    scripts []codersdk.WorkspaceAgentScript,
    4342
    ) (filteredScripts []codersdk.WorkspaceAgentScript, devcontainerScripts []codersdk.WorkspaceAgentScript) {
    @@ -47,7 +46,6 @@ ScriptLoop:
    4746
    // The devcontainer scripts match the devcontainer ID for
    4847
    // identification.
    4948
    if script.ID == dc.ID {
    50-
    dc = expandDevcontainerPaths(logger, expandPath, dc)
    5149
    devcontainerScripts = append(devcontainerScripts, devcontainerStartupScript(dc, script))
    5250
    continue ScriptLoop
    5351
    }
    @@ -75,6 +73,17 @@ func devcontainerStartupScript(dc codersdk.WorkspaceAgentDevcontainer, script co
    7573
    return script
    7674
    }
    7775

    76+
    // ExpandAllDevcontainerPaths expands all devcontainer paths in the given
    77+
    // devcontainers. This is required by the devcontainer CLI, which requires
    78+
    // absolute paths for the workspace folder and config path.
    79+
    func ExpandAllDevcontainerPaths(logger slog.Logger, expandPath func(string) (string, error), devcontainers []codersdk.WorkspaceAgentDevcontainer) []codersdk.WorkspaceAgentDevcontainer {
    80+
    expanded := make([]codersdk.WorkspaceAgentDevcontainer, 0, len(devcontainers))
    81+
    for _, dc := range devcontainers {
    82+
    expanded = append(expanded, expandDevcontainerPaths(logger, expandPath, dc))
    83+
    }
    84+
    return expa A938 nded
    85+
    }
    86+
    7887
    func expandDevcontainerPaths(logger slog.Logger, expandPath func(string) (string, error), dc codersdk.WorkspaceAgentDevcontainer) codersdk.WorkspaceAgentDevcontainer {
    7988
    logger = logger.With(slog.F("devcontainer", dc.Name), slog.F("workspace_folder", dc.WorkspaceFolder), slog.F("config_path", dc.ConfigPath))
    8089

    agent/agentcontainers/devcontainer_test.go

    Lines changed: 1 addition & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -243,8 +243,7 @@ func TestExtractAndInitializeDevcontainerScripts(t *testing.T) {
    243243
    }
    244244
    gotFilteredScripts, gotDevcontainerScripts := agentcontainers.ExtractAndInitializeDevcontainerScripts(
    245245
    logger,
    246-
    tt.args.expandPath,
    247-
    tt.args.devcontainers,
    246+
    agentcontainers.ExpandAllDevcontainerPaths(logger, tt.args.expandPath, tt.args.devcontainers),
    248247
    tt.args.scripts,
    249248
    )
    250249

    0 commit comments

    Comments
     (0)
    0