Skip to content

Commit 746c061

Browse files
committed
test: dev-zip flag test on managed package
chore: update snapshot chore: add flag in correct place of command-snapshot chore: correct placement of flag chore: move flag to version:create flags chore: update docs from TW feedback chore: remove description prop from flag test: nut for create version with flag and md retrieve test: use packageId instead of name for version creation test: try NUTS again after packaging changes merged test: use existing managed package for --generate-pkg-zip test chore: update dependencies test: establish auth with TestSession first test: add debugging log to see if flag set on request test: fix package name for CI dh
1 parent 78d6158 commit 746c061

5 files changed

Lines changed: 142 additions & 12 deletions

File tree

command-snapshot.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@
432432
"version-description",
433433
"version-name",
434434
"version-number",
435-
"wait"
435+
"wait",
436+
"generate-pkg-zip"
436437
],
437438
"plugin": "@salesforce/plugin-packaging"
438439
},

messages/package_version_create.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,11 @@ Specifying async validation returns the package version earlier in the process,
147147

148148
# flags.generate-pkg-zip.summary
149149

150-
Request the package zip file for development use.
151-
152-
# flags.generate-pkg-zip.description
153-
154-
When set to true, generates a package zip file for development use. This file can be used for debugging or examining the package contents.
150+
Generate a package ZIP file that you can use for debugging or to examine the package contents.
155151

156152
# flags.skip-ancestor-check.summary
157153

158-
Overrides ancestry requirements, which allows you to specify a package ancestor that isn’t the highest released package version.
154+
Override ancestry requirements, which allows you to specify a package ancestor that isn’t the highest released package version.
159155

160156
# flags.post-install-url.summary
161157

