71 lines
3.2 KiB
Go
71 lines
3.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
|
)
|
|
|
|
func TestDestinationProbesPreserveCacheAndCleanUp(t *testing.T) {
|
|
root := t.TempDir()
|
|
output, cache := filepath.Join(root, "output"), filepath.Join(root, "cache")
|
|
if err := os.Mkdir(cache, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
entry := filepath.Join(cache, "accepted.json")
|
|
if err := os.WriteFile(entry, []byte(`{"accepted":true}`), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
resolved := pipeline.ResolvedPipeline{ChunkExecutionClass: contracts.ExecutionClassLLMBacked}
|
|
for _, mode := range []contracts.CacheMode{contracts.CacheAuto, contracts.CacheRefresh} {
|
|
resolved.ChunkControls.Cache = mode
|
|
if outputErr, cacheErr := probePipelineDestinations(output, cache, resolved); outputErr != nil || cacheErr != nil {
|
|
t.Fatalf("%s: output %v, cache %v", mode, outputErr, cacheErr)
|
|
}
|
|
content, err := os.ReadFile(entry)
|
|
if err != nil || string(content) != `{"accepted":true}` {
|
|
t.Fatalf("cache entry = %q, %v", content, err)
|
|
}
|
|
entries, err := os.ReadDir(cache)
|
|
if err != nil || len(entries) != 1 {
|
|
t.Fatalf("cache directory = %v, %v", entries, err)
|
|
}
|
|
entries, err = os.ReadDir(output)
|
|
if err != nil || len(entries) != 0 {
|
|
t.Fatalf("output directory = %v, %v", entries, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDestinationProbesDistinguishRequiredAndOptionalAccess(t *testing.T) {
|
|
root := t.TempDir()
|
|
file := filepath.Join(root, "file")
|
|
if err := os.WriteFile(file, []byte("x"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
bad := filepath.Join(file, "child")
|
|
resolved := pipeline.ResolvedPipeline{ChunkExecutionClass: contracts.ExecutionClassLLMBacked, ChunkControls: contracts.ProducerControls{Cache: contracts.CacheAuto}}
|
|
if outputErr, cacheErr := probePipelineDestinations(bad, bad, resolved); outputErr == nil || cacheErr != nil {
|
|
t.Fatalf("output=%v cache=%v", outputErr, cacheErr)
|
|
}
|
|
if outputErr, cacheErr := probePipelineDestinations(filepath.Join(root, "output"), bad, resolved); outputErr != nil || cacheErr == nil {
|
|
t.Fatalf("output=%v cache=%v", outputErr, cacheErr)
|
|
}
|
|
resolved.ChunkControls.Cache = contracts.CacheBypass
|
|
if outputErr, cacheErr := probePipelineDestinations(filepath.Join(root, "output"), bad, resolved); outputErr != nil || cacheErr != nil {
|
|
t.Fatalf("bypass: output=%v cache=%v", outputErr, cacheErr)
|
|
}
|
|
resolved.ChunkControls.Cache = contracts.CacheAuto
|
|
resolved.ChunkExecutionClass = contracts.ExecutionClassDeterministic
|
|
if outputErr, cacheErr := probePipelineDestinations(filepath.Join(root, "output"), bad, resolved); outputErr != nil || cacheErr != nil {
|
|
t.Fatalf("deterministic: output=%v cache=%v", outputErr, cacheErr)
|
|
}
|
|
resolved.Steps = []pipeline.ResolvedPipelineStep{{ArtifactLanes: []pipeline.ResolvedArtifactLane{{NormalizeExecutionClass: contracts.ExecutionClassLLMBacked, NormalizeControls: contracts.ProducerControls{Cache: contracts.CacheRefresh}}}}}
|
|
if outputErr, cacheErr := probePipelineDestinations(filepath.Join(root, "output"), bad, resolved); outputErr != nil || cacheErr == nil {
|
|
t.Fatalf("selected model lane: output=%v cache=%v", outputErr, cacheErr)
|
|
}
|
|
}
|