Skip to content
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

force: package: beta: version: create doesn't use unpackagedMetadata for testing. #1743

Closed
David-Polehonski opened this issue Oct 10, 2022 · 11 comments
Labels
bug Issue or pull request that identifies or fixes a bug

Comments

@David-Polehonski
Copy link

Summary

Short summary of what is going on or to provide context.

Steps To Reproduce:

Repository to reproduce: dreamhouse-lwc
(Steps 1 through 3 are included in the main branch of the above repository)

  1. Add a new unpackaged folder to the file system, and the sfdx-project.json. Add the unpackagedMetadata attribute to the DreamhouseLWC package definition.
"packageDirectories": [
        {
            "path": "force-app",
            "default": true,
            "package": "DreamhouseLWC",
            "versionName": "Summer '22",
            "versionNumber": "55.0.0.NEXT",
            "unpackagedMetadata": {
                "path": ".\\unpackaged"
            }
        },
        {
            "path": ".\\unpackaged",
            "default": false
        }
    ],
  1. Alter the standardValueSet for contracts by creating the file unpackaged\standardValueSets\ContractStatus.standardValueSet-meta.xml with the following content;
<?xml version="1.0" encoding="UTF-8"?>
<StandardValueSet xmlns="http://soap.sforce.com/2006/04/metadata">
    <groupingStringEnum>ContractStatusCode</groupingStringEnum>
    <sorted>false</sorted>
    <standardValue>
        <fullName>Pending_Approval</fullName>
        <default>false</default>
        <label>Pending Approval</label>
        <groupingString>InApproval</groupingString>
    </standardValue>
    <standardValue>
        <fullName>Contracted</fullName>
        <default>false</default>
        <label>Contracted</label>
        <groupingString>Activated</groupingString>
    </standardValue>
    <standardValue>
        <fullName>Working_Draft</fullName>
        <default>false</default>
        <label>Working Draft</label>
        <groupingString>Draft</groupingString>
    </standardValue>
</StandardValueSet>
  1. Create a new apex test that creates a contract with an unpackaged value:
@IsTest
public class ContractValueTest {
    @IsTest
    public static void test_CustomContractStatus()
    {
        Account a = new Account(Name='testing');
        insert a;

        Contract c = new Contract(AccountId=a.Id);
        Test.startTest();
            c.status = 'Working_Draft';
            insert c;
            System.assertEquals('Working_Draft', c.status, 'Custom contract status is set');
        Test.stopTest();
    }

}
  1. Create a new package; sfdx force:package:beta:create -n DreamhouseLWC -t Unlocked -r .\force-app\
  2. Create a new package version; sfdx force:package:beta:version:create -p DreamhouseLWC -k DreamhouseLWC -c -w 15

Expected result

A new package version should be created.

Actual result

unpackagedMetadata appears to be missing during test execution:

Version create.... Create version status: Error
ERROR running force:package:beta:version:create:  Package version creation failed with unknown error. Apex Test Failure: Class.ContractValueTest.test_CustomContractStatus: line 12, column 1 System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Status: bad value for restricted picklist field: Working_Draft: [Status]

System Information

