Skip to content

Commit

Permalink
Merge #6033 from justinmk3/morebeta
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk3 authored Nov 15, 2024
2 parents 041e30d + 79b5204 commit e7c8784
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/dev/beta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/shared/logger/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/shared/logger/toolkitLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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')
}
Expand Down
22 changes: 21 additions & 1 deletion packages/core/src/shared/vscode/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
*/
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/test/shared/vscode/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit e7c8784

Please sign in to comment.