diff --git a/src/spec-node/imageMetadata.ts b/src/spec-node/imageMetadata.ts index 70a913965..60884592e 100644 --- a/src/spec-node/imageMetadata.ts +++ b/src/spec-node/imageMetadata.ts @@ -497,11 +497,9 @@ export function getDevcontainerMetadataLabel(devContainerMetadata: SubstitutedCo if (!metadata.length) { return ''; } - const imageMetadataLabelValue = metadata.length !== 1 - ? `[${metadata - .map(feature => ` \\\n${toLabelString(feature)}`) - .join(',')} \\\n]` - : toLabelString(metadata[0]); + const imageMetadataLabelValue = `[${metadata + .map(feature => ` \\\n${toLabelString(feature)}`) + .join(',')} \\\n]`; return `LABEL ${imageMetadataLabel}="${imageMetadataLabelValue}"`; } diff --git a/src/test/imageMetadata.test.ts b/src/test/imageMetadata.test.ts index 24045ac4e..fb78df0f5 100644 --- a/src/test/imageMetadata.test.ts +++ b/src/test/imageMetadata.test.ts @@ -432,6 +432,22 @@ describe('Image Metadata', function () { assert.strictEqual(label.replace(/ \\\n/g, ''), `LABEL devcontainer.metadata="${JSON.stringify(expected).replace(/"/g, '\\"')}"`); }); + it('should create array label for single metadata entry (docker-compose with Dockerfile, no features)', () => { + // When there is only one metadata entry, the label should still be a JSON array. + // Regression test for https://github.com/devcontainers/cli/issues/1054 + const label = getDevcontainerMetadataLabel(configWithRaw([ + { + remoteUser: 'testUser', + } + ])); + const expected = [ + { + remoteUser: 'testUser', + } + ]; + assert.strictEqual(label.replace(/ \\\n/g, ''), `LABEL devcontainer.metadata="${JSON.stringify(expected).replace(/"/g, '\\"')}"`); + }); + it('should merge metadata from devcontainer.json and features', () => { const merged = mergeConfiguration({ configFilePath: URI.parse('file:///devcontainer.json'),