Repository navigation
test(contracts): pin daemon convergence, status, and privacy contracts (#1060) - #1085
Conversation
Adds 16 contract tests under tests/unit/daemon/test_daemon_http_contracts.py
covering five families that were previously unpinned at the HTTP-surface
level:
1. Status envelope shape — REQUIRED_STATUS_KEYS / REQUIRED_HEALTH_KEYS
enumerate the documented keys; missing fields must be explicit
null, not absent.
2. Read-only contract — GET /api/status and GET /api/health do not
mutate archive state across repeated polls.
3. Stale/disconnected/degraded — daemon_liveness=False with no
pidfile; health/check returns 503 on degraded health; the
exception path translates to a bounded {ok:false,status:error,...}
envelope rather than a raw traceback; fts_readiness is a
structured dict.
4. Privacy — status payload never leaks VOYAGE/OPENAI/ANTHROPIC
sentinel env vars or a stray POLYLOGUE_TEST_SENTINEL_*; the
static web shell HTML never inlines env-derived secrets;
GET /api/conversations/<id> never returns adjacent rows.
5. Operation specs — RUNTIME_OPERATION_SPECS are strictly
well-formed (name, code_refs, effects, mutates_state matches
declared write effects); DECLARED_OPERATION_SPECS satisfies the
light-touch structural contract; all names are unique.
Tests use the in-process DaemonAPIHandler harness from
test_daemon_http_security.py — no real daemon process, no socket
listener. Each test is @pytest.mark.contract and emits bounded
evidence via record_contract_evidence under
daemon.status.*, daemon.operations.*.
Ref #1060
Ref #1058
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3836ccea7f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| archive_root = workspace_env["archive_root"] | ||
| archive_root.mkdir(parents=True, exist_ok=True) |
There was a problem hiding this comment.
Track DB state in read-only status/health contract tests
These read-only contracts fingerprint only workspace_env["archive_root"], but daemon persistence lives under db_path() (XDG_DATA_HOME/polylogue/polylogue.db) and related WAL files. If a future regression makes GET /api/status or GET /api/health perform convergence/persistence work in the database, these tests will still pass because the mutated files are outside the hashed tree. This leaves the core "no side effects on status polling" contract effectively unguarded for the primary write path.
Useful? React with 👍 / 👎.
Summary
Adds 16 contract tests under
tests/unit/daemon/test_daemon_http_contracts.pycovering five operational daemon HTTP contract families — status envelope shape, read-only convergence behavior, stale/disconnected/degraded state, privacy boundaries, and operation-spec catalog discipline.Problem
The security-boundary contracts of the daemon HTTP surface are pinned by
tests/unit/daemon/test_daemon_http_security.py(added in #1075 / #1076 — auth gates, origin allowlist, JSON serialization fallback). The operational contracts of the same surface were unpinned at the HTTP layer:GET /api/statusenvelope (daemon_liveness,component_state,fts_readiness,convergence,health, …) had no test asserting which keys are required vs. optional. A regression that dropped or renamed a key would only fail downstream in the web reader or dashboard.GET /api/statusandGET /api/healthare read-only — a future change that triggered convergence work as a side effect of status polling could pass review.VOYAGE_API_KEY/OPENAI_API_KEY/ANTHROPIC_API_KEYsentinel env vars, never accidentally dumpsos.environ, and that the static web shell HTML has no inlined secrets.GET /api/conversations/<id>returns only the requested row.OperationSpeccatalog had no assertion that every spec declares the metadata downstream consumers depend on (name shape, code_refs format, effects enum membership,mutates_stateconsistency with declared write effects).Solution
One new file:
tests/unit/daemon/test_daemon_http_contracts.py. FiveTestXclasses, all marked@pytest.mark.contract, all using the in-processDaemonAPIHandlerharness fromtest_daemon_http_security.py(no real daemon process, no socket listener):TestStatusEnvelopeContract— enumeratesREQUIRED_STATUS_KEYS/REQUIRED_HEALTH_KEYSfrom the actualdaemon_status_payload()shape. Extending the envelope requires extending the test in the same PR. Pinscomponent_statesubsystems to{api, watcher, browser_capture}andquick_checkto the documented enum.TestStatusReadOnlyContract— repeated polls of/api/statusand/api/healthleave the archive directory hash unchanged across 3 polls each.TestDegradedStateContract—daemon_liveness=Falsewith no pidfile;/api/health/checkreturns 503 on degraded health (mocks_run_fast_checksto inject a CRITICAL alert); the documented exception path translates to a bounded{ok:false, status:"error", detail:"health check failed"}envelope rather than a raw 500;fts_readinessis asserted to be a structured dict, never a free-form string.TestPrivacyContract— plants sentinel values inVOYAGE_API_KEY/OPENAI_API_KEY/ANTHROPIC_API_KEYand a uniquely-namedPOLYLOGUE_TEST_SENTINEL_ENV_DO_NOT_DUMP, asserts none appear in the serialized status payload; asserts the staticWEB_SHELL_HTMLconstant never inlines env-derived secrets; seeds three conversations (c1/c2/c3) and assertsGET /api/conversations/c1mentionsc1but not the adjacent rows' distinctive markers.TestOperationSpecContract— two-tier check.RUNTIME_OPERATION_SPECSstrictly require kebab-case name, non-trivial description, well-formedcode_refs, declaredeffectsfrom the known enum, andmutates_state=TruewheneverDbWrite|FileWrite|Destructiveis declared.DECLARED_OPERATION_SPECS(superset including scenario/benchmark entries) only require the structural fields — these advisory entries may legitimately omitcode_refs. All names must be unique across the declared catalog.Each test that produces something worth aggregating calls
record_contract_evidence(...)and writes a bounded JSON artifact under.cache/verification/evidence/keyeddaemon.status.envelope,daemon.status.read_only,daemon.status.disconnected,daemon.status.no_secret_leak,daemon.operations.runtime_spec_contract.No daemon source changes required — every contract pins existing behavior. The exception-path contract (the third degraded-state test) confirms the existing
daemon_safe_handler-style try/except in_handle_health_checkworks as documented.Verification
Ref #1060
Ref #1058
🤖 Generated with Claude Code