test: improve code coverage from 63% to 74% (+179 tests)#325
Merged
Conversation
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>
Deploying archgate-cli with
|
| 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 |
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/commands/doctor.test.ts,tests/commands/telemetry.test.tsCoverage improvements by area
scanImportedRuleSource()— 0% → covereddetectTarget(), cache-miss paths, CI detection, WSL handling--json/--check/--yespathsWhat's NOT covered (and why)
cli.tsinit.tstests/integration/init.test.tssubprocesslogin-flow.tsplugin-install.tsSource changes
Only one source file changed:
src/commands/upgrade.ts— exported_formatBytesand_createDownloadProgressas test hooks (following existing_reset*pattern).src/engine/rule-scanner.ts— removed@internalJSDoc to allow test import.Test plan
bun run validatepasses: lint, typecheck, format, test (1,023 pass / 0 fail), ADR check (27/27), knip, buildglobalThis.fetchafterEachsafeRmSync, path separator handling)test.skipIfguards