Stevesolun commited on
Commit
041f1b0
·
verified ·
1 Parent(s): c8b5444

Add files using upload-large-folder tool

Browse files
src/ctx_monitor.py CHANGED
@@ -1714,10 +1714,18 @@ def _read_sidecar_file(path: Path) -> dict | None:
1714
  def _load_sidecar(slug: str, entity_type: str | None = None) -> dict | None:
1715
  if not _is_safe_slug(slug):
1716
  return None
1717
- for path in (
1718
  _sidecar_dir() / f"{slug}.json",
1719
  _sidecar_dir() / "mcp" / f"{slug}.json",
1720
- ):
 
 
 
 
 
 
 
 
1721
  if not path.exists():
1722
  continue
1723
  sidecar = _read_sidecar_file(path)
@@ -1725,7 +1733,7 @@ def _load_sidecar(slug: str, entity_type: str | None = None) -> dict | None:
1725
  continue
1726
  if entity_type is None or _sidecar_entity_type(sidecar) == entity_type:
1727
  return sidecar
1728
- if entity_type is not None:
1729
  return _sidecar_index().get((slug, entity_type))
1730
  return None
1731
 
 
1714
  def _load_sidecar(slug: str, entity_type: str | None = None) -> dict | None:
1715
  if not _is_safe_slug(slug):
1716
  return None
1717
+ paths = [
1718
  _sidecar_dir() / f"{slug}.json",
1719
  _sidecar_dir() / "mcp" / f"{slug}.json",
1720
+ ]
1721
+ if entity_type is not None:
1722
+ suffixes = [entity_type]
1723
+ if entity_type == "mcp-server":
1724
+ suffixes.append("mcp")
1725
+ for suffix in suffixes:
1726
+ paths.append(_sidecar_dir() / f"{slug}-{suffix}.json")
1727
+
1728
+ for path in paths:
1729
  if not path.exists():
1730
  continue
1731
  sidecar = _read_sidecar_file(path)
 
1733
  continue
1734
  if entity_type is None or _sidecar_entity_type(sidecar) == entity_type:
1735
  return sidecar
1736
+ if entity_type is not None and _SIDECAR_INDEX_CACHE_VALUE is not None:
1737
  return _sidecar_index().get((slug, entity_type))
1738
  return None
1739
 
src/tests/test_ctx_monitor.py CHANGED
@@ -766,6 +766,20 @@ def test_load_sidecar_can_disambiguate_duplicate_slug(fake_claude: Path) -> None
766
  assert harness["grade"] == "A"
767
 
768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769
  def test_monitor_post_requires_token(
770
  fake_claude: Path, monkeypatch: pytest.MonkeyPatch,
771
  ) -> None:
 
766
  assert harness["grade"] == "A"
767
 
768
 
769
+ def test_load_sidecar_typed_miss_does_not_build_global_index(
770
+ fake_claude: Path,
771
+ monkeypatch: pytest.MonkeyPatch,
772
+ ) -> None:
773
+ _write_sidecar(fake_claude, "unrelated", {"slug": "unrelated"})
774
+ monkeypatch.setattr(
775
+ cm,
776
+ "_sidecar_index",
777
+ lambda: (_ for _ in ()).throw(AssertionError("cold full sidecar scan")),
778
+ )
779
+
780
+ assert cm._load_sidecar("missing", entity_type="skill") is None
781
+
782
+
783
  def test_monitor_post_requires_token(
784
  fake_claude: Path, monkeypatch: pytest.MonkeyPatch,
785
  ) -> None:
src/tests/test_ctx_monitor_3type.py CHANGED
@@ -220,7 +220,9 @@ def test_wiki_index_sampling_is_sorted_by_slug(wiki_3type: Path) -> None:
220
 
221
  def test_wiki_entity_page_marks_truncated_body_and_frontmatter(
222
  wiki_3type: Path,
 
223
  ) -> None:
 
224
  long_description = "x" * 160
225
  long_body = "body-line\n" * 1400
226
  (wiki_3type / "entities" / "skills" / "long-page.md").write_text(
 
220
 
221
  def test_wiki_entity_page_marks_truncated_body_and_frontmatter(
222
  wiki_3type: Path,
223
+ monkeypatch: pytest.MonkeyPatch,
224
  ) -> None:
225
+ monkeypatch.setattr(_cm, "_render_entity_subgraph", lambda *_, **__: "")
226
  long_description = "x" * 160
227
  long_body = "body-line\n" * 1400
228
  (wiki_3type / "entities" / "skills" / "long-page.md").write_text(