refactor(automation): remove browser automation, use OS-level automation only

This commit is contained in:
2025-11-22 17:57:35 +01:00
parent 99fa06e12b
commit 84800c663a
44 changed files with 110 additions and 5125 deletions

View File

@@ -5,33 +5,21 @@
* allowing switching between different adapters based on NODE_ENV.
*
* Mapping:
* - NODE_ENV=development → BrowserDevToolsAdapter → Fixture Server → CSS Selectors
* - NODE_ENV=production → NutJsAutomationAdapter → iRacing Window → Image Templates
* - NODE_ENV=test → MockBrowserAutomation → N/A → N/A
* - NODE_ENV=development → MockBrowserAutomation → N/A → N/A
*/
export type AutomationMode = 'development' | 'production' | 'test';
export type AutomationMode = 'production' | 'test';
/**
* @deprecated Use AutomationMode instead. Will be removed in future version.
*/
export type LegacyAutomationMode = 'dev' | 'production' | 'mock';
export interface FixtureServerConfig {
port: number;
autoStart: boolean;
fixturesPath: string;
}
export interface AutomationEnvironmentConfig {
mode: AutomationMode;
/** Development mode configuration (Browser DevTools with fixture server) */
devTools?: {
browserWSEndpoint?: string;
debuggingPort?: number;
};
/** Production mode configuration (nut.js) */
nutJs?: {
mouseSpeed?: number;
@@ -41,9 +29,6 @@ export interface AutomationEnvironmentConfig {
confidence?: number;
};
/** Fixture server configuration for development mode */
fixtureServer?: FixtureServerConfig;
/** Default timeout for automation operations in milliseconds */
defaultTimeout?: number;
/** Number of retry attempts for failed operations */
@@ -57,8 +42,7 @@ export interface AutomationEnvironmentConfig {
*
* Mapping:
* - NODE_ENV=production → 'production'
* - NODE_ENV=test → 'test'
* - NODE_ENV=development → 'development' (default)
* - All other values → 'test' (default)
*
* For backward compatibility, if AUTOMATION_MODE is explicitly set,
* it will be used with a deprecation warning logged to console.
@@ -70,34 +54,28 @@ export function getAutomationMode(): AutomationMode {
if (legacyMode && isValidLegacyAutomationMode(legacyMode)) {
console.warn(
`[DEPRECATED] AUTOMATION_MODE environment variable is deprecated. ` +
`Use NODE_ENV instead. Mapping: dev→development, mock→test, production→production`
`Use NODE_ENV instead. Mapping: dev→test, mock→test, production→production`
);
return mapLegacyMode(legacyMode);
}
const nodeEnv = process.env.NODE_ENV;
if (nodeEnv === 'production') return 'production';
if (nodeEnv === 'test') return 'test';
return 'development';
return 'test';
}
/**
* Load automation configuration from environment variables.
*
* Environment variables:
* - NODE_ENV: 'development' | 'production' | 'test' (default: 'development')
* - NODE_ENV: 'production' | 'test' (default: 'test')
* - AUTOMATION_MODE: (deprecated) 'dev' | 'production' | 'mock'
* - CHROME_DEBUG_PORT: Chrome debugging port (default: 9222)
* - CHROME_WS_ENDPOINT: WebSocket endpoint for Chrome DevTools
* - IRACING_WINDOW_TITLE: Window title for nut.js (default: 'iRacing')
* - TEMPLATE_PATH: Path to template images (default: './resources/templates')
* - OCR_CONFIDENCE: OCR confidence threshold (default: 0.9)
* - AUTOMATION_TIMEOUT: Default timeout in ms (default: 30000)
* - RETRY_ATTEMPTS: Number of retry attempts (default: 3)
* - SCREENSHOT_ON_ERROR: Capture screenshots on error (default: true)
* - FIXTURE_SERVER_PORT: Port for fixture server (default: 3456)
* - FIXTURE_SERVER_AUTO_START: Auto-start fixture server (default: true in development)
* - FIXTURE_SERVER_PATH: Path to fixtures (default: './resources/iracing-hosted-sessions')
*
* @returns AutomationEnvironmentConfig with parsed environment values
*/
@@ -106,10 +84,6 @@ export function loadAutomationConfig(): AutomationEnvironmentConfig {
return {
mode,
devTools: {
debuggingPort: parseIntSafe(process.env.CHROME_DEBUG_PORT, 9222),
browserWSEndpoint: process.env.CHROME_WS_ENDPOINT,
},
nutJs: {
mouseSpeed: parseIntSafe(process.env.NUTJS_MOUSE_SPEED, 1000),
keyboardDelay: parseIntSafe(process.env.NUTJS_KEYBOARD_DELAY, 50),
@@ -117,11 +91,6 @@ export function loadAutomationConfig(): AutomationEnvironmentConfig {
templatePath: process.env.TEMPLATE_PATH || './resources/templates',
confidence: parseFloatSafe(process.env.OCR_CONFIDENCE, 0.9),
},
fixtureServer: {
port: parseIntSafe(process.env.FIXTURE_SERVER_PORT, 3456),
autoStart: process.env.FIXTURE_SERVER_AUTO_START !== 'false' && mode === 'development',
fixturesPath: process.env.FIXTURE_SERVER_PATH || './resources/iracing-hosted-sessions',
},
defaultTimeout: parseIntSafe(process.env.AUTOMATION_TIMEOUT, 30000),
retryAttempts: parseIntSafe(process.env.RETRY_ATTEMPTS, 3),
screenshotOnError: process.env.SCREENSHOT_ON_ERROR !== 'false',
@@ -132,7 +101,7 @@ export function loadAutomationConfig(): AutomationEnvironmentConfig {
* Type guard to validate automation mode string.
*/
function isValidAutomationMode(value: string | undefined): value is AutomationMode {
return value === 'development' || value === 'production' || value === 'test';
return value === 'production' || value === 'test';
}
/**
@@ -147,7 +116,7 @@ function isValidLegacyAutomationMode(value: string | undefined): value is Legacy
*/
function mapLegacyMode(legacy: LegacyAutomationMode): AutomationMode {
switch (legacy) {
case 'dev': return 'development';
case 'dev': return 'test';
case 'mock': return 'test';
case 'production': return 'production';
}

View File

@@ -2,10 +2,5 @@
* Configuration module exports for infrastructure layer.
*/
export {
AutomationMode,
AutomationEnvironmentConfig,
FixtureServerConfig,
loadAutomationConfig,
getAutomationMode,
} from './AutomationConfig';
export type { AutomationMode, AutomationEnvironmentConfig } from './AutomationConfig';
export { loadAutomationConfig, getAutomationMode } from './AutomationConfig';