vomebook commited on
Commit
382909e
·
1 Parent(s): 7ab041f

Invalidate search snapshots after matching change

Browse files
backend/app.py CHANGED
@@ -180,7 +180,7 @@ SEARCH_CACHE_TTL_SECONDS = 120
180
  _search_cache: dict[Hashable, tuple[float, object] | tuple[float, object, int]] = {}
181
  _search_instance = uuid4().hex
182
  # Bump when matching, filtering, ordering or public record semantics change.
183
- SEARCH_SEMANTICS_VERSION = "hf-search-v6"
184
  _search_generation: str | None = None
185
  _search_logged_generation: int | None = None
186
  SearchOrderKey = tuple[Hashable, ...]
 
180
  _search_cache: dict[Hashable, tuple[float, object] | tuple[float, object, int]] = {}
181
  _search_instance = uuid4().hex
182
  # Bump when matching, filtering, ordering or public record semantics change.
183
+ SEARCH_SEMANTICS_VERSION = "hf-search-v7"
184
  _search_generation: str | None = None
185
  _search_logged_generation: int | None = None
186
  SearchOrderKey = tuple[Hashable, ...]
scripts/check_backend_coverage.py CHANGED
@@ -34,6 +34,8 @@ SEARCH_RELEASE_TERM_SHA = "dc2251331033e4787f7a4edabdf8de6351b85b1c160fbf1b03927
34
  SEARCH_RELEASE_DEBT_SHA = "d7bed3e96d3cbdc8dc20d9c8f5a92dbc96d4d0f6c2e45fb6237bad9c2c70bed5"
35
  SEARCH_RELEASE_DIFF_SHA = "2155663554e77d4f3ffe4164a154b9c9d4c1ad216f5b7b37d3ba1a6b8e765b85"
36
  SEARCH_SIGMA_APP_SHA = "cd78aa10d6202c71ce7c99bc7da06c0842bbe2adece90f60ff01347a1eafda02"
 
 
37
  SEARCH_SIGMA_OLD_DEBT_SHA = "0326c931227ea305f66e2ca42108a288660d2b88e530bed6637a1f57d92618a3"
38
 
39
 
