{
  "id": 41567,
  "title": "The Bug Class Where Your Code Is Correct, Your Tests Pass, and It Never Runs",
  "url": "https://urgent.news/2026/08/02/the-bug-class-where-your-code-is-correct-your-tests-pass-and-it-never",
  "topic": "culture",
  "section": "Culture",
  "published": "2026-08-02T12:06:58.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/neu_portal_999f2396dbff8d/the-bug-class-where-your-code-is-correct-your-tests-pass-and-it-never-runs-11d4"
  },
  "original_language": "en",
  "account": "Three significant software defects in the article all share a common characteristic: they were coded correctly, passed tests, yet never executed the paths that mattered due to improper configuration paths or misunderstood assumptions.\n\nCase 1 involved a feature that at first glance appeared fine, but a toggle value (useConditioning=false) was the root cause. The code was written correctly, unit tests passed, and its presence never alerted anyone to its absence. The toggle defaulted to false, meaning the conditioned intervals never ran, and the published bands were always the unconditional ones. Test coverage was high at 84%, masking the issue as the test only verified the unconditional path.\n\nCase 2 introduced a function that maintained internal state across invocations. In Pine Script, this is typical for moving averages and correlations. The code looked correct as it returned plausible numbers for the EMA branch, but this branch was never taken because only one of the two branches (EMA or SMA) executed per bar. The other branch was fed incomplete data, resulting in an incorrect moving average. Writing the function to compute both branches unconditionally and then select the correct one fixed the issue.\n\nCase 3 focused on a text sanitizer function meant to convert typographic characters to ASCII. However, it contained a check that replaced \" - \" with \" - \", effectively collapsing indentation in files. This check ran fine in \"check mode\", flagging false positives. Yet in \"fix mode\", it silently altered the files' structure. This clean-up step, designed for a specific case, became a global transformation affecting every file. The unit tests for this function only verified the specific case where it was supposed to work, missing its negative impact on other inputs.\n\nThe key takeaway is that unit tests, which call the functions directly, do not account for the larger context of how components interact and under what conditions they execute. Reviewing the call graph, specifically identifying paths under which components run is crucial. Every default should be regarded as a decision point that can alter execution paths. By checking observable outputs rather than internal states, and by actively tracing through all possible execution paths after adding new features, many such subtle defects could be uncovered early. In essence, written code is not always as reliable as it seems; it must be rigorously verified to ensure it runs under the conditions it was intended to.",
  "summary": "The article highlights three common software defects that can go unnoticed despite the code being correctly written and tests passing. In the first case, a feature toggle was incorrectly set to false, resulting in the conditional logic never executing, leading to the publication of unconditional forecast intervals instead of the intended conditioned ones. The second case involves a stateful function that only updates its internal state when its branch is taken, causing the other branch to process data with incomplete history and produce incorrect moving average values. Lastly, the third case demonstrates a sanitization function that removes double spaces, but contains a while loop that checks for the wrong character, inadvertently leaving double spaces untouched. These examples illustrate how even well-tested and seemingly correct code can contain subtle bugs that only manifest when the specific conditions are met.",
  "key_points": [
    "Correct code passed tests but never executed due to improper configuration paths.",
    "Toggle value defaulting to false caused conditioned intervals to never run in Case 1.",
    "Silent alteration of file structure in Case 3 due to a specific check in text sanitizer function."
  ],
  "editors_take": null,
  "illustration": "https://urgent.news/ill/41567.png",
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}