Repository navigation
refactor(daemon): table-drive route contract coverage (#1847) - #2158
Conversation
Problem: #1847 had route-contract metadata, but the daemon dispatcher still kept most implemented routes in ad hoc conditionals. Tests derived auth coverage from ROUTE_CONTRACTS, so a new implemented route could still skip classification if the dispatcher and metadata drifted apart.\n\nWhat changed: authenticated daemon GET routes now dispatch through static and parameterized route tables that expose implemented route patterns. User-state HTTP routing now uses the same table-shaped model. Route-contract tests compare the live dispatcher patterns against ROUTE_CONTRACTS in both directions, and docs describe the checked relationship.\n\nVerification: devtools test tests/unit/daemon/test_user_state_http.py::TestDispatchRouting::test_empty_id_in_get_path_does_not_route tests/unit/daemon/test_route_contracts.py tests/unit/daemon/test_daemon_http_security.py -> 404 passed. devtools verify --quick -> exit_code 0. devtools verify --seed-testmon --skip-slow -> 11493 passed, 1 xfailed, exit_code 0.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughReplaces ChangesTable-driven HTTP routing and route-contract enforcement
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@polylogue/daemon/http.py`:
- Around line 191-207: The POST route patterns are currently hardcoded in two
separate locations: the routes list in `implemented_daemon_route_patterns()` and
the actual POST matching logic in `_do_post_impl()`. This duplication creates a
maintenance gap where routes can drift out of sync. Extract the POST route
definitions into a shared constant or class-level data structure (e.g., a list
of tuples containing the POST endpoints) that both `_do_post_impl()` and the
routes list in `implemented_daemon_route_patterns()` can reference, ensuring a
single source of truth for all POST route patterns.
- Around line 11-16: Fix the 8 mypy --strict errors across the polylogue
directory: In machine_main.py at line 117, remove the redundant condition
causing the error. In gateway.py at line 174, add explicit return type
annotations instead of returning Any. In sqlite_vec_embeddings.py at line 42,
add proper type annotations to the untyped decorator. In registry.py at line 61,
provide missing or correct type arguments to fix the type-arg error. In
raw_state.py at lines 217 and 248, add explicit return type annotations to avoid
no-any-return violations. In query_output_contracts.py at line 78, add explicit
return type annotations to fix the no-any-return error. In
click_option_groups.py at line 47, remove the unused type: ignore comment.
Ensure all changes pass mypy --strict validation before merging.
In `@tests/unit/daemon/test_route_contracts.py`:
- Around line 30-40: The tests convert the result of
implemented_daemon_route_patterns() to a set before comparison, which masks any
duplicate route pairs in the actual implementation since sets automatically
remove duplicates. Add an explicit assertion that checks for uniqueness in the
raw sequence returned by implemented_daemon_route_patterns() before converting
it to a set. This assertion should verify that the length of the raw sequence
equals the length of the set, or compare the sequence to its set representation
to catch accidental duplicate (method, pattern) entries in both
test_route_contract_no_stale_docs and
test_route_contract_metadata_targets_live_daemon_routes functions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6d3713b4-7fb4-4b68-a9c8-b707076d22d6
📒 Files selected for processing (5)
docs/daemon.mdpolylogue/daemon/http.pypolylogue/daemon/route_contracts.pypolylogue/daemon/user_state_http.pytests/unit/daemon/test_route_contracts.py
| from dataclasses import dataclass, replace | ||
| from datetime import datetime | ||
| from http import HTTPStatus | ||
| from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer | ||
| from pathlib import Path, PurePath | ||
| from typing import TYPE_CHECKING, Any, cast | ||
| from typing import TYPE_CHECKING, Any, Literal, cast |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
targets=()
for d in polylogue tests devtools; do
if [ -d "$d" ]; then
targets+=("$d")
fi
done
ruff format --check "${targets[@]}"
ruff check "${targets[@]}"
mypy --strict "${targets[@]}"Repository: Sinity/polylogue
Length of output: 183
🏁 Script executed:
pip install mypy --quiet && \
mypy --strict polylogue tests devtools 2>&1 | head -100Repository: Sinity/polylogue
Length of output: 739
🏁 Script executed:
/home/jailuser/.local/bin/mypy --strict polylogue tests devtools 2>&1 | head -150Repository: Sinity/polylogue
Length of output: 21275
🏁 Script executed:
/home/jailuser/.local/bin/mypy --strict polylogue/daemon/http.py && \
cat -n polylogue/daemon/http.py | head -30Repository: Sinity/polylogue
Length of output: 1037
🏁 Script executed:
cat -n polylogue/daemon/http.py | head -30Repository: Sinity/polylogue
Length of output: 1268
🏁 Script executed:
/home/jailuser/.local/bin/mypy --strict polylogue/daemon/http.py 2>&1 | grep "polylogue/daemon/http.py"Repository: Sinity/polylogue
Length of output: 42
🏁 Script executed:
/home/jailuser/.local/bin/mypy --strict polylogue/daemon/http.py 2>&1Repository: Sinity/polylogue
Length of output: 1037
🏁 Script executed:
/home/jailuser/.local/bin/mypy --strict polylogue/daemon/http.py --show-traceback 2>&1 | head -30Repository: Sinity/polylogue
Length of output: 1037
Quality gates are not passing. Fix 8 mypy --strict errors before merge.
The code fails mypy --strict type checking in the polylogue directory:
polylogue/cli/machine_main.py:117- redundant conditionpolylogue/sources/drive/gateway.py:174- no-any-returnpolylogue/storage/search_providers/sqlite_vec_embeddings.py:42- untyped decoratorpolylogue/insights/registry.py:61- type-arg errorpolylogue/storage/sqlite/queries/raw_state.py:217, 248- no-any-returnpolylogue/cli/query_output_contracts.py:78- no-any-returnpolylogue/cli/click_option_groups.py:47- unused type: ignore comment
ruff format and ruff check pass, but per the coding guidelines, all code in polylogue/, tests/, and devtools/ must pass mypy --strict with no excludes.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@polylogue/daemon/http.py` around lines 11 - 16, Fix the 8 mypy --strict
errors across the polylogue directory: In machine_main.py at line 117, remove
the redundant condition causing the error. In gateway.py at line 174, add
explicit return type annotations instead of returning Any. In
sqlite_vec_embeddings.py at line 42, add proper type annotations to the untyped
decorator. In registry.py at line 61, provide missing or correct type arguments
to fix the type-arg error. In raw_state.py at lines 217 and 248, add explicit
return type annotations to avoid no-any-return violations. In
query_output_contracts.py at line 78, add explicit return type annotations to
fix the no-any-return error. In click_option_groups.py at line 47, remove the
unused type: ignore comment. Ensure all changes pass mypy --strict validation
before merging.
Source: Coding guidelines
Address CodeRabbit review on #2158. POST route patterns now come from the same table used by dispatch and implemented-route inventory, and route-contract tests assert implemented route pairs are unique before set comparison.\n\nVerification: devtools test tests/unit/daemon/test_route_contracts.py tests/unit/daemon/test_daemon_http_security.py tests/unit/daemon/test_user_state_http.py::TestDispatchRouting::test_empty_id_in_get_path_does_not_route -> 404 passed. devtools verify --quick -> exit_code 0. devtools verify -> 701 passed, exit_code 0.
|
Review follow-up:
Verification after review fixes:
|
Summary
Refactors the daemon HTTP route boundary so implemented route patterns are exposed from the routing tables used at runtime, then checks those live routes against
ROUTE_CONTRACTSin both directions. This keeps #1847's route-class/auth/payload metadata from drifting away from the dispatcher while preserving the existing auth behavior.Problem
#1847 already had route-contract metadata and route/security tests, but the daemon dispatcher still carried most routes in an ad hoc conditional chain. The security matrix derived from
ROUTE_CONTRACTS, so a newly implemented route could still skip classification if a future edit touched dispatch but forgot the metadata. That weakens the web/API boundary exactly where #1847 is trying to make it explicit.Solution
polylogue/daemon/http.py.UserStateRoutetable inpolylogue/daemon/user_state_http.py.implemented_daemon_route_patterns()from the live dispatcher tables and compare it againstROUTE_CONTRACTSin both directions.:idsegments do not route.Verification
devtools test tests/unit/daemon/test_route_contracts.py tests/unit/daemon/test_daemon_http_security.py tests/unit/daemon/test_web_reader.py -k 'route_contract or auth or cross_origin or read_view_execution or recovery_endpoint or assertions_endpoint'->324 passed, 197 deselected.devtools verify --seed-testmon --skip-slowcaught a route-table regression:tests/unit/daemon/test_user_state_http.py::TestDispatchRouting::test_empty_id_in_get_path_does_not_routefailed because empty:idmatched. Fixed the matcher.devtools test tests/unit/daemon/test_user_state_http.py::TestDispatchRouting::test_empty_id_in_get_path_does_not_route tests/unit/daemon/test_route_contracts.py tests/unit/daemon/test_daemon_http_security.py->404 passed.devtools verify --quick->exit_code: 0.devtools verify --seed-testmon --skip-slow->11493 passed, 1 xfailed,exit_code: 0, peak pytest RSS3419.1 MiB.devtools verify->7 passed,exit_code: 0.Summary by CodeRabbit
Release Notes