Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions Assets/Tests/Editor/CompileSessionResultServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void CreateCompileResult_WhenNormalCompileCompletes_MapsDetailedIssues()
errors: new[] { error },
warnings: new[] { warning });

UnityCliLoopCompileResult response =
CompileResponse response =
CompileSessionResultService.CreateCompileResult(result, forceRecompile: false);

Assert.That(response.Success, Is.False);
Expand Down Expand Up @@ -75,7 +75,7 @@ public void CreateCompileResult_WhenForceCompileIsUnknown_ExplainsNullDetails()
isIndeterminate: true,
message: null);

UnityCliLoopCompileResult response =
CompileResponse response =
CompileSessionResultService.CreateCompileResult(result, forceRecompile: true);

Assert.That(response.Success, Is.Null);
Expand All @@ -100,7 +100,7 @@ public void CreateCompileResult_WhenForceCompileHasOutcome_ExplainsNullDetails()
warnings: Array.Empty<CompilerMessage>(),
message: "Internal force compile status message.");

UnityCliLoopCompileResult response =
CompileResponse response =
CompileSessionResultService.CreateCompileResult(result, forceRecompile: true);

Assert.That(response.Success, Is.True);
Expand Down Expand Up @@ -133,7 +133,7 @@ public void CreateCompileResult_WhenForceCompileHasPreservedFailure_MapsDetailed
message: "Compilation stopped because open Scene files changed externally.",
preserveDetailsWhenForceRecompile: true);

UnityCliLoopCompileResult response =
CompileResponse response =
CompileSessionResultService.CreateCompileResult(result, forceRecompile: true);

Assert.That(response.Success, Is.False);
Expand Down Expand Up @@ -163,7 +163,7 @@ public void CreateCompileResult_WhenUnityTestFrameworkSymbolIsMissing_AddsTestAs
errors: new[] { error },
warnings: Array.Empty<CompilerMessage>());

UnityCliLoopCompileResult response =
CompileResponse response =
CompileSessionResultService.CreateCompileResult(result, forceRecompile: false);

Assert.That(response.Message, Does.Contain("TestAssemblies"));
Expand All @@ -182,13 +182,13 @@ public void StoreCompileResult_WhenResultIsPersisted_UsesPascalCaseJson()

