Simplify manual cleaning to directory targets
This commit is contained in:
@@ -41,10 +41,10 @@ their scope. Unless assigned otherwise, a finding remains independent audit
|
|||||||
remediation. Shared code does not make a refactoring a prerequisite or assign
|
remediation. Shared code does not make a refactoring a prerequisite or assign
|
||||||
the whole finding to a roadmap.
|
the whole finding to a roadmap.
|
||||||
|
|
||||||
Twenty-five entries are closed by the safety, transfer, audio discovery, S3
|
Twenty-six entries are closed by the safety, transfer, audio discovery, S3
|
||||||
planning, prerequisite-history, publication-import, CLI classification,
|
planning, prerequisite-history, publication-import, CLI classification,
|
||||||
inspection aggregation, test maintenance, dead-code removal, and associated
|
inspection aggregation, test maintenance, dead-code removal, and associated
|
||||||
documentation work; 18 remain open. **Planned** identifies
|
documentation work; 17 remain open. **Planned** identifies
|
||||||
an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending
|
an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending
|
||||||
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
|
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
|
||||||
that a related feature implements the entire finding. Findings close only after their
|
that a related feature implements the entire finding. Findings close only after their
|
||||||
@@ -946,7 +946,10 @@ configuration descriptor is needed.
|
|||||||
|
|
||||||
### CAT-39 — P3: Simplify manual clean to its live directory-only contract
|
### CAT-39 — P3: Simplify manual clean to its live directory-only contract
|
||||||
|
|
||||||
Status: Open
|
Status: Closed
|
||||||
|
|
||||||
|
**Closure.** Manual clean now validates directories through one entry point;
|
||||||
|
focused clean, cleanup, confinement, and lock tests pass.
|
||||||
|
|
||||||
Original findings: [DD-04](12-deadcode.md#dd-04--p3-manual-cleaning-retains-a-file-target-mode-unavailable-through-its-cli).
|
Original findings: [DD-04](12-deadcode.md#dd-04--p3-manual-cleaning-retains-a-file-target-mode-unavailable-through-its-cli).
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ Validation: `go test ./internal/config ./internal/artifacts ./internal/app ./int
|
|||||||
|
|
||||||
## Stage 4: Make Manual Clean Explicitly Directory-Oriented
|
## Stage 4: Make Manual Clean Explicitly Directory-Oriented
|
||||||
|
|
||||||
CAT IDs: CAT-39. Status: Pending.
|
CAT IDs: CAT-39. Status: Complete.
|
||||||
|
|
||||||
Read [DD-04](audit/12-deadcode.md#dd-04--p3-manual-cleaning-retains-a-file-target-mode-unavailable-through-its-cli).
|
Read [DD-04](audit/12-deadcode.md#dd-04--p3-manual-cleaning-retains-a-file-target-mode-unavailable-through-its-cli).
|
||||||
Inspect `app/clean_command.go`, `clean.go`, `cleanup_targets.go`, and their tests.
|
Inspect `app/clean_command.go`, `clean.go`, `cleanup_targets.go`, and their tests.
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
func validateScopedFile(root, target, policy string) (scopedDir, error) {
|
|
||||||
return validateScopedTarget(root, target, policy, false)
|
|
||||||
}
|
|
||||||
@@ -93,16 +93,16 @@ func cleanSelectedSession(ctx context.Context, input *cleanCommandInput, deps co
|
|||||||
}
|
}
|
||||||
defer func() { err = errors.Join(err, store.ReleaseWorkspaceLock(lock)) }()
|
defer func() { err = errors.Join(err, store.ReleaseWorkspaceLock(lock)) }()
|
||||||
}
|
}
|
||||||
appendTarget := func(root, target, policy string, directory bool) error {
|
appendTarget := func(root, target, policy string) error {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
action, err := cleanScopedTarget(root, target, policy, directory, input.DryRun)
|
action, err := cleanScopedTarget(root, target, policy, input.DryRun)
|
||||||
report.Actions = append(report.Actions, action)
|
report.Actions = append(report.Actions, action)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if input.All {
|
if input.All {
|
||||||
if err := appendTarget(pipeline.Workspace.Root, filepath.Join(pipeline.Workspace.Root, config.PathWorkDirSegment), "clean.workspace.all", true); err != nil {
|
if err := appendTarget(pipeline.Workspace.Root, filepath.Join(pipeline.Workspace.Root, config.PathWorkDirSegment), "clean.workspace.all"); err != nil {
|
||||||
return report, err
|
return report, err
|
||||||
}
|
}
|
||||||
return report, nil
|
return report, nil
|
||||||
@@ -114,15 +114,15 @@ func cleanSelectedSession(ctx context.Context, input *cleanCommandInput, deps co
|
|||||||
report.Campaign = cfg.Session.Campaign
|
report.Campaign = cfg.Session.Campaign
|
||||||
report.SessionID = cfg.Session.SessionID
|
report.SessionID = cfg.Session.SessionID
|
||||||
work := artifacts.SessionWorkDirForCampaign(pipeline.Workspace.Root, report.Campaign, report.SessionID)
|
work := artifacts.SessionWorkDirForCampaign(pipeline.Workspace.Root, report.Campaign, report.SessionID)
|
||||||
if err := appendTarget(pipeline.Workspace.Root, work, "clean.workspace.session", true); err != nil {
|
if err := appendTarget(pipeline.Workspace.Root, work, "clean.workspace.session"); err != nil {
|
||||||
return report, err
|
return report, err
|
||||||
}
|
}
|
||||||
return report, nil
|
return report, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanScopedTarget(root, target, policy string, directory, dryRun bool) (cleanAction, error) {
|
func cleanScopedTarget(root, target, policy string, dryRun bool) (cleanAction, error) {
|
||||||
action := cleanAction{Path: target, Status: "failed"}
|
action := cleanAction{Path: target, Status: "failed"}
|
||||||
scoped, err := validateScopedTarget(root, target, policy, directory)
|
scoped, err := validateScopedDir(root, target, policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
action.Error = err.Error()
|
action.Error = err.Error()
|
||||||
return action, err
|
return action, err
|
||||||
|
|||||||
@@ -116,22 +116,22 @@ func TestCleanRequiresSessionID(t *testing.T) {
|
|||||||
func TestCleanRejectsUnsafeTargets(t *testing.T) {
|
func TestCleanRejectsUnsafeTargets(t *testing.T) {
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
outside := t.TempDir()
|
outside := t.TempDir()
|
||||||
if _, err := cleanScopedTarget(root, filepath.Join(outside, "target"), "test.outside", true, false); err == nil {
|
if _, err := cleanScopedTarget(root, filepath.Join(outside, "target"), "test.outside", false); err == nil {
|
||||||
t.Fatal("outside target error = nil, want error")
|
t.Fatal("outside target error = nil, want error")
|
||||||
}
|
}
|
||||||
if _, err := cleanScopedTarget(root, root, "test.root", true, false); err == nil {
|
if _, err := cleanScopedTarget(root, root, "test.root", false); err == nil {
|
||||||
t.Fatal("root target error = nil, want error")
|
t.Fatal("root target error = nil, want error")
|
||||||
}
|
}
|
||||||
filePath := filepath.Join(root, "file.txt")
|
filePath := filepath.Join(root, "file.txt")
|
||||||
mustWriteTestFile(t, filePath, "file")
|
mustWriteTestFile(t, filePath, "file")
|
||||||
if _, err := cleanScopedTarget(root, filePath, "test.file", true, false); err == nil {
|
if _, err := cleanScopedTarget(root, filePath, "test.file", false); err == nil {
|
||||||
t.Fatal("file target error = nil, want error")
|
t.Fatal("file target error = nil, want error")
|
||||||
}
|
}
|
||||||
symlinkPath := filepath.Join(root, "link")
|
symlinkPath := filepath.Join(root, "link")
|
||||||
if err := os.Symlink(filepath.Join(root, "missing"), symlinkPath); err != nil {
|
if err := os.Symlink(filepath.Join(root, "missing"), symlinkPath); err != nil {
|
||||||
t.Fatalf("Symlink() error = %v", err)
|
t.Fatalf("Symlink() error = %v", err)
|
||||||
}
|
}
|
||||||
if _, err := cleanScopedTarget(root, symlinkPath, "test.symlink", true, false); err == nil {
|
if _, err := cleanScopedTarget(root, symlinkPath, "test.symlink", false); err == nil {
|
||||||
t.Fatal("symlink target error = nil, want error")
|
t.Fatal("symlink target error = nil, want error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ type scopedDir struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateScopedDir(root, target, policy string) (scopedDir, error) {
|
func validateScopedDir(root, target, policy string) (scopedDir, error) {
|
||||||
return validateScopedTarget(root, target, policy, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateScopedTarget(root, target, policy string, requireDir bool) (scopedDir, error) {
|
|
||||||
cleanRoot := strings.TrimSpace(root)
|
cleanRoot := strings.TrimSpace(root)
|
||||||
cleanTarget := strings.TrimSpace(target)
|
cleanTarget := strings.TrimSpace(target)
|
||||||
if cleanRoot == "" {
|
if cleanRoot == "" {
|
||||||
@@ -57,11 +53,8 @@ func validateScopedTarget(root, target, policy string, requireDir bool) (scopedD
|
|||||||
if info.Mode()&os.ModeSymlink != 0 {
|
if info.Mode()&os.ModeSymlink != 0 {
|
||||||
return scopedDir{}, fmt.Errorf("cleanup policy %s: refusing to delete symlink path %q", policy, targetAbs)
|
return scopedDir{}, fmt.Errorf("cleanup policy %s: refusing to delete symlink path %q", policy, targetAbs)
|
||||||
}
|
}
|
||||||
if requireDir && !info.IsDir() {
|
if !info.IsDir() {
|
||||||
return scopedDir{}, fmt.Errorf("cleanup policy %s: target %q is not a directory", policy, targetAbs)
|
return scopedDir{}, fmt.Errorf("cleanup policy %s: target %q is not a directory", policy, targetAbs)
|
||||||
}
|
}
|
||||||
if !requireDir && info.IsDir() {
|
|
||||||
return scopedDir{}, fmt.Errorf("cleanup policy %s: target %q is a directory", policy, targetAbs)
|
|
||||||
}
|
|
||||||
return scopedDir{RootAbs: rootAbs, TargetAbs: targetAbs, Exists: true}, nil
|
return scopedDir{RootAbs: rootAbs, TargetAbs: targetAbs, Exists: true}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,26 +7,16 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCleanValidateScopedDirAndFile(t *testing.T) {
|
func TestCleanValidateScopedDir(t *testing.T) {
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
dirTarget := filepath.Join(root, "runs", "run-1")
|
dirTarget := filepath.Join(root, "runs", "run-1")
|
||||||
fileTarget := filepath.Join(root, "cache", "a.flac")
|
|
||||||
if err := os.MkdirAll(dirTarget, 0o755); err != nil {
|
if err := os.MkdirAll(dirTarget, 0o755); err != nil {
|
||||||
t.Fatalf("MkdirAll(dirTarget) error = %v", err)
|
t.Fatalf("MkdirAll(dirTarget) error = %v", err)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(filepath.Dir(fileTarget), 0o755); err != nil {
|
|
||||||
t.Fatalf("MkdirAll(file parent) error = %v", err)
|
|
||||||
}
|
|
||||||
if err := os.WriteFile(fileTarget, []byte("audio"), 0o644); err != nil {
|
|
||||||
t.Fatalf("WriteFile(fileTarget) error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := validateScopedDir(root, dirTarget, "test.dir"); err != nil {
|
if _, err := validateScopedDir(root, dirTarget, "test.dir"); err != nil {
|
||||||
t.Fatalf("validateScopedDir() error = %v", err)
|
t.Fatalf("validateScopedDir() error = %v", err)
|
||||||
}
|
}
|
||||||
if _, err := validateScopedFile(root, fileTarget, "test.file"); err != nil {
|
|
||||||
t.Fatalf("validateScopedFile() error = %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCleanValidateScopedTargetSafetyRules(t *testing.T) {
|
func TestCleanValidateScopedTargetSafetyRules(t *testing.T) {
|
||||||
@@ -57,9 +47,6 @@ func TestCleanValidateScopedTargetSafetyRules(t *testing.T) {
|
|||||||
if _, err := validateScopedDir(root, fileTarget, "test.file-as-dir"); err == nil || !strings.Contains(err.Error(), "is not a directory") {
|
if _, err := validateScopedDir(root, fileTarget, "test.file-as-dir"); err == nil || !strings.Contains(err.Error(), "is not a directory") {
|
||||||
t.Fatalf("validateScopedDir(file) error = %v, want not-a-directory rejection", err)
|
t.Fatalf("validateScopedDir(file) error = %v, want not-a-directory rejection", err)
|
||||||
}
|
}
|
||||||
if _, err := validateScopedFile(root, target, "test.dir-as-file"); err == nil || !strings.Contains(err.Error(), "is a directory") {
|
|
||||||
t.Fatalf("validateScopedFile(dir) error = %v, want is-a-directory rejection", err)
|
|
||||||
}
|
|
||||||
if _, err := validateScopedDir(root, symlinkTarget, "test.symlink"); err == nil || !strings.Contains(err.Error(), "refusing to delete symlink path") {
|
if _, err := validateScopedDir(root, symlinkTarget, "test.symlink"); err == nil || !strings.Contains(err.Error(), "refusing to delete symlink path") {
|
||||||
t.Fatalf("validateScopedDir(symlink) error = %v, want symlink rejection", err)
|
t.Fatalf("validateScopedDir(symlink) error = %v, want symlink rejection", err)
|
||||||
}
|
}
|
||||||
@@ -75,13 +62,4 @@ func TestCleanValidateScopedTargetMissing(t *testing.T) {
|
|||||||
if got.Exists {
|
if got.Exists {
|
||||||
t.Fatalf("validateScopedDir(missing).Exists = true, want false")
|
t.Fatalf("validateScopedDir(missing).Exists = true, want false")
|
||||||
}
|
}
|
||||||
|
|
||||||
missingFile := filepath.Join(root, "cache", "missing.flac")
|
|
||||||
got, err = validateScopedFile(root, missingFile, "test.missing.file")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("validateScopedFile(missing) error = %v", err)
|
|
||||||
}
|
|
||||||
if got.Exists {
|
|
||||||
t.Fatalf("validateScopedFile(missing).Exists = true, want false")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user