diff --git a/packages/core/src/dev/beta.ts b/packages/core/src/dev/beta.ts index fbcf3bf4748..4975ae73e3d 100644 --- a/packages/core/src/dev/beta.ts +++ b/packages/core/src/dev/beta.ts @@ -19,14 +19,14 @@ import { telemetry } from '../shared/telemetry/telemetry' import { cast } from '../shared/utilities/typeConstructors' import { CancellationError } from '../shared/utilities/timeoutUtils' import { isAmazonQ, isCloud9, productName } from '../shared/extensionUtilities' -import * as config from './config' +import * as devConfig from './config' import { isReleaseVersion } from '../shared/vscode/env' import { getRelativeDate } from '../shared/datetime' const localize = nls.loadMessageBundle() const logger = getLogger('dev/beta') -const downloadIntervalMs = 1000 * 60 * 60 * 24 // A day in milliseconds +const downloadIntervalMs = 1000 * 60 * 60 * 3 // 3 hours (8 times/day). interface BetaToolkit { readonly needUpdate: boolean @@ -48,7 +48,7 @@ async function updateBetaToolkitData(vsixUrl: string, data: BetaToolkit) { * Set up "beta" update monitoring. */ export async function activate(ctx: vscode.ExtensionContext) { - const betaUrl = isAmazonQ() ? config.betaUrl.amazonq : config.betaUrl.toolkit + const betaUrl = isAmazonQ() ? devConfig.betaUrl.amazonq : devConfig.betaUrl.toolkit if (!isCloud9() && !isReleaseVersion() && betaUrl) { ctx.subscriptions.push(watchBetaVSIX(betaUrl)) } diff --git a/packages/core/src/shared/logger/activation.ts b/packages/core/src/shared/logger/activation.ts index 29d8f8f6fd9..ff3a8ad6076 100644 --- a/packages/core/src/shared/logger/activation.ts +++ b/packages/core/src/shared/logger/activation.ts @@ -13,6 +13,7 @@ import { resolvePath } from '../utilities/pathUtils' import fs from '../../shared/fs/fs' import { isWeb } from '../extensionGlobals' import { getUserAgent } from '../telemetry/util' +import { isBeta } from '../vscode/env' /** * Activate Logger functionality for the extension. @@ -80,7 +81,7 @@ export function makeLogger(opts: { outputChannels?: vscode.OutputChannel[] useConsoleLog?: boolean }): Logger { - const logger = new ToolkitLogger(opts.logLevel) + const logger = new ToolkitLogger(opts.logLevel, isBeta()) if (opts.logFile) { logger.logToFile(opts.logFile) logger.logFile = opts.logFile diff --git a/packages/core/src/shared/logger/toolkitLogger.ts b/packages/core/src/shared/logger/toolkitLogger.ts index 7a68e5c12d7..d525fb7cf20 100644 --- a/packages/core/src/shared/logger/toolkitLogger.ts +++ b/packages/core/src/shared/logger/toolkitLogger.ts @@ -24,7 +24,10 @@ export class ToolkitLogger extends BaseLogger implements vscode.Disposable { private idCounter: number = 0 private logMap: { [logID: number]: { [filePath: string]: string } } = {} - public constructor(logLevel: LogLevel) { + public constructor( + logLevel: LogLevel, + private readonly isBeta: boolean = false + ) { super() this.logger = winston.createLogger({ format: winston.format.combine( @@ -120,6 +123,9 @@ export class ToolkitLogger extends BaseLogger implements vscode.Disposable { } override sendToLog(level: LogLevel, message: string | Error, ...meta: any[]): number { + // XXX: force debug/verbose logs for Beta users. + level = this.isBeta && compareLogLevel(level, 'info') > 0 ? 'info' : level + if (this.disposed) { throw new Error('Cannot write to disposed logger') } diff --git a/packages/core/src/shared/vscode/env.ts b/packages/core/src/shared/vscode/env.ts index 952284b6e2c..516b1190c62 100644 --- a/packages/core/src/shared/vscode/env.ts +++ b/packages/core/src/shared/vscode/env.ts @@ -11,6 +11,7 @@ import { getLogger } from '../logger' import { onceChanged } from '../utilities/functionUtils' import { ChildProcess } from '../utilities/processUtils' import globals, { isWeb } from '../extensionGlobals' +import * as devConfig from '../../dev/config' /** * Returns true if the current build is running on CI (build server). @@ -31,12 +32,31 @@ try { /** * Returns true if the current build is a production build (as opposed to a - * prerelease/test/nightly build) + * prerelease/test/nightly build). + * + * Note: `isBeta()` is treated separately. */ export function isReleaseVersion(prereleaseOk: boolean = false): boolean { return (prereleaseOk || !semver.prerelease(extensionVersion)) && extensionVersion !== testVersion } +/** + * Returns true if the current build is a "beta" build. + */ +export function isBeta(): boolean { + const testing = extensionVersion === testVersion + for (const url of Object.values(devConfig.betaUrl)) { + if (url && url.length > 0) { + if (!testing && semver.lt(extensionVersion, '99.0.0')) { + throw Error('beta build must set version=99.0.0 in package.json') + } + + return true + } + } + return false +} + /** * Returns true when source mapping is available */ diff --git a/packages/core/src/test/shared/vscode/env.test.ts b/packages/core/src/test/shared/vscode/env.test.ts index 7bbbebb22a1..bc1c1dde9dc 100644 --- a/packages/core/src/test/shared/vscode/env.test.ts +++ b/packages/core/src/test/shared/vscode/env.test.ts @@ -4,15 +4,18 @@ */ import assert from 'assert' +import path from 'path' import { isCloudDesktop, getEnvVars, getServiceEnvVarConfig, isAmazonInternalOs as isAmazonInternalOS, + isBeta, } from '../../../shared/vscode/env' import { ChildProcess } from '../../../shared/utilities/processUtils' import * as sinon from 'sinon' import os from 'os' +import fs from '../../../shared/fs/fs' import vscode from 'vscode' import { getComputeEnvType } from '../../../shared/telemetry/util' @@ -82,6 +85,22 @@ describe('env', function () { return sandbox.stub(os, 'release').returns(verson) } + it('isBeta', async () => { + // HACK: read each package.json because env.ts thinks version is "testPluginVersion" during testing. + const toolkitPath = path.join(__dirname, '../../../../../../toolkit/package.json') + const amazonqPath = path.join(__dirname, '../../../../../../amazonq/package.json') + const toolkit = JSON.parse(await fs.readFileText(toolkitPath)) + const amazonq = JSON.parse(await fs.readFileText(amazonqPath)) + const toolkitVer = toolkit.version as string + const amazonqVer = amazonq.version as string + const toolkitBeta = toolkitVer.startsWith('99.') + const amazonqBeta = amazonqVer.startsWith('99.') + + assert(toolkitBeta === amazonqBeta) + const expected = toolkitBeta + assert.strictEqual(isBeta(), expected) + }) + it('isAmazonInternalOS', function () { sandbox.stub(process, 'platform').value('linux') const versionStub = stubOsVersion('5.10.220-188.869.amzn2int.x86_64')