symgrep-codesearch 0.9.3__tar.gz → 0.9.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. {symgrep_codesearch-0.9.3/src/symgrep_codesearch.egg-info → symgrep_codesearch-0.9.4}/PKG-INFO +1 -1
  2. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/pyproject.toml +1 -1
  3. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/semantic.py +3 -0
  4. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/semantic_sqlite.py +24 -2
  5. symgrep_codesearch-0.9.4/src/symgrep/semantic_sqlite_maintenance.py +37 -0
  6. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4/src/symgrep_codesearch.egg-info}/PKG-INFO +1 -1
  7. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/SOURCES.txt +2 -0
  8. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_sqlite_ivf_retrieval_pytest.py +13 -0
  9. symgrep_codesearch-0.9.4/tests/test_sqlite_maintenance_pytest.py +79 -0
  10. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/LICENSE +0 -0
  11. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/README.md +0 -0
  12. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/setup.cfg +0 -0
  13. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/__init__.py +0 -0
  14. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/absence_adjudication_writer.py +0 -0
  15. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/archives.py +0 -0
  16. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/blocks.py +0 -0
  17. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/capability_registry.py +0 -0
  18. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/capability_registry_data.jsonl +0 -0
  19. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/capability_surface_checks.py +0 -0
  20. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/classfile.py +0 -0
  21. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/cli.py +0 -0
  22. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/data_symbols.py +0 -0
  23. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/docsymbols.py +0 -0
  24. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/embedding_process.py +0 -0
  25. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/enclosing.py +0 -0
  26. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/glob_recall.py +0 -0
  27. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/mcp_server.py +0 -0
  28. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/mcp_structured.py +0 -0
  29. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/report.py +0 -0
  30. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/resolve.py +0 -0
  31. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/resolve_js.py +0 -0
  32. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/resolve_python.py +0 -0
  33. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/ripgrep.py +0 -0
  34. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/rss_ceiling.py +0 -0
  35. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/runtime_paths.py +0 -0
  36. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/semantic_ivf.py +0 -0
  37. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/semantic_sqlite_config.py +0 -0
  38. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/structural.py +0 -0
  39. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep/structure.py +0 -0
  40. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/dependency_links.txt +0 -0
  41. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/entry_points.txt +0 -0
  42. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/requires.txt +0 -0
  43. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/top_level.txt +0 -0
  44. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_absence_adjudication_authorship_pytest.py +0 -0
  45. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_absence_adjudication_binding_pytest.py +0 -0
  46. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_blocks_extraction.py +0 -0
  47. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_blocks_retrieval.py +0 -0
  48. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_bulk_describe.py +0 -0
  49. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_capability_documentation_guard_pytest.py +0 -0
  50. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_capability_surface_parity_guard_pytest.py +0 -0
  51. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_classfile.py +0 -0
  52. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_codex_hook_payload.py +0 -0
  53. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_daemon_deleted_cwd_pytest.py +0 -0
  54. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_data_symbols.py +0 -0
  55. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_describe_lane_confinement.py +0 -0
  56. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_doc_symbols.py +0 -0
  57. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_embedding_residency_pytest.py +0 -0
  58. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_file_structure.py +0 -0
  59. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_freshness.py +0 -0
  60. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_honest_recall.py +0 -0
  61. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_http_ensure.py +0 -0
  62. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_http_rss_shutdown_pytest.py +0 -0
  63. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_index_reconstruct.py +0 -0
  64. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_index_scope.py +0 -0
  65. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_index_worker.py +0 -0
  66. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_mcp_error_log.py +0 -0
  67. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_mcp_registry_behavior_pytest.py +0 -0
  68. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_mcp_structured.py +0 -0
  69. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_mcp_thread_safety.py +0 -0
  70. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_mcp_version.py +0 -0
  71. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_name_uniqueness.py +0 -0
  72. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_nudge_classify.py +0 -0
  73. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_nudge_runaway.py +0 -0
  74. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_report_filters.py +0 -0
  75. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_resolve.py +0 -0
  76. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_resolve_js.py +0 -0
  77. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_resolve_python.py +0 -0
  78. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_resolve_r2.py +0 -0
  79. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_review_regressions.py +0 -0
  80. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_rss_ceiling_pytest.py +0 -0
  81. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_semantic_census_pruning_pytest.py +0 -0
  82. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_semantic_freshness_signal.py +0 -0
  83. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_semantic_glob_lang.py +0 -0
  84. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_sites_and_symbols.py +0 -0
  85. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_sqlite_streaming_retrieval_pytest.py +0 -0
  86. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_structural.py +0 -0
  87. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_symbol_vocabulary.py +0 -0
  88. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_ts_fallback_loud.py +0 -0
  89. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_ts_symbol_coverage.py +0 -0
  90. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_usage.py +0 -0
  91. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_veccore_adoption.py +0 -0
  92. {symgrep_codesearch-0.9.3 → symgrep_codesearch-0.9.4}/tests/test_worker_lock_recovery_pytest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: symgrep-codesearch
