SKY-A101 · AI-code defects
Test assertion weakened
A test is weakened when a change replaces a precise check with a vague one: == 2400 becomes is not None, pytest.raises(ValueError, match=…) disappears, or the test gets skipped. SKY-A101 compares each changed test file with the base version and reports these swaps.
- Languages
- Python tests (pytest, unittest), JavaScript/TypeScript tests (Jest, Vitest, node:assert), snapshot files
- Turned on by
skylos . --ai-defects --diff origin/main(or-a) on a change; also listed as advice byskylos done- Quality gate
- counted toward the gate limits (full and diff scans). Counts toward
max_ai_defects.skylos donelists it as advice and does not block on it. - Finding type
- review
- Catalog name
- Test assertion weakening
Why it matters
A coding agent that cannot make a test pass sometimes edits the test instead of the code. The suite stays green while the behaviour it protected is no longer checked, and reviewers rarely spot a one-line change in a test file.
What Skylos flags
"""Invoice maths for the checkout service.""" Removed: TAX_RATE = 0.2Added: TAX_RATE = 0.25 def calculate_total(items): subtotal = sum(item["price"] * item["qty"] for item in items) return round(subtotal * (1 + TAX_RATE))from billing.invoices import calculate_total def test_total_includes_tax(): items = [{"price": 1000, "qty": 2}] total = calculate_total(items) Removed: assert total == 2400Added: assert total is not NoneWhat Skylos leaves alone
"""Invoice maths for the checkout service.""" Removed: TAX_RATE = 0.2Added: TAX_RATE = 0.25 def calculate_total(items): subtotal = sum(item["price"] * item["qty"] for item in items) return round(subtotal * (1 + TAX_RATE))from billing.invoices import calculate_total def test_total_includes_tax(): items = [{"price": 1000, "qty": 2}] total = calculate_total(items) Removed: assert total == 2400Added: assert total == 2500Why Skylos leaves it alone
The tax rate changed and the test still checks one exact value, the new one. Changing an expected value is a normal part of changing behaviour; only a swap from a precise check to a vague one is reported.
How Skylos decides
- Runs with
--ai-defectswhen there is a change to compare: in a diff scan (--diffor--diff-base), or in a full scan of a Git checkout with uncommitted changes (in CI, the pull request's changes when the base branch is known and fetched). It reads the Git diff of each changed file against the base; untracked files have no diff and are skipped. - Looks only at test files: a
tests,testor__tests__folder anywhere in the file's full path,test_*,*_test.py,test.pyandtests.pynames,.test.and.spec.files, and snapshot files. - Splits each changed hunk by test, and classes every removed and added line. Strong checks compare a value or an exception:
==,<,in,pytest.raises,assertEqual,toBe,toEqual,toThrow. Weak checks only test that something exists or is truthy: a bareassert x,is not None,assertTrue,assertIsNotNone,toBeDefined,toBeTruthy. - For each test in the hunk, reports the first weakening, in this order: a skip or
xfailadded; snapshot content changed or removed; an exception check loosened (match=dropped, widened toException) or removed; a negative test deleted; a mock check broadened (assert_called_once_withtoassert_called);spec=orautospecremoved from a mock; an expected value replaced byANY;== vwidened toin (v, …); a value check turned into a length check; a behaviour check replaced byis not None; or a strong check replaced by a weak one with no new strong check in the same hunk. - Reports on the added line in the new file. A hunk that only deletes lines (a removed
pytest.raises, a deleted negative test) is reported at its line in the base version, and only by a full scan: a--diffscan drops findings on deleted lines. Inskylos donethe findings are advice and do not block.
How to fix it
Keep the precise assertion and update the expected value to the new, intended behaviour. If the value really cannot be known any more, say why in the pull request and test a property that still matters, such as the type or a range.
assert total == 2500When it can be wrong
- A deliberate contract change, such as a function that now returns an opaque ID instead of a number, is reported. That is intended: it asks the reviewer to confirm the change.
- A new test file that arrives already skipped is reported as HIGH once it is staged or committed in the diff.
skylos donelists it as advice too: it exempts only lines inside a new test's body, and the skip decorator sits above thedef. - If the checkout itself sits inside a folder named
testsortest, every changed file counts as a test file, because the folder check reads the full path. - Because checks are compared within one hunk, a precise assertion moved further down the file can leave the weak one reported.
- It does not see an assertion deleted outright,
== 2400changed to>= 0, a looserpytest.approxtolerance, or an assertion moved into a helper function. In a--diffscan it also misses deletion-only changes such as a removedpytest.raisesblock.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
On the added line, with the reason the weaker check is right:
Python assert total is not None # skylos: ignore[SKY-A101] total now comes from pricing[tool.skylos] ignore = ["SKY-A101"]turns the rule off for the project.