symgrep-codesearch 0.9.2__tar.gz → 0.9.3__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 (91) hide show
  1. {symgrep_codesearch-0.9.2/src/symgrep_codesearch.egg-info → symgrep_codesearch-0.9.3}/PKG-INFO +1 -1
  2. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/pyproject.toml +1 -1
  3. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/cli.py +7 -6
  4. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/mcp_server.py +8 -3
  5. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/mcp_structured.py +2 -1
  6. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/report.py +3 -2
  7. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/resolve.py +2 -1
  8. symgrep_codesearch-0.9.3/src/symgrep/runtime_paths.py +77 -0
  9. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3/src/symgrep_codesearch.egg-info}/PKG-INFO +1 -1
  10. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep_codesearch.egg-info/SOURCES.txt +1 -0
  11. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_blocks_extraction.py +2 -1
  12. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_blocks_retrieval.py +4 -2
  13. symgrep_codesearch-0.9.3/tests/test_daemon_deleted_cwd_pytest.py +171 -0
  14. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_data_symbols.py +4 -2
  15. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_file_structure.py +2 -1
  16. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_freshness.py +3 -6
  17. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_index_reconstruct.py +6 -3
  18. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_nudge_classify.py +2 -1
  19. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_semantic_freshness_signal.py +2 -1
  20. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_semantic_glob_lang.py +9 -6
  21. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_symbol_vocabulary.py +8 -4
  22. symgrep_codesearch-0.9.2/src/symgrep/runtime_paths.py +0 -26
  23. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/LICENSE +0 -0
  24. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/README.md +0 -0
  25. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/setup.cfg +0 -0
  26. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/__init__.py +0 -0
  27. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/absence_adjudication_writer.py +0 -0
  28. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/archives.py +0 -0
  29. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/blocks.py +0 -0
  30. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/capability_registry.py +0 -0
  31. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/capability_registry_data.jsonl +0 -0
  32. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/capability_surface_checks.py +0 -0
  33. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/classfile.py +0 -0
  34. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/data_symbols.py +0 -0
  35. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/docsymbols.py +0 -0
  36. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/embedding_process.py +0 -0
  37. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/enclosing.py +0 -0
  38. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/glob_recall.py +0 -0
  39. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/resolve_js.py +0 -0
  40. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/resolve_python.py +0 -0
  41. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/ripgrep.py +0 -0
  42. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/rss_ceiling.py +0 -0
  43. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/semantic.py +0 -0
  44. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/semantic_ivf.py +0 -0
  45. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/semantic_sqlite.py +0 -0
  46. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/semantic_sqlite_config.py +0 -0
  47. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/structural.py +0 -0
  48. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep/structure.py +0 -0
  49. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep_codesearch.egg-info/dependency_links.txt +0 -0
  50. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep_codesearch.egg-info/entry_points.txt +0 -0
  51. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep_codesearch.egg-info/requires.txt +0 -0
  52. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/src/symgrep_codesearch.egg-info/top_level.txt +0 -0
  53. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_absence_adjudication_authorship_pytest.py +0 -0
  54. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_absence_adjudication_binding_pytest.py +0 -0
  55. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_bulk_describe.py +0 -0
  56. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_capability_documentation_guard_pytest.py +0 -0
  57. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_capability_surface_parity_guard_pytest.py +0 -0
  58. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_classfile.py +0 -0
  59. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_codex_hook_payload.py +0 -0
  60. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_describe_lane_confinement.py +0 -0
  61. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_doc_symbols.py +0 -0
  62. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_embedding_residency_pytest.py +0 -0
  63. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_honest_recall.py +0 -0
  64. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_http_ensure.py +0 -0
  65. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_http_rss_shutdown_pytest.py +0 -0
  66. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_index_scope.py +0 -0
  67. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_index_worker.py +0 -0
  68. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_mcp_error_log.py +0 -0
  69. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_mcp_registry_behavior_pytest.py +0 -0
  70. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_mcp_structured.py +0 -0
  71. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_mcp_thread_safety.py +0 -0
  72. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_mcp_version.py +0 -0
  73. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_name_uniqueness.py +0 -0
  74. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_nudge_runaway.py +0 -0
  75. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_report_filters.py +0 -0
  76. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_resolve.py +0 -0
  77. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_resolve_js.py +0 -0
  78. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_resolve_python.py +0 -0
  79. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_resolve_r2.py +0 -0
  80. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_review_regressions.py +0 -0
  81. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_rss_ceiling_pytest.py +0 -0
  82. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_semantic_census_pruning_pytest.py +0 -0
  83. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_sites_and_symbols.py +0 -0
  84. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_sqlite_ivf_retrieval_pytest.py +0 -0
  85. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_sqlite_streaming_retrieval_pytest.py +0 -0
  86. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_structural.py +0 -0
  87. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_ts_fallback_loud.py +0 -0
  88. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_ts_symbol_coverage.py +0 -0
  89. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_usage.py +0 -0
  90. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/tests/test_veccore_adoption.py +0 -0
  91. {symgrep_codesearch-0.9.2 → symgrep_codesearch-0.9.3}/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.2