3
- Version: 0.9.3
3
+ Version: 0.9.4
4
4
  Summary: Code search with honest recall — structure-aware grep that tells you what it does not know, plus search by meaning
5
5
  License-Expression: MIT
6
6
  Project-URL: Repository, https://github.com/ashdamle/symgrep
@@ -41,7 +41,7 @@ name = "symgrep-codesearch"
41
41
  # semantic search. Minor bump (dependency surface changed; no breaking import/CLI/MCP change).
42
42
  # 0.5.0: added the public `file_structure` library API (+ its MCP tool and `symgrep structure` CLI), import
43
43
  # module-name normalization, and the FileStructure `connects` list (structure schema v2).
44
- version = "0.9.3"
44
+ version = "0.9.4"
45
45
  description = "Code search with honest recall — structure-aware grep that tells you what it does not know, plus search by meaning"
46
46
  readme = "README.md"
47
47
  # 3.11+ : the maintained grammar pack (tree-sitter-language-pack, a CORE dep below) ships abi3 wheels for
@@ -258,6 +258,8 @@ def _open_index(INDEX):
258
258
  """Open the sqlite index with the efficient-and-safe pragmas + ensure/migrate schema. Raises sqlite errors
259
259
  to the caller, which decides lock (retry) vs corruption (reconstruct)."""
260
260
  con = sqlite3.connect(str(INDEX), timeout=10)
261
+ from .semantic_sqlite_maintenance import initialize_semantic_sqlite_layout, refresh_semantic_sqlite_statistics
262
+ initialize_semantic_sqlite_layout(con)
261
263
  con.execute("PRAGMA busy_timeout=10000") # veccore's store shares this file; tolerate its writes
262
264
  # WAL + synchronous=NORMAL is the recommended efficient-and-safe pair, set together so the safety guarantee
263
265
  # is self-contained: NORMAL drops FULL's per-commit fsync of the WAL (so the per-unit commits the describe/
@@ -268,6 +270,7 @@ def _open_index(INDEX):
268
270
  con.execute("PRAGMA synchronous=NORMAL")
269
271
  _ensure_book_schema(con)
270
272
  _migrate_to_veccore(con) # one-time: move vectors into veccore, drop the emb column
273
+ refresh_semantic_sqlite_statistics(con, missing_only=True)
271
274
  return con
272
275
 
273
276
 
@@ -10,7 +10,7 @@ import os
10
10
  import queue
11
11
  import sqlite3
12
12
  import threading
13
- from contextlib import contextmanager
13
+ from contextlib import contextmanager, closing
14
14
 
15
15
  import numpy as np
16
16
  from veccore.adapters.sqlite_numpy_store import SqliteNumpyStore
@@ -33,6 +33,19 @@ class SqliteStreamingStore(SqliteNumpyStore):
33
33
  if min(IVF_PROBE_COUNT, IVF_BUCKET_COUNT, IVF_TRAINING_ROWS,
34
34
  IVF_TRAINING_ITERATIONS, IVF_ASSIGNMENT_ROWS) <= 0 or IVF_PROBE_GROWTH <= 1 or IVF_RANDOM_SEED < 0:
35
35
  raise ValueError("IVF configuration must have positive workspace/probe sizes, growth > 1 and a nonnegative seed")
