vomebook commited on
Commit ·
03490d9
1
Parent(s): 6b25656
Cover Reader transport and search boundary paths
Browse files
quality/baselines/backend-coverage-debt.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"backend/app.py": {
|
| 3 |
-
"covered_lines":
|
| 4 |
-
"covered_branches":
|
| 5 |
"lines": [
|
| 6 |
3,
|
| 7 |
4,
|
|
@@ -447,6 +447,7 @@
|
|
| 447 |
700,
|
| 448 |
703,
|
| 449 |
705,
|
|
|
|
| 450 |
707,
|
| 451 |
708,
|
| 452 |
709,
|
|
@@ -1047,6 +1048,7 @@
|
|
| 1047 |
1650,
|
| 1048 |
1651,
|
| 1049 |
1652,
|
|
|
|
| 1050 |
1654,
|
| 1051 |
1657,
|
| 1052 |
1658,
|
|
@@ -1470,6 +1472,8 @@
|
|
| 1470 |
2298,
|
| 1471 |
2303,
|
| 1472 |
2304,
|
|
|
|
|
|
|
| 1473 |
2307,
|
| 1474 |
2308,
|
| 1475 |
2309,
|
|
@@ -1555,6 +1559,7 @@
|
|
| 1555 |
2419,
|
| 1556 |
2420,
|
| 1557 |
2421,
|
|
|
|
| 1558 |
2427,
|
| 1559 |
2428,
|
| 1560 |
2429,
|
|
@@ -1613,6 +1618,7 @@
|
|
| 1613 |
2512,
|
| 1614 |
2513,
|
| 1615 |
2514,
|
|
|
|
| 1616 |
2516,
|
| 1617 |
2517,
|
| 1618 |
2520,
|
|
@@ -2178,6 +2184,10 @@
|
|
| 2178 |
696,
|
| 2179 |
699
|
| 2180 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2181 |
[
|
| 2182 |
705,
|
| 2183 |
707
|
|
@@ -2730,6 +2740,10 @@
|
|
| 2730 |
1236,
|
| 2731 |
1237
|
| 2732 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2733 |
[
|
| 2734 |
1240,
|
| 2735 |
1241
|
|
@@ -3034,6 +3048,10 @@
|
|
| 3034 |
1650,
|
| 3035 |
1652
|
| 3036 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3037 |
[
|
| 3038 |
1652,
|
| 3039 |
1654
|
|
@@ -3118,6 +3136,10 @@
|
|
| 3118 |
1738,
|
| 3119 |
1741
|
| 3120 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3121 |
[
|
| 3122 |
1763,
|
| 3123 |
1764
|
|
@@ -3258,6 +3280,10 @@
|
|
| 3258 |
1902,
|
| 3259 |
1904
|
| 3260 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3261 |
[
|
| 3262 |
1919,
|
| 3263 |
1920
|
|
@@ -3614,6 +3640,10 @@
|
|
| 3614 |
2303,
|
| 3615 |
2329
|
| 3616 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3617 |
[
|
| 3618 |
2304,
|
| 3619 |
2307
|
|
@@ -3818,6 +3848,10 @@
|
|
| 3818 |
2419,
|
| 3819 |
2436
|
| 3820 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3821 |
[
|
| 3822 |
2421,
|
| 3823 |
2427
|
|
@@ -3894,6 +3928,10 @@
|
|
| 3894 |
2509,
|
| 3895 |
2513
|
| 3896 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3897 |
[
|
| 3898 |
2514,
|
| 3899 |
2516
|
|
@@ -4155,19 +4193,8 @@
|
|
| 4155 |
2806
|
| 4156 |
]
|
| 4157 |
],
|
| 4158 |
-
"missing_lines": [
|
| 4159 |
-
706,
|
| 4160 |
-
1653,
|
| 4161 |
-
2305,
|
| 4162 |
-
2306,
|
| 4163 |
-
2422,
|
| 4164 |
-
2515
|
| 4165 |
-
],
|
| 4166 |
"missing_arcs": [
|
| 4167 |
-
[
|
| 4168 |
-
705,
|
| 4169 |
-
706
|
| 4170 |
-
],
|
| 4171 |
[
|
| 4172 |
1011,
|
| 4173 |
1013
|
|
@@ -4184,22 +4211,6 @@
|
|
| 4184 |
1172,
|
| 4185 |
1174
|
| 4186 |
],
|
| 4187 |
-
[
|
| 4188 |
-
1236,
|
| 4189 |
-
1240
|
| 4190 |
-
],
|
| 4191 |
-
[
|
| 4192 |
-
1652,
|
| 4193 |
-
1653
|
| 4194 |
-
],
|
| 4195 |
-
[
|
| 4196 |
-
1763,
|
| 4197 |
-
-1759
|
| 4198 |
-
],
|
| 4199 |
-
[
|
| 4200 |
-
1919,
|
| 4201 |
-
-1915
|
| 4202 |
-
],
|
| 4203 |
[
|
| 4204 |
2250,
|
| 4205 |
-2249
|
|
@@ -4207,18 +4218,6 @@
|
|
| 4207 |
[
|
| 4208 |
2253,
|
| 4209 |
2250
|
| 4210 |
-
],
|
| 4211 |
-
[
|
| 4212 |
-
2304,
|
| 4213 |
-
2305
|
| 4214 |
-
],
|
| 4215 |
-
[
|
| 4216 |
-
2421,
|
| 4217 |
-
2422
|
| 4218 |
-
],
|
| 4219 |
-
[
|
| 4220 |
-
2514,
|
| 4221 |
-
2515
|
| 4222 |
]
|
| 4223 |
]
|
| 4224 |
},
|
|
|
|
| 1 |
{
|
| 2 |
"backend/app.py": {
|
| 3 |
+
"covered_lines": 1827,
|
| 4 |
+
"covered_branches": 590,
|
| 5 |
"lines": [
|
| 6 |
3,
|
| 7 |
4,
|
|
|
|
| 447 |
700,
|
| 448 |
703,
|
| 449 |
705,
|
| 450 |
+
706,
|
| 451 |
707,
|
| 452 |
708,
|
| 453 |
709,
|
|
|
|
| 1048 |
1650,
|
| 1049 |
1651,
|
| 1050 |
1652,
|
| 1051 |
+
1653,
|
| 1052 |
1654,
|
| 1053 |
1657,
|
| 1054 |
1658,
|
|
|
|
| 1472 |
2298,
|
| 1473 |
2303,
|
| 1474 |
2304,
|
| 1475 |
+
2305,
|
| 1476 |
+
2306,
|
| 1477 |
2307,
|
| 1478 |
2308,
|
| 1479 |
2309,
|
|
|
|
| 1559 |
2419,
|
| 1560 |
2420,
|
| 1561 |
2421,
|
| 1562 |
+
2422,
|
| 1563 |
2427,
|
| 1564 |
2428,
|
| 1565 |
2429,
|
|
|
|
| 1618 |
2512,
|
| 1619 |
2513,
|
| 1620 |
2514,
|
| 1621 |
+
2515,
|
| 1622 |
2516,
|
| 1623 |
2517,
|
| 1624 |
2520,
|
|
|
|
| 2184 |
696,
|
| 2185 |
699
|
| 2186 |
],
|
| 2187 |
+
[
|
| 2188 |
+
705,
|
| 2189 |
+
706
|
| 2190 |
+
],
|
| 2191 |
[
|
| 2192 |
705,
|
| 2193 |
707
|
|
|
|
| 2740 |
1236,
|
| 2741 |
1237
|
| 2742 |
],
|
| 2743 |
+
[
|
| 2744 |
+
1236,
|
| 2745 |
+
1240
|
| 2746 |
+
],
|
| 2747 |
[
|
| 2748 |
1240,
|
| 2749 |
1241
|
|
|
|
| 3048 |
1650,
|
| 3049 |
1652
|
| 3050 |
],
|
| 3051 |
+
[
|
| 3052 |
+
1652,
|
| 3053 |
+
1653
|
| 3054 |
+
],
|
| 3055 |
[
|
| 3056 |
1652,
|
| 3057 |
1654
|
|
|
|
| 3136 |
1738,
|
| 3137 |
1741
|
| 3138 |
],
|
| 3139 |
+
[
|
| 3140 |
+
1763,
|
| 3141 |
+
-1759
|
| 3142 |
+
],
|
| 3143 |
[
|
| 3144 |
1763,
|
| 3145 |
1764
|
|
|
|
| 3280 |
1902,
|
| 3281 |
1904
|
| 3282 |
],
|
| 3283 |
+
[
|
| 3284 |
+
1919,
|
| 3285 |
+
-1915
|
| 3286 |
+
],
|
| 3287 |
[
|
| 3288 |
1919,
|
| 3289 |
1920
|
|
|
|
| 3640 |
2303,
|
| 3641 |
2329
|
| 3642 |
],
|
| 3643 |
+
[
|
| 3644 |
+
2304,
|
| 3645 |
+
2305
|
| 3646 |
+
],
|
| 3647 |
[
|
| 3648 |
2304,
|
| 3649 |
2307
|
|
|
|
| 3848 |
2419,
|
| 3849 |
2436
|
| 3850 |
],
|
| 3851 |
+
[
|
| 3852 |
+
2421,
|
| 3853 |
+
2422
|
| 3854 |
+
],
|
| 3855 |
[
|
| 3856 |
2421,
|
| 3857 |
2427
|
|
|
|
| 3928 |
2509,
|
| 3929 |
2513
|
| 3930 |
],
|
| 3931 |
+
[
|
| 3932 |
+
2514,
|
| 3933 |
+
2515
|
| 3934 |
+
],
|
| 3935 |
[
|
| 3936 |
2514,
|
| 3937 |
2516
|
|
|
|
| 4193 |
2806
|
| 4194 |
]
|
| 4195 |
],
|
| 4196 |
+
"missing_lines": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4197 |
"missing_arcs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4198 |
[
|
| 4199 |
1011,
|
| 4200 |
1013
|
|
|
|
| 4211 |
1172,
|
| 4212 |
1174
|
| 4213 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4214 |
[
|
| 4215 |
2250,
|
| 4216 |
-2249
|
|
|
|
| 4218 |
[
|
| 4219 |
2253,
|
| 4220 |
2250
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4221 |
]
|
| 4222 |
]
|
| 4223 |
},
|
scripts/check_backend_coverage.py
CHANGED
|
@@ -1453,6 +1453,18 @@ def main() -> int:
|
|
| 1453 |
direct_single_parent = (previous is not None and
|
| 1454 |
hashlib.sha256(json.dumps(previous.get("backend/app.py"), sort_keys=True,
|
| 1455 |
separators=(",", ":")).encode()).hexdigest() == single_parent_digest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1456 |
if (previous is not None and star_anchor.exists() and previous.get("backend/app.py") != baseline.get("backend/app.py")
|
| 1457 |
and not direct_pdf_baseline and not direct_archive_baseline and not direct_typing_baseline
|
| 1458 |
and not direct_folder_parent and not direct_range_parent and not direct_term_parent and not direct_warm_parent
|
|
@@ -1521,7 +1533,7 @@ def main() -> int:
|
|
| 1521 |
except (OSError, ValueError) as error:
|
| 1522 |
print(f"download-warm coverage migration failed: {error}", file=sys.stderr)
|
| 1523 |
return 1
|
| 1524 |
-
if previous is not None and previous.get("backend/app.py") != baseline.get("backend/app.py"):
|
| 1525 |
try:
|
| 1526 |
previous = migrate_single_term_app_baseline(
|
| 1527 |
previous, ROOT / "scripts/coverage-anchors/single-term-old-app.py.snapshot",
|
|
|
|
| 1453 |
direct_single_parent = (previous is not None and
|
| 1454 |
hashlib.sha256(json.dumps(previous.get("backend/app.py"), sort_keys=True,
|
| 1455 |
separators=(",", ":")).encode()).hexdigest() == single_parent_digest)
|
| 1456 |
+
# Same-source debt improvements stay in current coordinates. Running the
|
| 1457 |
+
# historical translators again would treat an exact parent as an old layout.
|
| 1458 |
+
if previous is not None:
|
| 1459 |
+
parent_entry = previous.get("backend/app.py")
|
| 1460 |
+
parent_digest = hashlib.sha256(json.dumps(parent_entry, sort_keys=True, separators=(",", ":")).encode()).hexdigest()
|
| 1461 |
+
if parent_digest == "e7183c108470275129c4b12f2ad9f8e7a3d572ad14d46a96109f65ad10331d99":
|
| 1462 |
+
direct_single_parent = True
|
| 1463 |
+
current_layout_parent = True
|
| 1464 |
+
else:
|
| 1465 |
+
current_layout_parent = False
|
| 1466 |
+
else:
|
| 1467 |
+
current_layout_parent = False
|
| 1468 |
if (previous is not None and star_anchor.exists() and previous.get("backend/app.py") != baseline.get("backend/app.py")
|
| 1469 |
and not direct_pdf_baseline and not direct_archive_baseline and not direct_typing_baseline
|
| 1470 |
and not direct_folder_parent and not direct_range_parent and not direct_term_parent and not direct_warm_parent
|
|
|
|
| 1533 |
except (OSError, ValueError) as error:
|
| 1534 |
print(f"download-warm coverage migration failed: {error}", file=sys.stderr)
|
| 1535 |
return 1
|
| 1536 |
+
if previous is not None and previous.get("backend/app.py") != baseline.get("backend/app.py") and not current_layout_parent:
|
| 1537 |
try:
|
| 1538 |
previous = migrate_single_term_app_baseline(
|
| 1539 |
previous, ROOT / "scripts/coverage-anchors/single-term-old-app.py.snapshot",
|
tests/backend/test_coverage_safety.py
CHANGED
|
@@ -503,6 +503,40 @@ class LifespanAndCdnTests(unittest.IsolatedAsyncioTestCase):
|
|
| 503 |
close_flights.assert_awaited_once()
|
| 504 |
self.assertFalse(application.state.download_warm_enabled)
|
| 505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
async def test_lifespan_drains_only_its_active_background_tasks(self):
|
| 507 |
application = FastAPI()
|
| 508 |
session = SimpleNamespace(close=AsyncMock())
|
|
|
|
| 503 |
close_flights.assert_awaited_once()
|
| 504 |
self.assertFalse(application.state.download_warm_enabled)
|
| 505 |
|
| 506 |
+
async def test_lifespan_tolerates_absent_warm_task_and_still_closes_resources(self):
|
| 507 |
+
application = FastAPI()
|
| 508 |
+
session = SimpleNamespace(close=AsyncMock())
|
| 509 |
+
pool = SimpleNamespace(close=AsyncMock())
|
| 510 |
+
warm = asyncio.Event()
|
| 511 |
+
|
| 512 |
+
async def wait_for_warm():
|
| 513 |
+
try:
|
| 514 |
+
await warm.wait()
|
| 515 |
+
finally:
|
| 516 |
+
warm.set()
|
| 517 |
+
|
| 518 |
+
with patch.object(app, 'load_data'), patch.object(app, 'SearchExecutor', return_value=pool), \
|
| 519 |
+
patch.object(app.aiohttp, 'ClientSession', return_value=session), \
|
| 520 |
+
patch.object(app.aiohttp, 'TCPConnector', return_value=object()), \
|
| 521 |
+
patch.object(app, 'initialize_reader_bucket_state'), \
|
| 522 |
+
patch.object(app, 'initialize_reader_archive_state'), \
|
| 523 |
+
patch.object(app, 'shutdown_reader_bucket_state', new_callable=AsyncMock) as close_bucket, \
|
| 524 |
+
patch.object(app, 'shutdown_reader_archive_state', new_callable=AsyncMock) as close_archive, \
|
| 525 |
+
patch.object(app, 'shutdown_reader_range_flights', new_callable=AsyncMock) as close_flights, \
|
| 526 |
+
patch.object(app, 'warm_reader_indexes', side_effect=wait_for_warm):
|
| 527 |
+
async with app.lifespan(application):
|
| 528 |
+
task = application.state.reader_index_warm_task
|
| 529 |
+
await asyncio.sleep(0)
|
| 530 |
+
task.cancel()
|
| 531 |
+
await asyncio.gather(task, return_exceptions=True)
|
| 532 |
+
application.state.reader_index_warm_task = None
|
| 533 |
+
session.close.assert_awaited_once()
|
| 534 |
+
pool.close.assert_awaited_once()
|
| 535 |
+
close_bucket.assert_awaited_once_with(application)
|
| 536 |
+
close_archive.assert_awaited_once_with(application)
|
| 537 |
+
close_flights.assert_awaited_once()
|
| 538 |
+
self.assertEqual(application.state.reader_range_cache_bytes, 0)
|
| 539 |
+
|
| 540 |
async def test_lifespan_drains_only_its_active_background_tasks(self):
|
| 541 |
application = FastAPI()
|
| 542 |
session = SimpleNamespace(close=AsyncMock())
|
tests/gates/test_quality_inventory.py
CHANGED
|
@@ -23,6 +23,23 @@ from scripts.check_search_words_mutation import (EMPTY_STATUSES, EXECUTION_TESTS
|
|
| 23 |
from scripts.check_strict_inventory import inventory_errors
|
| 24 |
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def file_report(covered=1, statements=1, covered_branches=2, branches=2):
|
| 27 |
return {"summary": {"covered_lines": covered, "num_statements": statements,
|
| 28 |
"covered_branches": covered_branches, "num_branches": branches},
|
|
@@ -1524,7 +1541,7 @@ class Example:
|
|
| 1524 |
term_layout, ANCHORS / "download-warm-old-app.py.snapshot", ANCHORS / "single-term-old-app.py.snapshot", root / "backend/download_warm.py")
|
| 1525 |
current_layout = migrate_single_term_app_baseline(
|
| 1526 |
warm_layout, ANCHORS / "single-term-old-app.py.snapshot", root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1527 |
-
self.assertEqual(current_layout, current)
|
| 1528 |
self.assertEqual({k: v for k, v in migrated.items() if k != "backend/app.py"},
|
| 1529 |
{k: v for k, v in previous.items() if k != "backend/app.py"})
|
| 1530 |
before, after = previous["backend/app.py"], migrated["backend/app.py"]
|
|
@@ -1618,7 +1635,7 @@ class Example:
|
|
| 1618 |
term_layout, ANCHORS / "download-warm-old-app.py.snapshot", ANCHORS / "single-term-old-app.py.snapshot", root / "backend/download_warm.py")
|
| 1619 |
final_layout = migrate_single_term_app_baseline(
|
| 1620 |
warm_layout, ANCHORS / "single-term-old-app.py.snapshot", root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1621 |
-
self.assertEqual(final_layout, current)
|
| 1622 |
self.assertNotIn("backend/folder_contents.py", moved)
|
| 1623 |
self.assertEqual((before["backend/app.py"]["covered_lines"], before["backend/app.py"]["covered_branches"]),
|
| 1624 |
(1998, 693))
|
|
@@ -1693,7 +1710,7 @@ class Example:
|
|
| 1693 |
warm_layout, ANCHORS / "single-term-old-app.py.snapshot", root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1694 |
current = json.loads((root / "quality/baselines/backend-coverage-debt.json").read_text())
|
| 1695 |
self.assertEqual(previous, old_copy)
|
| 1696 |
-
self.assertEqual(final_layout, current)
|
| 1697 |
self.assertNotIn("backend/reader_range_cache.py", migrated)
|
| 1698 |
old, new = previous["backend/app.py"], migrated["backend/app.py"]
|
| 1699 |
self.assertEqual((old["covered_lines"], old["covered_branches"]), (1967, 678))
|
|
@@ -1763,7 +1780,7 @@ class Example:
|
|
| 1763 |
final_layout = migrate_single_term_app_baseline(warm_layout, ANCHORS / "single-term-old-app.py.snapshot", root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1764 |
current = json.loads((root / "quality/baselines/backend-coverage-debt.json").read_text())
|
| 1765 |
self.assertEqual(previous, old_copy)
|
| 1766 |
-
self.assertEqual(final_layout, current)
|
| 1767 |
self.assertNotIn("backend/search_term_candidates.py", migrated)
|
| 1768 |
old, new = previous["backend/app.py"], migrated["backend/app.py"]
|
| 1769 |
self.assertEqual((old["covered_lines"], old["covered_branches"]), (1941, 664))
|
|
@@ -1830,7 +1847,7 @@ class Example:
|
|
| 1830 |
final_layout = migrate_single_term_app_baseline(migrated, current_app, root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1831 |
current = json.loads((root / "quality/baselines/backend-coverage-debt.json").read_text())
|
| 1832 |
self.assertEqual(previous, old_copy)
|
| 1833 |
-
self.assertEqual(final_layout, current)
|
| 1834 |
self.assertNotIn("backend/download_warm.py", migrated)
|
| 1835 |
old, new = previous["backend/app.py"], migrated["backend/app.py"]
|
| 1836 |
self.assertEqual((old["covered_lines"], old["covered_branches"]), (1891, 627))
|
|
@@ -1898,7 +1915,7 @@ class Example:
|
|
| 1898 |
migrated = migrate_single_term_app_baseline(previous, old_app, current_app, extracted)
|
| 1899 |
current = json.loads((root / "quality/baselines/backend-coverage-debt.json").read_text())
|
| 1900 |
self.assertEqual(previous, old_copy)
|
| 1901 |
-
self.assertEqual(migrated, current)
|
| 1902 |
self.assertNotIn("backend/search_term_candidates.py", migrated)
|
| 1903 |
old, new = previous["backend/app.py"], migrated["backend/app.py"]
|
| 1904 |
self.assertEqual((old["covered_lines"], old["covered_branches"]), (1871, 619))
|
|
@@ -1946,6 +1963,61 @@ class Example:
|
|
| 1946 |
self.assertIn("backend coverage debt cannot remove prior exercised lines or arcs: backend/app.py",
|
| 1947 |
coverage_errors(root, {"meta": {"branch_coverage": True}, "files": {}}, weakened, migrated))
|
| 1948 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1949 |
def test_reader_archive_source_is_reviewed_only_with_its_exact_anchor(self):
|
| 1950 |
root = Path(__file__).resolve().parents[2]
|
| 1951 |
anchors = self.root / "scripts/coverage-anchors"
|
|
|
|
| 23 |
from scripts.check_strict_inventory import inventory_errors
|
| 24 |
|
| 25 |
|
| 26 |
+
def with_new_backend_coverage(migrated):
|
| 27 |
+
"""Apply only the newly exercised production coordinates, not new debt."""
|
| 28 |
+
promoted = json.loads(json.dumps(migrated))
|
| 29 |
+
entry = promoted["backend/app.py"]
|
| 30 |
+
for line in (706, 1653, 2305, 2306, 2422, 2515):
|
| 31 |
+
entry["missing_lines"].remove(line)
|
| 32 |
+
entry["lines"].append(line)
|
| 33 |
+
for arc in ([705, 706], [1236, 1240], [1652, 1653], [1763, -1759], [1919, -1915],
|
| 34 |
+
[2304, 2305], [2421, 2422], [2514, 2515]):
|
| 35 |
+
entry["missing_arcs"].remove(arc)
|
| 36 |
+
entry["arcs"].append(arc)
|
| 37 |
+
entry["lines"].sort()
|
| 38 |
+
entry["arcs"].sort()
|
| 39 |
+
entry["covered_lines"], entry["covered_branches"] = len(entry["lines"]), len(entry["arcs"])
|
| 40 |
+
return promoted
|
| 41 |
+
|
| 42 |
+
|
| 43 |
def file_report(covered=1, statements=1, covered_branches=2, branches=2):
|
| 44 |
return {"summary": {"covered_lines": covered, "num_statements": statements,
|
| 45 |
"covered_branches": covered_branches, "num_branches": branches},
|
|
|
|
| 1541 |
term_layout, ANCHORS / "download-warm-old-app.py.snapshot", ANCHORS / "single-term-old-app.py.snapshot", root / "backend/download_warm.py")
|
| 1542 |
current_layout = migrate_single_term_app_baseline(
|
| 1543 |
warm_layout, ANCHORS / "single-term-old-app.py.snapshot", root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1544 |
+
self.assertEqual(with_new_backend_coverage(current_layout), current)
|
| 1545 |
self.assertEqual({k: v for k, v in migrated.items() if k != "backend/app.py"},
|
| 1546 |
{k: v for k, v in previous.items() if k != "backend/app.py"})
|
| 1547 |
before, after = previous["backend/app.py"], migrated["backend/app.py"]
|
|
|
|
| 1635 |
term_layout, ANCHORS / "download-warm-old-app.py.snapshot", ANCHORS / "single-term-old-app.py.snapshot", root / "backend/download_warm.py")
|
| 1636 |
final_layout = migrate_single_term_app_baseline(
|
| 1637 |
warm_layout, ANCHORS / "single-term-old-app.py.snapshot", root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1638 |
+
self.assertEqual(with_new_backend_coverage(final_layout), current)
|
| 1639 |
self.assertNotIn("backend/folder_contents.py", moved)
|
| 1640 |
self.assertEqual((before["backend/app.py"]["covered_lines"], before["backend/app.py"]["covered_branches"]),
|
| 1641 |
(1998, 693))
|
|
|
|
| 1710 |
warm_layout, ANCHORS / "single-term-old-app.py.snapshot", root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1711 |
current = json.loads((root / "quality/baselines/backend-coverage-debt.json").read_text())
|
| 1712 |
self.assertEqual(previous, old_copy)
|
| 1713 |
+
self.assertEqual(with_new_backend_coverage(final_layout), current)
|
| 1714 |
self.assertNotIn("backend/reader_range_cache.py", migrated)
|
| 1715 |
old, new = previous["backend/app.py"], migrated["backend/app.py"]
|
| 1716 |
self.assertEqual((old["covered_lines"], old["covered_branches"]), (1967, 678))
|
|
|
|
| 1780 |
final_layout = migrate_single_term_app_baseline(warm_layout, ANCHORS / "single-term-old-app.py.snapshot", root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1781 |
current = json.loads((root / "quality/baselines/backend-coverage-debt.json").read_text())
|
| 1782 |
self.assertEqual(previous, old_copy)
|
| 1783 |
+
self.assertEqual(with_new_backend_coverage(final_layout), current)
|
| 1784 |
self.assertNotIn("backend/search_term_candidates.py", migrated)
|
| 1785 |
old, new = previous["backend/app.py"], migrated["backend/app.py"]
|
| 1786 |
self.assertEqual((old["covered_lines"], old["covered_branches"]), (1941, 664))
|
|
|
|
| 1847 |
final_layout = migrate_single_term_app_baseline(migrated, current_app, root / "backend/app.py", root / "backend/search_term_candidates.py")
|
| 1848 |
current = json.loads((root / "quality/baselines/backend-coverage-debt.json").read_text())
|
| 1849 |
self.assertEqual(previous, old_copy)
|
| 1850 |
+
self.assertEqual(with_new_backend_coverage(final_layout), current)
|
| 1851 |
self.assertNotIn("backend/download_warm.py", migrated)
|
| 1852 |
old, new = previous["backend/app.py"], migrated["backend/app.py"]
|
| 1853 |
self.assertEqual((old["covered_lines"], old["covered_branches"]), (1891, 627))
|
|
|
|
| 1915 |
migrated = migrate_single_term_app_baseline(previous, old_app, current_app, extracted)
|
| 1916 |
current = json.loads((root / "quality/baselines/backend-coverage-debt.json").read_text())
|
| 1917 |
self.assertEqual(previous, old_copy)
|
| 1918 |
+
self.assertEqual(with_new_backend_coverage(migrated), current)
|
| 1919 |
self.assertNotIn("backend/search_term_candidates.py", migrated)
|
| 1920 |
old, new = previous["backend/app.py"], migrated["backend/app.py"]
|
| 1921 |
self.assertEqual((old["covered_lines"], old["covered_branches"]), (1871, 619))
|
|
|
|
| 1963 |
self.assertIn("backend coverage debt cannot remove prior exercised lines or arcs: backend/app.py",
|
| 1964 |
coverage_errors(root, {"meta": {"branch_coverage": True}, "files": {}}, weakened, migrated))
|
| 1965 |
|
| 1966 |
+
def test_same_layout_coverage_improvement_cannot_bypass_prior_covered_coordinates(self):
|
| 1967 |
+
import subprocess
|
| 1968 |
+
root = Path(__file__).resolve().parents[2]
|
| 1969 |
+
baseline = json.loads((root / "quality/baselines/backend-coverage-debt.json").read_text())
|
| 1970 |
+
previous = json.loads(json.dumps(baseline))
|
| 1971 |
+
entry = previous["backend/app.py"]
|
| 1972 |
+
for line in (706, 1653, 2305, 2306, 2422, 2515):
|
| 1973 |
+
entry["lines"].remove(line)
|
| 1974 |
+
entry["missing_lines"].append(line)
|
| 1975 |
+
for arc in ([705, 706], [1236, 1240], [1652, 1653], [1763, -1759], [1919, -1915],
|
| 1976 |
+
[2304, 2305], [2421, 2422], [2514, 2515]):
|
| 1977 |
+
entry["arcs"].remove(arc)
|
| 1978 |
+
entry["missing_arcs"].append(arc)
|
| 1979 |
+
entry["missing_lines"].sort()
|
| 1980 |
+
entry["missing_arcs"].sort()
|
| 1981 |
+
entry["covered_lines"], entry["covered_branches"] = len(entry["lines"]), len(entry["arcs"])
|
| 1982 |
+
parent = self.root / "same-layout-parent.json"
|
| 1983 |
+
parent.write_text(json.dumps(previous))
|
| 1984 |
+
report = {"meta": {"branch_coverage": True}, "files": {
|
| 1985 |
+
path: {"summary": {"covered_lines": item["covered_lines"],
|
| 1986 |
+
"num_statements": item["covered_lines"] + len(item["missing_lines"]),
|
| 1987 |
+
"covered_branches": item["covered_branches"],
|
| 1988 |
+
"num_branches": item["covered_branches"] + len(item["missing_arcs"])},
|
| 1989 |
+
"executed_lines": list(item["lines"]), "missing_lines": list(item["missing_lines"]),
|
| 1990 |
+
"executed_branches": list(item["arcs"]), "missing_branches": list(item["missing_arcs"]),
|
| 1991 |
+
"excluded_lines": []} for path, item in baseline.items()}}
|
| 1992 |
+
for source in [*(root / "backend").rglob("*.py"), root / "app.py"]:
|
| 1993 |
+
if "__pycache__" not in source.parts:
|
| 1994 |
+
report["files"].setdefault(source.relative_to(root).as_posix(), file_report())
|
| 1995 |
+
path = self.root / "same-layout-report.json"
|
| 1996 |
+
checker = [sys.executable, "-B", str(root / "scripts/check_backend_coverage.py"), str(path), str(parent)]
|
| 1997 |
+
path.write_text(json.dumps(report))
|
| 1998 |
+
result = subprocess.run(checker, capture_output=True, text=True, check=False)
|
| 1999 |
+
self.assertEqual(result.returncode, 0, result.stderr)
|
| 2000 |
+
for field, value, count in (("executed_lines", entry["lines"][0], "covered_lines"),
|
| 2001 |
+
("executed_branches", entry["arcs"][0], "covered_branches")):
|
| 2002 |
+
changed = json.loads(json.dumps(report))
|
| 2003 |
+
item = changed["files"]["backend/app.py"]
|
| 2004 |
+
item[field].remove(value)
|
| 2005 |
+
item["missing_lines" if field == "executed_lines" else "missing_branches"].append(value)
|
| 2006 |
+
item["summary"][count] -= 1
|
| 2007 |
+
path.write_text(json.dumps(changed))
|
| 2008 |
+
result = subprocess.run(checker, capture_output=True, text=True, check=False)
|
| 2009 |
+
with self.subTest(lost=field):
|
| 2010 |
+
self.assertNotEqual(result.returncode, 0)
|
| 2011 |
+
self.assertIn("previously covered", result.stderr)
|
| 2012 |
+
mutated = json.loads(json.dumps(previous))
|
| 2013 |
+
mutated["backend/app.py"]["lines"].pop()
|
| 2014 |
+
mutated["backend/app.py"]["covered_lines"] -= 1
|
| 2015 |
+
parent.write_text(json.dumps(mutated))
|
| 2016 |
+
path.write_text(json.dumps(report))
|
| 2017 |
+
result = subprocess.run(checker, capture_output=True, text=True, check=False)
|
| 2018 |
+
self.assertNotEqual(result.returncode, 0)
|
| 2019 |
+
self.assertIn("coverage migration failed", result.stderr)
|
| 2020 |
+
|
| 2021 |
def test_reader_archive_source_is_reviewed_only_with_its_exact_anchor(self):
|
| 2022 |
root = Path(__file__).resolve().parents[2]
|
| 2023 |
anchors = self.root / "scripts/coverage-anchors"
|
tests/proxy/test_async_proxy.py
CHANGED
|
@@ -1892,6 +1892,116 @@ class AsyncProxyTests(unittest.IsolatedAsyncioTestCase):
|
|
| 1892 |
self.assertTrue(upstream.released)
|
| 1893 |
self.assertEqual(semaphore._value, 1)
|
| 1894 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1895 |
async def test_reader_cached_containing_range_serves_exact_slice_without_upstream(self):
|
| 1896 |
upstream = FakeResponse(206, {
|
| 1897 |
"Content-Type": "application/pdf", "Content-Length": "8",
|
|
|
|
| 1892 |
self.assertTrue(upstream.released)
|
| 1893 |
self.assertEqual(semaphore._value, 1)
|
| 1894 |
|
| 1895 |
+
async def test_owned_worker_cancellation_releases_bucket_and_archive_slots(self):
|
| 1896 |
+
state = app.app.state
|
| 1897 |
+
app.initialize_reader_archive_state(app.app)
|
| 1898 |
+
loop = asyncio.get_running_loop()
|
| 1899 |
+
original_create_task = asyncio.create_task
|
| 1900 |
+
observed = []
|
| 1901 |
+
|
| 1902 |
+
def capture(coro):
|
| 1903 |
+
task = original_create_task(coro)
|
| 1904 |
+
observed.append(task)
|
| 1905 |
+
return task
|
| 1906 |
+
|
| 1907 |
+
async def never(*_args):
|
| 1908 |
+
await asyncio.Event().wait()
|
| 1909 |
+
|
| 1910 |
+
with patch.object(app.asyncio, 'to_thread', side_effect=never), \
|
| 1911 |
+
patch.object(app.asyncio, 'create_task', side_effect=capture):
|
| 1912 |
+
bucket = original_create_task(app.run_reader_bucket_read('synthetic', 10))
|
| 1913 |
+
while not state.reader_bucket_workers:
|
| 1914 |
+
await asyncio.sleep(0)
|
| 1915 |
+
worker = next(iter(state.reader_bucket_workers))
|
| 1916 |
+
worker.cancel()
|
| 1917 |
+
with self.assertRaises(asyncio.CancelledError):
|
| 1918 |
+
await bucket
|
| 1919 |
+
await asyncio.sleep(0)
|
| 1920 |
+
self.assertEqual(state.reader_bucket_workers, set())
|
| 1921 |
+
self.assertEqual(state.reader_bucket_semaphore._value, app.READER_BUCKET_MAX_CONCURRENT_READS)
|
| 1922 |
+
|
| 1923 |
+
archive = original_create_task(app.run_reader_archive_worker(lambda: b'ok'))
|
| 1924 |
+
while not state.reader_archive_workers:
|
| 1925 |
+
await asyncio.sleep(0)
|
| 1926 |
+
worker = next(iter(state.reader_archive_workers))
|
| 1927 |
+
worker.cancel()
|
| 1928 |
+
with self.assertRaises(asyncio.CancelledError):
|
| 1929 |
+
await archive
|
| 1930 |
+
await asyncio.sleep(0)
|
| 1931 |
+
self.assertEqual(state.reader_archive_workers, set())
|
| 1932 |
+
self.assertEqual(state.reader_archive_worker_semaphore._value, app.READER_ARCHIVE_MAX_WORKERS)
|
| 1933 |
+
self.assertEqual(len(observed), 2)
|
| 1934 |
+
self.assertIs(asyncio.get_running_loop(), loop)
|
| 1935 |
+
await app.shutdown_reader_archive_state(app.app)
|
| 1936 |
+
|
| 1937 |
+
async def test_disconnect_monitor_rechecks_after_one_poll_before_transport_finishes(self):
|
| 1938 |
+
observed = []
|
| 1939 |
+
finished = asyncio.Event()
|
| 1940 |
+
|
| 1941 |
+
async def transport(*_args, **_kwargs):
|
| 1942 |
+
await asyncio.sleep(0.25)
|
| 1943 |
+
finished.set()
|
| 1944 |
+
return app.Response(content=b'ok')
|
| 1945 |
+
|
| 1946 |
+
async def is_disconnected():
|
| 1947 |
+
observed.append(len(observed))
|
| 1948 |
+
return False
|
| 1949 |
+
|
| 1950 |
+
with patch.object(app, '_stream_reader_document', side_effect=transport):
|
| 1951 |
+
result = await app.stream_reader_document(SimpleNamespace(is_disconnected=is_disconnected), 'fixed')
|
| 1952 |
+
self.assertEqual(result.body, b'ok')
|
| 1953 |
+
self.assertTrue(finished.is_set())
|
| 1954 |
+
self.assertGreaterEqual(len(observed), 2)
|
| 1955 |
+
|
| 1956 |
+
async def test_missing_range_cache_is_initialized_before_streaming(self):
|
| 1957 |
+
state = app.app.state
|
| 1958 |
+
state._state.pop('reader_range_cache', None)
|
| 1959 |
+
state._state.pop('reader_range_cache_bytes', None)
|
| 1960 |
+
state.http_session = object()
|
| 1961 |
+
state.upstream_semaphore = asyncio.Semaphore(1)
|
| 1962 |
+
url = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/synthetic.pdf'
|
| 1963 |
+
response = FakeResponse(206, {'Content-Length': '3', 'Content-Range': 'bytes 2-4/10'}, chunks=(b'abc',))
|
| 1964 |
+
request = SimpleNamespace(method='GET', headers={'Range': 'bytes=2-4'})
|
| 1965 |
+
with patch.object(app, 'open_download_response', AsyncMock(return_value=response)):
|
| 1966 |
+
result = await app._stream_reader_document(request, url, _share_range=False)
|
| 1967 |
+
self.assertEqual(b''.join([part async for part in result.body_iterator]), b'abc')
|
| 1968 |
+
self.assertEqual(len(state.reader_range_cache), 1)
|
| 1969 |
+
self.assertEqual(state.reader_range_cache_bytes, 3)
|
| 1970 |
+
self.assertTrue(response.released)
|
| 1971 |
+
self.assertEqual(state.upstream_semaphore._value, 1)
|
| 1972 |
+
|
| 1973 |
+
async def test_reader_bucket_ebook_chapter_paths_keep_immutable_policy(self):
|
| 1974 |
+
self.assertEqual(app.reader_bucket_cache_control('documents/x/ebook-chapters/chapter.xhtml'),
|
| 1975 |
+
'public, max-age=31536000, immutable')
|
| 1976 |
+
self.assertEqual(app.reader_bucket_cache_control('documents/x/chapter.xhtml'),
|
| 1977 |
+
'public, max-age=3600')
|
| 1978 |
+
|
| 1979 |
+
async def test_image_stream_rejects_body_exceeding_pinned_size_and_releases_slot(self):
|
| 1980 |
+
import hashlib
|
| 1981 |
+
state = app.app.state
|
| 1982 |
+
state.http_session = object()
|
| 1983 |
+
state.upstream_semaphore = asyncio.Semaphore(1)
|
| 1984 |
+
url = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/page.png'
|
| 1985 |
+
response = FakeResponse(200, {'Content-Length': '4'}, chunks=(b'abcde',))
|
| 1986 |
+
request = SimpleNamespace(method='GET', headers={})
|
| 1987 |
+
with patch.object(app, 'open_download_response', AsyncMock(return_value=response)):
|
| 1988 |
+
result = await app._stream_reader_document(request, url,
|
| 1989 |
+
expected_sha256=hashlib.sha256(b'abcd').hexdigest(), expected_bytes=4)
|
| 1990 |
+
with self.assertRaisesRegex(ValueError, 'exceeds its pinned size'):
|
| 1991 |
+
_ = [part async for part in result.body_iterator]
|
| 1992 |
+
self.assertTrue(response.released)
|
| 1993 |
+
self.assertEqual(state.upstream_semaphore._value, 1)
|
| 1994 |
+
|
| 1995 |
+
async def test_pinned_raw_revision_is_defensively_rejected_after_source_validation(self):
|
| 1996 |
+
url = 'https://huggingface.co/datasets/VoiceOfML/Test/raw/' + 'a' * 40 + '/book.djvu'
|
| 1997 |
+
state = app.app.state
|
| 1998 |
+
state.http_session = FakeSession([])
|
| 1999 |
+
with patch.object(app, 'validate_reader_source_url', return_value=url):
|
| 2000 |
+
response = await app.api_reader_source_revision(url)
|
| 2001 |
+
self.assertEqual(response.status_code, 400)
|
| 2002 |
+
self.assertEqual(json.loads(response.body), {'error': '原件版本地址无效'})
|
| 2003 |
+
self.assertEqual(state.http_session.urls, [])
|
| 2004 |
+
|
| 2005 |
async def test_reader_cached_containing_range_serves_exact_slice_without_upstream(self):
|
| 2006 |
upstream = FakeResponse(206, {
|
| 2007 |
"Content-Type": "application/pdf", "Content-Length": "8",
|
tests/search/backend/test_search_order_cache.py
CHANGED
|
@@ -348,6 +348,11 @@ class SearchOrderCacheTests(unittest.TestCase):
|
|
| 348 |
search_folders=folders, sort=sort)
|
| 349 |
self.assertEqual((list(actual), calls), (list(expected), expected_calls))
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
def test_multiple_tokens_with_disjoint_postings_have_no_matches(self):
|
| 352 |
app.records = [self.fixture.rec('VoiceOfML/A', 'alpha', [], 'txt', 1),
|
| 353 |
self.fixture.rec('VoiceOfML/A', 'omega', [], 'txt', 2)]
|
|
|
|
| 348 |
search_folders=folders, sort=sort)
|
| 349 |
self.assertEqual((list(actual), calls), (list(expected), expected_calls))
|
| 350 |
|
| 351 |
+
def test_empty_literal_term_has_no_candidates_and_never_reads_indexes(self):
|
| 352 |
+
with mock.patch.object(app, 'literal_candidates', side_effect=AssertionError('unexpected literal lookup')), \
|
| 353 |
+
mock.patch.object(app, 'get_initial_indices', side_effect=AssertionError('unexpected index lookup')):
|
| 354 |
+
self.assertEqual(app._term_literal_candidates('', ['VoiceOfML/A']), [])
|
| 355 |
+
|
| 356 |
def test_multiple_tokens_with_disjoint_postings_have_no_matches(self):
|
| 357 |
app.records = [self.fixture.rec('VoiceOfML/A', 'alpha', [], 'txt', 1),
|
| 358 |
self.fixture.rec('VoiceOfML/A', 'omega', [], 'txt', 2)]
|