diff --git a/AGENTS.md b/AGENTS.md index 9c288fa..f56a2d9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -81,12 +81,14 @@ The only way for actions to affect the view returned by the render-fn running in - Sync Python dependencies with `uv sync --all-groups`. - Run the app with `uv run repub`. - Generate CSS with `tailwindcss -i ./repub/static/app.tailwind.css -o ./repub/static/app.css` and add `--watch` when you need live rebuilds. +- Validate a generated feed with `./scripts/validate-feed path/to/feed.rss`. This wraps the local checkout at `~/src/github.com/w3c/feedvalidator` and pages the validator output through `less` by default. ```sh uv sync --all-groups uv run pytest uv run flake8 repub/ tests/ uv run pyright +./scripts/validate-feed out/feeds/mn-cuba/feed.rss nix fmt nix flake check uv run repub diff --git a/scripts/validate-feed b/scripts/validate-feed new file mode 100755 index 0000000..95c4661 --- /dev/null +++ b/scripts/validate-feed @@ -0,0 +1,11 @@ +#!/bin/sh +set -eu + +feedvalidator_dir="${FEEDVALIDATOR_DIR:-$HOME/src/github.com/w3c/feedvalidator}" +pager="${PAGER:-less}" + +feed_path="$(realpath "$1")" +shift + +cd "$feedvalidator_dir" +uv run validate_feed.py "$feed_path" "$@" | "$pager" diff --git a/tests/test_validate_feed_script.py b/tests/test_validate_feed_script.py new file mode 100644 index 0000000..6a89a49 --- /dev/null +++ b/tests/test_validate_feed_script.py @@ -0,0 +1,67 @@ +import os +import stat +import subprocess +from pathlib import Path + + +def test_validate_feed_script_changes_to_feedvalidator_and_forwards_args( + tmp_path: Path, +) -> None: + script_path = Path(__file__).resolve().parents[1] / "scripts" / "validate-feed" + feedvalidator_dir = tmp_path / "feedvalidator" + bin_dir = tmp_path / "bin" + caller_dir = tmp_path / "caller" + feed_path = caller_dir / "path" / "to" / "feed.rss" + trace_dir = tmp_path / "trace" + + feedvalidator_dir.mkdir() + bin_dir.mkdir() + feed_path.parent.mkdir(parents=True) + feed_path.write_text("", encoding="utf-8") + trace_dir.mkdir() + + uv_path = bin_dir / "uv" + uv_path.write_text( + """#!/bin/sh +printf '%s\\n' "$PWD" > "$TRACE_DIR/cwd" +printf '%s\\n' "$@" > "$TRACE_DIR/args" +printf 'validator output\\n' +""", + encoding="utf-8", + ) + uv_path.chmod(uv_path.stat().st_mode | stat.S_IXUSR) + + pager_path = bin_dir / "pager" + pager_path.write_text( + """#!/bin/sh +cat > "$TRACE_DIR/pager-input" +""", + encoding="utf-8", + ) + pager_path.chmod(pager_path.stat().st_mode | stat.S_IXUSR) + + env = os.environ.copy() + env["FEEDVALIDATOR_DIR"] = str(feedvalidator_dir) + env["PAGER"] = str(pager_path) + env["PATH"] = f"{bin_dir}:{env['PATH']}" + env["TRACE_DIR"] = str(trace_dir) + + subprocess.run( + [str(script_path), "path/to/feed.rss", "--flag"], + check=True, + env=env, + cwd=caller_dir, + ) + + assert (trace_dir / "cwd").read_text(encoding="utf-8").strip() == str( + feedvalidator_dir + ) + assert (trace_dir / "args").read_text(encoding="utf-8").splitlines() == [ + "run", + "validate_feed.py", + str(feed_path.resolve()), + "--flag", + ] + assert (trace_dir / "pager-input").read_text( + encoding="utf-8" + ) == "validator output\n"