3
+ Version: 0.9.3
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.2"
44
+ version = "0.9.3"
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 [os.getcwd()])]
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 [os.getcwd()])]
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 [os.getcwd()])]
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 [os.getcwd()])],
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 [os.getcwd()])]))
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 [os.getcwd()])]))
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 [os.getcwd()], k=k, unit=unit, kind=kind,
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 [os.getcwd()], lang=lang,
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 [os.getcwd()]
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 os.getcwd()
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 os.getcwd()
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 os.getcwd()
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: symgrep-codesearch
3
- Version: 0.9.2
3
+ Version: 0.9.3
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
@@ -45,6 +45,7 @@ tests/test_capability_documentation_guard_pytest.py
45
45
  tests/test_capability_surface_parity_guard_pytest.py
46
46
  tests/test_classfile.py
47
47
  tests/test_codex_hook_payload.py
48
+ tests/test_daemon_deleted_cwd_pytest.py
48
49
  tests/test_data_symbols.py
49
50
  tests/test_describe_lane_confinement.py
50
51
  tests/test_doc_symbols.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
- d = tempfile.mkdtemp()
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
- d = tempfile.mkdtemp()
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
- d2 = tempfile.mkdtemp()
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
- d = tempfile.mkdtemp()
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
- d2 = tempfile.mkdtemp()
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
- d = tempfile.mkdtemp()
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
- outside = pathlib.Path(tempfile.mkdtemp()) / "x.py"
69
- outside.write_text("def f():\n return 1\n")
70
- try:
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
- d = tempfile.mkdtemp()
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
- d2 = tempfile.mkdtemp()
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
- d3 = tempfile.mkdtemp()
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
- _tmp = tempfile.mkdtemp(prefix="nudge-test-")
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
@@ -19,7 +19,8 @@ from checklib import Checks
19
19
  _t = Checks("test_semantic_freshness_signal")
20
20
  check = _t.check
21
21
 
22
- work = tempfile.mkdtemp(prefix="symgrep-fresh-")
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
- _fx = _fixture_tree()
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([tempfile.mkdtemp(prefix="empty-")]) is None, "note fired with no archives")
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
- _gx = tempfile.mkdtemp(prefix="symgrep-glob-excl-")
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
- _ax = _fixture_tree() # has bundle.zip, data.tar.gz, sub/lib.jar + a.py/b.js (empty)
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", []))
@@ -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
- hp = os.path.join(tempfile.mkdtemp(), "page.html")
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
- jp = os.path.join(tempfile.mkdtemp(), "page.jsp")
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
- ep = os.path.join(tempfile.mkdtemp(), "view.erb")
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
- jp2 = os.path.join(tempfile.mkdtemp(), "view.ejs")
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