mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-05-31 22:06:16 -07:00
Compare commits
5 Commits
feature/ho
...
feature/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5355c5211 | ||
|
|
70a78dab74 | ||
|
|
5e54bcd4dd | ||
|
|
118671778f | ||
|
|
8d81236939 |
36
action.yml
36
action.yml
@@ -279,35 +279,23 @@ inputs:
|
||||
description:
|
||||
'[Orchestrator] Specifies the repo for the unity builder. Useful if you forked the repo for testing, features, or
|
||||
fixes.'
|
||||
|
||||
hotRunnerEnabled:
|
||||
description: '[HotRunner] Use persistent hot runner for builds (requires pre-registered runners)'
|
||||
testSuitePath:
|
||||
description: 'Path to YAML test suite definition file'
|
||||
required: false
|
||||
default: 'false'
|
||||
hotRunnerTransport:
|
||||
description: '[HotRunner] Transport protocol for hot runner communication: websocket, grpc, named-pipe'
|
||||
testSuiteEvent:
|
||||
description: 'CI event name for suite selection (pr, push, release)'
|
||||
required: false
|
||||
default: 'websocket'
|
||||
hotRunnerHost:
|
||||
description: '[HotRunner] Hot runner host address'
|
||||
testTaxonomyPath:
|
||||
description: 'Path to custom taxonomy definition YAML'
|
||||
required: false
|
||||
default: 'localhost'
|
||||
hotRunnerPort:
|
||||
description: '[HotRunner] Hot runner port number'
|
||||
testResultFormat:
|
||||
description: 'Test result output format: junit, json, or both'
|
||||
required: false
|
||||
default: '9090'
|
||||
hotRunnerHealthInterval:
|
||||
description: '[HotRunner] Health check interval in seconds'
|
||||
default: 'junit'
|
||||
testResultPath:
|
||||
description: 'Directory for structured test result output'
|
||||
required: false
|
||||
default: '30'
|
||||
hotRunnerMaxIdle:
|
||||
description: '[HotRunner] Maximum idle time in seconds before recycling runner'
|
||||
required: false
|
||||
default: '3600'
|
||||
hotRunnerFallbackToCold:
|
||||
description: '[HotRunner] Fall back to cold build if no hot runner available'
|
||||
required: false
|
||||
default: 'true'
|
||||
default: './test-results'
|
||||
|
||||
outputs:
|
||||
volume:
|
||||
|
||||
1771
dist/index.js
generated
vendored
1771
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
93
src/index.ts
93
src/index.ts
@@ -3,8 +3,7 @@ import { Action, BuildParameters, Cache, Orchestrator, Docker, ImageTag, Output
|
||||
import { Cli } from './model/cli/cli';
|
||||
import MacBuilder from './model/mac-builder';
|
||||
import PlatformSetup from './model/platform-setup';
|
||||
import { HotRunnerService } from './model/orchestrator/services/hot-runner';
|
||||
import { HotRunnerConfig } from './model/orchestrator/services/hot-runner/hot-runner-types';
|
||||
import { TestWorkflowService } from './model/orchestrator/services/test-workflow';
|
||||
|
||||
async function runMain() {
|
||||
try {
|
||||
@@ -19,50 +18,38 @@ async function runMain() {
|
||||
const { workspace, actionFolder } = Action;
|
||||
|
||||
const buildParameters = await BuildParameters.create();
|
||||
|
||||
// If a test suite path is provided, use the test workflow engine
|
||||
// instead of the standard build execution path
|
||||
if (buildParameters.testSuitePath) {
|
||||
core.info('[TestWorkflow] Test suite path detected, using test workflow engine');
|
||||
const results = await TestWorkflowService.executeTestSuite(buildParameters.testSuitePath, buildParameters);
|
||||
|
||||
const totalFailed = results.reduce((sum, r) => sum + r.failed, 0);
|
||||
if (totalFailed > 0) {
|
||||
core.setFailed(`Test workflow completed with ${totalFailed} failure(s)`);
|
||||
} else {
|
||||
core.info('[TestWorkflow] All test runs passed');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const baseImage = new ImageTag(buildParameters);
|
||||
|
||||
let exitCode = -1;
|
||||
|
||||
// Hot runner path: attempt to use a persistent Unity editor instance
|
||||
if (buildParameters.hotRunnerEnabled) {
|
||||
core.info('[HotRunner] Hot runner mode enabled, attempting hot build...');
|
||||
|
||||
const hotRunnerConfig: HotRunnerConfig = {
|
||||
enabled: true,
|
||||
transport: buildParameters.hotRunnerTransport,
|
||||
host: buildParameters.hotRunnerHost,
|
||||
port: buildParameters.hotRunnerPort,
|
||||
healthCheckInterval: buildParameters.hotRunnerHealthInterval,
|
||||
maxIdleTime: buildParameters.hotRunnerMaxIdle,
|
||||
maxJobsBeforeRecycle: 0, // no automatic recycle by job count
|
||||
};
|
||||
|
||||
const hotRunnerService = new HotRunnerService();
|
||||
|
||||
try {
|
||||
await hotRunnerService.initialize(hotRunnerConfig);
|
||||
const result = await hotRunnerService.submitBuild(buildParameters, (output) => {
|
||||
core.info(output);
|
||||
});
|
||||
|
||||
exitCode = result.exitCode;
|
||||
core.info(`[HotRunner] Build completed with exit code ${exitCode}`);
|
||||
await hotRunnerService.shutdown();
|
||||
} catch (hotRunnerError) {
|
||||
await hotRunnerService.shutdown();
|
||||
|
||||
if (buildParameters.hotRunnerFallbackToCold) {
|
||||
core.warning(
|
||||
`[HotRunner] Hot runner failed: ${(hotRunnerError as Error).message}. Falling back to cold build.`,
|
||||
);
|
||||
exitCode = await runColdBuild(buildParameters, baseImage, workspace, actionFolder);
|
||||
} else {
|
||||
throw hotRunnerError;
|
||||
}
|
||||
}
|
||||
} else if (buildParameters.providerStrategy === 'local') {
|
||||
if (buildParameters.providerStrategy === 'local') {
|
||||
core.info('Building locally');
|
||||
exitCode = await runColdBuild(buildParameters, baseImage, workspace, actionFolder);
|
||||
await PlatformSetup.setup(buildParameters, actionFolder);
|
||||
exitCode =
|
||||
process.platform === 'darwin'
|
||||
? await MacBuilder.run(actionFolder)
|
||||
: await Docker.run(baseImage.toString(), {
|
||||
workspace,
|
||||
actionFolder,
|
||||
...buildParameters,
|
||||
});
|
||||
} else {
|
||||
await Orchestrator.run(buildParameters, baseImage.toString());
|
||||
exitCode = 0;
|
||||
@@ -81,28 +68,4 @@ async function runMain() {
|
||||
}
|
||||
}
|
||||
|
||||
async function runColdBuild(
|
||||
buildParameters: BuildParameters,
|
||||
baseImage: ImageTag,
|
||||
workspace: string,
|
||||
actionFolder: string,
|
||||
): Promise<number> {
|
||||
if (buildParameters.providerStrategy === 'local') {
|
||||
core.info('Building locally');
|
||||
await PlatformSetup.setup(buildParameters, actionFolder);
|
||||
|
||||
return process.platform === 'darwin'
|
||||
? await MacBuilder.run(actionFolder)
|
||||
: await Docker.run(baseImage.toString(), {
|
||||
workspace,
|
||||
actionFolder,
|
||||
...buildParameters,
|
||||
});
|
||||
} else {
|
||||
await Orchestrator.run(buildParameters, baseImage.toString());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
runMain();
|
||||
|
||||
@@ -106,13 +106,12 @@ class BuildParameters {
|
||||
public cacheUnityInstallationOnMac!: boolean;
|
||||
public unityHubVersionOnMac!: string;
|
||||
public dockerWorkspacePath!: string;
|
||||
public hotRunnerEnabled!: boolean;
|
||||
public hotRunnerTransport!: 'websocket' | 'grpc' | 'named-pipe';
|
||||
public hotRunnerHost!: string;
|
||||
public hotRunnerPort!: number;
|
||||
public hotRunnerHealthInterval!: number;
|
||||
public hotRunnerMaxIdle!: number;
|
||||
public hotRunnerFallbackToCold!: boolean;
|
||||
|
||||
public testSuitePath!: string;
|
||||
public testSuiteEvent!: string;
|
||||
public testTaxonomyPath!: string;
|
||||
public testResultFormat!: string;
|
||||
public testResultPath!: string;
|
||||
|
||||
public static shouldUseRetainedWorkspaceMode(buildParameters: BuildParameters) {
|
||||
return buildParameters.maxRetainedWorkspaces > 0 && Orchestrator.lockedWorkspace !== ``;
|
||||
@@ -249,13 +248,11 @@ class BuildParameters {
|
||||
cacheUnityInstallationOnMac: Input.cacheUnityInstallationOnMac,
|
||||
unityHubVersionOnMac: Input.unityHubVersionOnMac,
|
||||
dockerWorkspacePath: Input.dockerWorkspacePath,
|
||||
hotRunnerEnabled: Input.hotRunnerEnabled,
|
||||
hotRunnerTransport: Input.hotRunnerTransport,
|
||||
hotRunnerHost: Input.hotRunnerHost,
|
||||
hotRunnerPort: Input.hotRunnerPort,
|
||||
hotRunnerHealthInterval: Input.hotRunnerHealthInterval,
|
||||
hotRunnerMaxIdle: Input.hotRunnerMaxIdle,
|
||||
hotRunnerFallbackToCold: Input.hotRunnerFallbackToCold,
|
||||
testSuitePath: Input.testSuitePath,
|
||||
testSuiteEvent: Input.testSuiteEvent,
|
||||
testTaxonomyPath: Input.testTaxonomyPath,
|
||||
testResultFormat: Input.testResultFormat,
|
||||
testResultPath: Input.testResultPath,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -282,36 +282,24 @@ class Input {
|
||||
return Input.getInput('skipActivation')?.toLowerCase() ?? 'false';
|
||||
}
|
||||
|
||||
static get hotRunnerEnabled(): boolean {
|
||||
const input = Input.getInput('hotRunnerEnabled') ?? false;
|
||||
|
||||
return input === 'true';
|
||||
static get testSuitePath(): string {
|
||||
return Input.getInput('testSuitePath') ?? '';
|
||||
}
|
||||
|
||||
static get hotRunnerTransport(): 'websocket' | 'grpc' | 'named-pipe' {
|
||||
return (Input.getInput('hotRunnerTransport') ?? 'websocket') as 'websocket' | 'grpc' | 'named-pipe';
|
||||
static get testSuiteEvent(): string {
|
||||
return Input.getInput('testSuiteEvent') ?? '';
|
||||
}
|
||||
|
||||
static get hotRunnerHost(): string {
|
||||
return Input.getInput('hotRunnerHost') ?? 'localhost';
|
||||
static get testTaxonomyPath(): string {
|
||||
return Input.getInput('testTaxonomyPath') ?? '';
|
||||
}
|
||||
|
||||
static get hotRunnerPort(): number {
|
||||
return Number.parseInt(Input.getInput('hotRunnerPort') ?? '9090', 10);
|
||||
static get testResultFormat(): string {
|
||||
return Input.getInput('testResultFormat') ?? 'junit';
|
||||
}
|
||||
|
||||
static get hotRunnerHealthInterval(): number {
|
||||
return Number.parseInt(Input.getInput('hotRunnerHealthInterval') ?? '30', 10);
|
||||
}
|
||||
|
||||
static get hotRunnerMaxIdle(): number {
|
||||
return Number.parseInt(Input.getInput('hotRunnerMaxIdle') ?? '3600', 10);
|
||||
}
|
||||
|
||||
static get hotRunnerFallbackToCold(): boolean {
|
||||
const input = Input.getInput('hotRunnerFallbackToCold') ?? 'true';
|
||||
|
||||
return input === 'true';
|
||||
static get testResultPath(): string {
|
||||
return Input.getInput('testResultPath') ?? './test-results';
|
||||
}
|
||||
|
||||
public static ToEnvVarFormat(input: string) {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# Hot Runner Protocol
|
||||
|
||||
Extensible runner registration and persistent Unity editor provider protocol.
|
||||
|
||||
See GitHub Issue for full specification.
|
||||
@@ -1,159 +0,0 @@
|
||||
import OrchestratorLogger from '../core/orchestrator-logger';
|
||||
import { HotRunnerRegistry } from './hot-runner-registry';
|
||||
import { HotRunnerJobRequest, HotRunnerJobResult, HotRunnerStatus, HotRunnerTransport } from './hot-runner-types';
|
||||
|
||||
const POLL_INTERVAL_MS = 1000;
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
export type OutputCallback = (output: string) => void;
|
||||
|
||||
export class HotRunnerDispatcher {
|
||||
private transports: Map<string, HotRunnerTransport>;
|
||||
|
||||
constructor(transports: Map<string, HotRunnerTransport>) {
|
||||
this.transports = transports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a job to an available hot runner matching the request's build target.
|
||||
* If no runner is immediately available, waits up to the request timeout.
|
||||
* Returns the job result, or throws if no runner becomes available in time.
|
||||
*/
|
||||
async dispatchJob(
|
||||
request: HotRunnerJobRequest,
|
||||
registry: HotRunnerRegistry,
|
||||
unityVersion: string,
|
||||
onOutput?: OutputCallback,
|
||||
): Promise<HotRunnerJobResult> {
|
||||
OrchestratorLogger.log(`[HotRunner] Dispatching job ${request.jobId} (target: ${request.buildTarget})`);
|
||||
|
||||
// Find or wait for an available runner
|
||||
let runner = registry.findAvailableRunner({
|
||||
unityVersion,
|
||||
platform: request.buildTarget,
|
||||
});
|
||||
|
||||
if (!runner) {
|
||||
OrchestratorLogger.log(
|
||||
`[HotRunner] No idle runner available for ${unityVersion}/${request.buildTarget}, waiting...`,
|
||||
);
|
||||
runner = await this.waitForRunner({ unityVersion, platform: request.buildTarget }, request.timeout, registry);
|
||||
}
|
||||
|
||||
// Mark runner as busy
|
||||
registry.updateRunner(runner.id, {
|
||||
state: 'busy',
|
||||
currentJob: request.jobId,
|
||||
});
|
||||
|
||||
const transport = this.transports.get(runner.id);
|
||||
if (!transport) {
|
||||
registry.updateRunner(runner.id, { state: 'idle', currentJob: undefined });
|
||||
throw new Error(`[HotRunner] No transport available for runner ${runner.id}`);
|
||||
}
|
||||
|
||||
OrchestratorLogger.log(`[HotRunner] Sending job ${request.jobId} to runner ${runner.id}`);
|
||||
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
const result = await this.executeWithTimeout(transport, request);
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
OrchestratorLogger.log(
|
||||
`[HotRunner] Job ${request.jobId} completed on runner ${runner.id} in ${duration}ms (exit: ${result.exitCode})`,
|
||||
);
|
||||
|
||||
if (onOutput && result.output) {
|
||||
onOutput(result.output);
|
||||
}
|
||||
|
||||
// Mark runner as idle and increment job count
|
||||
const currentStatus = registry.getRunner(runner.id);
|
||||
registry.updateRunner(runner.id, {
|
||||
state: 'idle',
|
||||
currentJob: undefined,
|
||||
lastJobCompleted: request.jobId,
|
||||
jobsCompleted: (currentStatus?.jobsCompleted ?? 0) + 1,
|
||||
});
|
||||
|
||||
return result;
|
||||
} catch (error: any) {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Job ${request.jobId} failed on runner ${runner.id}: ${error.message}`);
|
||||
|
||||
// Mark runner as idle despite failure -- the health monitor will recycle if needed
|
||||
registry.updateRunner(runner.id, {
|
||||
state: 'idle',
|
||||
currentJob: undefined,
|
||||
});
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for an available runner matching the requirements.
|
||||
* Polls the registry at a fixed interval until one becomes available or timeout expires.
|
||||
*/
|
||||
async waitForRunner(
|
||||
requirements: { unityVersion: string; platform: string },
|
||||
timeoutMs: number,
|
||||
registry: HotRunnerRegistry,
|
||||
): Promise<HotRunnerStatus> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
const runner = registry.findAvailableRunner(requirements);
|
||||
if (runner) {
|
||||
OrchestratorLogger.log(`[HotRunner] Runner ${runner.id} became available`);
|
||||
|
||||
return runner;
|
||||
}
|
||||
|
||||
await this.sleep(Math.min(POLL_INTERVAL_MS, deadline - Date.now()));
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`[HotRunner] Timed out waiting for available runner (${requirements.unityVersion}/${requirements.platform}) after ${timeoutMs}ms`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a job on a transport with a timeout guard.
|
||||
* On timeout, disconnects the transport to release the connection
|
||||
* and prevent the orphaned sendJob promise from holding resources.
|
||||
*/
|
||||
private async executeWithTimeout(
|
||||
transport: HotRunnerTransport,
|
||||
request: HotRunnerJobRequest,
|
||||
): Promise<HotRunnerJobResult> {
|
||||
const TIMEOUT_SENTINEL = Symbol('timeout');
|
||||
|
||||
const timeoutPromise = new Promise<typeof TIMEOUT_SENTINEL>((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(TIMEOUT_SENTINEL);
|
||||
}, request.timeout);
|
||||
});
|
||||
|
||||
const result = await Promise.race([transport.sendJob(request), timeoutPromise]);
|
||||
|
||||
if (result === TIMEOUT_SENTINEL) {
|
||||
// Disconnect the transport to clean up the orphaned sendJob call
|
||||
try {
|
||||
await transport.disconnect();
|
||||
} catch (disconnectError: any) {
|
||||
OrchestratorLogger.logWarning(
|
||||
`[HotRunner] Error disconnecting transport after timeout for job ${request.jobId}: ${disconnectError.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(`[HotRunner] Job ${request.jobId} timed out after ${request.timeout}ms`);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
import OrchestratorLogger from '../core/orchestrator-logger';
|
||||
import { HotRunnerRegistry } from './hot-runner-registry';
|
||||
import { HotRunnerTransport } from './hot-runner-types';
|
||||
|
||||
export class HotRunnerHealthMonitor {
|
||||
private intervalHandle: ReturnType<typeof setInterval> | undefined;
|
||||
private registry: HotRunnerRegistry | undefined;
|
||||
private transports: Map<string, HotRunnerTransport> = new Map();
|
||||
|
||||
/**
|
||||
* Start periodic health monitoring for all registered runners.
|
||||
*/
|
||||
startMonitoring(registry: HotRunnerRegistry, interval: number, transports: Map<string, HotRunnerTransport>): void {
|
||||
if (this.intervalHandle) {
|
||||
this.stopMonitoring();
|
||||
}
|
||||
|
||||
this.registry = registry;
|
||||
this.transports = transports;
|
||||
|
||||
OrchestratorLogger.log(`[HotRunner] Starting health monitoring (interval: ${interval}s)`);
|
||||
|
||||
this.intervalHandle = setInterval(() => {
|
||||
this.runHealthChecks().catch((error: any) => {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Health check cycle failed: ${error.message}`);
|
||||
});
|
||||
}, interval * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop periodic health monitoring.
|
||||
*/
|
||||
stopMonitoring(): void {
|
||||
if (this.intervalHandle) {
|
||||
clearInterval(this.intervalHandle);
|
||||
this.intervalHandle = undefined;
|
||||
OrchestratorLogger.log(`[HotRunner] Health monitoring stopped`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check health of a specific runner by ID. Returns true if healthy.
|
||||
*/
|
||||
async checkHealth(runnerId: string): Promise<boolean> {
|
||||
if (!this.registry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const transport = this.transports.get(runnerId);
|
||||
if (!transport) {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] No transport for runner ${runnerId}`);
|
||||
this.registry.updateRunner(runnerId, {
|
||||
state: 'unhealthy',
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const healthy = await transport.healthCheck();
|
||||
if (healthy) {
|
||||
const status = await transport.getStatus();
|
||||
this.registry.updateRunner(runnerId, {
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
memoryUsageMB: status.memoryUsageMB,
|
||||
uptime: status.uptime,
|
||||
libraryHash: status.libraryHash,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Runner ${runnerId} health check returned false`);
|
||||
this.registry.updateRunner(runnerId, {
|
||||
state: 'unhealthy',
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
});
|
||||
|
||||
return false;
|
||||
} catch (error: any) {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Runner ${runnerId} health check failed: ${error.message}`);
|
||||
this.registry.updateRunner(runnerId, {
|
||||
state: 'unhealthy',
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark an unhealthy runner for cleanup and disconnect its transport.
|
||||
*/
|
||||
async recycleUnhealthyRunner(runnerId: string): Promise<void> {
|
||||
if (!this.registry) {
|
||||
return;
|
||||
}
|
||||
|
||||
OrchestratorLogger.log(`[HotRunner] Recycling unhealthy runner ${runnerId}`);
|
||||
this.registry.updateRunner(runnerId, { state: 'stopping' });
|
||||
|
||||
const transport = this.transports.get(runnerId);
|
||||
if (transport) {
|
||||
try {
|
||||
await transport.disconnect();
|
||||
} catch (error: any) {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Error disconnecting runner ${runnerId}: ${error.message}`);
|
||||
}
|
||||
this.transports.delete(runnerId);
|
||||
}
|
||||
|
||||
this.registry.unregisterRunner(runnerId);
|
||||
OrchestratorLogger.log(`[HotRunner] Runner ${runnerId} recycled and removed`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recycle a runner that has been idle longer than the maximum idle time.
|
||||
*/
|
||||
async recycleIdleRunner(runnerId: string, maxIdleTime: number): Promise<void> {
|
||||
if (!this.registry) {
|
||||
return;
|
||||
}
|
||||
|
||||
const runner = this.registry.getRunner(runnerId);
|
||||
if (!runner || runner.state !== 'idle') {
|
||||
return;
|
||||
}
|
||||
|
||||
const lastCheckTime = new Date(runner.lastHealthCheck).getTime();
|
||||
const now = Date.now();
|
||||
const idleSeconds = (now - lastCheckTime) / 1000;
|
||||
|
||||
if (idleSeconds >= maxIdleTime) {
|
||||
OrchestratorLogger.log(
|
||||
`[HotRunner] Runner ${runnerId} idle for ${Math.floor(idleSeconds)}s (max: ${maxIdleTime}s), recycling`,
|
||||
);
|
||||
await this.recycleUnhealthyRunner(runnerId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run health checks and idle-recycle checks for all registered runners.
|
||||
*/
|
||||
private async runHealthChecks(): Promise<void> {
|
||||
if (!this.registry) {
|
||||
return;
|
||||
}
|
||||
|
||||
const runners = this.registry.listRunners();
|
||||
|
||||
for (const runner of runners) {
|
||||
if (runner.state === 'stopping') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const healthy = await this.checkHealth(runner.id);
|
||||
|
||||
if (!healthy && runner.state !== 'starting') {
|
||||
await this.recycleUnhealthyRunner(runner.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for idle timeout
|
||||
const config = this.registry.getConfig(runner.id);
|
||||
if (config && runner.state === 'idle') {
|
||||
await this.recycleIdleRunner(runner.id, config.maxIdleTime);
|
||||
}
|
||||
|
||||
// Check for max jobs before recycle
|
||||
if (config && config.maxJobsBeforeRecycle > 0 && runner.jobsCompleted >= config.maxJobsBeforeRecycle) {
|
||||
OrchestratorLogger.log(
|
||||
`[HotRunner] Runner ${runner.id} reached max jobs (${runner.jobsCompleted}/${config.maxJobsBeforeRecycle}), recycling`,
|
||||
);
|
||||
await this.recycleUnhealthyRunner(runner.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether health monitoring is currently active.
|
||||
*/
|
||||
get isMonitoring(): boolean {
|
||||
return this.intervalHandle !== undefined;
|
||||
}
|
||||
}
|
||||
@@ -1,315 +0,0 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { customAlphabet } from 'nanoid';
|
||||
import OrchestratorLogger from '../core/orchestrator-logger';
|
||||
import { HotRunnerConfig, HotRunnerStatus } from './hot-runner-types';
|
||||
|
||||
const generateId = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 12);
|
||||
|
||||
const PERSISTENCE_FILENAME = 'hot-runners.json';
|
||||
|
||||
const VALID_RUNNER_STATES: ReadonlySet<string> = new Set(['idle', 'busy', 'starting', 'stopping', 'unhealthy']);
|
||||
|
||||
export interface HotRunnerFilter {
|
||||
platform?: string;
|
||||
state?: string;
|
||||
unityVersion?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a restored runner entry has all required fields with correct types.
|
||||
* Returns true if the entry is a valid HotRunnerStatus, false otherwise.
|
||||
*/
|
||||
function isValidRunnerStatus(entry: unknown): entry is HotRunnerStatus {
|
||||
if (typeof entry !== 'object' || entry === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const record = entry as Record<string, unknown>;
|
||||
|
||||
return (
|
||||
typeof record.id === 'string' &&
|
||||
record.id.length > 0 &&
|
||||
typeof record.state === 'string' &&
|
||||
VALID_RUNNER_STATES.has(record.state) &&
|
||||
typeof record.unityVersion === 'string' &&
|
||||
typeof record.platform === 'string' &&
|
||||
typeof record.uptime === 'number' &&
|
||||
typeof record.jobsCompleted === 'number' &&
|
||||
typeof record.lastHealthCheck === 'string' &&
|
||||
typeof record.memoryUsageMB === 'number'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a restored config entry has all required fields with correct types.
|
||||
* Returns true if the entry is a valid HotRunnerConfig, false otherwise.
|
||||
*/
|
||||
function isValidRunnerConfig(entry: unknown): entry is HotRunnerConfig {
|
||||
if (typeof entry !== 'object' || entry === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const record = entry as Record<string, unknown>;
|
||||
|
||||
return (
|
||||
typeof record.enabled === 'boolean' &&
|
||||
typeof record.transport === 'string' &&
|
||||
['websocket', 'grpc', 'named-pipe'].includes(record.transport) &&
|
||||
typeof record.host === 'string' &&
|
||||
typeof record.port === 'number' &&
|
||||
typeof record.healthCheckInterval === 'number' &&
|
||||
typeof record.maxIdleTime === 'number' &&
|
||||
typeof record.maxJobsBeforeRecycle === 'number'
|
||||
);
|
||||
}
|
||||
|
||||
export class HotRunnerRegistry {
|
||||
private runners: Map<string, HotRunnerStatus> = new Map();
|
||||
private configs: Map<string, HotRunnerConfig> = new Map();
|
||||
private persistencePath: string;
|
||||
|
||||
constructor(persistenceDirectory?: string) {
|
||||
this.persistencePath = persistenceDirectory ? path.join(persistenceDirectory, PERSISTENCE_FILENAME) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new hot runner. Returns the generated runner ID.
|
||||
*/
|
||||
registerRunner(config: HotRunnerConfig): string {
|
||||
const id = `hr-${generateId()}`;
|
||||
|
||||
const status: HotRunnerStatus = {
|
||||
id,
|
||||
state: 'starting',
|
||||
unityVersion: config.unityVersion ?? 'unknown',
|
||||
platform: config.platform ?? 'unknown',
|
||||
uptime: 0,
|
||||
jobsCompleted: 0,
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
memoryUsageMB: 0,
|
||||
};
|
||||
|
||||
this.runners.set(id, status);
|
||||
this.configs.set(id, config);
|
||||
OrchestratorLogger.log(`[HotRunner] Registered runner ${id} (${status.unityVersion}/${status.platform})`);
|
||||
|
||||
this.persist();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a runner from the registry.
|
||||
*/
|
||||
unregisterRunner(id: string): void {
|
||||
const existed = this.runners.delete(id);
|
||||
this.configs.delete(id);
|
||||
|
||||
if (existed) {
|
||||
OrchestratorLogger.log(`[HotRunner] Unregistered runner ${id}`);
|
||||
this.persist();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a runner's current status by ID.
|
||||
*/
|
||||
getRunner(id: string): HotRunnerStatus | undefined {
|
||||
return this.runners.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a runner's config by ID.
|
||||
*/
|
||||
getConfig(id: string): HotRunnerConfig | undefined {
|
||||
return this.configs.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all runners, optionally filtered by platform, state, or Unity version.
|
||||
*/
|
||||
listRunners(filter?: HotRunnerFilter): HotRunnerStatus[] {
|
||||
let results = [...this.runners.values()];
|
||||
|
||||
if (filter?.platform) {
|
||||
results = results.filter((runner) => runner.platform === filter.platform);
|
||||
}
|
||||
|
||||
if (filter?.state) {
|
||||
results = results.filter((runner) => runner.state === filter.state);
|
||||
}
|
||||
|
||||
if (filter?.unityVersion) {
|
||||
results = results.filter((runner) => runner.unityVersion === filter.unityVersion);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an idle runner matching the given Unity version and platform requirements.
|
||||
*/
|
||||
findAvailableRunner(requirements: { unityVersion: string; platform: string }): HotRunnerStatus | undefined {
|
||||
return this.listRunners({
|
||||
state: 'idle',
|
||||
unityVersion: requirements.unityVersion,
|
||||
platform: requirements.platform,
|
||||
})[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a runner's status fields. Merges partial updates into existing status.
|
||||
*/
|
||||
updateRunner(id: string, update: Partial<HotRunnerStatus>): void {
|
||||
const existing = this.runners.get(id);
|
||||
if (!existing) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.runners.set(id, { ...existing, ...update, id });
|
||||
this.persist();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of registered runners.
|
||||
*/
|
||||
get size(): number {
|
||||
return this.runners.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate all runners in the registry and reset invalid ones to 'unhealthy'.
|
||||
* Returns the number of runners that were repaired.
|
||||
*/
|
||||
validateAndRepair(): number {
|
||||
let repaired = 0;
|
||||
|
||||
for (const [id, status] of this.runners) {
|
||||
// Cast to unknown to bypass the type guard narrowing to 'never',
|
||||
// since the Map is typed as HotRunnerStatus but entries may have
|
||||
// been corrupted via direct deserialization or unsafe casts.
|
||||
const entry = status as unknown as Record<string, unknown>;
|
||||
|
||||
if (!isValidRunnerStatus(entry)) {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Runner ${id} has invalid state, marking as unhealthy`);
|
||||
this.runners.set(id, {
|
||||
id,
|
||||
state: 'unhealthy',
|
||||
unityVersion: typeof entry.unityVersion === 'string' ? entry.unityVersion : 'unknown',
|
||||
platform: typeof entry.platform === 'string' ? entry.platform : 'unknown',
|
||||
uptime: typeof entry.uptime === 'number' ? entry.uptime : 0,
|
||||
jobsCompleted: typeof entry.jobsCompleted === 'number' ? entry.jobsCompleted : 0,
|
||||
lastHealthCheck: typeof entry.lastHealthCheck === 'string' ? entry.lastHealthCheck : new Date().toISOString(),
|
||||
memoryUsageMB: typeof entry.memoryUsageMB === 'number' ? entry.memoryUsageMB : 0,
|
||||
});
|
||||
repaired++;
|
||||
}
|
||||
}
|
||||
|
||||
if (repaired > 0) {
|
||||
this.persist();
|
||||
}
|
||||
|
||||
return repaired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist current registry state to disk for crash recovery.
|
||||
* Validates data before writing to prevent persisting corrupt state.
|
||||
*/
|
||||
private persist(): void {
|
||||
if (!this.persistencePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Validate data before persisting
|
||||
for (const [id, status] of this.runners) {
|
||||
if (!isValidRunnerStatus(status)) {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Skipping persistence -- runner ${id} has invalid state`);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const data = {
|
||||
runners: Object.fromEntries(this.runners),
|
||||
configs: Object.fromEntries(this.configs),
|
||||
};
|
||||
const directory = path.dirname(this.persistencePath);
|
||||
if (!fs.existsSync(directory)) {
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
}
|
||||
|
||||
fs.writeFileSync(this.persistencePath, JSON.stringify(data, undefined, 2));
|
||||
} catch (error: any) {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Failed to persist registry: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load registry state from disk. Returns the number of runners restored.
|
||||
* Validates each restored entry and discards corrupt entries with warnings.
|
||||
* If the persistence file itself is corrupt (invalid JSON), starts with
|
||||
* an empty registry.
|
||||
*/
|
||||
loadFromDisk(): number {
|
||||
if (!this.persistencePath || !fs.existsSync(this.persistencePath)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let data: any;
|
||||
|
||||
try {
|
||||
const raw = fs.readFileSync(this.persistencePath, 'utf8');
|
||||
data = JSON.parse(raw);
|
||||
} catch (error: any) {
|
||||
OrchestratorLogger.logWarning(
|
||||
`[HotRunner] Persistence file is corrupt, starting with empty registry: ${error.message}`,
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (typeof data !== 'object' || data === null) {
|
||||
OrchestratorLogger.logWarning('[HotRunner] Persistence file has invalid structure, starting with empty registry');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
let discarded = 0;
|
||||
|
||||
if (data.runners && typeof data.runners === 'object') {
|
||||
for (const [id, status] of Object.entries(data.runners)) {
|
||||
if (isValidRunnerStatus(status)) {
|
||||
this.runners.set(id, status);
|
||||
} else {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Discarding invalid runner entry '${id}' from persistence file`);
|
||||
discarded++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.configs && typeof data.configs === 'object') {
|
||||
for (const [id, config] of Object.entries(data.configs)) {
|
||||
// Only restore configs for runners that were successfully restored
|
||||
if (this.runners.has(id)) {
|
||||
if (isValidRunnerConfig(config)) {
|
||||
this.configs.set(id, config);
|
||||
} else {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Discarding invalid config entry '${id}' from persistence file`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (discarded > 0) {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Discarded ${discarded} invalid runner(s) from persistence file`);
|
||||
}
|
||||
|
||||
OrchestratorLogger.log(`[HotRunner] Restored ${this.runners.size} runner(s) from disk`);
|
||||
|
||||
return this.runners.size;
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
import OrchestratorLogger from '../core/orchestrator-logger';
|
||||
import { HotRunnerRegistry } from './hot-runner-registry';
|
||||
import { HotRunnerHealthMonitor } from './hot-runner-health-monitor';
|
||||
import { HotRunnerDispatcher, OutputCallback } from './hot-runner-dispatcher';
|
||||
import {
|
||||
HotRunnerConfig,
|
||||
HotRunnerJobRequest,
|
||||
HotRunnerJobResult,
|
||||
HotRunnerStatus,
|
||||
HotRunnerTransport,
|
||||
} from './hot-runner-types';
|
||||
import BuildParameters from '../../../build-parameters';
|
||||
|
||||
export class HotRunnerService {
|
||||
private registry: HotRunnerRegistry;
|
||||
private healthMonitor: HotRunnerHealthMonitor;
|
||||
private dispatcher: HotRunnerDispatcher;
|
||||
private transports: Map<string, HotRunnerTransport> = new Map();
|
||||
private config: HotRunnerConfig | undefined;
|
||||
|
||||
constructor(persistenceDirectory?: string) {
|
||||
this.registry = new HotRunnerRegistry(persistenceDirectory);
|
||||
this.healthMonitor = new HotRunnerHealthMonitor();
|
||||
this.dispatcher = new HotRunnerDispatcher(this.transports);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the hot runner service: load persisted state, start health monitoring.
|
||||
*/
|
||||
async initialize(config: HotRunnerConfig): Promise<void> {
|
||||
this.config = config;
|
||||
|
||||
OrchestratorLogger.log(
|
||||
`[HotRunner] Initializing service (transport: ${config.transport}, ${config.host}:${config.port})`,
|
||||
);
|
||||
|
||||
// Attempt to restore previously registered runners from disk
|
||||
const restored = this.registry.loadFromDisk();
|
||||
if (restored > 0) {
|
||||
OrchestratorLogger.log(`[HotRunner] Restored ${restored} runner(s) from persistence`);
|
||||
}
|
||||
|
||||
// Start health monitoring
|
||||
this.healthMonitor.startMonitoring(this.registry, config.healthCheckInterval, this.transports);
|
||||
|
||||
OrchestratorLogger.log(`[HotRunner] Service initialized`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a runner with a transport implementation.
|
||||
* Returns the runner ID.
|
||||
*/
|
||||
registerRunner(config: HotRunnerConfig, transport: HotRunnerTransport): string {
|
||||
const id = this.registry.registerRunner(config);
|
||||
this.transports.set(id, transport);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a build job to an available hot runner.
|
||||
* Converts BuildParameters to a HotRunnerJobRequest and dispatches.
|
||||
*/
|
||||
async submitBuild(params: BuildParameters, onOutput?: OutputCallback): Promise<HotRunnerJobResult> {
|
||||
const request: HotRunnerJobRequest = {
|
||||
jobId: params.buildGuid || `build-${Date.now()}`,
|
||||
buildMethod: params.buildMethod || undefined,
|
||||
buildTarget: params.targetPlatform,
|
||||
buildPath: params.buildPath,
|
||||
customParameters: params.customParameters ? this.parseCustomParameters(params.customParameters) : undefined,
|
||||
timeout: 30 * 60 * 1000, // 30 minutes default
|
||||
};
|
||||
|
||||
OrchestratorLogger.log(`[HotRunner] Submitting build: ${request.jobId} (target: ${request.buildTarget})`);
|
||||
|
||||
return this.dispatcher.dispatchJob(request, this.registry, params.editorVersion, onOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a test job to an available hot runner.
|
||||
* Converts BuildParameters and optional suite config to a test-mode HotRunnerJobRequest.
|
||||
*/
|
||||
async submitTest(
|
||||
params: BuildParameters,
|
||||
suiteConfig?: { testMode?: 'editmode' | 'playmode'; testSuitePath?: string },
|
||||
onOutput?: OutputCallback,
|
||||
): Promise<HotRunnerJobResult> {
|
||||
const request: HotRunnerJobRequest = {
|
||||
jobId: params.buildGuid || `test-${Date.now()}`,
|
||||
buildTarget: params.targetPlatform,
|
||||
customParameters: params.customParameters ? this.parseCustomParameters(params.customParameters) : undefined,
|
||||
timeout: 30 * 60 * 1000, // 30 minutes default
|
||||
testMode: suiteConfig?.testMode ?? 'editmode',
|
||||
testSuitePath: suiteConfig?.testSuitePath,
|
||||
};
|
||||
|
||||
OrchestratorLogger.log(`[HotRunner] Submitting test: ${request.jobId} (mode: ${request.testMode})`);
|
||||
|
||||
return this.dispatcher.dispatchJob(request, this.registry, params.editorVersion, onOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down the service: stop health monitoring, disconnect all transports,
|
||||
* and unregister all runners.
|
||||
*/
|
||||
async shutdown(): Promise<void> {
|
||||
OrchestratorLogger.log(`[HotRunner] Shutting down service`);
|
||||
|
||||
this.healthMonitor.stopMonitoring();
|
||||
|
||||
const disconnectPromises: Promise<void>[] = [];
|
||||
for (const [id, transport] of this.transports.entries()) {
|
||||
disconnectPromises.push(
|
||||
transport.disconnect().catch((error: any) => {
|
||||
OrchestratorLogger.logWarning(`[HotRunner] Error disconnecting runner ${id}: ${error.message}`);
|
||||
}),
|
||||
);
|
||||
}
|
||||
await Promise.all(disconnectPromises);
|
||||
|
||||
this.transports.clear();
|
||||
|
||||
OrchestratorLogger.log(`[HotRunner] Service shut down`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of all registered runners.
|
||||
*/
|
||||
getStatus(): HotRunnerStatus[] {
|
||||
return this.registry.listRunners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying registry (for testing or advanced use).
|
||||
*/
|
||||
getRegistry(): HotRunnerRegistry {
|
||||
return this.registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a space-separated custom parameters string into a key-value map.
|
||||
* Handles `-key value` and `-key=value` formats.
|
||||
*/
|
||||
private parseCustomParameters(raw: string): Record<string, string> {
|
||||
const result: Record<string, string> = {};
|
||||
const parts = raw.trim().split(/\s+/);
|
||||
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const part = parts[i];
|
||||
if (part.startsWith('-')) {
|
||||
const key = part.replace(/^-+/, '');
|
||||
if (key.includes('=')) {
|
||||
const [k, ...v] = key.split('=');
|
||||
result[k] = v.join('=');
|
||||
} else if (i + 1 < parts.length && !parts[i + 1].startsWith('-')) {
|
||||
result[key] = parts[i + 1];
|
||||
i++;
|
||||
} else {
|
||||
result[key] = 'true';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
export interface HotRunnerConfig {
|
||||
enabled: boolean;
|
||||
transport: 'websocket' | 'grpc' | 'named-pipe';
|
||||
host: string;
|
||||
port: number;
|
||||
healthCheckInterval: number; // seconds
|
||||
maxIdleTime: number; // seconds before recycling
|
||||
maxJobsBeforeRecycle: number;
|
||||
unityVersion?: string;
|
||||
platform?: string;
|
||||
}
|
||||
|
||||
export interface HotRunnerStatus {
|
||||
id: string;
|
||||
state: 'idle' | 'busy' | 'starting' | 'stopping' | 'unhealthy';
|
||||
unityVersion: string;
|
||||
platform: string;
|
||||
currentJob?: string;
|
||||
lastJobCompleted?: string;
|
||||
uptime: number;
|
||||
jobsCompleted: number;
|
||||
lastHealthCheck: string;
|
||||
memoryUsageMB: number;
|
||||
libraryHash?: string;
|
||||
}
|
||||
|
||||
export interface HotRunnerJobRequest {
|
||||
jobId: string;
|
||||
buildMethod?: string;
|
||||
buildTarget: string;
|
||||
buildPath?: string;
|
||||
customParameters?: Record<string, string>;
|
||||
timeout: number;
|
||||
testMode?: 'editmode' | 'playmode';
|
||||
testSuitePath?: string;
|
||||
}
|
||||
|
||||
export interface HotRunnerJobResult {
|
||||
jobId: string;
|
||||
success: boolean;
|
||||
exitCode: number;
|
||||
duration: number;
|
||||
output: string;
|
||||
artifacts?: string[];
|
||||
testResults?: string; // path to test result file
|
||||
}
|
||||
|
||||
export interface HotRunnerTransport {
|
||||
connect(config: HotRunnerConfig): Promise<void>;
|
||||
disconnect(): Promise<void>;
|
||||
sendJob(request: HotRunnerJobRequest): Promise<HotRunnerJobResult>;
|
||||
getStatus(): Promise<HotRunnerStatus>;
|
||||
healthCheck(): Promise<boolean>;
|
||||
}
|
||||
@@ -1,740 +0,0 @@
|
||||
import fs from 'node:fs';
|
||||
import { HotRunnerRegistry } from './hot-runner-registry';
|
||||
import { HotRunnerHealthMonitor } from './hot-runner-health-monitor';
|
||||
import { HotRunnerDispatcher } from './hot-runner-dispatcher';
|
||||
import { HotRunnerService } from './hot-runner-service';
|
||||
import {
|
||||
HotRunnerConfig,
|
||||
HotRunnerJobRequest,
|
||||
HotRunnerJobResult,
|
||||
HotRunnerStatus,
|
||||
HotRunnerTransport,
|
||||
} from './hot-runner-types';
|
||||
|
||||
// Mock dependencies
|
||||
jest.mock('node:fs');
|
||||
jest.mock('../core/orchestrator-logger');
|
||||
|
||||
const mockFs = fs as jest.Mocked<typeof fs>;
|
||||
|
||||
function createMockConfig(overrides?: Partial<HotRunnerConfig>): HotRunnerConfig {
|
||||
return {
|
||||
enabled: true,
|
||||
transport: 'websocket',
|
||||
host: 'localhost',
|
||||
port: 9090,
|
||||
healthCheckInterval: 30,
|
||||
maxIdleTime: 3600,
|
||||
maxJobsBeforeRecycle: 100,
|
||||
unityVersion: '2022.3.0f1',
|
||||
platform: 'StandaloneWindows64',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function createMockTransport(overrides?: Partial<HotRunnerTransport>): HotRunnerTransport {
|
||||
return {
|
||||
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||
connect: jest.fn().mockResolvedValue(undefined),
|
||||
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||
disconnect: jest.fn().mockResolvedValue(undefined),
|
||||
sendJob: jest.fn().mockResolvedValue({
|
||||
jobId: 'test-job',
|
||||
success: true,
|
||||
exitCode: 0,
|
||||
duration: 5000,
|
||||
output: 'Build succeeded',
|
||||
artifacts: ['build/output.exe'],
|
||||
} as HotRunnerJobResult),
|
||||
getStatus: jest.fn().mockResolvedValue({
|
||||
id: 'mock-runner',
|
||||
state: 'idle',
|
||||
unityVersion: '2022.3.0f1',
|
||||
platform: 'StandaloneWindows64',
|
||||
uptime: 3600,
|
||||
jobsCompleted: 5,
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
memoryUsageMB: 1024,
|
||||
} as HotRunnerStatus),
|
||||
healthCheck: jest.fn().mockResolvedValue(true),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function createMockJobRequest(overrides?: Partial<HotRunnerJobRequest>): HotRunnerJobRequest {
|
||||
return {
|
||||
jobId: 'job-001',
|
||||
buildTarget: 'StandaloneWindows64',
|
||||
timeout: 60000,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
// --- Registry Tests ---
|
||||
|
||||
describe('HotRunnerRegistry', () => {
|
||||
let registry: HotRunnerRegistry;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
registry = new HotRunnerRegistry();
|
||||
});
|
||||
|
||||
it('should register a runner and return an ID', () => {
|
||||
const config = createMockConfig();
|
||||
const id = registry.registerRunner(config);
|
||||
|
||||
expect(id).toMatch(/^hr-/);
|
||||
expect(registry.size).toBe(1);
|
||||
});
|
||||
|
||||
it('should retrieve a registered runner by ID', () => {
|
||||
const config = createMockConfig();
|
||||
const id = registry.registerRunner(config);
|
||||
const runner = registry.getRunner(id);
|
||||
|
||||
expect(runner).toBeDefined();
|
||||
expect(runner!.id).toBe(id);
|
||||
expect(runner!.state).toBe('starting');
|
||||
expect(runner!.unityVersion).toBe('2022.3.0f1');
|
||||
expect(runner!.platform).toBe('StandaloneWindows64');
|
||||
});
|
||||
|
||||
it('should return undefined for unknown runner ID', () => {
|
||||
const runner = registry.getRunner('nonexistent');
|
||||
expect(runner).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should unregister a runner', () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
expect(registry.size).toBe(1);
|
||||
|
||||
registry.unregisterRunner(id);
|
||||
expect(registry.size).toBe(0);
|
||||
expect(registry.getRunner(id)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should handle unregistering a nonexistent runner gracefully', () => {
|
||||
registry.unregisterRunner('nonexistent');
|
||||
expect(registry.size).toBe(0);
|
||||
});
|
||||
|
||||
it('should list all runners without filter', () => {
|
||||
registry.registerRunner(createMockConfig({ platform: 'StandaloneWindows64' }));
|
||||
registry.registerRunner(createMockConfig({ platform: 'StandaloneLinux64' }));
|
||||
registry.registerRunner(createMockConfig({ platform: 'StandaloneOSX' }));
|
||||
|
||||
const all = registry.listRunners();
|
||||
expect(all).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('should filter runners by platform', () => {
|
||||
registry.registerRunner(createMockConfig({ platform: 'StandaloneWindows64' }));
|
||||
registry.registerRunner(createMockConfig({ platform: 'StandaloneLinux64' }));
|
||||
registry.registerRunner(createMockConfig({ platform: 'StandaloneWindows64' }));
|
||||
|
||||
const windows = registry.listRunners({ platform: 'StandaloneWindows64' });
|
||||
expect(windows).toHaveLength(2);
|
||||
|
||||
const linux = registry.listRunners({ platform: 'StandaloneLinux64' });
|
||||
expect(linux).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should filter runners by state', () => {
|
||||
const id1 = registry.registerRunner(createMockConfig());
|
||||
registry.registerRunner(createMockConfig());
|
||||
|
||||
registry.updateRunner(id1, { state: 'idle' });
|
||||
|
||||
// second runner remains in 'starting' state
|
||||
|
||||
const idle = registry.listRunners({ state: 'idle' });
|
||||
expect(idle).toHaveLength(1);
|
||||
expect(idle[0].id).toBe(id1);
|
||||
});
|
||||
|
||||
it('should filter runners by Unity version', () => {
|
||||
registry.registerRunner(createMockConfig({ unityVersion: '2022.3.0f1' }));
|
||||
registry.registerRunner(createMockConfig({ unityVersion: '2023.1.0f1' }));
|
||||
registry.registerRunner(createMockConfig({ unityVersion: '2022.3.0f1' }));
|
||||
|
||||
const v2022 = registry.listRunners({ unityVersion: '2022.3.0f1' });
|
||||
expect(v2022).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should find an available idle runner matching requirements', () => {
|
||||
const id1 = registry.registerRunner(
|
||||
createMockConfig({ unityVersion: '2022.3.0f1', platform: 'StandaloneWindows64' }),
|
||||
);
|
||||
registry.updateRunner(id1, { state: 'idle' });
|
||||
|
||||
const id2 = registry.registerRunner(
|
||||
createMockConfig({ unityVersion: '2023.1.0f1', platform: 'StandaloneLinux64' }),
|
||||
);
|
||||
registry.updateRunner(id2, { state: 'idle' });
|
||||
|
||||
const found = registry.findAvailableRunner({
|
||||
unityVersion: '2022.3.0f1',
|
||||
platform: 'StandaloneWindows64',
|
||||
});
|
||||
|
||||
expect(found).toBeDefined();
|
||||
expect(found!.id).toBe(id1);
|
||||
});
|
||||
|
||||
it('should return undefined when no runner matches requirements', () => {
|
||||
const id = registry.registerRunner(
|
||||
createMockConfig({ unityVersion: '2022.3.0f1', platform: 'StandaloneWindows64' }),
|
||||
);
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const found = registry.findAvailableRunner({
|
||||
unityVersion: '2023.1.0f1',
|
||||
platform: 'StandaloneLinux64',
|
||||
});
|
||||
|
||||
expect(found).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should update runner status fields', () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle', memoryUsageMB: 2048 });
|
||||
|
||||
const runner = registry.getRunner(id);
|
||||
expect(runner!.state).toBe('idle');
|
||||
expect(runner!.memoryUsageMB).toBe(2048);
|
||||
|
||||
// ID should not be overridden by the update
|
||||
expect(runner!.id).toBe(id);
|
||||
});
|
||||
|
||||
it('should persist and load registry from disk', () => {
|
||||
const persistenceRegistry = new HotRunnerRegistry('/tmp/test');
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.writeFileSync.mockImplementation(() => {});
|
||||
mockFs.mkdirSync.mockImplementation(() => '' as any);
|
||||
|
||||
const id = persistenceRegistry.registerRunner(createMockConfig());
|
||||
|
||||
// Verify writeFileSync was called for persistence
|
||||
expect(mockFs.writeFileSync).toHaveBeenCalled();
|
||||
const writtenData = JSON.parse((mockFs.writeFileSync as jest.Mock).mock.calls[0][1] as string);
|
||||
expect(writtenData.runners).toBeDefined();
|
||||
expect(writtenData.runners[id]).toBeDefined();
|
||||
});
|
||||
|
||||
it('should load runners from disk on loadFromDisk', () => {
|
||||
const persistenceRegistry = new HotRunnerRegistry('/tmp/test');
|
||||
const storedData = {
|
||||
runners: {
|
||||
'hr-restored': {
|
||||
id: 'hr-restored',
|
||||
state: 'idle',
|
||||
unityVersion: '2022.3.0f1',
|
||||
platform: 'StandaloneWindows64',
|
||||
uptime: 100,
|
||||
jobsCompleted: 3,
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
memoryUsageMB: 512,
|
||||
},
|
||||
},
|
||||
configs: {
|
||||
'hr-restored': createMockConfig(),
|
||||
},
|
||||
};
|
||||
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue(JSON.stringify(storedData));
|
||||
|
||||
const count = persistenceRegistry.loadFromDisk();
|
||||
expect(count).toBe(1);
|
||||
expect(persistenceRegistry.getRunner('hr-restored')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should discard invalid runner entries when loading from disk', () => {
|
||||
const persistenceRegistry = new HotRunnerRegistry('/tmp/test');
|
||||
const storedData = {
|
||||
runners: {
|
||||
'hr-valid': {
|
||||
id: 'hr-valid',
|
||||
state: 'idle',
|
||||
unityVersion: '2022.3.0f1',
|
||||
platform: 'StandaloneWindows64',
|
||||
uptime: 100,
|
||||
jobsCompleted: 3,
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
memoryUsageMB: 512,
|
||||
},
|
||||
'hr-invalid': {
|
||||
// Missing required fields like state, unityVersion
|
||||
id: 'hr-invalid',
|
||||
},
|
||||
'hr-bad-state': {
|
||||
id: 'hr-bad-state',
|
||||
state: 'nonexistent-state',
|
||||
unityVersion: '2022.3.0f1',
|
||||
platform: 'StandaloneWindows64',
|
||||
uptime: 0,
|
||||
jobsCompleted: 0,
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
memoryUsageMB: 0,
|
||||
},
|
||||
},
|
||||
configs: {
|
||||
'hr-valid': createMockConfig(),
|
||||
'hr-invalid': createMockConfig(),
|
||||
'hr-bad-state': createMockConfig(),
|
||||
},
|
||||
};
|
||||
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue(JSON.stringify(storedData));
|
||||
|
||||
const count = persistenceRegistry.loadFromDisk();
|
||||
expect(count).toBe(1);
|
||||
expect(persistenceRegistry.getRunner('hr-valid')).toBeDefined();
|
||||
expect(persistenceRegistry.getRunner('hr-invalid')).toBeUndefined();
|
||||
expect(persistenceRegistry.getRunner('hr-bad-state')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should handle corrupt JSON persistence file gracefully', () => {
|
||||
const persistenceRegistry = new HotRunnerRegistry('/tmp/test');
|
||||
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue('{ invalid json !!!');
|
||||
|
||||
const count = persistenceRegistry.loadFromDisk();
|
||||
expect(count).toBe(0);
|
||||
expect(persistenceRegistry.size).toBe(0);
|
||||
});
|
||||
|
||||
it('should handle persistence file with invalid top-level structure', () => {
|
||||
const persistenceRegistry = new HotRunnerRegistry('/tmp/test');
|
||||
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue('"just a string"');
|
||||
|
||||
const count = persistenceRegistry.loadFromDisk();
|
||||
expect(count).toBe(0);
|
||||
});
|
||||
|
||||
it('should handle persistence file with null runners', () => {
|
||||
const persistenceRegistry = new HotRunnerRegistry('/tmp/test');
|
||||
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue('{"runners": null, "configs": null}');
|
||||
|
||||
const count = persistenceRegistry.loadFromDisk();
|
||||
expect(count).toBe(0);
|
||||
});
|
||||
|
||||
it('should validate and repair invalid runners', () => {
|
||||
const persistenceRegistry = new HotRunnerRegistry('/tmp/test');
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.writeFileSync.mockImplementation(() => {});
|
||||
mockFs.mkdirSync.mockImplementation(() => '' as any);
|
||||
|
||||
// Register a valid runner first
|
||||
const id = persistenceRegistry.registerRunner(createMockConfig());
|
||||
persistenceRegistry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
// Manually corrupt the runner's state by setting an invalid state
|
||||
// (we access via the public API -- updateRunner with a cast)
|
||||
persistenceRegistry.updateRunner(id, { state: 'invalid-state' as any });
|
||||
|
||||
const repaired = persistenceRegistry.validateAndRepair();
|
||||
expect(repaired).toBe(1);
|
||||
|
||||
const runner = persistenceRegistry.getRunner(id);
|
||||
expect(runner!.state).toBe('unhealthy');
|
||||
});
|
||||
|
||||
it('should not discard configs for valid runners when loading from disk', () => {
|
||||
const persistenceRegistry = new HotRunnerRegistry('/tmp/test');
|
||||
const storedData = {
|
||||
runners: {
|
||||
'hr-valid': {
|
||||
id: 'hr-valid',
|
||||
state: 'idle',
|
||||
unityVersion: '2022.3.0f1',
|
||||
platform: 'StandaloneWindows64',
|
||||
uptime: 100,
|
||||
jobsCompleted: 3,
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
memoryUsageMB: 512,
|
||||
},
|
||||
},
|
||||
configs: {
|
||||
'hr-valid': createMockConfig(),
|
||||
},
|
||||
};
|
||||
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue(JSON.stringify(storedData));
|
||||
|
||||
persistenceRegistry.loadFromDisk();
|
||||
expect(persistenceRegistry.getConfig('hr-valid')).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
// --- Health Monitor Tests ---
|
||||
|
||||
describe('HotRunnerHealthMonitor', () => {
|
||||
let monitor: HotRunnerHealthMonitor;
|
||||
let registry: HotRunnerRegistry;
|
||||
let transports: Map<string, HotRunnerTransport>;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.useFakeTimers();
|
||||
monitor = new HotRunnerHealthMonitor();
|
||||
registry = new HotRunnerRegistry();
|
||||
transports = new Map();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
monitor.stopMonitoring();
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('should start and stop monitoring', () => {
|
||||
monitor.startMonitoring(registry, 30, transports);
|
||||
expect(monitor.isMonitoring).toBe(true);
|
||||
|
||||
monitor.stopMonitoring();
|
||||
expect(monitor.isMonitoring).toBe(false);
|
||||
});
|
||||
|
||||
it('should report healthy when transport health check passes', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const transport = createMockTransport();
|
||||
transports.set(id, transport);
|
||||
monitor.startMonitoring(registry, 30, transports);
|
||||
|
||||
const healthy = await monitor.checkHealth(id);
|
||||
expect(healthy).toBe(true);
|
||||
expect(transport.healthCheck).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should mark runner as unhealthy when health check fails', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const transport = createMockTransport({
|
||||
healthCheck: jest.fn().mockResolvedValue(false),
|
||||
});
|
||||
transports.set(id, transport);
|
||||
monitor.startMonitoring(registry, 30, transports);
|
||||
|
||||
const healthy = await monitor.checkHealth(id);
|
||||
expect(healthy).toBe(false);
|
||||
|
||||
const runner = registry.getRunner(id);
|
||||
expect(runner!.state).toBe('unhealthy');
|
||||
});
|
||||
|
||||
it('should mark runner as unhealthy when health check throws', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const transport = createMockTransport({
|
||||
healthCheck: jest.fn().mockRejectedValue(new Error('Connection refused')),
|
||||
});
|
||||
transports.set(id, transport);
|
||||
monitor.startMonitoring(registry, 30, transports);
|
||||
|
||||
const healthy = await monitor.checkHealth(id);
|
||||
expect(healthy).toBe(false);
|
||||
});
|
||||
|
||||
it('should recycle unhealthy runner and remove from registry', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
const transport = createMockTransport();
|
||||
transports.set(id, transport);
|
||||
monitor.startMonitoring(registry, 30, transports);
|
||||
|
||||
await monitor.recycleUnhealthyRunner(id);
|
||||
|
||||
expect(registry.getRunner(id)).toBeUndefined();
|
||||
expect(transport.disconnect).toHaveBeenCalled();
|
||||
expect(transports.has(id)).toBe(false);
|
||||
});
|
||||
|
||||
it('should recycle idle runner when max idle time exceeded', async () => {
|
||||
const id = registry.registerRunner(createMockConfig({ maxIdleTime: 60 }));
|
||||
|
||||
// Set lastHealthCheck to 120 seconds ago
|
||||
const oldDate = new Date(Date.now() - 120 * 1000).toISOString();
|
||||
registry.updateRunner(id, { state: 'idle', lastHealthCheck: oldDate });
|
||||
|
||||
const transport = createMockTransport();
|
||||
transports.set(id, transport);
|
||||
monitor.startMonitoring(registry, 30, transports);
|
||||
|
||||
await monitor.recycleIdleRunner(id, 60);
|
||||
|
||||
expect(registry.getRunner(id)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not recycle idle runner when within max idle time', async () => {
|
||||
const id = registry.registerRunner(createMockConfig({ maxIdleTime: 3600 }));
|
||||
registry.updateRunner(id, {
|
||||
state: 'idle',
|
||||
lastHealthCheck: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const transport = createMockTransport();
|
||||
transports.set(id, transport);
|
||||
monitor.startMonitoring(registry, 30, transports);
|
||||
|
||||
await monitor.recycleIdleRunner(id, 3600);
|
||||
|
||||
// Runner should still exist
|
||||
expect(registry.getRunner(id)).toBeDefined();
|
||||
});
|
||||
|
||||
it('should return false when no transport exists for runner', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
|
||||
// Do not set any transport for this runner
|
||||
monitor.startMonitoring(registry, 30, transports);
|
||||
|
||||
const healthy = await monitor.checkHealth(id);
|
||||
expect(healthy).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// --- Dispatcher Tests ---
|
||||
|
||||
describe('HotRunnerDispatcher', () => {
|
||||
let registry: HotRunnerRegistry;
|
||||
let transports: Map<string, HotRunnerTransport>;
|
||||
let dispatcher: HotRunnerDispatcher;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
registry = new HotRunnerRegistry();
|
||||
transports = new Map();
|
||||
dispatcher = new HotRunnerDispatcher(transports);
|
||||
});
|
||||
|
||||
it('should dispatch a job to an available runner', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const transport = createMockTransport();
|
||||
transports.set(id, transport);
|
||||
|
||||
const request = createMockJobRequest();
|
||||
const result = await dispatcher.dispatchJob(request, registry, '2022.3.0f1');
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(transport.sendJob).toHaveBeenCalledWith(request);
|
||||
});
|
||||
|
||||
it('should mark runner as busy during job execution', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const statesDuringJob: string[] = [];
|
||||
const transport = createMockTransport({
|
||||
sendJob: jest.fn().mockImplementation(async () => {
|
||||
const runner = registry.getRunner(id);
|
||||
if (runner) statesDuringJob.push(runner.state);
|
||||
|
||||
return {
|
||||
jobId: 'job-001',
|
||||
success: true,
|
||||
exitCode: 0,
|
||||
duration: 1000,
|
||||
output: 'ok',
|
||||
};
|
||||
}),
|
||||
});
|
||||
transports.set(id, transport);
|
||||
|
||||
await dispatcher.dispatchJob(createMockJobRequest(), registry, '2022.3.0f1');
|
||||
|
||||
expect(statesDuringJob).toContain('busy');
|
||||
|
||||
// After completion, should be idle again
|
||||
const runner = registry.getRunner(id);
|
||||
expect(runner!.state).toBe('idle');
|
||||
});
|
||||
|
||||
it('should increment jobsCompleted after successful dispatch', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle', jobsCompleted: 5 });
|
||||
|
||||
const transport = createMockTransport();
|
||||
transports.set(id, transport);
|
||||
|
||||
await dispatcher.dispatchJob(createMockJobRequest(), registry, '2022.3.0f1');
|
||||
|
||||
const runner = registry.getRunner(id);
|
||||
expect(runner!.jobsCompleted).toBe(6);
|
||||
});
|
||||
|
||||
it('should throw when no runner is available and wait times out', async () => {
|
||||
// No runners registered at all
|
||||
const request = createMockJobRequest({ timeout: 100 });
|
||||
|
||||
await expect(dispatcher.dispatchJob(request, registry, '2022.3.0f1')).rejects.toThrow(/Timed out waiting/);
|
||||
});
|
||||
|
||||
it('should throw when runner has no transport', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
// No transport set for this runner
|
||||
|
||||
const request = createMockJobRequest();
|
||||
|
||||
await expect(dispatcher.dispatchJob(request, registry, '2022.3.0f1')).rejects.toThrow(/No transport available/);
|
||||
});
|
||||
|
||||
it('should handle job failure and return runner to idle', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const transport = createMockTransport({
|
||||
sendJob: jest.fn().mockRejectedValue(new Error('Unity crashed')),
|
||||
});
|
||||
transports.set(id, transport);
|
||||
|
||||
await expect(dispatcher.dispatchJob(createMockJobRequest(), registry, '2022.3.0f1')).rejects.toThrow(
|
||||
'Unity crashed',
|
||||
);
|
||||
|
||||
// Runner should be back to idle despite failure
|
||||
const runner = registry.getRunner(id);
|
||||
expect(runner!.state).toBe('idle');
|
||||
});
|
||||
|
||||
it('should handle job timeout', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const transport = createMockTransport({
|
||||
sendJob: jest.fn().mockImplementation(
|
||||
() => new Promise((resolve) => setTimeout(resolve, 60000)), // never resolves within timeout
|
||||
),
|
||||
});
|
||||
transports.set(id, transport);
|
||||
|
||||
const request = createMockJobRequest({ timeout: 50 });
|
||||
|
||||
await expect(dispatcher.dispatchJob(request, registry, '2022.3.0f1')).rejects.toThrow(/timed out/);
|
||||
});
|
||||
|
||||
it('should disconnect transport on job timeout', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const transport = createMockTransport({
|
||||
sendJob: jest.fn().mockImplementation(
|
||||
() => new Promise((resolve) => setTimeout(resolve, 60000)), // never resolves within timeout
|
||||
),
|
||||
});
|
||||
transports.set(id, transport);
|
||||
|
||||
const request = createMockJobRequest({ timeout: 50 });
|
||||
|
||||
await expect(dispatcher.dispatchJob(request, registry, '2022.3.0f1')).rejects.toThrow(/timed out/);
|
||||
|
||||
// Transport should have been disconnected to clean up orphaned connection
|
||||
expect(transport.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call output callback with job output', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
|
||||
const transport = createMockTransport();
|
||||
transports.set(id, transport);
|
||||
|
||||
const outputCallback = jest.fn();
|
||||
await dispatcher.dispatchJob(createMockJobRequest(), registry, '2022.3.0f1', outputCallback);
|
||||
|
||||
expect(outputCallback).toHaveBeenCalledWith('Build succeeded');
|
||||
});
|
||||
|
||||
it('should wait for runner to become available', async () => {
|
||||
const id = registry.registerRunner(createMockConfig());
|
||||
|
||||
// Runner starts in 'starting' state, not idle
|
||||
|
||||
const transport = createMockTransport();
|
||||
transports.set(id, transport);
|
||||
|
||||
// Simulate runner becoming idle after a short delay
|
||||
setTimeout(() => {
|
||||
registry.updateRunner(id, { state: 'idle' });
|
||||
}, 50);
|
||||
|
||||
const request = createMockJobRequest({ timeout: 5000 });
|
||||
const result = await dispatcher.dispatchJob(request, registry, '2022.3.0f1');
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// --- Service Integration Tests ---
|
||||
|
||||
describe('HotRunnerService', () => {
|
||||
let service: HotRunnerService;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockFs.existsSync.mockReturnValue(false);
|
||||
service = new HotRunnerService();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await service.shutdown();
|
||||
});
|
||||
|
||||
it('should initialize and shut down cleanly', async () => {
|
||||
const config = createMockConfig();
|
||||
await service.initialize(config);
|
||||
|
||||
const status = service.getStatus();
|
||||
expect(status).toEqual([]);
|
||||
|
||||
await service.shutdown();
|
||||
});
|
||||
|
||||
it('should register a runner with transport', async () => {
|
||||
await service.initialize(createMockConfig());
|
||||
|
||||
const transport = createMockTransport();
|
||||
const id = service.registerRunner(createMockConfig(), transport);
|
||||
|
||||
expect(id).toMatch(/^hr-/);
|
||||
expect(service.getStatus()).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should disconnect all transports on shutdown', async () => {
|
||||
await service.initialize(createMockConfig());
|
||||
|
||||
const transport1 = createMockTransport();
|
||||
const transport2 = createMockTransport();
|
||||
service.registerRunner(createMockConfig(), transport1);
|
||||
service.registerRunner(createMockConfig(), transport2);
|
||||
|
||||
await service.shutdown();
|
||||
|
||||
expect(transport1.disconnect).toHaveBeenCalled();
|
||||
expect(transport2.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should expose the underlying registry', async () => {
|
||||
await service.initialize(createMockConfig());
|
||||
const registry = service.getRegistry();
|
||||
|
||||
expect(registry).toBeInstanceOf(HotRunnerRegistry);
|
||||
});
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
export { HotRunnerService } from './hot-runner-service';
|
||||
export { HotRunnerRegistry } from './hot-runner-registry';
|
||||
export { HotRunnerHealthMonitor } from './hot-runner-health-monitor';
|
||||
export { HotRunnerDispatcher } from './hot-runner-dispatcher';
|
||||
export type {
|
||||
HotRunnerConfig,
|
||||
HotRunnerStatus,
|
||||
HotRunnerJobRequest,
|
||||
HotRunnerJobResult,
|
||||
HotRunnerTransport,
|
||||
} from './hot-runner-types';
|
||||
12
src/model/orchestrator/services/test-workflow/index.ts
Normal file
12
src/model/orchestrator/services/test-workflow/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export { TestSuiteParser } from './test-suite-parser';
|
||||
export { TaxonomyFilterService } from './taxonomy-filter-service';
|
||||
export { TestResultReporter } from './test-result-reporter';
|
||||
export { TestWorkflowService } from './test-workflow-service';
|
||||
export {
|
||||
TestSuiteDefinition,
|
||||
TestRunDefinition,
|
||||
TaxonomyDimension,
|
||||
TaxonomyDefinition,
|
||||
TestResult,
|
||||
TestFailure,
|
||||
} from './test-workflow-types';
|
||||
@@ -0,0 +1,198 @@
|
||||
import fs from 'node:fs';
|
||||
import YAML from 'yaml';
|
||||
import { TaxonomyDimension, TaxonomyDefinition } from './test-workflow-types';
|
||||
|
||||
/**
|
||||
* Manages test taxonomy dimensions and builds filter arguments for
|
||||
* the Unity test runner CLI. Supports comma-separated value lists,
|
||||
* regex patterns (/pattern/), and hierarchical dot-notation matching.
|
||||
*/
|
||||
export class TaxonomyFilterService {
|
||||
/**
|
||||
* Built-in taxonomy dimensions that are always available.
|
||||
* Projects may extend these via a custom taxonomy file.
|
||||
*/
|
||||
private static readonly BUILT_IN_DIMENSIONS: TaxonomyDimension[] = [
|
||||
{ name: 'Scope', values: ['Unit', 'Integration', 'System', 'End To End'] },
|
||||
{ name: 'Maturity', values: ['Trusted', 'Adolescent', 'Experimental'] },
|
||||
{ name: 'FeedbackSpeed', values: ['Fast', 'Moderate', 'Slow'] },
|
||||
{ name: 'Execution', values: ['Synchronous', 'Asynchronous', 'Coroutine'] },
|
||||
{ name: 'Rigor', values: ['Strict', 'Normal', 'Relaxed'] },
|
||||
{ name: 'Determinism', values: ['Deterministic', 'NonDeterministic'] },
|
||||
{ name: 'IsolationLevel', values: ['Full', 'Partial', 'None'] },
|
||||
];
|
||||
|
||||
/**
|
||||
* Load taxonomy dimensions: built-in dimensions plus any custom dimensions
|
||||
* from an optional taxonomy file.
|
||||
*/
|
||||
static loadTaxonomy(filePath?: string): TaxonomyDimension[] {
|
||||
const dimensions = [...TaxonomyFilterService.BUILT_IN_DIMENSIONS];
|
||||
|
||||
if (filePath && fs.existsSync(filePath)) {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const parsed = YAML.parse(content) as TaxonomyDefinition;
|
||||
|
||||
if (parsed?.extensible_groups && Array.isArray(parsed.extensible_groups)) {
|
||||
for (const group of parsed.extensible_groups) {
|
||||
if (group.name && Array.isArray(group.values)) {
|
||||
// If a custom dimension has the same name as a built-in, merge values
|
||||
const existing = dimensions.find((d) => d.name === group.name);
|
||||
if (existing) {
|
||||
const existingValues = new Set(existing.values);
|
||||
for (const value of group.values) {
|
||||
if (!existingValues.has(value)) {
|
||||
existing.values.push(value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dimensions.push({ name: group.name, values: [...group.values] });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a filter map to Unity test runner CLI args (--testFilter).
|
||||
*
|
||||
* Each filter dimension becomes a category expression. Multiple values in one
|
||||
* dimension are OR'd; multiple dimensions are AND'd. The result is a single
|
||||
* --testFilter string suitable for passing to Unity's test runner CLI.
|
||||
*
|
||||
* Regex patterns (values wrapped in /.../) are converted to category regex
|
||||
* expressions supported by the Unity test runner.
|
||||
*/
|
||||
static buildFilterArgs(filters: Record<string, string>): string {
|
||||
if (!filters || Object.keys(filters).length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const categoryExpressions: string[] = [];
|
||||
|
||||
for (const [dimension, valueSpec] of Object.entries(filters)) {
|
||||
const expression = TaxonomyFilterService.buildDimensionExpression(dimension, valueSpec);
|
||||
if (expression) {
|
||||
categoryExpressions.push(expression);
|
||||
}
|
||||
}
|
||||
|
||||
if (categoryExpressions.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Unity test runner uses --testFilter with category expressions
|
||||
// Multiple dimensions are AND'd by joining with ';'
|
||||
const filterString = categoryExpressions.join(';');
|
||||
return `--testFilter "${filterString}"`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a filter expression for a single taxonomy dimension.
|
||||
*/
|
||||
private static buildDimensionExpression(dimension: string, valueSpec: string): string {
|
||||
if (!valueSpec || valueSpec.trim() === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
const trimmed = valueSpec.trim();
|
||||
|
||||
// Check if the value is a regex pattern: /pattern/
|
||||
if (trimmed.startsWith('/') && trimmed.endsWith('/') && trimmed.length > 2) {
|
||||
const pattern = trimmed.slice(1, -1);
|
||||
return `${dimension}=~${pattern}`;
|
||||
}
|
||||
|
||||
// Comma-separated values: OR'd together
|
||||
const values = trimmed
|
||||
.split(',')
|
||||
.map((v) => v.trim())
|
||||
.filter((v) => v.length > 0);
|
||||
|
||||
if (values.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (values.length === 1) {
|
||||
return `${dimension}=${values[0]}`;
|
||||
}
|
||||
|
||||
// Multiple values: use pipe-separated OR syntax
|
||||
return `${dimension}=${values.join('|')}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a test's taxonomy metadata matches the given filter criteria.
|
||||
*
|
||||
* A test matches if ALL filter dimensions match (AND across dimensions).
|
||||
* Within a single dimension, the test must match ANY of the specified values (OR).
|
||||
* Regex patterns are matched as regular expressions.
|
||||
* Hierarchical dot-notation supports prefix matching (e.g., filter "Combat.Melee"
|
||||
* matches test category "Combat.Melee.Sword").
|
||||
*/
|
||||
static matchesFilter(testCategories: Record<string, string>, filters: Record<string, string>): boolean {
|
||||
for (const [dimension, valueSpec] of Object.entries(filters)) {
|
||||
const testValue = testCategories[dimension];
|
||||
|
||||
// If the test has no value for this dimension, it does not match
|
||||
if (testValue === undefined || testValue === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TaxonomyFilterService.matchesDimensionFilter(testValue, valueSpec)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a single test category value matches a dimension filter spec.
|
||||
*/
|
||||
private static matchesDimensionFilter(testValue: string, valueSpec: string): boolean {
|
||||
const trimmed = valueSpec.trim();
|
||||
|
||||
// Regex pattern
|
||||
if (trimmed.startsWith('/') && trimmed.endsWith('/') && trimmed.length > 2) {
|
||||
const pattern = trimmed.slice(1, -1);
|
||||
try {
|
||||
const regex = new RegExp(pattern);
|
||||
return regex.test(testValue);
|
||||
} catch {
|
||||
// Invalid regex, treat as literal
|
||||
return testValue === trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
// Comma-separated values
|
||||
const values = trimmed
|
||||
.split(',')
|
||||
.map((v) => v.trim())
|
||||
.filter((v) => v.length > 0);
|
||||
|
||||
return values.some((filterValue) => {
|
||||
// Exact match
|
||||
if (testValue === filterValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Hierarchical dot-notation prefix match
|
||||
// Filter "Combat.Melee" matches test "Combat.Melee" and "Combat.Melee.Sword"
|
||||
if (filterValue.includes('.') || testValue.includes('.')) {
|
||||
if (testValue.startsWith(filterValue + '.') || testValue === filterValue) {
|
||||
return true;
|
||||
}
|
||||
// Also allow the test to be a prefix of the filter for upward matching
|
||||
if (filterValue.startsWith(testValue + '.')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { TestResult, TestFailure } from './test-workflow-types';
|
||||
|
||||
/**
|
||||
* Parses test result files (JUnit XML, Unity JSON) and generates structured
|
||||
* summary reports. Supports writing results in multiple formats for CI
|
||||
* integration (GitHub Checks, artifact upload).
|
||||
*/
|
||||
export class TestResultReporter {
|
||||
/**
|
||||
* Parse a JUnit XML test result file into a TestResult.
|
||||
* JUnit XML is the standard format produced by Unity's test runner.
|
||||
*/
|
||||
static parseJUnitResults(xmlPath: string): TestResult {
|
||||
if (!fs.existsSync(xmlPath)) {
|
||||
throw new Error(`JUnit result file not found: ${xmlPath}`);
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(xmlPath, 'utf8');
|
||||
return TestResultReporter.parseJUnitXml(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse JUnit XML content string into a TestResult.
|
||||
*/
|
||||
static parseJUnitXml(xmlContent: string): TestResult {
|
||||
// Extract the testsuite opening tag
|
||||
const suiteTagMatch = xmlContent.match(/<testsuite\s[^>]*>/);
|
||||
|
||||
let runName = 'unknown';
|
||||
let totalTests = 0;
|
||||
let failureCount = 0;
|
||||
let skippedCount = 0;
|
||||
let duration = 0;
|
||||
|
||||
if (suiteTagMatch) {
|
||||
const tag = suiteTagMatch[0];
|
||||
|
||||
// Extract individual attributes -- order-independent
|
||||
const nameMatch = tag.match(/\sname="([^"]*)"/);
|
||||
const testsMatch = tag.match(/\stests="(\d+)"/);
|
||||
const failuresMatch = tag.match(/\sfailures="(\d+)"/);
|
||||
const skippedMatch = tag.match(/\sskipped="(\d+)"/);
|
||||
const timeMatch = tag.match(/\stime="([^"]*)"/);
|
||||
|
||||
runName = nameMatch ? nameMatch[1] : 'unknown';
|
||||
totalTests = testsMatch ? Number.parseInt(testsMatch[1], 10) : 0;
|
||||
failureCount = failuresMatch ? Number.parseInt(failuresMatch[1], 10) : 0;
|
||||
skippedCount = skippedMatch ? Number.parseInt(skippedMatch[1], 10) : 0;
|
||||
duration = timeMatch ? Number.parseFloat(timeMatch[1]) : 0;
|
||||
}
|
||||
|
||||
// Extract individual test failures by splitting into testcase blocks
|
||||
const failures: TestFailure[] = [];
|
||||
const testcasePattern = /<testcase\s[^>]*>[\s\S]*?<\/testcase>/g;
|
||||
|
||||
let tcMatch;
|
||||
while ((tcMatch = testcasePattern.exec(xmlContent)) !== null) {
|
||||
const block = tcMatch[0];
|
||||
|
||||
// Only process testcases that contain a <failure> element
|
||||
if (!block.includes('<failure')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract testcase attributes (order-independent)
|
||||
const tcTag = block.match(/<testcase\s[^>]*>/);
|
||||
if (!tcTag) continue;
|
||||
|
||||
const cnMatch = tcTag[0].match(/\sclassname="([^"]*)"/);
|
||||
const tnMatch = tcTag[0].match(/\sname="([^"]*)"/);
|
||||
|
||||
const className = cnMatch ? cnMatch[1] : 'unknown';
|
||||
const testName = tnMatch ? tnMatch[1] : 'unknown';
|
||||
|
||||
// Extract failure message
|
||||
const failTag = block.match(/<failure\s[^>]*>/);
|
||||
const msgMatch = failTag ? failTag[0].match(/\smessage="([^"]*)"/) : null;
|
||||
const message = msgMatch ? msgMatch[1] : 'Test failed';
|
||||
|
||||
// Extract stack trace from CDATA or text content
|
||||
const cdataMatch = block.match(/<failure[^>]*>[\s\S]*?<!\[CDATA\[([\s\S]*?)\]\]>/);
|
||||
const textMatch = !cdataMatch ? block.match(/<failure[^>]*>([^<]*)<\/failure>/) : null;
|
||||
const stackTrace = cdataMatch ? cdataMatch[1].trim() : textMatch ? textMatch[1].trim() : undefined;
|
||||
|
||||
failures.push({ testName, className, message, stackTrace: stackTrace || undefined });
|
||||
}
|
||||
|
||||
const passed = totalTests - failureCount - skippedCount;
|
||||
|
||||
return {
|
||||
runName,
|
||||
passed: Math.max(0, passed),
|
||||
failed: failureCount,
|
||||
skipped: skippedCount,
|
||||
duration,
|
||||
failures,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a Unity JSON test result file into a TestResult.
|
||||
*/
|
||||
static parseJsonResults(jsonPath: string): TestResult {
|
||||
if (!fs.existsSync(jsonPath)) {
|
||||
throw new Error(`JSON result file not found: ${jsonPath}`);
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(jsonPath, 'utf8');
|
||||
const data = JSON.parse(content);
|
||||
|
||||
return TestResultReporter.parseJsonData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Unity JSON test result data into a TestResult.
|
||||
*/
|
||||
static parseJsonData(data: any): TestResult {
|
||||
const runName = data.name ?? data.suiteName ?? 'unknown';
|
||||
const passed = data.passed ?? data.passCount ?? 0;
|
||||
const failed = data.failed ?? data.failCount ?? 0;
|
||||
const skipped = data.skipped ?? data.skipCount ?? data.inconclusive ?? 0;
|
||||
const duration = data.duration ?? data.time ?? 0;
|
||||
|
||||
const failures: TestFailure[] = [];
|
||||
|
||||
// Unity test results may have a 'testResults' or 'results' array
|
||||
const results = data.testResults ?? data.results ?? data.children ?? [];
|
||||
|
||||
if (Array.isArray(results)) {
|
||||
for (const result of results) {
|
||||
TestResultReporter.extractFailures(result, failures);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
runName,
|
||||
passed,
|
||||
failed,
|
||||
skipped,
|
||||
duration,
|
||||
failures,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively extract failures from nested Unity test result JSON.
|
||||
*/
|
||||
private static extractFailures(node: any, failures: TestFailure[]): void {
|
||||
if (!node) return;
|
||||
|
||||
const status = (node.result ?? node.status ?? '').toLowerCase();
|
||||
if (status === 'failed' || status === 'failure') {
|
||||
failures.push({
|
||||
testName: node.name ?? node.testName ?? 'unknown',
|
||||
className: node.className ?? node.fullName ?? node.name ?? 'unknown',
|
||||
message: node.message ?? node.output ?? 'Test failed',
|
||||
stackTrace: node.stackTrace ?? node.trace ?? undefined,
|
||||
});
|
||||
}
|
||||
|
||||
// Recurse into children (Unity nests test fixtures inside suites)
|
||||
const children = node.children ?? node.testResults ?? node.results ?? [];
|
||||
if (Array.isArray(children)) {
|
||||
for (const child of children) {
|
||||
TestResultReporter.extractFailures(child, failures);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a markdown summary table from an array of test results.
|
||||
*/
|
||||
static generateSummary(results: TestResult[]): string {
|
||||
if (results.length === 0) {
|
||||
return 'No test results available.';
|
||||
}
|
||||
|
||||
const lines: string[] = [];
|
||||
lines.push('## Test Results Summary');
|
||||
lines.push('');
|
||||
lines.push('| Run | Passed | Failed | Skipped | Duration |');
|
||||
lines.push('|-----|--------|--------|---------|----------|');
|
||||
|
||||
let totalPassed = 0;
|
||||
let totalFailed = 0;
|
||||
let totalSkipped = 0;
|
||||
let totalDuration = 0;
|
||||
|
||||
for (const result of results) {
|
||||
const status = result.failed > 0 ? 'X' : 'OK';
|
||||
const durationStr = TestResultReporter.formatDuration(result.duration);
|
||||
lines.push(
|
||||
`| ${status} ${result.runName} | ${result.passed} | ${result.failed} | ${result.skipped} | ${durationStr} |`,
|
||||
);
|
||||
totalPassed += result.passed;
|
||||
totalFailed += result.failed;
|
||||
totalSkipped += result.skipped;
|
||||
totalDuration += result.duration;
|
||||
}
|
||||
|
||||
lines.push(
|
||||
`| **Total** | **${totalPassed}** | **${totalFailed}** | **${totalSkipped}** | **${TestResultReporter.formatDuration(
|
||||
totalDuration,
|
||||
)}** |`,
|
||||
);
|
||||
lines.push('');
|
||||
|
||||
// Append failure details if any
|
||||
const allFailures = results.flatMap((r) => r.failures.map((f) => ({ ...f, run: r.runName })));
|
||||
if (allFailures.length > 0) {
|
||||
lines.push('### Failures');
|
||||
lines.push('');
|
||||
for (const failure of allFailures) {
|
||||
lines.push(`**${failure.run}** - \`${failure.className}.${failure.testName}\``);
|
||||
lines.push(`> ${failure.message}`);
|
||||
if (failure.stackTrace) {
|
||||
lines.push('```');
|
||||
lines.push(failure.stackTrace.slice(0, 500));
|
||||
lines.push('```');
|
||||
}
|
||||
lines.push('');
|
||||
}
|
||||
}
|
||||
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write test results to the output path in the specified format(s).
|
||||
*/
|
||||
static writeResults(results: TestResult[], outputPath: string, format: 'junit' | 'json' | 'both'): void {
|
||||
if (!fs.existsSync(outputPath)) {
|
||||
fs.mkdirSync(outputPath, { recursive: true });
|
||||
}
|
||||
|
||||
if (format === 'json' || format === 'both') {
|
||||
const jsonPath = path.join(outputPath, 'test-results.json');
|
||||
fs.writeFileSync(jsonPath, JSON.stringify(results, null, 2), 'utf8');
|
||||
}
|
||||
|
||||
if (format === 'junit' || format === 'both') {
|
||||
const junitPath = path.join(outputPath, 'test-results.xml');
|
||||
const xml = TestResultReporter.toJUnitXml(results);
|
||||
fs.writeFileSync(junitPath, xml, 'utf8');
|
||||
}
|
||||
|
||||
// Always write markdown summary
|
||||
const summaryPath = path.join(outputPath, 'test-summary.md');
|
||||
const summary = TestResultReporter.generateSummary(results);
|
||||
fs.writeFileSync(summaryPath, summary, 'utf8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert TestResult array to JUnit XML format.
|
||||
*/
|
||||
private static toJUnitXml(results: TestResult[]): string {
|
||||
const lines: string[] = [];
|
||||
lines.push('<?xml version="1.0" encoding="UTF-8"?>');
|
||||
lines.push('<testsuites>');
|
||||
|
||||
for (const result of results) {
|
||||
const total = result.passed + result.failed + result.skipped;
|
||||
lines.push(
|
||||
` <testsuite name="${TestResultReporter.escapeXml(result.runName)}" tests="${total}" failures="${
|
||||
result.failed
|
||||
}" skipped="${result.skipped}" time="${result.duration.toFixed(3)}">`,
|
||||
);
|
||||
|
||||
// Write failure test cases
|
||||
for (const failure of result.failures) {
|
||||
lines.push(
|
||||
` <testcase classname="${TestResultReporter.escapeXml(
|
||||
failure.className,
|
||||
)}" name="${TestResultReporter.escapeXml(failure.testName)}">`,
|
||||
);
|
||||
lines.push(` <failure message="${TestResultReporter.escapeXml(failure.message)}">`);
|
||||
if (failure.stackTrace) {
|
||||
lines.push(` <![CDATA[${failure.stackTrace}]]>`);
|
||||
}
|
||||
lines.push(' </failure>');
|
||||
lines.push(' </testcase>');
|
||||
}
|
||||
|
||||
lines.push(' </testsuite>');
|
||||
}
|
||||
|
||||
lines.push('</testsuites>');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape special XML characters.
|
||||
*/
|
||||
private static escapeXml(str: string): string {
|
||||
return str
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a duration in seconds to a human-readable string.
|
||||
*/
|
||||
private static formatDuration(seconds: number): string {
|
||||
if (seconds < 60) {
|
||||
return `${seconds.toFixed(1)}s`;
|
||||
}
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
return `${minutes}m ${remainingSeconds.toFixed(0)}s`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
import fs from 'node:fs';
|
||||
import YAML from 'yaml';
|
||||
import { TestSuiteDefinition, TestRunDefinition } from './test-workflow-types';
|
||||
|
||||
/**
|
||||
* Parses and validates YAML-based test suite definition files.
|
||||
* Handles dependency resolution (topological sort) for ordered test run execution.
|
||||
*/
|
||||
export class TestSuiteParser {
|
||||
/**
|
||||
* Read and parse a YAML test suite definition file.
|
||||
* Validates the structure and returns a typed TestSuiteDefinition.
|
||||
*/
|
||||
static parseSuiteFile(filePath: string): TestSuiteDefinition {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new Error(`Test suite file not found: ${filePath}`);
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const parsed = YAML.parse(content);
|
||||
|
||||
if (!parsed || typeof parsed !== 'object') {
|
||||
throw new Error(`Invalid YAML in test suite file: ${filePath}`);
|
||||
}
|
||||
|
||||
if (!parsed.name || typeof parsed.name !== 'string') {
|
||||
throw new Error(`Test suite must have a 'name' field (string): ${filePath}`);
|
||||
}
|
||||
|
||||
if (!Array.isArray(parsed.runs) || parsed.runs.length === 0) {
|
||||
throw new Error(`Test suite must have a non-empty 'runs' array: ${filePath}`);
|
||||
}
|
||||
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: parsed.name,
|
||||
description: parsed.description,
|
||||
runs: parsed.runs.map((run: any) => TestSuiteParser.parseRun(run)),
|
||||
};
|
||||
|
||||
const errors = TestSuiteParser.validateSuite(suite);
|
||||
if (errors.length > 0) {
|
||||
throw new Error(`Test suite validation failed:\n ${errors.join('\n ')}`);
|
||||
}
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a single run definition from raw YAML data.
|
||||
*/
|
||||
private static parseRun(raw: any): TestRunDefinition {
|
||||
if (!raw || typeof raw !== 'object') {
|
||||
throw new Error(`Each run must be an object`);
|
||||
}
|
||||
|
||||
if (!raw.name || typeof raw.name !== 'string') {
|
||||
throw new Error(`Each run must have a 'name' field (string)`);
|
||||
}
|
||||
|
||||
const run: TestRunDefinition = {
|
||||
name: raw.name,
|
||||
};
|
||||
|
||||
if (raw.needs !== undefined) {
|
||||
if (!Array.isArray(raw.needs)) {
|
||||
throw new Error(`Run '${raw.name}': 'needs' must be an array of strings`);
|
||||
}
|
||||
run.needs = raw.needs;
|
||||
}
|
||||
|
||||
if (raw.editMode !== undefined) {
|
||||
run.editMode = Boolean(raw.editMode);
|
||||
}
|
||||
|
||||
if (raw.playMode !== undefined) {
|
||||
run.playMode = Boolean(raw.playMode);
|
||||
}
|
||||
|
||||
if (raw.builtClient !== undefined) {
|
||||
run.builtClient = Boolean(raw.builtClient);
|
||||
}
|
||||
|
||||
if (raw.builtClientPath !== undefined) {
|
||||
run.builtClientPath = String(raw.builtClientPath);
|
||||
}
|
||||
|
||||
if (raw.filters !== undefined) {
|
||||
if (typeof raw.filters !== 'object' || Array.isArray(raw.filters)) {
|
||||
throw new Error(`Run '${raw.name}': 'filters' must be a key-value object`);
|
||||
}
|
||||
run.filters = {};
|
||||
for (const [key, value] of Object.entries(raw.filters)) {
|
||||
run.filters[key] = String(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (raw.timeout !== undefined) {
|
||||
const timeout = Number(raw.timeout);
|
||||
if (Number.isNaN(timeout) || timeout <= 0) {
|
||||
throw new Error(`Run '${raw.name}': 'timeout' must be a positive number`);
|
||||
}
|
||||
run.timeout = timeout;
|
||||
}
|
||||
|
||||
return run;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve run execution order via topological sort based on 'needs' dependencies.
|
||||
* Returns an array of parallel groups -- each group contains runs that can execute concurrently.
|
||||
* Runs within the same group have no inter-dependencies.
|
||||
*/
|
||||
static resolveRunOrder(suite: TestSuiteDefinition): TestRunDefinition[][] {
|
||||
const runMap = new Map<string, TestRunDefinition>();
|
||||
for (const run of suite.runs) {
|
||||
runMap.set(run.name, run);
|
||||
}
|
||||
|
||||
// Build adjacency: inDegree counts and dependents map
|
||||
const inDegree = new Map<string, number>();
|
||||
const dependents = new Map<string, string[]>();
|
||||
|
||||
for (const run of suite.runs) {
|
||||
if (!inDegree.has(run.name)) {
|
||||
inDegree.set(run.name, 0);
|
||||
}
|
||||
if (!dependents.has(run.name)) {
|
||||
dependents.set(run.name, []);
|
||||
}
|
||||
|
||||
if (run.needs) {
|
||||
for (const dep of run.needs) {
|
||||
inDegree.set(run.name, (inDegree.get(run.name) ?? 0) + 1);
|
||||
if (!dependents.has(dep)) {
|
||||
dependents.set(dep, []);
|
||||
}
|
||||
dependents.get(dep)!.push(run.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Kahn's algorithm producing parallel layers
|
||||
const groups: TestRunDefinition[][] = [];
|
||||
let ready = suite.runs.filter((r) => (inDegree.get(r.name) ?? 0) === 0);
|
||||
let processed = 0;
|
||||
|
||||
while (ready.length > 0) {
|
||||
groups.push(ready);
|
||||
processed += ready.length;
|
||||
|
||||
const nextReady: TestRunDefinition[] = [];
|
||||
for (const run of ready) {
|
||||
for (const dep of dependents.get(run.name) ?? []) {
|
||||
const newDegree = (inDegree.get(dep) ?? 1) - 1;
|
||||
inDegree.set(dep, newDegree);
|
||||
if (newDegree === 0) {
|
||||
nextReady.push(runMap.get(dep)!);
|
||||
}
|
||||
}
|
||||
}
|
||||
ready = nextReady;
|
||||
}
|
||||
|
||||
if (processed !== suite.runs.length) {
|
||||
throw new Error(`Circular dependency detected in test suite '${suite.name}'`);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a parsed test suite definition.
|
||||
* Returns an array of validation error messages (empty = valid).
|
||||
*/
|
||||
static validateSuite(suite: TestSuiteDefinition): string[] {
|
||||
const errors: string[] = [];
|
||||
const runNames = new Set<string>();
|
||||
|
||||
// Check for duplicate run names
|
||||
for (const run of suite.runs) {
|
||||
if (runNames.has(run.name)) {
|
||||
errors.push(`Duplicate run name: '${run.name}'`);
|
||||
}
|
||||
runNames.add(run.name);
|
||||
}
|
||||
|
||||
// Check that all 'needs' references exist
|
||||
for (const run of suite.runs) {
|
||||
if (run.needs) {
|
||||
for (const dep of run.needs) {
|
||||
if (!runNames.has(dep)) {
|
||||
errors.push(`Run '${run.name}' depends on unknown run '${dep}'`);
|
||||
}
|
||||
}
|
||||
|
||||
// Self-dependency
|
||||
if (run.needs.includes(run.name)) {
|
||||
errors.push(`Run '${run.name}' depends on itself`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check that at least one test mode is specified per run
|
||||
for (const run of suite.runs) {
|
||||
if (!run.editMode && !run.playMode && !run.builtClient) {
|
||||
errors.push(`Run '${run.name}' must specify at least one of: editMode, playMode, builtClient`);
|
||||
}
|
||||
}
|
||||
|
||||
// Detect circular dependencies via DFS
|
||||
const circularError = TestSuiteParser.detectCircularDependencies(suite);
|
||||
if (circularError) {
|
||||
errors.push(circularError);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect circular dependencies using DFS cycle detection.
|
||||
*/
|
||||
private static detectCircularDependencies(suite: TestSuiteDefinition): string | null {
|
||||
const adjacency = new Map<string, string[]>();
|
||||
for (const run of suite.runs) {
|
||||
adjacency.set(run.name, run.needs ?? []);
|
||||
}
|
||||
|
||||
const visited = new Set<string>();
|
||||
const visiting = new Set<string>();
|
||||
|
||||
const dfs = (node: string, path: string[]): string | null => {
|
||||
if (visiting.has(node)) {
|
||||
const cycleStart = path.indexOf(node);
|
||||
const cycle = path.slice(cycleStart).concat(node);
|
||||
return `Circular dependency: ${cycle.join(' -> ')}`;
|
||||
}
|
||||
if (visited.has(node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
visiting.add(node);
|
||||
path.push(node);
|
||||
|
||||
for (const dep of adjacency.get(node) ?? []) {
|
||||
if (adjacency.has(dep)) {
|
||||
const result = dfs(dep, [...path]);
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
|
||||
visiting.delete(node);
|
||||
visited.add(node);
|
||||
return null;
|
||||
};
|
||||
|
||||
for (const run of suite.runs) {
|
||||
const result = dfs(run.name, []);
|
||||
if (result) return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
import { exec } from 'node:child_process';
|
||||
import { promisify } from 'node:util';
|
||||
import path from 'node:path';
|
||||
import * as core from '@actions/core';
|
||||
import BuildParameters from '../../../build-parameters';
|
||||
import { TestSuiteParser } from './test-suite-parser';
|
||||
import { TaxonomyFilterService } from './taxonomy-filter-service';
|
||||
import { TestResultReporter } from './test-result-reporter';
|
||||
import { TestRunDefinition, TestResult } from './test-workflow-types';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
/**
|
||||
* Main entry point for the test workflow engine.
|
||||
* Orchestrates parsing of YAML suite definitions, resolving run order,
|
||||
* executing test runs via Unity CLI, and collecting structured results.
|
||||
*/
|
||||
export class TestWorkflowService {
|
||||
/**
|
||||
* Execute a full test suite from a YAML definition file.
|
||||
* Parses the suite, resolves dependency order, executes each parallel
|
||||
* group sequentially (runs within a group execute concurrently), and
|
||||
* collects all results.
|
||||
*/
|
||||
static async executeTestSuite(suitePath: string, parameters: BuildParameters): Promise<TestResult[]> {
|
||||
core.info(`[TestWorkflow] Loading test suite from: ${suitePath}`);
|
||||
|
||||
const suite = TestSuiteParser.parseSuiteFile(suitePath);
|
||||
core.info(`[TestWorkflow] Suite '${suite.name}' loaded with ${suite.runs.length} run(s)`);
|
||||
|
||||
if (suite.description) {
|
||||
core.info(`[TestWorkflow] Description: ${suite.description}`);
|
||||
}
|
||||
|
||||
const groups = TestSuiteParser.resolveRunOrder(suite);
|
||||
core.info(`[TestWorkflow] Resolved into ${groups.length} execution group(s)`);
|
||||
|
||||
const allResults: TestResult[] = [];
|
||||
let groupIndex = 0;
|
||||
|
||||
for (const group of groups) {
|
||||
groupIndex++;
|
||||
const runNames = group.map((r) => r.name).join(', ');
|
||||
core.info(`[TestWorkflow] Executing group ${groupIndex}/${groups.length}: [${runNames}]`);
|
||||
|
||||
// Execute runs within a group concurrently
|
||||
const groupResults = await Promise.all(group.map((run) => TestWorkflowService.executeTestRun(run, parameters)));
|
||||
|
||||
allResults.push(...groupResults);
|
||||
|
||||
// Check for failures -- if any run in this group failed, log a warning
|
||||
// but continue to the next group (fail-forward for maximum feedback)
|
||||
const failedRuns = groupResults.filter((r) => r.failed > 0);
|
||||
if (failedRuns.length > 0) {
|
||||
const failedNames = failedRuns.map((r) => r.runName).join(', ');
|
||||
core.warning(`[TestWorkflow] Failures detected in group ${groupIndex}: [${failedNames}]`);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate and output summary
|
||||
const summary = TestResultReporter.generateSummary(allResults);
|
||||
core.info(summary);
|
||||
|
||||
// Write results if output path is configured
|
||||
const resultPath = parameters.testResultPath;
|
||||
const resultFormat = parameters.testResultFormat;
|
||||
if (resultPath) {
|
||||
TestResultReporter.writeResults(allResults, resultPath, resultFormat as 'junit' | 'json' | 'both');
|
||||
core.info(`[TestWorkflow] Results written to: ${resultPath}`);
|
||||
}
|
||||
|
||||
return allResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a single test run definition.
|
||||
* Builds the Unity CLI arguments based on the run configuration (edit mode,
|
||||
* play mode, built client) and taxonomy filters, executes the command
|
||||
* asynchronously, and parses the result output.
|
||||
*
|
||||
* Uses promisified exec instead of execSync so that Promise.all can
|
||||
* actually run multiple test groups in parallel without blocking the
|
||||
* Node.js event loop.
|
||||
*/
|
||||
static async executeTestRun(run: TestRunDefinition, parameters: BuildParameters): Promise<TestResult> {
|
||||
core.info(`[TestWorkflow] Starting run: '${run.name}'`);
|
||||
|
||||
const unityArguments = TestWorkflowService.buildUnityArgs(run, parameters);
|
||||
const timeoutMs = (run.timeout ?? 600) * 1000;
|
||||
|
||||
core.info(`[TestWorkflow] Unity args: ${unityArguments}`);
|
||||
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
const resultDirectory = path.join(parameters.testResultPath ?? './test-results', run.name);
|
||||
const resultFile = path.join(resultDirectory, 'results.xml');
|
||||
|
||||
// Build the full Unity command
|
||||
const unityPath = TestWorkflowService.resolveUnityPath(parameters);
|
||||
const command = `"${unityPath}" ${unityArguments} -testResults "${resultFile}"`;
|
||||
|
||||
core.info(`[TestWorkflow] Executing: ${command}`);
|
||||
|
||||
await execAsync(command, {
|
||||
timeout: timeoutMs,
|
||||
maxBuffer: 50 * 1024 * 1024, // 50 MB to handle large Unity output
|
||||
cwd: parameters.projectPath || process.cwd(),
|
||||
});
|
||||
|
||||
const duration = (Date.now() - startTime) / 1000;
|
||||
|
||||
// Parse the result file
|
||||
try {
|
||||
const result = TestResultReporter.parseJUnitResults(resultFile);
|
||||
result.runName = run.name;
|
||||
result.duration = duration;
|
||||
|
||||
return result;
|
||||
} catch {
|
||||
// Result file may not exist if Unity exited early
|
||||
core.warning(`[TestWorkflow] Could not parse results for run '${run.name}' -- result file may be missing`);
|
||||
|
||||
return {
|
||||
runName: run.name,
|
||||
passed: 0,
|
||||
failed: 0,
|
||||
skipped: 0,
|
||||
duration,
|
||||
failures: [],
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
const duration = (Date.now() - startTime) / 1000;
|
||||
|
||||
// The promisified exec sets error.killed when the process is terminated
|
||||
// due to timeout, and error.signal will be 'SIGTERM'
|
||||
const isTimeout = error.killed === true || error.signal === 'SIGTERM';
|
||||
|
||||
if (isTimeout) {
|
||||
core.error(`[TestWorkflow] Run '${run.name}' timed out after ${run.timeout ?? 600}s`);
|
||||
} else {
|
||||
core.error(`[TestWorkflow] Run '${run.name}' failed: ${error.message}`);
|
||||
}
|
||||
|
||||
// Try to parse partial results even on failure
|
||||
const resultDirectory = path.join(parameters.testResultPath ?? './test-results', run.name);
|
||||
const resultFile = path.join(resultDirectory, 'results.xml');
|
||||
|
||||
try {
|
||||
const result = TestResultReporter.parseJUnitResults(resultFile);
|
||||
result.runName = run.name;
|
||||
result.duration = duration;
|
||||
|
||||
return result;
|
||||
} catch {
|
||||
return {
|
||||
runName: run.name,
|
||||
passed: 0,
|
||||
failed: 1,
|
||||
skipped: 0,
|
||||
duration,
|
||||
failures: [
|
||||
{
|
||||
testName: isTimeout ? 'Timeout' : 'ExecutionError',
|
||||
className: run.name,
|
||||
message: isTimeout
|
||||
? `Test run timed out after ${run.timeout ?? 600}s`
|
||||
: error.message ?? 'Unknown execution error',
|
||||
stackTrace: error.stderr ?? undefined,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Unity CLI arguments for a test run based on its configuration.
|
||||
*/
|
||||
static buildUnityArgs(run: TestRunDefinition, parameters: BuildParameters): string {
|
||||
const unityArguments: string[] = ['-batchmode', '-nographics'];
|
||||
|
||||
// Project path
|
||||
if (parameters.projectPath) {
|
||||
unityArguments.push(`-projectPath "${parameters.projectPath}"`);
|
||||
}
|
||||
|
||||
// Test mode
|
||||
if (run.builtClient && run.builtClientPath) {
|
||||
// Built client testing: run tests against a built player
|
||||
unityArguments.push(
|
||||
'-runTests',
|
||||
`-testPlatform StandalonePlayer`,
|
||||
`-assemblyNames Assembly-CSharp-Tests`,
|
||||
`-builtPlayerPath "${run.builtClientPath}"`,
|
||||
);
|
||||
} else if (run.editMode && run.playMode) {
|
||||
// Both modes: run EditMode first, then PlayMode will require a separate invocation
|
||||
// For combined mode, use EditMode (the service handles sequencing)
|
||||
unityArguments.push('-runTests', '-testPlatform EditMode');
|
||||
} else if (run.playMode) {
|
||||
unityArguments.push('-runTests', '-testPlatform PlayMode');
|
||||
} else if (run.editMode) {
|
||||
unityArguments.push('-runTests', '-testPlatform EditMode');
|
||||
}
|
||||
|
||||
// Apply taxonomy filters
|
||||
if (run.filters && Object.keys(run.filters).length > 0) {
|
||||
const filterArguments = TaxonomyFilterService.buildFilterArgs(run.filters);
|
||||
if (filterArguments) {
|
||||
unityArguments.push(filterArguments);
|
||||
}
|
||||
}
|
||||
|
||||
// Target platform
|
||||
if (parameters.targetPlatform) {
|
||||
unityArguments.push(`-buildTarget ${parameters.targetPlatform}`);
|
||||
}
|
||||
|
||||
return unityArguments.join(' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the path to the Unity editor executable.
|
||||
*/
|
||||
private static resolveUnityPath(parameters: BuildParameters): string {
|
||||
// In CI, Unity path is typically set via environment or the docker container
|
||||
const environmentUnityPath = process.env.UNITY_PATH ?? process.env.UNITY_EDITOR;
|
||||
if (environmentUnityPath) {
|
||||
return environmentUnityPath;
|
||||
}
|
||||
|
||||
// Default paths by platform
|
||||
if (process.platform === 'win32') {
|
||||
return `C:/Program Files/Unity/Hub/Editor/${parameters.editorVersion}/Editor/Unity.exe`;
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
return `/Applications/Unity/Hub/Editor/${parameters.editorVersion}/Unity.app/Contents/MacOS/Unity`;
|
||||
}
|
||||
|
||||
// Linux default (Docker container path)
|
||||
return '/opt/unity/Editor/Unity';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
export interface TestSuiteDefinition {
|
||||
name: string;
|
||||
description?: string;
|
||||
runs: TestRunDefinition[];
|
||||
}
|
||||
|
||||
export interface TestRunDefinition {
|
||||
name: string;
|
||||
needs?: string[];
|
||||
editMode?: boolean;
|
||||
playMode?: boolean;
|
||||
builtClient?: boolean;
|
||||
builtClientPath?: string;
|
||||
filters?: Record<string, string>; // dimension -> comma-separated values or /regex/
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export interface TaxonomyDimension {
|
||||
name: string;
|
||||
values: string[];
|
||||
}
|
||||
|
||||
export interface TaxonomyDefinition {
|
||||
extensible_groups: TaxonomyDimension[];
|
||||
}
|
||||
|
||||
export interface TestResult {
|
||||
runName: string;
|
||||
passed: number;
|
||||
failed: number;
|
||||
skipped: number;
|
||||
duration: number;
|
||||
failures: TestFailure[];
|
||||
}
|
||||
|
||||
export interface TestFailure {
|
||||
testName: string;
|
||||
className: string;
|
||||
message: string;
|
||||
stackTrace?: string;
|
||||
}
|
||||
@@ -0,0 +1,562 @@
|
||||
import fs from 'node:fs';
|
||||
import { TestSuiteParser } from './test-suite-parser';
|
||||
import { TaxonomyFilterService } from './taxonomy-filter-service';
|
||||
import { TestResultReporter } from './test-result-reporter';
|
||||
import { TestWorkflowService } from './test-workflow-service';
|
||||
import { TestSuiteDefinition, TestResult, TestRunDefinition } from './test-workflow-types';
|
||||
|
||||
jest.mock('node:fs');
|
||||
jest.mock('@actions/core');
|
||||
|
||||
const mockFs = fs as jest.Mocked<typeof fs>;
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// Test Suite Parser
|
||||
// ============================================================================
|
||||
|
||||
describe('TestSuiteParser', () => {
|
||||
describe('parseSuiteFile', () => {
|
||||
it('should parse a valid YAML suite file', () => {
|
||||
const yaml = `
|
||||
name: pull-request
|
||||
description: Fast feedback for pull requests
|
||||
runs:
|
||||
- name: fast
|
||||
editMode: true
|
||||
filters:
|
||||
Maturity: Trusted
|
||||
FeedbackSpeed: Fast,Moderate
|
||||
timeout: 300
|
||||
- name: basic
|
||||
needs: [fast]
|
||||
editMode: true
|
||||
playMode: true
|
||||
filters:
|
||||
Maturity: Trusted,Adolescent
|
||||
timeout: 600
|
||||
`;
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue(yaml);
|
||||
|
||||
const suite = TestSuiteParser.parseSuiteFile('/path/to/suite.yml');
|
||||
|
||||
expect(suite.name).toBe('pull-request');
|
||||
expect(suite.description).toBe('Fast feedback for pull requests');
|
||||
expect(suite.runs).toHaveLength(2);
|
||||
expect(suite.runs[0].name).toBe('fast');
|
||||
expect(suite.runs[0].editMode).toBe(true);
|
||||
expect(suite.runs[0].filters?.Maturity).toBe('Trusted');
|
||||
expect(suite.runs[0].timeout).toBe(300);
|
||||
expect(suite.runs[1].needs).toEqual(['fast']);
|
||||
});
|
||||
|
||||
it('should throw when file does not exist', () => {
|
||||
mockFs.existsSync.mockReturnValue(false);
|
||||
|
||||
expect(() => TestSuiteParser.parseSuiteFile('/missing.yml')).toThrow('not found');
|
||||
});
|
||||
|
||||
it('should throw on invalid YAML', () => {
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue('not: valid: yaml: [');
|
||||
|
||||
expect(() => TestSuiteParser.parseSuiteFile('/bad.yml')).toThrow();
|
||||
});
|
||||
|
||||
it('should throw when suite has no name', () => {
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue('runs:\n - name: test\n editMode: true');
|
||||
|
||||
expect(() => TestSuiteParser.parseSuiteFile('/no-name.yml')).toThrow("'name'");
|
||||
});
|
||||
|
||||
it('should throw when suite has no runs', () => {
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue('name: test');
|
||||
|
||||
expect(() => TestSuiteParser.parseSuiteFile('/no-runs.yml')).toThrow("'runs'");
|
||||
});
|
||||
|
||||
it('should throw on invalid needs reference', () => {
|
||||
const yaml = `
|
||||
name: bad-deps
|
||||
runs:
|
||||
- name: first
|
||||
editMode: true
|
||||
needs: [nonexistent]
|
||||
`;
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue(yaml);
|
||||
|
||||
expect(() => TestSuiteParser.parseSuiteFile('/bad-deps.yml')).toThrow("unknown run 'nonexistent'");
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveRunOrder', () => {
|
||||
it('should return single group when no dependencies exist', () => {
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: 'test',
|
||||
runs: [
|
||||
{ name: 'a', editMode: true },
|
||||
{ name: 'b', playMode: true },
|
||||
],
|
||||
};
|
||||
|
||||
const groups = TestSuiteParser.resolveRunOrder(suite);
|
||||
expect(groups).toHaveLength(1);
|
||||
expect(groups[0]).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should resolve linear dependencies into sequential groups', () => {
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: 'test',
|
||||
runs: [
|
||||
{ name: 'a', editMode: true },
|
||||
{ name: 'b', needs: ['a'], playMode: true },
|
||||
{ name: 'c', needs: ['b'], editMode: true },
|
||||
],
|
||||
};
|
||||
|
||||
const groups = TestSuiteParser.resolveRunOrder(suite);
|
||||
expect(groups).toHaveLength(3);
|
||||
expect(groups[0][0].name).toBe('a');
|
||||
expect(groups[1][0].name).toBe('b');
|
||||
expect(groups[2][0].name).toBe('c');
|
||||
});
|
||||
|
||||
it('should place independent runs in the same group', () => {
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: 'test',
|
||||
runs: [
|
||||
{ name: 'root', editMode: true },
|
||||
{ name: 'branch-a', needs: ['root'], playMode: true },
|
||||
{ name: 'branch-b', needs: ['root'], editMode: true },
|
||||
],
|
||||
};
|
||||
|
||||
const groups = TestSuiteParser.resolveRunOrder(suite);
|
||||
expect(groups).toHaveLength(2);
|
||||
expect(groups[0]).toHaveLength(1);
|
||||
expect(groups[1]).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should detect circular dependencies', () => {
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: 'circular',
|
||||
runs: [
|
||||
{ name: 'a', needs: ['b'], editMode: true },
|
||||
{ name: 'b', needs: ['a'], playMode: true },
|
||||
],
|
||||
};
|
||||
|
||||
expect(() => TestSuiteParser.resolveRunOrder(suite)).toThrow('Circular dependency');
|
||||
});
|
||||
|
||||
it('should detect three-way circular dependencies', () => {
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: 'circular3',
|
||||
runs: [
|
||||
{ name: 'a', needs: ['c'], editMode: true },
|
||||
{ name: 'b', needs: ['a'], playMode: true },
|
||||
{ name: 'c', needs: ['b'], editMode: true },
|
||||
],
|
||||
};
|
||||
|
||||
expect(() => TestSuiteParser.resolveRunOrder(suite)).toThrow('Circular dependency');
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateSuite', () => {
|
||||
it('should return no errors for a valid suite', () => {
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: 'valid',
|
||||
runs: [
|
||||
{ name: 'a', editMode: true },
|
||||
{ name: 'b', needs: ['a'], playMode: true },
|
||||
],
|
||||
};
|
||||
|
||||
const errors = TestSuiteParser.validateSuite(suite);
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should detect duplicate run names', () => {
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: 'dupes',
|
||||
runs: [
|
||||
{ name: 'a', editMode: true },
|
||||
{ name: 'a', playMode: true },
|
||||
],
|
||||
};
|
||||
|
||||
const errors = TestSuiteParser.validateSuite(suite);
|
||||
expect(errors.some((e) => e.includes('Duplicate'))).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect missing test mode', () => {
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: 'no-mode',
|
||||
runs: [{ name: 'empty' }],
|
||||
};
|
||||
|
||||
const errors = TestSuiteParser.validateSuite(suite);
|
||||
expect(errors.some((e) => e.includes('editMode'))).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect self-dependency', () => {
|
||||
const suite: TestSuiteDefinition = {
|
||||
name: 'self-dep',
|
||||
runs: [{ name: 'a', needs: ['a'], editMode: true }],
|
||||
};
|
||||
|
||||
const errors = TestSuiteParser.validateSuite(suite);
|
||||
expect(errors.some((e) => e.includes('depends on itself'))).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// Taxonomy Filter Service
|
||||
// ============================================================================
|
||||
|
||||
describe('TaxonomyFilterService', () => {
|
||||
describe('loadTaxonomy', () => {
|
||||
it('should return built-in dimensions when no file provided', () => {
|
||||
const dimensions = TaxonomyFilterService.loadTaxonomy();
|
||||
|
||||
expect(dimensions.length).toBeGreaterThanOrEqual(7);
|
||||
expect(dimensions.find((d) => d.name === 'Scope')).toBeDefined();
|
||||
expect(dimensions.find((d) => d.name === 'Maturity')).toBeDefined();
|
||||
expect(dimensions.find((d) => d.name === 'FeedbackSpeed')).toBeDefined();
|
||||
expect(dimensions.find((d) => d.name === 'Execution')).toBeDefined();
|
||||
expect(dimensions.find((d) => d.name === 'Rigor')).toBeDefined();
|
||||
expect(dimensions.find((d) => d.name === 'Determinism')).toBeDefined();
|
||||
expect(dimensions.find((d) => d.name === 'IsolationLevel')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should merge custom dimensions from file', () => {
|
||||
const yaml = `
|
||||
extensible_groups:
|
||||
- name: SubjectLevel
|
||||
values: [Class, Feature, System, Product]
|
||||
- name: DataScenario
|
||||
values: [HappyPath, EdgeCase]
|
||||
`;
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue(yaml);
|
||||
|
||||
const dimensions = TaxonomyFilterService.loadTaxonomy('/taxonomy.yml');
|
||||
|
||||
expect(dimensions.find((d) => d.name === 'SubjectLevel')).toBeDefined();
|
||||
expect(dimensions.find((d) => d.name === 'DataScenario')).toBeDefined();
|
||||
// Built-ins should still exist
|
||||
expect(dimensions.find((d) => d.name === 'Scope')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should merge values for existing dimensions', () => {
|
||||
const yaml = `
|
||||
extensible_groups:
|
||||
- name: Scope
|
||||
values: [Unit, Integration, Acceptance]
|
||||
`;
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.readFileSync.mockReturnValue(yaml);
|
||||
|
||||
const dimensions = TaxonomyFilterService.loadTaxonomy('/taxonomy.yml');
|
||||
const scope = dimensions.find((d) => d.name === 'Scope');
|
||||
|
||||
expect(scope).toBeDefined();
|
||||
// Should contain built-in + custom values without duplicates
|
||||
expect(scope!.values).toContain('Unit');
|
||||
expect(scope!.values).toContain('Integration');
|
||||
expect(scope!.values).toContain('Acceptance');
|
||||
expect(scope!.values).toContain('System');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildFilterArgs', () => {
|
||||
it('should return empty string for empty filters', () => {
|
||||
expect(TaxonomyFilterService.buildFilterArgs({})).toBe('');
|
||||
});
|
||||
|
||||
it('should build single-value filter', () => {
|
||||
const result = TaxonomyFilterService.buildFilterArgs({ Maturity: 'Trusted' });
|
||||
expect(result).toBe('--testFilter "Maturity=Trusted"');
|
||||
});
|
||||
|
||||
it('should build multi-value filter with pipe separator', () => {
|
||||
const result = TaxonomyFilterService.buildFilterArgs({ Scope: 'Unit,Integration' });
|
||||
expect(result).toBe('--testFilter "Scope=Unit|Integration"');
|
||||
});
|
||||
|
||||
it('should build regex filter', () => {
|
||||
const result = TaxonomyFilterService.buildFilterArgs({ Maturity: '/Trusted|Adolescent/' });
|
||||
expect(result).toBe('--testFilter "Maturity=~Trusted|Adolescent"');
|
||||
});
|
||||
|
||||
it('should AND multiple dimensions with semicolon', () => {
|
||||
const result = TaxonomyFilterService.buildFilterArgs({
|
||||
Maturity: 'Trusted',
|
||||
Scope: 'Unit',
|
||||
});
|
||||
expect(result).toContain(';');
|
||||
expect(result).toContain('Maturity=Trusted');
|
||||
expect(result).toContain('Scope=Unit');
|
||||
});
|
||||
});
|
||||
|
||||
describe('matchesFilter', () => {
|
||||
it('should match exact value', () => {
|
||||
const match = TaxonomyFilterService.matchesFilter({ Scope: 'Unit', Maturity: 'Trusted' }, { Scope: 'Unit' });
|
||||
expect(match).toBe(true);
|
||||
});
|
||||
|
||||
it('should match comma-separated values', () => {
|
||||
const match = TaxonomyFilterService.matchesFilter({ Scope: 'Integration' }, { Scope: 'Unit,Integration' });
|
||||
expect(match).toBe(true);
|
||||
});
|
||||
|
||||
it('should not match when value is not in list', () => {
|
||||
const match = TaxonomyFilterService.matchesFilter({ Scope: 'End To End' }, { Scope: 'Unit,Integration' });
|
||||
expect(match).toBe(false);
|
||||
});
|
||||
|
||||
it('should require all dimensions to match (AND)', () => {
|
||||
const match = TaxonomyFilterService.matchesFilter(
|
||||
{ Scope: 'Unit', Maturity: 'Experimental' },
|
||||
{ Scope: 'Unit', Maturity: 'Trusted' },
|
||||
);
|
||||
expect(match).toBe(false);
|
||||
});
|
||||
|
||||
it('should match regex patterns', () => {
|
||||
const match = TaxonomyFilterService.matchesFilter({ Maturity: 'Trusted' }, { Maturity: '/Trusted|Adolescent/' });
|
||||
expect(match).toBe(true);
|
||||
});
|
||||
|
||||
it('should not match when regex does not match', () => {
|
||||
const match = TaxonomyFilterService.matchesFilter(
|
||||
{ Maturity: 'Experimental' },
|
||||
{ Maturity: '/Trusted|Adolescent/' },
|
||||
);
|
||||
expect(match).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when test lacks a required dimension', () => {
|
||||
const match = TaxonomyFilterService.matchesFilter({}, { Scope: 'Unit' });
|
||||
expect(match).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle hierarchical dot-notation matching', () => {
|
||||
const match = TaxonomyFilterService.matchesFilter({ Domain: 'Combat.Melee.Sword' }, { Domain: 'Combat.Melee' });
|
||||
expect(match).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// Test Result Reporter
|
||||
// ============================================================================
|
||||
|
||||
describe('TestResultReporter', () => {
|
||||
describe('parseJUnitXml', () => {
|
||||
it('should parse a valid JUnit XML string', () => {
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuite name="EditMode" tests="10" failures="2" skipped="1" time="5.432">
|
||||
<testcase classname="MyTests" name="TestA">
|
||||
</testcase>
|
||||
<testcase classname="MyTests" name="TestB">
|
||||
<failure message="Expected true">
|
||||
<![CDATA[at MyTests.TestB() in TestFile.cs:42]]>
|
||||
</failure>
|
||||
</testcase>
|
||||
</testsuite>`;
|
||||
|
||||
const result = TestResultReporter.parseJUnitXml(xml);
|
||||
|
||||
expect(result.runName).toBe('EditMode');
|
||||
expect(result.passed).toBe(7);
|
||||
expect(result.failed).toBe(2);
|
||||
expect(result.skipped).toBe(1);
|
||||
expect(result.duration).toBeCloseTo(5.432);
|
||||
expect(result.failures).toHaveLength(1);
|
||||
expect(result.failures[0].testName).toBe('TestB');
|
||||
expect(result.failures[0].className).toBe('MyTests');
|
||||
expect(result.failures[0].message).toBe('Expected true');
|
||||
expect(result.failures[0].stackTrace).toContain('TestFile.cs:42');
|
||||
});
|
||||
|
||||
it('should handle empty test suite', () => {
|
||||
const xml = `<testsuite name="Empty" tests="0" failures="0" time="0.0"></testsuite>`;
|
||||
|
||||
const result = TestResultReporter.parseJUnitXml(xml);
|
||||
expect(result.passed).toBe(0);
|
||||
expect(result.failed).toBe(0);
|
||||
expect(result.failures).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseJsonData', () => {
|
||||
it('should parse Unity JSON test result data', () => {
|
||||
const data = {
|
||||
name: 'PlayMode',
|
||||
passed: 15,
|
||||
failed: 2,
|
||||
skipped: 3,
|
||||
duration: 12.5,
|
||||
testResults: [{ name: 'FailingTest', className: 'MyClass', result: 'Failed', message: 'Assert failed' }],
|
||||
};
|
||||
|
||||
const result = TestResultReporter.parseJsonData(data);
|
||||
expect(result.runName).toBe('PlayMode');
|
||||
expect(result.passed).toBe(15);
|
||||
expect(result.failed).toBe(2);
|
||||
expect(result.skipped).toBe(3);
|
||||
expect(result.failures).toHaveLength(1);
|
||||
expect(result.failures[0].testName).toBe('FailingTest');
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateSummary', () => {
|
||||
it('should generate a markdown summary table', () => {
|
||||
const results: TestResult[] = [
|
||||
{
|
||||
runName: 'fast',
|
||||
passed: 10,
|
||||
failed: 0,
|
||||
skipped: 2,
|
||||
duration: 5.0,
|
||||
failures: [],
|
||||
},
|
||||
{
|
||||
runName: 'basic',
|
||||
passed: 20,
|
||||
failed: 1,
|
||||
skipped: 0,
|
||||
duration: 30.0,
|
||||
failures: [{ testName: 'TestX', className: 'ClassX', message: 'Expected 1 but got 2' }],
|
||||
},
|
||||
];
|
||||
|
||||
const summary = TestResultReporter.generateSummary(results);
|
||||
|
||||
expect(summary).toContain('Test Results Summary');
|
||||
expect(summary).toContain('fast');
|
||||
expect(summary).toContain('basic');
|
||||
expect(summary).toContain('Total');
|
||||
expect(summary).toContain('Failures');
|
||||
expect(summary).toContain('TestX');
|
||||
});
|
||||
|
||||
it('should return message when no results available', () => {
|
||||
const summary = TestResultReporter.generateSummary([]);
|
||||
expect(summary).toContain('No test results');
|
||||
});
|
||||
});
|
||||
|
||||
describe('writeResults', () => {
|
||||
it('should create output directory and write files for json format', () => {
|
||||
mockFs.existsSync.mockReturnValue(false);
|
||||
mockFs.mkdirSync.mockReturnValue(undefined as any);
|
||||
mockFs.writeFileSync.mockReturnValue(undefined);
|
||||
|
||||
const results: TestResult[] = [
|
||||
{ runName: 'test', passed: 5, failed: 0, skipped: 0, duration: 1.0, failures: [] },
|
||||
];
|
||||
|
||||
TestResultReporter.writeResults(results, '/output', 'json');
|
||||
|
||||
expect(mockFs.mkdirSync).toHaveBeenCalledWith('/output', { recursive: true });
|
||||
// Should write JSON + summary
|
||||
expect(mockFs.writeFileSync).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should write both formats when specified', () => {
|
||||
mockFs.existsSync.mockReturnValue(true);
|
||||
mockFs.writeFileSync.mockReturnValue(undefined);
|
||||
|
||||
const results: TestResult[] = [
|
||||
{ runName: 'test', passed: 5, failed: 0, skipped: 0, duration: 1.0, failures: [] },
|
||||
];
|
||||
|
||||
TestResultReporter.writeResults(results, '/output', 'both');
|
||||
|
||||
// Should write JSON + JUnit XML + summary = 3 calls
|
||||
expect(mockFs.writeFileSync).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// Test Workflow Service - buildUnityArgs
|
||||
// ============================================================================
|
||||
|
||||
describe('TestWorkflowService', () => {
|
||||
describe('buildUnityArgs', () => {
|
||||
const baseParams = {
|
||||
projectPath: '/project',
|
||||
targetPlatform: 'StandaloneLinux64',
|
||||
testResultPath: './test-results',
|
||||
testResultFormat: 'junit',
|
||||
} as any;
|
||||
|
||||
it('should build EditMode args', () => {
|
||||
const run: TestRunDefinition = { name: 'edit', editMode: true };
|
||||
|
||||
const args = TestWorkflowService.buildUnityArgs(run, baseParams);
|
||||
|
||||
expect(args).toContain('-batchmode');
|
||||
expect(args).toContain('-nographics');
|
||||
expect(args).toContain('-runTests');
|
||||
expect(args).toContain('-testPlatform EditMode');
|
||||
expect(args).toContain('-projectPath');
|
||||
});
|
||||
|
||||
it('should build PlayMode args', () => {
|
||||
const run: TestRunDefinition = { name: 'play', playMode: true };
|
||||
|
||||
const args = TestWorkflowService.buildUnityArgs(run, baseParams);
|
||||
|
||||
expect(args).toContain('-testPlatform PlayMode');
|
||||
});
|
||||
|
||||
it('should build built-client args', () => {
|
||||
const run: TestRunDefinition = {
|
||||
name: 'client',
|
||||
builtClient: true,
|
||||
builtClientPath: './Builds/Linux',
|
||||
};
|
||||
|
||||
const args = TestWorkflowService.buildUnityArgs(run, baseParams);
|
||||
|
||||
expect(args).toContain('-testPlatform StandalonePlayer');
|
||||
expect(args).toContain('-builtPlayerPath');
|
||||
expect(args).toContain('./Builds/Linux');
|
||||
});
|
||||
|
||||
it('should include taxonomy filter args', () => {
|
||||
const run: TestRunDefinition = {
|
||||
name: 'filtered',
|
||||
editMode: true,
|
||||
filters: { Maturity: 'Trusted', Scope: 'Unit,Integration' },
|
||||
};
|
||||
|
||||
const args = TestWorkflowService.buildUnityArgs(run, baseParams);
|
||||
|
||||
expect(args).toContain('--testFilter');
|
||||
expect(args).toContain('Maturity=Trusted');
|
||||
});
|
||||
|
||||
it('should include build target', () => {
|
||||
const run: TestRunDefinition = { name: 'test', editMode: true };
|
||||
|
||||
const args = TestWorkflowService.buildUnityArgs(run, baseParams);
|
||||
|
||||
expect(args).toContain('-buildTarget StandaloneLinux64');
|
||||
});
|
||||
});
|
||||
});
|
||||
5
src/model/orchestrator/services/test/README.md
Normal file
5
src/model/orchestrator/services/test/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Test Workflow Engine
|
||||
|
||||
Service for YAML-based test suite definitions, taxonomy filtering, and structured test results.
|
||||
|
||||
See GitHub Issue for full specification.
|
||||
Reference in New Issue
Block a user