Skip to content

test: improve code coverage from 63% to 74% (+179 tests)#325

Merged
rhuanbarreto merged 8 commits into
mainfrom
coverage/phase-1
May 19, 2026
Merged

test: improve code coverage from 63% to 74% (+179 tests)#325
rhuanbarreto merged 8 commits into
mainfrom
coverage/phase-1

Conversation

@rhuanbarreto

Copy link
Copy Markdown
Contributor

Summary

  • Add 179 new tests across 21 files, raising test count from 844 to 1,023
  • Improve real code coverage (including never-loaded files) from ~63% to ~74%
  • Improve Bun-reported coverage from 89.10% to 92.68%
  • Create 2 new test files: tests/commands/doctor.test.ts, tests/commands/telemetry.test.ts
  • Extend 19 existing test files with action handler, error path, and edge case coverage

Coverage improvements by area

Area Files New Tests Key Coverage Gains
Engine rule-scanner 12 scanImportedRuleSource() — 0% → covered
Helpers registry, update-check, pack-recommend, telemetry, platform 40 detectTarget(), cache-miss paths, CI detection, WSL handling
Commands telemetry, doctor, login, adr/create, review-context, session-context (x4), adr/sync, adr/import, upgrade, plugin/url 127 Action handlers, error boundaries, ExitPromptError re-throw, --json/--check/--yes paths

What's NOT covered (and why)

File Coverage Reason
cli.ts 0% Entry point tested via subprocess in integration tests — invisible to Bun's coverage
init.ts 0% Same — tested via tests/integration/init.test.ts subprocess
login-flow.ts 4% GitHub device flow requires real HTTP polling + interactive prompts
plugin-install.ts 20% Requires real editor CLIs and authenticated network calls

Source changes

Only one source file changed: src/commands/upgrade.ts — exported _formatBytes and _createDownloadProgress as test hooks (following existing _reset* pattern). src/engine/rule-scanner.ts — removed @internal JSDoc to allow test import.

Test plan

  • bun run validate passes: lint, typecheck, format, test (1,023 pass / 0 fail), ADR check (27/27), knip, build
  • No network access in any test — all HTTP mocked via globalThis.fetch
  • All temp directories cleaned in afterEach
  • Windows-compatible (safeRmSync, path separator handling)
  • Platform-specific tests use test.skipIf guards

Renovate PR #284 re-pinned the SLSA generator to a SHA digest,
breaking provenance generation on the v0.37.0 release. The SLSA
generator's generate-builder.sh rejects non-tag refs.

This is the same fix as #250. A Renovate exclusion rule has been
added to archgate/renovate-config (PR #10) to prevent recurrence.

Ref: slsa-framework/slsa-github-generator#150
Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Add comprehensive tests across 21 files covering previously untested
command action handlers, helper functions, and engine logic. Tests
follow existing conventions: bun:test, temp dirs, spyOn mocking,
globalThis.fetch replacement, and SPDX headers.

Phase 1 - Pure logic:
- rule-scanner: scanImportedRuleSource() AST analysis
- registry: detectTarget() and resolveSource() edge cases
- update-check: cache-miss write path and semver edge cases
- pack-recommend: recommendPacks() with mocked shallowClone

Phase 2 - Command integration:
- New: telemetry command (status/enable/disable)
- New: doctor command (--json, formatted output, WSL, errors)
- session-context: error paths for all 4 editors
- review-context: error handling and option forwarding
- login: status/logout/login action handlers
- adr/create: --files, --rules, --json non-interactive paths

Phase 3 - Helpers with I/O mocking:
- telemetry: CI detection, shell detection, track* functions
- platform: WSL paths return null on non-WSL, resolveCommand

Phase 4 - Complex commands:
- adr/sync: --check, --yes, --json, diff detection, source filter
- adr/import: --list, --dry-run, --yes, ID remapping, rules copy
- upgrade: formatBytes, already-up-to-date, fetch failure paths
- plugin/url: all --editor variants

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026

Copy link
Copy Markdown

Deploying archgate-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: e9b5706
Status: ✅  Deploy successful!
Preview URL: https://918854a1.archgate-cli.pages.dev
Branch Preview URL: https://coverage-phase-1.archgate-cli.pages.dev

View logs

…ifferences

The --dry-run --json and --yes --json tests assumed ADR files would be
read in alphabetical order, but Linux readdir returns them in a different
order than Windows. Sort the parsed arrays by ID before asserting.

Also compact comment blocks to stay under the 500-line oxlint limit.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
On the Linux CI runner, set WSL_DISTRO_NAME/WSL_INTEROP env vars to
exercise the WSL detection branches in platform.ts without needing a
real WSL environment. The wslpath/cmd.exe calls fail gracefully
(returning null), which covers the error paths too.

Also test the vscode-settings WSL fallback path: when WSL is detected
but cmd.exe is unavailable, getVscodeUserSettingsPath falls through
to the standard Linux ~/.config path.

Tests are gated with test.skipIf(!isNativeLinux) so they only run on
the Linux CI runner and are skipped on Windows/macOS.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Add tests for 11 more files covering helpers with I/O mocking,
complex commands, and previously never-loaded modules.

Phase 3 - Helpers with I/O mocking:
- credential-store: gitCredentialFill timeout, clearCredentials
- telemetry-config: showFirstRunNoticeIfNeeded all branches
- install-info: getProjectContext edge cases, cache behavior
- vscode-settings: addMarketplaceToUserSettings, WSL fallback
- init-project: configureEditorSettings all editors, tryInstallPlugin
- binary-upgrade: checksum verify/mismatch, zip extraction, replaceBinary

Phase 4 - Complex commands and never-loaded files:
- plugin-install: URL builders, CLI checks, install/download functions
- plugin/install cmd: auth guard, editor paths, failure handling
- login-flow: full device flow, signup, TLS errors (all mocked)
- check cmd: registration + action handler via temp project fixtures
- formats/rules: RuleSet/RuleResult schema validation

Also fix mock.module cross-test pollution in plugin/install.test.ts
by converting findProjectRoot mock from mock.module to spyOn.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
- credential-store: gate saveCredentials tests that depend on OS
  credential helper behavior with test.skipIf(platform !== "win32").
  Fix round-trip test to set GIT_CONFIG_GLOBAL to point at the custom
  gitconfig with the store helper.
- vscode-settings: use a fresh nested subdir for the "creates directory
  structure" test so it doesn't fail when ~/.config/Code/ already exists
  on the CI runner.
- Re-add WSL fallback test that was lost during agent merge.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
- vscode-settings: remove pre-condition assertion that settings dir
  doesn't exist (homedir() on Linux may not reflect HOME override,
  and ~/.config/Code/ may already exist on CI runner)
- credential-store: skip round-trip test entirely — git credential
  store helper interaction differs across platforms due to Bun.env
  snapshot timing. Remove unused isWindows import.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
@rhuanbarreto rhuanbarreto enabled auto-merge (squash) May 19, 2026 21:00
@rhuanbarreto rhuanbarreto disabled auto-merge May 19, 2026 21:00
@rhuanbarreto rhuanbarreto merged commit 4b972c5 into main May 19, 2026
10 checks passed
@rhuanbarreto rhuanbarreto deleted the coverage/phase-1 branch May 19, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant