Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/browser/pluginAutoUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class PluginAutoUpdate extends Disposable implements IWorkbenchContributi
}

private async _triggerAutoUpdate(marketplaceIds: ReadonlySet<string>): Promise<void> {
await this._meteredConnectionService.whenInitialized;
if (this._store.isDisposed || this._updateInFlight || this._meteredConnectionService.isConnectionMetered) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export class PluginMarketplaceService extends Disposable implements IPluginMarke

this._register(runWhenGlobalIdle(() => {
this._updateChecksInitialized = true;
this._scheduleUpdateCheck();
void this._initializeUpdateChecks();
this._register(Event.filter(
_configurationService.onDidChangeConfiguration,
e => e.affectsConfiguration(AutoUpdateConfigurationKey)
Expand Down Expand Up @@ -442,6 +442,13 @@ export class PluginMarketplaceService extends Disposable implements IPluginMarke
}));
}

private async _initializeUpdateChecks(): Promise<void> {
await this._meteredConnectionService.whenInitialized;
if (!this._store.isDisposed) {
this._scheduleUpdateCheck();
}
}

clearUpdatesAvailable(marketplaceIds?: ReadonlySet<string>): void {
const remaining = marketplaceIds
? new Set([...this._marketplacesWithUpdates.get()].filter(id => !marketplaceIds.has(id)))
Expand Down Expand Up @@ -878,6 +885,11 @@ export class PluginMarketplaceService extends Disposable implements IPluginMarke
}

private async _doRunUpdateCheck(): Promise<void> {
await this._meteredConnectionService.whenInitialized;
if (this._store.isDisposed) {
return;
}

if (this._meteredConnectionService.isConnectionMetered) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import assert from 'assert';
import { DeferredPromise } from '../../../../../../base/common/async.js';
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
import { Emitter } from '../../../../../../base/common/event.js';
import { Disposable } from '../../../../../../base/common/lifecycle.js';
Expand Down Expand Up @@ -45,9 +46,13 @@ suite('PluginAutoUpdate', () => {
clearUpdatesAvailableCalls: ReadonlySet<string>[];
}

function createContribution(stateOverrides?: Partial<MockState>, isConnectionMetered = false): { contribution: PluginAutoUpdate; state: MockState; meteredConnectionService: TestMeteredConnectionService } {
function createContribution(
stateOverrides?: Partial<MockState>,
isConnectionMetered = false,
whenInitialized: Promise<void> = Promise.resolve(),
): { contribution: PluginAutoUpdate; state: MockState; meteredConnectionService: TestMeteredConnectionService } {
const instantiationService = store.add(new TestInstantiationService());
const meteredConnectionService = store.add(new TestMeteredConnectionService(isConnectionMetered));
const meteredConnectionService = store.add(new TestMeteredConnectionService(isConnectionMetered, whenInitialized));

const state: MockState = {
marketplacesWithUpdates: observableValue<ReadonlySet<string>>('test.marketplacesWithUpdates', new Set()),
Expand Down Expand Up @@ -104,6 +109,21 @@ suite('PluginAutoUpdate', () => {
})), [{ silent: true, automatic: true, marketplaceIds: ['github:microsoft/plugins'] }]);
});

test('waits for connection state initialization before updating', async () => {
const initialized = new DeferredPromise<void>();
const { state } = createContribution(undefined, false, initialized.p);

state.marketplacesWithUpdates.set(new Set(['github:microsoft/plugins']), undefined);
await flushMicrotasks();
assert.strictEqual(state.updateAllCalls.length, 0);

initialized.complete();
await flushMicrotasks();
await flushMicrotasks();

assert.deepStrictEqual(state.updateAllCalls.map(call => [...call.marketplaceIds ?? []]), [['github:microsoft/plugins']]);
});

test('retains queued updates while metered and runs them when unmetered', async () => {
const { state, meteredConnectionService } = createContribution(undefined, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,41 @@ suite('PluginMarketplaceService - installed plugins lifecycle', () => {
assert.strictEqual(fetchCount, 1);
});

test('periodic update checking waits for metered connection initialization', async () => {
let runIdle: ((idle: IdleDeadline) => void) | undefined;
store.add(installFakeRunWhenIdle((_target, runner) => {
runIdle = runner;
return Disposable.None;
}));
const initialized = new DeferredPromise<void>();
const meteredConnectionService = store.add(new TestMeteredConnectionService(false, initialized.p));
let fetchCount = 0;
const service = createService({
meteredConnectionService,
pluginRepositoryService: {
fetchRepository: async () => {
fetchCount++;
return false;
},
},
});
service.addInstalledPlugin(
URI.file('/agent-plugins/github.com/microsoft/plugins/my-plugin'),
makePlugin('my-plugin', 'my-plugin'),
);

assert.ok(runIdle);
runIdle({ didTimeout: false, timeRemaining: () => 50 });
await timeout(0);
assert.strictEqual(fetchCount, 0);

initialized.complete();
await timeout(0);
await timeout(0);

assert.strictEqual(fetchCount, 1);
});

test('defers an overdue check until queued updates are acknowledged', async () => {
const updateCheckInterval = 24 * 60 * 60 * 1000;
const clock = sinon.useFakeTimers({ now: updateCheckInterval + 1 });
Expand Down Expand Up @@ -993,6 +1028,7 @@ suite('PluginMarketplaceService - installed plugins lifecycle', () => {
assert.ok(runIdle);
runIdle({ didTimeout: false, timeRemaining: () => 50 });
await timeout(0);
await timeout(0);
assert.deepStrictEqual(fetched, [deferredRef.canonicalId]);

await configurationService.setUserConfiguration(ChatConfiguration.StrictMarketplaces, [
Expand Down