Download scripts/check_transport_coverage.py from VoiceOfML/Search: direct link, hf CLI and curl.
- Browser
- Download file 7.17 kB
-
https://huggingface.co/spaces/VoiceOfML/Search/resolve/main/scripts/check_transport_coverage.py
- Command line
-
hf download hf://spaces/VoiceOfML/Search/scripts/check_transport_coverage.py
-
curl -L -o check_transport_coverage.py https://huggingface.co/spaces/VoiceOfML/Search/resolve/main/scripts/check_transport_coverage.py
7.17 kB
| """Pinned S1/S2 source migration; only unchanged historical debt may survive.""" | |
| import difflib | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| from scripts.backend_paths import ( | |
| carry_catalog_coverage, carry_stream_override_coverage, carry_upstream_coverage, reviewed_source, | |
| require_audit_reader_assets_full_coverage, require_audit_seo_full_coverage, require_audit_upstream_full_coverage, | |
| ) | |
| APP_SHA = '769155429400702a51524f3d2cf2d6dee19b26f67ea08a1f9db22aec70fa61ef' | |
| STREAMS_SHA = '02c6df15f5058d322042f99b1e8cd454380b5059c7ac9815cddf49bbf3296d6a' | |
| TRANSPORT_SHA = '9c46e4c4fc1803ab3ff976b1694c27510fb92e2ed162043bf7495d8900c87ad1' | |
| CATALOG_PARENT_SHA = 'e0aeeb62753839ded9d749c88739f730a8657645ecbf81ea63574ddc92e9ccd0' | |
| CATALOG_SHA = '114424d45ebf5c45b9c28a24f0d09bca3e72fc97349b81bef58d9e4d028dde41' | |
| def transport_layout(root: Path) -> bool: | |
| from scripts.check_refactor_coverage import refactor_layout | |
| return (refactor_layout(root) | |
| or hashlib.sha256((root / 'backend/app.py').read_bytes()).hexdigest() == APP_SHA) | |
| def transport_baseline(root: Path, baseline: dict) -> dict: | |
| from scripts.check_refactor_coverage import refactor_layout, migrate_refactor_baseline | |
| if refactor_layout(root): | |
| parent = root / 'scripts/coverage-anchors/refactor-parent-app.py.snapshot' | |
| previous = migrate_refactor_baseline(root, _transport_baseline(root, baseline, parent)) | |
| previous = carry_catalog_coverage(root, previous) | |
| previous = carry_upstream_coverage(root, previous) | |
| previous = carry_stream_override_coverage(root, previous) | |
| previous = require_audit_upstream_full_coverage(root, previous) | |
| previous = require_audit_reader_assets_full_coverage(root, previous) | |
| return require_audit_seo_full_coverage(root, previous) | |
| return _transport_baseline(root, baseline, root / 'backend/app.py') | |
| def _transport_baseline(root: Path, baseline: dict, app_source: Path) -> dict: | |
| from scripts.check_backend_coverage import (LIFESPAN_APP_SHA, LIFESPAN_PARENT_DEBT_SHA, | |
| PROXY_SAFETY_NEW_STREAMS_SHA, migrate_lifespan_baseline, | |
| migrate_ci_baseline_to_lifespan_parent, coverage_debt_errors) | |
| anchors = root / 'scripts/coverage-anchors' | |
| expected = { | |
| 'backend/app.py': APP_SHA, | |
| 'backend/proxy_streams.py': STREAMS_SHA, | |
| 'backend/search_transport.py': TRANSPORT_SHA, | |
| 'backend/reader_v3_catalog.py': CATALOG_SHA, | |
| 'scripts/coverage-anchors/catalog-parent.py.snapshot': CATALOG_PARENT_SHA, | |
| 'scripts/coverage-anchors/transport-parent-app.py.snapshot': LIFESPAN_APP_SHA, | |
| 'scripts/coverage-anchors/proxy-safety-new-streams.py.snapshot': PROXY_SAFETY_NEW_STREAMS_SHA, | |
| 'scripts/coverage-anchors/lifespan-parent-backend-coverage-debt.json': LIFESPAN_PARENT_DEBT_SHA, | |
| } | |
| for name, digest in expected.items(): | |
| data = app_source.read_bytes() if name == 'backend/app.py' else reviewed_source(root, name) | |
| if hashlib.sha256(data).hexdigest() != digest: | |
| raise ValueError(f'transport coverage requires exact reviewed source: {name}') | |
| pinned = json.loads((anchors / 'lifespan-parent-backend-coverage-debt.json').read_text()) | |
| # The stored debt stays in its independently pinned historical coordinates. | |
| # No current report is ever used to create or expand missing coverage debt. | |
| if baseline != pinned: | |
| historical = migrate_ci_baseline_to_lifespan_parent(root, baseline) | |
| errors = coverage_debt_errors(pinned, historical) | |
| if errors: | |
| raise ValueError('\n'.join(errors)) | |
| # The independently pinned parent includes later coverage improvements. | |
| # Adopt it only after proving it retains the entire translated CI ratchet. | |
| baseline = pinned | |
| result = migrate_lifespan_baseline(baseline, anchors / 'lifespan-parent-app.py.snapshot', | |
| anchors / 'transport-parent-app.py.snapshot') | |
| for name, old in ( | |
| ('backend/app.py', anchors / 'transport-parent-app.py.snapshot'), | |
| ('backend/proxy_streams.py', anchors / 'proxy-safety-new-streams.py.snapshot'), | |
| ): | |
| data = app_source.read_bytes() if name == 'backend/app.py' else reviewed_source(root, name) | |
| operations = difflib.SequenceMatcher(None, old.read_text().splitlines(), | |
| data.decode().splitlines(), autojunk=False).get_opcodes() | |
| mapping = {i + 1: j + 1 + i - start for op, start, end, j, _ in operations | |
| if op == 'equal' for i in range(start, end)} | |
| def line(n): | |
| return (-1 if n < 0 else 1) * mapping[abs(n)] | |
| entry = result[name] | |
| # Changed statements/arcs leave the old debt inventory and therefore | |
| # must all execute. Every old missing coordinate must map unchanged. | |
| missing_lines = [line(n) for n in entry['missing_lines']] | |
| missing_arcs = [[line(a), line(b)] for a, b in entry['missing_arcs']] | |
| lines = [line(n) for n in entry['lines'] if abs(n) in mapping] | |
| arcs = [[line(a), line(b)] for a, b in entry['arcs'] if abs(a) in mapping and abs(b) in mapping] | |
| if name == 'backend/proxy_streams.py': | |
| # False branches now enter the added cleanup-stage bookkeeping. | |
| redirects = {(48, 53): (48, 51), (133, 136): (133, 135), (238, 242): (238, 240)} | |
| arcs = [list(redirects.get(tuple(arc), tuple(arc))) for arc in arcs] | |
| result[name] = {'lines': sorted(lines), 'arcs': sorted(arcs), | |
| 'missing_lines': sorted(missing_lines), 'missing_arcs': sorted(missing_arcs), | |
| 'covered_lines': len(lines), 'covered_branches': len(arcs)} | |
| # Catalog debt belongs to the parent layout, not the current coordinates. | |
| # Only identical lines carry debt; changed statements and crossing arcs | |
| # remain outside the inventory and must therefore be fully exercised. | |
| name = 'backend/reader_v3_catalog.py' | |
| old = anchors / 'catalog-parent.py.snapshot' | |
| operations = difflib.SequenceMatcher(None, old.read_text().splitlines(), | |
| reviewed_source(root, name).decode().splitlines(), autojunk=False).get_opcodes() | |
| mapping = {i + 1: j + 1 + i - start for op, start, end, j, _ in operations | |
| if op == 'equal' for i in range(start, end)} | |
| def translate(n): | |
| return (-1 if n < 0 else 1) * mapping[abs(n)] | |
| entry = result[name] | |
| missing_lines = [translate(n) for n in entry['missing_lines']] | |
| missing_arcs = [[translate(a), translate(b)] for a, b in entry['missing_arcs']] | |
| lines = [translate(n) for n in entry['lines'] if abs(n) in mapping] | |
| arcs = [[translate(a), translate(b)] for a, b in entry['arcs'] | |
| if abs(a) in mapping and abs(b) in mapping] | |
| result[name] = {'lines': sorted(lines), 'arcs': sorted(arcs), | |
| 'missing_lines': sorted(missing_lines), 'missing_arcs': sorted(missing_arcs), | |
| 'covered_lines': len(lines), 'covered_branches': len(arcs)} | |
| return result | |