package cli import ( "errors" "fmt" "os" "gitea.maximumdirect.net/eric/notarius/internal/framework/contracts" "gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline" ) // probeDestination checks practical write access without publishing an artifact. func probeDestination(root string, mode os.FileMode) error { if err := os.MkdirAll(root, mode); err != nil { return fmt.Errorf("create destination %q: %w", root, err) } file, err := os.CreateTemp(root, ".notarius-probe-*") if err != nil { return fmt.Errorf("create access probe in %q: %w", root, err) } _, writeErr := file.Write([]byte("probe")) closeErr := file.Close() removeErr := os.Remove(file.Name()) if err := errors.Join(writeErr, closeErr, removeErr); err != nil { return fmt.Errorf("access probe in %q: %w", root, err) } return nil } func pipelineUsesCache(resolved pipeline.ResolvedPipeline) bool { uses := func(class contracts.ExecutionClass, controls contracts.ProducerControls) bool { return class == contracts.ExecutionClassLLMBacked && controls.Cache != contracts.CacheBypass } if uses(resolved.ChunkExecutionClass, resolved.ChunkControls) { return true } for _, step := range resolved.Steps { for _, lane := range step.ArtifactLanes { if uses(lane.ExtractExecutionClass, lane.ExtractControls) || uses(lane.MergeExecutionClass, lane.MergeControls) || uses(lane.NormalizeExecutionClass, lane.NormalizeControls) { return true } } } return false } func probePipelineDestinations(outputRoot, cacheRoot string, resolved pipeline.ResolvedPipeline) (outputErr, cacheErr error) { outputErr = probeDestination(outputRoot, 0o755) if outputErr == nil && pipelineUsesCache(resolved) { cacheErr = probeDestination(cacheRoot, 0o777) } return outputErr, cacheErr }