feat(tests): improving E2E HTML report and output on remediation tests#7955
Open
cx-ricardo-jesus wants to merge 80 commits intomasterfrom
Open
feat(tests): improving E2E HTML report and output on remediation tests#7955cx-ricardo-jesus wants to merge 80 commits intomasterfrom
cx-ricardo-jesus wants to merge 80 commits intomasterfrom
Conversation
Contributor
…ed/payloads/all_payloads.json
…payloads/all_payloads.json
…payloads directory
…samples/sample.tf
…igured_for_organization/payloads/all_payloads.json
…igured_for_organization/payloads directory
…automated_using_release_channels/payloads/all_payloads.json
…automated_using_release_channels/payloads directory
…have_alpha_features_enabled/payloads/all_payloads.json
…older_google_projects/payloads/test_payload.json
…older_google_projects/payloads directory
…figuration_changes/payloads/all_payloads.json
…figuration_changes/payloads directory
…le_changes/test/test.tf
…le_changes/payloads directory
cx-artur-ribeiro
requested changes
Mar 16, 2026
Contributor
cx-artur-ribeiro
left a comment
There was a problem hiding this comment.
The .html and .js seems all good to me, but I have some questions regarding code maintainence and duplication. Some notes are just quality of life improvements.
Can you check and give me your opinion please?
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.








Reason for Proposed Changes
Proposed Changes
Summarystruct present inside theutils.gofile, added theRemediatedFiles, which is an array of strings, meant to store the path of the files that were remediated.testRemediationQuery, added a new map, meant to store the connections between the temporary files used to do the remediations and the original files from which those temporary files came. The key is the path to these temporary files, and the value is the path to the original file.tempToOriginalwill be necessary to send the path to the original file through theRemediateFilemethod inside the summary, which now takes one more argument (original_file_name). Within thisRemediateFilemethod, this path is passed to thewriteRemediationfunction to append the original filename to the new fieldRemediatedFilesin theSummarystruct.testRemediationQuery, the test now returns a different message from the original, and now also mentions the files that were remediated.remediation_test.goandremediate.go, because both use the changedRemediateFilemethod that now takes one more argument.remediation_test.go, I passed thefilePathCopyFrom, which is the path of the original file used for the tests.remediate.go, I passed an empty string, because this file handles the remediation command, and in this command, which is meant to apply a remediation to a certain file, the original file path was already sent to theRemediateFilemethod.Regarding the changes on the E2E tests, I basically made changes on the following two files:
e2e/utils/json.goand.github/scripts/report/main.go. The first one writes the results of the E2E tests to a JSON file, and the second is a script that transforms the information in those JSON files and produces an HTML report.On
e2e/utils/json.go, I basically added three new helper functions:func formatPayload(payload []string),func formatVulnFiles(files []map[string]interface{})andfunc toComparableFiles(queries []model.QueryResult).The helper function
formatPayloadformats a slice of strings into a single readable string, with each line separated by a newline. Used to improve the readability of the failure message in FileCheck when the number of lines between the expected and actual output files does not match. The script will use this improved output to generate a better HTML report.The helper function
toComparableFiles(queries []model.QueryResult)flattens a list ofQueryResult, into a list of of maps, each one representing a VulnerableFile(the result from a scan in a query) enriched with it's parent QueryName so, now, the other helper functionformatVulnFilescan take each result and pass the name of the query associated with that result.Regarding the changes made in the script
.github/scripts/report/main.goI added on the TestsData struct, the fieldExpectedActualthat is of type ExpectedActual. That ExpectedActual struct has the following fields:ExtraElements, which contained a list of the lines from the Expected Result and the Actual Result, that is the result of the extra elements that are given by the
require.ElementsMatchinside thejson.gofile.TestInfo, that is the information about which test is returning the error as shown below:
Messages, that is, the output returned from the Messages in the require package functions used in the
json.gofile. This also stores the positive and expected results.The FailOutput is the output in the test that starts with the
--- FAILas shown below:Both of the fields
ExtraElementsandMessageshave the typeActualExpectedWithStatusthat have a list ofCodeLineStatusthat is basically a line of the output with its status. The status will be used to parse the lines that differ from the expected result and the actual result to allow them to be highlighted in the generated HTML report.In this script, I added five helper functions:
cleanOutput(s string) stringcleans a line of test output by removing noise added by the go-spew library, such as type annotations (e.g.(string),(int),(model.IssueType)) and length annotations (e.g.,(len=3)). This ensures that when lines are compared and displayed in the report, they are readable and not cluttered with internal Go type information.extractPayloadDiffLines(failLog []string) ExpectedActualparses the fail log output for tests that failed due to a mismatch in the number of lines between the expected and actual payload files. It extracts the expectedPayload and actualPayload sections into the Messages field, and the --- FAIL line into FailOutput, by iterating over the log lines and switching state based on known prefixes.extractExpectedActualLines(failLog []string) ExpectedActualparses the fail log output for tests that failed due to mismatched query results (i.e. when require.ElementsMatch fails). It extracts the extra elements reported in "list A" and "list B" into the ExtraElements field, the full expected and actual query content into Messages, and the --- FAIL line into FailOutput. Each line is cleaned using cleanOutput before being stored.isDifferentNumberOfLines(failLog []string) boolinspects the fail log to determine whether the test failed because the expected and actual output files have a different number of lines. It does so by checking if the log contains both "Expected file number of lines:" and "Actual file number of lines:" markers, which are produced by the FileCheck function in json.go.isExpectedVsActual(failLog []string) boolinspects the fail log to determine whether the test failed due to a query result mismatch reported by require.ElementsMatch. It checks for the presence of both "extra elements in list A:" and "extra elements in list B:" markers in the log, which are the markers used by the testify library when two slices do not match.compareMessageContent(expectedActual *ExpectedActual)iterates over the Messages and ExtraElements fields of an ExpectedActual and compares each line at the same position between the expected and actual content. If a line differs, or if one side has more lines than the other, the differing lines are marked with Status = true. This status is later used by the HTML report template to highlight the lines that differ between the expected and actual output.E2E_CLI_068_RESULT.jsonin the e2e/fixtures file.E2E_CLI_032.json).As shown below, the HTML report is clearly more readable and shows the source of the error more clearly.
Before:
After:

I submit this contribution under the Apache-2.0 license.