Skip to content

Conversation

@gfs
Copy link
Contributor

@gfs gfs commented Jul 29, 2025

This pull request introduces several improvements and updates across the project, including bug fixes, dependency updates, enhancements to the SarifWriter logic, and the addition of comprehensive test cases. Below is a summary of the most important changes:

Bug Fixes and Enhancements:

  • Fixed an issue where the Sarif Markdown value failed to populate the rule's provided recommendation value. Updated the logic in SarifWriter to ensure recommendations, descriptions, and rule information are appropriately handled in SARIF output. (DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs, [1] [2]

Testing:

  • Added extensive test cases for SarifWriter to validate the handling of recommendations, descriptions, and fallback logic in SARIF Help fields. These tests ensure robust behavior for various rule configurations. (DevSkim-DotNet/Microsoft.DevSkim.Tests/SarifWriterTests.cs, DevSkim-DotNet/Microsoft.DevSkim.Tests/SarifWriterTests.csR1-R360)

Dependency Updates:

  • Updated the brace-expansion dependency in multiple package-lock.json files to address potential security or compatibility concerns:
    • Updated from version 1.1.11 to 1.1.12 in DevSkim-VSCode-Plugin/client/package-lock.json. [1] [2]
    • Updated from version 2.0.1 to 2.0.2 in DevSkim-VSCode-Plugin/package-lock.json.

Documentation:

  • Updated the Changelog.md file to document the changes introduced in version 1.0.63, including the bug fix, dependency updates, and new test cases.

@gfs gfs requested a review from Copilot July 29, 2025 16:23

This comment was marked as outdated.

gfs added 2 commits July 29, 2025 09:24
Populate the Description or Recommendation fields in the markdown description since that is what ends up rendered when used in github code scanning per report in #697 of inability to customize message with custom rules.
@gfs gfs changed the title Bumps npm dependencies and DevSkim .NET dependencies Bumps npm dependencies and DevSkim .NET dependencies, Fix #697 Jul 29, 2025
gfs added 2 commits July 29, 2025 09:46
Introduces SarifWriterTests to verify SARIF help field population for rules with various combinations of recommendation, description, and rule info. Tests cover fallback logic, markdown formatting, and edge cases such as empty or whitespace recommendations.
@gfs gfs requested a review from Copilot July 29, 2025 17:17

This comment was marked as outdated.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@danfiedler-msft danfiedler-msft left a comment

Choose a reason for hiding this comment

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

A few small suggestions and nits to take or leave; overall LGTM.

gfs added 5 commits July 29, 2025 15:03
Extracted markdown description building into a new BuildMarkdownDescription method for improved readability and maintainability. The logic for constructing the SARIF rule's Help.Markdown field is now encapsulated in a dedicated helper function.
Replaces class-level StringWriter and SarifWriter fields with local variables in each test method. This improves test isolation and resource management by using 'using' statements for disposable objects.
Replaced calls to the ParseSarifOutput helper with direct usage of JObject.Parse in SarifWriterTests. Removed the now-unused ParseSarifOutput method for simplification.
Test method names in SarifWriterTests.cs were updated to use descriptive, behavior-driven naming. This improves readability and makes test purposes clearer for future maintenance.
Eliminated the Patterns property from the test case object initialization in SarifWriterTests.cs, as it was not required for the test.

This comment was marked as outdated.

gfs added 3 commits July 29, 2025 19:50
Moved the logic for building SARIF rule text descriptions into a dedicated BuildTextDescription method for improved readability and maintainability.
Introduces a unit test to verify that when a rule has no recommendation and no rule info, the SARIF 'help.markdown' field is empty or null, while 'help.text' falls back to the rule description.
Added details for version 1.0.63 including a fix for Sarif Markdown recommendation value population (#697), new test cases for SarifWriter, and updated dependencies. Fixed some section header levels to improve formatting.
"integrity": "sha1-9y12C+Cbf3bQjtj66Ysomo0F+rM=",
"dev": true
},
"node_modules/brace-expansion": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Should we create a follow-up issue to change the other dependencies to use the artifact feed (rather than npm registry) as well? (and same for DevSkim-VSCode-Plugin/package-lock.json)

Copy link
Contributor Author

@gfs gfs Jul 30, 2025

Choose a reason for hiding this comment

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

No. It is intentional that the package-lock.json uses public sources when checked in - using the private feed would render the VS Code extention impossible for external contributors to build/reproduce without blowing up or modifying the package-lock.json, which obviates its purpose. It also would downgrade the integrity values in the package-lock.json to sha1 due to a longstanding issue with azure artifact feeds: https://developercommunity.visualstudio.com/t/npm-packages-from-azure-artifact-defaulting-to-sha/957522

As part of the previous work to enable the .npmrc in I added extra steps to the pipeline build that swap out npmjs.org with the private feed before building in the pipeline.

There is a special task in the package.json that performs the base uri swapping before building:

"pipeline-pack":"npm install --global @microsoft/artifacts-npm-credprovider --registry https://pkgs.dev.azure.com/artifacts-public/23934c1b-a3b5-4b70-9dd3-d1bef4cc72a0/_packaging/AzureArtifacts/npm/registry/ && artifacts-npm-credprovider && npm run restore-net && npm run rewrite-registry:root && npm run rewrite-registry:client && npm run pack-ext",

By calling this script: https://github.com/microsoft/DevSkim/blob/main/DevSkim-VSCode-Plugin/scripts/updatePackageLock.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see now what you meant, good catch, it seems that only the packages in the root level but not the client folder had been updated with the internal feed. This was inadvertent. I intended for all packages in the checked in package-lock to continue using npmjs.org.

