This commit is contained in:
2025-11-30 23:00:48 +01:00
parent 4b8c70978f
commit 645f537895
41 changed files with 738 additions and 1631 deletions

View File

@@ -1,8 +1,8 @@
import { IAutomationEngine, ValidationResult } from '../../../application/ports/IAutomationEngine';
import { HostedSessionConfig } from '../../../domain/entities/HostedSessionConfig';
import { StepId } from '../../../domain/value-objects/StepId';
import type { IBrowserAutomation } from '../../../application/ports/IScreenAutomation';
import { ISessionRepository } from '../../../application/ports/ISessionRepository';
import { IAutomationEngine, ValidationResult } from '../../../../application/ports/IAutomationEngine';
import { HostedSessionConfig } from '../../../../domain/entities/HostedSessionConfig';
import { StepId } from '../../../../domain/value-objects/StepId';
import type { IBrowserAutomation } from '../../../../application/ports/IScreenAutomation';
import { ISessionRepository } from '../../../../application/ports/ISessionRepository';
import { getStepName } from './templates/IRacingTemplateMap';
/**
@@ -14,12 +14,13 @@ import { getStepName } from './templates/IRacingTemplateMap';
* 3. Managing session state transitions
*
* This is a REAL implementation that uses actual automation,
* not a mock. Currently delegates to deprecated nut.js adapters for
* screen automation operations.
* not a mock. Historically delegated to legacy native screen
* automation adapters, but those are no longer part of the
* supported stack.
*
* @deprecated This adapter currently delegates to the deprecated NutJsAutomationAdapter.
* Should be updated to use Playwright browser automation when available.
* See docs/ARCHITECTURE.md for the updated automation strategy.
* @deprecated This adapter should be updated to use Playwright
* browser automation when available. See docs/ARCHITECTURE.md
* for the updated automation strategy.
*/
export class AutomationEngineAdapter implements IAutomationEngine {
private isRunning = false;

View File

@@ -1,8 +1,8 @@
import { IAutomationEngine, ValidationResult } from '../../../application/ports/IAutomationEngine';
import { HostedSessionConfig } from '../../../domain/entities/HostedSessionConfig';
import { StepId } from '../../../domain/value-objects/StepId';
import type { IBrowserAutomation } from '../../../application/ports/IScreenAutomation';
import { ISessionRepository } from '../../../application/ports/ISessionRepository';
import { IAutomationEngine, ValidationResult } from '../../../../application/ports/IAutomationEngine';
import { HostedSessionConfig } from '../../../../domain/entities/HostedSessionConfig';
import { StepId } from '../../../../domain/value-objects/StepId';
import type { IBrowserAutomation } from '../../../../application/ports/IScreenAutomation';
import { ISessionRepository } from '../../../../application/ports/ISessionRepository';
import { getStepName } from './templates/IRacingTemplateMap';
export class MockAutomationEngineAdapter implements IAutomationEngine {
@@ -68,9 +68,14 @@ export class MockAutomationEngineAdapter implements IAutomationEngine {
// Execute current step using the browser automation
if (this.browserAutomation.executeStep) {
// Use real workflow automation with IRacingSelectorMap
const result = await this.browserAutomation.executeStep(currentStep, config as unknown as Record<string, unknown>);
const result = await this.browserAutomation.executeStep(
currentStep,
config as unknown as Record<string, unknown>,
);
if (!result.success) {
const errorMessage = `Step ${currentStep.value} (${getStepName(currentStep.value)}) failed: ${result.error}`;
const errorMessage = `Step ${currentStep.value} (${getStepName(
currentStep.value,
)}) failed: ${result.error}`;
console.error(errorMessage);
// Stop automation and mark session as failed
@@ -95,9 +100,14 @@ export class MockAutomationEngineAdapter implements IAutomationEngine {
if (nextStep.isFinalStep()) {
// Execute final step handler
if (this.browserAutomation.executeStep) {
const result = await this.browserAutomation.executeStep(nextStep, config as unknown as Record<string, unknown>);
const result = await this.browserAutomation.executeStep(
nextStep,
config as unknown as Record<string, unknown>,
);
if (!result.success) {
const errorMessage = `Step ${nextStep.value} (${getStepName(nextStep.value)}) failed: ${result.error}`;
const errorMessage = `Step ${nextStep.value} (${getStepName(
nextStep.value,
)}) failed: ${result.error}`;
console.error(errorMessage);
// Don't try to fail terminal session - just log the error
// Session is already in STOPPED_AT_STEP_18 state after transitionToStep()
@@ -118,6 +128,19 @@ export class MockAutomationEngineAdapter implements IAutomationEngine {
} catch (error) {
console.error('Automation error:', error);
this.isRunning = false;
try {
const sessions = await this.sessionRepository.findAll();
const session = sessions[0];
if (session && !session.state.isTerminal()) {
const message =
error instanceof Error ? error.message : String(error);
session.fail(`Automation error: ${message}`);
await this.sessionRepository.update(session);
}
} catch {
}
return;
}
}

View File

@@ -1,6 +1,5 @@
import { StepId } from '../../../domain/value-objects/StepId';
import { HostedSessionConfig } from '../../../domain/entities/HostedSessionConfig';
import type { IBrowserAutomation } from '../../../application/ports/IScreenAutomation';
import { StepId } from '../../../../domain/value-objects/StepId';
import type { IBrowserAutomation } from '../../../../application/ports/IScreenAutomation';
import {
NavigationResult,
FormFillResult,
@@ -8,7 +7,7 @@ import {
WaitResult,
ModalResult,
AutomationResult,
} from '../../../application/ports/AutomationResults';
} from '../../../../application/ports/AutomationResults';
interface MockConfig {
simulateFailures?: boolean;