|
| 1 | +import { ProgressType } from '../progress/progress-logger.js'; |
| 2 | +import { PackageSummary } from '@safety-web/types'; |
| 3 | +import { |
| 4 | + AgentOutput, |
| 5 | + BrowserAgentTaskInput, |
| 6 | +} from '../testing/browser-agent/models.js'; |
| 7 | +import { Result } from 'axe-core'; |
| 8 | +import { CspViolation } from './auto-csp-types.js'; |
| 9 | + |
| 10 | +/** |
| 11 | + * Represents the message structure used for communication between |
| 12 | + * the main process and the build worker process. |
| 13 | + */ |
| 14 | +export interface BuildWorkerMessage { |
| 15 | + directory: string; |
| 16 | + /** Name of the app. */ |
| 17 | + appName: string; |
| 18 | + /** Command used to build the app. */ |
| 19 | + buildCommand: string; |
| 20 | + /** Command used to start a development server. */ |
| 21 | + serveCommand: string; |
| 22 | + /** Command used to run tests for the app. */ |
| 23 | + testCommand?: string; |
| 24 | + /** |
| 25 | + * Whether this application should be invoked via Puppeteer and |
| 26 | + * runtime errors should be collected and reported. |
| 27 | + */ |
| 28 | + collectRuntimeErrors?: boolean; |
| 29 | + /** |
| 30 | + * Whether to take a screenshot of the application after a successful build. |
| 31 | + */ |
| 32 | + takeScreenshots?: boolean; |
| 33 | + /** |
| 34 | + * Whether or not to perform Axe testing of the application after a successful build. |
| 35 | + */ |
| 36 | + includeAxeTesting?: boolean; |
| 37 | + |
| 38 | + /** Whether to enable the auto CSP checks. */ |
| 39 | + enableAutoCsp?: boolean; |
| 40 | + |
| 41 | + /** User journey browser agent task input */ |
| 42 | + userJourneyAgentTaskInput?: BrowserAgentTaskInput; |
| 43 | +} |
| 44 | + |
| 45 | +export enum BuildResultStatus { |
| 46 | + SUCCESS = 'success', |
| 47 | + ERROR = 'error', |
| 48 | +} |
| 49 | + |
| 50 | +export enum BuildErrorType { |
| 51 | + MISSING_DEPENDENCY = 'Missing Dependency', // "[ERROR] Could not resolve" |
| 52 | + TYPESCRIPT_ERROR = 'TypeScript Error', // "[ERROR] TS\d+" |
| 53 | + ANGULAR_DIAGNOSTIC = 'Angular Diagnostic', // "[ERROR] NG\d+" |
| 54 | + OTHER = 'Other', |
| 55 | +} |
| 56 | + |
| 57 | +export interface BuildResult { |
| 58 | + status: BuildResultStatus; |
| 59 | + message: string; |
| 60 | + errorType?: BuildErrorType; |
| 61 | + screenshotPngUrl?: string; |
| 62 | + missingDependency?: string; |
| 63 | + runtimeErrors?: string; |
| 64 | + /** JSON report from the Safety Web runner, if available. */ |
| 65 | + safetyWebReportJson?: PackageSummary[]; |
| 66 | + userJourneyAgentOutput: AgentOutput | null; |
| 67 | + cspViolations?: CspViolation[]; |
| 68 | + axeViolations?: Result[]; |
| 69 | +} |
| 70 | + |
| 71 | +export interface BuildResultMessage { |
| 72 | + type: 'build'; |
| 73 | + payload: BuildResult; |
| 74 | +} |
| 75 | + |
| 76 | +export interface BuildProgressLogMessage { |
| 77 | + type: 'log'; |
| 78 | + payload: { |
| 79 | + state: ProgressType; |
| 80 | + message: string; |
| 81 | + details?: string; |
| 82 | + }; |
| 83 | +} |
| 84 | + |
| 85 | +export type BuilderProgressLogFn = ( |
| 86 | + state: ProgressType, |
| 87 | + message: string, |
| 88 | + details?: string |
| 89 | +) => void; |
| 90 | + |
| 91 | +export type BuildWorkerResponseMessage = |
| 92 | + | BuildResultMessage |
| 93 | + | BuildProgressLogMessage; |
| 94 | + |
| 95 | +export enum RepairType { |
| 96 | + Build = 'Build', |
| 97 | + Axe = 'Axe', |
| 98 | + Test = 'Test', |
| 99 | +} |
0 commit comments