SKY-A137 · AI-code defects
New code only tests call
New code only tests call is a function, method, class or JavaScript file the change added whose only callers are test files. The change added the code and a test for it, but no production code uses it.
- Languages
- Python, TypeScript/JavaScript (symbols and whole files), Java, Kotlin, Go (needs the skylos-go engine), PHP, Rust, and the other languages the dead-code engine reads
- Turned on by
skylos doneafter a change (default baseHEAD, so uncommitted edits), orskylos done --base origin/mainfor a pull request- Quality gate
- not checked (full and diff scans). Only
skylos doneruns this rule, in itsbranch_orphanscheck, which advises by default. It stays advice even withbranch_orphans = "block", unless SKY-A137 is added tobranch_orphans_block_rulesin the base commit'spyproject.toml. - Finding type
- review
Why it matters
A green test for code nothing runs proves nothing about the feature. It is a common sign that an agent built and tested a helper but never wired it into the code path the task was about.
What Skylos flags
"""Order totals for the checkout service.""" def order_total(items): return sum(item["cents"] * item["qty"] for item in items)Added: Added: Added: def apply_coupon(total_cents, percent_off):Added: return round(total_cents * (100 - percent_off) / 100)Removed: from app.orders import order_totalAdded: from app.orders import apply_coupon, order_total def test_order_total_multiplies_quantity(): assert order_total([{"cents": 1250, "qty": 2}]) == 2500Added: Added: Added: def test_coupon_takes_percent_off():Added: assert apply_coupon(2500, 10) == 22501 committed file the change leaves alone
from app.orders import order_total if __name__ == "__main__": print(order_total([{"cents": 1250, "qty": 2}]))What Skylos leaves alone
"""Order totals for the checkout service.""" Removed: def order_total(items):Removed: return sum(item["cents"] * item["qty"] for item in items)Added: def order_total(items, percent_off=0):Added: total = sum(item["cents"] * item["qty"] for item in items)Added: return apply_coupon(total, percent_off)Added: Added: Added: def apply_coupon(total_cents, percent_off):Added: return round(total_cents * (100 - percent_off) / 100)Removed: from app.orders import order_totalAdded: from app.orders import apply_coupon, order_total def test_order_total_multiplies_quantity(): assert order_total([{"cents": 1250, "qty": 2}]) == 2500Added: Added: Added: def test_coupon_takes_percent_off():Added: assert apply_coupon(2500, 10) == 22501 committed file the change leaves alone
Why Skylos leaves it alone
The new apply_coupon and its test are the same, but order_total, which the entry point runs, now calls it. With one production caller the new code is wired in.
More languages
TypeScript
Flagged
export interface Item { cents: number; qty: number;} export function orderTotal(items: Item[]): number { return items.reduce((sum, item) => sum + item.cents * item.qty, 0);}Added: Added: export function applyCoupon(total: number, percentOff: number): number {Added: return Math.round((total * (100 - percentOff)) / 100);Added: }import { expect, test } from "vitest";import { applyCoupon } from "./orders.js"; test("takes the percentage off", () => { expect(applyCoupon(2500, 10)).toBe(2250);});2 committed files the change leaves alone
{"name": "shop", "type": "module", "main": "src/index.ts"}import { orderTotal } from "./orders.js"; console.log(orderTotal([{ cents: 1250, qty: 2 }]));Not flagged
export interface Item { cents: number; qty: number;} Removed: export function orderTotal(items: Item[]): number {Removed: return items.reduce((sum, item) => sum + item.cents * item.qty, 0);Added: export function orderTotal(items: Item[], percentOff = 0): number {Added: const total = items.reduce((sum, i) => sum + i.cents * i.qty, 0);Added: return applyCoupon(total, percentOff);}Added: Added: export function applyCoupon(total: number, percentOff: number): number {Added: return Math.round((total * (100 - percentOff)) / 100);Added: }import { expect, test } from "vitest";import { applyCoupon } from "./orders.js"; test("takes the percentage off", () => { expect(applyCoupon(2500, 10)).toBe(2250);});2 committed files the change leaves alone
Why Skylos leaves it alone
orderTotal now calls applyCoupon, so the test is not its only caller.
How Skylos decides
- Runs in
skylos donewhen the change touches production code. Copies the base commit and the working tree (or pull request head) into private temporary folders, removes test files from both, and runs the regular dead-code analysis on each, with a confidence of 75 or more. Because tests are removed, a symbol only tests call counts as unused. - A function, method or class the change added (its name on no removed line, most of its body new) that is unused in that production view is a candidate, like SKY-A136. Candidates the analyzer is unsure about, ones named in a template, config file or unparsed file, and ones under a registering decorator are not judged; the rest go through the grep check
skylos .uses. - A survivor whose name a test file references (a JS or TS file a test imports) is reported as SKY-A137, and the message names that test. Test files are
tests/and__tests__/folders,test_*.py,conftest.py,*.test.*and*.spec.*files,*_test.goandsrc/test/.
How to fix it
Call the new code from the production path the task is about, and test that path too. If the code is meant for a later change, move it and its test to that change.
def order_total(items, percent_off=0): total = sum(item["cents"] * item["qty"] for item in items) return apply_coupon(total, percent_off)When it can be wrong
- A new public library function that other packages will call is reported while only its own tests use it.
- Which tests "call" the code is decided by name. A test that only imports the name counts, and in JavaScript and TypeScript tests the name on any non-comment line counts, even inside a string. Such a symbol is reported as SKY-A137 rather than SKY-A136.
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
skylos donedoes not read# skylos: ignorecomments for this rule. It is advice by default; to turn the whole check off, set its mode in the base commit'spyproject.toml.TOML [tool.skylos.done.checks]branch_orphans = "off"