Skip to content

Commit 79a66b1

Browse files
authored
fix: deep-copy overlays during path resolution (#388)
1 parent ceb4aca commit 79a66b1

5 files changed

Lines changed: 28 additions & 163 deletions

File tree

internal/projectconfig/component.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ type ComponentConfig struct {
123123
// Where to get its spec and adjacent files from.
124124
Spec SpecSource `toml:"spec,omitempty" json:",omitempty" jsonschema:"title=Spec,description=Identifies where to find the spec for this component"`
125125

126-
// Where specific file artifacts should be sourced from, if not present alongside the spec.
127-
// If omitted, all files are expected to be present alongside the spec.
128-
Files []map[string]SourceFileReference `toml:"files,omitempty" json:",omitempty" jsonschema:"title=Files,description=List of file specifications declared under this component"`
129-
130126
// Overlays to apply to sources after they've been acquired. May mutate the spec as well as sources.
131127
Overlays []ComponentOverlay `toml:"overlays,omitempty" json:",omitempty" table:"-" jsonschema:"title=Overlays,description=Overlays to apply to this component's spec and/or sources"`
132128

@@ -160,5 +156,14 @@ func (c *ComponentConfig) WithAbsolutePaths(referenceDir string) *ComponentConfi
160156
// Fix up paths.
161157
result.Spec.Path = makeAbsolute(referenceDir, result.Spec.Path)
162158

159+
// Copy and fix up overlays.
160+
if c.Overlays != nil {
161+
result.Overlays = make([]ComponentOverlay, len(c.Overlays))
162+
163+
for i := range result.Overlays {
164+
result.Overlays[i] = *c.Overlays[i].WithAbsolutePaths(referenceDir)
165+
}
166+
}
167+
163168
return result
164169
}

internal/projectconfig/component_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ func TestComponentConfigWithAbsolutePaths(t *testing.T) {
8585

8686
require.Equal(t, comp, absComp)
8787
})
88+
89+
t.Run("overlays", func(t *testing.T) {
90+
comp := projectconfig.ComponentConfig{
91+
Name: "test",
92+
Overlays: []projectconfig.ComponentOverlay{
93+
{
94+
Type: projectconfig.ComponentOverlayAddFile,
95+
Source: "somefile.txt",
96+
},
97+
},
98+
}
99+
100+
absComp := *comp.WithAbsolutePaths(testRefDir)
101+
102+
require.Equal(t, comp.Name, absComp.Name)
103+
require.Len(t, absComp.Overlays, 1)
104+
require.Equal(t, comp.Overlays[0].Type, absComp.Overlays[0].Type)
105+
require.Equal(t, filepath.Join(testRefDir, comp.Overlays[0].Source), absComp.Overlays[0].Source)
106+
})
88107
}
89108

