-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add a did you mean action to AuthInfo
- Loading branch information
1 parent
f8876d8
commit f7328a2
Showing
6 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import Levenshtein from 'fast-levenshtein'; | ||
|
||
/** | ||
* From the haystack, will find the closest value to the needle | ||
* | ||
* @param needle - what the user provided - find results similar to this | ||
* @param haystack - possible results to search against | ||
*/ | ||
export const findSuggestion = (needle: string, haystack: string[]): string => { | ||
// we'll use this array to keep track of which piece of hay is the closest to the users entered value. | ||
// keys closer to the index 0 will be a closer guess than keys indexed further from 0 | ||
// an entry at 0 would be a direct match, an entry at 1 would be a single character off, etc. | ||
const index: string[] = []; | ||
haystack.map((hay) => { | ||
index[Levenshtein.get(needle, hay)] = hay; | ||
}); | ||
|
||
return index.find((item) => item !== undefined) ?? ''; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ import { OrgAccessor } from '../../../src/stateAggregator/accessors/orgAccessor' | |
import { Crypto } from '../../../src/crypto/crypto'; | ||
import { Config } from '../../../src/config/config'; | ||
import { SfdcUrl } from '../../../src/util/sfdcUrl'; | ||
import * as suggestion from '../../../src/util/findSuggestion'; | ||
import { SfError } from '../../../src'; | ||
|
||
class AuthInfoMockOrg extends MockTestOrgData { | ||
public privateKey = 'authInfoTest/jwt/server.key'; | ||
|
@@ -2083,11 +2085,16 @@ describe('AuthInfo No fs mock', () => { | |
|
||
it('invalid devhub username', async () => { | ||
const expectedErrorName = 'NamedOrgNotFoundError'; | ||
stubMethod($$.SANDBOX, suggestion, 'findSuggestion').returns('[email protected]'); | ||
try { | ||
await shouldThrow(AuthInfo.create({ username: '[email protected]', isDevHub: true })); | ||
} catch (e) { | ||
expect(e).to.have.property('name', expectedErrorName); | ||
expect(e).to.have.property('message', 'No authorization information found for [email protected].'); | ||
expect(e).to.have.property('actions'); | ||
expect((e as SfError).actions).to.deep.equal([ | ||
'It looks like you mistyped the username or alias. Did you mean "[email protected]"?', | ||
]); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { expect } from 'chai'; | ||
import { findSuggestion } from '../../../src/util/findSuggestion'; | ||
|
||
describe('findSuggestion Unit Tests', () => { | ||
it('will find one suggestion', () => { | ||
const res = findSuggestion('needl', ['haystack', 'needle']); | ||
expect(res).to.equal('needle'); | ||
}); | ||
|
||
it('will return empty string when no haystack', () => { | ||
const res = findSuggestion('needl', []); | ||
expect(res).to.equal(''); | ||
}); | ||
|
||
it('will return last closest result', () => { | ||
// j-k-l-m-n | ||
// 'needl' should be right between 'needk' and 'needm' - but we found 'needm' last, which overwrites 'needk' | ||
const res = findSuggestion('needl', ['needk', 'needm']); | ||
expect(res).to.equal('needm'); | ||
}); | ||
|
||
it('will find closest result', () => { | ||
const res = findSuggestion('a', ['z', 'x', 'y']); | ||
expect(res).to.equal('y'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f7328a2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger Benchmarks - ubuntu-latest
Child logger creation
465974
ops/sec (±1.80%
)467835
ops/sec (±1.60%
)1.00
Logging a string on root logger
774476
ops/sec (±11.99%
)774722
ops/sec (±10.63%
)1.00
Logging an object on root logger
568889
ops/sec (±8.05%
)588904
ops/sec (±7.92%
)1.04
Logging an object with a message on root logger
7208
ops/sec (±204.90%
)4189
ops/sec (±217.41%
)0.58
Logging an object with a redacted prop on root logger
384994
ops/sec (±12.95%
)507288
ops/sec (±8.26%
)1.32
Logging a nested 3-level object on root logger
374888
ops/sec (±6.98%
)377042
ops/sec (±6.48%
)1.01
This comment was automatically generated by workflow using github-action-benchmark.
f7328a2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger Benchmarks - windows-latest
Child logger creation
328651
ops/sec (±1.10%
)324884
ops/sec (±1.12%
)0.99
Logging a string on root logger
867117
ops/sec (±4.46%
)699770
ops/sec (±5.36%
)0.81
Logging an object on root logger
575272
ops/sec (±5.87%
)613094
ops/sec (±5.76%
)1.07
Logging an object with a message on root logger
3522
ops/sec (±220.49%
)8108
ops/sec (±200.19%
)2.30
Logging an object with a redacted prop on root logger
462524
ops/sec (±6.80%
)459854
ops/sec (±7.39%
)0.99
Logging a nested 3-level object on root logger
323712
ops/sec (±4.96%
)321072
ops/sec (±4.45%
)0.99
This comment was automatically generated by workflow using github-action-benchmark.
f7328a2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.Logging an object with a message on root logger
3522
ops/sec (±220.49%
)8108
ops/sec (±200.19%
)2.30
This comment was automatically generated by workflow using github-action-benchmark.