Skip to content

test/unit: local-branch, miner-init-verify-token, and miner-self-review-context leak real machine state into mocked assertions #7512

Description

@JSONbored

Context

Three test/unit/ files fail non-deterministically depending on the machine they run on,
independent of any working-tree change (reproduces on a clean checkout of main):

  • test/unit/local-branch.test.ts — two resolveWorkspaceCwd/normalizeMcpWorkspaceRoots
    assertions compare against the raw os.tmpdir() path, but
    packages/loopover-mcp/lib/local-branch.ts's safeResolvedPath correctly resolves it via
    realpathSync. On macOS, os.tmpdir() lives under /var/folders/..., itself a symlink to
    /private/var/folders/..., so the raw and resolved paths diverge and the assertion fails.
    Linux CI runners don't have this symlink, so the bug is invisible there.
  • test/unit/miner-init-verify-token.test.ts and test/unit/miner-self-review-context.test.ts
    — several runInit/fetchSelfReviewContext calls don't isolate env/loopoverAuth, so
    packages/loopover-miner/lib/github-token-resolution.ts's resolveGitHubToken /
    resolveLoopoverBackendSession fall through to process.env and read a real
    ~/.config/loopover/config.json on any machine that has ever run loopover-mcp login.
    That fires an extra, unmocked-in-intent concurrent fetch (the ORB live-gate-thresholds
    probe), which races with and corrupts other captured fetch calls/headers/timeouts in the
    same Promise.all — including reusing a mockResolvedValue'd Response object across two
    fetch calls, whose second .json() read silently fails since Response bodies are
    single-use streams. CI has no such config file, so this is invisible there too.

Requirements

  • local-branch.test.ts's two affected assertions must compare against the realpathSync-
    resolved form of the temp path, matching what safeResolvedPath itself does, so the test is
    correct on both macOS (symlinked tmpdir) and Linux (unsymlinked tmpdir).
  • Every fetchSelfReviewContext(...) call in miner-self-review-context.test.ts that is not
    itself testing the live-gate-thresholds probe feature must pass loopoverAuth: null
    (mirroring the file's own existing convention for the tests that already do this), so none of
    them depend on ambient machine state.
  • miner-init-verify-token.test.ts's makeTempEnv() helper must isolate
    LOOPOVER_CONFIG_DIR/LOOPOVER_CONFIG_PATH/XDG_CONFIG_HOME/GITHUB_TOKEN (pointing
    LOOPOVER_CONFIG_DIR at a fresh empty temp dir), following the same pattern
    test/unit/miner-github-token-resolution.test.ts's configuredEnv helper already
    establishes for this exact module.

Deliverables

  • test/unit/local-branch.test.ts — realpath-resolve the two expected-path comparisons.
  • test/unit/miner-init-verify-token.test.ts — isolate makeTempEnv() from real
    loopover-mcp config/session state.
  • test/unit/miner-self-review-context.test.ts — add loopoverAuth: null to every call
    site that isn't specifically exercising the probe.

Test Coverage Requirements

All changes are confined to test/**, which is outside Codecov's coverage.include
(src/** only), so this carries no codecov/patch obligation. The regression signal is the
fix itself: these are pre-existing tests whose assertions become environment-independent
rather than new tests being added.

Expected Outcome

npx vitest run test/unit/local-branch.test.ts test/unit/miner-init-verify-token.test.ts test/unit/miner-self-review-context.test.ts (and the full npm run test:coverage, unsharded)
is green regardless of the host OS or whether the machine has a real loopover-mcp session on
disk — no excluded files, no machine-specific caveats.

Links & Resources

  • packages/loopover-mcp/lib/local-branch.ts (safeResolvedPath, resolveWorkspaceCwd,
    normalizeMcpWorkspaceRoots)
  • packages/loopover-miner/lib/github-token-resolution.ts (resolveGitHubToken,
    resolveLoopoverBackendSession)
  • packages/loopover-miner/lib/self-review-context.ts (fetchSelfReviewContext,
    normalizeOptions, probeLiveGateThresholds)
  • test/unit/miner-github-token-resolution.test.ts's configuredEnv helper (the existing,
    correct isolation pattern for this exact module)

Metadata

Metadata

Assignees

Labels

gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.maintainer-onlyOwner-only work — yields no Gittensor points.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions