-
Notifications
You must be signed in to change notification settings - Fork 0
fix(ci): harden weekly etl integrity and remove nltk #17
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
Merged
Merged
Changes from all commits
Commits
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
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
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
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,129 @@ | ||
| """Valida que los bridges frontend conserven historial util antes de publicar.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| REQUIRED_HISTORY_DATASETS = { | ||
| "trend_score", | ||
| "github_commits", | ||
| "github_correlacion", | ||
| "github_lenguajes", | ||
| "so_volumen", | ||
| "so_aceptacion", | ||
| "so_tendencias", | ||
| "reddit_temas", | ||
| "interseccion", | ||
| } | ||
|
|
||
| REQUIRED_HISTORY_BRIDGES = ( | ||
| "github_frameworks_history.json", | ||
| "github_correlacion_history.json", | ||
| "so_volumen_history.json", | ||
| "so_aceptacion_history.json", | ||
| "so_tendencias_history.json", | ||
| "reddit_temas_history.json", | ||
| "reddit_interseccion_history.json", | ||
| ) | ||
|
|
||
|
|
||
| def _load_json(path: Path) -> dict: | ||
| return json.loads(path.read_text(encoding="utf-8")) | ||
|
|
||
|
|
||
| def _bridge_assets_root(project_root: Path) -> Path: | ||
| return project_root / "frontend" / "assets" / "data" | ||
|
|
||
|
|
||
| def check_bridge_integrity( | ||
| project_root: Path | str, | ||
| *, | ||
| expect_previous_history: bool = False, | ||
| ) -> dict[str, int | str]: | ||
| project_root = Path(project_root) | ||
| assets_root = _bridge_assets_root(project_root) | ||
| errors: list[str] = [] | ||
|
|
||
| history_index = _load_json(assets_root / "history_index.json") | ||
| dataset_names = { | ||
| str(item.get("dataset", "")).strip() | ||
| for item in history_index.get("datasets", []) | ||
| if str(item.get("dataset", "")).strip() | ||
| } | ||
| missing_datasets = sorted(REQUIRED_HISTORY_DATASETS - dataset_names) | ||
| if missing_datasets: | ||
| errors.append( | ||
| "history_index missing datasets: " + ", ".join(missing_datasets) | ||
| ) | ||
|
|
||
| trend_history = _load_json(assets_root / "trend_score_history.json") | ||
| snapshot_count = int(trend_history.get("snapshot_count", 0) or 0) | ||
| minimum_snapshots = 2 if expect_previous_history else 1 | ||
| if snapshot_count < minimum_snapshots: | ||
| errors.append( | ||
| f"trend_score_history snapshot_count={snapshot_count} < {minimum_snapshots}" | ||
| ) | ||
|
|
||
| technology_profiles = _load_json(assets_root / "technology_profiles.json") | ||
| if not technology_profiles.get("latest_snapshot_date"): | ||
| errors.append("technology_profiles latest_snapshot_date missing") | ||
| if int(technology_profiles.get("profile_count", 0) or 0) <= 0: | ||
| errors.append("technology_profiles profile_count must be positive") | ||
| if expect_previous_history and not technology_profiles.get("previous_snapshot_date"): | ||
| errors.append("technology_profiles previous_snapshot_date missing") | ||
|
|
||
| home_highlights = _load_json(assets_root / "home_highlights.json") | ||
| highlights = home_highlights.get("highlights", []) | ||
| minimum_highlights = 3 if expect_previous_history else 2 | ||
| if len(highlights) < minimum_highlights: | ||
| errors.append( | ||
| f"home_highlights highlights={len(highlights)} < {minimum_highlights}" | ||
| ) | ||
|
|
||
| for bridge_name in REQUIRED_HISTORY_BRIDGES: | ||
| payload = _load_json(assets_root / bridge_name) | ||
| source_mode = str(payload.get("source_mode", "")).strip().lower() | ||
| if source_mode in {"", "missing", "none"}: | ||
| errors.append(f"{bridge_name} source_mode={source_mode or 'missing'}") | ||
| if not payload.get("latest_snapshot_date"): | ||
| errors.append(f"{bridge_name} latest_snapshot_date missing") | ||
| if expect_previous_history and not payload.get("previous_snapshot_date"): | ||
| errors.append(f"{bridge_name} previous_snapshot_date missing") | ||
|
|
||
| if errors: | ||
| raise ValueError("; ".join(errors)) | ||
|
|
||
| return { | ||
| "status": "ok", | ||
| "dataset_count": len(dataset_names), | ||
| "trend_snapshot_count": snapshot_count, | ||
| "profile_count": int(technology_profiles.get("profile_count", 0) or 0), | ||
| "home_highlight_count": len(highlights), | ||
| } | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--project-root", default=".") | ||
| parser.add_argument( | ||
| "--expect-previous-history", | ||
| type=int, | ||
| default=0, | ||
| choices=(0, 1), | ||
| help="Exige snapshot previo cuando el workflow ya recupero un aggregate previo.", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| summary = check_bridge_integrity( | ||
| args.project_root, | ||
| expect_previous_history=bool(args.expect_previous_history), | ||
| ) | ||
| print(json.dumps(summary, ensure_ascii=False)) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
Oops, something went wrong.
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.
check_bridge_integrityhard-fails whenhome_highlights.highlightshas fewer than 3 entries wheneverexpect_previous_history=True. Howeverexport_history_json.build_home_highlights_payload()can legitimately emit <3 highlights when some upstream bridge summaries are null/empty (it only adds candidates when a specific payload is present). This makes the integrity gate brittle and can block publishes even when the bridge files are structurally valid and the UI can run in degraded mode. Consider validating the JSON shape (e.g.,highlightsis a list,candidate_count >= len(highlights)) and using a lower/conditional minimum (or tie the minimum tocandidate_count) instead of a fixed 3.