sfdx version --verbose --json 
{
  "cliVersion": "sfdx-cli/7.172.0",
  "architecture": "win32-x64",
  "nodeVersion": "node-v16.17.1",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 1.3.1 (core)",
    "@oclif/plugin-commands 2.2.0 (core)",
    "@oclif/plugin-help 5.1.14 (core)",
    "@oclif/plugin-not-found 2.3.3 (core)",
    "@oclif/plugin-plugins 2.1.1 (core)",
    "@oclif/plugin-update 3.0.2 (core)",
    "@oclif/plugin-version 1.1.2 (core)",
    "@oclif/plugin-warn-if-update-available 2.0.6 (core)",
    "@oclif/plugin-which 2.1.0 (core)",
    "alias 2.1.5 (core)",
    "apex 1.2.0 (core)",
    "auth 2.2.13 (core)",
    "community 2.0.3 (core)",
    "config 1.4.21 (core)",
    "custom-metadata 2.0.1 (core)",
    "data 2.1.4 (core)",
    "generator 2.0.5 (core)",
    "info 2.1.9 (core)",
    "limits 2.0.5 (core)",
    "org 2.2.7 (core)",
    "packaging 1.9.4 (core)",
    "schema 2.1.10 (core)",
    "signups 1.2.7 (core)",
    "source 2.0.17 (core)",
    "telemetry 2.0.2 (core)",
    "templates 55.1.0 (core)",
    "trust 2.0.4 (core)",
    "user 2.1.10 (core)",
    "@salesforce/sfdx-plugin-lwc-test 1.0.1 (core)",
    "salesforce-alm 54.8.1 (core)"
  ],
  "osVersion": "Windows_NT 10.0.22000",
  "shell": "cmd.exe",
}
@David-Polehonski David-Polehonski added the investigating We're actively investigating this issue label Oct 10, 2022
@github-actions
Copy link

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.

@David-Polehonski David-Polehonski changed the title force:package:beta:version:create doesn't use unpackagedMetadata for testing. force\:package:beta:version:create doesn't use unpackagedMetadata for testing. Oct 10, 2022
@David-Polehonski David-Polehonski changed the title force\:package:beta:version:create doesn't use unpackagedMetadata for testing. force::package:beta:version:create doesn't use unpackagedMetadata for testing. Oct 10, 2022
@David-Polehonski David-Polehonski changed the title force::package:beta:version:create doesn't use unpackagedMetadata for testing. force: package: beta: version: create doesn't use unpackagedMetadata for testing. Oct 10, 2022
@shetzel
Copy link
Contributor

shetzel commented Oct 10, 2022

Wow! You get 3 gold stars for this issue. 1 for using the packaging beta commands. 1 for using the release candidate version of the CLI. And 1 for providing all requested information including repro steps. Awesome!

That said, I tried a few variations of your steps (mostly modifying file paths) but can't reproduce the problem on a mac. I'm assuming this is a problem only on Windows OS. I'll try to reproduce on a Windows box but until then can you:

  1. Try different paths in your repro steps. E.g., instead of "path": ".\\unpackaged" use "path": "unpackaged" to see if that makes a difference.
  2. Run the packaging command with the doctor. E.g., sfdx doctor --command "force:package:beta:version:create -p DreamhouseLWC -k DreamhouseLWC -c -w 15" and check the debug log for any output that would help us locate the problem.

@shetzel shetzel added more information required Issue requires more information or a response from the customer and removed investigating We're actively investigating this issue labels Oct 10, 2022
@shetzel
Copy link
Contributor

shetzel commented Oct 10, 2022

We can't reproduce this on a windows box either. Are there other steps involved? I created this fork of the dreamhouse-lwc repo and ran the 2 commands you mentioned above and they both worked.

@David-Polehonski
Copy link
Author

Output from running the commands this morning;
image

I adjusted the "path" :"unpackaged" as suggested but it made no difference.

I ran the sfdx doctor command; but can't see any mention of unpackaged metadata in the debug output.

I note in your fork you have the ContractValueTest in the unpackaged folder. Whereas in my example fork they are in the force-app/test/classes. My apologies - I had not made the location of the test classes clear.

@m-rodriguez7
Copy link

This is happening in our project as well. We have a package/project that references unpackaged metadata. If we create a new package version using sfdx force:package:version:create with --codecoverage, the package creation process succeeds. All unit tests pass. If we use the sfdx force:package:beta:version:create command, the package creation process fails due to unit test failures caused by the missing unpackaged metadata.

@shetzel
Copy link
Contributor

shetzel commented Oct 18, 2022

Sorry for the delay. I reproduced it now. We'll get it fixed asap. Thank you for reporting!

@shetzel shetzel added bug Issue or pull request that identifies or fixes a bug and removed more information required Issue requires more information or a response from the customer labels Oct 18, 2022
@git2gus
Copy link

