mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-12 23:21:27 -07:00
refactor: remove virtual execution lifecycle aliases
This commit is contained in:
@@ -35,7 +35,7 @@ describe('ExecutionLifecycleService', () => {
|
||||
it('completes managed executions in the foreground and notifies exit subscribers', async () => {
|
||||
const handle = ExecutionLifecycleService.createExecution();
|
||||
if (handle.pid === undefined) {
|
||||
throw new Error('Expected virtual execution ID.');
|
||||
throw new Error('Expected execution ID.');
|
||||
}
|
||||
|
||||
const onExit = vi.fn();
|
||||
@@ -43,7 +43,7 @@ describe('ExecutionLifecycleService', () => {
|
||||
|
||||
ExecutionLifecycleService.appendOutput(handle.pid, 'Hello');
|
||||
ExecutionLifecycleService.appendOutput(handle.pid, ' World');
|
||||
ExecutionLifecycleService.completeVirtualExecution(handle.pid, {
|
||||
ExecutionLifecycleService.completeExecution(handle.pid, {
|
||||
exitCode: 0,
|
||||
});
|
||||
|
||||
@@ -66,20 +66,20 @@ describe('ExecutionLifecycleService', () => {
|
||||
'remote_agent',
|
||||
);
|
||||
if (handle.pid === undefined) {
|
||||
throw new Error('Expected virtual execution ID.');
|
||||
throw new Error('Expected execution ID.');
|
||||
}
|
||||
|
||||
ExecutionLifecycleService.completeVirtualExecution(handle.pid, {
|
||||
ExecutionLifecycleService.completeExecution(handle.pid, {
|
||||
exitCode: 0,
|
||||
});
|
||||
const result = await handle.result;
|
||||
expect(result.executionMethod).toBe('remote_agent');
|
||||
});
|
||||
|
||||
it('supports backgrounding virtual executions and continues streaming updates', async () => {
|
||||
const handle = ExecutionLifecycleService.createVirtualExecution();
|
||||
it('supports backgrounding managed executions and continues streaming updates', async () => {
|
||||
const handle = ExecutionLifecycleService.createExecution();
|
||||
if (handle.pid === undefined) {
|
||||
throw new Error('Expected virtual execution ID.');
|
||||
throw new Error('Expected execution ID.');
|
||||
}
|
||||
|
||||
const chunks: string[] = [];
|
||||
@@ -103,7 +103,7 @@ describe('ExecutionLifecycleService', () => {
|
||||
expect(backgroundResult.output).toBe('Chunk 1');
|
||||
|
||||
ExecutionLifecycleService.appendOutput(handle.pid, '\nChunk 2');
|
||||
ExecutionLifecycleService.completeVirtualExecution(handle.pid, {
|
||||
ExecutionLifecycleService.completeExecution(handle.pid, {
|
||||
exitCode: 0,
|
||||
});
|
||||
|
||||
@@ -116,11 +116,11 @@ describe('ExecutionLifecycleService', () => {
|
||||
unsubscribeExit();
|
||||
});
|
||||
|
||||
it('kills virtual executions and resolves with aborted result', async () => {
|
||||
it('kills managed executions and resolves with aborted result', async () => {
|
||||
const onKill = vi.fn();
|
||||
const handle = ExecutionLifecycleService.createVirtualExecution('', onKill);
|
||||
const handle = ExecutionLifecycleService.createExecution('', onKill);
|
||||
if (handle.pid === undefined) {
|
||||
throw new Error('Expected virtual execution ID.');
|
||||
throw new Error('Expected execution ID.');
|
||||
}
|
||||
|
||||
ExecutionLifecycleService.appendOutput(handle.pid, 'work');
|
||||
|
||||
@@ -91,7 +91,7 @@ type ManagedExecutionState = VirtualExecutionState | ExternalExecutionState;
|
||||
*/
|
||||
export class ExecutionLifecycleService {
|
||||
private static readonly EXIT_INFO_TTL_MS = 5 * 60 * 1000;
|
||||
private static nextVirtualExecutionId = 2_000_000_000;
|
||||
private static nextExecutionId = 2_000_000_000;
|
||||
|
||||
private static activeExecutions = new Map<number, ManagedExecutionState>();
|
||||
private static activeResolvers = new Map<
|
||||
@@ -121,10 +121,10 @@ export class ExecutionLifecycleService {
|
||||
}, this.EXIT_INFO_TTL_MS).unref();
|
||||
}
|
||||
|
||||
private static allocateVirtualExecutionId(): number {
|
||||
let executionId = ++this.nextVirtualExecutionId;
|
||||
private static allocateExecutionId(): number {
|
||||
let executionId = ++this.nextExecutionId;
|
||||
while (this.activeExecutions.has(executionId)) {
|
||||
executionId = ++this.nextVirtualExecutionId;
|
||||
executionId = ++this.nextExecutionId;
|
||||
}
|
||||
return executionId;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ export class ExecutionLifecycleService {
|
||||
this.activeResolvers.clear();
|
||||
this.activeListeners.clear();
|
||||
this.exitedExecutionInfo.clear();
|
||||
this.nextVirtualExecutionId = 2_000_000_000;
|
||||
this.nextExecutionId = 2_000_000_000;
|
||||
}
|
||||
|
||||
static registerExecution(
|
||||
@@ -196,7 +196,7 @@ export class ExecutionLifecycleService {
|
||||
onKill?: () => void,
|
||||
executionMethod: ExecutionMethod = 'none',
|
||||
): ExecutionHandle {
|
||||
const executionId = this.allocateVirtualExecutionId();
|
||||
const executionId = this.allocateExecutionId();
|
||||
|
||||
this.activeExecutions.set(executionId, {
|
||||
executionMethod,
|
||||
@@ -219,17 +219,6 @@ export class ExecutionLifecycleService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use createExecution() for new call sites.
|
||||
*/
|
||||
static createVirtualExecution(
|
||||
initialOutput = '',
|
||||
onKill?: () => void,
|
||||
executionMethod: ExecutionMethod = 'none',
|
||||
): ExecutionHandle {
|
||||
return this.createExecution(initialOutput, onKill, executionMethod);
|
||||
}
|
||||
|
||||
static appendOutput(executionId: number, chunk: string): void {
|
||||
const execution = this.activeExecutions.get(executionId);
|
||||
if (!execution || chunk.length === 0) {
|
||||
@@ -284,7 +273,7 @@ export class ExecutionLifecycleService {
|
||||
);
|
||||
}
|
||||
|
||||
static completeVirtualExecution(
|
||||
static completeExecution(
|
||||
executionId: number,
|
||||
options?: ExecutionCompletionOptions,
|
||||
): void {
|
||||
@@ -314,16 +303,6 @@ export class ExecutionLifecycleService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use completeVirtualExecution() for new call sites.
|
||||
*/
|
||||
static completeExecution(
|
||||
executionId: number,
|
||||
options?: ExecutionCompletionOptions,
|
||||
): void {
|
||||
this.completeVirtualExecution(executionId, options);
|
||||
}
|
||||
|
||||
static completeWithResult(
|
||||
executionId: number,
|
||||
result: ExecutionResult,
|
||||
|
||||
@@ -30,9 +30,7 @@ import {
|
||||
import { killProcessGroup } from '../utils/process-utils.js';
|
||||
import {
|
||||
ExecutionLifecycleService,
|
||||
type ExecutionCompletionOptions,
|
||||
type ExecutionHandle,
|
||||
type ExecutionMethod,
|
||||
type ExecutionOutputEvent,
|
||||
type ExecutionResult,
|
||||
} from './executionLifecycleService.js';
|
||||
@@ -224,29 +222,6 @@ export class ShellExecutionService {
|
||||
return { newBuffer: truncatedBuffer + chunk, truncated: true };
|
||||
}
|
||||
|
||||
static createVirtualExecution(
|
||||
initialOutput = '',
|
||||
onKill?: () => void,
|
||||
executionMethod: ExecutionMethod = 'none',
|
||||
): ShellExecutionHandle {
|
||||
return ExecutionLifecycleService.createVirtualExecution(
|
||||
initialOutput,
|
||||
onKill,
|
||||
executionMethod,
|
||||
);
|
||||
}
|
||||
|
||||
static appendVirtualOutput(pid: number, chunk: string): void {
|
||||
ExecutionLifecycleService.appendOutput(pid, chunk);
|
||||
}
|
||||
|
||||
static completeVirtualExecution(
|
||||
pid: number,
|
||||
options?: ExecutionCompletionOptions,
|
||||
): void {
|
||||
ExecutionLifecycleService.completeVirtualExecution(pid, options);
|
||||
}
|
||||
|
||||
private static childProcessFallback(
|
||||
commandToExecute: string,
|
||||
cwd: string,
|
||||
|
||||
Reference in New Issue
Block a user