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
2 changes: 1 addition & 1 deletion .github/workflows/linux-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
$installDirectory | Out-File -FilePath $env:GITHUB_PATH -Append -Encoding utf8

- name: Test encoders, executable formats, and Linux runtime
run: dotnet test source/Zero.slnx --configuration Release --disable-build-servers --maxcpucount:1
run: dotnet test source/Zero.slnx --configuration Release --disable-build-servers --maxcpucount:1 --blame-hang-timeout 2m --logger "console;verbosity=normal" --logger trx --results-directory output/test-results

- name: Validate all samples
run: ./validate-samples.ps1
Expand Down
9 changes: 9 additions & 0 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ Native Linux x86-64 runtime tests run under Linux/WSL and skip other hosts. The
PowerShell-only Linux CI workflow runs the tests, validates all sample formats,
and inspects/executes `linux64-cli-01-hello` on Ubuntu. See [Linux x64](linux64.md).

### Warning - LinuxRuntimeTests

`LinuxRuntimeTests` runs without test parallelization. Concurrent fork/exec calls
can briefly inherit another test's open executable writer, causing Linux to
reject an otherwise complete output with `ETXTBSY` ("Text file busy"). See the
[.NET runtime investigation](https://github.com/dotnet/runtime/issues/58964).
The Linux workflow also captures TRX results and aborts a test host after two
minutes without test progress, so a real hang produces diagnostics.

## IDE runtime targets

`Zero.Ide` builds for `win-x64`, `linux-x64`, `linux-arm64`, `linux-arm`,
Expand Down
49 changes: 49 additions & 0 deletions docs/ide-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,55 @@ separate `IDebugSession` owns execution, pause, step, and stop state.
`Built` is a progress notification emitted inside `CompileState`, not a separate
registered state, so it does not appear as a node.

## Event notifications

The singleton `IIdeEventService` uses Lite.EventIPC for local notifications.
It publishes these immutable records from `Zero.Ide.Events`:

| Event | Published when |
| --- | --- |
| `ExecutionStateChangedEvent` | A workflow stage is entered, including the `Built` progress notification and terminal outcomes. |
| `BuildStartedEvent` | Validation and saving succeeded and the compiler is about to run. |
| `BuildCompletedEvent` | A compiler attempt finishes, fails, or throws, before launching the output. |
| `WorkspaceOpenedEvent` | A folder is selected and its explorer root is initialized; children load lazily. |
| `DebugStoppedEvent` | Debugging pauses at entry, a breakpoint, a step, or an exception; includes a copied register snapshot. |
| `DebugSessionEndedEvent` | A debug session exits or faults. |

All events include a UTC `Timestamp`. Execution and build notifications share an
`ExecutionId`, source path, mode, and configuration. A canceled save or validation
failure has a terminal state notification but no compiler-attempt events.
`BuildCompletedEvent.Succeeded` describes compilation; a later launch can still
fail. Native debugger notifications come from `IDebugSession`, which owns the
running/paused lifecycle after the build workflow finishes.

Inject `IIdeEventService` into subscribers and retain the subscription token:

```csharp
IDisposable subscription = events.Subscribe<BuildCompletedEvent>(notification =>
{
Dispatcher.UIThread.Post(() =>
Status = notification.Succeeded ? "Build succeeded" : "Build failed");
});

// When the subscriber is closed or unloaded:
subscription.Dispose();
```

Handlers run in the background and must marshal UI work onto Avalonia's
dispatcher. An overload accepts `Func<TEvent, Task>` for asynchronous handlers;
use that overload instead of `async void`. Exceptions are traced and isolated.
Delivery is ordered within each subscription, with no ordering guarantee across
event types or subscriptions. Use `ExecutionId` to correlate build notifications.

These are best-effort observational signals. Each subscription has a bounded
256-event queue that drops its oldest pending item when full. A blocked or slow
subscriber therefore cannot stall the UI, state machine, or another subscriber,
and pending events cannot consume unbounded memory. Disposing a token detaches
it and stops queued delivery; an already executing handler may finish afterward.
Application shutdown disposes the hub without waiting for handlers. Use direct
service calls for commands or operations that require guaranteed completion.
This registers local delivery only; no named-pipe or network endpoint is opened.

## Regenerating

From the repository root, export all three DOT files without executing the
Expand Down
66 changes: 33 additions & 33 deletions source/Zero.Ide.Tests/EditorExecutionCoordinatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ namespace Zero.Ide.Tests;
public class EditorExecutionCoordinatorTests
{
[TestMethod]
[DataRow(EditorExecutionMode.Build)]
[DataRow(EditorExecutionMode.Run)]
[DataRow(EditorExecutionMode.Debug)]
public void DiagramExportUsesModeSpecificRegisteredTransitions(EditorExecutionMode mode)
[DataRow(BuildExecutionMode.Build)]
[DataRow(BuildExecutionMode.Run)]
[DataRow(BuildExecutionMode.Debug)]
public void DiagramExportUsesModeSpecificRegisteredTransitions(BuildExecutionMode mode)
{
var dot = EditorExecutionCoordinator.ExportStateDiagram(mode);
Assert.Contains("1. ValidateCompilerState", dot);
Assert.Contains("4. CompileState", dot);
Assert.Contains("\"Save\" -> \"Canceled\"", dot);
Assert.Contains("\"Build\" -> \"Failed\"", dot);
Assert.DoesNotContain("\"Built\" [", dot); // Built is a notification, not a registered state.
if (mode == EditorExecutionMode.Build)
if (mode == BuildExecutionMode.Build)
{
Assert.Contains("\"Build\" -> \"Completed\"", dot);
Assert.DoesNotContain("LaunchState", dot);
}
else
{
Assert.Contains("\"Build\" -> \"Launch\"", dot);
Assert.Contains(mode == EditorExecutionMode.Run ? "\"Launch\" -> \"RunFailed\"" : "\"Launch\" -> \"Failed\"", dot);
Assert.Contains(mode == BuildExecutionMode.Run ? "\"Launch\" -> \"RunFailed\"" : "\"Launch\" -> \"Failed\"", dot);
}

if (mode != EditorExecutionMode.Run) Assert.DoesNotContain("RunFailedState", dot);
if (mode != BuildExecutionMode.Run) Assert.DoesNotContain("RunFailedState", dot);
}

private static string SourcePath => Path.Combine(Path.GetTempPath(), "program" + SourceFileExtensions.Assembly);
Expand All @@ -51,16 +51,16 @@ public async Task CancelingSaveNeverValidatesBuildsOrLaunchesAsync()
{
var compiler = new Mock<ICompilerService>(MockBehavior.Strict);
var runner = new Mock<IProgramRunner>(MockBehavior.Strict);
var stages = new List<EditorExecutionStage>();
var stages = new List<BuildExecutionStage>();

var result = await new EditorExecutionCoordinator(compiler.Object, runner.Object).ExecuteAsync(
Request(EditorExecutionMode.Run) with
Request(BuildExecutionMode.Run) with
{
SaveSourceAsync = () => Task.FromResult<string?>(null)
}, update => stages.Add(update.Stage));

Assert.AreEqual(EditorExecutionStage.Canceled, result.Stage);
Assert.AreSequenceEqual(new[] { EditorExecutionStage.ValidateCompiler, EditorExecutionStage.Save, EditorExecutionStage.Canceled }, stages);
Assert.AreEqual(BuildExecutionStage.Canceled, result.Stage);
Assert.AreSequenceEqual(new[] { BuildExecutionStage.ValidateCompiler, BuildExecutionStage.Save, BuildExecutionStage.Canceled }, stages);

compiler.VerifyNoOtherCalls();
runner.VerifyNoOtherCalls();
Expand All @@ -78,14 +78,14 @@ public async Task ConcurrentExecutionIsRejectedWithoutASecondCompilerProcessAsyn
.Callback(() => entered.SetResult()).Returns(finished.Task);

var coordinator = new EditorExecutionCoordinator(compiler.Object);
var first = coordinator.ExecuteAsync(Request(EditorExecutionMode.Build), _ => { });
var first = coordinator.ExecuteAsync(Request(BuildExecutionMode.Build), _ => { });

await entered.Task.WaitAsync(TimeSpan.FromSeconds(5));

try
{
await Assert.ThrowsExactlyAsync<InvalidOperationException>(
() => coordinator.ExecuteAsync(Request(EditorExecutionMode.Build), _ => { }));
() => coordinator.ExecuteAsync(Request(BuildExecutionMode.Build), _ => { }));
}
finally
{
Expand Down Expand Up @@ -118,7 +118,7 @@ public async Task FailuresStopTheWorkflowBeforeLaunchingAsync(string failure)
.ThrowsAsync(new IOException("Unable to start"));

var runner = new Mock<IProgramRunner>(MockBehavior.Strict);
var request = Request(EditorExecutionMode.Run);
var request = Request(BuildExecutionMode.Run);

if (failure == "missing-compiler")
request = request with { CompilerPath = "" };
Expand All @@ -130,7 +130,7 @@ public async Task FailuresStopTheWorkflowBeforeLaunchingAsync(string failure)
request = request with { SaveSourceAsync = () => throw new IOException("Disk full") };

var result = await new EditorExecutionCoordinator(compiler.Object, runner.Object).ExecuteAsync(request, _ => { });
Assert.AreEqual(EditorExecutionStage.Failed, result.Stage);
Assert.AreEqual(BuildExecutionStage.Failed, result.Stage);

if (failure == "compiler-error")
Assert.AreSame(compilation, result.Compilation);
Expand All @@ -144,9 +144,9 @@ public async Task FailuresStopTheWorkflowBeforeLaunchingAsync(string failure)
}

[TestMethod]
[DataRow(EditorExecutionMode.Run, EditorExecutionStage.RunFailed)]
[DataRow(EditorExecutionMode.Debug, EditorExecutionStage.Failed)]
public async Task LaunchFailuresPreserveCompilerOutputAndPermitRetryAsync(EditorExecutionMode mode, EditorExecutionStage expected)
[DataRow(BuildExecutionMode.Run, BuildExecutionStage.RunFailed)]
[DataRow(BuildExecutionMode.Debug, BuildExecutionStage.Failed)]
public async Task LaunchFailuresPreserveCompilerOutputAndPermitRetryAsync(BuildExecutionMode mode, BuildExecutionStage expected)
{
var compiler = new Mock<ICompilerService>();

Expand All @@ -163,18 +163,18 @@ public async Task LaunchFailuresPreserveCompilerOutputAndPermitRetryAsync(Editor
Assert.AreEqual(expected, result.Stage);
Assert.AreEqual("compiled successfully", result.Compilation!.Output);
Assert.IsNotNull(result.Error);
Assert.AreEqual(EditorExecutionStage.Completed, (await coordinator.ExecuteAsync(Request(EditorExecutionMode.Build), _ => { })).Stage);
Assert.AreEqual(BuildExecutionStage.Completed, (await coordinator.ExecuteAsync(Request(BuildExecutionMode.Build), _ => { })).Stage);
}

[TestMethod]
[DataRow(EditorExecutionMode.Build)]
[DataRow(EditorExecutionMode.Run)]
[DataRow(EditorExecutionMode.Debug)]
public async Task SuccessfulWorkflowSavesBuildsThenUsesOnlyRequestedLauncherAsync(EditorExecutionMode mode)
[DataRow(BuildExecutionMode.Build)]
[DataRow(BuildExecutionMode.Run)]
[DataRow(BuildExecutionMode.Debug)]
public async Task SuccessfulWorkflowSavesBuildsThenUsesOnlyRequestedLauncherAsync(BuildExecutionMode mode)
{
var calls = new List<string>();
var compiler = new Mock<ICompilerService>();
var configuration = mode == EditorExecutionMode.Debug ? BuildConstants.DebugConfiguration : BuildConstants.ReleaseConfiguration;
var configuration = mode == BuildExecutionMode.Debug ? BuildConstants.DebugConfiguration : BuildConstants.ReleaseConfiguration;

compiler
.Setup(c => c.BuildAsync("compiler", SourcePath, configuration, true))
Expand Down Expand Up @@ -206,14 +206,14 @@ public async Task SuccessfulWorkflowSavesBuildsThenUsesOnlyRequestedLauncherAsyn
var updates = new List<EditorExecutionUpdate>();
var result = await new EditorExecutionCoordinator(compiler.Object, runner.Object).ExecuteAsync(request, updates.Add);

Assert.AreEqual(EditorExecutionStage.Completed, result.Stage);
Assert.AreEqual(BuildExecutionStage.Completed, result.Stage);
Assert.AreSequenceEqual(
mode == EditorExecutionMode.Build
mode == BuildExecutionMode.Build
? new[] { "save", "compile" }
: new[] { "save", "compile", mode == EditorExecutionMode.Run ? "run" : "debug" }, calls);
: new[] { "save", "compile", mode == BuildExecutionMode.Run ? "run" : "debug" }, calls);

Assert.AreEqual(EditorExecutionStage.ValidateCompiler, updates[0].Stage);
Assert.IsGreaterThan(updates.FindIndex(update => update.Stage == EditorExecutionStage.Build), updates.FindIndex(update => update.Stage == EditorExecutionStage.Built));
Assert.AreEqual(BuildExecutionStage.ValidateCompiler, updates[0].Stage);
Assert.IsGreaterThan(updates.FindIndex(update => update.Stage == BuildExecutionStage.Build), updates.FindIndex(update => update.Stage == BuildExecutionStage.Built));
}

[TestMethod]
Expand All @@ -233,7 +233,7 @@ await session.Dispatch(async () =>
});

var coordinator = new EditorExecutionCoordinator(compiler.Object);
var result = await coordinator.ExecuteAsync(Request(EditorExecutionMode.Debug) with
var result = await coordinator.ExecuteAsync(Request(BuildExecutionMode.Debug) with
{
SaveSourceAsync = async () =>
{
Expand All @@ -252,14 +252,14 @@ await session.Dispatch(async () =>
updates.Add(update);
});

Assert.AreEqual(EditorExecutionStage.Completed, result.Stage);
Assert.Contains(update => update.Stage == EditorExecutionStage.Launch, updates);
Assert.AreEqual(BuildExecutionStage.Completed, result.Stage);
Assert.Contains(update => update.Stage == BuildExecutionStage.Launch, updates);

return 0;
}, CancellationToken.None);
}

private static EditorExecutionRequest Request(EditorExecutionMode mode) =>
private static EditorExecutionRequest Request(BuildExecutionMode mode) =>
new(
"compiler",
BuildConstants.DebugConfiguration,
Expand Down
Loading