Repository navigation
test: expand trace redaction regression coverage - #34
Merged
utsab345 merged 1 commit intoOct 24, 2026
Merged
Conversation
Cover the gaps named in utsab345#29 that the existing tests did not reach: - credentials in exception messages, including a multi-line traceback and a dotenv-style KEY=value line; - string items inside lists, with per-item finding paths; - the Authorization: Bearer header form, asserted to redact exactly once; - ordinary values (ints, floats, bools, None, empty strings, Devanagari text, and a literal [REDACTED]) preserved untouched. Add direct coverage for prepare_trace_for_persistence, which had none: event redaction entries and their JSON-pointer paths, a credential inside a manifest failure message recorded against the manifest sentinel id, appending to an existing event redactions list, rejection of a credential in a protected structural field, non-mutation of the input trace, and stability across a second pass. Record the formats the current pattern set does not redact as a parametrized regression pin, so adding a pattern for one of them is a deliberate change rather than an unnoticed one. README already documents redaction as best effort, so this claims nothing stronger. No production code changed.
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.
Fixes #29
Summary
Expands
tests/unit/test_redaction.pyto cover the areas #29 names — credential formats, nested structures, exception messages, and values that must survive untouched — and adds the first direct tests forprepare_trace_for_persistence, the function that runs before persistence and previously had none.No production code is changed, and no stronger guarantee than the README's existing "best-effort" is claimed.
Changes
Exception messages and other shapes the existing tests did not reach
Authorization: Bearer …, asserted to redact exactly once (the two overlapping patterns must not double-substitute);OPENAI_API_KEY=sk-…line;/log/1);int,float,bool,None, empty string, Devanagari text, and a literal[REDACTED];prepare_trace_for_persistence(previously untested)redactionslist written, manifest entry carries(event_id, path, reason), and no raw secret in the dumped payload;MANIFEST_REDACTION_ID;redactionslist rather than replacing it;RedactionErrorraised for a credential in a protected structural field;Regression pin for formats outside the pattern set — a parametrized test records what is not redacted today, so adding a pattern for one of them is a deliberate change instead of an unnoticed one.
Behaviour observed while writing these tests
Reporting rather than fixing, since a fix would exceed a test-coverage PR:
{"token": …}key is not redacted.SENSITIVE_KEY_NORMALIZEDholdsaccesstoken,sessiontoken,refreshtoken,authtokenandbearertoken, but nottokenitself, so{"token": "<opaque bearer>"}passes through unless the value also matches a credential pattern. This is the one entry in the pinned list that may be worth changing; the smallest fix is addingtokento that set, though it would also redact non-secret uses of the key, so it is a judgement call for a maintainer.Authorization: Basic …is not covered by the pattern set (onlyBearer).redactionslist still records the path, so nothing is lost from a bundle written once, but a second pass over a loaded trace would report no redactions. The test pins this so changing it is deliberate.Also not covered, and out of scope for "supported credential formats": AWS access keys, Slack (
xoxb-), Google (AIza), GitLab (glpat-), and PEM private-key blocks.Testing
All fixtures use synthetic values only. Tests are deterministic and offline — no network access, no real credentials.
Checklist