---
title: "Fix a failing test: 7 AI models, one prompt | Straitly"
description: "Seven AI models got the same failing pytest run and fixed it once each. Hidden tests, first token, total time, tokens and cost per run."
url: https://straitly.ai/shootouts/fix-failing-test
updated: 2026-11-26
publisher: Straitly (https://straitly.ai)
---

# Fix a failing test: 7 AI models, one prompt

All 7 models passed all 14 checks, so speed and price decide. GPT-6.2 Astra wins: done in 4.8 s. DeepSeek V4.1 Flash 1017 cost the least at the maker's list price, $0.0073\. Kimi K3.1 Pro took the longest, 110 s.

Updated 26 November 2026

[See the results](#results) [Read every output ](#outputs)

The task

Asked

A small Python SemVer module fails CI on prerelease ordering. Fix it so the tests pass and the module follows SemVer 2.0.0 precedence in full.

Graded by

6 visible pytest tests plus 8 hidden tests for the rest of the SemVer 2.0.0 precedence rules

## Which model did best?

Every answer was run, not read. Here is who passed, how long each took and what each run cost.

- Pick this one
### GPT-6.2 Astra
14 of 14 checks, done in 4.8 s: the fastest full pass. $0.0376 at list price.
- Smallest bill
### DeepSeek V4.1 Flash 1017
14 of 14 checks for $0.0073 at list price, in 20.1 s.
- Biggest bill
### Claude Fable 5.2
14 of 14 checks too, at $0.106 at list price for the same result.
- Longest wait
### Kimi K3.1 Pro
Passed, after 110 s and 3,840 output tokens. Fine in a batch job, slow in an editor.
- Most tokens
### DeepSeek V4.1 Flash 1017
5,747 output tokens, 4,924 of them reasoning, for the same pass.

### Results

| Model                             | Tests      | First token | Total time | Output tokens | Reasoning | List cost | Straitly price                                                 |
| --------------------------------- | ---------- | ----------- | ---------- | ------------- | --------- | --------- | -------------------------------------------------------------- |
| Claude Opus 5.5 Anthropic         | Pass 14/14 | 4.5 s       | 19.9 s     | 2,196         | 649       | $0.0504   | [$0.0303](https://straitly.ai/models/claude-opus-5-5)          |
| GPT-6.2 Astra OpenAI              | Pass 14/14 | 2.7 s       | 4.8 s      | 711           | 12        | $0.0376   | [$0.0226](https://straitly.ai/models/gpt-6.2-astra)            |
| Gemini 4 Neon Google              | Pass 14/14 | 90.7 s      | 96.7 s     | 871           | 0         | $0.0171   | [See model page](https://straitly.ai/models/gemini-4-neon)     |
| Gemini 4 Carbon Google            | Pass 14/14 | 16.3 s      | 43.8 s     | 2,745         | 1,817     | $0.0301   | [$0.0301](https://straitly.ai/models/gemini-4-carbon)          |
| Claude Fable 5.2 Anthropic        | Pass 14/14 | 12.2 s      | 22.1 s     | 2,305         | 1,010     | $0.106    | [$0.0638](https://straitly.ai/models/claude-fable-5.2)         |
| DeepSeek V4.1 Flash 1017 DeepSeek | Pass 14/14 | 4.0 s       | 20.1 s     | 5,747         | 4,924     | $0.0073   | [$0.0022](https://straitly.ai/models/deepseek-v4-1-flash-1017) |
| Kimi K3.1 Pro Moonshot            | Pass 14/14 | 3.1 s       | 110 s      | 3,840         | 3,097     | $0.0408   | [$0.0233](https://straitly.ai/models/kimi-k3.1-pro)            |

One run per model, 26 November 2026, 5:48 PM to 6:01 PM PT. Reasoning tokens are part of output tokens. List cost is the run's input and output tokens at the maker's list price. The Straitly price column is the same tokens at the Straitly catalog price that day. Gemini 4 Neon: see its model page.

## What did each model write?

The prompt and all seven replies, exactly as they came back. Open one to read it.

**The prompt Sent word for word to every model**

System: You are a senior software engineer. Follow the requested output format exactly.

CI is failing on our small release-tooling repo. Fix the bug so the test suite passes and the module follows the SemVer 2.0.0 precedence rules in full (other callers rely on it, not just these tests). semver.py:

```
"""Tiny semantic version helper used by our release tooling."""
import re

_PATTERN = re.compile(
    r"^v?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"
    r"(?:-(?P<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?"
    r"(?:\+(?P<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$"
)

class Version:
    def __init__(self, major, minor, patch, pre=None, build=None):
        self.major = major
        self.minor = minor
        self.patch = patch
        self.pre = pre
        self.build = build

    @classmethod
    def parse(cls, text):
        m = _PATTERN.match(text.strip())
        if not m:
            raise ValueError(f"not a version: {text!r}")
        return cls(int(m["major"]), int(m["minor"]), int(m["patch"]), m["pre"], m["build"])

    def _key(self):
        return (self.major, self.minor, self.patch, self.pre or "")

    def __eq__(self, other):
        return self._key() == other._key()

    def __lt__(self, other):
        return self._key() < other._key()

    def __le__(self, other):
        return self == other or self < other

    def __gt__(self, other):
        return other < self

    def __ge__(self, other):
        return other <= self

    def __hash__(self):
        return hash(self._key())

    def __str__(self):
        s = f"{self.major}.{self.minor}.{self.patch}"
        if self.pre:
            s += "-" + self.pre
        if self.build:
            s += "+" + self.build
        return s

def latest(versions, include_prerelease=False):
    """Return the highest version string from an iterable of strings, or None."""
    parsed = [Version.parse(v) for v in versions]
    if not include_prerelease:
        parsed = [v for v in parsed if not v.pre]
    return str(max(parsed)) if parsed else None
```

test\_semver.py:

```
import pytest

from semver import Version, latest

def v(s):
    return Version.parse(s)

def test_basic_order():
    assert v("1.2.3") < v("1.2.4") < v("1.3.0") < v("2.0.0")

def test_prerelease_is_lower_than_release():
    assert v("1.0.0-alpha") < v("1.0.0")

def test_spec_prerelease_chain():
    chain = ["1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-alpha.beta", "1.0.0-beta",
             "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", "1.0.0"]
    for lo, hi in zip(chain, chain[1:]):
        assert v(lo) < v(hi), f"{lo} should sort before {hi}"

def test_build_metadata_is_ignored_for_order():
    assert v("1.0.0+build.1") == v("1.0.0+build.9")
    assert not (v("1.0.0+a") < v("1.0.0+b"))

def test_latest_skips_prereleases_by_default():
    assert latest(["1.0.0", "1.1.0-rc.1", "1.0.5"]) == "1.0.5"
    assert latest(["1.0.0", "1.1.0-rc.1"], include_prerelease=True) == "1.1.0-rc.1"

def test_bad_input():
    with pytest.raises(ValueError):
        Version.parse("1.2")
```

\`pytest -q\` output:

```
.FF...                                                                   [100%]
=================================== FAILURES ===================================
test_semver.py:15: AssertionError: assert <semver.Version object> < <semver.Version object>
test_semver.py:22: AssertionError: 1.0.0-beta.2 should sort before 1.0.0-beta.11
=========================== short test summary info ============================
FAILED test_semver.py::test_prerelease_is_lower_than_release - AssertionError...
FAILED test_semver.py::test_spec_prerelease_chain - AssertionError: 1.0.0-bet...
2 failed, 4 passed in 0.02s
```

Reply with the complete corrected semver.py in one \`\`\`python code block, then one or two sentences on the root cause.

**Claude Opus 5.5 Pass, 14 of 14, 19.9 s, 2,196 output tokens**

```
"""Tiny semantic version helper used by our release tooling."""
import re

# Pre-release identifiers: numeric ones must not have leading zeros (SemVer 2.0.0, item 9).
_PRE_IDENT = r"(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)"
_BUILD_IDENT = r"[0-9A-Za-z-]+"

_PATTERN = re.compile(
    r"^v?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"
    rf"(?:-(?P<pre>{_PRE_IDENT}(?:\.{_PRE_IDENT})*))?"
    rf"(?:\+(?P<build>{_BUILD_IDENT}(?:\.{_BUILD_IDENT})*))?$",
    re.ASCII,
)

def _pre_key(pre):
    """Precedence key for the pre-release part (SemVer 2.0.0, item 11).

    - A version without a pre-release ranks higher than any version with one.
    - Identifiers are compared left to right:
        * numeric identifiers compare numerically,
        * alphanumeric identifiers compare lexically in ASCII order,
        * numeric identifiers always rank lower than alphanumeric ones.
    - If all shared identifiers are equal, the longer list ranks higher
      (natural tuple comparison gives this).
    """
    if not pre:
        return (1,)
    idents = []
    for part in pre.split("."):
        if part.isdigit():
            idents.append((0, int(part), ""))
        else:
            idents.append((1, 0, part))
    return (0, tuple(idents))

class Version:
    def __init__(self, major, minor, patch, pre=None, build=None):
        self.major = major
        self.minor = minor
        self.patch = patch
        self.pre = pre
        self.build = build

    @classmethod
    def parse(cls, text):
        m = _PATTERN.match(text.strip())
        if not m:
            raise ValueError(f"not a version: {text!r}")
        return cls(int(m["major"]), int(m["minor"]), int(m["patch"]), m["pre"], m["build"])

    def _key(self):
        # Build metadata is intentionally excluded: it does not affect precedence.
        return (self.major, self.minor, self.patch, _pre_key(self.pre))

    def __eq__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() == other._key()

    def __lt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() < other._key()

    def __le__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() <= other._key()

    def __gt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() > other._key()

    def __ge__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() >= other._key()

    def __hash__(self):
        return hash(self._key())

    def __repr__(self):
        return f"Version({str(self)!r})"

    def __str__(self):
        s = f"{self.major}.{self.minor}.{self.patch}"
        if self.pre:
            s += "-" + self.pre
        if self.build:
            s += "+" + self.build
        return s

def latest(versions, include_prerelease=False):
    """Return the highest version string from an iterable of strings, or None."""
    parsed = [Version.parse(v) for v in versions]
    if not include_prerelease:
        parsed = [v for v in parsed if not v.pre]
    return str(max(parsed)) if parsed else None
```

The root cause was in \`\_key()\`, which compared the pre-release as one raw string, with \`""\` used for releases. That made a release sort \*below\* its pre-releases, and it compared identifiers like \`2\` and \`11\` lexically instead of numerically. The fix splits the pre-release into dot-separated identifiers, compares numeric identifiers as integers ranked below alphanumeric ones, and ranks a release above all of its pre-releases. I also tightened parsing to the spec in two ways that callers may notice. Pre-release numeric identifiers with leading zeros such as \`1.0.0-01\` are now rejected, and only ASCII digits are accepted (\`re.ASCII\`).

**GPT-6.2 Astra Pass, 14 of 14, 4.8 s, 711 output tokens**

```
"""Tiny semantic version helper used by our release tooling."""
import re
from functools import total_ordering

_PATTERN = re.compile(
    r"v?(?P<major>0|[1-9][0-9]*)\.(?P<minor>0|[1-9][0-9]*)\.(?P<patch>0|[1-9][0-9]*)"
    r"(?:-(?P<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?"
    r"(?:\+(?P<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?"
)

def _identifier_key(identifier):
    if identifier.isdigit():
        # With no leading zeroes, length then digits gives numeric order.
        return (0, len(identifier), identifier)
    return (1, identifier)

@total_ordering
class Version:
    def __init__(self, major, minor, patch, pre=None, build=None):
        self.major = major
        self.minor = minor
        self.patch = patch
        self.pre = pre
        self.build = build

    @classmethod
    def parse(cls, text):
        m = _PATTERN.fullmatch(text.strip())
        if not m:
            raise ValueError(f"not a version: {text!r}")

        pre = m["pre"]
        if pre and any(
            part.isdigit() and len(part) > 1 and part.startswith("0")
            for part in pre.split(".")
        ):
            raise ValueError(f"numeric prerelease identifier has a leading zero: {text!r}")

        return cls(int(m["major"]), int(m["minor"]), int(m["patch"]), pre, m["build"])

    def _key(self):
        identifiers = tuple(_identifier_key(part) for part in self.pre.split(".")) if self.pre else ()
        return (self.major, self.minor, self.patch, not self.pre, identifiers)

    def __eq__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() == other._key()

    def __lt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() < other._key()

    def __hash__(self):
        return hash(self._key())

    def __str__(self):
        s = f"{self.major}.{self.minor}.{self.patch}"
        if self.pre:
            s += "-" + self.pre
        if self.build:
            s += "+" + self.build
        return s

def latest(versions, include_prerelease=False):
    """Return the highest version string from an iterable of strings, or None."""
    parsed = [Version.parse(v) for v in versions]
    if not include_prerelease:
        parsed = [v for v in parsed if not v.pre]
    return str(max(parsed)) if parsed else None
```

The old key represented a release with an empty string, so it sorted below prereleases with the same major, minor, and patch. It also compared the entire prerelease as text instead of comparing dot-separated identifiers, so \`beta.11\` incorrectly sorted before \`beta.2\`.

**Gemini 4 Neon Pass, 14 of 14, 96.7 s, 871 output tokens**

```
"""Tiny semantic version helper used by our release tooling."""
import re

_PATTERN = re.compile(
    r"^v?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"
    r"(?:-(?P<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?"
    r"(?:\+(?P<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$"
)

class Version:
    def __init__(self, major, minor, patch, pre=None, build=None):
        self.major = major
        self.minor = minor
        self.patch = patch
        self.pre = pre
        self.build = build

    @classmethod
    def parse(cls, text):
        m = _PATTERN.match(text.strip())
        if not m:
            raise ValueError(f"not a version: {text!r}")
        return cls(int(m["major"]), int(m["minor"]), int(m["patch"]), m["pre"], m["build"])

    def _key(self):
        if not self.pre:
            return (self.major, self.minor, self.patch, 1, ())
        pre_parts = tuple(
            (0, int(part)) if (part.isascii() and part.isdigit()) else (1, part)
            for part in self.pre.split(".")
        )
        return (self.major, self.minor, self.patch, 0, pre_parts)

    def __eq__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() == other._key()

    def __lt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() < other._key()

    def __le__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() <= other._key()

    def __gt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() > other._key()

    def __ge__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() >= other._key()

    def __hash__(self):
        return hash(self._key())

    def __str__(self):
        s = f"{self.major}.{self.minor}.{self.patch}"
        if self.pre:
            s += "-" + self.pre
        if self.build:
            s += "+" + self.build
        return s

def latest(versions, include_prerelease=False):
    """Return the highest version string from an iterable of strings, or None."""
    parsed = [Version.parse(v) for v in versions]
    if not include_prerelease:
        parsed = [v for v in parsed if not v.pre]
    return str(max(parsed)) if parsed else None
```

The root cause was \`Version.\_key()\` representing the pre-release component as \`self.pre or ""\`, which made release versions (\`""\`) sort before pre-releases (\`"alpha"\`) and compared pre-release strings purely lexicographically (so \`"beta.11"\` sorted before \`"beta.2"\`). Encoding a release flag (\`0\` for pre-release, \`1\` for release) and splitting pre-release tags into dot-separated \`(0, int)\` numeric and \`(1, str)\` non-numeric identifiers implements all SemVer 2.0.0 precedence rules.

**Gemini 4 Carbon Pass, 14 of 14, 43.8 s, 2,745 output tokens**

```
"""Tiny semantic version helper used by our release tooling."""
import re

_PATTERN = re.compile(
    r"^v?(?P<major>0|[1-9][0-9]*)\.(?P<minor>0|[1-9][0-9]*)\.(?P<patch>0|[1-9][0-9]*)"
    r"(?:-(?P<pre>(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)"
    r"(?:\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?"
    r"(?:\+(?P<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$"
)

def _pre_key(pre):
    if not pre:
        return (1, ())
    parts = tuple(
        (0, int(part)) if part.isascii() and part.isdigit() else (1, part)
        for part in pre.split(".")
    )
    return (0, parts)

class Version:
    def __init__(self, major, minor, patch, pre=None, build=None):
        self.major = major
        self.minor = minor
        self.patch = patch
        self.pre = pre or None
        self.build = build or None

    @classmethod
    def parse(cls, text):
        m = _PATTERN.match(text.strip())
        if not m:
            raise ValueError(f"not a version: {text!r}")
        return cls(int(m["major"]), int(m["minor"]), int(m["patch"]), m["pre"], m["build"])

    def _key(self):
        return (self.major, self.minor, self.patch, _pre_key(self.pre))

    def __eq__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() == other._key()

    def __lt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() < other._key()

    def __le__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() <= other._key()

    def __gt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() > other._key()

    def __ge__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() >= other._key()

    def __hash__(self):
        return hash(self._key())

    def __str__(self):
        s = f"{self.major}.{self.minor}.{self.patch}"
        if self.pre:
            s += "-" + self.pre
        if self.build:
            s += "+" + self.build
        return s

def latest(versions, include_prerelease=False):
    """Return the highest version string from an iterable of strings, or None."""
    parsed = [Version.parse(v) for v in versions]
    if not include_prerelease:
        parsed = [v for v in parsed if not v.pre]
    return str(max(parsed)) if parsed else None
```

\`Version.\_key()\` previously compared \`self.pre or ""\` as a single plain string, which caused empty pre-release strings (\`""\`) on normal releases to sort \*before\* pre-releases like \`"alpha"\` and caused numeric identifiers like \`"11"\` to sort lexicographically before \`"2"\`. Splitting pre-release tags on \`"."\`, flagging normal releases above pre-releases, and tagging purely numeric identifiers ahead of alphanumeric ones restores full SemVer 2.0.0 precedence (along with rejecting leading zeroes on numeric pre-release identifiers).

**Claude Fable 5.2 Pass, 14 of 14, 22.1 s, 2,305 output tokens**

```
"""Tiny semantic version helper used by our release tooling."""
import re

_PATTERN = re.compile(
    r"^v?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"
    r"(?:-(?P<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?"
    r"(?:\+(?P<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$"
)

def _pre_identifier_key(identifier):
    # SemVer 2.0.0 section 11.4: numeric identifiers compare numerically and
    # always rank below alphanumeric ones, which compare lexically in ASCII order.
    if identifier.isdigit():
        return (0, int(identifier), "")
    return (1, 0, identifier)

class Version:
    def __init__(self, major, minor, patch, pre=None, build=None):
        self.major = major
        self.minor = minor
        self.patch = patch
        self.pre = pre
        self.build = build

    @classmethod
    def parse(cls, text):
        m = _PATTERN.match(text.strip())
        if not m:
            raise ValueError(f"not a version: {text!r}")
        return cls(int(m["major"]), int(m["minor"]), int(m["patch"]), m["pre"], m["build"])

    def _key(self):
        # Build metadata is deliberately excluded: it has no effect on precedence.
        if self.pre:
            # A pre-release sorts below its release. Tuple comparison also makes
            # a longer identifier list win when all preceding identifiers are equal.
            pre_key = (0, tuple(_pre_identifier_key(p) for p in self.pre.split(".")))
        else:
            pre_key = (1, ())
        return (self.major, self.minor, self.patch, pre_key)

    def __eq__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() == other._key()

    def __lt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() < other._key()

    def __le__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() <= other._key()

    def __gt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() > other._key()

    def __ge__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() >= other._key()

    def __hash__(self):
        return hash(self._key())

    def __str__(self):
        s = f"{self.major}.{self.minor}.{self.patch}"
        if self.pre:
            s += "-" + self.pre
        if self.build:
            s += "+" + self.build
        return s

def latest(versions, include_prerelease=False):
    """Return the highest version string from an iterable of strings, or None."""
    parsed = [Version.parse(v) for v in versions]
    if not include_prerelease:
        parsed = [v for v in parsed if not v.pre]
    return str(max(parsed)) if parsed else None
```

The root cause is that \`\_key()\` compared the pre-release as one raw string: a release (\`""\`) sorted below its own pre-releases, and identifiers compared character by character, so \`beta.11\` came before \`beta.2\`. The key now ranks a release above its pre-releases and compares identifiers one by one under the SemVer rules (numeric ones as integers and below alphanumeric ones, a longer list winning on a tie), and comparisons with non-\`Version\` objects now return \`NotImplemented\` instead of raising \`AttributeError\`.

**DeepSeek V4.1 Flash 1017 Pass, 14 of 14, 20.1 s, 5,747 output tokens**

```
"""Tiny semantic version helper used by our release tooling."""
import re

_PATTERN = re.compile(
    r"^v?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"
    r"(?:-(?P<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?"
    r"(?:\+(?P<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$"
)

class Version:
    def __init__(self, major, minor, patch, pre=None, build=None):
        self.major = major
        self.minor = minor
        self.patch = patch
        self.pre = pre
        self.build = build

    @classmethod
    def parse(cls, text):
        m = _PATTERN.match(text.strip())
        if not m:
            raise ValueError(f"not a version: {text!r}")

        pre = m["pre"]
        if pre is not None:
            for identifier in pre.split("."):
                if identifier.isdigit() and len(identifier) > 1 and identifier[0] == "0":
                    raise ValueError(f"invalid numeric prerelease identifier: {identifier!r}")

        return cls(
            int(m["major"]),
            int(m["minor"]),
            int(m["patch"]),
            pre,
            m["build"],
        )

    def _key(self):
        # Release versions sort after prerelease versions.
        if self.pre is None:
            pre_key = (1, ())
        else:
            pre_key = (
                0,
                tuple(
                    (0, int(identifier)) if identifier.isdigit() else (1, identifier)
                    for identifier in self.pre.split(".")
                ),
            )

        return (self.major, self.minor, self.patch) + pre_key

    def __eq__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() == other._key()

    def __lt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() < other._key()

    def __le__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() <= other._key()

    def __gt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() > other._key()

    def __ge__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() >= other._key()

    def __hash__(self):
        return hash(self._key())

    def __str__(self):
        s = f"{self.major}.{self.minor}.{self.patch}"
        if self.pre:
            s += "-" + self.pre
        if self.build:
            s += "+" + self.build
        return s

def latest(versions, include_prerelease=False):
    """Return the highest version string from an iterable of strings, or None."""
    parsed = [Version.parse(v) for v in versions]
    if not include_prerelease:
        parsed = [v for v in parsed if v.pre is None]
    return str(max(parsed)) if parsed else None
```

The bug was that \`\_key()\` used \`pre or ""\`, causing a release version to sort before prereleases, and it compared prerelease identifiers as plain strings so \`beta.2\` sorted after \`beta.11\`. The corrected key treats release versions as higher than prereleases, compares numeric prerelease identifiers numerically, and keeps build metadata out of precedence.

**Kimi K3.1 Pro Pass, 14 of 14, 110 s, 3,840 output tokens**

```
"""Tiny semantic version helper used by our release tooling."""
import re

_PATTERN = re.compile(
    r"^v?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"
    r"(?:-(?P<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?"
    r"(?:\+(?P<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$"
)

class Version:
    def __init__(self, major, minor, patch, pre=None, build=None):
        self.major = major
        self.minor = minor
        self.patch = patch
        self.pre = pre
        self.build = build

    @classmethod
    def parse(cls, text):
        m = _PATTERN.match(text.strip())
        if not m:
            raise ValueError(f"not a version: {text!r}")
        return cls(int(m["major"]), int(m["minor"]), int(m["patch"]), m["pre"], m["build"])

    def _key(self):
        if self.pre:
            identifiers = tuple(
                (0, int(identifier)) if identifier.isdigit()
                else (1, identifier)
                for identifier in self.pre.split(".")
            )
            # Prereleases have lower precedence than the associated release.
            pre_key = (0, identifiers)
        else:
            pre_key = (1, ())

        # Build metadata is deliberately excluded from precedence and equality.
        return (self.major, self.minor, self.patch, pre_key)

    def __eq__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() == other._key()

    def __lt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() < other._key()

    def __le__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() <= other._key()

    def __gt__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() > other._key()

    def __ge__(self, other):
        if not isinstance(other, Version):
            return NotImplemented
        return self._key() >= other._key()

    def __hash__(self):
        return hash(self._key())

    def __str__(self):
        s = f"{self.major}.{self.minor}.{self.patch}"
        if self.pre:
            s += "-" + self.pre
        if self.build:
            s += "+" + self.build
        return s

def latest(versions, include_prerelease=False):
    """Return the highest version string from an iterable of strings, or None."""
    parsed = [Version.parse(v) for v in versions]
    if not include_prerelease:
        parsed = [v for v in parsed if not v.pre]
    return str(max(parsed)) if parsed else None
```

The old key treated prereleases as single strings, making releases sort before their prereleases and numeric identifiers sort lexicographically. The new key implements identifier-by-identifier SemVer precedence, including numeric comparison, numeric-before-alphanumeric ordering, prefix handling, and release-over-prerelease ordering, while still ignoring build metadata.

## How was this run?

One run per model on the same day, through one API, graded by the same tests.

- **Run** 26 November 2026, 5:48 PM to 6:01 PM PT. Each model got each task once, with the same system prompt and the same user prompt, word for word.
- **How it was called** Through the Straitly API (OpenAI chat completions format, streaming) with our own test key. Each model's default temperature, max\_tokens 32,000, no tools.
- **Grading** The code block in the reply was saved and run against 6 visible pytest tests plus 8 hidden tests for the rest of the SemVer 2.0.0 precedence rules. Pass means every check passed.
- **Time** First token is the time from sending the request to the first streamed token, reasoning tokens included. Total time runs to the last token. Both were timed on the calling machine, so network time is included.
- **Tokens** From the usage block each reply ended with. Reasoning tokens are part of output tokens and are billed as output. The reasoning figure is what that block reported: Gemini 4 Neon reported none on all three tasks, though its first token took over a minute each time.
- **List cost** Input and output tokens times the maker's list price per 1M tokens, read on the run day. DeepSeek ran in its peak hours. Gemini 4 Carbon's rate is the one in force until 30 November 2026.
- **Straitly price** The same tokens at the Straitly catalog price on the run day. Gemini 4 Neon shows a link to its model page instead.
- **Reruns** One. Claude Fable 5.2's first request on the failing-test task timed out while connecting, before any token came back. It was sent again, and the second run is the one shown. Nothing was rerun for a better answer.

### Rates used

| Model                             | List           | Straitly price                                                       |
| --------------------------------- | -------------- | -------------------------------------------------------------------- |
| Claude Opus 5.5 Anthropic         | $4.00 / $20.00 | [$2.40 / $12.00](https://straitly.ai/models/claude-opus-5-5)         |
| GPT-6.2 Astra OpenAI              | $8.00 / $40.00 | [$4.80 / $24.00](https://straitly.ai/models/gpt-6.2-astra)           |
| Gemini 4 Neon Google              | $3.00 / $15.00 | [See model page](https://straitly.ai/models/gemini-4-neon)           |
| Gemini 4 Carbon Google            | $2.00 / $10.00 | [$2.00 / $10.00](https://straitly.ai/models/gemini-4-carbon)         |
| Claude Fable 5.2 Anthropic        | $8.00 / $40.00 | [$4.80 / $24.00](https://straitly.ai/models/claude-fable-5.2)        |
| DeepSeek V4.1 Flash 1017 DeepSeek | $0.30 / $1.20  | [$0.09 / $0.36](https://straitly.ai/models/deepseek-v4-1-flash-1017) |
| Kimi K3.1 Pro Moonshot            | $2.00 / $10.00 | [$1.14 / $5.70](https://straitly.ai/models/kimi-k3.1-pro)            |

List prices from each maker's pricing page, read on the run day. DeepSeek ran in its peak hours, so its peak rate applies.

## What else do people ask?

[Ask a question](https://straitly.ai/contact)

- ### Which AI model is best at this task?
On this run all 7 models passed all 14 checks, so pick on speed and cost: GPT-6.2 Astra was fastest at 4.8 s and DeepSeek V4.1 Flash 1017 cost the least at list price, $0.0073.
- ### How was each answer graded?
By running it: 6 visible pytest tests plus 8 hidden tests for the rest of the SemVer 2.0.0 precedence rules. A model passes only with every check green. Nobody scored the answers by reading them.
- ### Is one run enough to rank models?
No. Each model ran once, on 26 November 2026, so a gap of a few seconds can flip on another run. Gaps of a minute or more showed up on all three tasks.
- ### What does time to first token mean here?
Seconds from sending the request to the first streamed token, reasoning tokens included. Total time runs to the last token.

## Sources

List prices quoted from each maker's own pricing page on the run day. Spot something out of date? Tell us at [straitly.ai/contact](https://straitly.ai/contact).

1. \[1\] [Anthropic pricing](https://platform.claude.com/docs/en/about-claude/pricing) platform.claude.com, checked 26 November 2026
2. \[2\] [OpenAI pricing](https://developers.openai.com/api/docs/pricing) developers.openai.com, checked 26 November 2026
3. \[3\] [Gemini API pricing](https://ai.google.dev/gemini-api/docs/pricing) ai.google.dev, checked 26 November 2026
4. \[4\] [DeepSeek pricing](https://api-docs.deepseek.com/quick%5Fstart/pricing) api-docs.deepseek.com, checked 26 November 2026
5. \[5\] [Kimi API pricing](https://platform.kimi.ai/docs/pricing/chat) platform.kimi.ai, checked 26 November 2026
6. \[6\] [Straitly model catalog](https://straitly.ai/models) straitly.ai/models, checked 26 November 2026
7. \[7\] [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html) semver.org, checked 26 November 2026

**What each source says**

Anthropic pricing

Claude Opus 5.5 $4 / $20 and Claude Fable 5.2 $8 / $40 per 1M input / output tokens, base rate.

OpenAI pricing

gpt-6.2-astra $8 / $40 per 1M input / output tokens, Standard, prompts up to 272K tokens.

Gemini API pricing

Gemini 4 Neon $3 / $15 per 1M input / output tokens, paid tier. Gemini 4 Carbon $2 / $10 through 30 November 2026 and $4 / $20 from 1 December 2026.

DeepSeek pricing

V4.1 Flash $0.30 / $1.20 per 1M input (cache miss) / output tokens in peak hours, 01:00 to 04:00 and 06:00 to 10:00 UTC on weekdays; half that off-peak.

Kimi API pricing

kimi-k3.1-pro $2 / $10 per 1M input (cache miss) / output tokens.

Straitly model catalog

The per-model price list /models prints, read on the run day.

Semantic Versioning 2.0.0

Rule 11: how prerelease versions are ordered.

Read next: [Build a React component](https://straitly.ai/shootouts/react-component) , [Write a SQL migration](https://straitly.ai/shootouts/sql-migration) , [All shootouts](https://straitly.ai/shootouts) , [All comparisons](https://straitly.ai/compare).

## Start with one request.

Run the same prompt on every model with one key. [See pricing](https://straitly.ai/pricing).

[Console](https://straitly.ai/app) [Talk to sales ](https://straitly.ai/contact)

---
Markdown version of https://straitly.ai/shootouts/fix-failing-test.
