Skip to content

introduce JsonEmitterBase completion of ( Tweak MetaData Report format for better readability #5929) #6530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

IbrahimMNada
Copy link
Contributor

@IbrahimMNada IbrahimMNada commented Jun 20, 2025

Microsoft Reviewers: Open in CodeFlow

This pull request is a continuation of the following #5929

As the build was failing to file snapshots for the AI Templates

This pull request only tackle the generated metadata format putting different proprieties on new Lines

Tests were failing due to the differences between escapes in Windows and Linux ,
at the GeneratorTests class in the namespace Microsoft.Gen.MetadataExtractor.Unit.Tests; .
I introduced new method called NormalizeEscapes, which will only escape "\r\n" to neglect the gap between
Windows & Linux, I hope this addition is acceptable.

the test report has been changed to be aligned with the new formatting.
here are the unit tests :

image
Microsoft Reviewers: Open in CodeFlow

@IbrahimMNada IbrahimMNada requested a review from a team as a code owner June 20, 2025 19:39
@evgenyfedorov2 evgenyfedorov2 requested a review from Copilot July 7, 2025 09:46
@evgenyfedorov2
Copy link
Member

Hi,

what is the difference from #5929 and why did you decide to create a new PR?

Copy link
Contributor

@Copilot 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 PR centralizes JSON emission logic by introducing JsonEmitterBase, refactors existing emitters to leverage it, and updates tests and golden files to align with the new JSON structure and cross-platform line-ending normalization.

  • Extracted common JSON output routines into JsonEmitterBase and adjusted EmitterBase.
  • Refactored metric, compliance, and metadata emitters to use the new base class and updated their JSON shapes.
  • Updated tests: changed RunGenerator signature, added NormalizeEscapes, switched to verbatim string literals, and refreshed golden JSON files.

Reviewed Changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Generators/Shared/JsonEmitterBase.cs Introduces reusable JSON object/array emission routines.
src/Generators/Shared/EmitterBase.cs Adjusted brace handling and made indent methods support counts.
src/Generators/Microsoft.Gen.MetricsReports/MetricDefinitionEmitter.cs Refactored to inherit from JsonEmitterBase and changed JSON structure.
test/Generators/Microsoft.Gen.MetricsReports/Unit/GeneratorTests.cs Updated RunGenerator signature and added NormalizeEscapes.
test/Generators/Microsoft.Gen.MetricsReports/Unit/EmitterTests.cs Switched expected JSON to a verbatim multi-line string.
test/Generators/**/GoldenReports/*.json Refreshed golden outputs to match the new JSON formatting.
Comments suppressed due to low confidence (2)

test/Generators/Microsoft.Gen.MetricsReports/Unit/GeneratorTests.cs:147

  • Typo in the param description: change 'The coded that the generation will be based-on.' to 'The code that the generation will be based on.'
    /// <param name="code">The coded that the generation will be based-on.</param>

test/Generators/Microsoft.Gen.MetricsReports/Unit/EmitterTests.cs:158

  • The stray comma on its own line breaks the JSON structure in the expected string literal; remove this extra comma.
,

Comment on lines +22 to +24
protected void OutObject(Action action, bool isProprietyDependent = false)
{
NewItem(!isProprietyDependent);
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

The parameter name 'isProprietyDependent' is misspelled; consider renaming it to 'isPropertyDependent' for clarity.

Suggested change
protected void OutObject(Action action, bool isProprietyDependent = false)
{
NewItem(!isProprietyDependent);
protected void OutObject(Action action, bool isPropertyDependent = false)
{
NewItem(!isPropertyDependent);

Copilot uses AI. Check for mistakes.

@@ -34,16 +37,33 @@ public EmitterBase(bool emitPreamble = true)
}
}

protected void OutOpenBrace()
protected void OutOpenBrace(bool isRoot = false) // isRoot is used to neglect any extra indentation before the brace, root has no indentation, defaulted to false for backward compatibility.
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

[nitpick] The term 'neglect' is ambiguous here; consider rewording to 'omit extra indentation' and adding a proper XML doc comment.

Suggested change
protected void OutOpenBrace(bool isRoot = false) // isRoot is used to neglect any extra indentation before the brace, root has no indentation, defaulted to false for backward compatibility.
/// <summary>
/// Outputs an opening brace. Optionally omits extra indentation if it is the root.
/// </summary>
/// <param name="isRoot">If true, omits extra indentation before the brace. Defaults to false for backward compatibility.</param>
protected void OutOpenBrace(bool isRoot = false)

Copilot uses AI. Check for mistakes.

@IbrahimMNada
Copy link
Contributor Author

Hi,

what is the difference from #5929 and why did you decide to create a new PR?

@evgenyfedorov2 Hello there ! ,

there is no difference between them .

the old PR tests kept failing because of the AI.Templates Mocks,

@evgenyfedorov2
Copy link
Member

Hi,
what is the difference from #5929 and why did you decide to create a new PR?

@evgenyfedorov2 Hello there ! ,

there is no difference between them .

the old PR tests kept failing because of the AI.Templates Mocks,

But aren't they failing in the new PR too? And why can't we just fix the failing tests in the old PR? Just curious

@IbrahimMNada
Copy link
Contributor Author

IbrahimMNada commented Jul 7, 2025

Hi,
what is the difference from #5929 and why did you decide to create a new PR?

@evgenyfedorov2 Hello there ! ,
there is no difference between them .
the old PR tests kept failing because of the AI.Templates Mocks,

But aren't they failing in the new PR too? And why can't we just fix the failing tests in the old PR? Just curious

The Main conflict happened with the files snapshots on Ai.Templates , so i needed to install DiffEngineTray to manage the snapshots. my laptop's anti virus for some reason is blocking DiffEngineTray from reaching files, and my laptop is organization obedient.
i checked a fresh branch out the main branch and moved my changes to it. so i have the golden snapshots

if you have anything in mind that could help with the old PR please share it with me

Thanks

@evgenyfedorov2 evgenyfedorov2 requested a review from dariusclay July 7, 2025 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants