Files
zpan/shared/semver.test.ts
T
saltbo e700fd4977 feat(about): add changelog drawer, latest-version check, and commit hash
Maintain a CHANGELOG.md (Keep a Changelog format) at the repo root and surface
it on the admin About page:

- The page now shows the running build's short commit hash next to the version,
  linked to the GitHub commit. Commit is injected at build time via a new
  resolveAppCommit() (ZPAN_APP_COMMIT -> WORKERS_CI_COMMIT_SHA -> git rev-parse),
  wired through vite/tsup defines, the node entry, Docker, and CI.
- A new admin-only GET /api/system/changelog endpoint fetches CHANGELOG.md from
  master on GitHub, caches it, parses the latest released version, and reports
  whether an update is available (semver compare against the running version).
- The About page renders a "latest version" row with an update-available badge
  and a side drawer that displays the changelog markdown.

Tests cover the semver compare, changelog parse/fetch caching, the API wrapper,
and the route (admin-gated, parsed payload).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 13:38:29 -04:00

23 lines
803 B
TypeScript

import { describe, expect, it } from 'vitest'
import { compareSemver } from './semver'
describe('compareSemver', () => {
it('orders by major, minor, then patch', () => {
expect(compareSemver('2.8.0', '2.7.2')).toBe(1)
expect(compareSemver('2.7.2', '2.8.0')).toBe(-1)
expect(compareSemver('3.0.0', '2.9.9')).toBe(1)
expect(compareSemver('2.7.3', '2.7.2')).toBe(1)
expect(compareSemver('2.7.2', '2.7.2')).toBe(0)
})
it('tolerates a leading v and pre-release/build suffixes', () => {
expect(compareSemver('v2.8.0', '2.7.2')).toBe(1)
expect(compareSemver('2.8.0-beta.1', '2.8.0')).toBe(0)
})
it('returns 0 when either version is unparseable', () => {
expect(compareSemver('not-a-version', '2.7.2')).toBe(0)
expect(compareSemver('2.7.2', '')).toBe(0)
})
})