90109
func TestMergeComponentUpdates(t *testing.T) {

scenario/__snapshots__/TestSnapshotsContainer_config_generate-schema_stdout_1.snap

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@
4040
"title": "Spec",
4141
"description": "Identifies where to find the spec for this component"
4242
},
43-
"files": {
44-
"items": {
45-
"additionalProperties": {
46-
"$ref": "#/$defs/SourceFileReference"
47-
},
48-
"type": "object"
49-
},
50-
"type": "array",
51-
"title": "Files",
52-
"description": "List of file specifications declared under this component"
53-
},
5443
"overlays": {
5544
"items": {
5645
"$ref": "#/$defs/ComponentOverlay"
@@ -344,30 +333,6 @@
344333
"additionalProperties": false,
345334
"type": "object"
346335
},
347-
"Origin": {
348-
"properties": {
349-
"Type": {
350-
"type": "string"
351-
},
352-
"Location": {
353-
"type": "string"
354-
},
355-
"Script": {
356-
"type": "string"
357-
},
358-
"Args": {
359-
"items": {
360-
"type": "string"
361-
},
362-
"type": "array"
363-
}
364-
},
365-
"additionalProperties": false,
366-
"type": "object",
367-
"required": [
368-
"Type"
369-
]
370-
},
371336
"PackageRepository": {
372337
"properties": {
373338
"base-uri": {
@@ -431,24 +396,6 @@
431396
"additionalProperties": false,
432397
"type": "object"
433398
},
434-
"SourceFileReference": {
435-
"properties": {
436-
"Hash": {
437-
"type": "string"
438-
},
439-
"HashType": {
440-
"type": "string"
441-
},
442-
"Origins": {
443-
"items": {
444-
"$ref": "#/$defs/Origin"
445-
},
446-
"type": "array"
447-
}
448-
},
449-
"additionalProperties": false,
450-
"type": "object"
451-
},
452399
"SpecSource": {
453400
"properties": {
454401
"type": {

scenario/__snapshots__/TestSnapshots_config_generate-schema_stdout_1.snap

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@
4040
"title": "Spec",
4141
"description": "Identifies where to find the spec for this component"
4242
},
43-
"files": {
44-
"items": {
45-
"additionalProperties": {
46-
"$ref": "#/$defs/SourceFileReference"
47-
},
48-
"type": "object"
49-
},
50-
"type": "array",
51-
"title": "Files",
52-
"description": "List of file specifications declared under this component"
53-
},
5443
"overlays": {
5544
"items": {
5645
"$ref": "#/$defs/ComponentOverlay"
@@ -344,30 +333,6 @@
344333
"additionalProperties": false,
345334
"type": "object"
346335
},
347-
"Origin": {
348-
"properties": {
349-
"Type": {
350-
"type": "string"
351-
},
352-
"Location": {
353-
"type": "string"
354-
},
355-
"Script": {
356-
"type": "string"
357-
},
358-
"Args": {
359-
"items": {
360-
"type": "string"
361-
},
362-
"type": "array"
363-
}
364-
},
365-
"additionalProperties": false,
366-
"type": "object",
367-
"required": [
368-
"Type"
369-
]
370-
},
371336
"PackageRepository": {
372337
"properties": {
373338
"base-uri": {
@@ -431,24 +396,6 @@
431396
"additionalProperties": false,
432397
"type": "object"
433398
},
434-
"SourceFileReference": {
435-
"properties": {
436-
"Hash": {
437-
"type": "string"
438-
},
439-
"HashType": {
440-
"type": "string"
441-
},
442-
"Origins": {
443-
"items": {
444-
"$ref": "#/$defs/Origin"
445-
},
446-
"type": "array"
447-
}
448-
},
449-
"additionalProperties": false,
450-
"type": "object"
451-
},
452399
"SpecSource": {
453400
"properties": {
454401
"type": {

schemas/azldev.schema.json

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@
4040
"title": "Spec",
4141
"description": "Identifies where to find the spec for this component"
4242
},
43-
"files": {
44-
"items": {
45-
"additionalProperties": {
46-
"$ref": "#/$defs/SourceFileReference"
47-
},
48-
"type": "object"
49-
},
50-
"type": "array",
51-
"title": "Files",
52-
"description": "List of file specifications declared under this component"
53-
},
5443
"overlays": {
5544
"items": {
5645
"$ref": "#/$defs/ComponentOverlay"
@@ -344,30 +333,6 @@
344333
"additionalProperties": false,
345334
"type": "object"
346335
},
347-
"Origin": {
348-
"properties": {
349-
"Type": {
350-
"type": "string"
351-
},
352-
"Location": {
353-
"type": "string"
354-
},
355-
"Script": {
356-
"type": "string"
357-
},
358-
"Args": {
359-
"items": {
360-
"type": "string"
361-
},
362-
"type": "array"
363-
}
364-
},
365-
"additionalProperties": false,
366-
"type": "object",
367-
"required": [
368-
"Type"
369-
]
370-
},
371336
"PackageRepository": {
372337
"properties": {
373338
"base-uri": {
@@ -431,24 +396,6 @@
431396
"additionalProperties": false,
432397
"type": "object"
433398
},
434-
"SourceFileReference": {
435-
"properties": {
436-
"Hash": {
437-
"type": "string"
438-
},
439-
"HashType": {
440-
"type": "string"
441-
},
442-
"Origins": {
443-
"items": {
444-
"$ref": "#/$defs/Origin"
445-
},
446-
"type": "array"
447-
}
448-
},
449-
"additionalProperties": false,
450-
"type": "object"
451-
},
452399
"SpecSource": {
453400
"properties": {
454401
"type": {

0 commit comments

Comments
 (0)