DD-338 Phase E.python — depend on stallari-mcp-helpers (delete local helpers)

Pure substrate swap. Local `domain_hint.py` (155 LOC) deleted; canonical
`Pattern`, `compute_domain_hint`, `load_patterns_from_yaml` are now imported
from `stallari-mcp-helpers>=0.1.0,<1.0.0`. Local `meta_envelope` +
`append_meta` helpers in `formatters.py` deleted; canonical implementations
re-exported from the lib for backward call-site compatibility.

Surfaced two API divergences vs the spec's "names stay identical" assumption:

1. The lib's `append_meta(body, meta_line)` takes a pre-built meta line; the
   prior blade-local `append_meta(payload, **kwargs)` built the envelope
   internally. All 11 call-sites in `tools/folders.py` (8), `tools/devices.py`
   (1), `tools/instances.py` (1), `tools/system.py` (1) refactored to the
   two-step `append_meta(payload, meta_envelope(...))` pattern.

2. The lib's `compute_domain_hint(record, patterns)` takes 2 args and uses
   built-in dot-path field resolution; the prior blade-local
   `compute_domain_hint(record, patterns, projector)` took a per-blade
   projector callable. The flat record shapes this blade emits (folders +
   devices) resolve identically under either approach. The blade's
   `_syncthing_field_projector` was removed (was only used as the 3rd arg).

Wire-shape change (test fixtures updated for 2 sites):
- `_meta` field order now follows lib convention (matched_total, returned,
  latency_ms, filtered_by, redactions, next_cursor, error_notes?,
  domain_hints?). Prior local helper emitted latency_ms last.
- `_meta.next_cursor` is now always present (defaults to `null`). Tests
  pinning "next_cursor not in meta" updated to "next_cursor is None".
- `_meta.redactions`, `filtered_by`, `error_notes?`, `domain_hints?` all
  unchanged in conditional-inclusion semantics.

Pure substrate swap — no behavioural change to any tool. Pack-spec catalog
declarations unchanged.

Version: 0.7.0 → 0.8.0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
PiersandClaude Opus 4.7 committed 2026-05-24 09:38:46 +10:00
1 parent 2f630d9fe7
commit b3a5f23450
13 files changed
+212 -348

No files matched your search

