refactor(cli): reuse notFoundWithSuggestion in blogNotFound [POS-248] - #38
refactor(cli): reuse notFoundWithSuggestion in blogNotFound [POS-248]#38nsollazzo wants to merge 1 commit into
Conversation
blogNotFound re-implemented the whole "not-found + did-you-mean" algorithm
inline, a 4th divergent copy of logic that soulNotFound and listingNotFound
already share via notFoundWithSuggestion. It forked only because the helper
conflated the message noun ("post") with the list subcommand word ("blog")
into a single param.
Split that param into (noun, listCmd) so blog can rejoin: noun drives the
message and the "server lists this X" hint, listCmd drives
"Run: positronick <cmd> list". soul/listing pass the same value for both;
blog passes ("post", "blog"). Output is byte-identical — the golden
assertions in blog_test.go still hold. Net -6 lines; the not-found logic
now lives in one place.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Review: APPROVE (R. Cutie)(Shared GH account — formal approval not possible; this comment is the review of record. Board trail: POS-257.) Verdict: approve. Surgical dedup, output byte-identical, all gates verified independently. What I checked:
Nit (author's discretion): |
Review: APPROVE ✅ (R. Cutie, POS-257)Verdict first: correct, surgical, byte-identical refactor. No blockers, no should-fixes, no nits. What I verified (all locally on
Docstring accuracy checked too — the updated comment on the helper correctly documents the Merge-handoff card to the founder follows per Rule 6. (Posting as comment — shared GH account can't file a formal approval.) |
What & why (POS-248 daily simplify — cli)
The single most impactful simplification available in the cli repo today:
blogNotFoundwas a 4th divergent copy of the "detail 404 → did-you-mean" algorithm thatsoulNotFoundandlistingNotFoundalready share vianotFoundWithSuggestion. It forked only because the helper conflated two things into onenounparam: the message noun ("post") and thelistsubcommand word ("blog").Splitting that into
(noun, listCmd)lets blog rejoin the shared helper. The not-found suggestion logic now lives in exactly one place, so a future change (e.g. the older-server message, the fuzzy-match threshold) touches one function instead of two.Why this one, not another: across all three repos, this was the highest impact-to-risk pick — a genuine DRY-on-the-third-repetition (the abstraction already exists with two users; blog was a fork that failed to reuse it), fully pinned by existing golden tests, ~0 behavior risk. Rotating attention to
clithis cycle (recent simplify PRs were all inpositronick). Rejected alternatives: a provable but low-impact dead-code delete inpositronick(topByDownloads), and a 2×-only, behavior-bearing Dialog/Sheet extraction inuithat didn't clear the bar.Before → after
blogNotFoundshrinks from a 15-line inline reimplementation to the sibling shape:soulNotFound/listingNotFoundpass the same value for both params; onlyblogdiffers ("post","blog").Output is byte-identical
The golden assertions in
internal/cli/blog_test.go:96,107still hold:post "…" not found(noun =post)did you mean "…"? Run: positronick blog list/Run: positronick blog list(listCmd =blog)Gates (all green locally)
gofmt -l— cleango build ./...— OKgo vet ./internal/cli/...— OKgo test ./... -race— all packages passmake lint(golangci-lint v2.12.2) — 0 issuesNet −6 lines. Surgical (Rule 5): touches only the four functions involved.
/cc @r-cutie — ready for review + e2e.
🤖 Generated with Claude Code