Skip to content

mcp-package.ts's version-selection/fallback logic has zero test coverage #8388

Description

@JSONbored

Context

apps/loopover-ui/src/lib/mcp-package.ts provides the pure logic behind the two places the site tells
visitors which @loopover/mcp version to install: components/site/mcp-version-badge.tsx (the header
badge, showing a version dropdown) and components/site/npm-install.tsx (the copyable install
command). It has no React/DOM dependency in its exported helper functions:

  • isStableVersion(version) — regex-gates a version string to \d+\.\d+\.\d+ (excludes prereleases
    like 3.12.0-beta.1 from ever being shown as "latest" or offered in the install command).
  • getLatestMcpVersion(data) — falls back to the hardcoded MCP_PACKAGE_KNOWN_LATEST_VERSION when
    data is undefined, when dist-tags.latest is absent, or when it's present but not a stable
    version.
  • getRecentMcpVersions(data, limit = 6) — filters to stable versions with a known publish time, sorts
    descending by publish date (string comparison of ISO timestamps via localeCompare), and slices to
    limit; falls back to [MCP_PACKAGE_KNOWN_LATEST_VERSION] when data is undefined.
  • getMcpInstallCommand(version?) / getMcpNpxPackage(version?) — pin to the given version only when
    it's both present and stable, otherwise fall back to @latest.

None of these five functions has a test anywhere in the repo (no mcp-package.test.ts exists, and no
existing *.test.ts* file references mcp-package, getLatestMcpVersion, getRecentMcpVersions,
isStableVersion, or getMcpInstallCommand). Both consuming components
(components/site/mcp-version-badge.tsx, components/site/npm-install.tsx) are themselves untested,
so there is currently no automated coverage anywhere in the repo for "does the site ever recommend
installing a prerelease build" or "does the badge correctly fall back when npm is unreachable."

Requirements

  • Add apps/loopover-ui/src/lib/mcp-package.test.ts covering:
    • isStableVersion: accepts "3.11.0"; rejects "3.11.0-beta.1", "3.11", "v3.11.0", "", and
      a non-numeric string.
    • getLatestMcpVersion: returns dist-tags.latest when present and stable; falls back to
      MCP_PACKAGE_KNOWN_LATEST_VERSION when data is undefined, when dist-tags.latest is absent,
      and when dist-tags.latest is present but unstable (a prerelease tag must never surface as
      "latest").
    • getRecentMcpVersions: returns [MCP_PACKAGE_KNOWN_LATEST_VERSION] when data is undefined;
      excludes unstable versions and versions missing a time entry; sorts strictly by descending
      publish time (construct fixture data where insertion order and time order differ, to actually
      exercise the sort, not just confirm array order matches input order); respects a custom limit
      and defaults to 6.
    • getMcpInstallCommand / getMcpNpxPackage: pin to the given version when stable; fall back to
      @latest / @loopover/mcp@latest when version is undefined and when version is an unstable
      string.

Deliverables

  • apps/loopover-ui/src/lib/mcp-package.test.ts with the coverage listed above.

Test Coverage Requirements

apps/** is outside this repo's Codecov coverage.include (vitest.config.ts / codecov.yml's
ignore: ["apps/**", ...]), so this change owes no Codecov patch-coverage percentage. Aim for genuine
branch coverage of every conditional in the five functions listed above (both sides of each ?/??
fallback), since a one-line regex or fallback-order mistake here is exactly the kind of thing branch
coverage catches and line coverage doesn't. Run
npx vitest run apps/loopover-ui/src/lib/mcp-package.test.ts while iterating, and npm run ui:test
before opening the PR.

Expected Outcome

The version-selection logic that decides what install command and "latest" badge every visitor to the
site sees has a real regression suite, so a future change (e.g. adjusting the stable-version regex, or
changing the sort/fallback order) that accidentally started recommending a prerelease build as
"latest" would fail a test instead of shipping silently.

Links & Resources

  • apps/loopover-ui/src/lib/mcp-package.ts (the module to test)
  • apps/loopover-ui/src/components/site/mcp-version-badge.tsx and
    apps/loopover-ui/src/components/site/npm-install.tsx (the real call sites)
  • apps/loopover-ui/src/lib/config-generator-yaml.test.ts for this repo's established plain-vitest,
    no-React pure-function test pattern

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions