Skip to main content

SKY-A137 · AI-code defects

New code only tests call

Low

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 done after a change (default base HEAD, so uncommitted edits), or skylos done --base origin/main for a pull request
Quality gate
not checked (full and diff scans). Only skylos done runs this rule, in its branch_orphans check, which advises by default. It stays advice even with branch_orphans = "block", unless SKY-A137 is added to branch_orphans_block_rules in the base commit's pyproject.toml.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

app/orders.py · Python · changed
"""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)
tests/test_orders.py · Python · changed
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) == 2250
1 committed file the change leaves alone
app/cli.py · Python
from app.orders import order_total if __name__ == "__main__":    print(order_total([{"cents": 1250, "qty": 2}]))

What Skylos leaves alone

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

app/orders.py · Python · changed
"""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)
tests/test_orders.py · Python · changed
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) == 2250
1 committed file the change leaves alone

app/cli.py: same as in the flagged example.

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

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

src/orders.ts · TypeScript · changed
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: }
src/orders.test.ts · TypeScript · new file
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
package.json · JSON
{"name": "shop", "type": "module", "main": "src/index.ts"}
src/index.ts · TypeScript
import { orderTotal } from "./orders.js"; console.log(orderTotal([{ cents: 1250, qty: 2 }]));

Not flagged

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

src/orders.ts · TypeScript · changed
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: }
src/orders.test.ts · TypeScript · new file
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

package.json: same as in the flagged example.

src/index.ts: same as in the flagged example.

Why Skylos leaves it alone

orderTotal now calls applyCoupon, so the test is not its only caller.

How Skylos decides

  1. Runs in skylos done when 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.
  2. 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.
  3. 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.go and src/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.

Fix · Python
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 done does not read # skylos: ignore comments for this rule. It is advice by default; to turn the whole check off, set its mode in the base commit's pyproject.toml.

    TOML
    [tool.skylos.done.checks]branch_orphans = "off"

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.