+18 -37
View File
@@ -1,42 +1,23 @@
"""DD-338 A.2.dom.c — domain_hint pattern engine tests.
"""DD-338 A.2.dom.c — domain_hint pattern engine smoke-tests.
Tests the pure engine (Pattern, compute_domain_hint, load_patterns_from_yaml)
plus a local copy of the Syncthing field projector so the test file doesn't
trigger FastMCP server boot via ``syncthing_mcp.server`` import.
DD-338 Phase E.python — the pattern engine moved from the local
``syncthing_mcp.domain_hint`` module to the canonical
``stallari_mcp_helpers`` package. These tests now exercise the lib's
public surface and serve as a lightweight blade-side smoke-test
confirming the lib resolves the record shapes this blade emits
(folders + devices) correctly. The lib's own test suite is the
authoritative coverage layer.
"""
from __future__ import annotations
from typing import Any
from syncthing_mcp.domain_hint import (
from stallari_mcp_helpers import (
Pattern,
compute_domain_hint,
load_patterns_from_yaml,
)
# ---------------------------------------------------------------------------
# Local copy of _syncthing_field_projector — mirrors server.py to avoid
# importing the FastMCP server module (which spins up registry on import).
# ---------------------------------------------------------------------------
def _projector(record: dict[str, Any], field: str) -> Any:
if not isinstance(record, dict):
return None
if field in {"id", "label", "path", "type"}:
return record.get(field)
if field == "deviceID":
return record.get("deviceID")
if field == "name":
return record.get("name")
if field == "addresses":
v = record.get("addresses")
return v if isinstance(v, list) else None
return None
# ---------------------------------------------------------------------------
# compute_domain_hint
# ---------------------------------------------------------------------------
@@ -45,7 +26,7 @@ def _projector(record: dict[str, Any], field: str) -> Any:
def test_empty_patterns_returns_none() -> None:
"""No patterns ⇒ no domain hint regardless of record shape."""
record = {"id": "test", "label": "Test", "path": "/Family/photos"}
assert compute_domain_hint(record, [], _projector) is None
assert compute_domain_hint(record, []) is None
def test_single_pattern_match_folder() -> None:
@@ -57,7 +38,7 @@ def test_single_pattern_match_folder() -> None:
"type": "sendreceive",
}
patterns = [Pattern(field="path", op="contains", value="/Family/", domain="family")]
assert compute_domain_hint(record, patterns, _projector) == "family"
assert compute_domain_hint(record, patterns) == "family"
def test_first_match_wins() -> None:
@@ -72,21 +53,21 @@ def test_first_match_wins() -> None:
Pattern(field="path", op="contains", value="/work/", domain="work"),
Pattern(field="path", op="contains", value="/Family/", domain="family"),
]
assert compute_domain_hint(record, patterns, _projector) == "work"
assert compute_domain_hint(record, patterns) == "work"
def test_glob_wildcard_on_label() -> None:
"""fnmatch glob op handles wildcard label matches."""
record = {"id": "f1", "label": "Work Notes", "path": "/x"}
patterns = [Pattern(field="label", op="glob", value="Work*", domain="work")]
assert compute_domain_hint(record, patterns, _projector) == "work"
assert compute_domain_hint(record, patterns) == "work"
def test_projector_returns_none_for_unknown_field() -> None:
"""Unknown projector field ⇒ no match, no crash."""
def test_unknown_field_returns_none() -> None:
"""Unknown field path ⇒ no match, no crash."""
record = {"id": "f1", "label": "L", "path": "/x"}
patterns = [Pattern(field="nonsense", op="equals", value="x", domain="d")]
assert compute_domain_hint(record, patterns, _projector) is None
assert compute_domain_hint(record, patterns) is None
def test_device_record_addresses_list_match() -> None:
@@ -97,14 +78,14 @@ def test_device_record_addresses_list_match() -> None:
"addresses": ["dynamic", "tcp://10.0.0.5:22000"],
}
patterns = [Pattern(field="addresses", op="contains", value="10.0.0.5", domain="ops")]
assert compute_domain_hint(record, patterns, _projector) == "ops"
assert compute_domain_hint(record, patterns) == "ops"
def test_device_record_equals_deviceid() -> None:
"""Exact deviceID match emits the configured domain."""
record = {"deviceID": "ABCDEFG-XYZ", "name": "h"}
patterns = [Pattern(field="deviceID", op="equals", value="ABCDEFG-XYZ", domain="ops")]
assert compute_domain_hint(record, patterns, _projector) == "ops"
assert compute_domain_hint(record, patterns) == "ops"
# ---------------------------------------------------------------------------
+7 -3
View File
@@ -491,8 +491,10 @@ class TestFolderNeed:
assert isinstance(meta["returned"], int)
assert isinstance(meta["latency_ms"], int)
assert meta["returned"] == 3
# next_cursor must NOT be present per OQ-4 (v1)
assert "next_cursor" not in meta
# DD-338 Phase E.python — canonical lib always emits `next_cursor`
# (as `null` when caller passes None / omits the kwarg); semantic
# OQ-4 invariant unchanged (no cursor surfaced to callers in v1).
assert meta["next_cursor"] is None
# DD-338 Phase C Wave 2 — filtered_by content
async def test_filtered_by_contains_pagination(self, mock_api):
@@ -549,7 +551,9 @@ class TestRemoteNeed:
assert isinstance(meta["returned"], int)
assert isinstance(meta["latency_ms"], int)
assert meta["returned"] == 3
assert "next_cursor" not in meta
# DD-338 Phase E.python — canonical lib always emits `next_cursor`
# (as `null` when caller passes None / omits the kwarg).
assert meta["next_cursor"] is None
# DD-338 Phase C Wave 2 — filtered_by content
async def test_filtered_by_contains_device_and_pagination(self, mock_api):