microsoft / microsoft/aspire

Snapshot collections in container image inspection results

Open Beginner friendly
#19,796 1 comment 0 reactions 0 assignees View on GitHub
area-integrations
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

`ContainerImageConfig` is exposed as inspection result metadata but retains caller-owned `IReadOnlyList` instances directly:

```csharp
public ContainerImageConfig(
IReadOnlyList entrypoint,
IReadOnlyList command,
string? workingDirectory)
{
Entrypoint = entrypoint;
Command = command;
WorkingDirectory = workingDirectory;
}
```

`IReadOnlyList` does not imply immutable storage. A caller can pass a mutable `List`, construct a successful inspection result, and mutate the list afterward. Consumers then observe the inspection metadata change after construction.

This matters because the object is used as stable parsed output from `IContainerRuntime` image inspection. `ContainerImageManifestInspectionResult.Success` already snapshots its manifest collection, so the config result should have equivalent value semantics.

The issue was identified while reviewing the container inspection API added by #19008.

### Expected Behavior

`ContainerImageConfig` should snapshot caller collections during construction, for example with `ToArray()` or immutable collections, so its public read-only properties cannot change through aliases.

Add regression tests that:

1. Construct the config from mutable entrypoint and command lists.
2. Mutate and clear the original lists.
3. Verify the config still contains the original values.

Review sibling inspection result/value types for the same aliasing pattern.

### Steps To Reproduce

```csharp
var entrypoint = new List { "dotnet" };
var command = new List { "app.dll" };
var config = new ContainerImageConfig(entrypoint, command, "/app");

entrypoint.Clear();
command[0] = "other.dll";

// Currently reflects the mutations.
Assert.Equal(["dotnet"], config.Entrypoint);
Assert.Equal(["app.dll"], config.Command);
```

### Exceptions (if any)

N/A

### Aspire doctor output

N/A

### Anything else?

Follow-up from #19008. The affected APIs are experimental, but this can be fixed without changing their public shape.

Contributor guide

Open the contributing guide

Research direction

Start at the ContainerImageConfig constructor and compare its collection handling with ContainerImageManifestInspectionResult. Add regression coverage using mutable entrypoint and command lists, then verify mutations after construction do not change the exposed values. Review sibling inspection result/value types for similar aliasing and ensure the relevant container inspection tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devops
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.