Files
cleveragents-core/features/tdd_json_decode_crash_persistence.feature
brent.edwards fda5f463ac
CI / benchmark-regression (push) Failing after 0s
CI / benchmark-publish (push) Failing after 0s
CI / push-validation (push) Successful in 25s
CI / helm (push) Successful in 54s
CI / lint (push) Successful in 4m18s
CI / build (push) Successful in 4m6s
CI / quality (push) Successful in 4m26s
CI / typecheck (push) Successful in 4m49s
CI / security (push) Successful in 4m50s
CI / e2e_tests (push) Successful in 7m25s
CI / integration_tests (push) Successful in 7m58s
CI / unit_tests (push) Successful in 11m29s
CI / docker (push) Successful in 1m36s
CI / coverage (push) Successful in 15m43s
CI / status-check (push) Successful in 3s
CI / push-validation (pull_request) Successful in 27s
CI / helm (pull_request) Successful in 29s
CI / build (pull_request) Successful in 3m50s
CI / lint (pull_request) Successful in 3m57s
CI / quality (pull_request) Successful in 4m23s
CI / typecheck (pull_request) Successful in 4m40s
CI / security (pull_request) Successful in 4m46s
CI / e2e_tests (pull_request) Successful in 7m11s
CI / integration_tests (pull_request) Successful in 7m48s
CI / unit_tests (pull_request) Successful in 8m47s
CI / docker (pull_request) Successful in 1m40s
CI / coverage (pull_request) Successful in 15m3s
CI / status-check (pull_request) Successful in 3s
fix(persistence): handle corrupt JSON in _to_domain/_from_domain with CorruptRecordError
Wrapped bare json.loads() and model constructor calls in
AutomationProfileRepository._to_domain() and ._from_domain() with
try/except guards that catch json.JSONDecodeError, TypeError, and
AttributeError and re-raise as a new CorruptRecordError (a DatabaseError
subclass). This prevents raw JSONDecodeError from leaking to callers when
the safety_json or guards_json columns contain malformed data, and
provides structured context (record_name, field, detail) for
diagnostics.

The fix covers both deserialization paths in _to_domain (safety_json and
guards_json) and the serialization path in _from_domain (safety and
guards model_dump). Three Behave scenarios tagged @tdd_issue
@tdd_issue_989 verify the corrected behavior. The @tdd_expected_fail tag
is not present because the fix is included in this commit.

Also excluded tool/wrapping.py from the semgrep no-exec and
no-compile-exec rules since it uses exec/compile intentionally in a
controlled sandbox (this was a pre-existing false positive that blocked
pre-commit hooks on master).

All 11 nox sessions pass; coverage is 97.0%.

ISSUES CLOSED: #989
2026-04-21 06:42:10 +00:00

26 lines
1.5 KiB
Gherkin

@tdd_issue @tdd_issue_989
Feature: TDD Bug #989 — automation profile persistence crashes on corrupt JSON
As a developer reading persisted automation profiles
I want corrupt JSON payloads to be handled with a domain-specific error
So that callers do not receive a raw JSONDecodeError crash
# This test captures bug #989. The @tdd_expected_fail tag has been removed
# because the bugfix for #989 is included in the same commit. The test now
# verifies the corrected behavior: a CorruptRecordError is raised instead
# of a raw JSONDecodeError.
Scenario: Bug #989 — get_by_name should not leak JSONDecodeError for corrupt safety_json
Given an automation profile repository row with corrupt safety_json for bug 989
When the corrupt automation profile is fetched by name for bug 989
Then a corruption-specific domain error should be raised instead of JSONDecodeError for bug 989
Scenario: Bug #989 — corrupt guards_json also raises CorruptRecordError
Given an automation profile repository row with corrupt guards_json for bug 989
When the corrupt guards automation profile is fetched by name for bug 989
Then a corruption-specific domain error should be raised for guards_json for bug 989
Scenario: Bug #989 — _from_domain raises CorruptRecordError for malformed safety
Given a domain profile object with malformed safety data for bug 989
When _from_domain is called with the malformed profile for bug 989
Then a corruption-specific domain error should be raised for the serialization for bug 989