Skip to content

Commit

Permalink
fix: change mdcoverage url for getCurrentApiVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Dec 12, 2023
1 parent 1e8be82 commit 8616e0c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
9 changes: 9 additions & 0 deletions messages/sdr.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ A StaticResource must have an associated .resource file, missing %s.resource-met

The %s operation is missing a job ID. Initialize an operation with an ID, or start a new job.

# missingApiVersion

Could not determine an API version to use for the set of metadata components.

# missingApiVersion.actions

Set a `sourceApiVersion` or `apiVersion` on the ComponentSet.
Set an API version to use with the environment variable, `SF_ORG_API_VERSION`.

# invalid_xml_parsing

error parsing %s due to:\n message: %s\n line: %s\n code: %s
Expand Down
12 changes: 11 additions & 1 deletion src/collections/componentSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,17 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
* @returns Object representation of a package manifest
*/
public async getObject(destructiveType?: DestructiveChangesType): Promise<PackageManifestObject> {
const version = this.sourceApiVersion ?? this.apiVersion ?? `${await getCurrentApiVersion()}.0`;
let version: string;
try {
version =
this.sourceApiVersion ??
this.apiVersion ??
process.env.SF_ORG_API_VERSION ??
`${await getCurrentApiVersion()}.0`;
} catch (err: unknown) {
const cause = err instanceof Error ? err : isString(err) ? Error(err) : undefined;
throw messages.createError('missingApiVersion', undefined, undefined, 1, cause);
}

// If this ComponentSet has components marked for delete, we need to
// only include those components in a destructiveChanges.xml and
Expand Down
2 changes: 1 addition & 1 deletion src/registry/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const getProxiedOptions = (url: string): OptionsOfTextResponseBody => ({

export const getCurrentApiVersion = async (): Promise<number> =>
(
await got(getProxiedOptions('https://mdcoverage.secure.force.com/services/apexrest/report')).json<{
await got(getProxiedOptions('https://dx-extended-coverage.my.salesforce-sites.com/services/apexrest/report')).json<{
versions: { selected: number };
}>()
).versions.selected;
Expand Down
62 changes: 60 additions & 2 deletions test/collections/componentSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { join } from 'node:path';
import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup';
import { assert, expect } from 'chai';
import { SinonStub } from 'sinon';
import { AuthInfo, ConfigAggregator, Connection, Lifecycle, Messages } from '@salesforce/core';
import { AuthInfo, ConfigAggregator, Connection, Lifecycle, Messages, SfError } from '@salesforce/core';
import {
ComponentSet,
ComponentSetBuilder,
Expand Down Expand Up @@ -676,8 +676,18 @@ describe('ComponentSet', () => {
});

describe('getObject', () => {
const sfOrgApiVersion = process.env.SF_ORG_API_VERSION;
let getCurrentApiVersionStub: SinonStub;

beforeEach(() => {
$$.SANDBOX.stub(coverage, 'getCurrentApiVersion').resolves(testApiVersion);
getCurrentApiVersionStub = $$.SANDBOX.stub(coverage, 'getCurrentApiVersion').resolves(testApiVersion);
});

afterEach(() => {
process.env.SF_ORG_API_VERSION = sfOrgApiVersion;
if (!sfOrgApiVersion) {
delete process.env.SF_ORG_API_VERSION;
}
});

it('should return an object representing the package manifest', async () => {
Expand All @@ -701,6 +711,7 @@ describe('ComponentSet', () => {
version: testApiVersionAsString,
},
});
expect(getCurrentApiVersionStub.calledOnce).to.be.true;
});

it('should allow the componentSet to set the apiVersion', async () => {
Expand All @@ -725,6 +736,52 @@ describe('ComponentSet', () => {
version: testApiVersionAsString,
},
});
expect(getCurrentApiVersionStub.called).to.be.false;
});

it('should get an API version from env var', async () => {
const set = ComponentSet.fromSource({
fsPaths: ['.'],
registry: registryAccess,
tree: manifestFiles.TREE,
});
process.env.SF_ORG_API_VERSION = testApiVersionAsString;
expect(await set.getObject()).to.deep.equal({
Package: {
types: [
{
name: registry.types.customobjecttranslation.name,
members: ['a'],
},
{
name: registry.types.staticresource.name,
members: ['b', 'c'],
},
],
version: testApiVersionAsString,
},
});
expect(getCurrentApiVersionStub.called).to.be.false;
});

it('should throw an error when API version is missing', async () => {
getCurrentApiVersionStub.reset();
const causeErr = new Error('HTTP 404 - mdcoverage url is down');
getCurrentApiVersionStub.throws(causeErr);
const set = ComponentSet.fromSource({
fsPaths: ['.'],
registry: registryAccess,
tree: manifestFiles.TREE,
});
try {
await set.getObject();
expect(true, 'Expected an error to be thrown from getObject()').to.be.false;
} catch (err: unknown) {
expect(err).to.be.instanceOf(SfError);
const error = err as SfError;
expect(error.name).to.equal('MissingApiVersionError');
expect(error.cause).to.equal(causeErr);
}
});

it('should return an object representing destructive changes manifest', async () => {
Expand Down Expand Up @@ -798,6 +855,7 @@ describe('ComponentSet', () => {
version: set.sourceApiVersion,
},
});
expect(getCurrentApiVersionStub.called).to.be.false;
});

it('should interpret folder components as members of the type they are a container for', async () => {
Expand Down

2 comments on commit 8616e0c

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 8616e0c Previous: ec11f4e Ratio
eda-componentSetCreate-linux 216 ms 215 ms 1.00
eda-sourceToMdapi-linux 4482 ms 4634 ms 0.97
eda-sourceToZip-linux 4268 ms 4298 ms 0.99
eda-mdapiToSource-linux 3097 ms 2927 ms 1.06
lotsOfClasses-componentSetCreate-linux 360 ms 374 ms 0.96
lotsOfClasses-sourceToMdapi-linux 5726 ms 5964 ms 0.96
lotsOfClasses-sourceToZip-linux 4984 ms 5290 ms 0.94
lotsOfClasses-mdapiToSource-linux 3415 ms 3395 ms 1.01
lotsOfClassesOneDir-componentSetCreate-linux 637 ms 645 ms 0.99
lotsOfClassesOneDir-sourceToMdapi-linux 8573 ms 8449 ms 1.01
lotsOfClassesOneDir-sourceToZip-linux 7202 ms 7909 ms 0.91
lotsOfClassesOneDir-mdapiToSource-linux 6119 ms 6032 ms 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 8616e0c Previous: ec11f4e Ratio
eda-componentSetCreate-win32 402 ms 413 ms 0.97
eda-sourceToMdapi-win32 6045 ms 6735 ms 0.90
eda-sourceToZip-win32 5602 ms 5713 ms 0.98
eda-mdapiToSource-win32 6016 ms 5685 ms 1.06
lotsOfClasses-componentSetCreate-win32 861 ms 915 ms 0.94
lotsOfClasses-sourceToMdapi-win32 10462 ms 10782 ms 0.97
lotsOfClasses-sourceToZip-win32 7408 ms 7915 ms 0.94
lotsOfClasses-mdapiToSource-win32 7323 ms 7338 ms 1.00
lotsOfClassesOneDir-componentSetCreate-win32 1506 ms 1495 ms 1.01
lotsOfClassesOneDir-sourceToMdapi-win32 16148 ms 16851 ms 0.96
lotsOfClassesOneDir-sourceToZip-win32 10785 ms 11387 ms 0.95
lotsOfClassesOneDir-mdapiToSource-win32 13540 ms 13521 ms 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.