vomebook commited on
Commit ·
382909e
1
Parent(s): 7ab041f
Invalidate search snapshots after matching change
Browse filesFiles changed (4)
179 unmodified lines180181182183184185186179 unmodified lines_search_cache: dict[Hashable, tuple[float, object] | tuple[float, object, int]] = {}_search_instance = uuid4().hex# Bump when matching, filtering, ordering or public record semantics change.SEARCH_SEMANTICS_VERSION = "hf-search-v6"_search_generation: str | None = None_search_logged_generation: int | None = NoneSearchOrderKey = tuple[Hashable, ...]179 unmodified lines180181182183184185186179 unmodified lines_search_cache: dict[Hashable, tuple[float, object] | tuple[float, object, int]] = {}_search_instance = uuid4().hex# Bump when matching, filtering, ordering or public record semantics change.SEARCH_SEMANTICS_VERSION = "hf-search-v7"_search_generation: str | None = None_search_logged_generation: int | None = NoneSearchOrderKey = tuple[Hashable, ...]
33 unmodified lines3435363738391351 unmodified lines1391139213931394139513961397255 unmodified lines165316541655165616571658165933 unmodified linesSEARCH_RELEASE_DEBT_SHA = "d7bed3e96d3cbdc8dc20d9c8f5a92dbc96d4d0f6c2e45fb6237bad9c2c70bed5"SEARCH_RELEASE_DIFF_SHA = "2155663554e77d4f3ffe4164a154b9c9d4c1ad216f5b7b37d3ba1a6b8e765b85"SEARCH_SIGMA_APP_SHA = "cd78aa10d6202c71ce7c99bc7da06c0842bbe2adece90f60ff01347a1eafda02"SEARCH_SIGMA_OLD_DEBT_SHA = "0326c931227ea305f66e2ca42108a288660d2b88e530bed6637a1f57d92618a3"1351 unmodified lines"931758f2f2b76b4cbe51a00b3a5f408c48d9b4e42104476ee21cdd49a083b56d")sigma_source = root / "scripts/coverage-anchors/search-sigma-new-app.py.snapshot"sigma_debt = root / "scripts/coverage-anchors/search-sigma-old-debt.json"reviewed_sigma = (source_sha == SEARCH_SIGMA_APP_SHA and sigma_source.exists() and sigma_debt.exists() andhashlib.sha256(sigma_source.read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA andhashlib.sha256(sigma_debt.read_bytes()).hexdigest() == SEARCH_SIGMA_OLD_DEBT_SHA)release_source_sha = SEARCH_RELEASE_APP_SHA if reviewed_sigma else source_sha255 unmodified linessigma_layout = (sigma_new.exists() and sigma_debt.exists() andhashlib.sha256(sigma_new.read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA andhashlib.sha256(sigma_debt.read_bytes()).hexdigest() == SEARCH_SIGMA_OLD_DEBT_SHA andhashlib.sha256((ROOT / "backend/app.py").read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA)release_layout = (release_old.exists() and release_new.exists() and(sigma_layout or hashlib.sha256((ROOT / "backend/app.py").read_bytes()).hexdigest() == SEARCH_RELEASE_APP_SHA))direct_release_parent = (previous is not None and release_layout and release_debt.exists() and33 unmodified lines34353637383940411351 unmodified lines13931394139513961397139813991400255 unmodified lines1656165716581659166016611662166333 unmodified linesSEARCH_RELEASE_DEBT_SHA = "d7bed3e96d3cbdc8dc20d9c8f5a92dbc96d4d0f6c2e45fb6237bad9c2c70bed5"SEARCH_RELEASE_DIFF_SHA = "2155663554e77d4f3ffe4164a154b9c9d4c1ad216f5b7b37d3ba1a6b8e765b85"SEARCH_SIGMA_APP_SHA = "cd78aa10d6202c71ce7c99bc7da06c0842bbe2adece90f60ff01347a1eafda02"# A reviewed constant-only change keeps every sigma-layout coordinate intact.SEARCH_SIGMA_VERSION_APP_SHA = "20f24996fd3366a6e3bb903fd959f26385fe02c16037793c59b51a953cd1c63f"SEARCH_SIGMA_OLD_DEBT_SHA = "0326c931227ea305f66e2ca42108a288660d2b88e530bed6637a1f57d92618a3"1351 unmodified lines"931758f2f2b76b4cbe51a00b3a5f408c48d9b4e42104476ee21cdd49a083b56d")sigma_source = root / "scripts/coverage-anchors/search-sigma-new-app.py.snapshot"sigma_debt = root / "scripts/coverage-anchors/search-sigma-old-debt.json"reviewed_sigma = (source_sha in (SEARCH_SIGMA_APP_SHA, SEARCH_SIGMA_VERSION_APP_SHA)and sigma_source.exists() and sigma_debt.exists() andhashlib.sha256(sigma_source.read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA andhashlib.sha256(sigma_debt.read_bytes()).hexdigest() == SEARCH_SIGMA_OLD_DEBT_SHA)release_source_sha = SEARCH_RELEASE_APP_SHA if reviewed_sigma else source_sha255 unmodified linessigma_layout = (sigma_new.exists() and sigma_debt.exists() andhashlib.sha256(sigma_new.read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA andhashlib.sha256(sigma_debt.read_bytes()).hexdigest() == SEARCH_SIGMA_OLD_DEBT_SHA andhashlib.sha256((ROOT / "backend/app.py").read_bytes()).hexdigest() in(SEARCH_SIGMA_APP_SHA, SEARCH_SIGMA_VERSION_APP_SHA))release_layout = (release_old.exists() and release_new.exists() and(sigma_layout or hashlib.sha256((ROOT / "backend/app.py").read_bytes()).hexdigest() == SEARCH_RELEASE_APP_SHA))direct_release_parent = (previous is not None and release_layout and release_debt.exists() and
2239 unmodified lines2240224122422243224422452239 unmodified linesself.assertNotEqual(result.returncode, 0)self.assertIn("coverage migration failed", result.stderr)def test_search_sigma_migration_preserves_coverage_and_rejects_tampering(self):root = Path(__file__).resolve().parents[2]old, new = ANCHORS / 'search-release-new-app.py.snapshot', ANCHORS / 'search-sigma-new-app.py.snapshot'2239 unmodified lines22402241224222432244224522462247224822492250225122522253225422552239 unmodified linesself.assertNotEqual(result.returncode, 0)self.assertIn("coverage migration failed", result.stderr)def test_search_sigma_semantics_version_bump_is_only_reviewed_source_change(self):root = Path(__file__).resolve().parents[2]old = (ANCHORS / 'search-sigma-new-app.py.snapshot').read_text()current = (root / 'backend/app.py').read_text()before = 'SEARCH_SEMANTICS_VERSION = "hf-search-v6"'after = 'SEARCH_SEMANTICS_VERSION = "hf-search-v7"'self.assertEqual(old.count(before), 1)self.assertEqual(current, old.replace(before, after))self.assertEqual(len(old.splitlines()), len(current.splitlines()))def test_search_sigma_migration_preserves_coverage_and_rejects_tampering(self):root = Path(__file__).resolve().parents[2]old, new = ANCHORS / 'search-release-new-app.py.snapshot', ANCHORS / 'search-sigma-new-app.py.snapshot'
184 unmodified lines185186187188189190184 unmodified linesindex.write_bytes(b'words')with mock.patch.object(app, 'SEARCH_SEMANTICS_VERSION', 'next'):self.assertNotEqual(first, app.search_data_generation(b'corpus', [index]))def test_initial_payload_and_search_share_the_validated_generation(self):with mock.patch.object(app, '_search_generation', 'api:stable'):184 unmodified lines185186187188189190191192193194195184 unmodified linesindex.write_bytes(b'words')with mock.patch.object(app, 'SEARCH_SEMANTICS_VERSION', 'next'):self.assertNotEqual(first, app.search_data_generation(b'corpus', [index]))# The contextual-sigma matching fix changed results without changing# corpus/index bytes. Its generation must not reuse v6 snapshots.self.assertEqual(app.SEARCH_SEMANTICS_VERSION, 'hf-search-v7')with mock.patch.object(app, 'SEARCH_SEMANTICS_VERSION', 'hf-search-v6'):self.assertNotEqual(first, app.search_data_generation(b'corpus', [index]))def test_initial_payload_and_search_share_the_validated_generation(self):with mock.patch.object(app, '_search_generation', 'api:stable'):
backend/app.py+1-1
scripts/check_backend_coverage.py+6-2
tests/gates/test_quality_inventory.py+10
tests/search/backend/test_search_order_cache.py+5