Skip to content

Commit

Permalink
fix: query devhubs, non-scratch orgs, and non-sandboxes to identify s…
Browse files Browse the repository at this point in the history
…andboxes
  • Loading branch information
shetzel committed Aug 2, 2023
1 parent 9bf4154 commit 26d923e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 49 deletions.
9 changes: 4 additions & 5 deletions src/org/authInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ export class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
// TODO: someday we make this easier by asking the org if it is a scratch org

const hubAuthInfos = await AuthInfo.getDevHubAuthInfos();
// Get a list of org auths that are known not to be devhubs, scratch orgs, or sandboxes.
// Get a list of org auths that are known not to be scratch orgs or sandboxes.
const possibleProdOrgs = await AuthInfo.listAllAuthorizations(
(orgAuth) => orgAuth && !orgAuth.isDevHub && !orgAuth.isScratchOrg && !orgAuth.isSandbox
(orgAuth) => orgAuth && !orgAuth.isScratchOrg && !orgAuth.isSandbox
);

logger.debug(`found ${hubAuthInfos.length} DevHubs`);
Expand Down Expand Up @@ -435,9 +435,8 @@ export class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
logger.debug(`error updating auth file for ${orgAuthInfo.getUsername()}`, error);
}
} catch (error) {
if (error instanceof Error && error.name === 'SingleRecordQuery_NoRecords' && fields.orgId) {
// Not a scratch org owned by this hub. Check if it's a sandbox.
await AuthInfo.identifyPossibleSandbox(hubAuthInfo, fields, orgAuthInfo, logger);
if (error instanceof Error && error.name === 'NoActiveScratchOrgFound') {
logger.error(`devhub ${hubAuthInfo.username} has no scratch orgs`, error);
} else {
logger.error(`Error connecting to devhub ${hubAuthInfo.username}`, error);
}
Expand Down
44 changes: 0 additions & 44 deletions test/unit/org/authInfoTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1869,50 +1869,6 @@ describe('AuthInfo', () => {
expect(authInfoSaveStub.callCount).to.be.equal(1);
});

it('should update auth file as a sandbox from devhub', async () => {
adminTestData.makeDevHub();

await $$.stubAuths(adminTestData, user1);

const authInfo = await AuthInfo.create({
username: user1.username,
});

const stateAggregator = await StateAggregator.getInstance();
const stateAggregatorStub = stubMethod($$.SANDBOX, StateAggregator, 'getInstance');
const sandboxSetStub = stubMethod($$.SANDBOX, stateAggregator.sandboxes, 'set');
const sandboxWriteStub = stubMethod($$.SANDBOX, stateAggregator.sandboxes, 'write');
stateAggregatorStub.resolves(stateAggregator);
const devhubAuths = await AuthInfo.getDevHubAuthInfos();
stubMethod($$.SANDBOX, AuthInfo, 'getDevHubAuthInfos').resolves(devhubAuths);
stubMethod($$.SANDBOX, AuthInfo, 'listAllAuthorizations').resolves([]);
const authInfoSaveStub = stubMethod($$.SANDBOX, AuthInfo.prototype, 'save').resolves();
const queryScratchOrgStub = stubMethod($$.SANDBOX, AuthInfo, 'queryScratchOrg');
const queryScratchOrgError = new Error('not a scratch org');
queryScratchOrgError.name = 'SingleRecordQuery_NoRecords';
queryScratchOrgStub.throws(queryScratchOrgError);
const sbxQueryStub = stubMethod($$.SANDBOX, Org.prototype, 'querySandboxProcessByOrgId');
sbxQueryStub.resolves({
Id: '0GRB0000000L0ZVOA0',
Status: 'Completed',
SandboxName: 'TestSandbox',
SandboxInfoId: '0GQB0000000PCOdOAO',
LicenseType: 'DEVELOPER',
CreatedDate: '2021-01-22T22:49:52.000+0000',
});

await AuthInfo.identifyPossibleScratchOrgs(authInfo.getFields(), authInfo);

expect(authInfoSaveStub.callCount).to.be.equal(2);
expect(authInfoSaveStub.secondCall.args[0]).to.have.property('isSandbox', true);
expect(authInfoSaveStub.secondCall.args[0]).to.have.property('isScratch', false);
expect(sandboxSetStub.calledOnce).to.be.true;
expect(sandboxSetStub.firstCall.args[0]).to.equal(authInfo.getFields().orgId);
expect(sandboxSetStub.firstCall.args[1]).to.have.property('prodOrgUsername', adminTestData.username);
expect(sandboxWriteStub.calledOnce).to.be.true;
expect(sandboxWriteStub.firstCall.args[0]).to.equal(authInfo.getFields().orgId);
});

it('should update auth file as a sandbox from possible prod orgs', async () => {
adminTestData.makeDevHub();

Expand Down

4 comments on commit 26d923e

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 26d923e Previous: 9bf4154 Ratio
Child logger creation 556565 ops/sec (±0.20%) 373898 ops/sec (±44.29%) 0.67
Logging a string on root logger 646418 ops/sec (±4.95%) 553360 ops/sec (±13.70%) 0.86
Logging an object on root logger 459432 ops/sec (±12.11%) 328425 ops/sec (±17.70%) 0.71
Logging an object with a message on root logger 303026 ops/sec (±12.81%) 177367 ops/sec (±21.77%) 0.59
Logging an object with a redacted prop on root logger 4571 ops/sec (±223.38%) 212480 ops/sec (±20.24%) 46.48
Logging a nested 3-level object on root logger 238371 ops/sec (±26.10%) 143529 ops/sec (±19.27%) 0.60

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

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 26d923e Previous: 9bf4154 Ratio
Logging an object with a redacted prop on root logger 4571 ops/sec (±223.38%) 212480 ops/sec (±20.24%) 46.48

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

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Logger Benchmarks - windows-latest

Benchmark suite Current: 26d923e Previous: 9bf4154 Ratio
Child logger creation 408780 ops/sec (±6.92%) 438437 ops/sec (±1.88%) 1.07
Logging a string on root logger 494339 ops/sec (±11.00%) 593182 ops/sec (±16.67%) 1.20
Logging an object on root logger 394945 ops/sec (±16.56%) 353048 ops/sec (±22.10%) 0.89
Logging an object with a message on root logger 278591 ops/sec (±19.76%) 178322 ops/sec (±22.45%) 0.64
Logging an object with a redacted prop on root logger 8166 ops/sec (±190.88%) 214519 ops/sec (±23.88%) 26.27
Logging a nested 3-level object on root logger 190891 ops/sec (±21.38%) 126244 ops/sec (±21.91%) 0.66

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

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - windows-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 26d923e Previous: 9bf4154 Ratio
Logging an object with a redacted prop on root logger 8166 ops/sec (±190.88%) 214519 ops/sec (±23.88%) 26.27

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

Please sign in to comment.