Compare commits

..

5 Commits

Author SHA1 Message Date
frostebite
c5fd895bd6 fix: replace orchestrator-develop branch references with main
The orchestrator-develop branch no longer exists. Update all fallback
clone commands and test fixtures to use main instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:09:49 +00:00
frostebite
302a250b3d ci: set macOS builds to continue-on-error
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 23:34:08 +00:00
frostebite
d17b099593 style: format changed files with prettier
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 07:52:11 +00:00
frostebite
f4bc5d20c4 feat(orchestrator): multi-storage support for GCP and Azure providers
Both providers now support four storage backends via gcpStorageType / azureStorageType:

GCP Cloud Run:
  - gcs-fuse: Mount GCS bucket as POSIX filesystem (unlimited, best for large sequential I/O)
  - gcs-copy: Copy artifacts in/out via gsutil (simpler, no FUSE overhead)
  - nfs: Filestore NFS mount (true POSIX, good random I/O, up to 100 TiB)
  - in-memory: tmpfs (fastest, volatile, up to 32 GiB)

Azure ACI:
  - azure-files: SMB file share mount (up to 100 TiB, premium throughput)
  - blob-copy: Copy artifacts in/out via az storage blob (no mount overhead)
  - azure-files-nfs: NFS 4.1 file share mount (true POSIX, no SMB lock overhead)
  - in-memory: emptyDir tmpfs (fastest, volatile, limited by container memory)

New inputs: gcpStorageType, gcpFilestoreIp, gcpFilestoreShare, azureStorageType,
azureBlobContainer. Constructor validates storage config and warns on missing
prerequisites (e.g. NFS requires VPC connector/subnet).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 07:07:20 +00:00
frostebite
d8563369e1 feat(orchestrator): add experimental GCP Cloud Run and Azure ACI providers
Add two new cloud provider implementations for the orchestrator, both marked
as experimental:

- **GCP Cloud Run Jobs** (`providerStrategy: gcp-cloud-run`): Executes Unity
  builds as Cloud Run Jobs with GCS FUSE for large artifact storage. Supports
  configurable machine types, service accounts, and VPC connectors. 7 new inputs
  (gcpProject, gcpRegion, gcpBucket, gcpMachineType, gcpDiskSizeGb,
  gcpServiceAccount, gcpVpcConnector).

- **Azure Container Instances** (`providerStrategy: azure-aci`): Executes Unity
  builds as ACI containers with Azure File Shares (Premium FileStorage) for
  large artifact storage up to 100 TiB. Supports configurable CPU/memory,
  VNet integration, and subscription targeting. 9 new inputs
  (azureResourceGroup, azureLocation, azureStorageAccount, azureFileShareName,
  azureSubscriptionId, azureCpu, azureMemoryGb, azureDiskSizeGb, azureSubnetId).

Both providers use their respective CLIs (gcloud, az) for infrastructure
management and support garbage collection of old build resources. No tests
included as these require real cloud infrastructure to validate.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 07:00:09 +00:00
18 changed files with 2063 additions and 2683 deletions

View File

@@ -279,23 +279,120 @@ inputs:
description:
'[Orchestrator] Specifies the repo for the unity builder. Useful if you forked the repo for testing, features, or
fixes.'
testSuitePath:
description: 'Path to YAML test suite definition file'
gcpProject:
required: false
testSuiteEvent:
description: 'CI event name for suite selection (pr, push, release)'
default: ''
description:
'[Orchestrator] [Experimental] Google Cloud project ID for Cloud Run Jobs provider. Falls back to
GOOGLE_CLOUD_PROJECT env var.'
gcpRegion:
required: false
testTaxonomyPath:
description: 'Path to custom taxonomy definition YAML'
default: ''
description:
'[Orchestrator] [Experimental] Google Cloud region for Cloud Run Jobs (e.g. us-central1). Defaults to the region
input if empty.'
gcpStorageType:
required: false
testResultFormat:
description: 'Test result output format: junit, json, or both'
default: 'gcs-fuse'
description:
'[Orchestrator] [Experimental] Storage type for Cloud Run Jobs. Options: gcs-fuse (mount GCS bucket as filesystem,
unlimited size, best for large sequential I/O), gcs-copy (copy artifacts in/out via gsutil, simpler, no FUSE
overhead), nfs (Filestore NFS mount, true POSIX, good random I/O, up to 100 TiB), in-memory (tmpfs, fastest but
volatile, up to 32 GiB).'
gcpBucket:
required: false
default: 'junit'
testResultPath:
description: 'Directory for structured test result output'
default: ''
description:
'[Orchestrator] [Experimental] GCS bucket name for build artifact storage. Used by gcs-fuse and gcs-copy storage
types.'
gcpFilestoreIp:
required: false
default: './test-results'
default: ''
description:
'[Orchestrator] [Experimental] Filestore instance IP address for NFS storage type. Required when gcpStorageType is
nfs.'
gcpFilestoreShare:
required: false
default: '/share1'
description:
'[Orchestrator] [Experimental] Filestore share name for NFS storage type. Defaults to /share1 (the Filestore
default).'
gcpMachineType:
required: false
default: 'e2-standard-4'
description: '[Orchestrator] [Experimental] Machine type for Cloud Run Jobs (e.g. e2-standard-4, e2-highmem-8).'
gcpDiskSizeGb:
required: false
default: '100'
description:
'[Orchestrator] [Experimental] Disk size in GB for Cloud Run Jobs in-memory volumes. Only applies to in-memory
storage type (max 32).'
gcpServiceAccount:
required: false
default: ''
description: '[Orchestrator] [Experimental] Google Cloud service account email for Cloud Run Jobs execution.'
gcpVpcConnector:
required: false
default: ''
description: '[Orchestrator] [Experimental] VPC connector name for Cloud Run Jobs private networking.'
azureResourceGroup:
required: false
default: ''
description:
'[Orchestrator] [Experimental] Azure resource group for Container Instances provider. Falls back to
AZURE_RESOURCE_GROUP env var.'
azureLocation:
required: false
default: ''
description:
'[Orchestrator] [Experimental] Azure region for Container Instances (e.g. eastus, westeurope). Defaults to the
region input if empty.'
azureStorageType:
required: false
default: 'azure-files'
description:
'[Orchestrator] [Experimental] Storage type for Azure Container Instances. Options: azure-files (SMB file share
mount, up to 100 TiB, premium throughput), blob-copy (copy artifacts in/out via az storage blob, no mount
overhead), azure-files-nfs (NFS 4.1 file share mount, true POSIX, no SMB lock overhead), in-memory (emptyDir
tmpfs, fastest but volatile, size limited by container memory).'
azureStorageAccount:
required: false
default: ''
description:
'[Orchestrator] [Experimental] Azure Storage Account name. Used by azure-files, azure-files-nfs, and blob-copy
storage types.'
azureFileShareName:
required: false
default: 'unity-builds'
description:
'[Orchestrator] [Experimental] Azure File Share name within the storage account. Used by azure-files and
azure-files-nfs storage types. Supports up to 100 TiB per share.'
azureBlobContainer:
required: false
default: 'unity-builds'
description: '[Orchestrator] [Experimental] Azure Blob container name for blob-copy storage type.'
azureSubscriptionId:
required: false
default: ''
description: '[Orchestrator] [Experimental] Azure subscription ID. Falls back to AZURE_SUBSCRIPTION_ID env var.'
azureCpu:
required: false
default: '4'
description: '[Orchestrator] [Experimental] CPU cores for Azure Container Instances (1-16).'
azureMemoryGb:
required: false
default: '16'
description: '[Orchestrator] [Experimental] Memory in GB for Azure Container Instances (1-16).'
azureDiskSizeGb:
required: false
default: '100'
description:
'[Orchestrator] [Experimental] File share quota in GB for Azure Container Instances. Premium shares support up to
102400 GB (100 TiB).'
azureSubnetId:
required: false
default: ''
description: '[Orchestrator] [Experimental] Azure subnet resource ID for VNet-integrated Container Instances.'
outputs:
volume:

