fetch_ml/internal/worker/artifacts.go
Jeremie Fraeys 3b194ff2e8
Some checks failed
Build CLI with Embedded SQLite / build (arm64, aarch64-linux) (push) Waiting to run
Build CLI with Embedded SQLite / build (x86_64, x86_64-linux) (push) Waiting to run
Build CLI with Embedded SQLite / build-macos (arm64) (push) Waiting to run
Build CLI with Embedded SQLite / build-macos (x86_64) (push) Waiting to run
Security Scan / Security Analysis (push) Waiting to run
Security Scan / Native Library Security (push) Waiting to run
Checkout test / test (push) Successful in 6s
CI/CD Pipeline / Test (push) Failing after 1s
CI/CD Pipeline / Dev Compose Smoke Test (push) Has been skipped
CI/CD Pipeline / Build (push) Has been skipped
CI/CD Pipeline / Test Scripts (push) Has been skipped
CI/CD Pipeline / Test Native Libraries (push) Has been skipped
CI/CD Pipeline / GPU Golden Test Matrix (push) Has been skipped
Documentation / build-and-publish (push) Failing after 39s
CI/CD Pipeline / Docker Build (push) Has been skipped
feat: GPU detection transparency and artifact scanner improvements
- Surface GPUDetectionInfo from parseGPUCountFromConfig for detection metadata
- Document FETCH_ML_TOTAL_CPU and FETCH_ML_GPU_SLOTS_PER_GPU env vars
- Add debug logging for all env var overrides to stderr
- Track config-layer auto-detection in GPUDetectionInfo.ConfigLayerAutoDetected
- Add --include-all flag to artifact scanner (includeAll parameter)
- Add AMD production mode enforcement (error in non-local mode)
- Add GPU detector unit tests for env overrides and AMD aliasing
2026-02-23 12:29:34 -05:00

108 lines
2.1 KiB
Go

package worker
import (
"fmt"
"io/fs"
"path/filepath"
"sort"
"strings"
"time"
"github.com/jfraeys/fetch_ml/internal/manifest"
)
func scanArtifacts(runDir string, includeAll bool) (*manifest.Artifacts, error) {
runDir = strings.TrimSpace(runDir)
if runDir == "" {
return nil, fmt.Errorf("run dir is empty")
}
var files []manifest.ArtifactFile
var total int64
now := time.Now().UTC()
err := filepath.WalkDir(runDir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if path == runDir {
return nil
}
rel, err := filepath.Rel(runDir, path)
if err != nil {
return err
}
rel = filepath.ToSlash(rel)
// Standard exclusions (always apply)
if rel == manifestFilename {
return nil
}
if strings.HasSuffix(rel, "/"+manifestFilename) {
return nil
}
// Optional exclusions (skipped when includeAll is true)
if !includeAll {
if rel == "code" || strings.HasPrefix(rel, "code/") {
if d.IsDir() {
return fs.SkipDir
}
return nil
}
if rel == "snapshot" || strings.HasPrefix(rel, "snapshot/") {
if d.IsDir() {
return fs.SkipDir
}
return nil
}
if strings.HasSuffix(rel, ".log") {
return nil
}
if d.Type()&fs.ModeSymlink != 0 {
return nil
}
}
if d.IsDir() {
return nil
}
info, err := d.Info()
if err != nil {
return err
}
files = append(files, manifest.ArtifactFile{
Path: rel,
SizeBytes: info.Size(),
Modified: info.ModTime().UTC(),
})
total += info.Size()
return nil
})
if err != nil {
return nil, err
}
sort.Slice(files, func(i, j int) bool {
return files[i].Path < files[j].Path
})
return &manifest.Artifacts{
DiscoveryTime: now,
Files: files,
TotalSizeBytes: total,
}, nil
}
const manifestFilename = "run_manifest.json"
// ScanArtifacts is an exported wrapper for testing/benchmarking.
// When includeAll is false, excludes code/, snapshot/, *.log files, and symlinks.
func ScanArtifacts(runDir string, includeAll bool) (*manifest.Artifacts, error) {
return scanArtifacts(runDir, includeAll)
}