Skip to content

Add integration tests for nonexistent package caching and invalid log file path#9

Merged
Malcolmnixon merged 4 commits intomainfrom
copilot/add-integration-tests
Mar 1, 2026
Merged

Add integration tests for nonexistent package caching and invalid log file path#9
Malcolmnixon merged 4 commits intomainfrom
copilot/add-integration-tests

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

Two error paths in RunToolLogic and Context.OpenLogFile had no integration test coverage.

Description

  • IntegrationTest_CacheNonexistentPackage_ReturnsError — exercises the path where NuGetCache.EnsureCachedAsync throws InvalidOperationException for an unknown package; asserts non-zero exit code and "Error" in output
  • IntegrationTest_LogFlag_WithInvalidFilename_ReturnsError — exercises Context.OpenLogFile failure by passing a path into a nonexistent directory (/nonexistent_dir_xyz_abc/invalid.log); asserts non-zero exit code and "Error" in output. Path is a hard-coded const — no Path.Combine — to avoid CodeQL path-traversal alerts; works cross-platform since Windows resolves root-relative paths to the current drive.
  • requirements.yaml — linked new tests to NC-CLI-009 (error reporting) and NC-CLI-007 (log flag)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code quality improvement

Pre-Submission Checklist

Build and Test

  • Code builds successfully: dotnet build --configuration Release
  • All unit tests pass: dotnet test --configuration Release
  • Self-validation tests pass:
    dotnet run --project src/DemaConsulting.NuGet.CacheTool --configuration Release --framework net10.0
    --no-build -- --validate
  • Code produces zero warnings

Code Quality

  • Code formatting is correct: dotnet format --verify-no-changes
  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

  • Spell checker passes: cspell "**/*.{md,cs}"
  • Markdown linter passes: markdownlint "**/*.md"
  • YAML linter passes: yamllint .

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable)
  • Updated ARCHITECTURE.md (if applicable)
  • Added code examples for new features (if applicable)
  • Updated requirements.yaml (if applicable)

Additional Notes

Test count increases from 43 to 45 per framework (.NET 8/9/10). CodeQL reports 0 alerts.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Add missing integration tests for coverage Add integration tests for nonexistent package caching and invalid log file path Mar 1, 2026
public void IntegrationTest_LogFlag_WithInvalidFilename_ReturnsError()
{
// Arrange - use a path into a nonexistent directory to ensure failure
var invalidLogPath = Path.Combine(Path.GetTempPath(), "nonexistent_dir_xyz_abc", "invalid.log");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Path.Combine will trigger CodeQL issues. Consider hard-coding the full path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 886a817 — replaced Path.Combine(Path.GetTempPath(), ...) with fully hard-coded platform-specific paths:

var invalidLogPath = OperatingSystem.IsWindows()
    ? @"C:\nonexistent_dir_xyz_abc\invalid.log"
    : "/nonexistent_dir_xyz_abc/invalid.log";

CodeQL confirms 0 alerts.

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
@Malcolmnixon Malcolmnixon marked this pull request as ready for review March 1, 2026 20:30
@Malcolmnixon Malcolmnixon merged commit 2579687 into main Mar 1, 2026
11 checks passed
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.

2 participants