Commit 5e2f436
authored
* fix(cli): prune the hash registry by file_hash so `openkb remove` drops legacy entries
`HashRegistry.remove_by_doc_name` matched on
`meta.get("doc_name") == doc_name`. Registry rows ingested before
commit c504e26 carry only `{name, type}` — no `doc_name` key — so the
comparison was always `None == "<slug>"` and the method silently
returned False. The CLI never checked the return value, leaving an
orphan hash in `hashes.json` that then re-bound the next `openkb add`
of the same file via PageIndex / SHA dedup.
Add `HashRegistry.remove_by_hash(file_hash) -> bool` and call it from
`remove` with the hash already resolved by `_resolve_doc_identifier`.
The hash key is always present, so pruning no longer depends on the
metadata shape.
Tests: `test_hash_registry_remove_by_hash` (modern + legacy entry
shapes, idempotency, unknown-hash returns False) and the end-to-end
`test_cli_remove_prunes_legacy_registry_entry_without_doc_name`, which
seeds a registry entry in the exact pre-PR#51 shape from the issue.
Refs #58 (Bug 1).
* fix(cli): scope `openkb remove`'s post-pass lint to the files it touched
`remove` ran `fix_broken_links(wiki_dir)` after every deletion. That
helper was built for `openkb lint --fix` — an explicit, user-invoked
wiki-wide cleanup — and strips *every* dangling `[[wikilink]]` in the
KB. PR #51 reused it for the post-remove pass, whose declared intent
(per its own PR description) was only to strip links pointing at the
just-removed summary and deleted concept pages.
That mismatch meant a single `openkb remove` reformatted unrelated
pages KB-wide — 39-file / 1254-line diff in the repro — and silently
demoted pre-existing ghost links the user meant to keep, e.g. a
hand-written link to a concept they plan to add later.
Add a keyword-only `restrict_to` parameter to `fix_broken_links`:
when given, only those files are rewritten, while the valid-target
whitelist is still computed wiki-wide so legitimate cross-links in the
scoped files still resolve. `remove` now passes the union of the
concept pages it modified (`concept_result["modified"]`) and
`index.md`. `openkb lint --fix` is untouched — it omits the parameter
and keeps the wiki-wide behavior, which is correct for that command.
`test_cli_remove_lint_cleans_dangling_links` previously planted a
stray link in an unrelated page and asserted it was stripped, which
enshrined the over-zealous behavior. Renamed to `..._in_modified_page`
and re-targeted at a page the removal actually modifies; the new
`test_cli_remove_preserves_ghosts_in_unrelated_pages` locks in the
opposite contract. `TestFixBrokenLinksRestrictTo` adds 5 unit cases
covering default behavior, scoping, empty list, paths outside the
wiki, and the wiki-wide target set.
Closes #58.
1 parent c1fe2a0 commit 5e2f436
5 files changed
Lines changed: 317 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
882 | 882 | | |
883 | 883 | | |
884 | 884 | | |
885 | | - | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
886 | 900 | | |
887 | 901 | | |
888 | 902 | | |
| |||
909 | 923 | | |
910 | 924 | | |
911 | 925 | | |
912 | | - | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
913 | 930 | | |
914 | 931 | | |
915 | 932 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
| |||
184 | 188 | | |
185 | 189 | | |
186 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
187 | 201 | | |
188 | 202 | | |
189 | 203 | | |
| |||
200 | 214 | | |
201 | 215 | | |
202 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
203 | 235 | | |
204 | 236 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 237 | + | |
211 | 238 | | |
212 | 239 | | |
213 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
53 | 67 | | |
54 | 68 | | |
55 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
392 | 393 | | |
393 | 394 | | |
394 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
0 commit comments