feat: Add support for scanning GGUF models from OCI registries (#4335)

---------
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Christopher Angelo Phillips
2026-02-09 16:05:52 -05:00
committed by GitHub
co-authored by Alex Goodman
parent 3a23cfff1d
commit 2c5e193f7a
51 changed files with 6127 additions and 238 deletions
+43 -5
View File
@@ -13,16 +13,18 @@ import (
)
var _ Resolver = (*MockResolver)(nil)
var _ OCIMediaTypeResolver = (*MockResolver)(nil)
// MockResolver implements the FileResolver interface and is intended for use *only in test code*.
// It provides an implementation that can resolve local filesystem paths using only a provided discrete list of file
// paths, which are typically paths to test fixtures.
type MockResolver struct {
locations []Location
metadata map[Coordinates]Metadata
mimeTypeIndex map[string][]Location
extension map[string][]Location
basename map[string][]Location
locations []Location
metadata map[Coordinates]Metadata
mimeTypeIndex map[string][]Location
mediaTypeIndex map[string][]Location
extension map[string][]Location
basename map[string][]Location
}
// NewMockResolverForPaths creates a new MockResolver, where the only resolvable
@@ -72,6 +74,34 @@ func NewMockResolverForPathsWithMetadata(metadata map[Coordinates]Metadata) *Moc
}
}
// NewMockResolverForMediaTypes creates a MockResolver that can resolve files by media type.
// The mediaTypes map specifies which locations should be returned for each media type.
func NewMockResolverForMediaTypes(mediaTypes map[string][]Location) *MockResolver {
var locations []Location
mediaTypeIndex := make(map[string][]Location)
extension := make(map[string][]Location)
basename := make(map[string][]Location)
for mediaType, locs := range mediaTypes {
mediaTypeIndex[mediaType] = append(mediaTypeIndex[mediaType], locs...)
for _, l := range locs {
locations = append(locations, l)
ext := path.Ext(l.RealPath)
extension[ext] = append(extension[ext], l)
bn := path.Base(l.RealPath)
basename[bn] = append(basename[bn], l)
}
}
return &MockResolver{
locations: locations,
metadata: make(map[Coordinates]Metadata),
mediaTypeIndex: mediaTypeIndex,
extension: extension,
basename: basename,
}
}
// HasPath indicates if the given path exists in the underlying source.
func (r MockResolver) HasPath(path string) bool {
for _, l := range r.locations {
@@ -189,6 +219,14 @@ func (r MockResolver) FilesByMIMEType(types ...string) ([]Location, error) {
return locations, nil
}
func (r MockResolver) FilesByMediaType(types ...string) ([]Location, error) {
var locations []Location
for _, ty := range types {
locations = append(locations, r.mediaTypeIndex[ty]...)
}
return locations, nil
}
func (r MockResolver) FilesByExtension(extensions ...string) ([]Location, error) {
var results []Location
for _, ext := range extensions {