<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anatoly Khelmer on Medium]]></title>
        <description><![CDATA[Stories by Anatoly Khelmer on Medium]]></description>
        <link>https://medium.com/@anatoly.khelmer?source=rss-e502c1ce0fe2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GXJ_RZAaFXZ9ZMYv.jpg</url>
            <title>Stories by Anatoly Khelmer on Medium</title>
            <link>https://medium.com/@anatoly.khelmer?source=rss-e502c1ce0fe2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 05:30:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anatoly.khelmer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Google Linked Code Quality to Speed. Coverage Cannot Be the Way We Measure It.]]></title>
            <link>https://medium.com/@anatoly.khelmer/google-linked-code-quality-to-speed-coverage-cannot-be-the-way-we-measure-it-460382190a25?source=rss-e502c1ce0fe2------2</link>
            <guid isPermaLink="false">https://medium.com/p/460382190a25</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Anatoly Khelmer]]></dc:creator>
            <pubDate>Sun, 27 Sep 2026 15:54:21 GMT</pubDate>
            <atom:updated>2026-09-27T15:58:03.543Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDYs1WY8_TGVs7xe28fcDQ.png" /></figure><p>I deleted !arrays || from a guard in <a href="https://github.com/radashi-org/radashi">radashi</a>, a TypeScript utility library that fails CI below 100% line and branch coverage.</p><pre>// before<br>if (!arrays || !arrays.length) {<br>// after<br>if (!arrays.length) {</pre><p>Then I ran their CI command, pnpm test. All 911 tests passed. Coverage stayed at 100% lines and 100% branches, including on unzip.ts, the file I had just edited.</p><p>The suite is serious. Blanking a different guard, in replaceOrAppend, to if (false) failed a test. The harness kills mutants. It left this one alive.</p><p>if (!arrays || !arrays.length) is two questions. A coverage report records that the branch ran. Every test already passed a defined array, so both operands were evaluated, the line was green, and the null check was free to disappear. The tool counted an execution. The suite never asked the question the condition exists to answer.</p><h3>What Google actually measured</h3><p>In 2022, Lan Cheng, Emerson Murphy-Hill, and colleagues at Google published <a href="https://research.google/pubs/what-improves-developer-productivity-at-google-code-quality/">“What Improves Developer Productivity at Google? Code Quality”</a> at ESEC/FSE. They followed the same engineers over time — panel data, 39 factors from surveys and engineering logs — and looked at what moved with productivity.</p><p>Satisfaction with the code quality of an engineer’s own project was the strongest of the 39, by standardized effect size. Technical debt, infrastructure, shifting priorities, and code review were in the model too. The lagged analysis is the part worth quoting. A step from “very dissatisfied” to “very satisfied” with project code quality was followed, in the next period, by a 10% drop in median active coding time per changelist, a 12% drop in wall-clock time until the change was sent for review, and a 22% drop in wall-clock time from submit to deploy. The reverse order — faster engineers later reporting better code — did not appear.</p><p>Read that narrowly. One company. The first model uses how productive an engineer felt; the lag uses logs. The 39 factors are survey ratings and build, review, and coding-time logs. What the study measured was whether engineers considered the project’s code good, and whether that judgment came before they got faster.</p><p>A merge gate at 80% or 100% line coverage is a weak stand-in for that judgment. radashi was already at the ceiling, and a condition could still vanish without a red build. Once a team has seen that, the green check stops meaning “safe to change.” Refactors slow down, reviews get longer, and the confidence Google associated with speed drains away under a metric that was supposed to protect it.</p><h3>Agents optimize the rubric you hand them</h3><p>Coding agents make a bad rubric cheap to satisfy. A feature and a test file that executes every line take seconds. expect(result).toBeDefined() is enough for Istanbul, and enough for a model that is scored on the coverage diff in the pull request.</p><p>The model is solving the metric. Line coverage asks whether the line ran. A test that calls the function and asserts that the return value exists answers that question and says nothing about the order, the error, or the empty input.</p><p>Leave the rubric as “percentage of lines executed,” and an agent writing the tests will keep producing suites that pass the gate and miss the behavior. The rubric is the part to change.</p><h3>What DeepCover scores</h3><p>I wrote <a href="https://github.com/anatolykhelmer/deepcover">DeepCover</a> for TypeScript projects tested with Jest or Vitest. Istanbul remains the record of whether a line ran. DeepCover scores whether the tests pin the behavior.</p><p>Three stages.</p><p><strong>Extract</strong> is deterministic. It parses the module from the TypeScript AST: each || / &amp;&amp; operand split out, each assertion mapped to the function it targets, mocks, and the call graph. Jest or Vitest coverage is merged in when you have it. No model in this stage.</p><p><strong>Reason</strong> is a model, deliberately. Your coding agent, or an API, reads that model and writes structured JSON: which situations the function can be in, which of them a test reaches, how strong each assertion is, what is covered only because a caller asserts through it. Influence on a sub-score is capped at 20 points, so a fluent writeup cannot turn a weak suite into a high score. --no-llm skips this stage and keeps the deterministic pass.</p><p><strong>Analyze</strong> prints a composite, the sub-scores, and a ranked list of gaps.</p><p>On radashi’s src/array, 35 functions, against that same 100% suite:</p><pre>Composite 89/100<br>  Assertion Quality  100<br>  State Coverage      63</pre><p>Assertion quality at 100 fits the suite. The tests that exist use real matchers. State coverage at 63 means 37 of 112 domain states have no test. A domain state is a situation the function can be in — count &lt;= 0, a filter that removes every element — rather than a line that executed.</p><p>I checked two of those gaps by inserting a throw and re-running the suite. It stayed green for iterate when count &lt;= 0, and for select when a non-empty input is filtered down to nothing. The state is in the source. No test puts the function there. Line coverage had already given those functions full marks.</p><p>The same run flagged a miss the suite had already tried to close. toggle and selectFirst both decide &quot;found&quot; with Array.prototype.find, which returns undefined when nothing matched and when the matched element is undefined. A hit on undefined looks like a miss: toggle appends instead of removing, selectFirst never runs the mapper. radashi already had a test named should work with falsy values, covering 0 and null, and CI still required 100% coverage. I opened <a href="https://github.com/radashi-org/radashi/issues/482">radashi#482</a> and <a href="https://github.com/radashi-org/radashi/issues/483">radashi#483</a> with repros. Other contributors sent the fixes. Both were merged and published in radashi 12.9.5 within two days.</p><p>The same split is how this stays honest once agents write the tests. The agent that wrote the test can be the reasoner. It is held to a different rubric: the extractor has already listed the operands and the assertions, and the reasoner has a point cap. A test that only proves the line ran stays visible as a weak assertion or a missing state.</p><h3>One limit, in the open</h3><p>The deleted !arrays || was a hand edit. I ran radashi&#39;s suite myself. On that run there was no per-operand branch data, so the operand check was disabled. With the data, the check would still have missed this mutant: both operands run whenever the function is called with an array, and the detector does not yet notice that !arrays is never the one that decides. The same blind spot exists for a guard that returns, such as if (!a || !a.length) return [].</p><p>The full score also needs a coding agent as the reasoner. --no-llm is the deterministic half, which is the half you can run unattended.</p><p>What I will claim is smaller than “every boundary is tested.” On a library that already required 100%, the report named states the suite never builds, and two of those states survived a throw. Two more were real bugs. The maintainers shipped the fixes in two days.</p><h3>Try it</h3><pre>npx @anatolykhelmer/deepcover run --root . --module src/your-module</pre><p>The package is @anatolykhelmer/deepcover. The reasoner uses your coding agent; --no-llm prints the deterministic pass. Keep the coverage gate. Add a number that moves when the tests stop meaning anything.</p><p>Source: <a href="https://github.com/anatolykhelmer/deepcover">github.com/anatolykhelmer/deepcover</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=460382190a25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your coding agent has no memory. That’s a quality problem]]></title>
            <link>https://medium.com/@anatoly.khelmer/your-coding-agent-has-no-memory-thats-a-quality-problem-eed23f511f73?source=rss-e502c1ce0fe2------2</link>
            <guid isPermaLink="false">https://medium.com/p/eed23f511f73</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Anatoly Khelmer]]></dc:creator>
            <pubDate>Tue, 18 Aug 2026 15:51:09 GMT</pubDate>
            <atom:updated>2026-08-18T15:51:09.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QnEyRqKlrs5QNAlD-l_aDQ.png" /></figure><p><em>Kaizen and ISO 9001 are the same idea: a small, recorded loop beats a heroic postmortem.</em></p><p>I have spent most workdays for months writing code with Cursor and Claude. They are fast. They are confident. And every morning they are a different hire: they do not remember yesterday’s bug, the agreement that we do not invent mocks, or the fact that the payment API docs are wrong in one specific place.</p><p>“Be careful” in a system prompt does not scale. A factory does not run that way.</p><h4>A new employee every day</h4><p>A coding agent is not a linter. A linter remembers the rules because the rules live in the repo. An agent remembers only what made it into the current chat: the files you opened, the skill that fired, the sentence you said five minutes ago.</p><p>Close the session and it has left the company. Open a new one and you are doing onboarding again. A brilliant intern with amnesia. If you spent half an hour yesterday proving that a schema matched the docs and disagreed with production, today it will cheerfully generate the same schema. Not out of spite. It has no yesterday.</p><p>That is why “write the perfect prompt” is the wrong goal. A prompt is an induction talk. It is not the standard on the line.</p><h4>Kaizen, ISO 9001, and the boring loop that works</h4><p>Kaizen is the Japanese idea of continual improvement. Not a big project called “let’s clean up the process,” but many small changes: notice a gap, change the standard, check that the line no longer does that. Toyota did not wait for a perfect manual. They recorded millimetres.</p><p>ISO 9001 asks a quality system for the same thing, in audit language: Plan, Do, Check, Act. Plan how the problem will not recur. Do it. Check whether it worked. If it did not, change the standard, not the people. The standard calls this continual improvement. The certificate on the wall is irrelevant. The loop that keeps a lesson from dying after the postmortem is not.</p><p>Mapped onto an agent, it is almost literal.</p><p>The gap is not in the model. It lives in the process: the agent never sees a live JSON payload, it only runs the new tests, it treats optional().default(0) as harmless. While that gap sits in a chat transcript, it does not exist. The next session starts from a blank page — and from the same hole.</p><p>A quality system for someone who is onboarded from scratch every time looks like this: notice → write it down → turn it into a skill, a rule, or a checklist → the next chat hits that control <em>before</em> you have time to get angry.</p><h4>The story where money successfully became zero</h4><p>I needed a schema for a payment API response: TypeScript types and Zod, to validate JSON. Ordinary work. The agent opened the docs and wrote the schema in minutes.</p><p>In the docs the field was called refund_amount. In the live response it was amount_refunded.</p><p>The parser was not supposed to “fail” on a missing field, so the agent hung .optional().default(0) on it. Next came a business check: have we already refunded this money? It looked at the parsed object, saw zero, and said: no. Refund again.</p><p>The unit tests were green. The mocks were copied from the same schema the agent had just invented from the docs. Three layers of one error: paper, types, fixtures. They agreed with each other and disagreed with production.</p><p>It did not ship. It could have.</p><p>I was not angry at the model. It did exactly what people do when the deadline is close: trust the PDF and plug the hole with a default. 0 looks safe. On a money field it is not a safe default. It is camouflage.</p><p>The lesson is not “read the docs more carefully.” Documentation is a hypothesis. The contract is the JSON that actually arrives. Until you have checked field names, nesting, and what disappears without expand, the schema is fan fiction with a green test suite.</p><h4>The same incident as PDCA</h4><p><strong>Plan.</strong> Before writing a DTO, get a live response: staging, a log, an MCP call, anything as long as it is real JSON. Check the names. Look at money fields twice. If a field can be absent, write down <em>why</em> — do not hang default(0) on it so the parser stays quiet.</p><p><strong>Do.</strong> Do not keep this in your head, and do not paste another paragraph into the system prompt. Turn it into a skill. Trigger: any new Zod schema or DTO for an external API. Rule: test fixtures are copied from a live response, not from the docs. .optional().default() on amounts is a red flag until there is a comment.</p><p><strong>Check.</strong> The next similar ticket. Did the skill fire on its own, or did I spend five minutes again saying “do not trust the docs”?</p><p><strong>Act.</strong> If it did not fire, tighten the description and the trigger. Do not type “be smarter next time” into the chat. The chat will die. The standard that lives outside the chat has to get smarter.</p><p>That is Kaizen. Not a two-hour retro. One gap, one artifact, one check that the artifact is alive.</p><h4>Where the lesson goes if it has nowhere to go</h4><p>The real problem is not one wrong field name. It is the environment: the insight dies with the transcript. You can be careful today. Tomorrow it is a different chat, a different model, a different hurry. Without a place to put the gap, you catch it heroically with your hands again.</p><p>I keep a separate git repo for that: <a href="https://github.com/anatolykhelmer/kaizen-backlog">kaizen-backlog</a>. It is not a product backlog (“we want feature X”) and it is not a wiki. When a session goes wrong, a skill is missing, or a lesson is about to dissolve, it becomes a task. The task has a trigger, an analysis, a decision log. The deliverable is a skill, a rule, or a checklist the agent will actually pick up in the next chat. The board is generated from the tasks, so I cannot pretend we “already talked about this.”</p><p>The template is public and deliberately empty. Someone else’s list of landmines will not help you. The loop will: notice, record, close it with a skill, check that the next agent can see it.</p><h4>A process that remembers for the agent</h4><p>There will be no perfect prompt. There will be another quiet bug. The agent will still sound sure of itself, and it will still remember nothing.</p><p>The difference between “another bad session” and a quality system is one thing: the lesson sits where the next agent is required to look. Not in your head. Not in a dead chat. In a standard you improved by a millimetre after the money almost became zero.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eed23f511f73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[100% Test Coverage and a Permanent Inventory Leak]]></title>
            <link>https://medium.com/@anatoly.khelmer/100-test-coverage-and-a-permanent-inventory-leak-4d9c9ea21b32?source=rss-e502c1ce0fe2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d9c9ea21b32</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Anatoly Khelmer]]></dc:creator>
            <pubDate>Sun, 09 Aug 2026 07:39:18 GMT</pubDate>
            <atom:updated>2026-09-27T08:10:45.466Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Why line coverage can’t tell a good test suite from a worthless one — and what I built instead.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZr0SEO54f_P7jCVDYzIjw.png" /></figure><p>Here is a test. It passes. It contributes to 100% line coverage.</p><pre>it(&#39;creates an order&#39;, async () =&gt; {<br>  const order = await service.createOrder(&#39;cust-1&#39;, [<br>    { sku: &#39;SKU-1&#39;, qty: 2, unitPrice: 25 },<br>  ]);<br> <br>  expect(order).toBeDefined();<br>});</pre><p>It would also pass if createOrder charged the customer twice, returned the wrong total, forgot to send the confirmation email, or silently destroyed inventory. toBeDefined() asks one question — <em>did I get something back?</em> — and every one of those disasters answers yes.</p><p>Istanbul doesn’t care. It instruments your code, watches which lines execute, and reports a percentage. Execution is all it can see. Whether anything <em>checked</em> what happened during that execution is outside its vocabulary.</p><p>So we ship a number to the dashboard, gate the PR on it, and feel protected by a suite that would survive most of the bugs it exists to catch.</p><p>I got tired of that number. I built <strong>DeepCover</strong> to produce a different one.</p><h4>The idea</h4><p>DeepCover combines deterministic AST analysis with bounded LLM reasoning to produce a <em>meaningful coverage</em> score: not “what ran”, but “what’s actually protected”.</p><p>The split matters. Static analysis is exact but semantically blind — it can tell you a test uses toBeDefined(), but not that &quot;HTTP 429 rate limiting&quot; is a business scenario nobody tested. An LLM can spot the second but will happily hallucinate the first. So DeepCover gives each side the job it&#39;s good at, and — importantly — caps how much the LLM can move the final number.</p><p>Rather than describe it further, let me show you two real runs.</p><p>Everything below comes from an actual NestJS 11 + Jest 30 project. Every number is copied from real terminal output — no illustrative figures, no rounded-for-the-narrative scores.</p><h4>Warm-up: a calculator that lies about empty strings</h4><p>Start small. A CalculatorService with four operations and two guard clauses, plus a controller that validates query params:</p><pre>@Injectable()<br>export class CalculatorService {<br>  calculate(a: number, b: number, operation: Operation): number {<br>    switch (operation) {<br>      case &#39;add&#39;:      return a + b;<br>      case &#39;subtract&#39;: return a - b;<br>      case &#39;multiply&#39;: return a * b;<br>      case &#39;divide&#39;:<br>        if (b === 0) {<br>          throw new BadRequestException(&#39;Division by zero is not allowed&#39;);<br>        }<br>        return a / b;<br>      default:<br>        throw new BadRequestException(`Unknown operation: ${operation}`);<br>    }<br>  }<br>}</pre><p>The tests are genuinely reasonable. Not strawmen — the kind of thing a competent developer writes:</p><pre>it(&#39;adds two numbers&#39;, () =&gt; {<br>  expect(service.calculate(2, 3, &#39;add&#39;)).toBe(5);<br>});<br> <br>it(&#39;throws on division by zero&#39;, () =&gt; {<br>  expect(() =&gt; service.calculate(1, 0, &#39;divide&#39;)).toThrow(BadRequestException);<br>});</pre><p>Exact values. Typed exceptions. Every branch hit. Jest reports 100% statements, lines and functions.</p><p>Now, DeepCover’s deterministic mode — no LLM at all:</p><pre>Composite Score: 100/100<br> <br>  Assertion Quality      ██████████  100<br>  State Coverage         ░░░░░░░░░░  0<br>  Mutation Resilience    ██████████  100<br>  Criticality Weight     ██████████  100</pre><p>100/100. The static analyzer agrees with Istanbul: these assertions pin exact values, every branch is reached, nothing looks wrong. Note that State Coverage is 0 and <em>doesn’t drag the score down</em> — with no reasoner there are no discovered states, so the sub-score is marked inapplicable and its weight is redistributed across the other three. Deterministic analysis is honest about what it cannot see.</p><p>Then run it with the reasoning phase enabled:</p><pre>Composite Score: 87/100<br> <br>  Assertion Quality      ██████████  100<br>  State Coverage         ██████░░░░  56<br>  Mutation Resilience    ██████████  100<br>  Criticality Weight     ██████████  100<br> <br>Top gaps:<br>  #1 MED  CalculatorService.calculate — &quot;division yielding a fractional result<br>          is not silently truncated&quot;<br>  #2 MED  CalculatorService.calculate — &quot;NaN or Infinity reaching the service<br>          directly — the service has no numeric validation of its own, only the<br>          controller guards, so it silently returns NaN&quot;<br>  #3 MED  CalculatorController.calculate — &quot;an empty-string param coerces to 0<br>          rather than being rejected — Number(&#39;&#39;) is 0, so ?a=&amp;b=2&amp;op=add<br>          silently returns 2&quot;<br>  #4 MED  CalculatorController.calculate — &quot;a division-by-zero request<br>          propagates the service&#39;s exception to the caller&quot;</pre><p>Gap #3 is a real bug. The controller’s guard looks airtight:</p><pre>if (aRaw === undefined || bRaw === undefined ||<br>    Number.isNaN(a) || Number.isNaN(b)) {<br>  throw new BadRequestException(&#39;Query params &quot;a&quot; and &quot;b&quot; must be valid numbers&#39;);<br>}</pre><p>But Number(&#39;&#39;) is 0, not NaN. So an empty parameter sails straight through validation. I checked:</p><pre>?a=&amp;b=2&amp;op=add  -&gt;  {&quot;result&quot;:2}</pre><p>A missing operand returns an answer. Every line of that guard is covered. Every branch is hit. The test suite is green, and the endpoint is wrong.</p><p>Two things worth noticing here. First, assertion quality was <em>correctly</em> rated 100 — DeepCover isn’t a pessimism machine that marks everything down. Second, the drop from 100 to 87 came entirely from State Coverage, the one sub-score that requires semantic understanding of the domain.</p><p>Now the real case.</p><h4>The main event: an order service</h4><p>OrdersService.createOrder does what a hundred backends do. Validate the cart, reserve inventory, apply a coupon, charge the customer, send a confirmation:</p><pre>async createOrder(customerId: string, items: OrderItem[], couponCode?: string): Promise&lt;Order&gt; {<br>  if (items.length === 0) {<br>    throw new BadRequestException(&#39;Order must contain at least one item&#39;);<br>  }<br> <br>  const reserved: OrderItem[] = [];<br>  for (const item of items) {<br>    if (!this.inventory.reserve(item.sku, item.qty)) {<br>      for (const rollback of reserved) {<br>        this.inventory.release(rollback.sku, rollback.qty);<br>      }<br>      throw new ConflictException(`Out of stock: ${item.sku}`);<br>    }<br>    reserved.push(item);<br>  }<br> <br>  const subtotal = items.reduce((sum, item) =&gt; sum + item.unitPrice * item.qty, 0);<br>  const discount = this.applyDiscount(subtotal, couponCode);<br>  const total = subtotal - discount;<br> <br>  const payment = await this.payments.charge(customerId, Math.round(total * 100));<br>  if (payment.status === &#39;declined&#39;) {<br>    throw new BadRequestException(&#39;Payment was declined&#39;);<br>  }<br> <br>  const order: Order = { /* ... */ status: &#39;paid&#39;, transactionId: payment.transactionId };<br>  this.notifications.sendOrderConfirmation(order);<br>  return order;<br>}</pre><p>Read the failure paths carefully.</p><p>The out-of-stock path releases everything it already reserved before throwing — a proper compensating rollback. The declined-payment path throws immediately. <strong>It never releases the inventory it reserved seconds earlier.</strong></p><p>Every declined card permanently destroys stock. The items are gone from inventory, no order exists, no error is logged, nothing anywhere points at the cause. You find out weeks later when the warehouse count doesn’t match the database.</p><p>This is exactly the class of bug that survives code review, because the two failure paths are forty lines apart and each looks fine on its own.</p><h4>What Jest says</h4><p>Eighteen tests across five suites. Here is the shape of them:</p><pre>it(&#39;creates an order&#39;, async () =&gt; {<br>  const order = await service.createOrder(&#39;cust-1&#39;, [{ sku: &#39;SKU-1&#39;, qty: 2, unitPrice: 25 }]);<br>  expect(order).toBeDefined();<br>});<br> <br>it(&#39;applies the SAVE10 coupon&#39;, async () =&gt; {<br>  const order = await service.createOrder(&#39;cust-1&#39;, [{ sku: &#39;SKU-1&#39;, qty: 1, unitPrice: 200 }], &#39;SAVE10&#39;);<br>  expect(order.total).toBeGreaterThan(0);<br>});<br> <br>it(&#39;rejects an order when the payment is declined&#39;, async () =&gt; {<br>  await expect(<br>    service.createOrder(&#39;cust-1&#39;, [{ sku: &#39;SKU-1&#39;, qty: 1, unitPrice: 0 }]),<br>  ).rejects.toThrow();<br>});</pre><p>The verdict:</p><pre>---------------------------|---------|----------|---------|---------|<br>File                       | % Stmts | % Branch | % Funcs | % Lines |<br>---------------------------|---------|----------|---------|---------|<br> src/orders                |     100 |    88.63 |     100 |     100 |<br>  inventory.service.ts     |     100 |      100 |     100 |     100 |<br>  notification.service.ts  |     100 |      100 |     100 |     100 |<br>  orders.controller.ts     |     100 |       75 |     100 |     100 |<br>  orders.module.ts         |     100 |      100 |     100 |     100 |<br>  orders.service.ts        |     100 |    88.46 |     100 |     100 |<br>  payment.gateway.ts       |     100 |      100 |     100 |     100 |<br>---------------------------|---------|----------|---------|---------|<br> <br>Test Suites: 5 passed, 5 total<br>Tests:       18 passed, 18 total</pre><p>100% statements. 100% lines. 100% functions. Every real branch covered — the missing branch percentage is entirely TypeScript’s emitDecoratorMetadata output, compiler-generated ternaries in the __metadata calls that no test can reach.</p><p>Merge it. The coverage gate is green.</p><p>Note especially that rejects an order when the payment is declined <strong>executes the buggy path</strong>. It reserves stock, gets declined, throws. The line that should release the inventory doesn&#39;t exist, so there&#39;s no line for Istanbul to report as uncovered. A missing line is invisible to line coverage — and this test certifies the leak as correct behaviour.</p><h4>What DeepCover says</h4><pre>DeepCover Report (with Jest runtime data)<br>════════════════<br>Composite Score: 52/100<br> <br>  Assertion Quality      ████░░░░░░  43<br>  State Coverage         ██░░░░░░░░  22<br>  Mutation Resilience    ███████░░░  70<br>  Criticality Weight     ██████████  100<br> <br>Per-method breakdown:<br>  ⚠️ PaymentGateway.charge  (100% lines, transitive coverage only) 42<br>  ✅ OrdersService.createOrder  (100% lines)  74<br>  ✅ OrdersService.applyDiscount  (100% lines) 74<br>  ✅ OrdersController.create  (100% lines, 75% branches) 34<br>  ✅ NotificationService.sendOrderConfirmation  (100% lines) 32<br>  ✅ NotificationService.sentCount  (100% lines) 32<br>  ✅ InventoryService.seed  (100% lines, transitive coverage only) 30<br>  ✅ InventoryService.available  (100% lines) 44<br>  ⚠️ InventoryService.reserve  (100% lines, critical, weak tests) 42<br>  ✅ InventoryService.release  (100% lines)   52<br> <br>Top gaps:<br>  #1 HIGH  OrdersService.createOrder — &quot;one item in a multi-item order is out of<br>           stock — already-reserved items must be released (compensating rollback)&quot;<br>  #2 HIGH  OrdersService.createOrder — &quot;payment is declined after inventory was<br>           reserved — the reservation is never released, permanently leaking stock&quot;<br>  #3 HIGH  OrdersService.createOrder — &quot;successful order charges the gateway with<br>           the discounted total, not the subtotal&quot;<br>  #4 HIGH  OrdersService.createOrder — &quot;fractional totals are rounded to cents<br>           before charging (Math.round of total * 100)&quot;<br>  #5 HIGH  OrdersService.applyDiscount — &quot;SAVE10 yields exactly 10% of subtotal&quot;</pre><p>52 out of 100, from the same test run that Istanbul scored at 100%. Note PaymentGateway.charge at 42, flagged &quot;transitive coverage only&quot; — a payment method reached exclusively through another class&#39;s tests, with nothing asserting what it was called with.</p><p>With --bugs enabled, it goes further:</p><pre>🔍 Potential Bugs (9 found)<br> <br>  #3  HIGH  OrdersService.createOrder<br>      unchecked-side-effect | llm<br>      When PaymentGateway.charge returns &#39;declined&#39;, createOrder throws without<br>      releasing the inventory it already reserved. The out-of-stock branch performs<br>      a compensating release; the declined-payment branch does not. Every declined<br>      payment permanently removes stock that was never sold. The existing test<br>      &#39;rejects an order when the payment is declined&#39; executes this exact path and<br>      asserts only rejects.toThrow(), so the leak is covered by a passing test.<br>      → Seed SKU-1 with 10, attempt createOrder with qty 3 at unitPrice 0 so the<br>        gateway declines, await expect(...).rejects.toThrow(BadRequestException),<br>        then expect(inventory.available(&#39;SKU-1&#39;)).toBe(10). This currently fails with 7.</pre><p>That last sentence is the part I care about. It doesn’t just name the bug — it hands you the test that proves it, with the number the test will actually produce. I ran it verbatim:</p><pre>expect(received).toBe(expected)<br> <br>Expected: 10<br>Received: 7</pre><p>Three units, gone.</p><h4>The rest of what it found</h4><p>The leak wasn’t the only finding, and the others illustrate different detection mechanisms.</p><p><strong>Assertions that can’t fail.</strong> applies the SAVE10 coupon asserts expect(order.total).toBeGreaterThan(0). If SAVE10 applied a 90% discount, or 0%, or 1%, that assertion still passes. The test&#39;s name describes behaviour it never verifies. DeepCover rated it <em>weak</em>: &quot;toBeGreaterThan(0) on total is satisfied by any non-zero number.&quot;</p><p><strong>A rollback that’s executed but never checked.</strong> rejects an order with an out-of-stock item runs the compensating release loop, giving it 100% line coverage. No assertion reads inventory afterwards. Delete the rollback loop entirely and the suite stays green.</p><p><strong>A controller that mocks away its own subject.</strong> The controller spec replaces OrdersService with jest.fn().mockResolvedValue({ id: &#39;ord_1&#39; }) and asserts toBeDefined(). It never checks that customerId, items and couponCode are forwarded. Swap two arguments in the controller and nothing fails. This one comes from the dependency graph: DeepCover traces OrdersController → OrdersService → InventoryService, sees the chain is mocked at the top, and reports the transitive path as uncovered.</p><p><strong>Boundary conditions, found deterministically.</strong> No LLM involved here — the AST analyzer reads the condition subtotal &gt;= 100, reads the literals the tests pass in (200 and 30), and notices nothing touches 100 or 99. Flip &gt;= to &gt; and every test still passes, while customers are charged differently.</p><h4>Fixing it — and a counterintuitive detour</h4><p>I fixed the bug (three lines: run the same rollback loop on the declined path) and rewrote the suite following DeepCover’s suggested tests. Exact values instead of existence checks, toHaveBeenCalledWith on the gateway, inventory levels asserted after every failure path.</p><p>Then I re-ran coverage and payment.gateway.ts <strong>dropped from 100% to 87.5%</strong>.</p><p>This is worth sitting with. The old suite reached the gateway’s decline branch by accident — a test passed unitPrice: 0, which made the total 0, which happened to trip the gateway&#39;s amountCents &lt;= 0 guard. Incidental coverage, produced by a test that was trying to do something else entirely.</p><p>The new suite forces the decline explicitly with a one-shot mock, which is <em>more</em> precise about what it’s testing — and stops executing that line of the real gateway. Better test, worse coverage number.</p><p>The right fix isn’t to revert. It’s to test the gateway directly, which is where that logic belonged all along:</p><pre>it(&#39;declines a negative charge rather than issuing a refund&#39;, async () =&gt; {<br>  await expect(gateway.charge(&#39;cust-1&#39;, -5000)).resolves.toEqual({<br>    transactionId: &#39;&#39;,<br>    status: &#39;declined&#39;,<br>  });<br>});</pre><p>That case — a negative amount reaching a payment provider — didn’t exist in the old suite at any coverage level. If you’re wondering what a real refund-shaped bug looks like, it looks like that.</p><p>Coverage back to 100%. And notice what the metric did along the way: it went <em>down</em> when the tests got better and back <em>up</em> when I added a test for a genuinely dangerous case. It moved twice for reasons that had nothing to do with test quality. That’s the whole problem in one metric.</p><h4>Same coverage, different score</h4><p>Final suite: 33 tests instead of 18. Istanbul’s verdict, side by side:</p><p><strong>:</strong> Statements<br><strong>Weak suite:</strong> 100%<br><strong>Strong suite:</strong> 100%</p><p><strong>:</strong> Lines<br><strong>Weak suite:</strong> 100%<br><strong>Strong suite:</strong> 100%</p><p><strong>:</strong> Functions<br><strong>Weak suite:</strong> 100%<br><strong>Strong suite:</strong> 100%</p><p><strong>:</strong> Branches<br><strong>Weak suite:</strong> 88.63%<br><strong>Strong suite:</strong> 88.63%</p><p><strong>Identical. To the decimal.</strong> One suite ships a permanent inventory leak; the other catches it. Istanbul cannot distinguish them, because it was never designed to.</p><p>DeepCover:</p><pre>Composite Score: 93/100          (was 52/100)<br> <br>  Assertion Quality      ██████████  100     (was 43)<br>  State Coverage         ████████░░  75      (was 22)<br>  Mutation Resilience    ██████████  100     (was 70)<br>  Criticality Weight     ██████████  100     (was 100)<br> <br>Per-method breakdown:<br>  ✅ PaymentGateway.charge  (100% lines)      100     (was 42)<br>  ✅ OrdersService.createOrder  (100% lines)  90      (was 74)<br>  ✅ OrdersService.applyDiscount  (100% lines) 94     (was 74)<br>  ✅ OrdersController.create  (100% lines, 75% branches) 88  (was 34)<br>  ✅ InventoryService.reserve  (100% lines)   100     (was 42)<br>  ✅ InventoryService.release  (100% lines)   85      (was 52)</pre><p>The per-method column is where the change is easiest to read. PaymentGateway.charge went from 42 to 100 — same 100% line coverage in both runs, but in the first it was reached only as a side effect of testing something else, and in the second it has four direct tests pinning exact results at the guard boundary.</p><p>The deterministic bug detector also went quiet: three signals before, two after, and the surviving ones were downgraded to false positives by the reasoning phase, which could see the boundary tests I’d added.</p><p>52 → 93, from a metric that moved because the tests got better. That’s the number I wanted.</p><p>And it still isn’t 100, because the remaining gaps are real:</p><pre>#1 HIGH  OrdersService.createOrder — &quot;concurrent createOrder calls for the same<br>         sku can both pass the reserve guard — no locking around read-then-write<br>         in InventoryService&quot;</pre><p>InventoryService.reserve reads the current quantity and writes back the decremented value as two separate operations. Two concurrent orders for the last item can both pass the guard before either writes. Every test in the suite is sequential, so no test can observe it. That&#39;s a genuine race condition in code with 100% coverage and, now, strong assertions — and it&#39;s the kind of thing that only falls out of <em>reasoning about</em> the code rather than measuring it.</p><h4>How it works</h4><p>Four phases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xEMh-SPOVDK_VjwFK2lYQ.png" /></figure><p><strong>Extractor</strong> — ts-morph walks the AST and builds a structured model: classes, methods, branch conditions with their exact source expressions, external calls, dependency edges, and a full test inventory including every assertion’s matcher and target, plus what each test mocks. All deterministic, no LLM.</p><p><strong>Coverage Resolver</strong> — merges that static model with Jest’s runtime output. A custom Jest reporter captures per-test pass/fail and duration; Istanbul supplies line and branch data, mapped onto method line ranges. This is what makes the numbers ground truth rather than heuristics: DeepCover knows which tests actually ran and which lines they actually hit.</p><p><strong>Reasoner</strong> — the semantic pass, with four jobs: discover domain states, judge assertion quality, rate business criticality, and infer transitive coverage. The prompts are enriched with everything the extractor found, so the model reasons over structured facts rather than raw source. The inventory leak came out of the domain-state job; the toBeGreaterThan(0) verdict came out of assertion quality.</p><p><strong>Scorer</strong> — four weighted sub-scores:</p><p><strong>Sub-score:</strong> Assertion Quality<br><strong>Weight:</strong> 30%<br><strong>What it measures:</strong> Are assertions meaningful, relative to method complexity?</p><p><strong>Sub-score:</strong> State Coverage<br><strong>Weight:</strong> 30%<br><strong>What it measures:</strong> Are all meaningful domain states tested?</p><p><strong>Sub-score:</strong> Mutation Resilience<br><strong>Weight:</strong> 25%<br><strong>What it measures:</strong> Would tests catch a subtle code change?</p><p><strong>Sub-score:</strong> Criticality Weighting<br><strong>Weight:</strong> 15%<br><strong>What it measures:</strong> Is the <em>important</em> code the tested code?</p><h4>The part I’d argue about first</h4><p>Letting a language model score your test suite should make you suspicious. It makes me suspicious, and I wrote it.</p><p>So the LLM doesn’t get to set the score. Each sub-score is computed deterministically first, and the reasoner may adjust it by <strong>at most ±20%</strong>, scaled by its own stated confidence.</p><p>The weak run is the clearest illustration. The reasoner judged fourteen of that suite’s seventeen tests <em>weak</em>, one <em>strong</em>, and would, left alone, have driven assertion quality near the floor. What actually happened: a deterministic base of 50.0, an LLM adjustment of −6.5, a final of 43.5. The model shaped the result; the AST determined it. Every number in this article is bounded that way.</p><p>Sub-scores that don’t apply are dropped and their weight redistributed rather than counted as zero — which is why the calculator scored 100 in --no-llm mode instead of being punished for a State Coverage the analyzer had no way to compute.</p><p>That cuts both ways, and it’s the honest caveat: <strong>--no-llm is not a cheaper version of the full run.</strong> It scored the weak orders suite at 67 and the calculator at a flattering 100. Deterministic mode is fine as a CI gate against regression — it&#39;s reproducible and free — but it cannot find the inventory leak. The leak was a <em>missing</em> line, and no static analyzer finds a line that was never written.</p><h4>Running it</h4><p>DeepCover targets TypeScript with Jest. Node 18+.</p><pre>npm install -g @anatolykhelmer/deepcover</pre><p>Deterministic analysis works immediately, no API key:</p><pre>deepcover analyze --root . --module src/orders --no-llm</pre><p>For the full pipeline, the reasoning phase can run two ways.</p><p><strong>Through your coding agent</strong> — Claude Code or Cursor. Install the skill once:</p><pre>deepcover init --agent claude</pre><p>Then, in a session on your project, ask it to run deepcover on a module. The agent runs extract, performs the four reasoning jobs itself, writes the results, and runs the scorer. No API key and no extra bill — it uses the subscription you already have, and the agent already has your codebase in context.</p><p><strong>Through the Anthropic API</strong> — for CI or headless runs. Install @anthropic-ai/sdk, set ANTHROPIC_API_KEY, set provider: &#39;anthropic&#39; in deepcover.config.ts, and drop --no-llm.</p><p>To get the Jest runtime data — which measurably sharpens the results — add the reporter and enable coverage:</p><pre>{<br>  &quot;reporters&quot;: [&quot;default&quot;, &quot;@anatolykhelmer/deepcover/reporter&quot;],<br>  &quot;collectCoverage&quot;: true<br>}</pre><p>And for CI gating:</p><pre>deepcover score --root . --module src/orders --min-score 60</pre><p>Exit code 1 below the threshold. With --bugs --bug-threshold 1, it also fails the build on high-risk findings.</p><h4>What it doesn’t do</h4><p>I’d rather you hear this from me than discover it yourself.</p><p><strong>TypeScript and Jest only.</strong> No Python, Go, Vitest or Mocha. The extractor is built on ts-morph and the runtime integration on Jest’s reporter API. Other ecosystems are a rewrite of both, not a flag.</p><p><strong>The reasoning phase is non-deterministic.</strong> Two runs on the same code produce similar but not identical findings. The ±20% cap bounds how far the score can drift, but if you need byte-identical output, use --no-llm and accept the smaller feature set.</p><p><strong>Target-method attribution is heuristic.</strong> DeepCover maps each test to the method it exercises by reading the test body and title. It gets this right most of the time, but a test whose first call is a setup helper can be filed under that helper instead of the method it’s really about. It shifts individual per-method numbers, not the composite.</p><p><strong>It needs a coverage run to be at its best.</strong> Without --coverage and the Jest reporter, DeepCover falls back to static heuristics for which tests touch which methods. It still works; it&#39;s just less precise. Run your tests with coverage first.</p><p><strong>It costs a conversation.</strong> The agent path means a few minutes of reasoning per module, not a sub-second CLI run. This is a tool you point at your payment module before a release, not something you run on every save.</p><p><strong>It won’t tell you your suite is fine when it isn’t.</strong> Which is, admittedly, the entire point — but it does mean adopting it starts with a number that’s lower than the one you’re used to, on a codebase you thought was well tested. The calculator scored 87 and the tests were genuinely decent.</p><h4>The point</h4><p>Line coverage answers a question nobody actually has. <em>Did this line execute?</em> is only interesting as a proxy for <em>is this line protected?</em> — and it’s a bad proxy, because the gap between the two is precisely where the expensive bugs live.</p><p>Two suites. Identical coverage to the decimal place. One of them ships a permanent inventory leak.</p><p>Coverage told me nothing. It told me 100% twice.</p><p>DeepCover is MIT licensed and on npm as @anatolykhelmer/deepcover. The source is on <a href="https://github.com/anatolykhelmer/deepcover">GitHub</a> — issues and PRs welcome, particularly around the limitations above.</p><p>Every number in this article is reproducible. The orders module — both test suites, the three-line fix in between, and the checked-in reasoner output that makes the 52 and the 93 exact rather than illustrative — is at <a href="https://github.com/anatolykhelmer/deepcover-demo-orders">github.com/anatolykhelmer/deepcover-demo-orders</a>, on the weak-tests and strong-tests tags.</p><p>Go run it on your payment code. I’d genuinely like to know what it finds.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d9c9ea21b32" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>