erosolar-cli
Version:
Unified AI agent framework for the command line - Multi-provider support with schema-driven tools, code intelligence, and transparent reasoning
200 lines • 5.55 kB
TypeScript
/**
* CLI Test Harness - PTY-based interactive CLI testing
*
* This module provides real runtime verification of CLI behavior by:
* 1. Spawning the CLI in a pseudo-terminal (PTY)
* 2. Sending simulated user input (including paste sequences)
* 3. Capturing and analyzing output
* 4. Verifying expected behaviors
*
* @license MIT
*/
import { EventEmitter } from 'node:events';
export interface CLITestConfig {
/** Working directory for the CLI */
cwd: string;
/** Environment variables */
env?: Record<string, string>;
/** Timeout for the entire test (ms) */
timeout?: number;
/** Whether to use PTY mode (requires node-pty) */
usePty?: boolean;
/** Path to CLI entry point */
cliPath?: string;
}
export interface TestInput {
/** Type of input to send */
type: 'text' | 'paste' | 'key' | 'wait';
/** The content to send */
content?: string;
/** For 'key' type: special key name */
key?: 'enter' | 'tab' | 'escape' | 'ctrl-c' | 'ctrl-d';
/** For 'wait' type: milliseconds to wait */
delay?: number;
}
export interface TestExpectation {
/** Type of expectation */
type: 'output_contains' | 'output_matches' | 'output_not_contains' | 'exit_code';
/** Pattern or value to check */
value: string | number | RegExp;
/** Description for error messages */
description?: string;
/** Timeout for this specific expectation (ms) */
timeout?: number;
}
export interface CLITestScenario {
/** Unique test identifier */
id: string;
/** Human-readable description */
description: string;
/** Category of test */
category: 'paste' | 'input' | 'command' | 'output' | 'behavior';
/** Sequence of inputs to send */
inputs: TestInput[];
/** Expected outcomes */
expectations: TestExpectation[];
/** Setup commands to run before test */
setup?: string[];
/** Cleanup commands to run after test */
cleanup?: string[];
}
export interface TestResult {
scenario: CLITestScenario;
passed: boolean;
duration: number;
output: string;
errors: string[];
expectations: Array<{
expectation: TestExpectation;
passed: boolean;
actual?: string;
reason?: string;
}>;
}
declare const SPECIAL_KEYS: Record<string, string>;
export declare class CLITestHarness extends EventEmitter {
private config;
private process;
private output;
private errors;
private exitCode;
private ptyModule;
constructor(config: CLITestConfig);
/**
* Try to load node-pty for true PTY support
*/
private loadPtyModule;
/**
* Start the CLI process
*/
start(): Promise<void>;
/**
* Start CLI with PTY (for interactive features like bracketed paste)
*/
private startWithPty;
/**
* Start CLI with standard stdio (fallback, limited interactive support)
*/
private startWithStdio;
/**
* Send input to the CLI
*/
write(input: string): void;
/**
* Send a bracketed paste sequence
*/
paste(content: string): void;
/**
* Send a special key
*/
sendKey(key: keyof typeof SPECIAL_KEYS): void;
/**
* Wait for output matching a pattern
*/
waitForOutput(pattern: string | RegExp, timeout?: number): Promise<string>;
/**
* Wait for a specified duration
*/
wait(ms: number): Promise<void>;
/**
* Get current output
*/
getOutput(): string;
/**
* Get current errors
*/
getErrors(): string;
/**
* Stop the CLI process
*/
stop(): Promise<number>;
/**
* Run a complete test scenario
*/
runScenario(scenario: CLITestScenario): Promise<TestResult>;
/**
* Execute a single input action
*/
private executeInput;
/**
* Check a single expectation
*/
private checkExpectation;
}
/**
* Create a paste handling test scenario
*/
export declare function createPasteTestScenario(content: string, expectedLineCount: number): CLITestScenario;
/**
* Create a multi-line input test scenario
*/
export declare function createMultiLineInputScenario(): CLITestScenario;
/**
* Create a slash command test scenario
*/
export declare function createSlashCommandScenario(command: string): CLITestScenario;
/**
* Run verification tests for a specific claim type
*/
export declare function runVerificationTests(claimType: string, workingDir: string): Promise<{
passed: boolean;
results: TestResult[];
summary: string;
}>;
/**
* Claim structure for unified verification
*/
export interface VerificationClaim {
id: string;
statement: string;
category: string;
context: Record<string, unknown>;
}
/**
* Result of verifying a single claim
*/
export interface UnifiedClaimResult {
claim: VerificationClaim;
passed: boolean;
method: 'pty' | 'shell' | 'file_check' | 'unit_test';
output: string;
error?: string;
duration: number;
}
/**
* Verify a single claim using the appropriate method (PTY-based)
*/
export declare function verifyClaim(claim: VerificationClaim, workingDir: string): Promise<UnifiedClaimResult>;
/**
* Verify all claims using unified PTY harness
*/
export declare function verifyAllClaims(claims: VerificationClaim[], workingDir: string): Promise<{
results: UnifiedClaimResult[];
summary: {
total: number;
passed: number;
failed: number;
};
}>;
export default CLITestHarness;
//# sourceMappingURL=cliTestHarness.d.ts.map