DD-338 Phase B.1.b: canonical sort-before-return on syncthing_connections
Adds handler-level deterministic ordering to the one multi-record tool in this blade. Sort key is canonical deviceID ascending (dict key from the Syncthing REST API's `/rest/system/connections` response). Implementer-verified shape (architect OQ-5 deferred): the upstream Syncthing REST API returns `connections.connections` as a dict keyed by canonical deviceID — a fixed 64-character base32-shaped hex-class string (e.g. `AAAAAAA-AAAAAAA-...`). The dict key IS the canonical id; `format_connection` consumes `did` as its first positional arg and renders the device's name (or first 8 chars of the deviceID as fallback) at the top of each per-device section. Sort by `kv[0]` (the deviceID) is the canonical Track 2 contract. The change is in-place — a `sorted(..., key=lambda kv: kv[0])` wraps the existing `.items()` view inside the list-comprehension. No LOC delta. Adds tests/test_determinism.py with N=5 byte-equal harness, sort-key correctness, and empty-connections edge case (3 new cases / 136 total). Catalog declaration flip from `unstable → stable` lands in the paired stallari-plugins PR. Version bump 0.6.0 → 0.6.1 (patch — single-tool additive contract). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
4 files changed
+150
-4
No files matched your search
@@ -136,7 +136,7 @@ async def syncthing_device_completion(params: DeviceReadParams) -> str:
|
||||
},
|
||||
)
|
||||
async def syncthing_connections(params: ReadParams) -> str:
|
||||
"""Current connection details for all devices."""
|
||||
"""Current connection details for all devices. Sorted by deviceID ascending."""
|
||||
try:
|
||||
client = get_instance(params.instance)
|
||||
connections = await client._get("/rest/system/connections")
|
||||
@@ -145,11 +145,17 @@ async def syncthing_connections(params: ReadParams) -> str:
|
||||
d["deviceID"]: d.get("name", d["deviceID"][:8])
|
||||
for d in config.get("devices", [])
|
||||
}
|
||||
# DD-338 B.1.b: canonical sort-before-return on deviceID (dict key) ascending.
|
||||
# Syncthing REST API returns `connections.connections` as a dict keyed by
|
||||
# canonical deviceID (hex string per Syncthing protocol convention).
|
||||
result = [
|
||||
format_connection(
|
||||
did, conn, devices_map.get(did, did[:8]), concise=params.concise,
|
||||
)
|
||||
for did, conn in connections.get("connections", {}).items()
|
||||
for did, conn in sorted(
|
||||
connections.get("connections", {}).items(),
|
||||
key=lambda kv: kv[0],
|
||||
)
|
||||
]
|
||||
return fmt(result, concise=params.concise)
|
||||
except Exception as e:
|
||||
|
||||
Reference in new issue
Block a user