git2gus bot commented Oct 18, 2022

This issue has been linked to a new work item: W-11927980

@WillieRuemmele
Copy link
Member

Hi @David-Polehonski - I cloned your fork, and was able to create a package. I then ran the beta commands and saw the same error.

 ➜  sfdx force:package:beta:version:create -p DreamhouseLWC -k DreamhouseLWC -c -w 15
Version create.... Create version status: Error
ERROR running force:package:beta:version:create:  Package version creation failed with unknown error. 
(1) Apex Test Failure: Class.ContractValueTest.test_CustomContractStatus: line 12, column 1 System.DmlException: Insert failed. First exception on row 0;

I then tried it with the current packaging commands and saw the same error.

➜  dreamhouse1743 git:(main) ✗  hub:(GLOBAL - DevHub) scratch:([email protected])
 ➜  sfdx force:package:version:create -p DreamhouseLWC -k DreamhouseLWC -c -w 15 
 ›   Warning: We no longer maintain the current implementation of the "force:package:version:create" command. You should instead use the 
 ›   "force:package:beta:version:create" command, which is functionally the same. If you run into issues, file a report against the 
 ›   "force:package:beta:version:create" command on https://github.com/forcedotcom/cli/issues.
Request in progress. Sleeping 30 seconds. Will wait a total of 900 more seconds before timing out. Current Status='Queued'
Request in progress. Sleeping 30 seconds. Will wait a total of 870 more seconds before timing out. Current Status='Initializing'
Request in progress. Sleeping 30 seconds. Will wait a total of 840 more seconds before timing out. Current Status='Initializing'
Request in progress. Sleeping 30 seconds. Will wait a total of 810 more seconds before timing out. Current Status='Initializing'
Request in progress. Sleeping 30 seconds. Will wait a total of 780 more seconds before timing out. Current Status='Initializing'
Request in progress. Sleeping 30 seconds. Will wait a total of 750 more seconds before timing out. Current Status='Initializing'
Request in progress. Sleeping 30 seconds. Will wait a total of 720 more seconds before timing out. Current Status='Initializing'
Request in progress. Sleeping 30 seconds. Will wait a total of 690 more seconds before timing out. Current Status='Initializing'
Request in progress. Sleeping 30 seconds. Will wait a total of 660 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 630 more seconds before timing out. Current Status='Finalizing package version'
ERROR running force:package:version:create:  ContractStatus: field integrity exception: unknown (invalid value)

a git status only shows the sfdx-project.json as being modified

I'm curious if this is passing with the current commands for you?

@David-Polehonski
Copy link
Author

Results from sfdx force:package:version:create -p DreamhouseLWC -k DreamhouseLWC -c -w 15 on sfdx-cli/7.176.0 win32-x64 node-v18.12.0

 »   Warning: We no longer maintain the current implementation of the "force:package:version:create" command. You should instead use the "force:package:beta:version:create"     
 »   command, which is functionally the same. If you run into issues, file a report against the "force:package:beta:version:create" command on
 »   https://github.com/forcedotcom/cli/issues.
Request in progress. Sleeping 30 seconds. Will wait a total of 900 more seconds before timing out. Current Status='Queued'
Request in progress. Sleeping 30 seconds. Will wait a total of 870 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 840 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 810 more seconds before timing out. Current Status='Finalizing package version'
ERROR running force:package:version:create:  ContractStatus: field integrity exception: unknown (invalid value)

Result from sfdx force:package:beta:version:create -p DreamhouseLWC -k DreamhouseLWC -c -w 15 on sfdx-cli/7.176.0 win32-x64 node-v18.12.0

Version create.... Create version status: Error
ERROR running force:package:beta:version:create:  Package version creation failed with unknown error. Apex Test Failure: Class.ContractValueTest.test_CustomContractStatus: line 12, column 1 System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Status: bad value for restricted picklist field: Working_Draft: [Status]

It would appear the unpackaged metadata isn't being processed in either case now.

