Skip to content

test(infra): add unit tests for semantic version comparison helpers - #96750

Closed
dwc1997 wants to merge 1 commit into
openclaw:mainfrom
dwc1997:fix/semver-compare-tests
Closed

dwc1997 wants to merge 1 commit into
openclaw:mainfrom
dwc1997:fix/semver-compare-tests

Conversation

@dwc1997

@dwc1997 dwc1997 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

The semver-compare.ts module provides semantic version comparison helpers for package and runtime compatibility checks. However, this module lacked unit tests to verify the version comparison logic, which could lead to regressions when the function is modified.

Why This Change Was Made

Add unit tests for normalizeLegacyDotBetaVersion, parseComparableSemver, comparePrereleaseIdentifiers, and compareComparableSemver functions to verify version comparison behavior. This improves test coverage and prevents regressions.

Focused tests cover legacy dot-beta normalization, semver parsing, prerelease identifier comparison, and full semver comparison.

User Impact

Semantic version comparison now has comprehensive test coverage, reducing the risk of regressions when the function is modified.

Evidence

Reproducibility: not applicable. This PR adds direct coverage for existing helper behavior rather than reporting a user-visible runtime bug. Source inspection confirms the helper behavior the tests target.

Direct behavior probe:

$ node --import tsx -e "import('./src/infra/semver-compare.js').then(({ normalizeLegacyDotBetaVersion, parseComparableSemver, comparePrereleaseIdentifiers, compareComparableSemver }) => console.log(JSON.stringify([{ desc: 'normalizeLegacyDotBetaVersion converts legacy format', input: '1.2.3.beta.4', result: normalizeLegacyDotBetaVersion('1.2.3.beta.4'), expected: '1.2.3-beta.4' }, { desc: 'parseComparableSemver parses standard semver', input: '1.2.3', result: parseComparableSemver('1.2.3'), expected: { major: 1, minor: 2, patch: 3, prerelease: null } }, { desc: 'comparePrereleaseIdentifiers returns 0 for both null', input: [null, null], result: comparePrereleaseIdentifiers(null, null), expected: 0 }, { desc: 'compareComparableSemver compares major versions', input: [{ major: 1, minor: 0, patch: 0, prerelease: null }, { major: 2, minor: 0, patch: 0, prerelease: null }], result: compareComparableSemver({ major: 1, minor: 0, patch: 0, prerelease: null }, { major: 2, minor: 0, patch: 0, prerelease: null }), expected: -1 }], null, 2)))"
[
  {
    "desc": "normalizeLegacyDotBetaVersion converts legacy format",
    "input": "1.2.3.beta.4",
    "result": "1.2.3-beta.4",
    "expected": "1.2.3-beta.4"
  },
  {
    "desc": "parseComparableSemver parses standard semver",
    "input": "1.2.3",
    "result": {
      "major": 1,
      "minor": 2,
      "patch": 3,
      "prerelease": null
    },
    "expected": {
      "major": 1,
      "minor": 2,
      "patch": 3,
      "prerelease": null
    }
  },
  {
    "desc": "comparePrereleaseIdentifiers returns 0 for both null",
    "input": [
      null,
      null
    ],
    "result": 0,
    "expected": 0
  },
  {
    "desc": "compareComparableSemver compares major versions",
    "input": [
      {
        "major": 1,
        "minor": 0,
        "patch": 0,
        "prerelease": null
      },
      {
        "major": 2,
        "minor": 0,
        "patch": 0,
        "prerelease": null
      }
    ],
    "result": -1,
    "expected": -1
  }
]

Targeted test:

$ node scripts/run-vitest.mjs run src/infra/semver-compare.test.ts

 RUN  v4.1.8 /home/0668001110/ZTEProject/openclaw-worktrees/pr-94335

 Test Files  1 passed (1)
      Tests  25 passed (25)
   Start at  18:59:16
   Duration  322ms (transform 56ms, setup 0ms, import 77ms, tests 10ms)

[test] passed 1 Vitest shard in 9.59s

Formatting:

$ npx oxfmt --check src/infra/semver-compare.ts src/infra/semver-compare.test.ts
Checking formatting...

All matched files use the correct format.
Finished in 53ms on 2 files using 8 threads.

Whitespace:

$ git diff --check

AI-assisted

Prepared with Codex. I reviewed the change, understand the touched code path, and kept the PR focused on the bug described above.

Add unit tests for normalizeLegacyDotBetaVersion, parseComparableSemver,
comparePrereleaseIdentifiers, and compareComparableSemver functions in
src/infra/semver-compare.ts to verify version comparison behavior.

