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';
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;
}
}