@David-Polehonski
Copy link
Author

@WillieRuemmele I've taken another look at this; the integrity exception comes from the StandardValueSet ContractStatus. It appears to be attempting to delete values that aren't included, and this action is not permitted via the API.
I've updated the fork to resolve the issue and re-ran the commands, output is below:

Legacy

sfdx force:package:version:create -p DreamhouseLWC -k DreamhouseLWC -c -w 15

 »   Warning: We no longer maintain the current implementation of the "force:package:version:create" command. You should instead use the "force:package:beta:version:create" command, which is 
 »   functionally the same. If you run into issues, file a report against the "force:package:beta:version:create" command on https://github.com/forcedotcom/cli/issues.
Request in progress. Sleeping 30 seconds. Will wait a total of 900 more seconds before timing out. Current Status='Queued'
Request in progress. Sleeping 30 seconds. Will wait a total of 870 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 840 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 810 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 780 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 750 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 720 more seconds before timing out. Current Status='Finalizing package version'
Request in progress. Sleeping 30 seconds. Will wait a total of 690 more seconds before timing out. Current Status='Finalizing package version'
sfdx-project.json has been updated.
Successfully created the package version [08c8d000000Gnm7AAC]. Subscriber Package Version Id: 04t8d0000009cUEAAY
Package Installation URL: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t8d0000009cUEAAY
As an alternative, you can use the "sfdx force:package:install" command.

Beta

sfdx force:package:beta:version:create -p DreamhouseLWC -k DreamhouseLWC -c -w 15

Version create.... Create version status: Error
ERROR running force:package:beta:version:create:  Package version creation failed with unknown error. Apex Test Failure: Class.ContractValueTest.test_CustomContractStatus: line 12, column 1 System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Status: bad value for restricted picklist field: Working_Draft: [Status]

Result

With the issue out of the way it would appear that the legacy command is including and installing the unpackaged metadata as expected allowing for package creation with code coverage, whereas the beta command is failing to do so.

@David-Polehonski
Copy link
Author

Running these tests again on 7.177.1 which claims to have resolved this issue.

sfdx force:package:version:create -p DreamhouseLWC -k DreamhouseLWC -w 15 --codecoverage
Runs as expected and running a report on the package show codecoverage values:

=== Package Version

 Name                           Value
 ────────────────────────────── ────────────────── 
 Name                           Summer '22
 Subscriber Package Version Id  04t8d0000009f39AAA 
 Package Id                     0Ho8d0000008OcSCAU 
 Version                        55.0.0.3
 Description
 Branch
 Tag
 Released                       false
 Validation Skipped             false
 Ancestor                       N/A
 Ancestor Version               N/A
 Code Coverage                  98%
 Code Coverage Met              true
 Org-Dependent Unlocked Package No
 Release Version                56.0
 Build Duration in Seconds      104
 Managed Metadata Removed       N/A
 Created By                     005w00000054XxoAAE

And the beta equivalent:
sfdx force:package:beta:version:create -p DreamhouseLWC -k DreamhouseLWC -w 15 --codecoverage
Also runs as expected and running a report on the package show codecoverage values:

=== Package Version

 Name                           Value
 ────────────────────────────── ────────────────── 
 Name                           Summer '22
 Subscriber Package Version Id  04t8d0000009f3EAAQ 
 Package Id                     0Ho8d0000008OcSCAU 
 Version                        55.0.0.4
 Description
 Branch
 Tag
 Released                       false
 Validation Skipped             false
 Ancestor                       N/A
 Ancestor Version               N/A
 Code Coverage                  98%
 Code Coverage Met              true
 Org-Dependent Unlocked Package No
 Release Version                56.0
 Build Duration in Seconds      109.0
 Managed Metadata Removed       N/A
 Created By                     005w00000054XxoAAE

Thank you very much for resolving this issue. Keep up the excellent work, and let me know if I can do anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue or pull request that identifies or fixes a bug
Projects
None yet
Development

No branches or pull requests

4 participants