Deleted the test 'When_rule_has_recommendation_and_rule_info_then_markdown_includes_both' from SarifWriterTests.cs as it was redundant with `When_rule_has_recommendation_and_rule_info_then_markdown_is_properly_formatted`
The internal repository is substituted during pipeline build to allow for external contributor use
@gfs gfs requested a review from Copilot July 30, 2025 15:08

This comment was marked as outdated.

Introduced a CreateHelpUri method in SarifWriter to safely construct help URIs for DevSkim rules, handling null or empty RuleInfo values. Updated related unit tests to use the new baseHelpUri constant for consistency and maintainability.
Replaces references to SarifWriter.baseHelpUri with SarifWriter.CreateHelpUri in SarifWriterTests to ensure help URIs are generated consistently. This improves test accuracy and future-proofs against changes in URI construction.
@gfs gfs requested a review from Copilot July 30, 2025 15:29

This comment was marked as outdated.

gfs added 2 commits July 30, 2025 08:30
Updated the constant baseHelpUri to use PascalCase (BaseHelpUri) for consistency with naming conventions. Adjusted references to the constant accordingly.
Changed tests to use Assert.AreEqual with expected markdown and help text strings instead of Assert.IsTrue with Contains. This ensures stricter validation of the output format.
@gfs gfs requested a review from Copilot July 30, 2025 16:49

This comment was marked as outdated.

gfs added 2 commits July 30, 2025 09:52
Replaces repeated calls to SarifWriter.CreateHelpUri with a local helpUri variable in test assertions for expectedMarkdown. This improves readability and reduces redundant method calls.
@gfs gfs requested a review from Copilot July 30, 2025 16:55

This comment was marked as outdated.

gfs added 2 commits July 30, 2025 09:56
Updated the visibility of the BaseHelpUri constant from public to private in SarifWriter.cs to restrict its access within the class.
The CreateHelpUri method in SarifWriter was changed from public to internal to restrict its visibility within the assembly. This helps encapsulate implementation details and limits external usage.
@gfs gfs requested a review from Copilot July 30, 2025 16:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes a bug in the DevSkim SARIF output where recommendations were not properly included in the SARIF Help field, updates npm and .NET dependencies, and adds comprehensive test coverage.

  • Fixes SARIF markdown value failing to populate rule recommendation value (#697)
  • Updates brace-expansion dependency versions in package-lock.json files
  • Adds extensive test cases for SarifWriter to validate recommendation and help field handling

Reviewed Changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.

File Description
DevSkim-DotNet/Microsoft.DevSkim.Tests/SarifWriterTests.cs Adds comprehensive test suite for SarifWriter with 12 test methods covering various recommendation and help text scenarios
DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs Refactors SARIF help text generation logic into separate methods and fixes recommendation handling
Changelog.md Documents version 1.0.63 changes including the bug fix, dependency updates, and new test cases
Files not reviewed (2)
  • DevSkim-VSCode-Plugin/client/package-lock.json: Language not supported
  • DevSkim-VSCode-Plugin/package-lock.json: Language not supported
Comments suppressed due to low confidence (2)

DevSkim-DotNet/Microsoft.DevSkim.Tests/SarifWriterTests.cs:168

  • This test case creates a rule with null description but the test name and assertion suggest it should test the fallback behavior when both recommendation and description are missing. Consider using an empty string or ensuring the test validates the actual fallback logic.
            var rule = CreateTestRule("TEST007", "Test Rule", null, null, ruleInfo);

DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs:372

  • [nitpick] The variable name 'markdownDescriptionBuilder' is verbose. Consider shortening it to 'markdownBuilder' for better readability.
            StringBuilder markdownDescriptionBuilder = new();

Comment on lines +330 to +342
var baseUri = new Uri(BaseHelpUri);

if (string.IsNullOrEmpty(ruleInfo))
{
// Return base URI if no specific rule info is provided
return baseUri;
}

// Use Uri constructor to safely combine base URI with relative path
return new Uri(baseUri, ruleInfo);
}

/// <summary>
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Creating a new Uri object for the base URI on every method call is inefficient. Consider making this a static readonly field to avoid repeated object creation.

Suggested change
var baseUri = new Uri(BaseHelpUri);
if (string.IsNullOrEmpty(ruleInfo))
{
// Return base URI if no specific rule info is provided
return baseUri;
}
// Use Uri constructor to safely combine base URI with relative path
return new Uri(baseUri, ruleInfo);
}
/// <summary>
if (string.IsNullOrEmpty(ruleInfo))
{
// Return base URI if no specific rule info is provided
return BaseUri;
}
// Use Uri constructor to safely combine base URI with relative path
return new Uri(BaseUri, ruleInfo);
}
/// <summary>
/// Cached base URI for help links
/// </summary>
private static readonly Uri BaseUri = new Uri(BaseHelpUri);
/// <summary>

Copilot uses AI. Check for mistakes.
@gfs gfs requested a review from danfiedler-msft July 30, 2025 17:01
gfs added 4 commits July 30, 2025 10:18
Added InternalsVisibleTo for Microsoft.DevSkim.Tests in the CLI project file to allow unit testing of internal members. Changed CreateHelpUri from public to internal in SarifWriter to restrict its visibility to within the assembly.
Deleted the unused 'oneUpPath' variable from the test setup to clean up the code.
Deleted the unused 'oneUpPath' variable from the test method to clean up the code.
Eliminated the unused exception variable in the catch block of the regex creation method. Added a TODO comment noting the need to refactor for logging since the logger is not accessible in the static context.
@gfs gfs merged commit c93fbb0 into main Jul 30, 2025
16 checks passed
@gfs gfs deleted the gfs/JulyDeps branch July 30, 2025 20: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.

3 participants