SKY-A115 · AI-code defects
Test answer hard-coded in code
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 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 itstest_special_casingcheck. 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'spyproject.tomlto change that. - Finding type
- review
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
"""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
from billing.discounts import loyalty_discount def test_seven_year_customer_gets_seven_percent(): assert loyalty_discount(250.0, 7) == 17.5What Skylos leaves alone
"""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
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.0Why 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
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
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
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
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
- 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 andconftest.pyare skipped. - Collects special cases on the added lines: an
if, conditional expression,matchorswitchcase, 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. - 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.
- 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).
- 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.
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 donedoes not read# skylos: ignorecomments. To make the whole check advisory, set its mode in the base commit'spyproject.toml; settings in the change itself are ignored.TOML [tool.skylos.done.checks]test_special_casing = "advise"