36
+ from .semantic_sqlite_maintenance import initialize_semantic_sqlite_layout
37
+ # veccore creates tables in its constructor: choose the layout first.
38
+ from pathlib import Path
39
+ if path != ":memory:":
40
+ bootstrap_path = Path(path).expanduser()
41
+ bootstrap_path.parent.mkdir(parents=True, exist_ok=True)
42
+ try:
43
+ with closing(sqlite3.connect(bootstrap_path)) as bootstrap_connection:
44
+ initialize_semantic_sqlite_layout(bootstrap_connection)
45
+ except sqlite3.Error as error:
46
+ from veccore.errors import Unavailable
47
+ raise Unavailable("semantic SQLite layout could not be initialized",
48
+ code="store_unusable") from error
36
49
  super().__init__(path)
37
50
  if SQLITE_READER_COUNT <= 0 or SQLITE_READER_MMAP_BYTES < 0 or SQLITE_READER_CACHE_KIB <= 0:
38
51
  raise ValueError("SQLite reader configuration must be bounded and positive")
@@ -52,6 +65,9 @@ class SqliteStreamingStore(SqliteNumpyStore):
52
65
  with self._con_lock:
53
66
  initialize_ivf_schema(self._con)
54
67
  self._ivf_schema_available = True
68
+ from .semantic_sqlite_maintenance import refresh_semantic_sqlite_statistics
69
+ with self._con_lock:
70
+ refresh_semantic_sqlite_statistics(self._con, missing_only=True)
55
71
  except sqlite3.Error as error:
56
72
  self._log_ivf_fallback(str(error))
57
73
 
@@ -63,7 +79,13 @@ class SqliteStreamingStore(SqliteNumpyStore):
63
79
 
64
80
  def prepare_ann_index(self, collection):
65
81
  try:
66
- return self._prepare_ivf_generation(collection)
82
+ prepared = self._prepare_ivf_generation(collection)
83
+ # The generation transaction has exited and committed before ANALYZE.
84
+ from .semantic_sqlite_maintenance import refresh_semantic_sqlite_statistics, reclaim_semantic_sqlite_pages
85
+ with self._con_lock:
86
+ refresh_semantic_sqlite_statistics(self._con)
87
+ reclaim_semantic_sqlite_pages(self._con)
88
+ return prepared
67
89
  except (sqlite3.Error, OSError, ValueError) as error:
68
90
  with self._con_lock:
69
91
  self._con.rollback()
@@ -0,0 +1,37 @@
1
+ """Statistics and bounded page reclamation for the semantic SQLite index.
2
+
3
+ Existing NONE databases keep their layout until physical recreation; switching
4
+ that layout requires a full VACUUM, which normal index maintenance never forces.
5
+ """
6
+ import sqlite3
7
+
8
+ SQLITE_INCREMENTAL_LAYOUT = "INCREMENTAL"
9
+ SQLITE_INCREMENTAL_MODE = 2
10
+ SQLITE_INCREMENTAL_PAGE_BUDGET = 256 # Bound each post-index reclamation pass.
11
+ SQLITE_STATISTICS_REFRESH = "ANALYZE"
12
+ SQLITE_LAYOUT_INITIALIZATION = f"PRAGMA auto_vacuum={SQLITE_INCREMENTAL_LAYOUT}"
13
+ SQLITE_LAYOUT_INSPECTION = "PRAGMA auto_vacuum"
14
+ SQLITE_INCREMENTAL_RECLAMATION = f"PRAGMA incremental_vacuum({SQLITE_INCREMENTAL_PAGE_BUDGET})"
15
+ SQLITE_STATISTICS_PRESENT = "SELECT 1 FROM sqlite_master WHERE name='sqlite_stat1' AND type='table'"
16
+ SQLITE_SCHEMA_PRESENT = "SELECT 1 FROM sqlite_master LIMIT 1"
17
+
18
+
19
+ def initialize_semantic_sqlite_layout(connection):
20
+ """Set pointer-map layout only before the first schema is created."""
21
+ if connection.execute(SQLITE_SCHEMA_PRESENT).fetchone() is None:
22
+ connection.execute(SQLITE_LAYOUT_INITIALIZATION)
23
+
24
+
25
+ def refresh_semantic_sqlite_statistics(connection, *, missing_only=False):
26
+ """Analyze committed final shape; do not commit a caller's pending writes."""
27
+ if connection.in_transaction:
28
+ raise sqlite3.ProgrammingError("semantic statistics require committed index writes")
29
+ if not missing_only or connection.execute(SQLITE_STATISTICS_PRESENT).fetchone() is None:
30
+ with connection:
31
+ connection.execute(SQLITE_STATISTICS_REFRESH)
32
+
33
+
34
+ def reclaim_semantic_sqlite_pages(connection):
35
+ """Return a bounded number of pages only on incremental-layout databases."""
36
+ if connection.execute(SQLITE_LAYOUT_INSPECTION).fetchone()[0] == SQLITE_INCREMENTAL_MODE:
37
+ connection.execute(SQLITE_INCREMENTAL_RECLAMATION).fetchall()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: symgrep-codesearch
3
- Version: 0.9.3
3
+ Version: 0.9.4
4
4
  Summary: Code search with honest recall — structure-aware grep that tells you what it does not know, plus search by meaning