1836
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -3,7 +3,6 @@ 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 { TestWorkflowService } from './model/orchestrator/services/test-workflow';
async function runMain() {
try {
@@ -18,23 +17,6 @@ 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;

View File

@@ -107,11 +107,30 @@ class BuildParameters {
public unityHubVersionOnMac!: string;
public dockerWorkspacePath!: string;
public testSuitePath!: string;
public testSuiteEvent!: string;
public testTaxonomyPath!: string;
public testResultFormat!: string;
public testResultPath!: string;
// GCP Cloud Run (Experimental)
public gcpProject!: string;
public gcpRegion!: string;
public gcpStorageType!: string;
public gcpBucket!: string;
public gcpFilestoreIp!: string;
public gcpFilestoreShare!: string;
public gcpMachineType!: string;
public gcpDiskSizeGb!: string;
public gcpServiceAccount!: string;
public gcpVpcConnector!: string;
// Azure Container Instances (Experimental)
public azureResourceGroup!: string;
public azureLocation!: string;
public azureStorageType!: string;
public azureStorageAccount!: string;
public azureBlobContainer!: string;
public azureFileShareName!: string;
public azureSubscriptionId!: string;
public azureCpu!: string;
public azureMemoryGb!: string;
public azureDiskSizeGb!: string;
public azureSubnetId!: string;
public static shouldUseRetainedWorkspaceMode(buildParameters: BuildParameters) {
return buildParameters.maxRetainedWorkspaces > 0 && Orchestrator.lockedWorkspace !== ``;
@@ -234,6 +253,27 @@ class BuildParameters {
inputPullCommand: OrchestratorOptions.inputPullCommand,
pullInputList: OrchestratorOptions.pullInputList,
kubeStorageClass: OrchestratorOptions.kubeStorageClass,
gcpProject: Input.gcpProject,
gcpRegion: Input.gcpRegion,
gcpStorageType: Input.gcpStorageType,
gcpBucket: Input.gcpBucket,
gcpFilestoreIp: Input.gcpFilestoreIp,
gcpFilestoreShare: Input.gcpFilestoreShare,
gcpMachineType: Input.gcpMachineType,
gcpDiskSizeGb: Input.gcpDiskSizeGb,
gcpServiceAccount: Input.gcpServiceAccount,
gcpVpcConnector: Input.gcpVpcConnector,
azureResourceGroup: Input.azureResourceGroup,
azureLocation: Input.azureLocation,
azureStorageType: Input.azureStorageType,
azureStorageAccount: Input.azureStorageAccount,
azureBlobContainer: Input.azureBlobContainer,
azureFileShareName: Input.azureFileShareName,
azureSubscriptionId: Input.azureSubscriptionId,
azureCpu: Input.azureCpu,
azureMemoryGb: Input.azureMemoryGb,
azureDiskSizeGb: Input.azureDiskSizeGb,
azureSubnetId: Input.azureSubnetId,
cacheKey: OrchestratorOptions.cacheKey,
maxRetainedWorkspaces: Number.parseInt(OrchestratorOptions.maxRetainedWorkspaces),
useLargePackages: OrchestratorOptions.useLargePackages,
@@ -248,11 +288,6 @@ class BuildParameters {
cacheUnityInstallationOnMac: Input.cacheUnityInstallationOnMac,
unityHubVersionOnMac: Input.unityHubVersionOnMac,
dockerWorkspacePath: Input.dockerWorkspacePath,
testSuitePath: Input.testSuitePath,
testSuiteEvent: Input.testSuiteEvent,
testTaxonomyPath: Input.testTaxonomyPath,
testResultFormat: Input.testResultFormat,
testResultPath: Input.testResultPath,
};
}

View File

@@ -282,24 +282,90 @@ class Input {
return Input.getInput('skipActivation')?.toLowerCase() ?? 'false';
}
static get testSuitePath(): string {
return Input.getInput('testSuitePath') ?? '';
// GCP Cloud Run (Experimental)
static get gcpProject(): string {
return Input.getInput('gcpProject') ?? '';
}
static get testSuiteEvent(): string {
return Input.getInput('testSuiteEvent') ?? '';
static get gcpRegion(): string {
return Input.getInput('gcpRegion') ?? '';
}
static get testTaxonomyPath(): string {
return Input.getInput('testTaxonomyPath') ?? '';
static get gcpStorageType(): string {
return Input.getInput('gcpStorageType') ?? 'gcs-fuse';
}
static get testResultFormat(): string {
return Input.getInput('testResultFormat') ?? 'junit';
static get gcpBucket(): string {
return Input.getInput('gcpBucket') ?? '';
}
static get testResultPath(): string {
return Input.getInput('testResultPath') ?? './test-results';
static get gcpFilestoreIp(): string {
return Input.getInput('gcpFilestoreIp') ?? '';
}
static get gcpFilestoreShare(): string {
return Input.getInput('gcpFilestoreShare') ?? '/share1';
}
static get gcpMachineType(): string {
return Input.getInput('gcpMachineType') ?? 'e2-standard-4';
}
static get gcpDiskSizeGb(): string {
return Input.getInput('gcpDiskSizeGb') ?? '100';
}
static get gcpServiceAccount(): string {
return Input.getInput('gcpServiceAccount') ?? '';
}
static get gcpVpcConnector(): string {
return Input.getInput('gcpVpcConnector') ?? '';
}
// Azure Container Instances (Experimental)
static get azureResourceGroup(): string {
return Input.getInput('azureResourceGroup') ?? '';
}
static get azureLocation(): string {
return Input.getInput('azureLocation') ?? '';
}
static get azureStorageType(): string {
return Input.getInput('azureStorageType') ?? 'azure-files';
}
static get azureStorageAccount(): string {
return Input.getInput('azureStorageAccount') ?? '';
}
static get azureBlobContainer(): string {
return Input.getInput('azureBlobContainer') ?? 'unity-builds';
}
static get azureFileShareName(): string {
return Input.getInput('azureFileShareName') ?? 'unity-builds';
}
static get azureSubscriptionId(): string {
return Input.getInput('azureSubscriptionId') ?? '';
}
static get azureCpu(): string {
return Input.getInput('azureCpu') ?? '4';
}
static get azureMemoryGb(): string {
return Input.getInput('azureMemoryGb') ?? '16';
}
static get azureDiskSizeGb(): string {
return Input.getInput('azureDiskSizeGb') ?? '100';
}
static get azureSubnetId(): string {
return Input.getInput('azureSubnetId') ?? '';
}
public static ToEnvVarFormat(input: string) {

View File

@@ -13,6 +13,8 @@ import OrchestratorEnvironmentVariable from './options/orchestrator-environment-
import TestOrchestrator from './providers/test';
import LocalOrchestrator from './providers/local';
import LocalDockerOrchestrator from './providers/docker';
import GcpCloudRunProvider from './providers/gcp-cloud-run';
import AzureAciProvider from './providers/azure-aci';
import loadProvider from './providers/provider-loader';
import GitHub from '../github';
import SharedWorkspaceLocking from './services/core/shared-workspace-locking';
@@ -158,6 +160,14 @@ class Orchestrator {
case 'local':
Orchestrator.Provider = new LocalOrchestrator();
break;
case 'gcp-cloud-run':
OrchestratorLogger.log('⚠ EXPERIMENTAL: GCP Cloud Run Jobs provider');
Orchestrator.Provider = new GcpCloudRunProvider(Orchestrator.buildParameters);
break;
case 'azure-aci':
OrchestratorLogger.log('⚠ EXPERIMENTAL: Azure Container Instances provider');
Orchestrator.Provider = new AzureAciProvider(Orchestrator.buildParameters);
break;
default:
// Try to load provider using the dynamic loader for unknown providers
try {

View File

@@ -0,0 +1,536 @@
/**
* Azure Container Instances (ACI) Provider (Experimental)
*
* Executes Unity builds as Azure Container Instances with configurable storage backends.
*
* Storage types:
* - azure-files: SMB file share mount via Azure Files. Up to 100 TiB per share,
* premium throughput. Default.
* Requires: azureStorageAccount, azureFileShareName
* - blob-copy: Copy artifacts in/out of Azure Blob Storage before/after the build.
* No mount overhead, simpler.
* Requires: azureStorageAccount, azureBlobContainer
* - azure-files-nfs: NFS 4.1 file share mount. True POSIX semantics, no SMB lock overhead,
* better for Unity Library caching (many small random reads).
* Requires: azureStorageAccount, azureFileShareName, Premium FileStorage,
* VNet integration (azureSubnetId)
* - in-memory: emptyDir volume (tmpfs). Fastest I/O but volatile, size limited by
* container memory allocation.
*
* Prerequisites:
* - Azure CLI authenticated (az login or service principal)
* - A resource group for build resources
* - Contributor role on the resource group
*
* @experimental This provider is experimental. APIs and behavior may change.
*/
import { ProviderInterface } from '../provider-interface';
import BuildParameters from '../../../build-parameters';
import OrchestratorLogger from '../../services/core/orchestrator-logger';
import OrchestratorEnvironmentVariable from '../../options/orchestrator-environment-variable';
import OrchestratorSecret from '../../options/orchestrator-secret';
import { ProviderResource } from '../provider-resource';
import { ProviderWorkflow } from '../provider-workflow';
import { OrchestratorSystem } from '../../services/core/orchestrator-system';
import { Input } from '../../..';
import ResourceTracking from '../../services/core/resource-tracking';
type AzureStorageType = 'azure-files' | 'blob-copy' | 'azure-files-nfs' | 'in-memory';
class AzureAciProvider implements ProviderInterface {
private readonly resourceGroup: string;
private readonly location: string;
private readonly storageType: AzureStorageType;
private readonly storageAccount: string;
private readonly blobContainer: string;
private readonly fileShareName: string;
private readonly subscriptionId: string;
private readonly cpu: number;
private readonly memoryGb: number;
private readonly diskSizeGb: number;
private readonly subnetId: string;
private buildParameters: BuildParameters;
constructor(buildParameters: BuildParameters) {
this.buildParameters = buildParameters;
this.resourceGroup = buildParameters.azureResourceGroup || process.env.AZURE_RESOURCE_GROUP || '';
this.location = buildParameters.azureLocation || Input.region || 'eastus';
this.storageType = (buildParameters.azureStorageType || 'azure-files') as AzureStorageType;
this.storageAccount = buildParameters.azureStorageAccount || process.env.AZURE_STORAGE_ACCOUNT || '';
this.blobContainer = buildParameters.azureBlobContainer || 'unity-builds';
this.fileShareName = buildParameters.azureFileShareName || 'unity-builds';
this.subscriptionId = buildParameters.azureSubscriptionId || process.env.AZURE_SUBSCRIPTION_ID || '';
this.cpu = Number.parseInt(buildParameters.azureCpu || '4', 10);
this.memoryGb = Number.parseInt(buildParameters.azureMemoryGb || '16', 10);
this.diskSizeGb = Number.parseInt(buildParameters.azureDiskSizeGb || '100', 10);
this.subnetId = buildParameters.azureSubnetId || '';
OrchestratorLogger.log('[Azure ACI] Provider initialized (EXPERIMENTAL)');
OrchestratorLogger.log(`[Azure ACI] Resource Group: ${this.resourceGroup || '(not set)'}`);
OrchestratorLogger.log(`[Azure ACI] Location: ${this.location}`);
OrchestratorLogger.log(`[Azure ACI] Storage: ${this.storageType}`);
OrchestratorLogger.log(`[Azure ACI] Resources: ${this.cpu} CPU, ${this.memoryGb}GB RAM`);
this.validateStorageConfig();
}
private validateStorageConfig(): void {
switch (this.storageType) {
case 'azure-files':
if (!this.storageAccount) {
OrchestratorLogger.logWarning(
'[Azure ACI] Storage type "azure-files" requires azureStorageAccount to be set.',
);
} else {
OrchestratorLogger.log(`[Azure ACI] File Share: ${this.storageAccount}/${this.fileShareName} (SMB)`);
}
break;
case 'azure-files-nfs':
if (!this.storageAccount) {
OrchestratorLogger.logWarning(
'[Azure ACI] Storage type "azure-files-nfs" requires azureStorageAccount (Premium FileStorage).',
);
}
if (!this.subnetId) {
OrchestratorLogger.logWarning('[Azure ACI] NFS file shares require VNet integration. Set azureSubnetId.');
} else {
OrchestratorLogger.log(`[Azure ACI] File Share: ${this.storageAccount}/${this.fileShareName} (NFS 4.1)`);
}
break;
case 'blob-copy':
if (!this.storageAccount) {
OrchestratorLogger.logWarning('[Azure ACI] Storage type "blob-copy" requires azureStorageAccount to be set.');
} else {
OrchestratorLogger.log(`[Azure ACI] Blob container: ${this.storageAccount}/${this.blobContainer}`);
}
break;
case 'in-memory':
OrchestratorLogger.log(
`[Azure ACI] In-memory volume (emptyDir): limited by ${this.memoryGb}GB container memory`,
);
break;
default:
OrchestratorLogger.logWarning(
`[Azure ACI] Unknown storage type '${this.storageType}'. Valid: azure-files, blob-copy, azure-files-nfs, in-memory`,
);
}
if (!this.resourceGroup) {
OrchestratorLogger.logWarning(
'[Azure ACI] No resource group specified. Set azureResourceGroup input or AZURE_RESOURCE_GROUP env var.',
);
}
}
async setupWorkflow(
buildGuid: string,
buildParameters: BuildParameters,
branchName: string,
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
) {
OrchestratorLogger.log(`[Azure ACI] Setting up workflow for build ${buildGuid}`);
ResourceTracking.logAllocationSummary('azure-aci setup');
// Verify Azure CLI is available
try {
await OrchestratorSystem.Run('az version --output json', false, true);
OrchestratorLogger.log('[Azure ACI] Azure CLI detected');
} catch {
throw new Error(
'[Azure ACI] Azure CLI not found. Install Azure CLI: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli',
);
}
if (this.subscriptionId) {
await OrchestratorSystem.Run(`az account set --subscription="${this.subscriptionId}"`);
}
// Ensure resource group exists
if (this.resourceGroup) {
try {
await OrchestratorSystem.Run(`az group show --name "${this.resourceGroup}" --output json`, false, true);
OrchestratorLogger.log(`[Azure ACI] Resource group ${this.resourceGroup} exists`);
} catch {
OrchestratorLogger.log(`[Azure ACI] Creating resource group ${this.resourceGroup}`);
await OrchestratorSystem.Run(`az group create --name "${this.resourceGroup}" --location "${this.location}"`);
}
}
// Storage-specific setup
switch (this.storageType) {
case 'azure-files':
await this.setupStorageAccount('Standard_LRS', 'StorageV2');
await this.setupFileShare();
break;
case 'azure-files-nfs':
await this.setupStorageAccount('Premium_LRS', 'FileStorage');
await this.setupNfsFileShare();
break;
case 'blob-copy':
await this.setupStorageAccount('Standard_LRS', 'StorageV2');
await this.setupBlobContainer();
break;
case 'in-memory':
// No storage setup needed
break;
}
}
private async setupStorageAccount(sku: string, kind: string): Promise<void> {
if (!this.storageAccount || !this.resourceGroup) return;
try {
await OrchestratorSystem.Run(
`az storage account show --name "${this.storageAccount}" --resource-group "${this.resourceGroup}" --output json`,
false,
true,
);
OrchestratorLogger.log(`[Azure ACI] Storage account ${this.storageAccount} exists`);
} catch {
OrchestratorLogger.log(`[Azure ACI] Creating storage account ${this.storageAccount} (${sku}, ${kind})`);
await OrchestratorSystem.Run(
`az storage account create --name "${this.storageAccount}" --resource-group "${this.resourceGroup}" --location "${this.location}" --sku ${sku} --kind ${kind}`,
);
}
}
private async setupFileShare(): Promise<void> {
if (!this.storageAccount || !this.resourceGroup) return;
try {
await OrchestratorSystem.Run(
`az storage share-rm show --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --output json`,
false,
true,
);
} catch {
OrchestratorLogger.log(`[Azure ACI] Creating file share ${this.fileShareName} (${this.diskSizeGb}GB)`);
await OrchestratorSystem.Run(
`az storage share-rm create --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --quota ${this.diskSizeGb}`,
);
}
}
private async setupNfsFileShare(): Promise<void> {
if (!this.storageAccount || !this.resourceGroup) return;
try {
await OrchestratorSystem.Run(
`az storage share-rm show --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --output json`,
false,
true,
);
} catch {
OrchestratorLogger.log(`[Azure ACI] Creating NFS file share ${this.fileShareName} (${this.diskSizeGb}GB)`);
await OrchestratorSystem.Run(
`az storage share-rm create --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --quota ${this.diskSizeGb} --enabled-protocols NFS`,
);
}
}
private async setupBlobContainer(): Promise<void> {
if (!this.storageAccount || !this.resourceGroup) return;
try {
await OrchestratorSystem.Run(
`az storage container show --name "${this.blobContainer}" --account-name "${this.storageAccount}" --output json`,
false,
true,
);
} catch {
OrchestratorLogger.log(`[Azure ACI] Creating blob container ${this.blobContainer}`);
await OrchestratorSystem.Run(
`az storage container create --name "${this.blobContainer}" --account-name "${this.storageAccount}"`,
);
}
}
private async getStorageKey(): Promise<string> {
if (!this.storageAccount || !this.resourceGroup) return '';
try {
const keyJson = await OrchestratorSystem.Run(
`az storage account keys list --account-name "${this.storageAccount}" --resource-group "${this.resourceGroup}" --output json`,
false,
true,
);
const keys = JSON.parse(keyJson);
return keys[0]?.value || '';
} catch (error: any) {
OrchestratorLogger.logWarning(`[Azure ACI] Could not get storage key: ${error.message}`);
return '';
}
}
private async buildVolumeFlags(mountdir: string): Promise<string> {
switch (this.storageType) {
case 'azure-files': {
const storageKey = await this.getStorageKey();
if (!storageKey) return '';
return [
`--azure-file-volume-account-name "${this.storageAccount}"`,
`--azure-file-volume-account-key "${storageKey}"`,
`--azure-file-volume-share-name "${this.fileShareName}"`,
`--azure-file-volume-mount-path "${mountdir}"`,
].join(' ');
}
case 'azure-files-nfs': {
// ACI NFS mount uses a YAML deployment template; for CLI we use the same
// azure-file-volume flags but the share must be NFS-enabled and
// the container must be in a VNet
const storageKey = await this.getStorageKey();
if (!storageKey) return '';
return [
`--azure-file-volume-account-name "${this.storageAccount}"`,
`--azure-file-volume-account-key "${storageKey}"`,
`--azure-file-volume-share-name "${this.fileShareName}"`,
`--azure-file-volume-mount-path "${mountdir}"`,
].join(' ');
}
case 'in-memory':
// ACI emptyDir volumes require YAML deployment; for simplicity we skip
// the volume mount and let the container use its own filesystem
OrchestratorLogger.log('[Azure ACI] In-memory mode: using container filesystem (no persistent mount)');
return '';
case 'blob-copy':
// No volume mount — artifacts are copied in/out via az storage blob commands
return '';
default:
return '';
}
}
async runTaskInWorkflow(
buildGuid: string,
image: string,
commands: string,
mountdir: string,
workingdir: string,
environment: OrchestratorEnvironmentVariable[],
secrets: OrchestratorSecret[],
): Promise<string> {
OrchestratorLogger.log(`[Azure ACI] Running task for build ${buildGuid}`);
ResourceTracking.logAllocationSummary('azure-aci task');
const containerName = `unity-build-${buildGuid}`
.toLowerCase()
.replace(/[^a-z0-9-]/g, '-')
.slice(0, 63);
// Build environment variable flags
const allEnvVars = [
...environment.map((env) => `${env.name}=${env.value}`),
...secrets.map((s) => `${s.EnvironmentVariable}=${s.ParameterValue}`),
];
const envFlag = allEnvVars.length > 0 ? `--environment-variables ${allEnvVars.map((e) => `"${e}"`).join(' ')}` : '';
// Build volume flags based on storage type
const volumeFlags = await this.buildVolumeFlags(mountdir);
const subnetFlag = this.subnetId ? `--subnet "${this.subnetId}"` : '';
// For blob-copy, wrap the user command with copy-in/copy-out steps
let effectiveCommands = commands;
if (this.storageType === 'blob-copy' && this.storageAccount && commands) {
effectiveCommands = [
`az storage blob download-batch --destination "${mountdir}" --source "${this.blobContainer}" --account-name "${this.storageAccount}" 2>/dev/null || true`,
commands,
`az storage blob upload-batch --source "${mountdir}" --destination "${this.blobContainer}" --account-name "${this.storageAccount}" --overwrite`,
].join(' && ');
}
const commandFlag = effectiveCommands
? `--command-line "/bin/sh -c '${effectiveCommands.replace(/'/g, "'\\''")}'"`
: '';
const createCmd = [
'az container create',
`--resource-group "${this.resourceGroup}"`,
`--name "${containerName}"`,
`--image "${image}"`,
`--location "${this.location}"`,
`--cpu ${this.cpu}`,
`--memory ${this.memoryGb}`,
'--restart-policy Never',
'--os-type Linux',
volumeFlags,
envFlag,
subnetFlag,
commandFlag,
'--output json',
]
.filter(Boolean)
.join(' ');
try {
await OrchestratorSystem.Run(createCmd);
OrchestratorLogger.log(
`[Azure ACI] Container ${containerName} created (storage: ${this.storageType}), waiting for completion...`,
);
} catch (error: any) {
throw new Error(`[Azure ACI] Failed to create container: ${error.message}`);
}
const output = await this.waitForContainerCompletion(containerName);
return output;
}
private async waitForContainerCompletion(containerName: string): Promise<string> {
const maxWaitMs = 24 * 60 * 60 * 1000;
const pollIntervalMs = 15_000;
const startTime = Date.now();
let lastLogLength = 0;
while (Date.now() - startTime < maxWaitMs) {
try {
const stateJson = await OrchestratorSystem.Run(
`az container show --resource-group "${this.resourceGroup}" --name "${containerName}" --output json`,
false,
true,
);
const state = JSON.parse(stateJson);
const containerState =
state.containers?.[0]?.instanceView?.currentState?.state || state.instanceView?.state || 'Unknown';
const provisioningState = state.provisioningState || 'Unknown';
// Stream logs incrementally
try {
const logs = await OrchestratorSystem.Run(
`az container logs --resource-group "${this.resourceGroup}" --name "${containerName}"`,
false,
true,
);
if (logs && logs.length > lastLogLength) {
const newLogs = logs.slice(lastLogLength);
for (const line of newLogs.split('\n')) {
if (line.trim()) {
OrchestratorLogger.log(`[Build] ${line}`);
}
}
lastLogLength = logs.length;
}
} catch {
// Logs may not be available yet
}
if (containerState === 'Terminated' || provisioningState === 'Succeeded') {
const exitCode = state.containers?.[0]?.instanceView?.currentState?.exitCode;
if (exitCode !== undefined && exitCode !== 0) {
throw new Error(`[Azure ACI] Container exited with code ${exitCode}`);
}
OrchestratorLogger.log('[Azure ACI] Container completed successfully');
try {
return await OrchestratorSystem.Run(
`az container logs --resource-group "${this.resourceGroup}" --name "${containerName}"`,
false,
true,
);
} catch {
return '';
}
}
if (provisioningState === 'Failed') {
const detail =
state.containers?.[0]?.instanceView?.currentState?.detailStatus ||
state.containers?.[0]?.instanceView?.events?.map((e: any) => e.message).join('; ') ||
'Unknown error';
throw new Error(`[Azure ACI] Container provisioning failed: ${detail}`);
}
} catch (error: any) {
if (error.message?.includes('Container provisioning failed') || error.message?.includes('exited with code')) {
throw error;
}
OrchestratorLogger.logWarning(`[Azure ACI] Polling error: ${error.message}`);
}
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
}
throw new Error('[Azure ACI] Container execution timed out after 24 hours');
}
async cleanupWorkflow(
buildParameters: BuildParameters,
branchName: string,
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
) {
OrchestratorLogger.log('[Azure ACI] Cleaning up workflow');
}
async garbageCollect(
filter: string,
previewOnly: boolean,
olderThan: Number,
fullCache: boolean,
baseDependencies: boolean,
): Promise<string> {
OrchestratorLogger.log('[Azure ACI] Garbage collecting old container groups');
try {
const containersJson = await OrchestratorSystem.Run(
`az container list --resource-group "${this.resourceGroup}" --output json`,
false,
true,
);
const containers = JSON.parse(containersJson || '[]');
const cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() - Number(olderThan));
let deletedCount = 0;
for (const container of containers) {
const name = container.name || '';
if (!name.startsWith('unity-build-')) continue;
const createdAt = new Date(container.tags?.createdAt || container.properties?.provisioningState || 0);
const state = container.containers?.[0]?.instanceView?.currentState?.state || '';
if (state === 'Terminated' || createdAt < cutoffDate) {
if (previewOnly) {
OrchestratorLogger.log(`[Azure ACI] Would delete: ${name}`);
} else {
await OrchestratorSystem.Run(
`az container delete --resource-group "${this.resourceGroup}" --name "${name}" --yes`,
);
deletedCount++;
}
}
}
return `Garbage collected ${deletedCount} Azure container instances`;
} catch (error: any) {
OrchestratorLogger.logWarning(`[Azure ACI] Garbage collection failed: ${error.message}`);
return '';
}
}
async listResources(): Promise<ProviderResource[]> {
try {
const containersJson = await OrchestratorSystem.Run(
`az container list --resource-group "${this.resourceGroup}" --output json`,
false,
true,
);
const containers = JSON.parse(containersJson || '[]');
return containers
.filter((c: any) => (c.name || '').startsWith('unity-build-'))
.map((c: any) => ({ Name: c.name || '' }));
} catch {
return [];
}
}
listWorkflow(): Promise<ProviderWorkflow[]> {
throw new Error('[Azure ACI] listWorkflow not implemented for this experimental provider');
}
async watchWorkflow(): Promise<string> {
throw new Error('[Azure ACI] watchWorkflow not implemented for this experimental provider');
}
}
export default AzureAciProvider;

View File

@@ -0,0 +1,435 @@
/**
* Google Cloud Run Jobs Provider (Experimental)
*
* Executes Unity builds as Cloud Run Jobs with configurable storage backends.
*
* Storage types:
* - gcs-fuse: Mount a GCS bucket as a POSIX filesystem via GCS FUSE sidecar.
* Unlimited size, best for large sequential reads/writes.
* Requires: gcpBucket
* - gcs-copy: Copy artifacts in/out of GCS before/after the build via gsutil.
* No mount overhead, simpler, works everywhere.
* Requires: gcpBucket
* - nfs: Mount a Filestore NFS share. True POSIX semantics, good random I/O,
* up to 100 TiB. Best for Library caching (many small random reads).
* Requires: gcpFilestoreIp, gcpFilestoreShare
* - in-memory: tmpfs volume (emptyDir). Fastest I/O but volatile and limited to 32 GiB.
* Good for scratch/temp space during builds.
*
* Prerequisites:
* - Google Cloud SDK authenticated (GOOGLE_APPLICATION_CREDENTIALS or gcloud auth)
* - Cloud Run Jobs API enabled
* - Service account with roles: Cloud Run Admin, Storage Admin, Logs Viewer
*
* @experimental This provider is experimental. APIs and behavior may change.
*/
import { ProviderInterface } from '../provider-interface';
import BuildParameters from '../../../build-parameters';
import OrchestratorLogger from '../../services/core/orchestrator-logger';
import OrchestratorEnvironmentVariable from '../../options/orchestrator-environment-variable';
import OrchestratorSecret from '../../options/orchestrator-secret';
import { ProviderResource } from '../provider-resource';
import { ProviderWorkflow } from '../provider-workflow';
import { OrchestratorSystem } from '../../services/core/orchestrator-system';
import { Input } from '../../..';
import ResourceTracking from '../../services/core/resource-tracking';
type GcpStorageType = 'gcs-fuse' | 'gcs-copy' | 'nfs' | 'in-memory';
class GcpCloudRunProvider implements ProviderInterface {
private readonly project: string;
private readonly region: string;
private readonly storageType: GcpStorageType;
private readonly bucket: string;
private readonly filestoreIp: string;
private readonly filestoreShare: string;
private readonly machineType: string;
private readonly diskSizeGb: number;
private readonly serviceAccount: string;
private readonly vpcConnector: string;
private buildParameters: BuildParameters;
constructor(buildParameters: BuildParameters) {
this.buildParameters = buildParameters;
this.project = buildParameters.gcpProject || process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT || '';
this.region = buildParameters.gcpRegion || Input.region || 'us-central1';
this.storageType = (buildParameters.gcpStorageType || 'gcs-fuse') as GcpStorageType;
this.bucket = buildParameters.gcpBucket || '';
this.filestoreIp = buildParameters.gcpFilestoreIp || '';
this.filestoreShare = buildParameters.gcpFilestoreShare || '/share1';
this.machineType = buildParameters.gcpMachineType || 'e2-standard-4';
this.diskSizeGb = Number.parseInt(buildParameters.gcpDiskSizeGb || '100', 10);
this.serviceAccount = buildParameters.gcpServiceAccount || '';
this.vpcConnector = buildParameters.gcpVpcConnector || '';
OrchestratorLogger.log('[GCP Cloud Run] Provider initialized (EXPERIMENTAL)');
OrchestratorLogger.log(`[GCP Cloud Run] Project: ${this.project || '(auto-detect)'}`);
OrchestratorLogger.log(`[GCP Cloud Run] Region: ${this.region}`);
OrchestratorLogger.log(`[GCP Cloud Run] Storage: ${this.storageType}`);
this.validateStorageConfig();
}
private validateStorageConfig(): void {
switch (this.storageType) {
case 'gcs-fuse':
case 'gcs-copy':
if (!this.bucket) {
OrchestratorLogger.logWarning(
`[GCP Cloud Run] Storage type '${this.storageType}' requires gcpBucket to be set.`,
);
} else {
OrchestratorLogger.log(`[GCP Cloud Run] Bucket: gs://${this.bucket}`);
}
break;
case 'nfs':
if (!this.filestoreIp) {
OrchestratorLogger.logWarning('[GCP Cloud Run] Storage type "nfs" requires gcpFilestoreIp to be set.');
} else {
OrchestratorLogger.log(`[GCP Cloud Run] Filestore: ${this.filestoreIp}:${this.filestoreShare}`);
}
if (!this.vpcConnector) {
OrchestratorLogger.logWarning(
'[GCP Cloud Run] NFS storage usually requires gcpVpcConnector for private network access to Filestore.',
);
}
break;
case 'in-memory':
OrchestratorLogger.log(`[GCP Cloud Run] In-memory volume: ${Math.min(this.diskSizeGb, 32)} GiB (max 32)`);
break;
default:
OrchestratorLogger.logWarning(
`[GCP Cloud Run] Unknown storage type '${this.storageType}'. Valid: gcs-fuse, gcs-copy, nfs, in-memory`,
);
}
if (!this.project) {
OrchestratorLogger.logWarning(
'[GCP Cloud Run] No project specified. Set gcpProject input or GOOGLE_CLOUD_PROJECT env var.',
);
}
}
async setupWorkflow(
buildGuid: string,
buildParameters: BuildParameters,
branchName: string,
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
) {
OrchestratorLogger.log(`[GCP Cloud Run] Setting up workflow for build ${buildGuid}`);
ResourceTracking.logAllocationSummary('gcp-cloud-run setup');
// Verify gcloud CLI is available
try {
await OrchestratorSystem.Run('gcloud --version', false, true);
OrchestratorLogger.log('[GCP Cloud Run] gcloud CLI detected');
} catch {
throw new Error(
'[GCP Cloud Run] gcloud CLI not found. Install Google Cloud SDK: https://cloud.google.com/sdk/docs/install',
);
}
// Verify Cloud Run Jobs API is enabled
try {
const projectFlag = this.project ? `--project=${this.project}` : '';
await OrchestratorSystem.Run(
`gcloud services list --enabled --filter="name:run.googleapis.com" ${projectFlag} --format="value(name)"`,
false,
true,
);
} catch {
OrchestratorLogger.logWarning(
'[GCP Cloud Run] Could not verify Cloud Run API status. Ensure run.googleapis.com is enabled.',
);
}
// Storage-specific setup
if ((this.storageType === 'gcs-fuse' || this.storageType === 'gcs-copy') && this.bucket) {
await this.ensureBucketExists();
}
}
private async ensureBucketExists(): Promise<void> {
try {
await OrchestratorSystem.Run(
`gcloud storage buckets describe gs://${this.bucket} --format="value(name)"`,
false,
true,
);
OrchestratorLogger.log(`[GCP Cloud Run] Bucket gs://${this.bucket} exists`);
} catch {
OrchestratorLogger.log(`[GCP Cloud Run] Creating bucket gs://${this.bucket}`);
const projectFlag = this.project ? `--project=${this.project}` : '';
await OrchestratorSystem.Run(
`gcloud storage buckets create gs://${this.bucket} --location=${this.region} ${projectFlag}`,
);
}
}
private buildVolumeFlags(mountdir: string): { volumeFlags: string; mountFlags: string } {
switch (this.storageType) {
case 'gcs-fuse':
if (!this.bucket) return { volumeFlags: '', mountFlags: '' };
return {
volumeFlags: `--add-volume=name=gcs-fuse,type=cloud-storage,bucket=${this.bucket}`,
mountFlags: `--add-volume-mount=volume=gcs-fuse,mount-path=${mountdir}`,
};
case 'nfs':
if (!this.filestoreIp) return { volumeFlags: '', mountFlags: '' };
return {
volumeFlags: `--add-volume=name=nfs-vol,type=nfs,location=${this.filestoreIp}:${this.filestoreShare}`,
mountFlags: `--add-volume-mount=volume=nfs-vol,mount-path=${mountdir}`,
};
case 'in-memory': {
const sizeGib = Math.min(this.diskSizeGb, 32);
return {
volumeFlags: `--add-volume=name=tmpfs-vol,type=in-memory,size-limit=${sizeGib}Gi`,
mountFlags: `--add-volume-mount=volume=tmpfs-vol,mount-path=${mountdir}`,
};
}
case 'gcs-copy':
// No volume mount — artifacts are copied in/out via gsutil commands
return { volumeFlags: '', mountFlags: '' };
default:
return { volumeFlags: '', mountFlags: '' };
}
}
private async copyArtifactsIn(mountdir: string): Promise<void> {
if (this.storageType !== 'gcs-copy' || !this.bucket) return;
OrchestratorLogger.log(`[GCP Cloud Run] Copying artifacts from gs://${this.bucket} to ${mountdir}`);
try {
await OrchestratorSystem.Run(`gcloud storage cp -r "gs://${this.bucket}/*" "${mountdir}/" || true`, false, true);
} catch {
OrchestratorLogger.log('[GCP Cloud Run] No existing artifacts to restore (bucket may be empty)');
}
}
private async copyArtifactsOut(mountdir: string): Promise<void> {
if (this.storageType !== 'gcs-copy' || !this.bucket) return;
OrchestratorLogger.log(`[GCP Cloud Run] Uploading artifacts from ${mountdir} to gs://${this.bucket}`);
await OrchestratorSystem.Run(`gcloud storage cp -r "${mountdir}/*" "gs://${this.bucket}/"`, false, true);
}
async runTaskInWorkflow(
buildGuid: string,
image: string,
commands: string,
mountdir: string,
workingdir: string,
environment: OrchestratorEnvironmentVariable[],
secrets: OrchestratorSecret[],
): Promise<string> {
OrchestratorLogger.log(`[GCP Cloud Run] Running task for build ${buildGuid}`);
ResourceTracking.logAllocationSummary('gcp-cloud-run task');
const jobName = `unity-build-${buildGuid}`
.toLowerCase()
.replace(/[^a-z0-9-]/g, '-')
.slice(0, 63);
const projectFlag = this.project ? `--project=${this.project}` : '';
// Build environment variable flags
const envFlags = environment
.map((env) => `${env.name}=${env.value}`)
.concat(secrets.map((s) => `${s.EnvironmentVariable}=${s.ParameterValue}`));
const envString = envFlags.length > 0 ? `--set-env-vars="${envFlags.join(',')}"` : '';
// Build storage volume flags
const { volumeFlags, mountFlags } = this.buildVolumeFlags(mountdir);
// For gcs-copy, wrap the user command with copy-in/copy-out steps
let effectiveCommands = commands;
if (this.storageType === 'gcs-copy' && this.bucket && commands) {
effectiveCommands = [
`gcloud storage cp -r "gs://${this.bucket}/*" "${mountdir}/" 2>/dev/null || true`,
commands,
`gcloud storage cp -r "${mountdir}/*" "gs://${this.bucket}/"`,
].join(' && ');
}
const saFlag = this.serviceAccount ? `--service-account=${this.serviceAccount}` : '';
const vpcFlag = this.vpcConnector ? `--vpc-connector=${this.vpcConnector}` : '';
// Create the Cloud Run Job
const createCmd = [
'gcloud run jobs create',
jobName,
`--image=${image}`,
`--region=${this.region}`,
'--task-timeout=86400s',
'--max-retries=0',
'--cpu=4',
'--memory=16Gi',
volumeFlags,
mountFlags,
envString,
saFlag,
vpcFlag,
projectFlag,
'--format=json',
'--quiet',
]
.filter(Boolean)
.join(' ');
try {
await OrchestratorSystem.Run(createCmd);
OrchestratorLogger.log(`[GCP Cloud Run] Job ${jobName} created`);
} catch (error: any) {
if (error.message?.includes('already exists')) {
OrchestratorLogger.log(`[GCP Cloud Run] Job ${jobName} already exists, updating...`);
const updateCmd = createCmd.replace('jobs create', 'jobs update');
await OrchestratorSystem.Run(updateCmd);
} else {
throw error;
}
}
// Override the command if provided
if (effectiveCommands) {
const updateCmd = [
'gcloud run jobs update',
jobName,
`--region=${this.region}`,
'--command="/bin/sh"',
`--args="-c,${effectiveCommands}"`,
projectFlag,
'--quiet',
]
.filter(Boolean)
.join(' ');
await OrchestratorSystem.Run(updateCmd);
}
// Execute the job
OrchestratorLogger.log(`[GCP Cloud Run] Executing job ${jobName} (storage: ${this.storageType})...`);
const executeCmd = [
'gcloud run jobs execute',
jobName,
`--region=${this.region}`,
projectFlag,
'--wait',
'--format=json',
'--quiet',
]
.filter(Boolean)
.join(' ');
let output = '';
try {
output = await OrchestratorSystem.Run(executeCmd);
OrchestratorLogger.log('[GCP Cloud Run] Job execution completed');
} catch (error: any) {
await this.streamJobLogs(jobName);
throw new Error(`[GCP Cloud Run] Job execution failed: ${error.message}`);
}
await this.streamJobLogs(jobName);
return output;
}
private async streamJobLogs(jobName: string): Promise<void> {
const projectFlag = this.project ? `--project=${this.project}` : '';
try {
const logs = await OrchestratorSystem.Run(
`gcloud logging read "resource.type=cloud_run_job AND resource.labels.job_name=${jobName}" ${projectFlag} --limit=1000 --format="value(textPayload)" --order=asc`,
false,
true,
);
if (logs) {
for (const line of logs.split('\n')) {
if (line.trim()) {
OrchestratorLogger.log(`[Build] ${line}`);
}
}
}
} catch {
OrchestratorLogger.logWarning('[GCP Cloud Run] Could not retrieve job logs');
}
}
async cleanupWorkflow(
buildParameters: BuildParameters,
branchName: string,
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
) {
OrchestratorLogger.log('[GCP Cloud Run] Cleaning up workflow');
}
async garbageCollect(
filter: string,
previewOnly: boolean,
olderThan: Number,
fullCache: boolean,
baseDependencies: boolean,
): Promise<string> {
OrchestratorLogger.log('[GCP Cloud Run] Garbage collecting old jobs');
const projectFlag = this.project ? `--project=${this.project}` : '';
try {
const jobsJson = await OrchestratorSystem.Run(
`gcloud run jobs list --region=${this.region} ${projectFlag} --filter="metadata.name~unity-build-" --format="json(metadata.name,metadata.creationTimestamp)"`,
false,
true,
);
const jobs = JSON.parse(jobsJson || '[]');
const cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() - Number(olderThan));
let deletedCount = 0;
for (const job of jobs) {
const createdAt = new Date(job.metadata?.creationTimestamp || 0);
if (createdAt < cutoffDate) {
const name = job.metadata?.name;
if (previewOnly) {
OrchestratorLogger.log(`[GCP Cloud Run] Would delete: ${name}`);
} else {
await OrchestratorSystem.Run(
`gcloud run jobs delete ${name} --region=${this.region} ${projectFlag} --quiet`,
);
deletedCount++;
}
}
}
return `Garbage collected ${deletedCount} Cloud Run jobs`;
} catch (error: any) {
OrchestratorLogger.logWarning(`[GCP Cloud Run] Garbage collection failed: ${error.message}`);
return '';
}
}
async listResources(): Promise<ProviderResource[]> {
const projectFlag = this.project ? `--project=${this.project}` : '';
try {
const jobsJson = await OrchestratorSystem.Run(
`gcloud run jobs list --region=${this.region} ${projectFlag} --filter="metadata.name~unity-build-" --format="json(metadata.name)"`,
false,
true,
);
const jobs = JSON.parse(jobsJson || '[]');
return jobs.map((job: any) => ({ Name: job.metadata?.name || '' }));
} catch {
return [];
}
}
listWorkflow(): Promise<ProviderWorkflow[]> {
throw new Error('[GCP Cloud Run] listWorkflow not implemented for this experimental provider');
}
async watchWorkflow(): Promise<string> {
throw new Error('[GCP Cloud Run] watchWorkflow not implemented for this experimental provider');
}
}
export default GcpCloudRunProvider;

View File

@@ -62,6 +62,8 @@ export default async function loadProvider(
'local-docker': './docker',
'local-system': './local',
local: './local',
'gcp-cloud-run': './gcp-cloud-run',
'azure-aci': './azure-aci',
};
modulePath = providerModuleMap[providerSource] || providerSource;
@@ -136,7 +138,7 @@ export class ProviderLoader {
* @returns string[] - Array of available provider names
*/
static getAvailableProviders(): string[] {
return ['aws', 'k8s', 'test', 'local-docker', 'local-system', 'local'];
return ['aws', 'k8s', 'test', 'local-docker', 'local-system', 'local', 'gcp-cloud-run', 'azure-aci'];
}
/**

View File

@@ -1,12 +0,0 @@
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';

View File

@@ -1,198 +0,0 @@
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;
});
}
}

View File

@@ -1,316 +0,0 @@
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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
}
/**
* 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`;
}
}

View File

@@ -1,263 +0,0 @@
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;
}
}

View File

@@ -1,246 +0,0 @@
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';
}
}

View File

@@ -1,41 +0,0 @@
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;
}

View File

@@ -1,562 +0,0 @@
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');
});
});
});

View File

@@ -1,5 +0,0 @@
# Test Workflow Engine
Service for YAML-based test suite definitions, taxonomy filtering, and structured test results.
See GitHub Issue for full specification.