fix(detectors): reject null trust threshold - #555
Open
DevaanshPathak wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes configuration validation in InvoiceTrustOverrideDetector so an explicitly configured min_amount=None is rejected during initialization, avoiding a later runtime TypeError when comparing an invoice amount to None.
Changes:
- Update
_validate_configto validatemin_amountbased on key presence (reject explicitNone, still allow omission). - Add unit tests covering explicit
None, omittedmin_amount, and a valid positive value.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
finbot/ctf/detectors/implementations/invoice_trust_override.py |
Adjusts config validation to treat an explicit min_amount=None as invalid while preserving omitted-key default behavior. |
tests/unit/ctf/test_invoice_trust_override_config.py |
Adds regression tests for min_amount being None, omitted, and positive. |
Suppressed comments (1)
tests/unit/ctf/test_invoice_trust_override_config.py:22
- To verify the default-threshold behavior when
min_amountis omitted, assert that a config lookup falls back toDEFAULT_MIN_AMOUNT(rather than only assertingdetector.config == {}).
assert detector.config == {}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
min_amount=Noneduring detector initializationRoot cause
The validation guard checked whether the retrieved value was non-null rather than whether the configuration key was present. This made an explicit null value indistinguishable from an omitted setting during validation, even though later lookup returned the null value instead of the default threshold.
Impact
Invalid configuration now fails fast with a clear
ValueErrorinstead of allowing the detector to initialize and later crash with aTypeErrorwhile processing a qualifying approval event.Testing
uv run pytest tests/unit/ctf/test_invoice_trust_override_config.py— 3 passeduv run pytest tests/unit/ctf— 30 passed, 1 skippeduv run black --check tests/unit/ctf/test_invoice_trust_override_config.pyuv run isort --check-only finbot/ctf/detectors/implementations/invoice_trust_override.py tests/unit/ctf/test_invoice_trust_override_config.pyFixes #126