Issue #34: handle worktree roots in live smoke tests

This commit is contained in:
Joseph Doherty
2026-04-26 20:03:21 -04:00
parent 0f17a1d1d9
commit a9ef6d10d4
2 changed files with 30 additions and 4 deletions
@@ -37,7 +37,7 @@ public static class IntegrationTestEnvironment
return Path.GetFullPath(configuredPath);
}
string repositoryRoot = ResolveRepositoryRoot();
string repositoryRoot = ResolveRepositoryRoot(AppContext.BaseDirectory);
string[] candidatePaths =
[
Path.Combine(repositoryRoot, "src", "MxGateway.Worker", "bin", "x86", "Debug", "net48", "MxGateway.Worker.exe"),
@@ -74,12 +74,13 @@ public static class IntegrationTestEnvironment
return defaultValue;
}
private static string ResolveRepositoryRoot()
internal static string ResolveRepositoryRoot(string startDirectory)
{
DirectoryInfo? directory = new(AppContext.BaseDirectory);
DirectoryInfo? directory = new(startDirectory);
while (directory is not null)
{
if (Directory.Exists(Path.Combine(directory.FullName, ".git"))
if ((Directory.Exists(Path.Combine(directory.FullName, ".git"))
|| File.Exists(Path.Combine(directory.FullName, ".git")))
&& Directory.Exists(Path.Combine(directory.FullName, "src")))
{
return directory.FullName;
@@ -17,4 +17,29 @@ public sealed class IntegrationTestEnvironmentTests
"MXGATEWAY_LIVE_MXACCESS_WORKER_EXE",
IntegrationTestEnvironment.LiveMxAccessWorkerExecutableVariableName);
}
[Fact]
public void ResolveRepositoryRoot_AcceptsGitWorktreeFile()
{
string temporaryRoot = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
string nestedDirectory = Path.Combine(temporaryRoot, "tests", "bin");
try
{
Directory.CreateDirectory(nestedDirectory);
Directory.CreateDirectory(Path.Combine(temporaryRoot, "src"));
File.WriteAllText(Path.Combine(temporaryRoot, ".git"), "gitdir: ../.git/worktrees/test");
string repositoryRoot = IntegrationTestEnvironment.ResolveRepositoryRoot(nestedDirectory);
Assert.Equal(temporaryRoot, repositoryRoot);
}
finally
{
if (Directory.Exists(temporaryRoot))
{
Directory.Delete(temporaryRoot, recursive: true);
}
}
}
}