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
5 changes: 3 additions & 2 deletions src/ModVerify.CliApp/Settings/SettingsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ private AppVerifySettings BuildFromVerifyVerb(VerifyVerbOption verifyOptions)
ParallelVerifiers = verifyOptions.Parallel ? 4 : 1,
VerifiersProvider = new DefaultGameVerifiersProvider(),
FailFastSettings = failFastSetting,
UseLiveVirtualFileSystem = true,
GameVerifySettings = new GameVerifySettings
{
IgnoreAsserts = verifyOptions.IgnoreAsserts,
ThrowsOnMinimumSeverity = failFastSetting.IsFailFast
ThrowsOnMinimumSeverity = failFastSetting.IsFailFast
? failFastSetting.MinumumSeverity
// The app shall not make a specific verifier throw, but it should always run to completion.
: null
: null
}
},
AppFailsOnMinimumSeverity = verifyOptions.MinimumFailureSeverity,
Expand Down
18 changes: 13 additions & 5 deletions src/ModVerify/GameVerifyPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PG.StarWarsGame.Engine;
using PG.StarWarsGame.Engine.IO;

namespace AET.ModVerify;

Expand All @@ -35,6 +36,8 @@ internal sealed class GameVerifyPipeline : StepRunnerPipelineBase<AsyncStepRunne
private readonly SuppressionList _suppressions;
private VerificationErrors _errors = VerificationErrors.Empty;

private IStarWarsGameEngineHandle? _gameEngine;

internal VerificationErrors Errors => _errors;

internal IReadOnlyCollection<IGameVerifierInfo> Verifiers => [.. _verifiers];
Expand Down Expand Up @@ -78,17 +81,20 @@ protected override async Task PrepareCoreAsync(CancellationToken token)
_verifiers.Clear();
_errors = VerificationErrors.Empty;

IStarWarsGameEngine gameEngine;

try
{
var engineService = ServiceProvider.GetRequiredService<IPetroglyphStarWarsGameEngineService>();
gameEngine = await engineService.InitializeAsync(
Action<PetroglyphFileSystem>? configureFs = _serviceSettings.UseLiveVirtualFileSystem
? static fs => fs.UseLiveVirtualStrategy()
: null;

_gameEngine = await engineService.InitializeAsync(
_verificationTarget.Engine,
_verificationTarget.Location,
_engineErrorReporter,
_engineInitializationReporter,
false,
configureFs,
CancellationToken.None).ConfigureAwait(false);
}
catch (Exception e)
Expand All @@ -97,9 +103,9 @@ protected override async Task PrepareCoreAsync(CancellationToken token)
throw;
}

AddStep(new GameEngineErrorCollector(_engineErrorReporter, gameEngine, _serviceSettings.GameVerifySettings, ServiceProvider));
AddStep(new GameEngineErrorCollector(_engineErrorReporter, _gameEngine, _serviceSettings.GameVerifySettings, ServiceProvider));

foreach (var gameVerificationStep in CreateVerifiers(gameEngine))
foreach (var gameVerificationStep in CreateVerifiers(_gameEngine))
AddStep(gameVerificationStep);
}

Expand Down Expand Up @@ -153,6 +159,8 @@ protected override void DisposeResources()
_engineErrorReporter.Clear();
_aggregatedVerifyProgressReporter?.Dispose();
_aggregatedVerifyProgressReporter = null;
_gameEngine?.Dispose();
_gameEngine = null;
}

private void AddStep(GameVerifier verifier)
Expand Down
2 changes: 2 additions & 0 deletions src/ModVerify/Settings/VerifierServiceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public sealed class VerifierServiceSettings
public FailFastSetting FailFastSettings { get; init; } = FailFastSetting.NoFailFast;

public int ParallelVerifiers { get; init; } = 4;

public bool UseLiveVirtualFileSystem { get; init; } = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO.Abstractions;
using System.Runtime.InteropServices;
using PG.StarWarsGame.Engine.IO;
using PG.StarWarsGame.Engine.IO.FileExistStrategies;
using PG.StarWarsGame.Engine.Utilities;
using Testably.Abstractions;
using Xunit;
Expand All @@ -20,6 +21,39 @@ protected override IFileSystem CreateFileSystem()

protected abstract override void ConfigureStrategy(PetroglyphFileSystem fs);

/// <summary>
/// Constructs a fresh instance of the strategy under test, so generic suite
/// tests (<see cref="Cleanup_CalledTwice_DoesNotThrow"/>) can exercise it directly without
/// fighting the <see cref="PetroglyphFileSystem"/>'s ownership of the active strategy.
/// </summary>
private protected abstract FileExistsStrategy CreateStrategyForCleanupTest();

[Fact]
public void Cleanup_CalledTwice_DoesNotThrow()
{
var strategy = CreateStrategyForCleanupTest();
strategy.Cleanup();
strategy.Cleanup();
}

[Fact]
public void FileExists_AfterCleanup_RemainsUsable()
{
var dir = NewTempDir();
var file = FileSystem.Path.Combine(dir, "test.txt");
FileSystem.File.WriteAllText(file, "x");

// Warm up the strategy.
Assert.True(FileExists("test.txt".AsSpan(), dir.AsSpan()));

// Cleanup must not permanently break the strategy.
PgFileSystem.Strategy.Cleanup();

// Must still serve correct lookups after Cleanup.
Assert.True(FileExists("test.txt".AsSpan(), dir.AsSpan()));
Assert.False(FileExists("missing.txt".AsSpan(), dir.AsSpan()));
}

protected virtual void AssertResolvedPath(string expectedOnDiskPath, string actualResult)
{
var expected = expectedOnDiskPath.Replace('\\', FileSystem.Path.DirectorySeparatorChar).Replace('/', FileSystem.Path.DirectorySeparatorChar);
Expand Down Expand Up @@ -53,10 +87,6 @@ protected string NewTempDir()
return dir;
}

// ---------------------------------------------------------------------------------------------
// Shared tests — every strategy must satisfy.
// ---------------------------------------------------------------------------------------------

[Theory]
[InlineData("/gameDir")]
[InlineData(null)]
Expand Down
Loading
Loading