feat: rm guards (scope widening, merge targets), lint --clean and --suggest, v0.1.3
ci / release (push) Successful in 1m21s
ci / release (push) Successful in 1m21s
This commit is contained in:
@@ -379,6 +379,97 @@ suite "lint":
|
||||
check "error: schema.md:" in o
|
||||
check lastCode == 1
|
||||
|
||||
suite "rm guards":
|
||||
test "rm refuses to widen a preference scope (with and without cascade)":
|
||||
let d = freshDir()
|
||||
seed(d)
|
||||
discard run(d, "new", "p1", "preference")
|
||||
discard run(d, "new", "p2", "preference")
|
||||
discard run(d, "link", "p1", "applies-to", "a")
|
||||
discard run(d, "link", "p2", "applies-to", "a")
|
||||
discard run(d, "link", "p2", "applies-to", "b")
|
||||
for args in [@["rm", "a"], @["rm", "a", "--cascade"]]:
|
||||
let m = fails(d, args)
|
||||
check m.contains("widen") and m.contains(" p1") and not m.contains(" p2")
|
||||
check fileExists(d / "entities" / "a.md")
|
||||
# p2 still has b: removing b is fine; a preference removed itself is fine
|
||||
check run(d, "rm", "b", "--cascade").contains("removed entities/b.md")
|
||||
check run(d, "rm", "p1", "--cascade").contains("removed entities/p1.md")
|
||||
|
||||
test "rm refuses an entity that tombstones point to":
|
||||
let d = freshDir()
|
||||
seed(d)
|
||||
discard run(d, "merge", "a", "b")
|
||||
let m = fails(d, "rm", "b")
|
||||
check m.contains("tombstones point to it") and m.contains(" a -> b")
|
||||
check fileExists(d / "entities" / "b.md")
|
||||
|
||||
suite "lint --clean / --suggest":
|
||||
test "clean removes tombstones, redundant relates-to and part-of; prints changes":
|
||||
let d = freshDir()
|
||||
seed(d)
|
||||
discard run(d, "new", "t1", "concept")
|
||||
discard run(d, "new", "t2", "concept")
|
||||
discard run(d, "merge", "t1", "t2") # t1 -> t2 -> (t2 is live)
|
||||
discard run(d, "merge", "t2", "d") # t2 -> d, t1 -> t2
|
||||
discard run(d, "link", "a", "uses", "b")
|
||||
discard run(d, "link", "b", "relates-to", "a", "n")
|
||||
discard run(d, "new", "e", "concept")
|
||||
discard run(d, "link", "e", "relates-to", "d") # keep
|
||||
discard run(d, "link", "a", "part-of", "b")
|
||||
discard run(d, "link", "b", "part-of", "c")
|
||||
discard run(d, "link", "a", "part-of", "c") # redundant
|
||||
discard run(d, "link", "a", "part-of", "d") # redundant (a>b>c>d below)
|
||||
discard run(d, "link", "c", "part-of", "d")
|
||||
let o = run(d, "lint", "--clean")
|
||||
check "removed relation a relates-to b # n (pair already linked by a typed verb)" in o
|
||||
check "removed relation a part-of c (implied by a part-of chain)" in o
|
||||
check "removed relation a part-of d (implied by a part-of chain)" in o
|
||||
check "removed tombstone entities/t1.md" in o
|
||||
check "removed tombstone entities/t2.md" in o
|
||||
check not fileExists(d / "entities" / "t1.md") and not fileExists(d / "entities" / "t2.md")
|
||||
check "d\trelates-to\te" in relsText(d) # kept
|
||||
check relsText(d).count("part-of") == 3
|
||||
check "0 errors" in o and lastCode == 0
|
||||
check run(d, "lint", "--clean").startsWith("nothing to clean")
|
||||
|
||||
test "clean keeps referenced tombstones":
|
||||
let d = freshDir()
|
||||
seed(d)
|
||||
discard run(d, "merge", "a", "b")
|
||||
writeFile(d / "relations.tsv", "a\tuses\tc\n")
|
||||
check run(d, "lint", "--clean").startsWith("nothing to clean")
|
||||
check fileExists(d / "entities" / "a.md")
|
||||
|
||||
test "suggest lists candidates read-only; clean + suggest combine":
|
||||
let d = freshDir()
|
||||
seed(d)
|
||||
discard run(d, "new", "old", "concept")
|
||||
discard run(d, "new", "mid", "concept")
|
||||
discard run(d, "new", "new1", "concept")
|
||||
discard run(d, "link", "new1", "supersedes", "mid")
|
||||
discard run(d, "link", "mid", "supersedes", "old")
|
||||
discard run(d, "link", "a", "contradicts", "b")
|
||||
discard run(d, "new", "foo-bar", "concept", "Foo Bar")
|
||||
discard run(d, "new", "fb", "concept", "fb")
|
||||
discard run(d, "alias", "fb", "foo_bar")
|
||||
discard run(d, "new", "pref", "preference") # everywhere: not an orphan
|
||||
let before = relsText(d)
|
||||
let o = run(d, "lint", "--suggest")
|
||||
check "[superseded] mid is superseded by new1 -> rm mid" in o
|
||||
check "[superseded] old is superseded by new1 -> rm old" in o
|
||||
check "[contradicted] a contradicts b (b is the older statement) -> supersede or rm b" in o
|
||||
check "[duplicate]" in o and "merge " in o and "'foobar'" in o
|
||||
check "[orphan] c has no relations -> rm or link c" in o
|
||||
check "orphan] pref" notin o
|
||||
check "1. " in o and "2. " in o
|
||||
check relsText(d) == before
|
||||
let o2 = run(d, "lint", "--clean", "--suggest")
|
||||
check o2.startsWith("nothing to clean") and "suggestions:" in o2
|
||||
let d2 = freshDir()
|
||||
check run(d2, "lint", "--suggest").endsWith("no suggestions")
|
||||
check fails(d2, "lint", "--bogus").contains("usage")
|
||||
|
||||
suite "cli":
|
||||
test "help, version, missing dir, unknown command (binary)":
|
||||
let exe = getCurrentDir() / "bin" / "sirmem"
|
||||
|
||||
Reference in New Issue
Block a user