Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sm/crdt-config
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 9, 2023
2 parents 5562a3d + b3c1d6b commit a702f2b
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 59 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## [5.3.19](https://github.com/forcedotcom/sfdx-core/compare/5.3.18...5.3.19) (2023-11-08)

### Bug Fixes

- use memory logger instance when disabled ([c2ef3a0](https://github.com/forcedotcom/sfdx-core/commit/c2ef3a0f8fea0518b5eec2f6f515064e9741b46e))

## [5.3.18](https://github.com/forcedotcom/sfdx-core/compare/5.3.17...5.3.18) (2023-11-05)

### Bug Fixes

- **deps:** bump @types/semver from 7.5.3 to 7.5.4 ([a3be392](https://github.com/forcedotcom/sfdx-core/commit/a3be3922f96f8420eb871c413858eac395a95ad3))

## [5.3.17](https://github.com/forcedotcom/sfdx-core/compare/5.3.16...5.3.17) (2023-11-02)

### Bug Fixes

- **deps:** testSetup has non ts-sinon dependency ([9fcb206](https://github.com/forcedotcom/sfdx-core/commit/9fcb206220174af1c20fcc041e127409a41c3593))

## [5.3.16](https://github.com/forcedotcom/sfdx-core/compare/5.3.15...5.3.16) (2023-10-29)

### Bug Fixes
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@salesforce/kit": "^3.0.15",
"@salesforce/schemas": "^1.6.1",
"@salesforce/ts-types": "^2.0.9",
"@types/semver": "^7.5.3",
"@types/semver": "^7.5.4",
"ajv": "^8.12.0",
"change-case": "^4.1.2",
"faye": "^1.4.0",
Expand All @@ -64,7 +64,7 @@
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "^1.4.18",
"@types/benchmark": "^2.1.3",
"@types/chai-string": "^1.4.3",
"@types/chai-string": "^1.4.4",
"@types/jsonwebtoken": "9.0.3",
"@types/lodash": "^4.14.200",
"@types/proper-lockfile": "^4.1.2",
Expand All @@ -74,7 +74,7 @@
"benchmark": "^2.1.4",
"chai": "^4.3.10",
"chai-string": "^1.5.0",
"eslint": "^8.52.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-salesforce": "^2.0.2",
"eslint-config-salesforce-license": "^0.2.0",
Expand Down
6 changes: 4 additions & 2 deletions src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export class Logger {
* `Logger`.
*/
public constructor(optionsOrName: LoggerOptions | string) {
const enabled = process.env.SFDX_DISABLE_LOG_FILE !== 'true' && process.env.SF_DISABLE_LOG_FILE !== 'true';

const options: LoggerOptions =
typeof optionsOrName === 'string'
? { name: optionsOrName, level: Logger.DEFAULT_LEVEL, fields: {} }
Expand All @@ -167,9 +169,9 @@ export class Logger {
name: options.name ?? Logger.ROOT_NAME,
base: options.fields ?? {},
level,
enabled: process.env.SFDX_DISABLE_LOG_FILE !== 'true' && process.env.SF_DISABLE_LOG_FILE !== 'true',
enabled,
};
if (options.useMemoryLogger || Global.getEnvironmentMode() === Mode.TEST) {
if (options.useMemoryLogger || Global.getEnvironmentMode() === Mode.TEST || !enabled) {
this.memoryLogger = new MemoryLogger();
this.pinoLogger = pino(
{
Expand Down
73 changes: 41 additions & 32 deletions src/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { tmpdir as osTmpdir } from 'os';
import { basename, join as pathJoin, dirname } from 'path';
import { SinonSandbox, SinonStatic, SinonStub } from 'sinon';

import { stubMethod } from '@salesforce/ts-sinon';
import {
AnyFunction,
AnyJson,
Expand Down Expand Up @@ -290,9 +289,12 @@ export class TestContext {
);
const orgMap = new Map(entries);

stubMethod(this.SANDBOX, OrgAccessor.prototype, 'getAllFiles').resolves([...orgMap.keys()].map((o) => `${o}.json`));
// @ts-expect-error because private method
this.SANDBOX.stub(OrgAccessor.prototype, 'getAllFiles').resolves([...orgMap.keys()].map((o) => `${o}.json`));

stubMethod(this.SANDBOX, OrgAccessor.prototype, 'hasFile').callsFake((username: string) => orgMap.has(username));
this.SANDBOX.stub(OrgAccessor.prototype, 'hasFile').callsFake((username: string) =>
Promise.resolve(orgMap.has(username))
);

const retrieveContents = async function (this: { path: string }): Promise<AuthFields> {
const username = basename(this.path.replace('.json', ''));
Expand Down Expand Up @@ -337,9 +339,11 @@ export class TestContext {
})
);

stubMethod(this.SANDBOX, User.prototype, 'retrieve').callsFake(
(username): Promise<UserFields | undefined> => Promise.resolve(mockUsers.find((org) => org.username === username))
);
this.SANDBOX.stub(User.prototype, 'retrieve').callsFake((username): Promise<UserFields> => {
const user = mockUsers.find((org) => org.username === username);
if (!user) throw new SfError('User not found', 'UserNotFoundError');
return Promise.resolve(user);
});

const retrieveContents = async function (this: { path: string }): Promise<{ usernames?: string[] }> {
const orgId = basename(this.path.replace('.json', ''));
Expand All @@ -358,7 +362,8 @@ export class TestContext {
)) as Array<[string, SandboxFields]>;
const sandboxMap = new Map(entries);

stubMethod(this.SANDBOX, SandboxAccessor.prototype, 'getAllFiles').resolves(
// @ts-expect-error because private method
this.SANDBOX.stub(SandboxAccessor.prototype, 'getAllFiles').resolves(
[...sandboxMap.keys()].map((o) => `${o}.sandbox.json`)
);

Expand Down Expand Up @@ -501,8 +506,8 @@ export const stubContext = (testContext: TestContext): Record<string, SinonStub>
const stubs: Record<string, SinonStub> = {};

// Most core files create a child logger so stub this to return our test logger.
stubMethod(testContext.SANDBOX, Logger, 'child').resolves(testContext.TEST_LOGGER);
stubMethod(testContext.SANDBOX, Logger, 'childFromRoot').returns(testContext.TEST_LOGGER);
testContext.SANDBOX.stub(Logger, 'child').resolves(testContext.TEST_LOGGER);
testContext.SANDBOX.stub(Logger, 'childFromRoot').returns(testContext.TEST_LOGGER);
testContext.inProject(true);
testContext.SANDBOXES.CONFIG.stub(ConfigFile, 'resolveRootFolder').callsFake((isGlobal: boolean) =>
testContext.rootPathRetriever(isGlobal, testContext.id)
Expand All @@ -511,7 +516,8 @@ export const stubContext = (testContext: TestContext): Record<string, SinonStub>
testContext.rootPathRetrieverSync(isGlobal, testContext.id)
);

stubMethod(testContext.SANDBOXES.PROJECT, SfProjectJson.prototype, 'doesPackageExist').callsFake(() => true);
// @ts-expect-error using private method
testContext.SANDBOXES.PROJECT.stub(SfProjectJson.prototype, 'doesPackageExist').callsFake(() => true);

const initStubForRead = (configFile: ConfigFile<ConfigFile.Options>): ConfigStub => {
testContext.configStubs[configFile.constructor.name] ??= {};
Expand Down Expand Up @@ -568,23 +574,24 @@ export const stubContext = (testContext: TestContext): Record<string, SinonStub>
writeSync.call(this);
};

stubs.configWriteSync = stubMethod(testContext.SANDBOXES.CONFIG, ConfigFile.prototype, 'writeSync').callsFake(
writeSync
);
stubs.configWriteSync = testContext.SANDBOXES.CONFIG.stub(ConfigFile.prototype, 'writeSync').callsFake(writeSync);

stubs.configWrite = stubMethod(testContext.SANDBOXES.CONFIG, ConfigFile.prototype, 'write').callsFake(write);
stubs.configWrite = testContext.SANDBOXES.CONFIG.stub(ConfigFile.prototype, 'write').callsFake(write);

stubMethod(testContext.SANDBOXES.CRYPTO, Crypto.prototype, 'getKeyChain').callsFake(() =>
// @ts-expect-error: getKeyChain is private
testContext.SANDBOXES.CRYPTO.stub(Crypto.prototype, 'getKeyChain').callsFake(() =>
// @ts-expect-error: not the full type
Promise.resolve({
setPassword: () => Promise.resolve(),
getPassword: (data: Record<string, unknown>, cb: AnyFunction) =>
cb(undefined, '12345678901234567890123456789012'),
})
);

stubMethod(testContext.SANDBOXES.CONNECTION, Connection.prototype, 'isResolvable').resolves(true);
testContext.SANDBOXES.CONNECTION.stub(Connection.prototype, 'isResolvable').resolves(true);

stubMethod(testContext.SANDBOXES.CONNECTION, Connection.prototype, 'request').callsFake(function (
// @ts-expect-error: just enough of an httpResponse for testing
testContext.SANDBOXES.CONNECTION.stub(Connection.prototype, 'request').callsFake(function (
this: Connection,
request: string,
options?: Dictionary
Expand All @@ -595,23 +602,25 @@ export const stubContext = (testContext: TestContext): Record<string, SinonStub>
return testContext.fakeConnectionRequest.call(this, request, options as AnyJson);
});

stubMethod(testContext.SANDBOX, aliasAccessorEntireFile, 'getFileLocation').returns(getAliasFileLocation());
testContext.SANDBOX.stub(aliasAccessorEntireFile, 'getFileLocation').returns(getAliasFileLocation());

stubs.configExists = stubMethod(testContext.SANDBOXES.ORGS, OrgAccessor.prototype, 'exists').callsFake(
async function (this: OrgAccessor, username: string): Promise<boolean | undefined> {
// @ts-expect-error because private member
if ([...this.contents.keys()].includes(username)) return Promise.resolve(true);
else return Promise.resolve(false);
}
);
stubs.configExists = testContext.SANDBOXES.ORGS.stub(OrgAccessor.prototype, 'exists').callsFake(async function (
this: OrgAccessor,
username: string
): Promise<boolean> {
// @ts-expect-error because private member
if ([...this.contents.keys()].includes(username)) return Promise.resolve(true);
else return Promise.resolve(false);
});

stubs.configRemove = stubMethod(testContext.SANDBOXES.ORGS, OrgAccessor.prototype, 'remove').callsFake(
async function (this: OrgAccessor, username: string): Promise<boolean | undefined> {
// @ts-expect-error because private member
if ([...this.contents.keys()].includes(username)) return Promise.resolve(true);
else return Promise.resolve(false);
}
);
stubs.configRemove = testContext.SANDBOXES.ORGS.stub(OrgAccessor.prototype, 'remove').callsFake(async function (
this: OrgAccessor,
username: string
): Promise<void> {
// @ts-expect-error because private member
if ([...this.contents.keys()].includes(username)) return Promise.resolve();
else return Promise.resolve();
});

// Always start with the default and tests beforeEach or it methods can override it.
testContext.fakeConnectionRequest = defaultFakeConnectionRequest;
Expand Down
17 changes: 17 additions & 0 deletions test/unit/loggerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ describe('Logger', () => {
const logger2 = await Logger.root();
expect(logger2).to.not.equal(logger1);
});

describe('DISABLE_LOG_FILE', () => {
const LOG_FILES_DISABLED = process.env.SF_DISABLE_LOG_FILE;
before(() => {
process.env.SF_DISABLE_LOG_FILE = 'true';
});
after(() => {
process.env.SF_DISABLE_LOG_FILE = LOG_FILES_DISABLED;
});
it('should construct a new named logger', async () => {
const logger1 = new Logger({ name: 'testLogger-noop' });
expect(logger1).to.be.instanceof(Logger);
// @ts-expect-error testing a private property
expect(logger1.memoryLogger).to.be.ok;
expect(logger1.getName()).to.equal('testLogger-noop');
});
});
});

describe('levels', () => {
Expand Down
44 changes: 22 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@
resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.6.2.tgz#1816b5f6948029c5eaacb0703b850ee0cb37d8f8"
integrity sha512-pPTNuaAG3QMH+buKyBIGJs3g/S5y0caxw0ygM3YyE6yJFySwiGGSzA+mM3KJ8QQvzeLh3blwgSonkFjgQdxzMw==

"@eslint/eslintrc@^2.1.2":
version "2.1.2"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.2.tgz#c6936b4b328c64496692f76944e755738be62396"
integrity sha512-+wvgpDsrB1YqAMdEUCcnTlpfVBH7Vqn6A/NT3D8WVXFIaKMlErPIZT3oCIAVCOtarRpMtelZLqJeU3t7WY6X6g==
"@eslint/eslintrc@^2.1.3":
version "2.1.3"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.3.tgz#797470a75fe0fbd5a53350ee715e85e87baff22d"
integrity sha512-yZzuIG+jnVu6hNSzFEN07e8BxF3uAzYtQb6uDkaYZLo6oYZDCq454c5kB8zxnzfCYyP4MIuyBn10L0DqwujTmA==
dependencies:
ajv "^6.12.4"
debug "^4.3.2"
Expand All @@ -407,10 +407,10 @@
minimatch "^3.1.2"
strip-json-comments "^3.1.1"

"@eslint/js@8.52.0":
version "8.52.0"
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.52.0.tgz#78fe5f117840f69dc4a353adf9b9cd926353378c"
integrity sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA==
"@eslint/js@8.53.0":
version "8.53.0"
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.53.0.tgz#bea56f2ed2b5baea164348ff4d5a879f6f81f20d"
integrity sha512-Kn7K8dx/5U6+cT1yEhpX1w4PCSg0M+XyRILPgvwcEBjerFWCwQj5sbr3/VmxqV0JGHCBCzyd6LxypEuehypY1w==

"@humanwhocodes/config-array@^0.11.13":
version "0.11.13"
Expand Down Expand Up @@ -701,10 +701,10 @@
resolved "https://registry.yarnpkg.com/@types/benchmark/-/benchmark-2.1.3.tgz#7f62084640c509d5619ad33f4d4a29be044ecbe2"
integrity sha512-psuUawgwIy/hSjO4AUDiPBJhJx72e3cBL+YzmVK/5ofRJC02R0NmvrSenGRuSmJc++0j95y2T01xKKNz50FGZw==

"@types/chai-string@^1.4.3":
version "1.4.3"
resolved "https://registry.yarnpkg.com/@types/chai-string/-/chai-string-1.4.3.tgz#06e02d74deed77c2bfccccae44ece6e57a8ecedd"
integrity sha512-bLp5xMQ7Ml0fWa05IPpLjIznTkNbuBE3GtRTzKrp0d10IavlBFcu9vXP2liWaXta79unO693q3kuRxD7g2YYGw==
"@types/chai-string@^1.4.4":
version "1.4.4"
resolved "https://registry.yarnpkg.com/@types/chai-string/-/chai-string-1.4.4.tgz#d0f332715d8c5bf890cbd9fa312292637945de31"
integrity sha512-dVLg4ukDw9y2uEtjq9nHV9pSOomguOhW5AxlWxEU7kYU6chZ0xGC1C7YptkCFEinFVoomJ8WCRUfmTipUqOOXw==
dependencies:
"@types/chai" "*"

Expand Down Expand Up @@ -795,10 +795,10 @@
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.2.tgz#ed279a64fa438bb69f2480eda44937912bb7480a"
integrity sha512-XISRgDJ2Tc5q4TRqvgJtzsRkFYNJzZrhTdtMoGVBttwzzQJkPnS3WWTFc7kuDRoPtPakl+T+OfdEUjYJj7Jbow==

"@types/semver@^7.3.12", "@types/semver@^7.5.3":
version "7.5.3"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.3.tgz#9a726e116beb26c24f1ccd6850201e1246122e04"
integrity sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==
"@types/semver@^7.3.12", "@types/semver@^7.5.4":
version "7.5.4"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.4.tgz#0a41252ad431c473158b22f9bfb9a63df7541cff"
integrity sha512-MMzuxN3GdFwskAnb6fz0orFvhfqi752yjaXylr0Rp4oDg5H0Zn1IuyRhDVvYOwAXoJirx2xuS16I3WjxnAIHiQ==

"@types/[email protected]":
version "0.8.13"
Expand Down Expand Up @@ -1991,15 +1991,15 @@ eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800"
integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==

eslint@^8.41.0, eslint@^8.52.0:
version "8.52.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.52.0.tgz#d0cd4a1fac06427a61ef9242b9353f36ea7062fc"
integrity sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg==
eslint@^8.41.0, eslint@^8.53.0:
version "8.53.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.53.0.tgz#14f2c8244298fcae1f46945459577413ba2697ce"
integrity sha512-N4VuiPjXDUa4xVeV/GC/RV3hQW9Nw+Y463lkWaKKXKYMvmRiRDAtfpuPFLN+E1/6ZhyR8J2ig+eVREnYgUsiag==
dependencies:
"@eslint-community/eslint-utils" "^4.2.0"
"@eslint-community/regexpp" "^4.6.1"
"@eslint/eslintrc" "^2.1.2"
"@eslint/js" "8.52.0"
"@eslint/eslintrc" "^2.1.3"
"@eslint/js" "8.53.0"
"@humanwhocodes/config-array" "^0.11.13"
"@humanwhocodes/module-importer" "^1.0.1"
"@nodelib/fs.walk" "^1.2.8"
Expand Down

4 comments on commit a702f2b

@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: a702f2b Previous: 5562a3d Ratio
Child logger creation 301912 ops/sec (±0.86%) 465143 ops/sec (±4.21%) 1.54
Logging a string on root logger 502958 ops/sec (±12.36%) 490019 ops/sec (±15.46%) 0.97
Logging an object on root logger 362410 ops/sec (±11.17%) 323162 ops/sec (±15.95%) 0.89
Logging an object with a message on root logger 263524 ops/sec (±15.83%) 187505 ops/sec (±18.26%) 0.71
Logging an object with a redacted prop on root logger 258563 ops/sec (±16.36%) 169424 ops/sec (±22.56%) 0.66
Logging a nested 3-level object on root logger 2557 ops/sec (±215.13%) 136545 ops/sec (±21.98%) 53.40

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: a702f2b Previous: 5562a3d Ratio
Logging a nested 3-level object on root logger 2557 ops/sec (±215.13%) 136545 ops/sec (±21.98%) 53.40

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: a702f2b Previous: 5562a3d Ratio
Child logger creation 345983 ops/sec (±0.46%) 458326 ops/sec (±0.56%) 1.32
Logging a string on root logger 806782 ops/sec (±7.23%) 645321 ops/sec (±11.02%) 0.80
Logging an object on root logger 585281 ops/sec (±6.49%) 320024 ops/sec (±22.34%) 0.55
Logging an object with a message on root logger 7111 ops/sec (±204.28%) 181644 ops/sec (±21.24%) 25.54
Logging an object with a redacted prop on root logger 446007 ops/sec (±9.91%) 213966 ops/sec (±21.44%) 0.48
Logging a nested 3-level object on root logger 310288 ops/sec (±5.39%) 122796 ops/sec (±24.61%) 0.40

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: a702f2b Previous: 5562a3d Ratio
Logging an object with a message on root logger 7111 ops/sec (±204.28%) 181644 ops/sec (±21.24%) 25.54

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

Please sign in to comment.