[feat]: Add /extensions restart command (#12739)

This commit is contained in:
Jacob MacDonald
2025-11-07 15:17:23 -08:00
committed by GitHub
parent fdb6088603
commit bafbcbbe8b
9 changed files with 457 additions and 10 deletions

View File

@@ -0,0 +1,75 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect } from 'vitest';
import {
extensionUpdatesReducer,
type ExtensionUpdatesState,
ExtensionUpdateState,
} from './extensions.js';
describe('extensionUpdatesReducer', () => {
it('should handle RESTARTED action', () => {
const initialState: ExtensionUpdatesState = {
extensionStatuses: new Map([
[
'ext1',
{
status: ExtensionUpdateState.UPDATED_NEEDS_RESTART,
lastUpdateTime: 0,
lastUpdateCheck: 0,
notified: true,
},
],
]),
batchChecksInProgress: 0,
scheduledUpdate: null,
};
const action = {
type: 'RESTARTED' as const,
payload: { name: 'ext1' },
};
const newState = extensionUpdatesReducer(initialState, action);
const expectedStatus = {
status: ExtensionUpdateState.UPDATED,
lastUpdateTime: 0,
lastUpdateCheck: 0,
notified: true,
};
expect(newState.extensionStatuses.get('ext1')).toEqual(expectedStatus);
});
it('should not change state for RESTARTED action if status is not UPDATED_NEEDS_RESTART', () => {
const initialState: ExtensionUpdatesState = {
extensionStatuses: new Map([
[
'ext1',
{
status: ExtensionUpdateState.UPDATED,
lastUpdateTime: 0,
lastUpdateCheck: 0,
notified: true,
},
],
]),
batchChecksInProgress: 0,
scheduledUpdate: null,
};
const action = {
type: 'RESTARTED' as const,
payload: { name: 'ext1' },
};
const newState = extensionUpdatesReducer(initialState, action);
expect(newState).toEqual(initialState);
});
});

View File

@@ -63,7 +63,8 @@ export type ExtensionUpdateAction =
| { type: 'BATCH_CHECK_START' }
| { type: 'BATCH_CHECK_END' }
| { type: 'SCHEDULE_UPDATE'; payload: ScheduleUpdateArgs }
| { type: 'CLEAR_SCHEDULED_UPDATE' };
| { type: 'CLEAR_SCHEDULED_UPDATE' }
| { type: 'RESTARTED'; payload: { name: string } };
export function extensionUpdatesReducer(
state: ExtensionUpdatesState,
@@ -125,6 +126,20 @@ export function extensionUpdatesReducer(
...state,
scheduledUpdate: null,
};
case 'RESTARTED': {
const existing = state.extensionStatuses.get(action.payload.name);
if (existing?.status !== ExtensionUpdateState.UPDATED_NEEDS_RESTART) {
return state;
}
const newStatuses = new Map(state.extensionStatuses);
newStatuses.set(action.payload.name, {
...existing,
status: ExtensionUpdateState.UPDATED,
});
return { ...state, extensionStatuses: newStatuses };
}
default:
checkExhaustive(action);
}