src/commands/package/version/create.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ export class PackageVersionCreateCommand extends SfCommand<PackageVersionCommand
144144
}),
145145
'generate-pkg-zip': Flags.boolean({
146146
summary: messages.getMessage('flags.generate-pkg-zip.summary'),
147-
description: messages.getMessage('flags.generate-pkg-zip.description'),
148147
default: false,
149148
}),
150149
tag: Flags.string({
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright 2026, Salesforce, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import * as fs from 'node:fs';
17+
import * as path from 'node:path';
18+
import { expect } from 'chai';
19+
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
20+
import { Org, SfProject } from '@salesforce/core';
21+
import { Duration } from '@salesforce/kit';
22+
import { PackageVersionCreateRequestResult } from '@salesforce/packaging';
23+
import { FileDownloadEntry } from '../../../src/commands/package/version/retrieve.js';
24+
25+
let packageName: string;
26+
let devHubOrg: Org;
27+
28+
describe('package:version:create with managed package (--generate-pkg-zip)', () => {
29+
let session: TestSession;
30+
let managedPackageId: string;
31+
32+
before('setup managed package', async function () {
33+
this.timeout(Duration.minutes(5).milliseconds);
34+
35+
session = await TestSession.create({
36+
devhubAuthStrategy: 'AUTO',
37+
project: { name: 'managed-pkg-test' },
38+
});
39+
40+
devHubOrg = await Org.create({ aliasOrUsername: session.hubOrg.username });
41+
42+
// Query for existing managed package
43+
const existingPkgQuery = `
44+
SELECT Id, Name, NamespacePrefix
45+
FROM Package2
46+
WHERE ContainerOptions = 'Managed'
47+
AND IsDeprecated = false
48+
AND Name = 'pnhmanaged'
49+
LIMIT 1
50+
`;
51+
const existingPkgRecords = (
52+
await devHubOrg
53+
.getConnection()
54+
.tooling.query<{ Id: string; Name: string; NamespacePrefix: string }>(existingPkgQuery)
55+
).records;
56+
57+
managedPackageId = existingPkgRecords[0].Id;
58+
59+
// Create minimal source structure for a custom object
60+
const objectName = 'TestObject__c';
61+
const objectDir = path.join(session.project.dir, 'force-app', 'main', 'default', 'objects', objectName);
62+
fs.mkdirSync(objectDir, { recursive: true });
63+
64+
fs.writeFileSync(
65+
path.join(objectDir, `${objectName}.object-meta.xml`),
66+
`<?xml version="1.0" encoding="UTF-8"?>
67+
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
68+
<deploymentStatus>Deployed</deploymentStatus>
69+
<label>Test Object</label>
70+
<nameField>
71+
<label>Test Object Name</label>
72+
<type>Text</type>
73+
</nameField>
74+
<pluralLabel>Test Objects</pluralLabel>
75+
<sharingModel>ReadWrite</sharingModel>
76+
</CustomObject>`
77+
);
78+
79+
// Configure the project for the managed package
80+
const project = await SfProject.resolve(session.project.dir);
81+
const projectJson = project.getSfProjectJson();
82+
const namespacePrefix = existingPkgRecords[0].NamespacePrefix;
83+
packageName = existingPkgRecords[0].Name;
84+
85+
const packageDirectory = {
86+
path: 'force-app',
87+
package: existingPkgRecords[0].Name,
88+
versionNumber: '1.0.0.NEXT',
89+
ancestorVersion: 'NONE',
90+
versionName: 'v1',
91+
default: true,
92+
};
93+
94+
projectJson.set('packageDirectories', [packageDirectory]);
95+
projectJson.set('packageAliases', { [packageName]: managedPackageId });
96+
projectJson.set('namespace', namespacePrefix);
97+
projectJson.writeSync();
98+
});
99+
100+
after(async () => {
101+
await session?.clean();
102+
});
103+
104+
it('should create a managed package version with --generate-pkg-zip flag and retrieve the metadata', async function () {
105+
this.timeout(Duration.minutes(25).milliseconds);
106+
107+
const createResult = execCmd<PackageVersionCreateRequestResult>(
108+
`package:version:create --package ${packageName} --wait 20 -x --generate-pkg-zip --version-description "Test pkg zip" --json --skip-ancestor-check`,
109+
{ ensureExitCode: 0, timeout: Duration.minutes(20).milliseconds }
110+
).jsonOutput?.result;
111+
112+
// Debug: verify the flag was actually set
113+
const pvcRequestId = createResult?.Id;
114+
const verifyQuery = `SELECT Id, IsDevUsePkgZipRequested FROM Package2VersionCreateRequest WHERE Id = '${pvcRequestId}'`;
115+
const verifyResult = await devHubOrg
116+
.getConnection()
117+
.tooling.query<{ Id: string; IsDevUsePkgZipRequested: boolean }>(verifyQuery);
118+
// eslint-disable-next-line no-console
119+
console.log('IsDevUsePkgZipRequested:', verifyResult.records[0]?.IsDevUsePkgZipRequested);
120+
121+
expect(createResult?.Status).to.equal('Success');
122+
const subscriberPkgVersionId = createResult?.SubscriberPackageVersionId;
123+
expect(subscriberPkgVersionId).to.match(/04t.{15}/);
124+
125+
const retrieveOutputDir = 'pkg-zip-test-output';
126+
const retrieveResult = execCmd<FileDownloadEntry[]>(
127+
`package:version:retrieve --package ${subscriberPkgVersionId} --output-dir ${retrieveOutputDir} --json`,
128+
{ ensureExitCode: 0 }
129+
).jsonOutput?.result;
130+
131+
expect(retrieveResult).to.be.an('array');
132+
expect(retrieveResult?.length).to.be.greaterThan(0);
133+
});
134+
});

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,16 +2023,16 @@
20232023
terminal-link "^3.0.0"
20242024

20252025
"@salesforce/source-deploy-retrieve@^12.31.9":
2026-
version "12.31.10"
2027-
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-12.31.10.tgz#612886356d81c87eb9053bbc9173546556fd5f36"
2028-
integrity sha512-kUdJicJUd3/lzNQOvDW1Sc5iBl8PVv2Tz7L59YA/Le0fzZCYM72oyKwdbl/f6kc+MzJpMVia2+AxrvVZir8oJw==
2026+
version "12.31.9"
2027+
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-12.31.9.tgz#69592e0b1564157fce8b7c66b33412460fa62b6e"
2028+
integrity sha512-UVRmLVl+Es1jLGnSx4G2xxTNHR7L6v5uzOpBFbg1ADMOQ4b1v8cDwZO9noJa9xAG+MLJJ7zDkcqywgFxU/3mmQ==
20292029
dependencies:
20302030
"@salesforce/core" "^8.24.0"
20312031
"@salesforce/kit" "^3.2.4"
20322032
"@salesforce/ts-types" "^2.0.12"
20332033
"@salesforce/types" "^1.6.0"
20342034
fast-levenshtein "^3.0.0"
2035-
fast-xml-parser "^5.3.4"
2035+
fast-xml-parser "^4.5.3"
20362036
got "^11.8.6"
20372037
graceful-fs "^4.2.11"
20382038
ignore "^5.3.2"

0 commit comments

Comments
 (0)