mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 21:03:05 -07:00
refactor: make createExecution the primary lifecycle API
This commit is contained in:
@@ -32,8 +32,8 @@ describe('ExecutionLifecycleService', () => {
|
|||||||
ExecutionLifecycleService.resetForTest();
|
ExecutionLifecycleService.resetForTest();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('completes virtual executions in the foreground and notifies exit subscribers', async () => {
|
it('completes managed executions in the foreground and notifies exit subscribers', async () => {
|
||||||
const handle = ExecutionLifecycleService.createVirtualExecution();
|
const handle = ExecutionLifecycleService.createExecution();
|
||||||
if (handle.pid === undefined) {
|
if (handle.pid === undefined) {
|
||||||
throw new Error('Expected virtual execution ID.');
|
throw new Error('Expected virtual execution ID.');
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,23 @@ describe('ExecutionLifecycleService', () => {
|
|||||||
unsubscribe();
|
unsubscribe();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('supports explicit execution methods for managed executions', async () => {
|
||||||
|
const handle = ExecutionLifecycleService.createExecution(
|
||||||
|
'',
|
||||||
|
undefined,
|
||||||
|
'remote_agent',
|
||||||
|
);
|
||||||
|
if (handle.pid === undefined) {
|
||||||
|
throw new Error('Expected virtual execution ID.');
|
||||||
|
}
|
||||||
|
|
||||||
|
ExecutionLifecycleService.completeVirtualExecution(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 () => {
|
it('supports backgrounding virtual executions and continues streaming updates', async () => {
|
||||||
const handle = ExecutionLifecycleService.createVirtualExecution();
|
const handle = ExecutionLifecycleService.createVirtualExecution();
|
||||||
if (handle.pid === undefined) {
|
if (handle.pid === undefined) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export type ExecutionMethod =
|
|||||||
| 'lydell-node-pty'
|
| 'lydell-node-pty'
|
||||||
| 'node-pty'
|
| 'node-pty'
|
||||||
| 'child_process'
|
| 'child_process'
|
||||||
|
| 'remote_agent'
|
||||||
| 'none';
|
| 'none';
|
||||||
|
|
||||||
export interface ExecutionResult {
|
export interface ExecutionResult {
|
||||||
@@ -190,14 +191,15 @@ export class ExecutionLifecycleService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static createVirtualExecution(
|
static createExecution(
|
||||||
initialOutput = '',
|
initialOutput = '',
|
||||||
onKill?: () => void,
|
onKill?: () => void,
|
||||||
|
executionMethod: ExecutionMethod = 'none',
|
||||||
): ExecutionHandle {
|
): ExecutionHandle {
|
||||||
const executionId = this.allocateVirtualExecutionId();
|
const executionId = this.allocateVirtualExecutionId();
|
||||||
|
|
||||||
this.activeExecutions.set(executionId, {
|
this.activeExecutions.set(executionId, {
|
||||||
executionMethod: 'none',
|
executionMethod,
|
||||||
output: initialOutput,
|
output: initialOutput,
|
||||||
kind: 'virtual',
|
kind: 'virtual',
|
||||||
onKill,
|
onKill,
|
||||||
@@ -218,13 +220,14 @@ export class ExecutionLifecycleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use createVirtualExecution() for new call sites.
|
* @deprecated Use createExecution() for new call sites.
|
||||||
*/
|
*/
|
||||||
static createExecution(
|
static createVirtualExecution(
|
||||||
initialOutput = '',
|
initialOutput = '',
|
||||||
onKill?: () => void,
|
onKill?: () => void,
|
||||||
|
executionMethod: ExecutionMethod = 'none',
|
||||||
): ExecutionHandle {
|
): ExecutionHandle {
|
||||||
return this.createVirtualExecution(initialOutput, onKill);
|
return this.createExecution(initialOutput, onKill, executionMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
static appendOutput(executionId: number, chunk: string): void {
|
static appendOutput(executionId: number, chunk: string): void {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import {
|
|||||||
ExecutionLifecycleService,
|
ExecutionLifecycleService,
|
||||||
type ExecutionCompletionOptions,
|
type ExecutionCompletionOptions,
|
||||||
type ExecutionHandle,
|
type ExecutionHandle,
|
||||||
|
type ExecutionMethod,
|
||||||
type ExecutionOutputEvent,
|
type ExecutionOutputEvent,
|
||||||
type ExecutionResult,
|
type ExecutionResult,
|
||||||
} from './executionLifecycleService.js';
|
} from './executionLifecycleService.js';
|
||||||
@@ -226,8 +227,13 @@ export class ShellExecutionService {
|
|||||||
static createVirtualExecution(
|
static createVirtualExecution(
|
||||||
initialOutput = '',
|
initialOutput = '',
|
||||||
onKill?: () => void,
|
onKill?: () => void,
|
||||||
|
executionMethod: ExecutionMethod = 'none',
|
||||||
): ShellExecutionHandle {
|
): ShellExecutionHandle {
|
||||||
return ExecutionLifecycleService.createVirtualExecution(initialOutput, onKill);
|
return ExecutionLifecycleService.createVirtualExecution(
|
||||||
|
initialOutput,
|
||||||
|
onKill,
|
||||||
|
executionMethod,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static appendVirtualOutput(pid: number, chunk: string): void {
|
static appendVirtualOutput(pid: number, chunk: string): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user