-
Notifications
You must be signed in to change notification settings - Fork 407
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
Code Coverage Reports in Deploy Commands Produce Unreliable Covered
Lines
#5511
Comments
Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support. |
There is nothing new to report on the code coverage front from that last issue you mentioned. The CLI team is dependent on some other internal teams and their priorities for any work to begin on this. If the code coverage data in the API response is not accurate then there's nothing we can do except report what's given to us. So from a CLI perspective, the code is making the correct calls and reporting the response as provided (i.e., working as designed), and to change that we need other teams to prioritize that work. It's on their roadmaps but I don't know when it will be delivered. |
Should we keep this issue open @shetzel or just close it since this seems out of the CLI team's responsibility? Seems like once the API team updates the API response to provide accurate code coverage, it will work fine on any version of the CLI. |
In my opinion we should close it. Unless there is a breaking change involved with responses there is nothing the CLI would have to do to provide better, more accurate code coverage when those fixes are made to the server side APIs and libraries. You and any others are welcome to post here asking for updates on this. I'm hopeful that the work will at least be prioritized this year and we can relay that information when we have it to keep everyone up to date.
If the fixes are only serverside, then yes. If there is more involved (e.g., updates to the |
it is a blocker for pipeline with Quality Gates. I've been struggling with this issue for few months now. One thing I noticed is the code should be modularized and clean for the issue not to happened. There are times that the error still shows up even the code is modularized and well written which becomes a blocker on development as the code can't be enhanced anymore. |
@jfaderanga - Per @shetzel , this issue needs to be fixed by the team that manages the API first. I agree with you that this is a blocker for anyone who is trying to implement Quality Gates that enforce code coverage. @shetzel - Is there a different way to contact the right team that owns updates to the API (outside of a general Salesforce support case)? |
I agree with both of you that it's an issue, just not an issue that anyone on the CLI team can do anything about. This repo is about issues with the CLI. If it's open, it implies we can take some action on it but in this case we can't.
The best ways to influence the right team are opening a support case, and voting up the idea on the IdeaExchange. |
mcarvin8/apex-code-coverage-transformer#3 @jfaderanga - I was working on this with my plug-in that converts the coverage JSON to an XML SonarQube will accept. This will convert covered lines and work around this known issue by reassigning out of bound lines with unused lines. The coverage % will vary but it should still pass if you're hitting coverage. I could release this but I'm skeptical since the covered lines won't always report back the same way (comments and new lines can change it). But then again, however the API calculates deploy coverage is incorrect so this plugin would just convert that JSON entry to a XML entry. Like I've seen it report back 86% coverage and then 88% coverage on other runs for example. So it should pass in most cases as long as your not near the 75% minimum requirement but this updates isn't ideal until the API is fixed to report back the right covered lines. If you want, you can try my beta plugin with these updates - That creates a coverage.xml you can pass to SQ. It's not ideal until the API is fixed but this will get coverage % in SonarQube relative to what the deploy command currently splits out. |
@mcarvin8 I'm using the direct XML (cobertura) output from the deploy command, it has coverage rate from the class node. I upload this to Azure DevOps and Sonar Cloud, from what I noticed, the SC only reads the coverage rate from the class node and it just uses the lines for the UI line highlighting. I haven't seen the JSON output but I expect it should be the same, does your plugin also update the coverage rate, it shouldn't be ay, just the lines? I've been doing heavy manipulation already to fix the XML to correct the file path (no-map/classname issue), adding more may affect the pipeline performance, but I'll give it a go as I don't have any workaround at the moment, thanks for the suggestion. |
@jfaderanga - My plugin essentially just converts the JSON output from the deploy command into a XML file containing the uncovered lines/covered lines. The All builds will take care of replacing We noticed with SonarQube that just providing uncovered lines will not update the Coverage % (with the After doing the updates in the |
@shetzel is IdeaExchange really the best way forward in our situation? I mean this code coverage functionality for validation deployments is already part of the end product, rather than being a new "Idea" that the POs would need to prioritize. Therefore, there should be a more streamlined approach how to highlight this issue/bug directly to the correct team for them to start bug fixing. |
@xL3o - I meant that more as a general statement of how to get issues in front of non-CLI teams. For this issue, a support case is best. However, I'll open this back up and transfer it to the apex-node library. That team is a better choice to own this issue. |
The no-map replacement feature, does it support multiple packageDirectories or just defaults it to force-app? |
Currently it just supports one directory via the I can look into supporting multiple package directories if you want (probably something like scanning for the sfdx-project.json file and reading all directories listed). |
@jfaderanga - I just released a new version of the plugin which supports multiple package directories as listed in your project's https://github.com/mcarvin8/apex-code-coverage-transformer/releases/tag/v1.5.0 This version (which is the I will need to do some additional work to back-fit these changes into a pre-release/ Of course, if this issue is escalated and fixed soon, I don't need to do extra manipulation to correct |
@mcarvin8 that's awesome mate, thanks for the quick turn around time for this, i'll try this today.. |
@jfaderanga - Awesome! I just released a new Big catch like I've stated previously is that the Salesforce CLI will produce out-of-range If you want to try the Otherwise, the So just to sum up:
|
@mcarvin8 I have tried the beta version From what I noticed with the API output, the coverage percentage is correct. If you divide the number of uncovered lines by the number of covered lines, it gives you the coverage percentage which is the same with what is showing in Salesforce. The plugin beta version Also the plugin correctly maps the file path, kudos for this mate! I would say your plugin mate is an acceptable long-term workaround for this issue as I bet it will take a long time for the issue to be generally fixed. I'm happy to implement this in our CI, thanks a lot @mcarvin8 and @xL3o and @shetzel ! Let me know when you release the stable version of the 1.6.0 beta. |
@jfaderanga - Thank you for testing this out and letting me know! I have released the Once this issue is resolved by Salesforce, I'll remove that re-number function.
|
@mcarvin8 I started looking into implementing this and made few more tests. The plugin seems to be having an issue trying to find a matching file if the file name contains underscores. The sample below is from the JSON API output.
The plugin returns the following error even though the file is indeed within one of the package directory. |
@jfaderanga Can you make an issue here on my repo, please? - https://github.com/mcarvin8/apex-code-coverage-transformer/issues I just tested it out by renaming the Test Apex Class I use in my Unit Test to What's the full path to the file in your package directory? In the code, I'm assuming the classes, triggers, and flows are in these sub-folder names ( I've only worked with repos following the default
EDIT: I have released a new version -
Please try |
@mcarvin8 yeah looks like the
The |
@peternhale - Could you provide any updates to the task of fixing the API to correctly return Code Coverage covered lines during deploy commands? The covered lines returned by the API for deployment commands are inaccurate in their current state, which makes it unreliable to track coverage percentages in tools like SonarQube. I recall your name being brought up in a code coverage discussion with Allan Oricil, so feel free to include anyone else here if you are the not right person to contact for this. Please ignore the back-and-forth with JaysonF and I in previous comments on this thread regarding my Salesforce plugin which is designed to convert the code coverage JSON output to an XML for SQ. |
Hi @mcarvin8 Sure, the root issue of the inaccuracy of the code coverage for tests run during a deploy is in the data returned from the deploy. To get to the code coverage we drill down on the returned data starting with DeployResult -> DeployDetails[] -> RunTestResult -> CodeCoverageResult[] You will find field The I have tried to find an alternative source to fetch the coverage for the test run, but that did not yield anything to use. |
Thanks @peternhale. Is there any POC you could provide on the team who owns the CodeCoverageResult object that I could tag to escalate this issue? Or should I raise a Salesforce support case to see if this can get prioritized for release this year? |
@mcarvin8 the only recourse would be to open a support case. |
I just discovered this problem yesterday and found this thread. @mcarvin8 do you already have a case? I can help with a scenario for them to analyse if needed. |
@marcoalmodova - Here's the case i just submitted. I can add you as a collaborator if you provide me an email to use. A scenario to have them analyze would be great. https://help.salesforce.com/s/case-view?caseId=500Hx00000VnAu1IAF |
@mcarvin8 hey mate, can you add me too as collaborator? thanks heaps mate.. |
@mcarvin8 thanks! My email: [email protected] I can create an org with a basic apex class + test method, but I think I will need to give them a user so they can authentic locally to run the command, right? |
This issue has been linked to a new work item: W-16286380 |
Is there a way to track the linked work item (W-16286380) status somewhere (publicly) or is it private. If so, could someone please share a link? |
I am trying to implement a pipleine with coverage data as well. I see that when I run with cobertura no results are returned from the CLI.
|
@mcarvin8 can you help me figure what this error means? What am I missing here?
I'm using [email protected] version and the commands I'm running are as follows
Is this because of source directory not being force-app. It's with a different name. I tried --dx-directory abc-application as well, but got same error. |
I figured it out, the right command to be run is But it still gives me error, Any help further is appreciated, thank you! |
@littyphilip90 please use the latest plugin version. |
Concur with @xL3o , @littyphilip90 please use the latest plugin version and submit any issues you may have with the plugin to https://github.com/mcarvin8/apex-code-coverage-transformer. Let's keep this specific issue clean so that Salesforce can let us know when the API is corrected to report back correct deploy coverage data. Your specific issue with my plugin sounds fixed by the Windows-specific path fix I included with 1.7.1 - mcarvin8/apex-code-coverage-transformer@v1.7.0...v1.7.1 Please use the latest plugin though. I removed the need to provide the Starting with the 1.7.X builds, I have replaced the |
@peternhale - Could you potentially answer @xL3o 's question above, please? |
We have determined that the issue you reported exists in code owned by another team that uses only the official support channels, and thus we are closing this issue. To ensure that your issue is addressed, open an official Salesforce customer support ticket with a link to this issue. We encourage anyone experiencing this issue to do the same to increase the priority. |
Sounds like this may have been fixed via forcedotcom/cli#3030 Can someone from Salesforce confirm? |
Hi @mcarvin8, The issue is on the server side and hasn't been resolved yet by the Apex Team. The CLI Team produced a workaround to try to produce better code coverage results, but the coverage percentage will not be 100% accurate until the issue on the server side is fixed. |
Is there any way to escalate this issue to the Apex Team without going through the customer support ticket process? I do not have the time to go through the ticketing process of having a service rep engage me, having to get on a call with them to go over details, potentially trying to reproduce it, etc. for a bug which affects all users that is well known and has been open for years. I'm not sure if there's a simple way to create a playground environment to reproduce this issue as I've seen it randomly and not sure if there's a sure fire way to reproduce this with test apex code. But I do not think a bug fix should take dozens of developers raising their own service rep tickets and going through the chains for this ticket to be prioritized. I echo this comment from this thread made earlier. I'd rather open an IdeaExchange or something that everyone here can post their comments on rather than having everyone open their own support cases, but there has to be a more efficient way to get bug fixes on existing code prioritized. I have no issue with how CLI bugs are resolved by creating tickets on GitHub for them. I understand GitHub isn't apart of the SLA, but that is a much more efficient process for engaging end-users and getting bug fixes than going through support reps. I'm not sure who moved my ticket to this Repo anyway, but is there any GitHub repos that the Apex Team monitors? https://github.com/forcedotcom/salesforcedx-apex/issues perhaps? |
Hi @mcarvin8, Our product manager let us know that Apex Team prioritizes issues based on the number of customer reports. To escalate this ticket and increase the report count, please file a support case to make Apex Team aware of the impact of this bug. We apologize for the inconvenience and appreciate your patience. |
Summary
This has already been reported as bugs such as forcedotcom/cli#1568 but this has been closed due to "working as expected".
Please look into this soon for a new CLI Build.
When running
sf project deploy start
/sf project deploy validate
commands with the code coverage flags (like--coverage-formatters json
), theuncovered
lines reported back are correct. Thecovered
lines are incorrect for various reasons:covered
lines will sometimes be out-of-range lines (if there is a 98 line Apex Class, the coverage reports will report line 100 ascovered
)covered
lines are inconsistent and report back more lines than there are in the filePlease update the Salesforce CLI to reliably report
covered
lines in the code coverage files so they can be exported to tools like SonarQube for code coverage tracking. In the current state, theuncovered
lines can be exported to SonarQube correctly, but you need to havecovered
lines reported to SonarQube to calculate the coverage percentage. At this point, coverage in SonarQube will always be at 0% or the coverage % will be unreliable due to thecovered
lines being incorrectly reported.I'm unclear if the CLI's
apex
commands produce the same outputs as thedeploy
commands in terms of code coverage. But we need reliabledeploy
coverage output so we can report back accurate code coverage during deployment and validation.@xL3o - Please add anything I missed here based on our testing in my plugin.
See additional notes on my plugin here - mcarvin8/apex-code-coverage-transformer#2
Steps To Reproduce
sf project deploy start -x manifest/package.xml --coverage-formatters json
Expected result
Uncovered and covered lines are reported back correctly. The covered lines should not have out-of-range line numbers.
Actual result
Uncovered lines are correct. Covered Lines are incorrectly reported back.
System Information
Tested on Windows 11/Powershell and Ubuntu/Bash (CI/CD).
Additional information
The text was updated successfully, but these errors were encountered: