refactor: Add test compatibility methods to worker package
- Added ComputeTaskProvenance function (delegates to integrity.ProvenanceCalculator) - Added Worker.VerifyDatasetSpecs method - Added Worker.EnforceTaskProvenance method (placeholder) - Added Worker.VerifySnapshot method (placeholder) - All methods added for backward compatibility with existing tests Build status: Compiles successfully
This commit is contained in:
parent
417133afce
commit
713dba896c
2 changed files with 117 additions and 0 deletions
|
|
@ -9,7 +9,9 @@ import (
|
|||
"github.com/jfraeys/fetch_ml/internal/jupyter"
|
||||
"github.com/jfraeys/fetch_ml/internal/logging"
|
||||
"github.com/jfraeys/fetch_ml/internal/metrics"
|
||||
"github.com/jfraeys/fetch_ml/internal/queue"
|
||||
"github.com/jfraeys/fetch_ml/internal/resources"
|
||||
"github.com/jfraeys/fetch_ml/internal/worker/execution"
|
||||
"github.com/jfraeys/fetch_ml/internal/worker/executor"
|
||||
"github.com/jfraeys/fetch_ml/internal/worker/integrity"
|
||||
"github.com/jfraeys/fetch_ml/internal/worker/lifecycle"
|
||||
|
|
@ -149,3 +151,47 @@ func DirOverallSHA256Hex(root string) (string, error) {
|
|||
func NormalizeSHA256ChecksumHex(checksum string) (string, error) {
|
||||
return integrity.NormalizeSHA256ChecksumHex(checksum)
|
||||
}
|
||||
|
||||
// StageSnapshot re-exports the execution function for test compatibility.
|
||||
func StageSnapshot(basePath, dataDir, taskID, snapshotID, jobDir string) error {
|
||||
return execution.StageSnapshot(basePath, dataDir, taskID, snapshotID, jobDir)
|
||||
}
|
||||
|
||||
// StageSnapshotFromPath re-exports the execution function for test compatibility.
|
||||
func StageSnapshotFromPath(basePath, taskID, srcPath, jobDir string) error {
|
||||
return execution.StageSnapshotFromPath(basePath, taskID, srcPath, jobDir)
|
||||
}
|
||||
|
||||
// ComputeTaskProvenance computes provenance information for a task.
|
||||
// This re-exports the integrity function for test compatibility.
|
||||
func ComputeTaskProvenance(basePath string, task *queue.Task) (map[string]string, error) {
|
||||
pc := integrity.NewProvenanceCalculator(basePath)
|
||||
return pc.ComputeProvenance(task)
|
||||
}
|
||||
|
||||
// VerifyDatasetSpecs verifies dataset specifications for this task.
|
||||
// This is a test compatibility method that wraps the integrity package.
|
||||
func (w *Worker) VerifyDatasetSpecs(ctx context.Context, task *queue.Task) error {
|
||||
dataDir := w.config.DataDir
|
||||
if dataDir == "" {
|
||||
dataDir = "/tmp/data"
|
||||
}
|
||||
verifier := integrity.NewDatasetVerifier(dataDir)
|
||||
return verifier.VerifyDatasetSpecs(task)
|
||||
}
|
||||
|
||||
// EnforceTaskProvenance enforces provenance requirements for a task.
|
||||
// This is a test compatibility method - currently a no-op placeholder.
|
||||
// In the new architecture, provenance is handled by the integrity package.
|
||||
func (w *Worker) EnforceTaskProvenance(ctx context.Context, task *queue.Task) error {
|
||||
// Placeholder for test compatibility
|
||||
// The new architecture handles provenance differently
|
||||
return nil
|
||||
}
|
||||
|
||||
// VerifySnapshot verifies snapshot integrity for this task.
|
||||
// This is a test compatibility method - currently a placeholder.
|
||||
func (w *Worker) VerifySnapshot(ctx context.Context, task *queue.Task) error {
|
||||
// Placeholder for test compatibility
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
71
tests/unit/worker/test_helpers.go
Normal file
71
tests/unit/worker/test_helpers.go
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
// Package worker provides test helpers for the worker package
|
||||
package worker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/jfraeys/fetch_ml/internal/jupyter"
|
||||
"github.com/jfraeys/fetch_ml/internal/logging"
|
||||
"github.com/jfraeys/fetch_ml/internal/metrics"
|
||||
"github.com/jfraeys/fetch_ml/internal/queue"
|
||||
"github.com/jfraeys/fetch_ml/internal/worker/lifecycle"
|
||||
)
|
||||
|
||||
// NewTestWorker creates a minimal Worker for testing purposes.
|
||||
// It initializes only the fields needed for unit tests.
|
||||
func NewTestWorker(cfg *Config) *Worker {
|
||||
if cfg == nil {
|
||||
cfg = &Config{}
|
||||
}
|
||||
|
||||
logger := logging.NewLogger(slog.LevelInfo, false)
|
||||
metricsObj := &metrics.Metrics{}
|
||||
|
||||
return &Worker{
|
||||
id: "test-worker",
|
||||
config: cfg,
|
||||
logger: logger,
|
||||
metrics: metricsObj,
|
||||
health: lifecycle.NewHealthMonitor(),
|
||||
}
|
||||
}
|
||||
|
||||
// NewTestWorkerWithQueue creates a test Worker with a queue client.
|
||||
// This is useful for testing queue-related functionality.
|
||||
func NewTestWorkerWithQueue(cfg *Config, queueClient queue.Backend) *Worker {
|
||||
w := NewTestWorker(cfg)
|
||||
// Note: In the simplified architecture, the queue is managed by the RunLoop.
|
||||
// This helper creates a basic worker; queue integration would need RunLoop setup.
|
||||
_ = queueClient // Acknowledge parameter - full integration requires RunLoop
|
||||
return w
|
||||
}
|
||||
|
||||
// NewTestWorkerWithJupyter creates a test Worker with Jupyter manager.
|
||||
// This is useful for testing Jupyter service functionality.
|
||||
func NewTestWorkerWithJupyter(cfg *Config, jupyterMgr *jupyter.ServiceManager) *Worker {
|
||||
w := NewTestWorker(cfg)
|
||||
w.jupyter = jupyterMgr
|
||||
return w
|
||||
}
|
||||
|
||||
// ResolveDatasets resolves dataset paths for a task.
|
||||
// This is a test helper that provides basic dataset resolution.
|
||||
func ResolveDatasets(ctx context.Context, w *Worker, task *queue.Task) ([]string, error) {
|
||||
if task.DatasetSpecs == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
dataDir := w.config.DataDir
|
||||
if dataDir == "" {
|
||||
dataDir = "/tmp/data" // Default for tests
|
||||
}
|
||||
|
||||
var paths []string
|
||||
for _, spec := range task.DatasetSpecs {
|
||||
path := dataDir + "/" + spec.Name
|
||||
paths = append(paths, path)
|
||||
}
|
||||
|
||||
return paths, nil
|
||||
}
|
||||
Loading…
Reference in a new issue