Repository navigation
test(environments): cover non-dict valid JSON secrets in _sessions_token_from_secret - #2053
Open
janmejai2002 wants to merge 1 commit into
Open
janmejai2002 wants to merge 1 commit into
janmejai2002 wants to merge 1 commit into
Conversation
mangeshraut712
left a comment
There was a problem hiding this comment.
Good catch on closing that test gap. Testing valid base64-encoded JSON primitives (array, string, int, bool) directly exercises if not isinstance(parsed, dict): return None where previously only the json.JSONDecodeError branch on non-JSON plaintext was covered.
This branch has not been deployed
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.
PR Brief: Add Unit Test Coverage for Non-Dict JSON Payloads in
_sessions_token_from_secretRepository:
anthropics/anthropic-sdk-pythonTarget File:
src/anthropic/lib/environments/_worker.pyTarget Function:
_sessions_token_from_secretPatch File:
findings/anthropic-sdk-python_fix.patchDiscovery Engine: Cordis Verification Engine (Gate 2 Coverage-Verified Mutation Analysis)
1. Problem Statement
In
src/anthropic/lib/environments/_worker.py,_sessions_token_from_secret(secret: str | None) -> str | Noneextracts the per-item sessions bearer token from a work item's URL-safe base64secretpayload.Lines 295–296 guard against payloads that decode to valid JSON that are not JSON objects (dictionaries):
However, upstream tests in
tests/lib/environments/test_worker.py::test_sessions_token_from_secretonly tested invalid base64 and non-JSON plaintext (b"plain text"), which raisesjson.JSONDecodeErrorand exits earlier on line 293. The test suite did not test valid base64-encoded JSON that decodes to non-dict JSON primitives (lists, strings, numbers, booleans).As a result, an AST mutation perturbing line 296 (
return Noneto a non-None value or removing the check) survived upstream test runs with zero failures.2. Invariant Fix
Added explicit unit test assertions in
tests/lib/environments/test_worker.py::test_sessions_token_from_secretverifying that valid base64-encoded JSON scalars and sequences (list,str,int,bool) correctly resolve toNone:3. Verification & Mutation Kill Rate
report.target_executed == True(function execution actively verified under test suite).1 passed, 38 deselected in 0.59s).