test: regression guard for devcontainer JSON trailing-data parse error#855
Conversation
|
@Bryan-Roe Unfortunately, I hit an error while trying to use the custom Copilot setup steps configured for this repository and had to close this PR. The error I am seeing is: Once you or someone with the necessary access fixes the problem, please unassign and then reassign issue #0 to me and I'll retry. Thanks! |
Add tests/test_devcontainer_config.py to verify that both .devcontainer/devcontainer.json and .devcontainer/devcontainer-lock.json are valid JSON with no trailing data. Root cause of build-and-test CI failure (job 86511118286): a stray ` }` appended after the root object in devcontainer-lock.json caused @devcontainers/cli to throw: SyntaxError: Unexpected non-whitespace character after JSON at position 2143 aborting the devcontainer build step entirely. The structural fix (removing the stray brace) was applied in commit 6b470e3. These tests prevent regression.
Use json.JSONDecoder().raw_decode() in the trailing-data tests so that the end position of the JSON value is explicitly checked, rather than relying on json.loads() implicitly. This makes the test intent clear and produces a descriptive failure message showing exactly what trailing characters were found and at which offset.
There was a problem hiding this comment.
Sorry @Bryan-Roe, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
@Bryan-Roe Thanks for sending me some feedback. Unfortunately, I hit an error while trying to use the custom Copilot setup steps configured for this repository. The error I am seeing is: Once you or someone with the necessary access fixes the problem, please let me know in a comment and I'll try again. Thanks! |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
| """ | ||
| decoder = json.JSONDecoder() | ||
| try: | ||
| _parsed, end_index = decoder.raw_decode(content) |
The
build-and-testdevcontainer CI job failed because.devcontainer/devcontainer-lock.jsonhad a stray}after the root closing brace, causing@devcontainers/clito throwSyntaxError: Unexpected non-whitespace character after JSON at position 2143and abort the build.The structural fix (removing the stray brace) landed in PR #852. This PR adds a regression test to catch the same class of corruption before it reaches CI.
Changes
tests/test_devcontainer_config.py— four@pytest.mark.unittests:test_devcontainer_json_is_valid_json/test_devcontainer_lock_json_is_valid_json— basicjson.loads()validitytest_devcontainer_json_no_trailing_data/test_devcontainer_lock_json_no_trailing_data— usesJSONDecoder.raw_decode()to explicitly verify no non-whitespace content follows the root object, with a descriptive failure message showing the offset and trailing bytes