Tests cover:
- normalizeLegacyDotBetaVersion converts legacy dot-beta format
- parseComparableSemver parses standard semver with/without prerelease
- comparePrereleaseIdentifiers handles null, empty, numeric, and string identifiers
- compareComparableSemver compares major, minor, patch, and prerelease versions
@clawsweeper

clawsweeper Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

This PR is technically coherent, but it repeats an earlier same-scope semver-helper test-only PR that was closed with explicit reviewer guidance to resubmit only with a concrete semver bug or maintainer request.

Root-cause cluster
Relationship: superseded
Canonical: #58313
Summary: An earlier PR proposed direct tests for the same semver helper exports and was closed with explicit guidance that this test-only coverage needs a concrete bug or maintainer request.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Keep the prior reviewer decision as the current repository stance: direct semver-helper coverage should come with a concrete regression, linked maintainer request, or maintainer-sponsored follow-up.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Keep the prior reviewer decision as the current repository stance: direct semver-helper coverage should come with a concrete regression, linked maintainer request, or maintainer-sponsored follow-up.

Do we have a high-confidence way to reproduce the issue?

Not applicable; this is a test coverage PR, not a bug report. The PR body includes a direct helper probe and targeted test output, but no linked semver regression to reproduce.

Is this the best way to solve the issue?

No for the current repository state. Direct colocated tests are a plausible implementation, but the same test-only proposal was already closed without a concrete regression or maintainer request.

Security review:

Security review cleared: The diff adds only a colocated Vitest test file and does not change dependencies, scripts, workflows, secrets handling, or runtime code.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Root AGENTS.md was read fully from the checkout; no scoped AGENTS.md exists for src/infra, and the review applied the repository's read-only PR review and test-only cleanup guidance. (AGENTS.md:1, 4ecb45bf7729)
  • PR diff surface: The branch adds only src/infra/semver-compare.test.ts with assertions for normalizeLegacyDotBetaVersion, parseComparableSemver, comparePrereleaseIdentifiers, and compareComparableSemver. (src/infra/semver-compare.test.ts:1, a183f5907b2c)
  • Current helper contract: Current main exposes the four helper functions targeted by the tests: legacy dot-beta normalization, exact semver parsing, prerelease identifier comparison, and parsed semver comparison. (src/infra/semver-compare.ts:12, 4ecb45bf7729)
  • Current caller surface: The helper is used by runtime/update paths including config version handling, update-channel prerelease detection, plugin install/update ordering, update checks, and ClawHub compatibility checks. (src/infra/update-channels.ts:60, 4ecb45bf7729)
  • Existing indirect coverage: Current main already has indirect semver-like behavior coverage in caller tests such as update-check comparison and config version handling, but no existing direct src/infra/semver-compare.test.ts file. (src/infra/update-check.test.ts:21, 4ecb45bf7729)
  • Prior same-scope PR decision: test(infra): add unit tests for semver-compare version utilities #58313 added direct tests for the same four semver helpers and was closed unmerged with reviewer guidance that test-only coverage should be resubmitted only with a concrete semver bug.

Likely related people:

  • vincentkoc: Closed the earlier same-scope test-only PR with explicit resubmission guidance and has recent update-check history in the caller surface. (role: prior reviewer and adjacent contributor; confidence: medium; commits: 86a28636fa80, 62fad3da8606, b8f6e16ba5ec; files: src/infra/update-check.ts)
  • steipete: GitHub path history shows repeated commits around semver-compare.ts and config version handling before the current checkout import commit. (role: feature-history contributor; confidence: medium; commits: a9a386dee19f, 638437b7588d, bcd61f0a382d; files: src/infra/semver-compare.ts, src/config/version.ts)
  • jalehman: Local blame points the current checked-out helper file to the graft/import commit, so this is useful checkout provenance but not strong product ownership. (role: current checkout provenance; confidence: low; commits: 0cdb050bac19; files: src/infra/semver-compare.ts)

Codex review notes: model internal, reasoning high; reviewed against 4ecb45bf7729.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jun 25, 2026
@vincentkoc vincentkoc self-assigned this Jun 26, 2026
@vincentkoc

Copy link
Copy Markdown
Member

closing this test-only PR as a duplicate/low-signal addition. closed PR #58313 already covered this semver helper family more comprehensively and explicitly asked for a concrete regression, linked bug, or maintainer request before resubmitting. this PR has none, and existing update-check/update-channel/ClawHub caller tests already exercise the meaningful behavior. the 25 added tests pass, but they are weaker than #58313 and do not justify another standalone test-only PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants