-
Notifications
You must be signed in to change notification settings - Fork 0
Gate RSS live publication on complete fetches #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #!/usr/bin/env python3 | ||
| """Fail closed unless the existing RSS fetch status is complete.""" | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) | ||
|
|
||
| from political_event_tracking_research.rss_source_fetch import FetchStatusError, validate_fetch_status # noqa: E402 | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--status", required=True, type=Path) | ||
| parser.add_argument("--fetch-exit", required=True, type=Path) | ||
| args = parser.parse_args() | ||
| try: | ||
| fetch_exit = int(args.fetch_exit.read_text(encoding="utf-8").strip()) | ||
| complete = validate_fetch_status(json.loads(args.status.read_text(encoding="utf-8")), fetch_exit=fetch_exit) | ||
| except (FetchStatusError, OSError, UnicodeError, json.JSONDecodeError, TypeError, ValueError): | ||
| raise SystemExit("fetch_status_invalid") from None | ||
| if not complete: | ||
| raise SystemExit("fetch_incomplete") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/political_event_tracking_research/workflow_boundary.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """Pure guards for the existing RSS workflow boundary.""" | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import PurePosixPath | ||
|
|
||
| CANONICAL_FEEDS = "config/free_rss_feeds.csv" | ||
| CANONICAL_ALIASES = "config/core_us_equity_aliases.csv" | ||
| CANONICAL_WATCHLIST = "data/live/political_watchlist.csv" | ||
| CANONICAL_MAX_ITEMS_PER_FEED = "50" | ||
|
|
||
|
|
||
| class PathBoundaryError(ValueError): | ||
| def __init__(self, code: str) -> None: | ||
| self.code = code | ||
| super().__init__(code) | ||
|
|
||
|
|
||
| def validate_source_paths(feeds_path: object, aliases_path: object, watchlist_path: object) -> None: | ||
| expected = (CANONICAL_FEEDS, CANONICAL_ALIASES, CANONICAL_WATCHLIST) | ||
| actual = (feeds_path, aliases_path, watchlist_path) | ||
| if any(type(value) is not str or value != expected_value for value, expected_value in zip(actual, expected, strict=True)): | ||
| raise PathBoundaryError("workflow_input_path_invalid") | ||
| for value in actual: | ||
| path = PurePosixPath(value) | ||
| if path.is_absolute() or value != str(path) or any(part in {"", ".", ".."} for part in path.parts) or "\\" in value: | ||
| raise PathBoundaryError("workflow_input_path_invalid") | ||
|
|
||
|
|
||
| def validate_workflow_options(commit_outputs: object, max_items_per_feed: object) -> None: | ||
| if type(commit_outputs) is not str or commit_outputs not in {"false", "true"} or type(max_items_per_feed) is not str: | ||
| raise PathBoundaryError("workflow_option_invalid") | ||
| if commit_outputs == "true" and max_items_per_feed != CANONICAL_MAX_ITEMS_PER_FEED: | ||
| raise PathBoundaryError("production_fetch_override_invalid") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from political_event_tracking_research.rss_source_fetch import FetchStatusError, validate_fetch_status | ||
| from political_event_tracking_research.workflow_boundary import PathBoundaryError, validate_source_paths, validate_workflow_options | ||
|
|
||
|
|
||
| def status(**overrides: object) -> dict[str, object]: | ||
| payload: dict[str, object] = { | ||
| "generated_at": "2026-07-16T00:00:00Z", | ||
| "feed_count": 2, | ||
| "successful_feed_count": 2, | ||
| "failed_feed_count": 0, | ||
| "item_count": 1, | ||
| "feeds": [ | ||
| {"feed_id": "a", "feed_url": "https://a.example/feed", "ok": True, "item_count": 1, "error": ""}, | ||
| {"feed_id": "b", "feed_url": "https://b.example/feed", "ok": True, "item_count": 0, "error": ""}, | ||
| ], | ||
| } | ||
| payload.update(overrides) | ||
| return payload | ||
|
|
||
|
|
||
| def test_fetch_status_validation_returns_complete_state() -> None: | ||
| assert validate_fetch_status(status()) is True | ||
| assert validate_fetch_status(status(failed_feed_count=1, successful_feed_count=1, feeds=[ | ||
| {"feed_id": "a", "feed_url": "https://a.example/feed", "ok": True, "item_count": 1, "error": ""}, | ||
| {"feed_id": "b", "feed_url": "https://b.example/feed", "ok": False, "item_count": 0, "error": "blocked"}, | ||
| ])) is False | ||
| with pytest.raises(FetchStatusError): | ||
| validate_fetch_status(status(), fetch_exit=7) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("change", [{"complete": False}, {"failed_feed_count": 1}, {"unknown": 1}, {"feeds": []}]) | ||
| def test_fetch_status_shape_or_incompleteness_fails_closed(change: dict[str, object]) -> None: | ||
| with pytest.raises(FetchStatusError): | ||
| validate_fetch_status({**status(), **change}) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", ["config/other.csv", "../config/free_rss_feeds.csv", "/tmp/feeds.csv", "config\\feeds.csv", ""]) | ||
| def test_manual_source_paths_are_canonical_only(value: str) -> None: | ||
| with pytest.raises(PathBoundaryError): | ||
| validate_source_paths(value, "config/core_us_equity_aliases.csv", "data/live/political_watchlist.csv") | ||
|
|
||
|
|
||
| def test_production_commit_rejects_fetch_override_before_fetch() -> None: | ||
| validate_workflow_options("false", "7") | ||
| validate_workflow_options("true", "50") | ||
| with pytest.raises(PathBoundaryError): | ||
| validate_workflow_options("true", "7") | ||
|
|
||
|
|
||
| def test_workflow_orders_debug_upload_gate_and_live_push() -> None: | ||
| workflow = Path(__file__).parents[1].joinpath(".github/workflows/rss_source_pipeline.yml").read_text(encoding="utf-8") | ||
| assert workflow.index("Validate canonical workflow inputs") < workflow.index("actions/checkout@") | ||
| assert workflow.index("Upload RSS source artifact") < workflow.index("Validate feed completeness") | ||
| assert workflow.index("Validate feed completeness") < workflow.index("Publish live CSV outputs") | ||
| assert "git push origin HEAD:refs/heads/main" in workflow | ||
| assert "git rev-parse HEAD" in workflow | ||
| assert "fetch_exit" in workflow | ||
| assert "--fetch-exit" in workflow | ||
| assert "COMMIT_OUTPUTS" in workflow | ||
| assert "weekly" not in workflow.lower() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
COMMIT_OUTPUTS=trueand there are live-output changes, this push now depends on a manually addedAuthorization: bearerheader after checkout credentials were disabled withpersist-credentials: false; GitHub’s HTTPS Git docs describe authenticating Git operations by using the token as the password, and theactions/checkoutREADME’s push example relies on its persisted credentials, so this custom Bearer header can leave scheduled live publication unable to push even after a complete fetch. Use checkout’s persisted token or a Basic/credential-helper based Git credential for this scoped push.Useful? React with 👍 / 👎.