symgrep-codesearch 0.9.2__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.
- {symgrep_codesearch-0.9.2/src/symgrep_codesearch.egg-info → symgrep_codesearch-0.9.4}/PKG-INFO +1 -1
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/pyproject.toml +1 -1
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/cli.py +7 -6
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/mcp_server.py +8 -3
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/mcp_structured.py +2 -1
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/report.py +3 -2
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/resolve.py +2 -1
- symgrep_codesearch-0.9.4/src/symgrep/runtime_paths.py +77 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/semantic.py +3 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/semantic_sqlite.py +24 -2
- symgrep_codesearch-0.9.4/src/symgrep/semantic_sqlite_maintenance.py +37 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4/src/symgrep_codesearch.egg-info}/PKG-INFO +1 -1
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/SOURCES.txt +3 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_blocks_extraction.py +2 -1
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_blocks_retrieval.py +4 -2
- symgrep_codesearch-0.9.4/tests/test_daemon_deleted_cwd_pytest.py +171 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_data_symbols.py +4 -2
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_file_structure.py +2 -1
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_freshness.py +3 -6
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_index_reconstruct.py +6 -3
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_nudge_classify.py +2 -1
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_semantic_freshness_signal.py +2 -1
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_semantic_glob_lang.py +9 -6
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_sqlite_ivf_retrieval_pytest.py +13 -0
- symgrep_codesearch-0.9.4/tests/test_sqlite_maintenance_pytest.py +79 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_symbol_vocabulary.py +8 -4
- symgrep_codesearch-0.9.2/src/symgrep/runtime_paths.py +0 -26
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/LICENSE +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/README.md +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/setup.cfg +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/__init__.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/absence_adjudication_writer.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/archives.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/blocks.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/capability_registry.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/capability_registry_data.jsonl +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/capability_surface_checks.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/classfile.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/data_symbols.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/docsymbols.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/embedding_process.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/enclosing.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/glob_recall.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/resolve_js.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/resolve_python.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/ripgrep.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/rss_ceiling.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/semantic_ivf.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/semantic_sqlite_config.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/structural.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/structure.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/dependency_links.txt +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/entry_points.txt +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/requires.txt +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/top_level.txt +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_absence_adjudication_authorship_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_absence_adjudication_binding_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_bulk_describe.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_capability_documentation_guard_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_capability_surface_parity_guard_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_classfile.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_codex_hook_payload.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_describe_lane_confinement.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_doc_symbols.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_embedding_residency_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_honest_recall.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_http_ensure.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_http_rss_shutdown_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_index_scope.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_index_worker.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_mcp_error_log.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_mcp_registry_behavior_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_mcp_structured.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_mcp_thread_safety.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_mcp_version.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_name_uniqueness.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_nudge_runaway.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_report_filters.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_resolve.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_resolve_js.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_resolve_python.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_resolve_r2.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_review_regressions.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_rss_ceiling_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_semantic_census_pruning_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_sites_and_symbols.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_sqlite_streaming_retrieval_pytest.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_structural.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_ts_fallback_loud.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_ts_symbol_coverage.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_usage.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_veccore_adoption.py +0 -0
- {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_worker_lock_recovery_pytest.py +0 -0
{symgrep_codesearch-0.9.2/src/symgrep_codesearch.egg-info → symgrep_codesearch-0.9.4}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: symgrep-codesearch
|
|
3
|
-
Version: 0.9.
|
|
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.
|
|
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
|
|
@@ -9,6 +9,7 @@ import shlex
|
|
|
9
9
|
import subprocess
|
|
10
10
|
import sys
|
|
11
11
|
|
|
12
|
+
from .runtime_paths import current_or_stable_symgrep_directory
|
|
12
13
|
from .report import (DEFAULT_MAX_SITES, DEFAULT_MAX_LINES_PER_SITE, Report,
|
|
13
14
|
build_sites, render_report, zero_hit_expansions)
|
|
14
15
|
from .ripgrep import RipgrepNotFound, run_rg
|
|
@@ -88,7 +89,7 @@ def build_report(pattern, roots, case_insensitive=False, fixed_string=False,
|
|
|
88
89
|
# Scope resolution: an omitted `roots` falls back to the host cwd. The RESOLVED scope is recorded on the
|
|
89
90
|
# returned Report (`roots=roots` below) as provenance, so the result names exactly which directories were
|
|
90
91
|
# searched rather than leaving it to an unrecorded ambient value.
|
|
91
|
-
roots = [os.path.abspath(r) for r in (roots or [
|
|
92
|
+
roots = [os.path.abspath(r) for r in (roots or [current_or_stable_symgrep_directory()])]
|
|
92
93
|
rg = run_rg(pattern, roots, case_insensitive=case_insensitive,
|
|
93
94
|
fixed_string=fixed_string, multiline=multiline, globs=globs,
|
|
94
95
|
include_ignored=include_ignored)
|
|
@@ -543,7 +544,7 @@ def main(argv=None) -> int:
|
|
|
543
544
|
ap.error("--structural needs a PATTERN")
|
|
544
545
|
if args.index or args.semantic:
|
|
545
546
|
from . import semantic
|
|
546
|
-
roots = [os.path.abspath(r) for r in (args.roots or [
|
|
547
|
+
roots = [os.path.abspath(r) for r in (args.roots or [current_or_stable_symgrep_directory()])]
|
|
547
548
|
try:
|
|
548
549
|
if args.index:
|
|
549
550
|
# The DESCRIBER is injected, so semantic.py needs no API key and holds no opinion about
|
|
@@ -572,7 +573,7 @@ def main(argv=None) -> int:
|
|
|
572
573
|
|
|
573
574
|
if args.structural:
|
|
574
575
|
from . import structural as _st
|
|
575
|
-
roots = [os.path.abspath(r) for r in (args.roots or [
|
|
576
|
+
roots = [os.path.abspath(r) for r in (args.roots or [current_or_stable_symgrep_directory()])]
|
|
576
577
|
try:
|
|
577
578
|
report = _st.structural_report(args.pattern, roots, lang=args.lang,
|
|
578
579
|
include_ignored=args.include_ignored,
|
|
@@ -611,13 +612,13 @@ def main(argv=None) -> int:
|
|
|
611
612
|
# R0 — cross-file candidate resolution. Its own module builds the symbol table + reference set; it
|
|
612
613
|
# ignores --within (a whole-scope question). Exit 0 iff the name is defined or referenced somewhere.
|
|
613
614
|
from .resolve import resolve_name, render_resolution
|
|
614
|
-
res = resolve_name(args.pattern, [os.path.abspath(r) for r in (args.roots or [
|
|
615
|
+
res = resolve_name(args.pattern, [os.path.abspath(r) for r in (args.roots or [current_or_stable_symgrep_directory()])],
|
|
615
616
|
fixed_string=args.fixed_string, case_insensitive=args.ignore_case,
|
|
616
617
|
include_ignored=args.include_ignored, globs=args.globs)
|
|
617
618
|
if args.json:
|
|
618
619
|
print(json.dumps(dataclasses.asdict(res), indent=1))
|
|
619
620
|
else:
|
|
620
|
-
print(render_resolution(res, [os.path.abspath(r) for r in (args.roots or [
|
|
621
|
+
print(render_resolution(res, [os.path.abspath(r) for r in (args.roots or [current_or_stable_symgrep_directory()])]))
|
|
621
622
|
return 0 if (res.n_def or res.n_ref) else 1
|
|
622
623
|
|
|
623
624
|
if args.usage:
|
|
@@ -634,7 +635,7 @@ def main(argv=None) -> int:
|
|
|
634
635
|
if args.json:
|
|
635
636
|
print(json.dumps(dataclasses.asdict(summary), indent=1))
|
|
636
637
|
else:
|
|
637
|
-
print(render_usage(summary, [os.path.abspath(r) for r in (args.roots or [
|
|
638
|
+
print(render_usage(summary, [os.path.abspath(r) for r in (args.roots or [current_or_stable_symgrep_directory()])]))
|
|
638
639
|
return 0 if (summary.n_def or summary.n_ref) else 1
|
|
639
640
|
|
|
640
641
|
if args.within:
|
|
@@ -24,7 +24,8 @@ from importlib import import_module
|
|
|
24
24
|
|
|
25
25
|
from .report import DEFAULT_MAX_SITES, DEFAULT_MAX_LINES_PER_SITE, render_report
|
|
26
26
|
from .cli import build_report
|
|
27
|
-
from .runtime_paths import resolved_mcp_log_path
|
|
27
|
+
from .runtime_paths import (current_or_stable_symgrep_directory, resolved_mcp_log_path,
|
|
28
|
+
resolved_daemon_working_directory)
|
|
28
29
|
|
|
29
30
|
PROTOCOL_VERSION_FALLBACK = "2024-11-05"
|
|
30
31
|
HTTP_HOST_DEFAULT = "127.0.0.1" # $SYMGREP_MCP_HOST — loopback unless deliberately widened
|
|
@@ -155,7 +156,7 @@ def _search(pattern, roots, case_insensitive=False, fixed_string=False,
|
|
|
155
156
|
# remember at the moment remembering fails.
|
|
156
157
|
from . import semantic as sem
|
|
157
158
|
try:
|
|
158
|
-
hits = sem.search_by_meaning(pattern, roots or [
|
|
159
|
+
hits = sem.search_by_meaning(pattern, roots or [current_or_stable_symgrep_directory()], k=k, unit=unit, kind=kind,
|
|
159
160
|
globs=globs, lang=lang)
|
|
160
161
|
return sem.render_meaning_hits(pattern, hits)
|
|
161
162
|
except sem.Unavailable as e:
|
|
@@ -166,7 +167,7 @@ def _search(pattern, roots, case_insensitive=False, fixed_string=False,
|
|
|
166
167
|
from . import structural as structural_engine
|
|
167
168
|
try:
|
|
168
169
|
report = structural_engine.structural_report(
|
|
169
|
-
pattern, roots or [
|
|
170
|
+
pattern, roots or [current_or_stable_symgrep_directory()], lang=lang,
|
|
170
171
|
include_ignored=include_ignored, max_sites=max_sites)
|
|
171
172
|
except structural_engine.StructuralUnavailable as error:
|
|
172
173
|
return f"structural search UNAVAILABLE — this is NOT 'nothing matches':\n {error}"
|
|
@@ -353,6 +354,10 @@ def serve_mcp_transport() -> None:
|
|
|
353
354
|
|
|
354
355
|
|
|
355
356
|
def main() -> None:
|
|
357
|
+
if "--http" in sys.argv[1:]:
|
|
358
|
+
stable_daemon_cwd = resolved_daemon_working_directory()
|
|
359
|
+
os.chdir(stable_daemon_cwd)
|
|
360
|
+
_mcp_request_logger().info("HTTP daemon adopted stable cwd %s", stable_daemon_cwd)
|
|
356
361
|
from .rss_ceiling import enforce_process_rss_ceiling
|
|
357
362
|
with enforce_process_rss_ceiling():
|
|
358
363
|
serve_mcp_transport()
|
|
@@ -28,6 +28,7 @@ Two result-level HONESTY keys make a silent false-negative visible to a PROGRAM,
|
|
|
28
28
|
import os
|
|
29
29
|
from typing import List, Optional
|
|
30
30
|
|
|
31
|
+
from .runtime_paths import current_or_stable_symgrep_directory
|
|
31
32
|
from .cli import build_report
|
|
32
33
|
from .enclosing import file_symbols
|
|
33
34
|
from .report import DEFAULT_MAX_SITES, DEFAULT_MAX_LINES_PER_SITE
|
|
@@ -55,7 +56,7 @@ def structured_search(pattern, roots, *, case_insensitive=False, fixed_string=Fa
|
|
|
55
56
|
# and therefore the findings — is not reproducible unless the output names it. A caller that passed roots
|
|
56
57
|
# sees them echoed back unchanged; a caller that passed none sees exactly which directory was searched.
|
|
57
58
|
# Every return below carries "roots": eff_roots so no result's scope is left to an unrecorded ambient value.
|
|
58
|
-
eff_roots = list(roots) if roots else [
|
|
59
|
+
eff_roots = list(roots) if roots else [current_or_stable_symgrep_directory()]
|
|
59
60
|
if resolve:
|
|
60
61
|
# R0 cross-file candidate resolution: definitions (cross-file symbol table) + references, with
|
|
61
62
|
# AMBIGUITY surfaced (n_def>1). Candidates are by name (basis=candidate-name), never binding-resolved.
|
|
@@ -16,6 +16,7 @@ from collections import OrderedDict
|
|
|
16
16
|
from dataclasses import dataclass, field
|
|
17
17
|
from typing import Dict, List, Optional
|
|
18
18
|
|
|
19
|
+
from .runtime_paths import current_or_stable_symgrep_directory
|
|
19
20
|
from .archives import archive_note
|
|
20
21
|
from .enclosing import Symbol, file_symbols
|
|
21
22
|
from .ripgrep import RgResult, RawMatch, count_files_with_match, ExpansionFailed
|
|
@@ -301,7 +302,7 @@ _USAGE_CAVEAT = ("LEXICAL — by NAME, not resolved. A same-named symbol elsewhe
|
|
|
301
302
|
|
|
302
303
|
def render_usage(summary: UsageSummary, roots: List[str], cwd: Optional[str] = None,
|
|
303
304
|
max_list: int = 10) -> str:
|
|
304
|
-
cwd = cwd or
|
|
305
|
+
cwd = cwd or current_or_stable_symgrep_directory()
|
|
305
306
|
|
|
306
307
|
def rel(p: str) -> str:
|
|
307
308
|
try:
|
|
@@ -343,7 +344,7 @@ def render_usage(summary: UsageSummary, roots: List[str], cwd: Optional[str] = N
|
|
|
343
344
|
|
|
344
345
|
def render_report(report: Report, max_lines_per_site: int = DEFAULT_MAX_LINES_PER_SITE,
|
|
345
346
|
cwd: Optional[str] = None) -> str:
|
|
346
|
-
cwd = cwd or
|
|
347
|
+
cwd = cwd or current_or_stable_symgrep_directory()
|
|
347
348
|
|
|
348
349
|
def rel(p: str) -> str:
|
|
349
350
|
try:
|
|
@@ -22,6 +22,7 @@ import re
|
|
|
22
22
|
from dataclasses import dataclass, field
|
|
23
23
|
from typing import Dict, List, Optional
|
|
24
24
|
|
|
25
|
+
from .runtime_paths import current_or_stable_symgrep_directory
|
|
25
26
|
from .enclosing import file_symbols
|
|
26
27
|
from .ripgrep import list_files
|
|
27
28
|
from .report import compile_name_query, _bare_symbol_name
|
|
@@ -226,7 +227,7 @@ _RESOLVE_CAVEAT = ("R0 candidates by NAME (basis=candidate-name); R1 narrows via
|
|
|
226
227
|
|
|
227
228
|
def render_resolution(res: NameResolution, roots: List[str], cwd: Optional[str] = None,
|
|
228
229
|
max_list: int = 15) -> str:
|
|
229
|
-
cwd = cwd or
|
|
230
|
+
cwd = cwd or current_or_stable_symgrep_directory()
|
|
230
231
|
|
|
231
232
|
def rel(p: str) -> str:
|
|
232
233
|
try:
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Shared runtime paths used by the server and its lifecycle hooks."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import pathlib
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
SYMGREP_CACHE_DIRECTORY_ENV = "SYMGREP_CACHE_DIR"
|
|
8
|
+
SYMGREP_LOG_PATH_ENV = "SYMGREP_LOG"
|
|
9
|
+
SYMGREP_CACHE_DIRECTORY_NAME = "symgrep"
|
|
10
|
+
SYMGREP_MCP_LOG_FILENAME = "mcp.log"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def home_anchored_runtime_path(configured_path) -> pathlib.Path:
|
|
14
|
+
"""Resolve relative runtime overrides against home, independent of daemon cwd."""
|
|
15
|
+
runtime_path = pathlib.Path(configured_path).expanduser()
|
|
16
|
+
return runtime_path if runtime_path.is_absolute() else pathlib.Path.home() / runtime_path
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def resolved_symgrep_cache_directory() -> pathlib.Path:
|
|
20
|
+
"""Return symgrep's configured cache directory, using the repository's existing user-cache default."""
|
|
21
|
+
configured = os.environ.get(SYMGREP_CACHE_DIRECTORY_ENV)
|
|
22
|
+
if configured:
|
|
23
|
+
return home_anchored_runtime_path(configured)
|
|
24
|
+
return pathlib.Path.home() / ".cache" / SYMGREP_CACHE_DIRECTORY_NAME
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def resolved_mcp_log_path() -> pathlib.Path:
|
|
28
|
+
"""Return the request/crash log path shared by the MCP process and its ensure hook."""
|
|
29
|
+
configured = os.environ.get(SYMGREP_LOG_PATH_ENV)
|
|
30
|
+
if configured:
|
|
31
|
+
return home_anchored_runtime_path(configured)
|
|
32
|
+
return resolved_symgrep_cache_directory() / SYMGREP_MCP_LOG_FILENAME
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class DeletedWorkingDirectoryNotice:
|
|
36
|
+
"""Serialize the process-lived, durable degraded-cwd warning."""
|
|
37
|
+
|
|
38
|
+
def __init__(self):
|
|
39
|
+
import threading
|
|
40
|
+
self._cwd_notice_lock = threading.Lock()
|
|
41
|
+
self._cwd_notice_logged = False
|
|
42
|
+
|
|
43
|
+
def warn_deleted_cwd_once(self, fallback_directory, cwd_error):
|
|
44
|
+
with self._cwd_notice_lock:
|
|
45
|
+
if self._cwd_notice_logged:
|
|
46
|
+
return
|
|
47
|
+
from .mcp_server import _mcp_request_logger
|
|
48
|
+
from .rss_ceiling import flush_rss_monitor_log
|
|
49
|
+
cwd_logger = _mcp_request_logger()
|
|
50
|
+
cwd_logger.warning("Working directory unavailable (%s); using stable cwd %s",
|
|
51
|
+
cwd_error, fallback_directory)
|
|
52
|
+
flush_rss_monitor_log(cwd_logger)
|
|
53
|
+
self._cwd_notice_logged = True
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
_DELETED_WORKING_DIRECTORY_NOTICE = DeletedWorkingDirectoryNotice()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def resolved_daemon_working_directory() -> pathlib.Path:
|
|
60
|
+
"""Create an absolute cache root independent of the inherited working directory.
|
|
61
|
+
|
|
62
|
+
Relative cache overrides are anchored to home for daemon residency, since they
|
|
63
|
+
cannot safely be resolved against a potentially deleted inherited cwd.
|
|
64
|
+
"""
|
|
65
|
+
daemon_directory = resolved_symgrep_cache_directory()
|
|
66
|
+
daemon_directory.mkdir(parents=True, exist_ok=True)
|
|
67
|
+
return daemon_directory.resolve()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def current_or_stable_symgrep_directory() -> str:
|
|
71
|
+
"""Preserve a valid cwd verbatim; durably report fallback when it disappears."""
|
|
72
|
+
try:
|
|
73
|
+
return os.getcwd()
|
|
74
|
+
except OSError as cwd_error:
|
|
75
|
+
fallback_directory = resolved_daemon_working_directory()
|
|
76
|
+
_DELETED_WORKING_DIRECTORY_NOTICE.warn_deleted_cwd_once(fallback_directory, cwd_error)
|
|
77
|
+
return str(fallback_directory)
|
|
@@ -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
|
-
|
|
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()
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4/src/symgrep_codesearch.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: symgrep-codesearch
|
|
3
|
-
Version: 0.9.
|
|
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
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/SOURCES.txt
RENAMED
|
@@ -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
|
|
@@ -45,6 +46,7 @@ tests/test_capability_documentation_guard_pytest.py
|
|
|
45
46
|
tests/test_capability_surface_parity_guard_pytest.py
|
|
46
47
|
tests/test_classfile.py
|
|
47
48
|
tests/test_codex_hook_payload.py
|
|
49
|
+
tests/test_daemon_deleted_cwd_pytest.py
|
|
48
50
|
tests/test_data_symbols.py
|
|
49
51
|
tests/test_describe_lane_confinement.py
|
|
50
52
|
tests/test_doc_symbols.py
|
|
@@ -77,6 +79,7 @@ tests/test_semantic_freshness_signal.py
|
|
|
77
79
|
tests/test_semantic_glob_lang.py
|
|
78
80
|
tests/test_sites_and_symbols.py
|
|
79
81
|
tests/test_sqlite_ivf_retrieval_pytest.py
|
|
82
|
+
tests/test_sqlite_maintenance_pytest.py
|
|
80
83
|
tests/test_sqlite_streaming_retrieval_pytest.py
|
|
81
84
|
tests/test_structural.py
|
|
82
85
|
tests/test_symbol_vocabulary.py
|
|
@@ -37,7 +37,8 @@ diff = b"def h(rows):\n n = 0\n for r in rows:\n if r.weight > 0:\n n += r.co
|
|
|
37
37
|
c.check("distinguishes a different job", _sig(clone_a) != _sig(diff))
|
|
38
38
|
|
|
39
39
|
# 3/4/5/6 operate on real files via blocks().
|
|
40
|
-
|
|
40
|
+
_BLOCK_EXTRACTION_TMPDIR = tempfile.TemporaryDirectory()
|
|
41
|
+
d = _BLOCK_EXTRACTION_TMPDIR.name
|
|
41
42
|
(pathlib.Path(d) / "m.py").write_text(
|
|
42
43
|
"def big(xs):\n"
|
|
43
44
|
" total = 0\n"
|
|
@@ -47,7 +47,8 @@ except Exception:
|
|
|
47
47
|
c.skip("veccore/fastembed absent — retrieval not exercisable in this interpreter")
|
|
48
48
|
c.finish()
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
_BLOCK_RETRIEVAL_TMPDIR = tempfile.TemporaryDirectory()
|
|
51
|
+
d = _BLOCK_RETRIEVAL_TMPDIR.name
|
|
51
52
|
(pathlib.Path(d) / "a.py").write_text(
|
|
52
53
|
"def process_invoices(invoices):\n"
|
|
53
54
|
" total = 0\n"
|
|
@@ -107,7 +108,8 @@ c.check("structured symbol hit keeps the pre-v6 key set (no block-only keys)",
|
|
|
107
108
|
f"keys={sorted(sym_hit)}")
|
|
108
109
|
|
|
109
110
|
# 3. DEGRADES: a fresh index built WITHOUT blocks → unit=block is an honest empty set, symbol search works.
|
|
110
|
-
|
|
111
|
+
_SYMBOL_ONLY_RETRIEVAL_TMPDIR = tempfile.TemporaryDirectory()
|
|
112
|
+
d2 = _SYMBOL_ONLY_RETRIEVAL_TMPDIR.name
|
|
111
113
|
(pathlib.Path(d2) / "c.py").write_text(
|
|
112
114
|
"def add_amounts(rows):\n s = 0\n for r in rows:\n s += r.amount\n return s\n")
|
|
113
115
|
sem2 = _build(d2, blocks_on=False)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""A shared daemon must survive deletion of its caller-owned working directory."""
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import socket
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
import time
|
|
9
|
+
import urllib.error
|
|
10
|
+
import urllib.request
|
|
11
|
+
|
|
12
|
+
from symgrep import mcp_server, runtime_paths
|
|
13
|
+
from symgrep.report import Report, render_report
|
|
14
|
+
|
|
15
|
+
CWD_REGRESSION_HOST = "127.0.0.1"
|
|
16
|
+
CWD_REGRESSION_TIMEOUT_SECONDS = float(os.environ.get("SYMGREP_TEST_CWD_TIMEOUT_SECONDS", "30"))
|
|
17
|
+
CWD_REGRESSION_POLL_SECONDS = 0.05
|
|
18
|
+
CWD_REGRESSION_MARKER = "daemon_directory_probe"
|
|
19
|
+
CWD_REGRESSION_SOURCE = "def daemon_directory_probe():\n return True\n"
|
|
20
|
+
CWD_REGRESSION_CHILD_PROGRAM = """
|
|
21
|
+
import os
|
|
22
|
+
import shutil
|
|
23
|
+
import sys
|
|
24
|
+
from symgrep.mcp_server import _search
|
|
25
|
+
spawn_directory, source_directory, marker = sys.argv[1:]
|
|
26
|
+
os.chdir(spawn_directory)
|
|
27
|
+
shutil.rmtree(spawn_directory)
|
|
28
|
+
first_report = _search(marker, [source_directory])
|
|
29
|
+
second_report = _search(marker, [source_directory])
|
|
30
|
+
default_roots_report = _search(marker, [])
|
|
31
|
+
assert default_roots_report == first_report
|
|
32
|
+
print(first_report)
|
|
33
|
+
assert first_report == second_report
|
|
34
|
+
assert '1 line match(es)' in first_report
|
|
35
|
+
assert marker in first_report
|
|
36
|
+
assert 'sample.py' in first_report
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_deleted_cwd_search_uses_stable_root_and_warns_once(tmp_path):
|
|
41
|
+
deleted_spawn_directory = tmp_path / "spawn"
|
|
42
|
+
deleted_spawn_directory.mkdir()
|
|
43
|
+
durable_cache_directory = tmp_path / "cache"
|
|
44
|
+
durable_cache_directory.mkdir()
|
|
45
|
+
(durable_cache_directory / "sample.py").write_text(CWD_REGRESSION_SOURCE)
|
|
46
|
+
deletion_warning_log = tmp_path / "cwd-warning.log"
|
|
47
|
+
deleted_cwd_result = subprocess.run(
|
|
48
|
+
[sys.executable, "-c", CWD_REGRESSION_CHILD_PROGRAM, str(deleted_spawn_directory),
|
|
49
|
+
str(durable_cache_directory), CWD_REGRESSION_MARKER],
|
|
50
|
+
env=dict(os.environ, SYMGREP_CACHE_DIR=str(durable_cache_directory),
|
|
51
|
+
SYMGREP_LOG=str(deletion_warning_log)),
|
|
52
|
+
capture_output=True, text=True, timeout=CWD_REGRESSION_TIMEOUT_SECONDS)
|
|
53
|
+
assert deleted_cwd_result.returncode == 0, deleted_cwd_result.stdout + deleted_cwd_result.stderr
|
|
54
|
+
# Relative-to-cache output proves render_report used the stable root, not an arbitrary fallback.
|
|
55
|
+
assert str(durable_cache_directory / "sample.py") not in deleted_cwd_result.stdout
|
|
56
|
+
warning_lines = [line for line in deletion_warning_log.read_text().splitlines() if " WARNING " in line]
|
|
57
|
+
assert len(warning_lines) == 1, warning_lines
|
|
58
|
+
assert str(durable_cache_directory) in warning_lines[0]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_valid_cwd_report_retains_implicit_and_explicit_path_behavior(tmp_path, monkeypatch):
|
|
62
|
+
monkeypatch.chdir(tmp_path)
|
|
63
|
+
valid_cwd_report = Report(pattern=CWD_REGRESSION_MARKER, roots=[str(tmp_path)],
|
|
64
|
+
total_line_matches=0, total_files=0, sites=[], truncated_events=False, shown_sites=0)
|
|
65
|
+
assert render_report(valid_cwd_report) == render_report(valid_cwd_report, cwd=str(tmp_path))
|
|
66
|
+
explicit_render_root = tmp_path / "other"
|
|
67
|
+
assert render_report(valid_cwd_report, cwd=str(explicit_render_root)).startswith(
|
|
68
|
+
f"symgrep '{CWD_REGRESSION_MARKER}' in {tmp_path}:")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_http_daemon_adopts_stable_cwd_before_spawn_directory_disappears(tmp_path):
|
|
72
|
+
inherited_spawn_directory = tmp_path / "spawn"
|
|
73
|
+
inherited_spawn_directory.mkdir()
|
|
74
|
+
http_cache_directory = tmp_path / "cache"
|
|
75
|
+
http_cache_directory.mkdir()
|
|
76
|
+
(http_cache_directory / "sample.py").write_text(CWD_REGRESSION_SOURCE)
|
|
77
|
+
startup_cwd_log = tmp_path / "http-cwd.log"
|
|
78
|
+
with socket.socket() as ephemeral_port_probe:
|
|
79
|
+
ephemeral_port_probe.bind((CWD_REGRESSION_HOST, 0))
|
|
80
|
+
isolated_http_port = ephemeral_port_probe.getsockname()[1]
|
|
81
|
+
isolated_http_url = f"http://{CWD_REGRESSION_HOST}:{isolated_http_port}{mcp_server.HTTP_PATH}"
|
|
82
|
+
http_cwd_daemon = subprocess.Popen(
|
|
83
|
+
[sys.executable, "-m", "symgrep.mcp_server", "--http"], cwd=inherited_spawn_directory,
|
|
84
|
+
env=dict(os.environ, SYMGREP_CACHE_DIR=str(http_cache_directory), SYMGREP_LOG=str(startup_cwd_log),
|
|
85
|
+
SYMGREP_MCP_HOST=CWD_REGRESSION_HOST, SYMGREP_MCP_PORT=str(isolated_http_port)),
|
|
86
|
+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
87
|
+
try:
|
|
88
|
+
http_cwd_deadline = time.monotonic() + CWD_REGRESSION_TIMEOUT_SECONDS
|
|
89
|
+
http_search_payload = json.dumps({"jsonrpc": "2.0", "id": 1, "method": "tools/call",
|
|
90
|
+
"params": {"name": "search", "arguments": {
|
|
91
|
+
"pattern": CWD_REGRESSION_MARKER,
|
|
92
|
+
"roots": [str(http_cache_directory)]}}}).encode()
|
|
93
|
+
while True:
|
|
94
|
+
try:
|
|
95
|
+
http_ready_request = urllib.request.Request(isolated_http_url, data=http_search_payload,
|
|
96
|
+
headers={"Content-Type": "application/json", "Accept": "application/json, text/event-stream"})
|
|
97
|
+
with urllib.request.urlopen(http_ready_request, timeout=CWD_REGRESSION_TIMEOUT_SECONDS) as ready_response:
|
|
98
|
+
ready_response.read()
|
|
99
|
+
break
|
|
100
|
+
except (urllib.error.URLError, TimeoutError, ConnectionError):
|
|
101
|
+
if http_cwd_daemon.poll() is not None or time.monotonic() >= http_cwd_deadline:
|
|
102
|
+
raise AssertionError("isolated HTTP daemon did not become ready")
|
|
103
|
+
time.sleep(CWD_REGRESSION_POLL_SECONDS)
|
|
104
|
+
shutil.rmtree(inherited_spawn_directory)
|
|
105
|
+
with urllib.request.urlopen(http_ready_request, timeout=CWD_REGRESSION_TIMEOUT_SECONDS) as search_response:
|
|
106
|
+
http_search_result = json.loads(search_response.read())
|
|
107
|
+
assert not http_search_result["result"].get("isError"), http_search_result
|
|
108
|
+
http_search_text = "\n".join(item.get("text", "") for item in http_search_result["result"]["content"])
|
|
109
|
+
assert "1 line match(es)" in http_search_text, http_search_result
|
|
110
|
+
assert CWD_REGRESSION_MARKER in http_search_text
|
|
111
|
+
assert str(http_cache_directory / "sample.py") not in http_search_text
|
|
112
|
+
startup_log_lines = startup_cwd_log.read_text().splitlines()
|
|
113
|
+
assert any(" INFO " in line and "cwd" in line.lower() and str(http_cache_directory) in line
|
|
114
|
+
for line in startup_log_lines), startup_log_lines
|
|
115
|
+
assert not any(" WARNING " in line for line in startup_log_lines), startup_log_lines
|
|
116
|
+
finally:
|
|
117
|
+
if http_cwd_daemon.poll() is None:
|
|
118
|
+
http_cwd_daemon.terminate()
|
|
119
|
+
try:
|
|
120
|
+
http_cwd_daemon.communicate(timeout=CWD_REGRESSION_TIMEOUT_SECONDS)
|
|
121
|
+
except subprocess.TimeoutExpired:
|
|
122
|
+
http_cwd_daemon.kill()
|
|
123
|
+
http_cwd_daemon.communicate(timeout=CWD_REGRESSION_TIMEOUT_SECONDS)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_cwd_helper_handles_generic_oserror_and_preserves_valid_cwd(tmp_path, monkeypatch):
|
|
127
|
+
monkeypatch.setenv(runtime_paths.SYMGREP_CACHE_DIRECTORY_ENV, str(tmp_path))
|
|
128
|
+
monkeypatch.setenv(runtime_paths.SYMGREP_LOG_PATH_ENV, str(tmp_path / "helper-cwd.log"))
|
|
129
|
+
assert runtime_paths.current_or_stable_symgrep_directory() == os.getcwd()
|
|
130
|
+
|
|
131
|
+
def raise_cwd_probe_oserror():
|
|
132
|
+
raise OSError("cwd probe unavailable")
|
|
133
|
+
|
|
134
|
+
with monkeypatch.context() as unavailable_cwd_patch:
|
|
135
|
+
unavailable_cwd_patch.setattr(os, "getcwd", raise_cwd_probe_oserror)
|
|
136
|
+
assert runtime_paths.current_or_stable_symgrep_directory() == str(tmp_path.resolve())
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_relative_daemon_cache_configuration_is_anchored_to_home(tmp_path, monkeypatch):
|
|
140
|
+
relative_cache_name = "relative-daemon-cache"
|
|
141
|
+
monkeypatch.setattr(runtime_paths.pathlib.Path, "home", lambda: tmp_path)
|
|
142
|
+
monkeypatch.setenv(runtime_paths.SYMGREP_CACHE_DIRECTORY_ENV, relative_cache_name)
|
|
143
|
+
relative_daemon_directory = runtime_paths.resolved_daemon_working_directory()
|
|
144
|
+
assert relative_daemon_directory == tmp_path / relative_cache_name
|
|
145
|
+
assert relative_daemon_directory.is_dir()
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_deleted_cwd_relative_cache_and_log_overrides_resolve_against_home(tmp_path):
|
|
149
|
+
relative_spawn_directory = tmp_path / "spawn"
|
|
150
|
+
relative_spawn_directory.mkdir()
|
|
151
|
+
isolated_runtime_home = tmp_path / "home"
|
|
152
|
+
relative_cache_override = "relative-cache"
|
|
153
|
+
relative_log_override = "relative-logs/cwd-warning.log"
|
|
154
|
+
isolated_home_cache = isolated_runtime_home / relative_cache_override
|
|
155
|
+
isolated_home_cache.mkdir(parents=True)
|
|
156
|
+
(isolated_home_cache / "sample.py").write_text(CWD_REGRESSION_SOURCE)
|
|
157
|
+
relative_override_result = subprocess.run(
|
|
158
|
+
[sys.executable, "-c", CWD_REGRESSION_CHILD_PROGRAM, str(relative_spawn_directory),
|
|
159
|
+
str(isolated_home_cache), CWD_REGRESSION_MARKER],
|
|
160
|
+
env=dict(os.environ, HOME=str(isolated_runtime_home), SYMGREP_CACHE_DIR=relative_cache_override,
|
|
161
|
+
SYMGREP_LOG=relative_log_override),
|
|
162
|
+
capture_output=True, text=True, timeout=CWD_REGRESSION_TIMEOUT_SECONDS)
|
|
163
|
+
assert relative_override_result.returncode == 0, relative_override_result.stdout + relative_override_result.stderr
|
|
164
|
+
assert str(isolated_home_cache / "sample.py") not in relative_override_result.stdout
|
|
165
|
+
relative_warning_log = isolated_runtime_home / relative_log_override
|
|
166
|
+
relative_warning_lines = [line for line in relative_warning_log.read_text().splitlines()
|
|
167
|
+
if " WARNING " in line]
|
|
168
|
+
assert len(relative_warning_lines) == 1, relative_warning_lines
|
|
169
|
+
assert str(isolated_home_cache) in relative_warning_lines[0]
|
|
170
|
+
assert not (isolated_home_cache / relative_cache_override).exists()
|
|
171
|
+
assert not (isolated_home_cache / relative_log_override).exists()
|
|
@@ -24,7 +24,8 @@ def _stub(text):
|
|
|
24
24
|
return "Purpose: " + " ".join(text.split()) # description = the WHOLE grounded input (no truncation)
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
_DATA_SYMBOLS_TMPDIR = tempfile.TemporaryDirectory()
|
|
28
|
+
d = _DATA_SYMBOLS_TMPDIR.name
|
|
28
29
|
(pathlib.Path(d) / "prices.json").write_text(
|
|
29
30
|
'{"models": {"gpt-5": {"price_in": 1.25}}, "retry": {"max": 3, "backoff": "exp"}}')
|
|
30
31
|
(pathlib.Path(d) / "billing.proto").write_text(
|
|
@@ -108,7 +109,8 @@ c.check("2. default unit=symbol returns no data units",
|
|
|
108
109
|
all(h.get("unit") != "data" for h in hits("account balances", unit="symbol")))
|
|
109
110
|
|
|
110
111
|
# 4. DEGRADES: a fresh index built WITHOUT data → unit=data is an honest empty set; code search unaffected
|
|
111
|
-
|
|
112
|
+
_CODE_ONLY_DATA_TEST_TMPDIR = tempfile.TemporaryDirectory()
|
|
113
|
+
d2 = _CODE_ONLY_DATA_TEST_TMPDIR.name
|
|
112
114
|
(pathlib.Path(d2) / "a.py").write_text("def f(x):\n return x + 1\n")
|
|
113
115
|
os.environ["SYMGREP_INDEX"] = os.path.join(d2, "idx.sqlite")
|
|
114
116
|
os.environ.pop("SYMGREP_INDEX_DATA", None)
|
|
@@ -22,7 +22,8 @@ from checklib import Checks # noqa: E402
|
|
|
22
22
|
|
|
23
23
|
c = Checks("test_file_structure")
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
_FILE_STRUCTURE_TMPDIR = tempfile.TemporaryDirectory()
|
|
26
|
+
d = _FILE_STRUCTURE_TMPDIR.name
|
|
26
27
|
PY = pathlib.Path(d) / "etl.py"
|
|
27
28
|
PY.write_text(
|
|
28
29
|
"import pandas as pd\n"
|
|
@@ -65,13 +65,10 @@ try:
|
|
|
65
65
|
import symgrep_index_freshness as hook # noqa: E402
|
|
66
66
|
check("in-scope .py is indexable to the hook", hook._indexable(str(mod)))
|
|
67
67
|
check("a .md is not (no trusted parser basis for meaning)", not hook._indexable(str(TMP / "notes.md")))
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
with tempfile.TemporaryDirectory() as outside_dir:
|
|
69
|
+
outside = pathlib.Path(outside_dir) / "x.py"
|
|
70
|
+
outside.write_text("def f():\n return 1\n")
|
|
71
71
|
check("an indexable file OUTSIDE indexed roots is not enqueued", not hook._indexable(str(outside)))
|
|
72
|
-
finally:
|
|
73
|
-
outside.unlink()
|
|
74
|
-
outside.parent.rmdir()
|
|
75
72
|
finally:
|
|
76
73
|
if _real_env is None:
|
|
77
74
|
os.environ.pop("SYMGREP_INDEX", None)
|
|
@@ -31,7 +31,8 @@ def _valid_index(path, what):
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
# 1. corrupt index + a valid snapshot → RESTORE the last-good state; corrupt preserved (not deleted)
|
|
34
|
-
|
|
34
|
+
_SNAPSHOT_RESTORE_TMPDIR = tempfile.TemporaryDirectory()
|
|
35
|
+
d = _SNAPSHOT_RESTORE_TMPDIR.name
|
|
35
36
|
idx = os.path.join(d, "semantic.sqlite")
|
|
36
37
|
os.makedirs(os.path.join(d, "snapshots"))
|
|
37
38
|
_valid_index(os.path.join(d, "snapshots", "semantic.sqlite"), "the last good described row")
|
|
@@ -46,7 +47,8 @@ c.check("1. corrupt file PRESERVED aside (never deleted)", bool(glob.glob(idx +
|
|
|
46
47
|
c.check("1. original path is a valid index again", os.path.exists(idx))
|
|
47
48
|
|
|
48
49
|
# 2. corrupt index + NO snapshot → reconstruct EMPTY (no crash), corrupt still preserved
|
|
49
|
-
|
|
50
|
+
_EMPTY_RECONSTRUCTION_TMPDIR = tempfile.TemporaryDirectory()
|
|
51
|
+
d2 = _EMPTY_RECONSTRUCTION_TMPDIR.name
|
|
50
52
|
idx2 = os.path.join(d2, "semantic.sqlite")
|
|
51
53
|
with open(idx2, "wb") as f:
|
|
52
54
|
f.write(b"also not a database " * 80)
|
|
@@ -58,7 +60,8 @@ c.check("2. no snapshot → reconstructed EMPTY (no crash)", n == 0)
|
|
|
58
60
|
c.check("2. corrupt file still preserved", bool(glob.glob(idx2 + ".corrupt-*")))
|
|
59
61
|
|
|
60
62
|
# 3. a HEALTHY index is opened untouched — reconstruction never fires on a good index
|
|
61
|
-
|
|
63
|
+
_HEALTHY_REOPEN_TMPDIR = tempfile.TemporaryDirectory()
|
|
64
|
+
d3 = _HEALTHY_REOPEN_TMPDIR.name
|
|
62
65
|
idx3 = os.path.join(d3, "semantic.sqlite")
|
|
63
66
|
os.environ["SYMGREP_INDEX"] = idx3
|
|
64
67
|
con = semantic._db() # fresh healthy open
|
|
@@ -56,7 +56,8 @@ def _with(tmp_cache, py_exists=True):
|
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
import tempfile # noqa: E402
|
|
59
|
-
|
|
59
|
+
_NUDGE_CLASSIFY_TMPDIR = tempfile.TemporaryDirectory(prefix="nudge-test-")
|
|
60
|
+
_tmp = _NUDGE_CLASSIFY_TMPDIR.name
|
|
60
61
|
_cache = os.path.join(_tmp, "verdicts.sqlite")
|
|
61
62
|
|
|
62
63
|
_orig_run = h.subprocess.run
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_semantic_freshness_signal.py
RENAMED
|
@@ -19,7 +19,8 @@ from checklib import Checks
|
|
|
19
19
|
_t = Checks("test_semantic_freshness_signal")
|
|
20
20
|
check = _t.check
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
_FRESHNESS_SIGNAL_TMPDIR = tempfile.TemporaryDirectory(prefix="symgrep-fresh-")
|
|
23
|
+
work = _FRESHNESS_SIGNAL_TMPDIR.name
|
|
23
24
|
os.environ["SYMGREP_INDEX"] = os.path.join(work, "index.sqlite")
|
|
24
25
|
from symgrep import semantic # noqa: E402
|
|
25
26
|
|
|
@@ -30,8 +30,7 @@ from symgrep.enclosing import TS_LANG_BY_EXT
|
|
|
30
30
|
from symgrep.report import Report, render_report # noqa: E402
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
def _fixture_tree():
|
|
34
|
-
d = tempfile.mkdtemp(prefix="symgrep-glob-test-")
|
|
33
|
+
def _fixture_tree(d):
|
|
35
34
|
open(os.path.join(d, "a.py"), "w").close()
|
|
36
35
|
open(os.path.join(d, "b.js"), "w").close()
|
|
37
36
|
open(os.path.join(d, "bundle.zip"), "w").close()
|
|
@@ -50,7 +49,8 @@ check("is_archive: source + bare .gz are NOT archives (a .gz is one file, not a
|
|
|
50
49
|
not any(archives.is_archive(n) for n in ("a.py", "b.js", "notes.txt.gz", "r.txt")),
|
|
51
50
|
"a non-container was misread as an archive")
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
_GLOB_ARCHIVE_TMPDIR = tempfile.TemporaryDirectory(prefix="symgrep-glob-test-")
|
|
53
|
+
_fx = _fixture_tree(_GLOB_ARCHIVE_TMPDIR.name)
|
|
54
54
|
found, capped = archives.archive_files([_fx])
|
|
55
55
|
_names = sorted(os.path.basename(p) for p in found)
|
|
56
56
|
check("archive_files finds the containers (recursively), not the source/.gz",
|
|
@@ -59,8 +59,9 @@ check("archive_files reports capped=False on a small complete scan", capped is F
|
|
|
59
59
|
check("archive_note names the opaque archives and says contents are not covered",
|
|
60
60
|
(lambda n: n is not None and "archive(s)" in n and "OPAQUE" in n)(archives.archive_note([_fx])),
|
|
61
61
|
"archive_note did not produce the honest-skip line")
|
|
62
|
+
_EMPTY_ARCHIVE_TMPDIR = tempfile.TemporaryDirectory(prefix="empty-")
|
|
62
63
|
check("archive_note is None when there are no archives (vanishes when irrelevant)",
|
|
63
|
-
archives.archive_note([
|
|
64
|
+
archives.archive_note([_EMPTY_ARCHIVE_TMPDIR.name]) is None, "note fired with no archives")
|
|
64
65
|
|
|
65
66
|
# capped scan must SIGNAL, never silently undercount (the truncation doctrine)
|
|
66
67
|
_f2, _cap2 = archives.archive_files([_fx], cap=1)
|
|
@@ -170,7 +171,8 @@ check("semantic render appends the opaque-archive note (archives under the searc
|
|
|
170
171
|
from symgrep import glob_recall # noqa: E402
|
|
171
172
|
from symgrep.cli import build_report # noqa: E402
|
|
172
173
|
|
|
173
|
-
|
|
174
|
+
_GLOB_EXCLUSION_TMPDIR = tempfile.TemporaryDirectory(prefix="symgrep-glob-excl-")
|
|
175
|
+
_gx = _GLOB_EXCLUSION_TMPDIR.name
|
|
174
176
|
open(os.path.join(_gx, "widget.py"), "w").write("def handle_WIDGETZ(): pass\n")
|
|
175
177
|
open(os.path.join(_gx, "widget.js"), "w").write("function handle_WIDGETZ(){}\n")
|
|
176
178
|
open(os.path.join(_gx, "readme.md"), "w").write("WIDGETZ documentation\n")
|
|
@@ -219,7 +221,8 @@ else:
|
|
|
219
221
|
# A .zip/.tar.gz is never indexed/searched, so a programmatic consumer must be able to tell "searched,
|
|
220
222
|
# nothing matched, and there were these unopened containers" from "nothing anywhere". The prose render
|
|
221
223
|
# names archives on a name-search ONLY at zero hits; the structured name payload mirrors that exactly.
|
|
222
|
-
|
|
224
|
+
_STRUCTURED_ARCHIVE_TMPDIR = tempfile.TemporaryDirectory(prefix="symgrep-glob-test-")
|
|
225
|
+
_ax = _fixture_tree(_STRUCTURED_ARCHIVE_TMPDIR.name) # has bundle.zip, data.tar.gz, sub/lib.jar + a.py/b.js (empty)
|
|
223
226
|
if _rg:
|
|
224
227
|
_zero = mcp_structured.structured_search("zzz_no_such_symbol_qpz", [_ax])
|
|
225
228
|
_azn = sorted(os.path.basename(p) for p in _zero.get("archives", []))
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_sqlite_ivf_retrieval_pytest.py
RENAMED
|
@@ -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"
|
|
@@ -106,7 +106,8 @@ else:
|
|
|
106
106
|
fs is not None and fs.basis == "treesitter", str(getattr(fs, "basis", None)))
|
|
107
107
|
|
|
108
108
|
# HTML goes through file_symbols (its handler is ext-scoped); assert its own element/component/script model
|
|
109
|
-
|
|
109
|
+
_HTML_VOCABULARY_TMPDIR = tempfile.TemporaryDirectory()
|
|
110
|
+
hp = os.path.join(_HTML_VOCABULARY_TMPDIR.name, "page.html")
|
|
110
111
|
with open(hp, "w", encoding="utf-8") as f:
|
|
111
112
|
f.write(HTML_SRC)
|
|
112
113
|
hfs = file_symbols(hp)
|
|
@@ -117,7 +118,8 @@ else:
|
|
|
117
118
|
hfs.basis == "treesitter" and hfs.note is None, f"basis={hfs.basis} note={hfs.note}")
|
|
118
119
|
|
|
119
120
|
# JSP: declarations→java methods, jsp:useBean→bean, include directive, element; comment code excluded
|
|
120
|
-
|
|
121
|
+
_JSP_VOCABULARY_TMPDIR = tempfile.TemporaryDirectory()
|
|
122
|
+
jp = os.path.join(_JSP_VOCABULARY_TMPDIR.name, "page.jsp")
|
|
121
123
|
with open(jp, "w", encoding="utf-8") as f:
|
|
122
124
|
f.write(JSP_SRC)
|
|
123
125
|
jfs = file_symbols(jp)
|
|
@@ -132,7 +134,8 @@ else:
|
|
|
132
134
|
# offset lines — a helper def/function extracted at its real line.
|
|
133
135
|
ERB_SRC = "<h1>Users</h1>\n<% def full_name(u)\n u.first + u.last\nend %>\n<%= full_name(user) %>\n"
|
|
134
136
|
ERB_GOLDEN = {("full_name", "method", 2, 4)}
|
|
135
|
-
|
|
137
|
+
_ERB_VOCABULARY_TMPDIR = tempfile.TemporaryDirectory()
|
|
138
|
+
ep = os.path.join(_ERB_VOCABULARY_TMPDIR.name, "view.erb")
|
|
136
139
|
with open(ep, "w", encoding="utf-8") as f:
|
|
137
140
|
f.write(ERB_SRC)
|
|
138
141
|
efs = file_symbols(ep)
|
|
@@ -142,7 +145,8 @@ else:
|
|
|
142
145
|
|
|
143
146
|
EJS_SRC = "<h1><%= title %></h1>\n<% function render(items){ return items.length } %>\n"
|
|
144
147
|
EJS_GOLDEN = {("render", "function", 2, 2)}
|
|
145
|
-
|
|
148
|
+
_EJS_VOCABULARY_TMPDIR = tempfile.TemporaryDirectory()
|
|
149
|
+
jp2 = os.path.join(_EJS_VOCABULARY_TMPDIR.name, "view.ejs")
|
|
146
150
|
with open(jp2, "w", encoding="utf-8") as f:
|
|
147
151
|
f.write(EJS_SRC)
|
|
148
152
|
j2fs = file_symbols(jp2)
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"""Shared runtime paths used by the server and its lifecycle hooks."""
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import pathlib
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
SYMGREP_CACHE_DIRECTORY_ENV = "SYMGREP_CACHE_DIR"
|
|
8
|
-
SYMGREP_LOG_PATH_ENV = "SYMGREP_LOG"
|
|
9
|
-
SYMGREP_CACHE_DIRECTORY_NAME = "symgrep"
|
|
10
|
-
SYMGREP_MCP_LOG_FILENAME = "mcp.log"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def resolved_symgrep_cache_directory() -> pathlib.Path:
|
|
14
|
-
"""Return symgrep's configured cache directory, using the repository's existing user-cache default."""
|
|
15
|
-
configured = os.environ.get(SYMGREP_CACHE_DIRECTORY_ENV)
|
|
16
|
-
if configured:
|
|
17
|
-
return pathlib.Path(configured).expanduser()
|
|
18
|
-
return pathlib.Path.home() / ".cache" / SYMGREP_CACHE_DIRECTORY_NAME
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def resolved_mcp_log_path() -> pathlib.Path:
|
|
22
|
-
"""Return the request/crash log path shared by the MCP process and its ensure hook."""
|
|
23
|
-
configured = os.environ.get(SYMGREP_LOG_PATH_ENV)
|
|
24
|
-
if configured:
|
|
25
|
-
return pathlib.Path(configured).expanduser()
|
|
26
|
-
return resolved_symgrep_cache_directory() / SYMGREP_MCP_LOG_FILENAME
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/absence_adjudication_writer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/capability_registry_data.jsonl
RENAMED
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep/capability_surface_checks.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/requires.txt
RENAMED
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/src/symgrep_codesearch.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_describe_lane_confinement.py
RENAMED
|
File without changes
|
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_embedding_residency_pytest.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_http_rss_shutdown_pytest.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_mcp_registry_behavior_pytest.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_semantic_census_pruning_pytest.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.4}/tests/test_worker_lock_recovery_pytest.py
RENAMED
|
File without changes
|