SDT/tests/DevTool.Tests/ActionRunnerLegacyPwshTests.cs
2026-03-01 20:52:56 -06:00

67 lines
2.3 KiB
C#

using Sdt.Config;
using Sdt.Core;
using Xunit;
namespace DevTool.Tests;
public sealed class ActionRunnerLegacyPwshTests
{
[Fact]
public async Task LegacyPwshTarget_ReroutesToPythonScript_WhenPs1Missing()
{
var root = Path.Combine(Path.GetTempPath(), "sdt-actionrunner-" + Guid.NewGuid().ToString("N"));
var scripts = Path.Combine(root, "scripts");
Directory.CreateDirectory(scripts);
File.WriteAllText(Path.Combine(scripts, "publish-app.py"), "print('rerouted')");
var step = new WorkflowStep
{
Id = "legacy",
Label = "legacy",
Command = "pwsh",
Args = ["-NoProfile", "-File", "scripts/publish-app.ps1", "-Target", "web"],
WorkingDir = "."
};
var runner = new ActionRunner();
var run = await runner.RunStepAsync(step, root, (_, _) => { });
Assert.True(run.Success);
}
[Fact]
public async Task LegacyPwshTarget_DoesNotFallbackToPowerShell_ByDefaultWhenPythonFails()
{
var root = Path.Combine(Path.GetTempPath(), "sdt-actionrunner-" + Guid.NewGuid().ToString("N"));
var scripts = Path.Combine(root, "scripts");
Directory.CreateDirectory(scripts);
File.WriteAllText(Path.Combine(scripts, "publish-app.py"), "import sys\nsys.exit(7)\n");
File.WriteAllText(Path.Combine(scripts, "publish-app.ps1"), "Write-Host 'legacy'");
var step = new WorkflowStep
{
Id = "legacy",
Label = "legacy",
Command = "pwsh",
Args = ["-NoProfile", "-File", "scripts/publish-app.ps1", "-Target", "web"],
WorkingDir = "."
};
Environment.SetEnvironmentVariable("SDT_PWSH_LEGACY_FALLBACK", null);
try
{
var output = new List<string>();
var runner = new ActionRunner();
var run = await runner.RunStepAsync(step, root, (line, _) => output.Add(line));
Assert.False(run.Success);
Assert.Equal(7, run.ExitCode);
Assert.Contains(output, line => line.Contains("Legacy PowerShell fallback is disabled by default", StringComparison.OrdinalIgnoreCase));
}
finally
{
Environment.SetEnvironmentVariable("SDT_PWSH_LEGACY_FALLBACK", null);
}
}
}