5
5
  License-Expression: MIT
6
6
  Project-URL: Repository, https://github.com/ashdamle/symgrep
@@ -28,6 +28,7 @@ src/symgrep/semantic.py
28
28
  src/symgrep/semantic_ivf.py
29
29
  src/symgrep/semantic_sqlite.py
30
30
  src/symgrep/semantic_sqlite_config.py
31
+ src/symgrep/semantic_sqlite_maintenance.py
31
32
  src/symgrep/structural.py
32
33
  src/symgrep/structure.py
33
34
  src/symgrep_codesearch.egg-info/PKG-INFO
@@ -78,6 +79,7 @@ tests/test_semantic_freshness_signal.py
78
79
  tests/test_semantic_glob_lang.py
79
80
  tests/test_sites_and_symbols.py
80
81
  tests/test_sqlite_ivf_retrieval_pytest.py
82
+ tests/test_sqlite_maintenance_pytest.py
81
83
  tests/test_sqlite_streaming_retrieval_pytest.py
82
84
  tests/test_structural.py
83
85
  tests/test_symbol_vocabulary.py
@@ -276,3 +276,16 @@ def test_ivf_unit_parser_uses_registry_members_and_rejects_undeclared_plural(pre
276
276
  with pytest.raises(ValueError, match="Invalid semantic unit"):
277
277
  search_method(IVF_TEST_COLLECTION, vectors[0], IVF_TEST_K_VALUES[0],
278
278
  {"symgrep_unit": invalid_ivf_unit})
279
+
280
+
281
+ def test_ivf_reindex_refreshes_statistics_after_committed_postings(prepared_ivf_contract_store):
282
+ store, _vectors = prepared_ivf_contract_store
283
+ with sqlite3.connect(store.path) as reader:
284
+ stat = reader.execute("SELECT stat FROM sqlite_stat1 WHERE idx='symgrep_ivf_covering_members'").fetchone()
285
+ assert int(stat[0].split()[0]) == IVF_TEST_ROWS
286
+ with store._con_lock, store._con:
287
+ store._con.execute("DROP TABLE sqlite_stat1")
288
+ assert store.prepare_ann_index(IVF_TEST_COLLECTION)
289
+ with sqlite3.connect(store.path) as reader:
290
+ stat = reader.execute("SELECT stat FROM sqlite_stat1 WHERE idx='symgrep_ivf_covering_members'").fetchone()
291
+ assert int(stat[0].split()[0]) == IVF_TEST_ROWS
@@ -0,0 +1,79 @@
1
+ """Statistics follow committed generations; existing layouts avoid rewrites."""
2
+ import sqlite3
3
+
4
+ from symgrep import semantic
5
+ from symgrep.semantic_sqlite import SqliteStreamingStore
6
+ from symgrep.semantic_sqlite_maintenance import SQLITE_INCREMENTAL_MODE
7
+
8
+ MAINTENANCE_TEST_FILENAME = "planner.sqlite"
9
+ MAINTENANCE_LEGACY_LAYOUT = 0
10
+
11
+
12
+ def test_semantic_first_open_adds_missing_statistics_without_rewriting(tmp_path):
13
+ database = tmp_path / MAINTENANCE_TEST_FILENAME
14
+ with sqlite3.connect(database) as connection:
15
+ connection.execute("CREATE TABLE maintenance_fixture(value INTEGER PRIMARY KEY)")
16
+ assert connection.execute("SELECT name FROM sqlite_master WHERE name='sqlite_stat1'").fetchone() is None
17
+ connection = semantic._open_index(database)
18
+ try:
19
+ assert connection.execute("SELECT name FROM sqlite_master WHERE name='sqlite_stat1'").fetchone()
20
+ assert connection.execute("PRAGMA auto_vacuum").fetchone()[0] == MAINTENANCE_LEGACY_LAYOUT
21
+ finally:
22
+ connection.close()
23
+
24
+
25
+ def test_semantic_new_database_chooses_incremental_layout(tmp_path):
26
+ database = tmp_path / MAINTENANCE_TEST_FILENAME
27
+ connection = semantic._open_index(database)
28
+ assert connection.execute("PRAGMA auto_vacuum").fetchone()[0] == SQLITE_INCREMENTAL_MODE
29
+ connection.close()
30
+ store = SqliteStreamingStore(str(tmp_path / ("store_" + MAINTENANCE_TEST_FILENAME)))
31
+ try:
32
+ assert store._con.execute("PRAGMA auto_vacuum").fetchone()[0] == SQLITE_INCREMENTAL_MODE
33
+ finally:
34
+ store.close()
35
+
36
+
37
+ def test_semantic_statistics_refuses_pending_write_without_committing(tmp_path):
38
+ import pytest
39
+ from symgrep.semantic_sqlite_maintenance import refresh_semantic_sqlite_statistics
40
+ connection = sqlite3.connect(tmp_path / MAINTENANCE_TEST_FILENAME)
41
+ connection.execute("CREATE TABLE maintenance_pending(value INTEGER)")
42
+ connection.execute("INSERT INTO maintenance_pending VALUES(?)", (SQLITE_INCREMENTAL_MODE,))
43
+ with pytest.raises(sqlite3.ProgrammingError):
44
+ refresh_semantic_sqlite_statistics(connection)
45
+ assert connection.in_transaction
46
+ connection.rollback()
47
+ assert connection.execute("SELECT COUNT(*) FROM maintenance_pending").fetchone()[0] == 0
48
+ connection.close()
49
+
50
+
51
+ def test_semantic_incremental_reclamation_returns_only_bounded_pages(tmp_path):
52
+ from symgrep.semantic_sqlite_maintenance import (
53
+ initialize_semantic_sqlite_layout, reclaim_semantic_sqlite_pages,
54
+ SQLITE_INCREMENTAL_PAGE_BUDGET,
55
+ )
56
+ connection = sqlite3.connect(tmp_path / MAINTENANCE_TEST_FILENAME)
57
+ initialize_semantic_sqlite_layout(connection)
58
+ connection.execute("CREATE TABLE maintenance_pages(payload BLOB)")
59
+ page_size = connection.execute("PRAGMA page_size").fetchone()[0]
60
+ with connection:
61
+ connection.executemany("INSERT INTO maintenance_pages VALUES(?)",
62
+ ((bytes(page_size),) for _ in range(SQLITE_INCREMENTAL_PAGE_BUDGET * 2)))
63
+ with connection:
64
+ connection.execute("DELETE FROM maintenance_pages")
65
+ before = connection.execute("PRAGMA freelist_count").fetchone()[0]
66
+ reclaim_semantic_sqlite_pages(connection)
67
+ after = connection.execute("PRAGMA freelist_count").fetchone()[0]
68
+ assert 0 < before - after <= SQLITE_INCREMENTAL_PAGE_BUDGET
69
+ connection.close()
70
+
71
+
72
+ def test_semantic_bootstrap_preserves_unavailable_error_contract(tmp_path):
73
+ import pytest
74
+ from veccore.errors import Unavailable
75
+ database = tmp_path / MAINTENANCE_TEST_FILENAME
76
+ database.write_bytes(MAINTENANCE_TEST_FILENAME.encode())
77
+ with pytest.raises(Unavailable) as failure:
78
+ SqliteStreamingStore(str(database))
79
+ assert failure.value.code == "store_unusable"