forcedotcom / cli

Salesforce CLI
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/
BSD 3-Clause "New" or "Revised" License
494 stars 78 forks source link

sf project deploy validate : Can not use option --test-level: NoTestRun #3023

Closed nvuillam closed 3 weeks ago

nvuillam commented 2 months ago

Summary

sf project deploy validate : Can not use value --test-level: NoTestRun

If I want to validate the future deployment of a single layout, I should be able to do so without running test classes :)

Note: --ignore-warnings is not accepted either

Steps To Reproduce

Any call to sf project deploy validate with --test-level: NoTestRun

Expected result

Deployment validation without running test classes

Actual result

Error (1): Expected --test-level=NoTestRun to be one of: RunAllTestsInOrg, RunLocalTests, RunSpecifiedTests

Additional information

image

System Information

$ sf version --json --verbose
 »   Warning: sfdx-hardis is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.
{
  "architecture": "win32-x64",
  "cliVersion": "@salesforce/cli/2.58.7",
  "nodeVersion": "node-v20.16.0",
  "osVersion": "Windows_NT 10.0.22631",
  "rootPath": "C:\\Users\\33614\\AppData\\Roaming\\npm\\node_modules\\@salesforce\\cli",
  "shell": "C:\\Program Files\\Git\\usr\\bin\\bash.exe",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 3.2.2 (core)",
    "@oclif/plugin-commands 4.0.13 (core)",
    "@oclif/plugin-help 6.2.10 (core)",
    "@oclif/plugin-not-found 3.2.18 (core)",
    "@oclif/plugin-plugins 5.4.6 (core)",
    "@oclif/plugin-search 1.2.7 (core)",
    "@oclif/plugin-update 4.5.5 (core)",
    "@oclif/plugin-version 2.2.11 (core)",
    "@oclif/plugin-warn-if-update-available 3.1.13 (core)",
    "@oclif/plugin-which 3.2.12 (core)",
    "@salesforce/cli 2.58.7 (core)",
    "apex 3.4.8 (core)",
    "api 1.2.1 (core)",
    "auth 3.6.54 (core)",
    "data 3.6.5 (core)",
    "deploy-retrieve 1.17.6 (user) published 389 days ago (Wed Aug 23 2023) (latest is 3.12.10)",
    "dev 2.4.2 (user) published 20 days ago (Mon Aug 26 2024)",
    "info 3.4.3 (core)",
    "limits 3.3.29 (core)",
    "marketplace 1.2.25 (core)",
    "org 4.5.7 (core)",
    "packaging 2.8.6 (user) published 2 days ago (Sat Sep 14 2024)",
    "schema 3.3.26 (core)",
    "settings 2.3.16 (core)",
    "sobject 1.4.33 (core)",
    "source 3.5.18 (core)",
    "telemetry 3.6.10 (core)",
    "templates 56.3.17 (core)",
    "trust 3.7.27 (core)",
    "user 3.5.29 (core)",
    "@salesforce/sfdx-scanner 3.23.0 (user) published 174 days ago (Tue Mar 26 2024) (latest is 4.5.0)",
    "lightning-flow-scanner 2.22.0 (user) published 155 days ago (Sun Apr 14 2024) (latest is 2.34.0)",
    "sfdmu 4.36.0 (user) published 8 days ago (Sat Sep 07 2024)",
    "sfdx-essentials 2.12.0 (user) published 1007 days ago (Tue Dec 14 2021)",
    "sfdx-git-delta 5.44.0 (user) published 3 days ago (Fri Sep 13 2024)",
    "sfdx-hardis 5.0.0 (link) C:\\git\\pro\\sfdx-hardis2",
    "texei-sfdx-plugin 2.7.0 (user) published 6 days ago (Tue Sep 10 2024)"
  ]
github-actions[bot] commented 2 months ago

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.

shetzel commented 2 months ago

You can use this command: sf project deploy start --dry-run --test-level NoTestRun

nvuillam commented 2 months ago

@shetzel i know but ... will it allow me to use quickDeploy after ? I need that :)

nvuillam commented 2 months ago

@shetzel i made a PR :)

shetzel commented 2 months ago

@nvuillam that command with --dry-run still does a "check-only" deploy so you can use the ID for the subsequent quick deploy.

See https://github.com/forcedotcom/cli/discussions/2688 and https://github.com/forcedotcom/cli/issues/2470#issuecomment-1721450764

nvuillam commented 2 months ago

@shetzel I'm sorry but it does not work using start --dry-run and NoTestRun

  "context": "DeployMetadataQuick",
  "data": {
    "errorCode": "sf:INVALID_ID_FIELD",
    "message": "INVALID_ID_FIELD: Source validate did not run tests in the org"
  },
  "stack": "CannotQuickDeployError: Job ID can't be used for quick deployment. Possible reasons include the deployment hasn't been validated, has already been deployed, or the validation expired because you ran it more than 10 days ago.

I don't know what this validate command can be used for, if it can not ignore warnings and can not be called with NoTestRun :(

Would you consider accepting enhancements ? :)

shetzel commented 2 months ago

That's the Metadata API enforcement, not CLI. If you're quick deploying to production then tests are required. I'm pretty sure that's a rule regardless of what's being deployed. If you're quick deploying to non-prod then that enforcement isn't there.

JaydeepGo commented 2 months ago

Hi @nvuillam

you can simply run sf project deploy start command for both with/without test run.

sf project deploy start --manifest ./manifest/package.xml --dry-run --test-level RunSpecifiedTests --tests testRecordsTest

The new sf project deploy start command will trigger the Quick Deploy Option if validation meets the following condition. Same as sfdx force:source:deploy.

    1. The components have been validated successfully for the target environment within the last 10 days.
    2. As part of the validation, Apex tests in the target org have passed.
    3. Code coverage requirements are met.
    * If all tests in the org or all local tests are run, overall code coverage is at least 75%, and Apex triggers have some coverage.
    * If specific tests are run with the RunSpecifiedTests test level, each class and trigger that was deployed is covered by at least 75% individually.
shetzel commented 1 month ago

@nvuillam - would it solve your usecase if the --test-level default value was removed from the validate command? In theory, that leaves it up to the org whether it needs to run tests or not based on what's deployed. That might satisfy the quick deploy requirements so that it can be used. If you're able to test it out and confirm we could move forward with that.

https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deployRecentValidation.htm

nvuillam commented 1 month ago

@shetzel i moved all calls to deploy start --dry-run, but if validate is able to handle the options I need, i'll gladly switch back :)

cristiand391 commented 3 weeks ago

circling back to this...

sf project deploy validate's goal is to validate deployments that can be quick-deployed later. Allowing --test-level to be NoTestRun would invalidate the quick deploy and sf project deploy quick will not work.

If someone can test Steve's suggestion in a prod org and confirm it allows deploy quicks we can consider supporting it, in my testing that didn't work. https://github.com/forcedotcom/cli/issues/3023#issuecomment-2412020863