Go 64 lines
package workflow
import (
"path/filepath"
"testing"
)
func TestCommentHygiene_CleanTree(t *testing.T) {
cfg := newCfg(t)
writeRepoFile(t, cfg.RepoRoot, "main.go", "package main\nfunc main(){}\n")
writeRepoFile(t, cfg.RepoRoot, "docs/readme.md", "a normal document\n")
res, err := commentHygiene{}.Run(Env{Config: cfg})
if err != nil {
t.Fatal(err)
}
if res.Code != CodeClean {
t.Fatalf("clean tree -> %d (%s) %+v", res.Code, res.Summary, res.Findings)
}
}
func TestCommentHygiene_FlagsFingerprint(t *testing.T) {
cfg := newCfg(t)
trailer := fragCoAB + ": Someone <[email protected]>"
writeRepoFile(t, cfg.RepoRoot, "src/util.go", "package src\n// "+"\n"+trailer+"\n")
res, err := commentHygiene{}.Run(Env{Config: cfg})
if err != nil {
t.Fatal(err)
}
if res.Code != CodeFinding {
t.Fatalf("planted fingerprint -> %d, want %d", res.Code, CodeFinding)
}
if len(res.Findings) != 1 || res.Findings[0].Path != "src/util.go" {
t.Fatalf("findings = %+v", res.Findings)
}
}
func TestCommentHygiene_SkipsWorkspace(t *testing.T) {
cfg := newCfg(t)
// A fingerprint inside the gitignored workspace must not gate the
// tracked tree (engine output is not shippable).
trailer := fragCoAB + ": Eng <e@x>"
writeRepoFile(t, cfg.RepoRoot, filepath.Join(".eeco", "state", "note.md"), trailer+"\n")
res, err := commentHygiene{}.Run(Env{Config: cfg})
if err != nil {
t.Fatal(err)
}
if res.Code != CodeClean {
t.Fatalf("workspace fingerprint leaked into gate: %+v", res.Findings)
}
}
func TestCommentHygiene_SkipsBinary(t *testing.T) {
cfg := newCfg(t)
trailer := fragCoAB + ": Bin <b@x>"
writeRepoFile(t, cfg.RepoRoot, "blob.bin", "\x00\x00"+trailer)
res, err := commentHygiene{}.Run(Env{Config: cfg})
if err != nil {
t.Fatal(err)
}
if res.Code != CodeClean {
t.Fatalf("binary file scanned: %+v", res.Findings)
}
}