Allow absent inputs to use import contexts

This commit is contained in:
2026-10-24 15:55:10 +00:00
parent 2f0900535d
commit 53ce6c63d8
13 changed files with 176 additions and 31 deletions

View File

@@ -539,6 +539,41 @@ func TestSourceVersionNoSourceMainRetainsAbsentCallback(t *testing.T) {
if !called || len(result.diagnostics) != 0 || result.evidence != nil || result.payload != nil {
t.Fatalf("NoSource result = %#v, callback called = %v", result, called)
}
type config struct{}
for _, reject := range []bool{false, true} {
called = false
definition := Definition[config]{Version: &VersionRule{
Path: Keys("version"),
Check: func(version Version, _ *Validation) error {
called = true
if version != (Version{}) {
t.Errorf("NoSource load version = %#v", version)
}
if reject {
return errors.New("rejected absent main")
}
return nil
},
}}
loaded, loadErr := testLoad(NoSource(), Options[config]{
Definition: definition, Imports: true, SourceVersionMode: test.mode,
})
if !called {
t.Fatal("NoSource load did not call the source-version checker")
}
if reject {
var failure *LoadError
if !errors.As(loadErr, &failure) {
t.Fatalf("rejected NoSource load = %v, want *LoadError", loadErr)
}
requireSourceVersionDiagnostic(t, failure.Diagnostics(), CodeVersionHookFailed, "/version")
continue
}
if loadErr != nil || loaded == nil || len(loaded.Sources()) != 0 {
t.Fatalf("accepted NoSource load = %#v, %v", loaded, loadErr)
}
}
})
}
}