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 tests/GenWave.Host.Tests/Specs/Gh019_ScriptPreflight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class FeatureScriptPreflight

static string WriteEnvFile(params string[] assignments)
{
var path = Path.Combine(Directory.CreateTempSubdirectory("gw-preflight-env-").FullName, "test.env");
var path = Path.Combine(TempDir.CreateForProcessLifetime(), "test.env");
File.WriteAllLines(path, assignments);
return path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static string WriteEnvFile() =>

static string WriteEnvFile(string[] assignments)
{
var path = Path.Combine(Directory.CreateTempSubdirectory("gh332-env-").FullName, "test.env");
var path = Path.Combine(TempDir.CreateForProcessLifetime(), "test.env");
File.WriteAllLines(path, assignments);
return path;
}
Expand All @@ -72,7 +72,7 @@ sealed record Run(int ExitCode, string StdOut, string StdErr, string[] DockerCal
static Run RunPinnedLaunch()
{
var bin = MakeBinDirWithDockerStub();
var log = Path.Combine(Directory.CreateTempSubdirectory("gh332-log-").FullName, "docker.log");
var log = Path.Combine(TempDir.CreateForProcessLifetime(), "docker.log");

var (exitCode, stdOut, stdErr) = ScriptProcess.Run(
"launch.sh", bin, envFile: WriteEnvFile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using GenWave.Core.Domain;
using GenWave.Core.Playout;
using GenWave.Host.Tests.Fakes;
using GenWave.Host.Tests.Support;
using GenWave.Orchestration;
using GenWave.Tts;

Expand Down Expand Up @@ -199,16 +200,16 @@ public sealed class ScenarioSynthesizerAlwaysFailsOrchestratorYieldsMusic
: IAsyncLifetime
{
KokoroStubServer stub = null!;
DirectoryInfo cacheDir = null!;
TempDir cacheDir = null!;
Orchestrator orchestrator = null!;

public async Task InitializeAsync()
{
stub = await KokoroStubServer.StartAsync(KokoroStubMode.Fail500);
cacheDir = System.IO.Directory.CreateTempSubdirectory("genwave-t015-fail-");
cacheDir = new TempDir();
orchestrator = BuildOrchestrator(
stub.BaseUri,
cacheDir.FullName,
cacheDir.Path,
voice: $"voice-{Guid.NewGuid():N}",
renderBudget: TimeSpan.FromSeconds(2),
catalog: new MultiTrackCatalog());
Expand All @@ -217,7 +218,7 @@ public async Task InitializeAsync()
public async Task DisposeAsync()
{
await stub.DisposeAsync();
if (cacheDir.Exists) cacheDir.Delete(recursive: true);
cacheDir.Dispose();
}

[Fact]
Expand Down Expand Up @@ -284,7 +285,7 @@ public sealed class ScenarioSynthesizerTimesOutOrchestratorYieldsMusic
: IAsyncLifetime
{
KokoroStubServer stub = null!;
DirectoryInfo cacheDir = null!;
TempDir cacheDir = null!;
Orchestrator orchestrator = null!;

// Budget is 200 ms — well under the 30-second delay the stub introduces.
Expand All @@ -293,10 +294,10 @@ public sealed class ScenarioSynthesizerTimesOutOrchestratorYieldsMusic
public async Task InitializeAsync()
{
stub = await KokoroStubServer.StartAsync(KokoroStubMode.DelayPastBudget);
cacheDir = System.IO.Directory.CreateTempSubdirectory("genwave-t015-timeout-");
cacheDir = new TempDir();
orchestrator = BuildOrchestrator(
stub.BaseUri,
cacheDir.FullName,
cacheDir.Path,
voice: $"voice-{Guid.NewGuid():N}",
renderBudget: RenderBudget,
catalog: new MultiTrackCatalog());
Expand All @@ -305,7 +306,7 @@ public async Task InitializeAsync()
public async Task DisposeAsync()
{
await stub.DisposeAsync();
if (cacheDir.Exists) cacheDir.Delete(recursive: true);
cacheDir.Dispose();
}

[Fact]
Expand Down Expand Up @@ -395,16 +396,16 @@ public sealed class ScenarioSynthesizerRecoveryTtsResumesOnceKokoroIsBack
: IAsyncLifetime
{
KokoroStubServer stub = null!;
DirectoryInfo cacheDir = null!;
TempDir cacheDir = null!;
Orchestrator orchestrator = null!;

public async Task InitializeAsync()
{
stub = await KokoroStubServer.StartAsync(KokoroStubMode.Fail500);
cacheDir = System.IO.Directory.CreateTempSubdirectory("genwave-t015-recovery-");
cacheDir = new TempDir();
orchestrator = BuildOrchestrator(
stub.BaseUri,
cacheDir.FullName,
cacheDir.Path,
// Unique voice ensures no stale cache hits from the Fail500 window.
voice: $"voice-{Guid.NewGuid():N}",
renderBudget: TimeSpan.FromSeconds(2),
Expand All @@ -414,7 +415,7 @@ public async Task InitializeAsync()
public async Task DisposeAsync()
{
await stub.DisposeAsync();
if (cacheDir.Exists) cacheDir.Delete(recursive: true);
cacheDir.Dispose();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

// Alias to disambiguate the GenWave.Loudness namespace from the Loudness domain type.
using GenWave.Host.Tests.Fakes;
using GenWave.Host.Tests.Support;
using FfmpegAnalyzer = GenWave.Loudness.FfmpegLoudnessAnalyzer;
using TrackLoudness = GenWave.Core.Domain.Loudness;

Expand Down Expand Up @@ -135,7 +136,7 @@ static async Task<MediaItem> RenderSegmentAsync(string cacheRoot, string kokoroB
public sealed class ScenarioRenderedSegmentHasMeasuredLoudness : IAsyncLifetime
{
readonly KokoroFixture fixture;
DirectoryInfo cacheDir = null!;
TempDir cacheDir = null!;
MediaItem renderedItem = null!;

public ScenarioRenderedSegmentHasMeasuredLoudness(KokoroFixture fixture)
Expand All @@ -145,14 +146,14 @@ public ScenarioRenderedSegmentHasMeasuredLoudness(KokoroFixture fixture)

public async Task InitializeAsync()
{
cacheDir = System.IO.Directory.CreateTempSubdirectory("genwave-t016-");
cacheDir = new TempDir();
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(2));
renderedItem = await RenderSegmentAsync(cacheDir.FullName, fixture.BaseUrl, cts.Token);
renderedItem = await RenderSegmentAsync(cacheDir.Path, fixture.BaseUrl, cts.Token);
}

public Task DisposeAsync()
{
if (cacheDir.Exists) cacheDir.Delete(recursive: true);
cacheDir.Dispose();
return Task.CompletedTask;
}

Expand Down
24 changes: 9 additions & 15 deletions tests/GenWave.Host.Tests/Specs/Story328_CrosstalkStockWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,15 @@ public void Files_left_over_from_a_previous_run_are_deleted()
// Given a crosstalk cache directory holding an asset an earlier, crashed/restarted
// process assembled but never vended (SPEC F127.7's own "the stock survives nothing" —
// PLAN T285's recorded rider: crosstalk/ has no other sweeper)
var dir = Directory.CreateTempSubdirectory("crosstalk-purge-test-").FullName;
try
{
var orphan = Path.Combine(dir, "orphan.wav");
File.WriteAllBytes(orphan, [0]);

CrosstalkStockWorker.PurgeStaleAssets(dir, NullLogger.Instance);

// Then the orphaned asset is gone
Assert.False(File.Exists(orphan));
}
finally
{
Directory.Delete(dir, recursive: true);
}
using var tmp = new TempDir();
var dir = tmp.Path;
var orphan = Path.Combine(dir, "orphan.wav");
File.WriteAllBytes(orphan, [0]);

CrosstalkStockWorker.PurgeStaleAssets(dir, NullLogger.Instance);

// Then the orphaned asset is gone
Assert.False(File.Exists(orphan));
}

[Fact]
Expand Down
26 changes: 15 additions & 11 deletions tests/GenWave.Host.Tests/Specs/Story342_PreflightExpansion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exit 0

static string WriteEnvFile(params string[] assignments)
{
var path = Path.Combine(Directory.CreateTempSubdirectory("gw-preflight-story342-env-").FullName, "test.env");
var path = Path.Combine(TempDir.CreateForProcessLifetime(), "test.env");
File.WriteAllLines(path, assignments);
return path;
}
Expand All @@ -51,7 +51,7 @@ static string CompleteEnvFile(string mediaDir, string? adminPasswordLine = null)
/// <summary>A fresh scratch directory holding the given count of .flac/.mp3 files (and nothing else).</summary>
static string MakeMediaDir(int flacCount = 0, int mp3Count = 0)
{
var dir = Directory.CreateTempSubdirectory("gw-preflight-story342-media-").FullName;
var dir = TempDir.CreateForProcessLifetime();
for (var i = 0; i < flacCount; i++) File.WriteAllText(Path.Combine(dir, $"track{i}.flac"), "");
for (var i = 0; i < mp3Count; i++) File.WriteAllText(Path.Combine(dir, $"track{i}.mp3"), "");
return dir;
Expand All @@ -73,8 +73,7 @@ static string MakeMediaDir(int flacCount = 0, int mp3Count = 0)
string binDir, string? envFile = null, IReadOnlyDictionary<string, string>? extraEnv = null,
string script = DefaultPreflightScript)
{
var scriptPath = Path.Combine(
Directory.CreateTempSubdirectory("gw-preflight-story342-script-").FullName, "run.sh");
var scriptPath = Path.Combine(TempDir.CreateForProcessLifetime(), "run.sh");
File.WriteAllText(scriptPath, script);

return ScriptProcess.Run(scriptPath, binDir, envFile, extraEnv);
Expand Down Expand Up @@ -393,8 +392,8 @@ exit 0
echo "Filesystem 1024-blocks Used Available Capacity Mounted on"
echo "tmpfs 2000000 1000000 900000 53% /"
""");
var missingFallback = Path.Combine(
Directory.CreateTempSubdirectory("gw-preflight-story342-nodockerroot-").FullName, "does-not-exist");
using var missingFallbackDir = new TempDir();
var missingFallback = Path.Combine(missingFallbackDir.Path, "does-not-exist");
var envFile = CompleteEnvFile(MakeMediaDir(flacCount: 1));

var (_, stdOut, _) = RunPreflight(
Expand All @@ -407,7 +406,8 @@ exit 0
[Fact]
public void RamUnderTheFullTopologyConstantSuggestsPiperOnly()
{
var meminfo = Path.Combine(Directory.CreateTempSubdirectory("gw-preflight-story342-ram-").FullName, "meminfo");
using var meminfoDir = new TempDir();
var meminfo = Path.Combine(meminfoDir.Path, "meminfo");
File.WriteAllText(meminfo, "MemTotal: 3945000 kB\nMemFree: 100000 kB\n");
var envFile = CompleteEnvFile(MakeMediaDir(flacCount: 1));

Expand All @@ -423,7 +423,8 @@ public void PiWithoutCgroupMemoryWarnsThatMemLimitsAreDiscarded()
{
// cmdline.txt probe (test seam points at a scratch file) missing
// cgroup_enable=memory → WARN with the HARDWARE.md pointer.
var cmdline = Path.Combine(Directory.CreateTempSubdirectory("gw-preflight-story342-cmdline-").FullName, "cmdline.txt");
using var cmdlineDir = new TempDir();
var cmdline = Path.Combine(cmdlineDir.Path, "cmdline.txt");
File.WriteAllText(cmdline, "console=serial0,115200 root=PARTUUID=xyz rootfstype=ext4 rootwait\n");
var envFile = CompleteEnvFile(MakeMediaDir(flacCount: 1));

Expand Down Expand Up @@ -485,7 +486,8 @@ public void UppercaseExtensionFilesCountTowardTheTotal()
public void AnNfsMediaDirPrintsTheStaleInodeAndCaseNotes()
{
var mediaDir = MakeMediaDir(flacCount: 1);
var mounts = Path.Combine(Directory.CreateTempSubdirectory("gw-preflight-story342-mounts-").FullName, "mounts");
using var mountsDir = new TempDir();
var mounts = Path.Combine(mountsDir.Path, "mounts");
File.WriteAllLines(mounts,
[
"/dev/sda1 / ext4 rw 0 0",
Expand All @@ -508,7 +510,8 @@ public void ALocalMediaDirNamesTheDetectedFilesystemType()
// determined (see the next fact). Capitalized and reworded to "Local disk (...)"
// either way, matching the neighboring "NFS-mounted (...)" row's own capitalization.
var mediaDir = MakeMediaDir(flacCount: 1);
var mounts = Path.Combine(Directory.CreateTempSubdirectory("gw-preflight-story342-mounts-").FullName, "mounts");
using var mountsDir = new TempDir();
var mounts = Path.Combine(mountsDir.Path, "mounts");
File.WriteAllLines(mounts, [$"/dev/sda1 {mediaDir} ext4 rw 0 0"]);
var envFile = CompleteEnvFile(mediaDir);

Expand All @@ -526,7 +529,8 @@ public void AMediaDirWithNoMatchingMountEntrySaysTypeNotIdentifiedNotUnknown()
// "local" itself read as though IT were unverified, when only the TYPE is. Honest
// wording now, and the parenthetical stays reserved for an actual detected type.
var mediaDir = MakeMediaDir(flacCount: 1);
var mounts = Path.Combine(Directory.CreateTempSubdirectory("gw-preflight-story342-mounts-").FullName, "mounts");
using var mountsDir = new TempDir();
var mounts = Path.Combine(mountsDir.Path, "mounts");
File.WriteAllLines(mounts, ["/dev/sda1 / ext4 rw 0 0"]); // no entry matching mediaDir
var envFile = CompleteEnvFile(mediaDir);

Expand Down
2 changes: 1 addition & 1 deletion tests/GenWave.Host.Tests/Specs/Story343_StagedStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static string[] PlanLines(string stdOut) =>
/// <summary>Writes a scratch env file (the Gh332 GW_ENV_FILE idiom) — never the real .env.</summary>
static string WriteEnvFile(params string[] assignments)
{
var path = Path.Combine(Directory.CreateTempSubdirectory("story343-env-").FullName, "test.env");
var path = Path.Combine(TempDir.CreateForProcessLifetime(), "test.env");
File.WriteAllLines(path, assignments);
return path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static string BinWithFailingMv()
return dir;
}

static string ScratchEnvDir() => Directory.CreateTempSubdirectory("gw-setup-story344-env-").FullName;
static string ScratchEnvDir() => TempDir.CreateForProcessLifetime();

static string ScratchEnvPath() => Path.Combine(ScratchEnvDir(), ".env");

Expand All @@ -153,7 +153,7 @@ static string WriteExistingEnvFile(string content)
/// <summary>A fresh scratch directory holding the given count of .flac/.mp3 files (and nothing else).</summary>
static string MakeMediaDir(int flacCount = 0, int mp3Count = 0)
{
var dir = Directory.CreateTempSubdirectory("gw-setup-story344-media-").FullName;
var dir = TempDir.CreateForProcessLifetime();
for (var i = 0; i < flacCount; i++) File.WriteAllText(Path.Combine(dir, $"track{i}.flac"), "");
for (var i = 0; i < mp3Count; i++) File.WriteAllText(Path.Combine(dir, $"track{i}.mp3"), "");
return dir;
Expand All @@ -174,7 +174,7 @@ static string MakeMediaDir(int flacCount = 0, int mp3Count = 0)
string binDir, string envFile, string stdinAnswers,
IReadOnlyDictionary<string, string>? extraEnv = null)
{
var scratchDir = Directory.CreateTempSubdirectory("gw-setup-story344-stdin-").FullName;
var scratchDir = TempDir.CreateForProcessLifetime();
var answersPath = Path.Combine(scratchDir, "answers.txt");
File.WriteAllText(answersPath, stdinAnswers);

Expand All @@ -190,8 +190,7 @@ static string MakeMediaDir(int flacCount = 0, int mp3Count = 0)
/// WriteLaunchStub (file-scoped there too, so duplicated rather than shared).</summary>
static string WriteExitZeroLaunchStub()
{
var path = Path.Combine(
Directory.CreateTempSubdirectory("gw-setup-story344-launch-").FullName, "launch-stub.sh");
var path = Path.Combine(TempDir.CreateForProcessLifetime(), "launch-stub.sh");
File.WriteAllText(path, "#!/usr/bin/env bash\nexit 0\n");
if (!OperatingSystem.IsWindows())
{
Expand Down Expand Up @@ -276,7 +275,8 @@ public void TheTopologyRecommendationFollowsDetectedRamAndArch()
// GW_MEMINFO_FILE + GW_ARCH report a 3 GiB x86_64 box -> piper-only recommended; the
// owner overrides to Full at the prompt (answer "1"). The final .env must honor the
// OVERRIDE, not the recommendation.
var meminfo = Path.Combine(Directory.CreateTempSubdirectory("gw-setup-story344-ram-").FullName, "meminfo");
using var meminfoDir = new TempDir();
var meminfo = Path.Combine(meminfoDir.Path, "meminfo");
File.WriteAllText(meminfo, "MemTotal: 3945000 kB\nMemFree: 100000 kB\n");
var mediaDir = MakeMediaDir(flacCount: 1);
var envFile = ScratchEnvPath();
Expand Down Expand Up @@ -337,7 +337,8 @@ public void Arm64WithAmpleKnownRamRecommendsFullNotPiperOnly()
{
// A beefy arm64 box (16 GiB) — bare arch used to force piper-only regardless of
// headroom; the recommendation must now follow the RAM, same as any other arch.
var meminfo = Path.Combine(Directory.CreateTempSubdirectory("gw-setup-story344-ram-").FullName, "meminfo");
using var meminfoDir = new TempDir();
var meminfo = Path.Combine(meminfoDir.Path, "meminfo");
File.WriteAllText(meminfo, "MemTotal: 16000000 kB\nMemFree: 1000000 kB\n");
var mediaDir = MakeMediaDir(flacCount: 1);
var envFile = ScratchEnvPath();
Expand Down
Loading
Loading