try
{
UnityCliLoopCompileResult response = new UnityCliLoopCompileResult
CompileResponse response = new CompileResponse
{
Success = true,
ErrorCount = 0,
WarningCount = 0,
Errors = Array.Empty<UnityCliLoopCompileIssue>(),
Warnings = Array.Empty<UnityCliLoopCompileIssue>(),
Errors = Array.Empty<CompileIssue>(),
Warnings = Array.Empty<CompileIssue>(),
Message = "Compilation completed."
};

Expand All @@ -202,8 +202,15 @@ public void StoreCompileResult_WhenResultIsPersisted_UsesPascalCaseJson()
UnityCliLoopStoredCompileResult storedResult =
sessionStateService.GetCompileResult("compile_test_request");

// Pins every property name of the stored payload because the CLI parses this JSON
// and CompileResponse no longer has a dedicated storage DTO guarding the shape.
Assert.That(storedResult.ResultJson, Does.Contain("\"Success\":true"));
Assert.That(storedResult.ResultJson, Does.Contain("\"ErrorCount\":0"));
Assert.That(storedResult.ResultJson, Does.Contain("\"WarningCount\":0"));
Assert.That(storedResult.ResultJson, Does.Contain("\"Errors\":[]"));
Assert.That(storedResult.ResultJson, Does.Contain("\"Warnings\":[]"));
Assert.That(storedResult.ResultJson, Does.Contain("\"Message\":\"Compilation completed.\""));
Assert.That(storedResult.ResultJson, Does.Contain("\"ProjectRoot\":"));
Assert.That(storedResult.ResultJson, Does.Not.Contain("\"success\""));
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CompilationExecutionService(UnityCliLoopEditorSessionStateService session
/// </summary>
/// <param name="request">Compile request with force and delayed-result settings.</param>
/// <returns>Compilation result</returns>
public async Task<CompileResult> ExecuteCompilationAsync(UnityCliLoopCompileRequest request, CancellationToken ct)
public async Task<CompileResult> ExecuteCompilationAsync(CompileSchema request, CancellationToken ct)
{
if (request == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ private void RecordCompileResultIfNeeded(
return;
}

UnityCliLoopCompileResult response =
CompileResponse response =
CompileSessionResultService.CreateCompileResult(result, _resultRecordingContext.ForceRecompile);
CompileSessionResultService.StoreCompileResult(
_sessionStateService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class CompileSessionResultService
private const string MissingTestFrameworkReferenceHint =
"Possible test asmdef issue: Unity test framework symbols are missing. Make sure com.unity.test-framework is installed and add optionalUnityReferences: [\"TestAssemblies\"] or enable testAssemblies on the test asmdef.";

internal static UnityCliLoopCompileResult CreateCompileResult(
internal static CompileResponse CreateCompileResult(
CompileResult result,
bool forceRecompile)
{
Expand All @@ -30,33 +30,29 @@ internal static UnityCliLoopCompileResult CreateCompileResult(

if (result.IsIndeterminate)
{
return new UnityCliLoopCompileResult
{
Success = result.Success,
ErrorCount = result.ErrorCount,
WarningCount = result.WarningCount,
Errors = null,
Warnings = null,
Message = result.Message ?? "Compilation status is unknown. Use get-logs to inspect the compiler output."
};
return new CompileResponse(
success: result.Success,
errorCount: result.ErrorCount,
warningCount: result.WarningCount,
errors: null,
warnings: null,
message: result.Message ?? "Compilation status is unknown. Use get-logs to inspect the compiler output.");
}

return new UnityCliLoopCompileResult
{
Success = result.Success,
ErrorCount = result.Errors?.Length ?? 0,
WarningCount = result.Warnings?.Length ?? 0,
Errors = ToIssues(result.Errors),
Warnings = ToIssues(result.Warnings),
Message = AddMissingTestFrameworkReferenceHint(result.Message, result.Errors)
};
return new CompileResponse(
success: result.Success,
errorCount: result.Errors?.Length ?? 0,
warningCount: result.Warnings?.Length ?? 0,
errors: ToIssues(result.Errors),
warnings: ToIssues(result.Warnings),
message: AddMissingTestFrameworkReferenceHint(result.Message, result.Errors));
}

internal static void StoreCompileResult(
UnityCliLoopEditorSessionStateService sessionStateService,
string requestId,
bool forceRecompile,
UnityCliLoopCompileResult result,
CompileResponse result,
string correlationId)
{
Debug.Assert(sessionStateService != null, "sessionStateService must not be null");
Expand Down Expand Up @@ -98,33 +94,26 @@ internal static void StoreCompileResult(
correlationId);
}

private static UnityCliLoopCompileResult CreateForceCompileResult(CompileResult result)
private static CompileResponse CreateForceCompileResult(CompileResult result)
{
ForceCompileUnknownResult unknownResult = ForceCompileUnknownResult.Create(result.Success);
return new UnityCliLoopCompileResult
{
Success = unknownResult.Success,
ErrorCount = unknownResult.ErrorCount,
WarningCount = unknownResult.WarningCount,
Errors = null,
Warnings = null,
Message = unknownResult.Message
};
return new CompileResponse(
success: unknownResult.Success,
errorCount: unknownResult.ErrorCount,
warningCount: unknownResult.WarningCount,
errors: null,
warnings: null,
message: unknownResult.Message);
}

private static UnityCliLoopCompileIssue[] ToIssues(UnityEditor.Compilation.CompilerMessage[] messages)
private static CompileIssue[] ToIssues(UnityEditor.Compilation.CompilerMessage[] messages)
{
if (messages == null)
{
return null;
}

return messages.Select(message => new UnityCliLoopCompileIssue
{
Message = message.message,
File = message.file,
Line = message.line
}).ToArray();
return messages.Select(message => new CompileIssue(message.message, message.file, message.line)).ToArray();
}

private static string AddMissingTestFrameworkReferenceHint(
Expand Down Expand Up @@ -193,7 +182,7 @@ internal static CompileResultRecordingContext Disabled()
return new CompileResultRecordingContext(false, "", false);
}

internal static CompileResultRecordingContext Create(UnityCliLoopCompileRequest request)
internal static CompileResultRecordingContext Create(CompileSchema request)
{
Debug.Assert(request != null, "request must not be null");

Expand Down
55 changes: 1 addition & 54 deletions Packages/src/Editor/FirstPartyTools/Compile/CompileTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,7 @@ protected override async Task<CompileResponse> ExecuteAsync(CompileSchema parame
UnityCliLoopEditorSessionStateService sessionStateService =
UnityCliLoopEditorSessionStateFacade.Service;
CompileUseCase useCase = new(sessionStateService);
UnityCliLoopCompileResult result = await useCase.CompileAsync(ToRequest(parameters), ct);
return ToResponse(result);
}

private static UnityCliLoopCompileRequest ToRequest(CompileSchema parameters)
{
if (parameters == null)
{
throw new System.ArgumentNullException(nameof(parameters));
}

return new UnityCliLoopCompileRequest
{
ForceRecompile = parameters.ForceRecompile,
WaitForDomainReload = parameters.WaitForDomainReload,
ReloadExternalSceneChanges = parameters.ReloadExternalSceneChanges,
RequestId = parameters.RequestId,
};
}

private static CompileResponse ToResponse(UnityCliLoopCompileResult result)
{
if (result == null)
{
throw new System.ArgumentNullException(nameof(result));
}

CompileResponse response = new(
success: result.Success,
errorCount: result.ErrorCount,
warningCount: result.WarningCount,
errors: ToCompileIssues(result.Errors),
warnings: ToCompileIssues(result.Warnings),
message: result.Message);

response.ProjectRoot = result.ProjectRoot;
return response;
}

private static CompileIssue[] ToCompileIssues(UnityCliLoopCompileIssue[] issues)
{
if (issues == null)
{
return null;
}

CompileIssue[] mappedIssues = new CompileIssue[issues.Length];
for (int i = 0; i < issues.Length; i++)
{
UnityCliLoopCompileIssue issue = issues[i];
mappedIssues[i] = new CompileIssue(issue.Message, issue.File, issue.Line);
}

return mappedIssues;
return await useCase.CompileAsync(parameters, ct);
}
}
}
Loading
Loading