test(telemetry): add coverage for PolicyRegisteredEvent - #4338
Open
TomeHirata wants to merge 1 commit into
Open
Conversation
PolicyRegisteredEvent was defined and called in both policy routes but
had zero test coverage. Add three test groups:
1. _build_record serialisation (tests/test_telemetry.py): verify that
admin-scope (session_id=None) and session-scope events produce the
correct wire format — promoted top-level fields vs. params content.
2. Default-policy route emit (tests/server/routes/test_default_policies.py):
POST /v1/policies fires exactly one PolicyRegisteredEvent with
scope='admin'; a 409 conflict does not emit.
3. Session-policy route emit (tests/server/routes/test_session_policies_crud.py):
POST /v1/sessions/{id}/policies fires exactly one PolicyRegisteredEvent
with scope='session' and the correct session_id; a 409 conflict does not emit.
Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
Contributor
|
| into ``params``. Admin policies have ``session_id=None`` which becomes | ||
| an empty string in the wire format. | ||
| """ | ||
| import omnigent.telemetry.client as _mod |
| ``session_id`` is a real string for session-scoped policies and must appear | ||
| as the top-level ``session_id`` field, not inside ``params``. | ||
| """ | ||
| import omnigent.telemetry.client as _mod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PolicyRegisteredEventwas defined and wired into both policy creation routes (POST /v1/policiesandPOST /v1/sessions/{id}/policies) but had zero test coverage.Changes
tests/test_telemetry.py— two unit tests for_build_recordserialisation:session_id=None) produces empty-stringsession_idin the wire envelope and putshandler/policy_type/scopeinparams.session_id="sess_abc123") promotes the session ID to the top-level field and keeps it out ofparams.tests/server/routes/test_default_policies.py— two route-level tests:POST /v1/policiesfires exactly onePolicyRegisteredEventwithscope='admin'andsession_id=None.tests/server/routes/test_session_policies_crud.py— two route-level tests:POST /v1/sessions/{id}/policiesfires exactly onePolicyRegisteredEventwithscope='session'and the correctsession_id.Test Plan
All 6 pass locally.
Demo
N/A — test-only change, no UI.
Type of change
Test coverage
Coverage notes
N/A