Schedule item-local import scopes
This commit is contained in:
@@ -812,8 +812,14 @@ func TestItemAcquisitionRetainsInclusionGraphAndScopeOwnership(t *testing.T) {
|
||||
if rootScope.owner != graph.nodes[0].key || len(rootScope.contributions) != 2 {
|
||||
t.Fatalf("root acquisition scope = %#v", rootScope)
|
||||
}
|
||||
item := rootScope.contributions[1]
|
||||
if item.identity != graph.nodes[1].key || item.role != importRoleItem || item.scopeOwner != rootScope.owner || item.nested == nil {
|
||||
var item *acquiredContribution
|
||||
for index := range rootScope.contributions {
|
||||
if rootScope.contributions[index].role == importRoleItem {
|
||||
item = &rootScope.contributions[index]
|
||||
break
|
||||
}
|
||||
}
|
||||
if item == nil || item.identity != graph.nodes[1].key || item.scopeOwner != rootScope.owner || item.nested == nil {
|
||||
t.Fatalf("outer item contribution = %#v", item)
|
||||
}
|
||||
itemScope := item.nested.acquisition[0]
|
||||
@@ -831,6 +837,131 @@ func TestItemAcquisitionRetainsInclusionGraphAndScopeOwnership(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestItemContributionsUseDependencyReadySchedules(t *testing.T) {
|
||||
t.Run("outer independent items", func(t *testing.T) {
|
||||
type item struct {
|
||||
ID string `yaml:"id"`
|
||||
}
|
||||
type config struct {
|
||||
Items []item `yaml:"items"`
|
||||
}
|
||||
definition := Definition[config]{sequenceRegistrations: []sequenceRegistration{{path: Keys("items"), identityField: "id"}}}
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
imports:
|
||||
- path: z-item.yml
|
||||
destination: [items]
|
||||
placement: sequence-item
|
||||
- path: a-item.yml
|
||||
destination: [items]
|
||||
placement: sequence-item
|
||||
items: []
|
||||
`)
|
||||
zPath := writeImportFile(t, directory, "z-item.yml", "id: z\n")
|
||||
aPath := writeImportFile(t, directory, "a-item.yml", "id: a\n")
|
||||
result, err := testLoad[config](File(mainPath), Options[config]{Imports: true, Definition: definition})
|
||||
if err != nil {
|
||||
t.Fatalf("load item imports: %v", err)
|
||||
}
|
||||
if len(result.Config.Items) != 2 || result.Config.Items[0].ID != "a" || result.Config.Items[1].ID != "z" {
|
||||
t.Fatalf("scheduled items = %#v", result.Config.Items)
|
||||
}
|
||||
wantSources := []string{canonicalTestPath(t, mainPath), canonicalTestPath(t, zPath), canonicalTestPath(t, aPath)}
|
||||
for index, want := range wantSources {
|
||||
if got := result.Sources()[index].Path; got != want {
|
||||
t.Errorf("acquired source %d = %q, want %q", index, got, want)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unequal helper branches", func(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
imports:
|
||||
- path: item.yml
|
||||
destination: [items]
|
||||
placement: sequence-item
|
||||
`)
|
||||
writeImportFile(t, directory, "item.yml", `configkit:
|
||||
imports:
|
||||
- path: b-parent.yml
|
||||
- path: c-independent.yml
|
||||
id: item
|
||||
`)
|
||||
writeImportFile(t, directory, "b-parent.yml", "configkit: {imports: [{path: a-dependency.yml}]}\nid: b\n")
|
||||
writeImportFile(t, directory, "a-dependency.yml", "id: a\n")
|
||||
writeImportFile(t, directory, "c-independent.yml", "id: c\n")
|
||||
loadError := requireLoadCode(t, File(mainPath), Options[importTestConfig]{Imports: true}, CodeComposeConflict)
|
||||
diagnostic := loadError.Diagnostics()[0]
|
||||
if diagnostic.Path.String() != "/items/0/id" || diagnostic.Primary == nil || diagnostic.Primary.SourceID != "source-4" {
|
||||
t.Fatalf("item helper conflict = %#v", diagnostic)
|
||||
}
|
||||
wantRelated := map[string]bool{"source-3": false, "source-5": false, "source-2": false}
|
||||
if len(diagnostic.Related) != len(wantRelated) {
|
||||
t.Fatalf("related sites = %#v", diagnostic.Related)
|
||||
}
|
||||
for _, site := range diagnostic.Related {
|
||||
if _, expected := wantRelated[site.SourceID]; !expected {
|
||||
t.Errorf("unexpected related site source %q", site.SourceID)
|
||||
}
|
||||
wantRelated[site.SourceID] = true
|
||||
}
|
||||
for sourceID, found := range wantRelated {
|
||||
if !found {
|
||||
t.Errorf("related sites do not include %q", sourceID)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("selected main item dependencies", func(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", "configkit: {imports: [{path: helper.yml}]}\nid: main\n")
|
||||
writeImportFile(t, directory, "helper.yml", "id: helper\n")
|
||||
options := Options[importTestConfig]{
|
||||
Imports: true, destination: Keys("items"), placementMode: placementModeSequenceItem,
|
||||
}
|
||||
loadError := requireLoadCode(t, File(mainPath), options, CodeComposeConflict)
|
||||
diagnostic := loadError.Diagnostics()[0]
|
||||
if diagnostic.Path.String() != "/items/0/id" || diagnostic.Primary == nil || diagnostic.Primary.SourceID != "source-2" || len(diagnostic.Related) != 1 || diagnostic.Related[0].SourceID != "source-1" {
|
||||
t.Fatalf("main item helper conflict = %#v", diagnostic)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestItemHelperScopeScheduleInterleavesUnequalBranches(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
imports:
|
||||
- path: item.yml
|
||||
destination: [items]
|
||||
placement: sequence-item
|
||||
`)
|
||||
writeImportFile(t, directory, "item.yml", "configkit: {imports: [{path: b-parent.yml}, {path: c-independent.yml}]}\nitem: true\n")
|
||||
writeImportFile(t, directory, "b-parent.yml", "configkit: {imports: [{path: a-dependency.yml}]}\nb: true\n")
|
||||
writeImportFile(t, directory, "a-dependency.yml", "a: true\n")
|
||||
writeImportFile(t, directory, "c-independent.yml", "c: true\n")
|
||||
input, diagnostics := assembleBaseInput[importTestConfig](File(mainPath), Options[importTestConfig]{Imports: true})
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatalf("assemble item scope: %#v", diagnostics)
|
||||
}
|
||||
var nested *composedDocument
|
||||
for _, contribution := range input.composition.acquisition[0].contributions {
|
||||
if contribution.role == importRoleItem {
|
||||
nested = contribution.nested
|
||||
break
|
||||
}
|
||||
}
|
||||
if nested == nil || len(nested.acquisition) != 1 {
|
||||
t.Fatalf("item composition = %#v", nested)
|
||||
}
|
||||
wantIDs := []string{"source-4", "source-3", "source-5", "source-2"}
|
||||
for index, want := range wantIDs {
|
||||
if got := nested.acquisition[0].contributions[index].source.ID; got != want {
|
||||
t.Errorf("local contribution %d = %q, want %q", index, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadImportsCanonicalSymlinksAndKeepsHardLinksDistinct(t *testing.T) {
|
||||
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
|
||||
t.Skip("initial filesystem contract covers Linux and macOS")
|
||||
|
||||
Reference in New Issue
Block a user