Repository navigation
docs: rules for using assert, test the -O guard - #10521
Merged
ThomasWaldmann merged 1 commit intoOct 12, 2026
Merged
Conversation
…8649 Add a "Using assert" section to the development docs: assert is only for conditions that can be false only due to a borg bug; everything coming from outside (repo objects, local files, legacy data, remote responses, user input, OS results) needs a real check that raises a borg exception, done at the boundary where the data enters. Add a regression test that borg refuses to run with assertions disabled (python -O and PYTHONOPTIMIZE=1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10521 +/- ##
==========================================
- Coverage 89.34% 89.32% -0.02%
==========================================
Files 104 104
Lines 20079 20079
Branches 3152 3152
==========================================
- Hits 17940 17936 -4
- Misses 1481 1484 +3
- Partials 658 659 +1 ☔ View full report in Codecov by Harness. |
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.
Refs #8649.
The assert policy from #8649 only existed in the issue body, so asserts get converted one module at a time without a written criterion. This adds the rules to the development docs and a regression test for the startup guard (noted as missing in #10019).
Docs: new "Using assert" section in
docs/development.rstassertonly for conditions that can be false only through a borg bug: internal invariants, pre-/postconditions between borg's own functions, argument types from borg's own callers, unreachable branches.if ...: raise ...: repository/store objects (authenticated does not mean well-formed), local cache/config/key files, legacy borg 1.x data, remote responses, user input, OS/filesystem results. Prefer borg's exception classes (IntegrityError,Errorsubclasses with an exit code);ValueError/TypeErroronly where callers catch them.src/borg/archiver/__init__.pyonly covers code paths that importborg.archiver.assert.Test
test_refuses_to_run_without_assertionsinsrc/borg/testsuite/archiver/version_cmd_test.pyrunspython -O -m borg --versionandPYTHONOPTIMIZE=1 python -m borg --versionand checks for rc 2, the "Borg requires working assertions" message on stderr and empty stdout.🤖 Generated with Claude Code