yak(link-validator-never-sees-compiled-html-internal-link-validation-is-vacuous-ddd1): Link validator never sees compiled HTML — internal-link validation is vacuous

This commit is contained in:
Willem van den Ende
2026-10-28 22:08:45 +00:00
parent 4e7798c906
commit c04d8c856c
8 changed files with 175 additions and 19 deletions
@@ -88,6 +88,49 @@ defmodule FirehoseWeb.BlogTest do
end
end
describe "internal links in compiled posts" do
# `Blogex.Blog._validate_links/2` validates `post.body` after
# NimblePublisher rendered it to HTML. If extraction cannot read that HTML,
# every post looks link-free and compile-time validation is vacuous - which
# is the failure the real posts below pin against.
defp posts_with_internal_links do
Enum.filter(Firehose.EngineeringBlog.all_posts(), fn post ->
Blogex.LinkValidator.extract_links(post.body) != []
end)
end
test "the validator sees internal links in real compiled posts" do
refute posts_with_internal_links() == []
end
test "the post that links to swim-the-test exposes that link" do
post =
Enum.find(posts_with_internal_links(), &(&1.id == "delayed-gratification-in-ai-summer"))
assert post, "expected the compiled post to be visible with internal links extracted"
assert "/blog/engineering/swim-the-test" in Blogex.LinkValidator.extract_links(post.body)
end
test "no internal link in a real compiled post is invisible to extraction" do
# Deliberately permissive scan (any <a> whose href appears in any
# position, quoted or not): every /blog/ link it finds must also come out
# of extract_links/1, or a bad one could never be reported.
links_in_body = fn body ->
~r/<a\s[^>]*?href=["']?(\/blog\/[^"'\s>]+)/
|> Regex.scan(body)
|> Enum.map(fn [_, link] -> link end)
|> Enum.uniq()
end
for post <- Firehose.EngineeringBlog.all_posts(),
link <- links_in_body.(post.body) do
assert link in Blogex.LinkValidator.extract_links(post.body),
"#{post.id}: #{link} is in the compiled body but not extracted"
end
end
end
describe "input validation" do
test "GET /blog/nonexistent returns 404", %{conn: conn} do
assert conn |> get("/blog/nonexistent") |> html_response(404)