migration: audit uncertain code and prepare handoff
This commit is contained in:
@@ -17,6 +17,16 @@ SOURCE_RANGE = re.compile(
|
||||
re.DOTALL,
|
||||
)
|
||||
|
||||
# These exact original app.js line ranges were retired in slice 11 after the
|
||||
# definition-only symbols passed static, runtime, and compatibility review.
|
||||
RETIRED_FRONTEND_SOURCE_RANGES = (
|
||||
(3537, 3540),
|
||||
(4139, 4145),
|
||||
(4973, 4989),
|
||||
(9022, 9027),
|
||||
(9052, 9055),
|
||||
)
|
||||
|
||||
|
||||
def sha256(path: Path) -> str:
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
@@ -38,8 +48,6 @@ def reassembled_frontend_runtime() -> str:
|
||||
raise AssertionError(
|
||||
f"app.js source coverage gap: expected line {next_line}, got {start}"
|
||||
)
|
||||
if len(content.splitlines(keepends=True)) != end - start + 1:
|
||||
raise AssertionError(f"app.js line count changed in range {start}-{end}")
|
||||
assembled.append(content)
|
||||
next_line = end + 1
|
||||
|
||||
@@ -53,6 +61,27 @@ def reassembled_frontend_runtime() -> str:
|
||||
return "".join(assembled)
|
||||
|
||||
|
||||
def original_runtime_after_audited_retirements() -> str:
|
||||
lines = (ORIGINAL_STATIC / "app.js").read_text(encoding="utf-8").splitlines(
|
||||
keepends=True
|
||||
)
|
||||
retired = {
|
||||
line_number
|
||||
for start, end in RETIRED_FRONTEND_SOURCE_RANGES
|
||||
for line_number in range(start, end + 1)
|
||||
}
|
||||
return "".join(
|
||||
line for line_number, line in enumerate(lines, start=1) if line_number not in retired
|
||||
)
|
||||
|
||||
|
||||
def assert_frontend_runtime_matches_audited_baseline(testcase) -> None:
|
||||
testcase.assertEqual(
|
||||
reassembled_frontend_runtime(),
|
||||
original_runtime_after_audited_retirements(),
|
||||
)
|
||||
|
||||
|
||||
def assert_moved_asset_matches(
|
||||
testcase,
|
||||
original_relative: str,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from database import ReviewDatabase
|
||||
|
||||
|
||||
APP_ROOT = Path(__file__).resolve().parents[1]
|
||||
FRONTEND_ROOT = APP_ROOT / "frontend"
|
||||
|
||||
|
||||
class CleanupContractTests(unittest.TestCase):
|
||||
def test_retired_files_stay_absent(self) -> None:
|
||||
self.assertFalse((APP_ROOT / "demo_data.py").exists())
|
||||
self.assertFalse((FRONTEND_ROOT / "heaven-loading.js").exists())
|
||||
|
||||
def test_only_active_heaven_loading_asset_is_loaded(self) -> None:
|
||||
html = (FRONTEND_ROOT / "index.html").read_text(encoding="utf-8")
|
||||
self.assertIn('src="/pages/heaven/loading-v2.js', html)
|
||||
self.assertNotIn('src="/heaven-loading.js', html)
|
||||
|
||||
def test_audited_definition_only_functions_stay_absent(self) -> None:
|
||||
runtime = "\n".join(
|
||||
path.read_text(encoding="utf-8")
|
||||
for path in FRONTEND_ROOT.rglob("*.js")
|
||||
if "vendor" not in path.parts
|
||||
)
|
||||
for symbol in (
|
||||
"commonReviewColumns",
|
||||
"outcomeClass",
|
||||
"screenerResultMatchesSelection",
|
||||
"selectRegime",
|
||||
"showHeartRitualCurtain",
|
||||
):
|
||||
with self.subTest(symbol=symbol):
|
||||
self.assertNotIn(symbol, runtime)
|
||||
|
||||
def test_wencai_history_compatibility_is_retained(self) -> None:
|
||||
for method in (
|
||||
"list_wencai_saved_queries",
|
||||
"save_wencai_query",
|
||||
"delete_wencai_saved_query",
|
||||
):
|
||||
with self.subTest(method=method):
|
||||
self.assertTrue(hasattr(ReviewDatabase, method))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -7,18 +7,15 @@ from backend.bootstrap.config import APP_DIR, STATIC_DIR
|
||||
from tests.preservation_helpers import (
|
||||
FRONTEND_ROOT,
|
||||
ORIGINAL_STATIC,
|
||||
assert_frontend_runtime_matches_audited_baseline,
|
||||
assert_moved_asset_matches,
|
||||
assert_page_prefix_matches,
|
||||
reassembled_frontend_runtime,
|
||||
)
|
||||
|
||||
|
||||
class FrontendPreservationSliceTests(unittest.TestCase):
|
||||
def test_split_runtime_reassembles_to_the_exact_original(self) -> None:
|
||||
self.assertEqual(
|
||||
reassembled_frontend_runtime(),
|
||||
(ORIGINAL_STATIC / "app.js").read_text(encoding="utf-8"),
|
||||
)
|
||||
def test_split_runtime_matches_original_except_audited_retirements(self) -> None:
|
||||
assert_frontend_runtime_matches_audited_baseline(self)
|
||||
|
||||
def test_index_diff_is_limited_to_asset_relocation_and_split_loading(self) -> None:
|
||||
migrated = (FRONTEND_ROOT / "index.html").read_text(encoding="utf-8")
|
||||
@@ -64,7 +61,6 @@ class FrontendPreservationSliceTests(unittest.TestCase):
|
||||
for original, migrated in (
|
||||
("ui-core.js", "shared/ui-core.js"),
|
||||
("heaven-loading-v2.js", "pages/heaven/loading-v2.js"),
|
||||
("heaven-loading.js", "heaven-loading.js"),
|
||||
("vendor/lucide.min.js", "vendor/lucide.min.js"),
|
||||
("pages.config.js", "pages.config.js"),
|
||||
("pages/runtime.js", "pages/runtime.js"),
|
||||
|
||||
@@ -6,10 +6,9 @@ import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from tests.preservation_helpers import (
|
||||
ORIGINAL_STATIC,
|
||||
assert_frontend_runtime_matches_audited_baseline,
|
||||
assert_moved_asset_matches,
|
||||
assert_page_prefix_matches,
|
||||
reassembled_frontend_runtime,
|
||||
)
|
||||
|
||||
|
||||
@@ -84,10 +83,7 @@ class LadderRotationSliceSourceEquivalenceTests(unittest.TestCase):
|
||||
sha256(APP_ROOT / "config/api.config.json"),
|
||||
sha256(ORIGINAL_ROOT / "config/api.config.json"),
|
||||
)
|
||||
self.assertEqual(
|
||||
reassembled_frontend_runtime(),
|
||||
(ORIGINAL_STATIC / "app.js").read_text(encoding="utf-8"),
|
||||
)
|
||||
assert_frontend_runtime_matches_audited_baseline(self)
|
||||
assert_moved_asset_matches(self, "styles.css", "styles/styles.css")
|
||||
for page in ("pages/ladder/page.js", "pages/rotation/page.js"):
|
||||
assert_page_prefix_matches(self, page)
|
||||
|
||||
@@ -14,9 +14,8 @@ from backend.data.providers import ifind_client as canonical_ifind
|
||||
from backend.data.providers import tushare_client as canonical_tushare
|
||||
from backend.features.market import charts
|
||||
from tests.preservation_helpers import (
|
||||
ORIGINAL_STATIC,
|
||||
assert_frontend_runtime_matches_audited_baseline,
|
||||
assert_moved_asset_matches,
|
||||
reassembled_frontend_runtime,
|
||||
)
|
||||
|
||||
|
||||
@@ -152,10 +151,7 @@ class MarketSliceSourceEquivalenceTests(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_relocated_frontend_preserves_original_market_runtime_and_styles(self) -> None:
|
||||
self.assertEqual(
|
||||
reassembled_frontend_runtime(),
|
||||
(ORIGINAL_STATIC / "app.js").read_text(encoding="utf-8"),
|
||||
)
|
||||
assert_frontend_runtime_matches_audited_baseline(self)
|
||||
for original, migrated in (
|
||||
("styles.css", "styles/styles.css"),
|
||||
("renovation.css", "styles/renovation.css"),
|
||||
|
||||
@@ -8,10 +8,9 @@ from pathlib import Path
|
||||
import market_insights
|
||||
from backend.features.market import insights as canonical_insights
|
||||
from tests.preservation_helpers import (
|
||||
ORIGINAL_STATIC,
|
||||
assert_frontend_runtime_matches_audited_baseline,
|
||||
assert_moved_asset_matches,
|
||||
assert_page_prefix_matches,
|
||||
reassembled_frontend_runtime,
|
||||
)
|
||||
|
||||
|
||||
@@ -184,10 +183,7 @@ class MarketInsightsSliceSourceEquivalenceTests(unittest.TestCase):
|
||||
sha256(APP_ROOT / "config/api.config.json"),
|
||||
sha256(ORIGINAL_ROOT / "config/api.config.json"),
|
||||
)
|
||||
self.assertEqual(
|
||||
reassembled_frontend_runtime(),
|
||||
(ORIGINAL_STATIC / "app.js").read_text(encoding="utf-8"),
|
||||
)
|
||||
assert_frontend_runtime_matches_audited_baseline(self)
|
||||
assert_moved_asset_matches(self, "styles.css", "styles/styles.css")
|
||||
for page in (
|
||||
"pages/auction/page.js",
|
||||
|
||||
@@ -12,10 +12,9 @@ import strategy_tracking
|
||||
from backend.features.screener import compiler, engine, strategies, tracking
|
||||
from backend.features.screener import service as screener_service
|
||||
from tests.preservation_helpers import (
|
||||
ORIGINAL_STATIC,
|
||||
assert_frontend_runtime_matches_audited_baseline,
|
||||
assert_moved_asset_matches,
|
||||
assert_page_prefix_matches,
|
||||
reassembled_frontend_runtime,
|
||||
)
|
||||
|
||||
|
||||
@@ -188,10 +187,7 @@ class ScreenerSliceSourceEquivalenceTests(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_screener_frontend_assets_are_unchanged(self) -> None:
|
||||
self.assertEqual(
|
||||
reassembled_frontend_runtime(),
|
||||
(ORIGINAL_STATIC / "app.js").read_text(encoding="utf-8"),
|
||||
)
|
||||
assert_frontend_runtime_matches_audited_baseline(self)
|
||||
assert_moved_asset_matches(self, "styles.css", "styles/styles.css")
|
||||
assert_page_prefix_matches(self, "pages/screener/page.js")
|
||||
|
||||
|
||||
@@ -8,10 +8,9 @@ from pathlib import Path
|
||||
import sentiment_engine
|
||||
from backend.features.sentiment import engine as canonical_engine
|
||||
from tests.preservation_helpers import (
|
||||
ORIGINAL_STATIC,
|
||||
assert_frontend_runtime_matches_audited_baseline,
|
||||
assert_moved_asset_matches,
|
||||
assert_page_prefix_matches,
|
||||
reassembled_frontend_runtime,
|
||||
)
|
||||
|
||||
|
||||
@@ -105,10 +104,7 @@ class SentimentPoolSliceSourceEquivalenceTests(unittest.TestCase):
|
||||
sha256(APP_ROOT / "config/api.config.json"),
|
||||
sha256(ORIGINAL_ROOT / "config/api.config.json"),
|
||||
)
|
||||
self.assertEqual(
|
||||
reassembled_frontend_runtime(),
|
||||
(ORIGINAL_STATIC / "app.js").read_text(encoding="utf-8"),
|
||||
)
|
||||
assert_frontend_runtime_matches_audited_baseline(self)
|
||||
assert_moved_asset_matches(self, "styles.css", "styles/styles.css")
|
||||
for page in ("pages/sentiment/page.js", "pages/pools/page.js"):
|
||||
assert_page_prefix_matches(self, page)
|
||||
|
||||
Reference in New Issue
Block a user