@@ -1391,7 +1393,8 @@ def coverage_errors(root: Path, report: dict[str, object], baseline: dict[str, d
1391
  "931758f2f2b76b4cbe51a00b3a5f408c48d9b4e42104476ee21cdd49a083b56d")
1392
  sigma_source = root / "scripts/coverage-anchors/search-sigma-new-app.py.snapshot"
1393
  sigma_debt = root / "scripts/coverage-anchors/search-sigma-old-debt.json"
1394
- reviewed_sigma = (source_sha == SEARCH_SIGMA_APP_SHA and sigma_source.exists() and sigma_debt.exists() and
 
1395
  hashlib.sha256(sigma_source.read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA and
1396
  hashlib.sha256(sigma_debt.read_bytes()).hexdigest() == SEARCH_SIGMA_OLD_DEBT_SHA)
1397
  release_source_sha = SEARCH_RELEASE_APP_SHA if reviewed_sigma else source_sha
@@ -1653,7 +1656,8 @@ def main() -> int:
1653
  sigma_layout = (sigma_new.exists() and sigma_debt.exists() and
1654
  hashlib.sha256(sigma_new.read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA and
1655
  hashlib.sha256(sigma_debt.read_bytes()).hexdigest() == SEARCH_SIGMA_OLD_DEBT_SHA and
1656
- hashlib.sha256((ROOT / "backend/app.py").read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA)
 
1657
  release_layout = (release_old.exists() and release_new.exists() and
1658
  (sigma_layout or hashlib.sha256((ROOT / "backend/app.py").read_bytes()).hexdigest() == SEARCH_RELEASE_APP_SHA))
1659
  direct_release_parent = (previous is not None and release_layout and release_debt.exists() and
 
34
  SEARCH_RELEASE_DEBT_SHA = "d7bed3e96d3cbdc8dc20d9c8f5a92dbc96d4d0f6c2e45fb6237bad9c2c70bed5"
35
  SEARCH_RELEASE_DIFF_SHA = "2155663554e77d4f3ffe4164a154b9c9d4c1ad216f5b7b37d3ba1a6b8e765b85"
36
  SEARCH_SIGMA_APP_SHA = "cd78aa10d6202c71ce7c99bc7da06c0842bbe2adece90f60ff01347a1eafda02"
37
+ # A reviewed constant-only change keeps every sigma-layout coordinate intact.
38
+ SEARCH_SIGMA_VERSION_APP_SHA = "20f24996fd3366a6e3bb903fd959f26385fe02c16037793c59b51a953cd1c63f"
39
  SEARCH_SIGMA_OLD_DEBT_SHA = "0326c931227ea305f66e2ca42108a288660d2b88e530bed6637a1f57d92618a3"
40
 
41
 
 
1393
  "931758f2f2b76b4cbe51a00b3a5f408c48d9b4e42104476ee21cdd49a083b56d")
1394
  sigma_source = root / "scripts/coverage-anchors/search-sigma-new-app.py.snapshot"
1395
  sigma_debt = root / "scripts/coverage-anchors/search-sigma-old-debt.json"
1396
+ reviewed_sigma = (source_sha in (SEARCH_SIGMA_APP_SHA, SEARCH_SIGMA_VERSION_APP_SHA)
1397
+ and sigma_source.exists() and sigma_debt.exists() and
1398
  hashlib.sha256(sigma_source.read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA and
1399
  hashlib.sha256(sigma_debt.read_bytes()).hexdigest() == SEARCH_SIGMA_OLD_DEBT_SHA)
1400
  release_source_sha = SEARCH_RELEASE_APP_SHA if reviewed_sigma else source_sha
 
1656
  sigma_layout = (sigma_new.exists() and sigma_debt.exists() and
1657
  hashlib.sha256(sigma_new.read_bytes()).hexdigest() == SEARCH_SIGMA_APP_SHA and
1658
  hashlib.sha256(sigma_debt.read_bytes()).hexdigest() == SEARCH_SIGMA_OLD_DEBT_SHA and
1659
+ hashlib.sha256((ROOT / "backend/app.py").read_bytes()).hexdigest() in
1660
+ (SEARCH_SIGMA_APP_SHA, SEARCH_SIGMA_VERSION_APP_SHA))
1661
  release_layout = (release_old.exists() and release_new.exists() and
1662
  (sigma_layout or hashlib.sha256((ROOT / "backend/app.py").read_bytes()).hexdigest() == SEARCH_RELEASE_APP_SHA))
1663
  direct_release_parent = (previous is not None and release_layout and release_debt.exists() and
tests/gates/test_quality_inventory.py CHANGED
@@ -2240,6 +2240,16 @@ class Example:
2240
  self.assertNotEqual(result.returncode, 0)
2241
  self.assertIn("coverage migration failed", result.stderr)
2242
 
 
 
 
 
 
 
 
 
 
 
2243
  def test_search_sigma_migration_preserves_coverage_and_rejects_tampering(self):
2244
  root = Path(__file__).resolve().parents[2]
2245
  old, new = ANCHORS / 'search-release-new-app.py.snapshot', ANCHORS / 'search-sigma-new-app.py.snapshot'
 
2240
  self.assertNotEqual(result.returncode, 0)
2241
  self.assertIn("coverage migration failed", result.stderr)
2242
 
2243
+ def test_search_sigma_semantics_version_bump_is_only_reviewed_source_change(self):
2244
+ root = Path(__file__).resolve().parents[2]
2245
+ old = (ANCHORS / 'search-sigma-new-app.py.snapshot').read_text()
2246
+ current = (root / 'backend/app.py').read_text()
2247
+ before = 'SEARCH_SEMANTICS_VERSION = "hf-search-v6"'
2248
+ after = 'SEARCH_SEMANTICS_VERSION = "hf-search-v7"'
2249
+ self.assertEqual(old.count(before), 1)
2250
+ self.assertEqual(current, old.replace(before, after))
2251
+ self.assertEqual(len(old.splitlines()), len(current.splitlines()))
2252
+
2253
  def test_search_sigma_migration_preserves_coverage_and_rejects_tampering(self):
2254
  root = Path(__file__).resolve().parents[2]
2255
  old, new = ANCHORS / 'search-release-new-app.py.snapshot', ANCHORS / 'search-sigma-new-app.py.snapshot'
tests/search/backend/test_search_order_cache.py CHANGED
@@ -185,6 +185,11 @@ class SearchOrderCacheTests(unittest.TestCase):
185
  index.write_bytes(b'words')
186
  with mock.patch.object(app, 'SEARCH_SEMANTICS_VERSION', 'next'):
187
  self.assertNotEqual(first, app.search_data_generation(b'corpus', [index]))
 
 
 
 
 
188
 
189
  def test_initial_payload_and_search_share_the_validated_generation(self):
190
  with mock.patch.object(app, '_search_generation', 'api:stable'):
 
185
  index.write_bytes(b'words')
186
  with mock.patch.object(app, 'SEARCH_SEMANTICS_VERSION', 'next'):
187
  self.assertNotEqual(first, app.search_data_generation(b'corpus', [index]))
188
+ # The contextual-sigma matching fix changed results without changing
189
+ # corpus/index bytes. Its generation must not reuse v6 snapshots.
190
+ self.assertEqual(app.SEARCH_SEMANTICS_VERSION, 'hf-search-v7')
191
+ with mock.patch.object(app, 'SEARCH_SEMANTICS_VERSION', 'hf-search-v6'):
192
+ self.assertNotEqual(first, app.search_data_generation(b'corpus', [index]))
193
 
194
  def test_initial_payload_and_search_share_the_validated_generation(self):
195
  with mock.patch.object(app, '_search_generation', 'api:stable'):