Skip to content

Commit b3765c3

Browse files
Mpdreamzclaude
andcommitted
Bump Nullean.ScopedFileSystem to 0.4.0; use InnerType for mock detection
0.4.0 exposes ScopedFileSystem.InnerType, removing the need to check the outer wrapper's type name when inspecting the underlying filesystem. FileSystemFactory.BuildWriteOptions: use sf.InnerType where the inner FS is available through a ScopedFileSystem to check for MockFileSystem, with a note linking to the upstream fix PR (TestableIO/System.IO.Abstractions#1454). GitCheckoutInformation.Create: replace fileSystem.GetType().Name.Contains("Mock") with (fileSystem is ScopedFileSystem sf ? sf.InnerType : fileSystem.GetType()) so the check correctly sees through the ScopedFileSystem wrapper. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
1 parent 911129b commit b3765c3

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0" />
4343
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.3" />
4444
<PackageVersion Include="Microsoft.Extensions.Telemetry.Abstractions" Version="10.0.0" />
45-
<PackageVersion Include="Nullean.ScopedFileSystem" Version="0.2.0" />
45+
<PackageVersion Include="Nullean.ScopedFileSystem" Version="0.4.0" />
4646
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.13.0" />
4747
<PackageVersion Include="Generator.Equals" Version="3.3.0" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
4848
<PackageVersion Include="KubernetesClient" Version="18.0.5" />

src/Elastic.Documentation.Configuration/FileSystemFactory.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,23 @@ public static ScopedFileSystem ScopeCurrentWorkingDirectory(IFileSystem inner, I
102102
}
103103

104104
// Builds write options that include AllowedSpecialFolders.Temp PLUS the inner FS's own
105-
// GetTempPath() as an explicit root. This is necessary because MockFileSystem on non-Windows
106-
// returns a hardcoded Unix-ified path ("/temp/") instead of System.IO.Path.GetTempPath(),
107-
// causing a mismatch with the AllowedSpecialFolder.Temp validation which uses the real API.
105+
// GetTempPath() as an explicit root — but only when the inner FS is MockFileSystem.
106+
//
107+
// On non-Windows MockFileSystem hardcodes a Unix-ified path ("/temp/", derived from "C:\temp")
108+
// instead of calling System.IO.Path.GetTempPath(). AllowedSpecialFolder.Temp uses the real
109+
// GetTempPath() (e.g. "/tmp/" on Linux), so the two diverge and scope validation fails for any
110+
// path created via mockFs.Path.GetTempPath().
111+
//
112+
// Fix tracked upstream: https://github.com/TestableIO/System.IO.Abstractions/pull/1454
113+
// Once that ships and we update the package reference we can drop this workaround.
114+
//
115+
// We use ScopedFileSystem.InnerType (added in Nullean.ScopedFileSystem 0.4.0) to avoid a
116+
// fragile string-based type check.
108117
private static ScopedFileSystemOptions BuildWriteOptions(IFileSystem inner, params string[] roots)
109118
{
110119
var allRoots = roots.ToList();
111-
if (!OperatingSystem.IsWindows())
120+
var innerType = inner is ScopedFileSystem sf ? sf.InnerType : inner.GetType();
121+
if (!OperatingSystem.IsWindows() && innerType.Name.Contains("Mock", StringComparison.OrdinalIgnoreCase))
112122
{
113123
// Cover MockFileSystem's unixified hardcoded temp path
114124
var innerTemp = inner.Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

src/Elastic.Documentation/GitCheckoutInformation.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text.RegularExpressions;
88
using Elastic.Documentation.Extensions;
99
using Microsoft.Extensions.Logging;
10+
using Nullean.ScopedFileSystem;
1011
using SoftCircuits.IniFileParser;
1112

1213
namespace Elastic.Documentation;
@@ -45,9 +46,11 @@ public static GitCheckoutInformation Create(IDirectoryInfo? source, IFileSystem
4546
if (source is null)
4647
return Unavailable;
4748

48-
// Return test data for in-memory (mock) file systems. ScopedFileSystem wraps the real
49-
// FileSystem so we check if the FS implementation name indicates an in-memory mock.
50-
if (fileSystem.GetType().Name.Contains("Mock", StringComparison.OrdinalIgnoreCase))
49+
// Return test data for in-memory (mock) file systems. Use ScopedFileSystem.InnerType
50+
// (available since Nullean.ScopedFileSystem 0.4.0) to inspect through the scope wrapper
51+
// rather than relying on the outer type name.
52+
var fsType = fileSystem is ScopedFileSystem sf ? sf.InnerType : fileSystem.GetType();
53+
if (fsType.Name.Contains("Mock", StringComparison.OrdinalIgnoreCase))
5154
{
5255
return new GitCheckoutInformation
5356
{

0 commit comments

Comments
 (0)