fix(policy): refactor policy dialog to remove process.exit and fix integration tests

- Refactored `PolicyUpdateDialog` to remove side effects (`process.exit`, `relaunchApp`) and delegate logic to parent.
- Updated `AppContainer` to handle relaunch logic.
- Added comprehensive unit tests for `PolicyUpdateDialog`.
- Fixed `project-policy-cli.test.ts` to correctly mock `PolicyIntegrityManager`.
- Fixed typo in `packages/core/src/policy/config.ts`.
This commit is contained in:
Abhijit Balaji
2026-02-13 16:11:42 -08:00
parent c73e47bbbe
commit 73b3cb86eb
5 changed files with 136 additions and 40 deletions

View File

@@ -1,20 +1,15 @@
/**
* @license
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { Box, Text } from 'ink';
import type React from 'react';
import { useEffect, useState, useCallback } from 'react';
import { theme } from '../semantic-colors.js';
import type { RadioSelectItem } from './shared/RadioButtonSelect.js';
import { RadioButtonSelect } from './shared/RadioButtonSelect.js';
import { useKeypress } from '../hooks/useKeypress.js';
import * as process from 'node:process';
import { relaunchApp } from '../../utils/processUtils.js';
import { runExitCleanup } from '../../utils/cleanup.js';
import { ExitCodes } from '@google/gemini-cli-core';
export enum PolicyUpdateChoice {
ACCEPT = 'accept',
@@ -34,33 +29,10 @@ export const PolicyUpdateDialog: React.FC<PolicyUpdateDialogProps> = ({
identifier,
isRestarting,
}) => {
const [exiting, setExiting] = useState(false);
useEffect(() => {
let timer: ReturnType<typeof setTimeout>;
if (isRestarting) {
timer = setTimeout(async () => {
await relaunchApp();
}, 250);
}
return () => {
if (timer) clearTimeout(timer);
};
}, [isRestarting]);
const handleExit = useCallback(() => {
setExiting(true);
// Give time for the UI to render the exiting message
setTimeout(async () => {
await runExitCleanup();
process.exit(ExitCodes.FATAL_CANCELLATION_ERROR);
}, 100);
}, []);
useKeypress(
(key) => {
if (key.name === 'escape') {
handleExit();
onSelect(PolicyUpdateChoice.IGNORE);
return true;
}
return false;
@@ -114,14 +86,6 @@ export const PolicyUpdateDialog: React.FC<PolicyUpdateDialogProps> = ({
</Text>
</Box>
)}
{exiting && (
<Box marginLeft={1} marginTop={1}>
<Text color={theme.status.warning}>
A selection must be made to continue. Exiting since escape was
pressed.
</Text>
</Box>
)}
</Box>
);
};