Index manifest input candidates within each operation

This commit is contained in:
2026-12-02 21:49:40 +00:00
parent 6fb15b0094
commit f7a7afe12f
14 changed files with 108 additions and 37 deletions

View File

@@ -46,6 +46,11 @@ type PreparedInputIdentity struct {
// ResolvePreparedInput resolves a prepared stable source exclusively from its
// current manifest record and verifies the canonical file's identity.
func ResolvePreparedInput(paths SessionPaths, m *manifest.Manifest, sourceID string) (PreparedInputIdentity, error) {
return ResolvePreparedInputWithLookup(paths, NewInputLookup(paths, m), sourceID)
}
// ResolvePreparedInputWithLookup resolves a source against one input snapshot.
func ResolvePreparedInputWithLookup(paths SessionPaths, lookup *InputLookup, sourceID string) (PreparedInputIdentity, error) {
descriptor, ok := artifactpolicy.DescribePreparedInputSource(sourceID)
if !ok {
if sourceID == artifactpolicy.SourceInputGlossary {
@@ -59,27 +64,13 @@ func ResolvePreparedInput(paths SessionPaths, m *manifest.Manifest, sourceID str
return PreparedInputIdentity{}, err
}
matching := make([]manifest.InputRecord, 0, 1)
if m != nil {
for _, record := range m.Inputs {
if strings.TrimSpace(record.Kind) == descriptor.ManifestKind {
matching = append(matching, record)
}
}
}
matching := lookup.byKind[descriptor.ManifestKind]
if len(matching) == 0 {
if m != nil {
for _, record := range m.Inputs {
recordedPath, pathErr := resolvePreparedManifestPath(paths, record.Path, rootPath)
if pathErr == nil && recordedPath == canonicalPath {
return PreparedInputIdentity{}, fmt.Errorf(
"prepared input source %q canonical path is recorded with manifest kind %q, want %q",
descriptor.SourceID,
strings.TrimSpace(record.Kind),
descriptor.ManifestKind,
)
}
}
if records := lookup.byPath[canonicalPath]; len(records) > 0 {
return PreparedInputIdentity{}, fmt.Errorf(
"prepared input source %q canonical path is recorded with manifest kind %q, want %q",
descriptor.SourceID, strings.TrimSpace(records[0].Kind), descriptor.ManifestKind,
)
}
return PreparedInputIdentity{}, &PreparedInputAbsentError{SourceID: descriptor.SourceID}
}