Skip to main content

SKY-A115 · AI-code defects

Test answer hard-coded in code

High

Reported as advice, not as a blocking finding, when the evidence is weaker: the test does not call the function, the assertion is new in the change, the function has no other way to compute its answer, the input is a trivial value or a single word, or the input and answer are small enough to be a real edge case.

A hard-coded test answer is a branch, match or switch case, or lookup table that recognises one test's exact input and returns that test's exact expected answer. SKY-A115 compares the lines a change added to non-test code with the assertions in the repository's tests and reports such a match.

Languages
Python, JavaScript, TypeScript
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 test_special_casing check. That check blocks by default: a blocking SKY-A115 finding fails the done verdict, and advice findings are listed without failing it. Set the check to "advise" or "off" under [tool.skylos.done.checks] in the base commit's pyproject.toml to change that.
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 coding agent that cannot make a failing test pass may teach the code the test instead of fixing the logic. The test goes green, every other input still gets the wrong answer, and the change looks like a fix in review.

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).

billing/discounts.py · Python · changed
"""Loyalty discounts for the checkout service."""  def loyalty_discount(order_total, years):Added:     if order_total == 250.0 and years == 7:Added:         return 17.5    rate = min(years, 5) * 0.01    return round(order_total * rate, 2)
1 committed file the change leaves alone
tests/test_discounts.py · Python
from billing.discounts import loyalty_discount  def test_seven_year_customer_gets_seven_percent():    assert loyalty_discount(250.0, 7) == 17.5

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).

billing/discounts.py · Python · changed
"""Loyalty discounts for the checkout service."""  def loyalty_discount(order_total, years):Removed:     rate = min(years, 5) * 0.01Added:     if order_total == 0:Added:         return 0.0Added:     rate = min(years, 10) * 0.01    return round(order_total * rate, 2)
1 committed file the change leaves alone
tests/test_discounts.py · Python
from billing.discounts import loyalty_discount  def test_seven_year_customer_gets_seven_percent():    assert loyalty_discount(250.0, 7) == 17.5  def test_empty_order_gets_no_discount():    assert loyalty_discount(0, 7) == 0.0

Why Skylos leaves it alone

The new branch also returns one test's exact answer for that test's exact input, but the input is 0, a trivial value that real base cases use all the time. The change also fixes the rate, so the seven-year test passes by computing the answer.

More languages

JavaScript

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/shipping.js · JavaScript · changed
const RATE_PER_KG = 3.2; export function shippingCost(weightKg) {Added:   if (weightKg === 12.5) {Added:     return 43.75;Added:   }  return Math.round(weightKg * RATE_PER_KG * 100) / 100;}
1 committed file the change leaves alone
tests/shipping.test.js · JavaScript
import { expect, test } from "vitest";import { shippingCost } from "../src/shipping.js"; test("charges the per-kilo rate", () => {  expect(shippingCost(12.5)).toBe(43.75);});

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/shipping.js · JavaScript · changed
Removed: const RATE_PER_KG = 3.2;Added: const RATE_PER_KG = 3.5; export function shippingCost(weightKg) {Added:   if (weightKg === 0) {Added:     return 0;Added:   }  return Math.round(weightKg * RATE_PER_KG * 100) / 100;}
1 committed file the change leaves alone
tests/shipping.test.js · JavaScript
import { expect, test } from "vitest";import { shippingCost } from "../src/shipping.js"; test("charges the per-kilo rate", () => {  expect(shippingCost(12.5)).toBe(43.75);}); test("an empty parcel costs nothing", () => {  expect(shippingCost(0)).toBe(0);});

Why Skylos leaves it alone

The rate is fixed, so the 12.5 kg test passes by computing 43.75. The new zero-weight branch matches a test too, but 0 is a trivial input, so it is left alone.

How Skylos decides

  1. Runs in skylos done, which compares the working tree (or a pull request) with a base commit. Only lines the change added to non-test Python, JavaScript and TypeScript files are read; test files, test helper folders and conftest.py are skipped.
  2. Collects special cases on the added lines: an if, conditional expression, match or switch case, or dictionary or object lookup that compares an input with a literal and answers with a literal. Cases whose answer restates the input, or whose inputs and answer are all trivial (0, 1, -1, empty, None, booleans), are dropped.
  3. Reads the repository's Python and JavaScript/TypeScript tests and looks for an assertion that passes the same input and expects the same answer. A special case that matches no assertion is not reported, and one whose exact code was already in the base version (moved or reformatted) is not new.
  4. Blocks only when everything points at the test: the test calls the function by name, the assertion was already in the base version, the function also computes its answer another way, no input is trivial or a single word, no string input or answer is already quoted in non-test code at the base, and the values are specific (a number of two or more digits or with a fraction, two or more inputs, a collection, or text of more than one word).
  5. Anything weaker is reported as advice, or dropped when the input is a single word such as a keyword or an enum value and the evidence is weak. A special case in generated code, or in a new file nothing imports or runs, is advice too.

How to fix it

Remove the special case and fix the general calculation, so every input gets the right answer and the test passes for the right reason.

Fix · Python
def loyalty_discount(order_total, years):    rate = min(years, 10) * 0.01    return round(order_total * rate, 2)

When it can be wrong

  • A real business rule whose numbers happen to equal a test's input and answer, such as a fixed price for one product size, can be reported. Quoting the value as a named constant elsewhere in the code at the base turns a string match into advice; numbers are not looked up.
  • It only sees literal comparisons on added lines. A special case hidden in a data file, computed from the test's name, or added in an earlier commit than the base is not reported.

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. To make the whole check advisory, set its mode in the base commit's pyproject.toml; settings in the change itself are ignored.

    TOML
    [tool.skylos.done.checks]test_special_casing = "advise"

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