diff --git a/Directory.Packages.props b/Directory.Packages.props index ab7d3125e4..edf02ac382 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -42,7 +42,6 @@ - diff --git a/src/Elastic.Codex/Building/CodexBuildService.cs b/src/Elastic.Codex/Building/CodexBuildService.cs index d82ce54115..71d6a5a43b 100644 --- a/src/Elastic.Codex/Building/CodexBuildService.cs +++ b/src/Elastic.Codex/Building/CodexBuildService.cs @@ -25,7 +25,6 @@ using Elastic.Markdown.Exporters; using Elastic.Markdown.IO; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Codex.Building; @@ -47,7 +46,7 @@ public class CodexBuildService( public async Task BuildAll( CodexContext context, CodexCloneResult cloneResult, - ScopedFileSystem fileSystem, + IFileSystem fileSystem, Cancel ctx, IReadOnlySet? exporters = null) { @@ -67,7 +66,7 @@ public async Task BuildAll( var buildContexts = new List(); var environment = context.Configuration.Environment ?? "internal"; - using var codexLinkIndexReader = new GitLinkIndexReader(environment, FileSystemFactory.AppData, skipFetch: true); + using var codexLinkIndexReader = new GitLinkIndexReader(environment, context.ReadFileSystem, skipFetch: true); // Phase 1: Load and parse all documentation sets foreach (var checkout in cloneResult.Checkouts) @@ -137,7 +136,7 @@ public async Task BuildAll( private async Task LoadDocumentationSet( CodexContext context, CodexCheckout checkout, - ScopedFileSystem fileSystem, + IFileSystem fileSystem, ILinkIndexReader codexLinkIndexReader, Cancel ctx) { @@ -402,10 +401,10 @@ internal sealed class CodexDocumentationContext(CodexContext codexContext) : ICo public IDiagnosticsCollector Collector => codexContext.Collector; /// - public ScopedFileSystem ReadFileSystem => codexContext.ReadFileSystem; + public IFileSystem ReadFileSystem => codexContext.ReadFileSystem; /// - public ScopedFileSystem WriteFileSystem => codexContext.WriteFileSystem; + public IFileSystem WriteFileSystem => codexContext.WriteFileSystem; /// public IDirectoryInfo OutputDirectory => codexContext.OutputDirectory; diff --git a/src/Elastic.Codex/CodexContext.cs b/src/Elastic.Codex/CodexContext.cs index a432f72a34..f8ff2104e9 100644 --- a/src/Elastic.Codex/CodexContext.cs +++ b/src/Elastic.Codex/CodexContext.cs @@ -6,7 +6,6 @@ using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.Codex; using Elastic.Documentation.Diagnostics; -using Nullean.ScopedFileSystem; namespace Elastic.Codex; @@ -15,8 +14,8 @@ namespace Elastic.Codex; /// public class CodexContext { - public ScopedFileSystem ReadFileSystem { get; } - public ScopedFileSystem WriteFileSystem { get; } + public IFileSystem ReadFileSystem { get; } + public IFileSystem WriteFileSystem { get; } public IDiagnosticsCollector Collector { get; } public CodexConfiguration Configuration { get; } public IFileInfo ConfigurationPath { get; } @@ -35,8 +34,8 @@ public CodexContext( CodexConfiguration configuration, IFileInfo configurationPath, IDiagnosticsCollector collector, - ScopedFileSystem readFileSystem, - ScopedFileSystem writeFileSystem, + IFileSystem readFileSystem, + IFileSystem writeFileSystem, string? checkoutDirectory, string? outputDirectory) { @@ -46,10 +45,10 @@ public CodexContext( ReadFileSystem = readFileSystem; WriteFileSystem = writeFileSystem; - var defaultCheckoutDirectory = Path.Join(Paths.ApplicationData.FullName, "codex", "clone"); + var defaultCheckoutDirectory = Path.Join(Paths.GitCommonRoot.FullName, ".artifacts", "codex", "clone"); CheckoutDirectory = ReadFileSystem.DirectoryInfo.New(checkoutDirectory ?? defaultCheckoutDirectory); var defaultOutputDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "codex", "docs"); - OutputDirectory = WriteFileSystem.DirectoryInfo.New(outputDirectory ?? defaultOutputDirectory); + OutputDirectory = ReadFileSystem.DirectoryInfo.New(outputDirectory ?? defaultOutputDirectory); } } diff --git a/src/Elastic.Codex/Indexing/CodexIndexService.cs b/src/Elastic.Codex/Indexing/CodexIndexService.cs index c1235c58be..5a4de17046 100644 --- a/src/Elastic.Codex/Indexing/CodexIndexService.cs +++ b/src/Elastic.Codex/Indexing/CodexIndexService.cs @@ -10,7 +10,6 @@ using Elastic.Documentation.Isolated; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Codex.Indexing; @@ -31,7 +30,7 @@ IsolatedBuildService isolatedBuildService public async Task Index( CodexContext codexContext, CodexCloneResult cloneResult, - ScopedFileSystem fileSystem, + FileSystem fileSystem, ElasticsearchIndexOptions esOptions, Cancel ctx = default) { diff --git a/src/Elastic.Documentation.Configuration/BuildContext.cs b/src/Elastic.Documentation.Configuration/BuildContext.cs index 85db4b731a..64301d8333 100644 --- a/src/Elastic.Documentation.Configuration/BuildContext.cs +++ b/src/Elastic.Documentation.Configuration/BuildContext.cs @@ -13,7 +13,6 @@ using Elastic.Documentation.Configuration.Toc; using Elastic.Documentation.Configuration.Versions; using Elastic.Documentation.Diagnostics; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Configuration; @@ -22,8 +21,8 @@ public record BuildContext : IDocumentationSetContext, IDocumentationConfigurati public static string Version { get; } = Assembly.GetExecutingAssembly().GetCustomAttributes() .FirstOrDefault()?.InformationalVersion ?? "0.0.0"; - public ScopedFileSystem ReadFileSystem { get; } - public ScopedFileSystem WriteFileSystem { get; } + public IFileSystem ReadFileSystem { get; } + public IFileSystem WriteFileSystem { get; } public IReadOnlySet AvailableExporters { get; } public IDirectoryInfo? DocumentationCheckoutDirectory { get; } @@ -73,7 +72,7 @@ public string? UrlPathPrefix public BuildContext( IDiagnosticsCollector collector, - ScopedFileSystem fileSystem, + IFileSystem fileSystem, IConfigurationContext configurationContext ) : this(collector, fileSystem, fileSystem, configurationContext, ExportOptions.Default, null, null) @@ -82,8 +81,8 @@ IConfigurationContext configurationContext public BuildContext( IDiagnosticsCollector collector, - ScopedFileSystem readFileSystem, - ScopedFileSystem writeFileSystem, + IFileSystem readFileSystem, + IFileSystem writeFileSystem, IConfigurationContext configurationContext, IReadOnlySet availableExporters, string? source = null, @@ -108,7 +107,7 @@ public BuildContext( (DocumentationSourceDirectory, ConfigurationPath) = Paths.FindDocsFolderFromRoot(ReadFileSystem, rootFolder); - DocumentationCheckoutDirectory = Paths.FindGitRoot(DocumentationSourceDirectory); + DocumentationCheckoutDirectory = Paths.DetermineSourceDirectoryRoot(DocumentationSourceDirectory); OutputDirectory = !string.IsNullOrWhiteSpace(output) ? WriteFileSystem.DirectoryInfo.New(output) diff --git a/src/Elastic.Documentation.Configuration/ConfigurationFileProvider.cs b/src/Elastic.Documentation.Configuration/ConfigurationFileProvider.cs index 4fd9970baf..c9eb037037 100644 --- a/src/Elastic.Documentation.Configuration/ConfigurationFileProvider.cs +++ b/src/Elastic.Documentation.Configuration/ConfigurationFileProvider.cs @@ -45,11 +45,7 @@ public ConfigurationFileProvider( _fileSystem = fileSystem; _assemblyName = typeof(ConfigurationFileProvider).Assembly.GetName().Name!; SkipPrivateRepositories = skipPrivateRepositories; - // Use a unique subdirectory per instance to avoid file-locking collisions when - // multiple processes or parallel tests share the same ApplicationData path. - var configRuntimeDir = Path.Join(Paths.ApplicationData.FullName, "config-runtime", Guid.NewGuid().ToString("N")); - TemporaryDirectory = fileSystem.DirectoryInfo.New(configRuntimeDir); - TemporaryDirectory.Create(); + TemporaryDirectory = fileSystem.Directory.CreateTempSubdirectory("docs-builder-config"); // TODO: This doesn't work as expected if a github actions consumer repo has a `config` directory. // ConfigurationSource = configurationSource ?? ( @@ -271,7 +267,7 @@ public static IServiceCollection AddConfigurationFileProvider(this IServiceColle { using var sp = services.BuildServiceProvider(); var logFactory = sp.GetRequiredService(); - var provider = new ConfigurationFileProvider(logFactory, FileSystemFactory.RealRead, skipPrivateRepositories, configurationSource); + var provider = new ConfigurationFileProvider(logFactory, new FileSystem(), skipPrivateRepositories, configurationSource); _ = services.AddSingleton(provider); configure(services, provider); return services; diff --git a/src/Elastic.Documentation.Configuration/Elastic.Documentation.Configuration.csproj b/src/Elastic.Documentation.Configuration/Elastic.Documentation.Configuration.csproj index 83887a031e..ff9d136a49 100644 --- a/src/Elastic.Documentation.Configuration/Elastic.Documentation.Configuration.csproj +++ b/src/Elastic.Documentation.Configuration/Elastic.Documentation.Configuration.csproj @@ -9,17 +9,15 @@ - + - - - - + + diff --git a/src/Elastic.Documentation.Configuration/FileSystemFactory.cs b/src/Elastic.Documentation.Configuration/FileSystemFactory.cs deleted file mode 100644 index 2025cf2a54..0000000000 --- a/src/Elastic.Documentation.Configuration/FileSystemFactory.cs +++ /dev/null @@ -1,215 +0,0 @@ -// Licensed to Elasticsearch B.V under one or more agreements. -// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information - -using System.IO.Abstractions; -using System.IO.Abstractions.TestingHelpers; -using Nullean.ScopedFileSystem; - -namespace Elastic.Documentation.Configuration; - -public static class FileSystemFactory -{ - // Read options: workspace + app data, all confirmed hidden names allowed. - // Includes .git (GitCheckoutInformation reads it) and .artifacts/.doc.state - // (incremental build reads existing output state). - private static readonly ScopedFileSystemOptions WorkingDirectoryReadOptions = new( - [Paths.WorkingDirectoryRoot.FullName, Paths.ApplicationData.FullName]) - { - AllowedHiddenFolderNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".git", ".artifacts" }, - AllowedHiddenFileNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".git", ".doc.state" } - }; - - // Write options: same scope roots but no .git — nothing in the build output - // pipeline should ever write into the git repository metadata. - // Temp is allowed because deploy operations (e.g. S3 sync) stage files there. - private static readonly ScopedFileSystemOptions WorkingDirectoryWriteOptions = new( - [Paths.WorkingDirectoryRoot.FullName, Paths.ApplicationData.FullName]) - { - AllowedHiddenFolderNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".artifacts" }, - AllowedHiddenFileNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".doc.state" }, - AllowedSpecialFolders = AllowedSpecialFolder.Temp - }; - - // AppData-only options: for components that only access caches/state files. - private static readonly ScopedFileSystemOptions AppDataOptions = new([Paths.ApplicationData.FullName]) - { - // .git needed for codex-link-index clone directory inside ApplicationData - AllowedHiddenFolderNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".git" } - }; - - /// - /// A pre-allocated for reading workspace files. - /// Scoped to the working directory root and per-user app data; allows .git - /// (read by GitCheckoutInformation), .artifacts and .doc.state - /// (read for incremental build state). - /// - public static ScopedFileSystem RealRead { get; } = new ScopedFileSystem(new FileSystem(), WorkingDirectoryReadOptions); - - /// - /// A pre-allocated for writing build output. - /// Same scope as but without .git access — - /// nothing in the output pipeline should write into git repository metadata. - /// - public static ScopedFileSystem RealWrite { get; } = new ScopedFileSystem(new FileSystem(), WorkingDirectoryWriteOptions); - - /// - /// A pre-allocated scoped only to the per-user - /// elastic/docs-builder application data folder. Use for components that - /// access caches or state and have no need for workspace files - /// (e.g. CrossLinkFetcher, CheckForUpdatesFilter, GitLinkIndexReader). - /// - public static ScopedFileSystem AppData { get; } = new ScopedFileSystem(new FileSystem(), AppDataOptions); - - /// - /// Creates a new wrapping a fresh , - /// using the working-directory read options. Each call returns a new independent in-memory file system. - /// - public static ScopedFileSystem InMemory() => new(new MockFileSystem(), WorkingDirectoryReadOptions); - - /// - /// Scopes to and - /// for reading. Use when the inner FS contains files - /// that live within the current working-directory tree (e.g. a test MockFileSystem - /// seeded with workspace-relative paths). - /// - public static ScopedFileSystem ScopeCurrentWorkingDirectory(IFileSystem inner) => - new(inner, WorkingDirectoryReadOptions); - - /// - /// Scopes to and - /// for reading, extended by - /// (e.g. detection-rules folders declared via - /// ). - /// - public static ScopedFileSystem ScopeCurrentWorkingDirectory(IFileSystem inner, IEnumerable? extensionRoots) - { - if (extensionRoots is null) - return ScopeCurrentWorkingDirectory(inner); - - var roots = new[] { Paths.WorkingDirectoryRoot.FullName, Paths.ApplicationData.FullName } - .Concat(extensionRoots) - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToArray(); - if (roots.Length == 2) - return ScopeCurrentWorkingDirectory(inner); - - return new ScopedFileSystem(inner, new ScopedFileSystemOptions(roots) - { - AllowedHiddenFolderNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".git", ".artifacts" }, - AllowedHiddenFileNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".git", ".doc.state" } - }); - } - - // Builds write options that include AllowedSpecialFolders.Temp PLUS the inner FS's own - // GetTempPath() as an explicit root — but only when the inner FS is MockFileSystem. - // - // On non-Windows MockFileSystem hardcodes a Unix-ified path ("/temp/", derived from "C:\temp") - // instead of calling System.IO.Path.GetTempPath(). AllowedSpecialFolder.Temp uses the real - // GetTempPath() (e.g. "/tmp/" on Linux), so the two diverge and scope validation fails for any - // path created via mockFs.Path.GetTempPath(). - // - // Fix tracked upstream: https://github.com/TestableIO/System.IO.Abstractions/pull/1454 - // Once that ships and we update the package reference we can drop this workaround. - // - // We use ScopedFileSystem.InnerType (added in Nullean.ScopedFileSystem 0.4.0) to avoid a - // fragile string-based type check. - private static ScopedFileSystemOptions BuildWriteOptions(IFileSystem inner, params string[] roots) - { - var allRoots = roots.ToList(); - var innerType = inner is ScopedFileSystem sf ? sf.InnerType : inner.GetType(); - if (!OperatingSystem.IsWindows() && innerType.Name.Contains("Mock", StringComparison.OrdinalIgnoreCase)) - { - // Cover MockFileSystem's unixified hardcoded temp path - var innerTemp = inner.Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); - if (!string.IsNullOrEmpty(innerTemp) && !allRoots.Contains(innerTemp, StringComparer.OrdinalIgnoreCase)) - allRoots.Add(innerTemp); - } - return new ScopedFileSystemOptions([.. allRoots]) - { - AllowedHiddenFolderNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".artifacts" }, - AllowedHiddenFileNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".doc.state" }, - AllowedSpecialFolders = AllowedSpecialFolder.Temp - }; - } - - /// - /// Scopes to and - /// for writing (.git not allowed). Use when - /// the inner FS writes into the working-directory tree. - /// - public static ScopedFileSystem ScopeCurrentWorkingDirectoryForWrite(IFileSystem inner) => - new(inner, BuildWriteOptions( - inner, Paths.WorkingDirectoryRoot.FullName, Paths.ApplicationData.FullName)); - - /// - /// Scopes to an explicit and - /// for reading. Use when the files to be read live under - /// a specific known root that is not — for example - /// test fixtures with assembler-checkout paths or service code operating on a given directory. - /// - public static ScopedFileSystem ScopeSourceDirectory(IFileSystem inner, string sourceRoot) => - new(inner, new ScopedFileSystemOptions([sourceRoot, Paths.ApplicationData.FullName]) - { - AllowedHiddenFolderNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".git", ".artifacts" }, - AllowedHiddenFileNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".git", ".doc.state" } - }); - - /// - /// Scopes to an explicit and - /// for writing (.git not allowed). Write variant - /// of . - /// - public static ScopedFileSystem ScopeSourceDirectoryForWrite(IFileSystem inner, string sourceRoot) => - new(inner, BuildWriteOptions(inner, sourceRoot, Paths.ApplicationData.FullName)); - - /// - /// Creates a read scoped to the git root of - /// . Falls back to when - /// is . Use in commands that accept an explicit --path argument. - /// - /// Suitable for command-layer code. Service-layer tests use directly - /// and do not exercise this method. - /// - /// - public static ScopedFileSystem RealGitRootForPath(string? path) - { - if (path is null) - return RealRead; - var root = Paths.FindGitRoot(path); - return new ScopedFileSystem(new FileSystem(), new ScopedFileSystemOptions([root, Paths.ApplicationData.FullName]) - { - AllowedHiddenFolderNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".git", ".artifacts" }, - AllowedHiddenFileNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".git", ".doc.state" } - }); - } - - /// - /// Creates a write scoped to the git root of - /// (and if it falls outside that root). - /// Falls back to when both are . - /// Use in commands that accept explicit --path and/or --output arguments. - /// - public static ScopedFileSystem RealGitRootForPathWrite(string? path, string? output = null) - { - if (path is null && output is null) - return RealWrite; - - var gitRoot = path is not null ? Paths.FindGitRoot(path) : Paths.WorkingDirectoryRoot.FullName; - var roots = new List { gitRoot, Paths.ApplicationData.FullName }; - - if (output is not null) - { - var absOutput = Path.IsPathRooted(output) ? output : Path.GetFullPath(output); - var plain = new FileSystem(); - if (!plain.DirectoryInfo.New(absOutput).IsSubPathOf(plain.DirectoryInfo.New(gitRoot))) - roots.Add(absOutput); - } - - return new ScopedFileSystem(new FileSystem(), new ScopedFileSystemOptions([.. roots]) - { - AllowedHiddenFolderNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".artifacts" }, - AllowedHiddenFileNames = new HashSet(StringComparer.OrdinalIgnoreCase) { ".doc.state" } - }); - } -} diff --git a/src/Elastic.Documentation.Configuration/Paths.cs b/src/Elastic.Documentation.Configuration/Paths.cs index 3c0f61bc14..47d2468074 100644 --- a/src/Elastic.Documentation.Configuration/Paths.cs +++ b/src/Elastic.Documentation.Configuration/Paths.cs @@ -11,108 +11,79 @@ public static class Paths { public static readonly DirectoryInfo WorkingDirectoryRoot = DetermineWorkingDirectoryRoot(); + public static readonly DirectoryInfo GitCommonRoot = InitGitCommonRoot(); + public static readonly DirectoryInfo ApplicationData = GetApplicationFolder(); - /// - /// Walks up from until a .git directory or file - /// (worktree pointer) is found and returns that ancestor. Returns - /// itself when no git root is found within the allowed depth. - /// - /// - /// Depth protection: in release builds the .git anchor must be at most 1 directory - /// above — documentation is not expected to live deep inside - /// a repo. In debug builds a deeper .git is accepted when a *.slnx file is - /// adjacent (developer running the binary from an IDE output directory). - /// - public static string FindGitRoot(string startPath) + private static DirectoryInfo DetermineWorkingDirectoryRoot() { - var resolved = Path.IsPathRooted(startPath) ? startPath : Path.GetFullPath(startPath); - var dir = Directory.Exists(resolved) - ? new DirectoryInfo(resolved) - : new DirectoryInfo(Path.GetDirectoryName(resolved) ?? resolved); - var depth = 0; - while (dir != null) + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null) { - var hasGit = dir.GetDirectories(".git").Length > 0 || dir.GetFiles(".git").Length > 0; - if (hasGit) - { -#if DEBUG - if (depth <= 1 || dir.GetFiles("*.slnx").Length > 0) - return dir.FullName; -#else - if (depth <= 1) - return dir.FullName; -#endif - // .git found but too deep — stop searching - return resolved; - } - depth++; - dir = dir.Parent; + if (directory.GetFiles("*.slnx").Length > 0) + break; + if (directory.GetDirectories(".git").Length > 0) + break; + // support for git worktrees + if (directory.GetFiles(".git").Length > 0) + break; + directory = directory.Parent; } - return resolved; + return directory ?? new DirectoryInfo(Directory.GetCurrentDirectory()); } - /// - /// Walks up from via until - /// a .git directory or file (worktree pointer) is found. - /// Returns if no git root is found within the allowed depth. - /// - /// Same depth protection as . - public static IDirectoryInfo? FindGitRoot(IDirectoryInfo startDirectory) + public static IDirectoryInfo? DetermineSourceDirectoryRoot(IDirectoryInfo sourceDirectory) { - var directory = startDirectory; - var depth = 0; - while (directory != null) + IDirectoryInfo? sourceRoot = null; + var directory = sourceDirectory; + while (directory != null && directory.GetDirectories(".git").Length == 0) { - var hasGit = directory.GetDirectories(".git").Length > 0 - || directory.GetFiles(".git").Length > 0; - if (hasGit) - { -#if DEBUG - if (depth <= 1 || directory.GetFiles("*.slnx").Length > 0) - return directory; -#else - if (depth <= 1) - return directory; -#endif - // .git found but too deep - return null; - } - depth++; + if (directory.GetDirectories(".git").Length > 0) + break; + // support for git worktrees + if (directory.GetFiles(".git").Length > 0) + break; + directory = directory.Parent; } - return null; + sourceRoot ??= directory; + return sourceRoot; } - private static DirectoryInfo DetermineWorkingDirectoryRoot() + /// Resolves the root of the main git repository, following worktree links when present. Disabled on CI. + public static IDirectoryInfo ResolveGitCommonRoot(IFileSystem fileSystem, IDirectoryInfo workingDirectoryRoot, bool? isCI = null) { - var cwd = new DirectoryInfo(Directory.GetCurrentDirectory()); - var directory = cwd; - var depth = 0; - while (directory != null) - { - if (directory.GetFiles("*.slnx").Length > 0) - return directory; - var hasGit = directory.GetDirectories(".git").Length > 0 - || directory.GetFiles(".git").Length > 0; - if (hasGit) - { - // Only accept .git beyond 1 level up in debug when a *.slnx is adjacent - // (developer running from IDE output directory such as bin/Debug/net10.0/). -#if DEBUG - if (depth <= 1 || directory.GetFiles("*.slnx").Length > 0) - return directory; -#else - if (depth <= 1) - return directory; -#endif - // .git found but too deep — stop without adopting it - return cwd; - } - depth++; - directory = directory.Parent; - } - return cwd; + if (isCI ?? !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"))) + return workingDirectoryRoot; + + var gitPath = Path.Join(workingDirectoryRoot.FullName, ".git"); + + if (fileSystem.Directory.Exists(gitPath)) + return workingDirectoryRoot; + + if (!fileSystem.File.Exists(gitPath)) + return workingDirectoryRoot; + + var content = fileSystem.File.ReadAllText(gitPath).Trim(); + if (!content.StartsWith("gitdir:", StringComparison.OrdinalIgnoreCase)) + return workingDirectoryRoot; + + var gitDirPath = content["gitdir:".Length..].Trim(); + if (!Path.IsPathRooted(gitDirPath)) + gitDirPath = Path.GetFullPath(gitDirPath, workingDirectoryRoot.FullName); + + var dir = fileSystem.DirectoryInfo.New(gitDirPath); + while (dir != null && dir.Name != ".git") + dir = dir.Parent; + + return dir?.Parent ?? workingDirectoryRoot; + } + + private static DirectoryInfo InitGitCommonRoot() + { + var fs = new FileSystem(); + var root = fs.DirectoryInfo.New(WorkingDirectoryRoot.FullName); + return new DirectoryInfo(ResolveGitCommonRoot(fs, root).FullName); } /// Used in debug to locate static folder, so we can change js/css files while the server is running diff --git a/src/Elastic.Documentation.Configuration/Toc/DocumentationSetFile.cs b/src/Elastic.Documentation.Configuration/Toc/DocumentationSetFile.cs index c2bf385b95..9ba12a78bf 100644 --- a/src/Elastic.Documentation.Configuration/Toc/DocumentationSetFile.cs +++ b/src/Elastic.Documentation.Configuration/Toc/DocumentationSetFile.cs @@ -7,7 +7,6 @@ using Elastic.Documentation.Configuration.Toc.DetectionRules; using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Extensions; -using Nullean.ScopedFileSystem; using YamlDotNet.Serialization; using static Elastic.Documentation.Configuration.SymlinkValidator; @@ -97,9 +96,9 @@ public static DocumentationSetFile LoadMetadata(IFileInfo file) /// replacing them with their resolved children and ensuring file paths carry over parent paths. /// Validates the table of contents structure and emits diagnostics for issues. /// - public static DocumentationSetFile LoadAndResolve(IDiagnosticsCollector collector, IFileInfo docsetPath, ScopedFileSystem? fileSystem = null, HashSet? noSuppress = null) + public static DocumentationSetFile LoadAndResolve(IDiagnosticsCollector collector, IFileInfo docsetPath, IFileSystem? fileSystem = null, HashSet? noSuppress = null) { - fileSystem ??= FileSystemFactory.ScopeSourceDirectory(docsetPath.FileSystem, docsetPath.Directory!.FullName); + fileSystem ??= docsetPath.FileSystem; // Validate that the docset.yml is not a symlink (security: prevents path traversal attacks) EnsureNotSymlink(docsetPath); var yaml = fileSystem.File.ReadAllText(docsetPath.FullName); @@ -119,9 +118,9 @@ public static DocumentationSetFile LoadAndResolve(IDiagnosticsCollector collecto /// replacing them with their resolved children and ensuring file paths carry over parent paths. /// Validates the table of contents structure and emits diagnostics for issues. /// - public static DocumentationSetFile LoadAndResolve(IDiagnosticsCollector collector, string yaml, IDirectoryInfo sourceDirectory, ScopedFileSystem? fileSystem = null, HashSet? noSuppress = null) + public static DocumentationSetFile LoadAndResolve(IDiagnosticsCollector collector, string yaml, IDirectoryInfo sourceDirectory, IFileSystem? fileSystem = null, HashSet? noSuppress = null) { - fileSystem ??= FileSystemFactory.ScopeSourceDirectory(sourceDirectory.FileSystem, sourceDirectory.FullName); + fileSystem ??= sourceDirectory.FileSystem; var docSet = Deserialize(yaml); var docsetPath = fileSystem.Path.Join(sourceDirectory.FullName, "docset.yml").OptionalWindowsReplace(); docSet.SuppressDiagnostics.ExceptWith(noSuppress ?? []); diff --git a/src/Elastic.Documentation.LinkIndex/Elastic.Documentation.LinkIndex.csproj b/src/Elastic.Documentation.LinkIndex/Elastic.Documentation.LinkIndex.csproj index 1fef2ce2a0..e86f0f7745 100644 --- a/src/Elastic.Documentation.LinkIndex/Elastic.Documentation.LinkIndex.csproj +++ b/src/Elastic.Documentation.LinkIndex/Elastic.Documentation.LinkIndex.csproj @@ -8,12 +8,10 @@ - - diff --git a/src/Elastic.Documentation.LinkIndex/GitLinkIndexReader.cs b/src/Elastic.Documentation.LinkIndex/GitLinkIndexReader.cs index b1028031ff..901aff790c 100644 --- a/src/Elastic.Documentation.LinkIndex/GitLinkIndexReader.cs +++ b/src/Elastic.Documentation.LinkIndex/GitLinkIndexReader.cs @@ -4,9 +4,7 @@ using System.Diagnostics; using System.IO.Abstractions; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Links; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.LinkIndex; @@ -18,8 +16,9 @@ public class GitLinkIndexReader : ILinkIndexReader, IDisposable { private const string LinkIndexOrigin = "elastic/codex-link-index"; private static readonly string CloneDirectory = Path.Join( - Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), - "elastic", "docs-builder", "codex-link-index"); + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), + ".docs-builder", + "codex-link-index"); private readonly string _environment; private readonly IFileSystem _fileSystem; @@ -27,13 +26,13 @@ public class GitLinkIndexReader : ILinkIndexReader, IDisposable private readonly SemaphoreSlim _cloneLock = new(1, 1); private bool _ensuredClone; - public GitLinkIndexReader(string environment, ScopedFileSystem? fileSystem = null, bool skipFetch = false) + public GitLinkIndexReader(string environment, IFileSystem? fileSystem = null, bool skipFetch = false) { if (string.IsNullOrWhiteSpace(environment)) throw new ArgumentException("Environment must be specified in the codex configuration (e.g., 'internal', 'security').", nameof(environment)); _environment = environment; - _fileSystem = fileSystem ?? FileSystemFactory.AppData; + _fileSystem = fileSystem ?? new FileSystem(); _skipFetch = skipFetch; } diff --git a/src/Elastic.Documentation.Links/CrossLinks/CrossLinkFetcher.cs b/src/Elastic.Documentation.Links/CrossLinks/CrossLinkFetcher.cs index c0c7d21e76..f48379cde9 100644 --- a/src/Elastic.Documentation.Links/CrossLinks/CrossLinkFetcher.cs +++ b/src/Elastic.Documentation.Links/CrossLinks/CrossLinkFetcher.cs @@ -4,13 +4,11 @@ using System.Collections.Concurrent; using System.Collections.Frozen; -using System.IO.Abstractions; using System.Text.Json; using Elastic.Documentation.Configuration; using Elastic.Documentation.LinkIndex; using Elastic.Documentation.Serialization; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Links.CrossLinks; @@ -44,10 +42,9 @@ public record FetchedCrossLinks }; } -public abstract class CrossLinkFetcher(ILoggerFactory logFactory, ILinkIndexReader linkIndexProvider, ScopedFileSystem? fileSystem = null) : IDisposable +public abstract class CrossLinkFetcher(ILoggerFactory logFactory, ILinkIndexReader linkIndexProvider) : IDisposable { protected ILogger Logger { get; } = logFactory.CreateLogger(nameof(CrossLinkFetcher)); - private readonly IFileSystem _fileSystem = fileSystem ?? FileSystemFactory.AppData; private LinkRegistry? _linkIndex; public static RepositoryLinks Deserialize(string json) => @@ -149,12 +146,12 @@ private void WriteLinksJsonCachedFile(string repository, LinkRegistryEntry linkR { var cachedFileName = $"links-elastic-{repository}-{linkRegistryEntry.Branch}-{linkRegistryEntry.ETag}.json"; var cachedPath = Path.Join(Paths.ApplicationData.FullName, "links", cachedFileName); - if (_fileSystem.File.Exists(cachedPath)) + if (File.Exists(cachedPath)) return; try { - _ = _fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(cachedPath)!); - _fileSystem.File.WriteAllText(cachedPath, RepositoryLinks.Serialize(linkReference)); + _ = Directory.CreateDirectory(Path.GetDirectoryName(cachedPath)!); + File.WriteAllText(cachedPath, RepositoryLinks.Serialize(linkReference)); } catch (Exception e) { @@ -171,11 +168,11 @@ private void WriteLinksJsonCachedFile(string repository, LinkRegistryEntry linkR if (_cachedLinkReferences.TryGetValue(cachedFileName, out var cachedLinkReference)) return cachedLinkReference; - if (_fileSystem.File.Exists(cachedPath)) + if (File.Exists(cachedPath)) { try { - var json = await _fileSystem.File.ReadAllTextAsync(cachedPath); + var json = await File.ReadAllTextAsync(cachedPath); var linkReference = Deserialize(json); _ = _cachedLinkReferences.TryAdd(cachedFileName, linkReference); return linkReference; diff --git a/src/Elastic.Documentation/Elastic.Documentation.csproj b/src/Elastic.Documentation/Elastic.Documentation.csproj index a6a49d02a2..fbc2f8c723 100644 --- a/src/Elastic.Documentation/Elastic.Documentation.csproj +++ b/src/Elastic.Documentation/Elastic.Documentation.csproj @@ -15,7 +15,6 @@ - diff --git a/src/Elastic.Documentation/GitCheckoutInformation.cs b/src/Elastic.Documentation/GitCheckoutInformation.cs index e08b965101..6981b40ef8 100644 --- a/src/Elastic.Documentation/GitCheckoutInformation.cs +++ b/src/Elastic.Documentation/GitCheckoutInformation.cs @@ -7,7 +7,6 @@ using System.Text.RegularExpressions; using Elastic.Documentation.Extensions; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; using SoftCircuits.IniFileParser; namespace Elastic.Documentation; @@ -46,11 +45,7 @@ public static GitCheckoutInformation Create(IDirectoryInfo? source, IFileSystem if (source is null) return Unavailable; - // Return test data for in-memory (mock) file systems. Use ScopedFileSystem.InnerType - // (available since Nullean.ScopedFileSystem 0.4.0) to inspect through the scope wrapper - // rather than relying on the outer type name. - var fsType = fileSystem is ScopedFileSystem sf ? sf.InnerType : fileSystem.GetType(); - if (fsType.Name.Contains("Mock", StringComparison.OrdinalIgnoreCase)) + if (fileSystem is not FileSystem) { return new GitCheckoutInformation { diff --git a/src/Elastic.Documentation/IDocumentationContext.cs b/src/Elastic.Documentation/IDocumentationContext.cs index 72512d4c09..cf7daaddd1 100644 --- a/src/Elastic.Documentation/IDocumentationContext.cs +++ b/src/Elastic.Documentation/IDocumentationContext.cs @@ -4,15 +4,14 @@ using System.IO.Abstractions; using Elastic.Documentation.Diagnostics; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation; public interface IDocumentationContext { IDiagnosticsCollector Collector { get; } - ScopedFileSystem ReadFileSystem { get; } - ScopedFileSystem WriteFileSystem { get; } + IFileSystem ReadFileSystem { get; } + IFileSystem WriteFileSystem { get; } IDirectoryInfo OutputDirectory { get; } IFileInfo ConfigurationPath { get; } BuildType BuildType { get; } diff --git a/src/Elastic.Markdown/Extensions/DetectionRules/DetectionRulesDocsBuilderExtension.cs b/src/Elastic.Markdown/Extensions/DetectionRules/DetectionRulesDocsBuilderExtension.cs index bf161d8a6d..dc99b1c1d7 100644 --- a/src/Elastic.Markdown/Extensions/DetectionRules/DetectionRulesDocsBuilderExtension.cs +++ b/src/Elastic.Markdown/Extensions/DetectionRules/DetectionRulesDocsBuilderExtension.cs @@ -19,13 +19,6 @@ public class DetectionRulesDocsBuilderExtension(BuildContext build) : IDocsBuild private BuildContext Build { get; } = build; private bool _versionLockInitialized; - public IEnumerable ExternalScopeRoots => - Build.ConfigurationYaml.TableOfContents - .OfType() - .SelectMany(f => f.Children.OfType()) - .SelectMany(r => r.DetectionRuleFolders) - .Distinct(); - public IDocumentationFileExporter? FileExporter { get; } = new RuleDocumentationFileExporter(build.ReadFileSystem, build.WriteFileSystem); public DocumentationFile? CreateDocumentationFile(IFileInfo file, MarkdownParser markdownParser) diff --git a/src/Elastic.Markdown/Extensions/IDocsBuilderExtension.cs b/src/Elastic.Markdown/Extensions/IDocsBuilderExtension.cs index a1d5af396d..1dcba78d65 100644 --- a/src/Elastic.Markdown/Extensions/IDocsBuilderExtension.cs +++ b/src/Elastic.Markdown/Extensions/IDocsBuilderExtension.cs @@ -15,12 +15,6 @@ public interface IDocsBuilderExtension { IDocumentationFileExporter? FileExporter { get; } - /// - /// Directories outside the working directory root that this extension requires read access to. - /// These are collected and added as additional ScopedFileSystem roots when building. - /// - IEnumerable ExternalScopeRoots => []; - /// Create an instance of if it matches the . /// Return `null` to let another extension handle this. DocumentationFile? CreateDocumentationFile(IFileInfo file, MarkdownParser markdownParser); diff --git a/src/Elastic.Markdown/Myst/Directives/CsvInclude/CsvReader.cs b/src/Elastic.Markdown/Myst/Directives/CsvInclude/CsvReader.cs index 12f6b1d68f..50b9f85e7e 100644 --- a/src/Elastic.Markdown/Myst/Directives/CsvInclude/CsvReader.cs +++ b/src/Elastic.Markdown/Myst/Directives/CsvInclude/CsvReader.cs @@ -3,17 +3,15 @@ // See the LICENSE file in the project root for more information using System.IO.Abstractions; -using Elastic.Documentation.Configuration; using nietras.SeparatedValues; -using Nullean.ScopedFileSystem; namespace Elastic.Markdown.Myst.Directives.CsvInclude; public static class CsvReader { - public static IEnumerable ReadCsvFile(string filePath, string separator, ScopedFileSystem? fileSystem = null) + public static IEnumerable ReadCsvFile(string filePath, string separator, IFileSystem? fileSystem = null) { - var fs = fileSystem ?? FileSystemFactory.RealRead; + var fs = fileSystem ?? new FileSystem(); return ReadWithSep(filePath, separator, fs); } @@ -22,16 +20,35 @@ private static IEnumerable ReadWithSep(string filePath, string separat var separatorChar = separator == "," ? ',' : separator[0]; var spec = Sep.New(separatorChar); - // Always read via IFileSystem so that scoped and mock file systems are respected. - var content = fileSystem.File.ReadAllText(filePath); - using var reader = spec.Reader(o => o with { HasHeader = false, Unescape = true }).FromText(content); + // Sep works with actual file paths, not virtual file systems + // For testing with MockFileSystem, we'll read content first + if (fileSystem.GetType().Name == "MockFileSystem") + { + var content = fileSystem.File.ReadAllText(filePath); + using var reader = spec.Reader(o => o with { HasHeader = false, Unescape = true }).FromText(content); - foreach (var row in reader) + foreach (var row in reader) + { + var rowData = new string[row.ColCount]; + for (var i = 0; i < row.ColCount; i++) + rowData[i] = row[i].ToString(); + yield return rowData; + } + } + else { - var rowData = new string[row.ColCount]; - for (var i = 0; i < row.ColCount; i++) - rowData[i] = row[i].ToString(); - yield return rowData; + using var reader = spec.Reader(o => o with { HasHeader = false, Unescape = true }).FromFile(filePath); + + foreach (var row in reader) + { + var rowData = new string[row.ColCount]; + for (var i = 0; i < row.ColCount; i++) + { + rowData[i] = row[i].ToString(); + } + yield return rowData; + } } } + } diff --git a/src/authoring/Elastic.Documentation.Refactor/FormatService.cs b/src/authoring/Elastic.Documentation.Refactor/FormatService.cs index 591a8c8da9..785089c7bc 100644 --- a/src/authoring/Elastic.Documentation.Refactor/FormatService.cs +++ b/src/authoring/Elastic.Documentation.Refactor/FormatService.cs @@ -10,7 +10,6 @@ using Elastic.Documentation.Services; using Elastic.Markdown.IO; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Refactor; @@ -35,7 +34,7 @@ public async Task Format( IDiagnosticsCollector collector, string? path, bool checkOnly, - ScopedFileSystem fs, + IFileSystem fs, Cancel ctx ) { diff --git a/src/authoring/Elastic.Documentation.Refactor/MoveFileService.cs b/src/authoring/Elastic.Documentation.Refactor/MoveFileService.cs index 91fbaedd56..20de1525d7 100644 --- a/src/authoring/Elastic.Documentation.Refactor/MoveFileService.cs +++ b/src/authoring/Elastic.Documentation.Refactor/MoveFileService.cs @@ -9,7 +9,6 @@ using Elastic.Documentation.Services; using Elastic.Markdown.IO; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Refactor; @@ -24,7 +23,7 @@ public async Task Move( string target, bool? dryRun, string? path, - ScopedFileSystem fs, + IFileSystem fs, Cancel ctx ) { diff --git a/src/authoring/Elastic.Documentation.Refactor/Tracking/LocalChangesService.cs b/src/authoring/Elastic.Documentation.Refactor/Tracking/LocalChangesService.cs index 530e46a021..da1e910935 100644 --- a/src/authoring/Elastic.Documentation.Refactor/Tracking/LocalChangesService.cs +++ b/src/authoring/Elastic.Documentation.Refactor/Tracking/LocalChangesService.cs @@ -9,7 +9,6 @@ using Elastic.Documentation.Extensions; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Refactor.Tracking; @@ -20,7 +19,7 @@ IConfigurationContext configurationContext { private readonly ILogger _logger = logFactory.CreateLogger(); - public Task ValidateRedirects(IDiagnosticsCollector collector, string? path, ScopedFileSystem fs) + public Task ValidateRedirects(IDiagnosticsCollector collector, string? path, FileSystem fs) { var runningOnCi = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTIONS")); @@ -39,7 +38,7 @@ public Task ValidateRedirects(IDiagnosticsCollector collector, string? pat return Task.FromResult(false); } - var root = Paths.FindGitRoot(buildContext.DocumentationSourceDirectory); + var root = Paths.DetermineSourceDirectoryRoot(buildContext.DocumentationSourceDirectory); if (root is null) { collector.EmitError(redirectFile.Source, $"Unable to determine the root of the source directory {buildContext.DocumentationSourceDirectory}."); diff --git a/src/services/Elastic.Changelog/Bundling/ChangelogBundleAmendService.cs b/src/services/Elastic.Changelog/Bundling/ChangelogBundleAmendService.cs index ef02dbb697..df79c8099c 100644 --- a/src/services/Elastic.Changelog/Bundling/ChangelogBundleAmendService.cs +++ b/src/services/Elastic.Changelog/Bundling/ChangelogBundleAmendService.cs @@ -6,13 +6,11 @@ using System.IO.Abstractions; using System.Text; using System.Text.RegularExpressions; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.ReleaseNotes; using Elastic.Documentation.Diagnostics; using Elastic.Documentation.ReleaseNotes; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Bundling; @@ -41,10 +39,10 @@ public record AmendBundleArguments /// /// Service for amending changelog bundles with additional entries /// -public partial class ChangelogBundleAmendService(ILoggerFactory logFactory, ScopedFileSystem? fileSystem = null) : IService +public partial class ChangelogBundleAmendService(ILoggerFactory logFactory, IFileSystem? fileSystem = null) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); - private readonly IFileSystem _fileSystem = fileSystem ?? FileSystemFactory.RealRead; + private readonly IFileSystem _fileSystem = fileSystem ?? new FileSystem(); [GeneratedRegex(@"\.amend-(\d+)\.ya?ml$", RegexOptions.IgnoreCase)] private static partial Regex AmendFileRegex(); diff --git a/src/services/Elastic.Changelog/Bundling/ChangelogBundlingService.cs b/src/services/Elastic.Changelog/Bundling/ChangelogBundlingService.cs index e8fe5cdadd..35c194b6c8 100644 --- a/src/services/Elastic.Changelog/Bundling/ChangelogBundlingService.cs +++ b/src/services/Elastic.Changelog/Bundling/ChangelogBundlingService.cs @@ -16,7 +16,6 @@ using Elastic.Documentation.ReleaseNotes; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Bundling; @@ -89,15 +88,15 @@ public record BundleChangelogsArguments public partial class ChangelogBundlingService( ILoggerFactory logFactory, IConfigurationContext? configurationContext = null, - ScopedFileSystem? fileSystem = null, + IFileSystem? fileSystem = null, IGitHubReleaseService? releaseService = null) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); - private readonly ScopedFileSystem _fileSystem = fileSystem ?? FileSystemFactory.RealRead; + private readonly IFileSystem _fileSystem = fileSystem ?? new FileSystem(); private readonly IGitHubReleaseService _releaseService = releaseService ?? new GitHubReleaseService(logFactory); private readonly ChangelogConfigurationLoader? _configLoader = configurationContext != null - ? new ChangelogConfigurationLoader(logFactory, configurationContext, fileSystem ?? FileSystemFactory.RealRead) + ? new ChangelogConfigurationLoader(logFactory, configurationContext, fileSystem ?? new FileSystem()) : null; [GeneratedRegex(@"(\s+)version:", RegexOptions.Multiline)] diff --git a/src/services/Elastic.Changelog/Bundling/ChangelogRemoveService.cs b/src/services/Elastic.Changelog/Bundling/ChangelogRemoveService.cs index 3f66938565..1589c4e418 100644 --- a/src/services/Elastic.Changelog/Bundling/ChangelogRemoveService.cs +++ b/src/services/Elastic.Changelog/Bundling/ChangelogRemoveService.cs @@ -12,7 +12,6 @@ using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Bundling; @@ -63,15 +62,15 @@ public record BundleDependency(string ChangelogFile, string BundleFile); public class ChangelogRemoveService( ILoggerFactory logFactory, IConfigurationContext? configurationContext = null, - ScopedFileSystem? fileSystem = null, + IFileSystem? fileSystem = null, IGitHubReleaseService? releaseService = null) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); - private readonly ScopedFileSystem _fileSystem = fileSystem ?? FileSystemFactory.RealRead; + private readonly IFileSystem _fileSystem = fileSystem ?? new FileSystem(); private readonly IGitHubReleaseService _releaseService = releaseService ?? new GitHubReleaseService(logFactory); private readonly ChangelogConfigurationLoader? _configLoader = configurationContext != null - ? new ChangelogConfigurationLoader(logFactory, configurationContext, fileSystem ?? FileSystemFactory.RealRead) + ? new ChangelogConfigurationLoader(logFactory, configurationContext, fileSystem ?? new FileSystem()) : null; public async Task RemoveChangelogs(IDiagnosticsCollector collector, ChangelogRemoveArguments input, Cancel ctx) diff --git a/src/services/Elastic.Changelog/Bundling/ProfileFilterResolver.cs b/src/services/Elastic.Changelog/Bundling/ProfileFilterResolver.cs index a8b39073ed..a08dced8f8 100644 --- a/src/services/Elastic.Changelog/Bundling/ProfileFilterResolver.cs +++ b/src/services/Elastic.Changelog/Bundling/ProfileFilterResolver.cs @@ -11,7 +11,6 @@ using Elastic.Documentation.ReleaseNotes; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Bundling; @@ -80,7 +79,7 @@ public static partial class ProfileFilterResolver string profileName, string? profileArgument, ChangelogConfiguration? config, - ScopedFileSystem fileSystem, + IFileSystem fileSystem, ILogger? logger, Cancel ctx, string? profileReport = null, @@ -193,7 +192,7 @@ public static partial class ProfileFilterResolver string profileArgument, string profileReport, BundleProfile profile, - ScopedFileSystem fileSystem, + IFileSystem fileSystem, ILogger? logger, Cancel ctx) { @@ -271,7 +270,7 @@ public static partial class ProfileFilterResolver internal static async Task ResolveUrlListFileAsync( IDiagnosticsCollector collector, string filePath, - ScopedFileSystem fileSystem, + IFileSystem fileSystem, Cancel ctx) { var content = await fileSystem.File.ReadAllTextAsync(filePath, ctx); @@ -327,7 +326,7 @@ public static partial class ProfileFilterResolver return hasPrs ? new UrlListFileResult(lines, null) : new UrlListFileResult(null, lines); } - private static ProfileArgumentType DetectLocalFileType(ScopedFileSystem fileSystem, string path) => + private static ProfileArgumentType DetectLocalFileType(IFileSystem fileSystem, string path) => fileSystem.Path.GetExtension(path).ToLowerInvariant() is ".html" or ".htm" ? ProfileArgumentType.PromotionReportFile : ProfileArgumentType.UrlListFile; diff --git a/src/services/Elastic.Changelog/Bundling/PromotionReportParser.cs b/src/services/Elastic.Changelog/Bundling/PromotionReportParser.cs index aeda3acf34..b1ed95d351 100644 --- a/src/services/Elastic.Changelog/Bundling/PromotionReportParser.cs +++ b/src/services/Elastic.Changelog/Bundling/PromotionReportParser.cs @@ -5,20 +5,18 @@ using System.IO.Abstractions; using System.Net.Http.Headers; using System.Text.RegularExpressions; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Bundling; /// /// Parser for promotion report HTML files to extract PR lists /// -public partial class PromotionReportParser(ILoggerFactory logFactory, ScopedFileSystem? fileSystem = null) +public partial class PromotionReportParser(ILoggerFactory logFactory, IFileSystem? fileSystem = null) { private readonly ILogger _logger = logFactory.CreateLogger(); - private readonly IFileSystem _fileSystem = fileSystem ?? FileSystemFactory.RealRead; + private readonly IFileSystem _fileSystem = fileSystem ?? new FileSystem(); private static readonly HttpClient HttpClient = new(); static PromotionReportParser() diff --git a/src/services/Elastic.Changelog/Creation/ChangelogCreationService.cs b/src/services/Elastic.Changelog/Creation/ChangelogCreationService.cs index a1a091db81..2ef0ce90dc 100644 --- a/src/services/Elastic.Changelog/Creation/ChangelogCreationService.cs +++ b/src/services/Elastic.Changelog/Creation/ChangelogCreationService.cs @@ -11,7 +11,6 @@ using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Creation; @@ -62,16 +61,16 @@ public class ChangelogCreationService( ILoggerFactory logFactory, IConfigurationContext configurationContext, IGitHubPrService? githubPrService = null, -ScopedFileSystem? fileSystem = null, +IFileSystem? fileSystem = null, IEnvironmentVariables? env = null ) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); - private readonly ChangelogConfigurationLoader _configLoader = new(logFactory, configurationContext, fileSystem ?? FileSystemFactory.RealRead); + private readonly ChangelogConfigurationLoader _configLoader = new(logFactory, configurationContext, fileSystem ?? new FileSystem()); private readonly CreateChangelogArgumentsValidator _validator = new(configurationContext); private readonly PrInfoProcessor _prProcessor = new(githubPrService, logFactory.CreateLogger()); private readonly IssueInfoProcessor _issueProcessor = new(githubPrService, logFactory.CreateLogger()); - private readonly ChangelogFileWriter _fileWriter = new(fileSystem ?? FileSystemFactory.RealRead, logFactory.CreateLogger()); + private readonly ChangelogFileWriter _fileWriter = new(fileSystem ?? new FileSystem(), logFactory.CreateLogger()); private readonly ProductInferService _productInferService = new( configurationContext.ProductsConfiguration); diff --git a/src/services/Elastic.Changelog/Evaluation/ChangelogPrEvaluationService.cs b/src/services/Elastic.Changelog/Evaluation/ChangelogPrEvaluationService.cs index cc92d1dc51..34f06d539a 100644 --- a/src/services/Elastic.Changelog/Evaluation/ChangelogPrEvaluationService.cs +++ b/src/services/Elastic.Changelog/Evaluation/ChangelogPrEvaluationService.cs @@ -14,7 +14,6 @@ using Elastic.Documentation.ReleaseNotes; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Evaluation; @@ -24,12 +23,12 @@ public class ChangelogPrEvaluationService( IConfigurationContext configurationContext, IGitHubPrService gitHubPrService, ICoreService coreService, - ScopedFileSystem? fileSystem = null + IFileSystem? fileSystem = null ) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); - private readonly IFileSystem _fileSystem = fileSystem ?? FileSystemFactory.RealRead; - private readonly ChangelogConfigurationLoader _configLoader = new(logFactory, configurationContext, fileSystem ?? FileSystemFactory.RealRead); + private readonly IFileSystem _fileSystem = fileSystem ?? new FileSystem(); + private readonly ChangelogConfigurationLoader _configLoader = new(logFactory, configurationContext, fileSystem ?? new FileSystem()); public async Task EvaluatePr(IDiagnosticsCollector collector, EvaluatePrArguments input, Cancel ctx) { diff --git a/src/services/Elastic.Changelog/GithubRelease/GitHubReleaseChangelogService.cs b/src/services/Elastic.Changelog/GithubRelease/GitHubReleaseChangelogService.cs index 95d98324f6..4d07ae3980 100644 --- a/src/services/Elastic.Changelog/GithubRelease/GitHubReleaseChangelogService.cs +++ b/src/services/Elastic.Changelog/GithubRelease/GitHubReleaseChangelogService.cs @@ -15,7 +15,6 @@ using Elastic.Documentation.ReleaseNotes; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.GithubRelease; @@ -69,13 +68,13 @@ public class GitHubReleaseChangelogService( IConfigurationContext configurationContext, IGitHubReleaseService? releaseService = null, IGitHubPrService? prService = null, - ScopedFileSystem? fileSystem = null, + IFileSystem? fileSystem = null, ChangelogBundlingService? bundlingService = null ) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); - private readonly IFileSystem _fileSystem = fileSystem ?? FileSystemFactory.RealRead; - private readonly ChangelogConfigurationLoader _configLoader = new(logFactory, configurationContext, fileSystem ?? FileSystemFactory.RealRead); + private readonly IFileSystem _fileSystem = fileSystem ?? new FileSystem(); + private readonly ChangelogConfigurationLoader _configLoader = new(logFactory, configurationContext, fileSystem ?? new FileSystem()); private readonly IGitHubReleaseService _releaseService = releaseService ?? new GitHubReleaseService(logFactory); private readonly IGitHubPrService _prService = prService ?? new GitHubPrService(logFactory); private readonly ChangelogBundlingService _bundlingService = bundlingService ?? new ChangelogBundlingService(logFactory, configurationContext, fileSystem); diff --git a/src/services/Elastic.Changelog/Rendering/ChangelogRenderer.cs b/src/services/Elastic.Changelog/Rendering/ChangelogRenderer.cs index 2f901c29d4..19b55cb506 100644 --- a/src/services/Elastic.Changelog/Rendering/ChangelogRenderer.cs +++ b/src/services/Elastic.Changelog/Rendering/ChangelogRenderer.cs @@ -6,14 +6,13 @@ using Elastic.Changelog.Rendering.Asciidoc; using Elastic.Changelog.Rendering.Markdown; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Rendering; /// /// Coordinates rendering of changelog output to different formats. /// -public class ChangelogRenderer(ScopedFileSystem fileSystem, ILogger logger) +public class ChangelogRenderer(IFileSystem fileSystem, ILogger logger) { /// /// Renders changelog output based on the specified file type. diff --git a/src/services/Elastic.Changelog/Rendering/ChangelogRenderingService.cs b/src/services/Elastic.Changelog/Rendering/ChangelogRenderingService.cs index 099ea5587b..af1942494c 100644 --- a/src/services/Elastic.Changelog/Rendering/ChangelogRenderingService.cs +++ b/src/services/Elastic.Changelog/Rendering/ChangelogRenderingService.cs @@ -14,7 +14,6 @@ using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; using NetEscapades.EnumGenerators; -using Nullean.ScopedFileSystem; using YamlDotNet.Core; namespace Elastic.Changelog.Rendering; @@ -66,11 +65,11 @@ public enum ChangelogFileType public class ChangelogRenderingService( ILoggerFactory logFactory, IConfigurationContext? configurationContext = null, - ScopedFileSystem? fileSystem = null + IFileSystem? fileSystem = null ) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); - private readonly ScopedFileSystem _fileSystem = fileSystem ?? FileSystemFactory.RealWrite; + private readonly IFileSystem _fileSystem = fileSystem ?? new FileSystem(); public async Task RenderChangelogs( IDiagnosticsCollector collector, diff --git a/src/services/Elastic.Changelog/Rendering/Markdown/BreakingChangesMarkdownRenderer.cs b/src/services/Elastic.Changelog/Rendering/Markdown/BreakingChangesMarkdownRenderer.cs index 7cace43f70..cdaf94fc43 100644 --- a/src/services/Elastic.Changelog/Rendering/Markdown/BreakingChangesMarkdownRenderer.cs +++ b/src/services/Elastic.Changelog/Rendering/Markdown/BreakingChangesMarkdownRenderer.cs @@ -6,7 +6,6 @@ using System.Text; using Elastic.Documentation; using Elastic.Documentation.ReleaseNotes; -using Nullean.ScopedFileSystem; using static System.Globalization.CultureInfo; using static Elastic.Documentation.ChangelogEntryType; @@ -15,7 +14,7 @@ namespace Elastic.Changelog.Rendering.Markdown; /// /// Renderer for the breaking-changes.md changelog file /// -public class BreakingChangesMarkdownRenderer(ScopedFileSystem fileSystem) : MarkdownRendererBase(fileSystem) +public class BreakingChangesMarkdownRenderer(IFileSystem fileSystem) : MarkdownRendererBase(fileSystem) { /// public override string OutputFileName => "breaking-changes.md"; diff --git a/src/services/Elastic.Changelog/Rendering/Markdown/ChangelogMarkdownRenderer.cs b/src/services/Elastic.Changelog/Rendering/Markdown/ChangelogMarkdownRenderer.cs index c57d7b1162..2d512ace8d 100644 --- a/src/services/Elastic.Changelog/Rendering/Markdown/ChangelogMarkdownRenderer.cs +++ b/src/services/Elastic.Changelog/Rendering/Markdown/ChangelogMarkdownRenderer.cs @@ -4,14 +4,13 @@ using System.Collections.Generic; using System.IO.Abstractions; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Rendering.Markdown; /// /// Coordinates rendering of all markdown changelog files. /// -public class ChangelogMarkdownRenderer(ScopedFileSystem fileSystem) +public class ChangelogMarkdownRenderer(IFileSystem fileSystem) { /// /// Renders all markdown changelog files (index, breaking changes, deprecations, known issues, highlights). diff --git a/src/services/Elastic.Changelog/Rendering/Markdown/DeprecationsMarkdownRenderer.cs b/src/services/Elastic.Changelog/Rendering/Markdown/DeprecationsMarkdownRenderer.cs index 78dcf5fbd5..0a31bd1709 100644 --- a/src/services/Elastic.Changelog/Rendering/Markdown/DeprecationsMarkdownRenderer.cs +++ b/src/services/Elastic.Changelog/Rendering/Markdown/DeprecationsMarkdownRenderer.cs @@ -5,7 +5,6 @@ using System.IO.Abstractions; using System.Text; using Elastic.Documentation.ReleaseNotes; -using Nullean.ScopedFileSystem; using static System.Globalization.CultureInfo; using static Elastic.Documentation.ChangelogEntryType; @@ -14,7 +13,7 @@ namespace Elastic.Changelog.Rendering.Markdown; /// /// Renderer for the deprecations.md changelog file /// -public class DeprecationsMarkdownRenderer(ScopedFileSystem fileSystem) : MarkdownRendererBase(fileSystem) +public class DeprecationsMarkdownRenderer(IFileSystem fileSystem) : MarkdownRendererBase(fileSystem) { /// public override string OutputFileName => "deprecations.md"; diff --git a/src/services/Elastic.Changelog/Rendering/Markdown/HighlightsMarkdownRenderer.cs b/src/services/Elastic.Changelog/Rendering/Markdown/HighlightsMarkdownRenderer.cs index f55a3c19a3..f13394286f 100644 --- a/src/services/Elastic.Changelog/Rendering/Markdown/HighlightsMarkdownRenderer.cs +++ b/src/services/Elastic.Changelog/Rendering/Markdown/HighlightsMarkdownRenderer.cs @@ -5,7 +5,6 @@ using System.IO.Abstractions; using System.Text; using Elastic.Documentation.ReleaseNotes; -using Nullean.ScopedFileSystem; using static System.Globalization.CultureInfo; namespace Elastic.Changelog.Rendering.Markdown; @@ -13,7 +12,7 @@ namespace Elastic.Changelog.Rendering.Markdown; /// /// Renderer for the highlights.md changelog file /// -public class HighlightsMarkdownRenderer(ScopedFileSystem fileSystem) : MarkdownRendererBase(fileSystem) +public class HighlightsMarkdownRenderer(IFileSystem fileSystem) : MarkdownRendererBase(fileSystem) { /// public override string OutputFileName => "highlights.md"; diff --git a/src/services/Elastic.Changelog/Rendering/Markdown/IndexMarkdownRenderer.cs b/src/services/Elastic.Changelog/Rendering/Markdown/IndexMarkdownRenderer.cs index e4ec681950..059d5ad120 100644 --- a/src/services/Elastic.Changelog/Rendering/Markdown/IndexMarkdownRenderer.cs +++ b/src/services/Elastic.Changelog/Rendering/Markdown/IndexMarkdownRenderer.cs @@ -5,7 +5,6 @@ using System.IO.Abstractions; using System.Text; using Elastic.Documentation.ReleaseNotes; -using Nullean.ScopedFileSystem; using static System.Globalization.CultureInfo; using static Elastic.Documentation.ChangelogEntryType; @@ -14,7 +13,7 @@ namespace Elastic.Changelog.Rendering.Markdown; /// /// Renderer for the index.md changelog file containing features, enhancements, fixes, docs, regressions, and other changes /// -public class IndexMarkdownRenderer(ScopedFileSystem fileSystem) : MarkdownRendererBase(fileSystem) +public class IndexMarkdownRenderer(IFileSystem fileSystem) : MarkdownRendererBase(fileSystem) { /// public override string OutputFileName => "index.md"; diff --git a/src/services/Elastic.Changelog/Rendering/Markdown/KnownIssuesMarkdownRenderer.cs b/src/services/Elastic.Changelog/Rendering/Markdown/KnownIssuesMarkdownRenderer.cs index a8640f14b3..bddadcf74d 100644 --- a/src/services/Elastic.Changelog/Rendering/Markdown/KnownIssuesMarkdownRenderer.cs +++ b/src/services/Elastic.Changelog/Rendering/Markdown/KnownIssuesMarkdownRenderer.cs @@ -5,7 +5,6 @@ using System.IO.Abstractions; using System.Text; using Elastic.Documentation.ReleaseNotes; -using Nullean.ScopedFileSystem; using static System.Globalization.CultureInfo; using static Elastic.Documentation.ChangelogEntryType; @@ -14,7 +13,7 @@ namespace Elastic.Changelog.Rendering.Markdown; /// /// Renderer for the known-issues.md changelog file /// -public class KnownIssuesMarkdownRenderer(ScopedFileSystem fileSystem) : MarkdownRendererBase(fileSystem) +public class KnownIssuesMarkdownRenderer(IFileSystem fileSystem) : MarkdownRendererBase(fileSystem) { /// public override string OutputFileName => "known-issues.md"; diff --git a/src/services/Elastic.Changelog/Rendering/Markdown/MarkdownRendererBase.cs b/src/services/Elastic.Changelog/Rendering/Markdown/MarkdownRendererBase.cs index bfe20d359a..350bf84af4 100644 --- a/src/services/Elastic.Changelog/Rendering/Markdown/MarkdownRendererBase.cs +++ b/src/services/Elastic.Changelog/Rendering/Markdown/MarkdownRendererBase.cs @@ -5,16 +5,15 @@ using System.IO.Abstractions; using System.Text; using Elastic.Documentation.ReleaseNotes; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Rendering.Markdown; /// /// Abstract base class for changelog markdown renderers /// -public abstract class MarkdownRendererBase(ScopedFileSystem fileSystem) : IChangelogMarkdownRenderer +public abstract class MarkdownRendererBase(IFileSystem fileSystem) : IChangelogMarkdownRenderer { - protected ScopedFileSystem FileSystem { get; } = fileSystem; + protected IFileSystem FileSystem { get; } = fileSystem; /// public abstract string OutputFileName { get; } diff --git a/src/services/Elastic.Documentation.Assembler/AssembleContext.cs b/src/services/Elastic.Documentation.Assembler/AssembleContext.cs index ab7d81b0b9..99ceba0b37 100644 --- a/src/services/Elastic.Documentation.Assembler/AssembleContext.cs +++ b/src/services/Elastic.Documentation.Assembler/AssembleContext.cs @@ -10,14 +10,13 @@ using Elastic.Documentation.Configuration.Search; using Elastic.Documentation.Configuration.Versions; using Elastic.Documentation.Diagnostics; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Assembler; public class AssembleContext : IDocumentationConfigurationContext { - public ScopedFileSystem ReadFileSystem { get; } - public ScopedFileSystem WriteFileSystem { get; } + public IFileSystem ReadFileSystem { get; } + public IFileSystem WriteFileSystem { get; } public IDiagnosticsCollector Collector { get; } @@ -62,8 +61,8 @@ public AssembleContext( IConfigurationContext configurationContext, string environment, IDiagnosticsCollector collector, - ScopedFileSystem readFileSystem, - ScopedFileSystem writeFileSystem, + IFileSystem readFileSystem, + IFileSystem writeFileSystem, string? checkoutDirectory, string? output ) @@ -89,10 +88,10 @@ public AssembleContext( Endpoints.Environment = environment; var contentSource = Environment.ContentSource.ToStringFast(true); - var defaultCheckoutDirectory = Path.Join(Paths.ApplicationData.FullName, "checkouts", contentSource); + var defaultCheckoutDirectory = Path.Join(Paths.GitCommonRoot.FullName, ".artifacts", "checkouts", contentSource); CheckoutDirectory = ReadFileSystem.DirectoryInfo.New(checkoutDirectory ?? defaultCheckoutDirectory); var defaultOutputDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"); - OutputDirectory = WriteFileSystem.DirectoryInfo.New(output ?? defaultOutputDirectory); + OutputDirectory = ReadFileSystem.DirectoryInfo.New(output ?? defaultOutputDirectory); // Calculate the output directory with path prefix once var pathPrefix = Environment.PathPrefix; diff --git a/src/services/Elastic.Documentation.Assembler/Building/AssemblerBuildService.cs b/src/services/Elastic.Documentation.Assembler/Building/AssemblerBuildService.cs index ff62a4d184..3e2e77e6be 100644 --- a/src/services/Elastic.Documentation.Assembler/Building/AssemblerBuildService.cs +++ b/src/services/Elastic.Documentation.Assembler/Building/AssemblerBuildService.cs @@ -15,7 +15,6 @@ using Elastic.Documentation.Navigation.Assembler; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Assembler.Building; @@ -37,7 +36,7 @@ public async Task BuildAll( bool? showHints, IReadOnlySet? exporters, bool? assumeBuild, - ScopedFileSystem fs, + FileSystem fs, Cancel ctx ) { @@ -123,7 +122,7 @@ Cancel ctx await cloner.WriteLinkRegistrySnapshot(checkoutResult.LinkRegistrySnapshot, ctx); var redirectsPath = Path.Join(assembleContext.OutputDirectory.FullName, "redirects.json"); - if (fs.File.Exists(redirectsPath)) + if (File.Exists(redirectsPath)) await githubActionsService.SetOutputAsync("redirects-artifact-path", redirectsPath); if (exporters.Contains(Exporter.Html)) diff --git a/src/services/Elastic.Documentation.Assembler/Building/AssemblerSitemapService.cs b/src/services/Elastic.Documentation.Assembler/Building/AssemblerSitemapService.cs index 84843a2c37..8cd5be0f66 100644 --- a/src/services/Elastic.Documentation.Assembler/Building/AssemblerSitemapService.cs +++ b/src/services/Elastic.Documentation.Assembler/Building/AssemblerSitemapService.cs @@ -11,7 +11,6 @@ using Elastic.Documentation.Services; using Elastic.Markdown.Exporters.Elasticsearch; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Assembler.Building; @@ -26,7 +25,7 @@ ICoreService githubActionsService public async Task GenerateSitemapAsync( IDiagnosticsCollector collector, - ScopedFileSystem fileSystem, + FileSystem fileSystem, string? endpoint = null, string? environment = null, string? apiKey = null, diff --git a/src/services/Elastic.Documentation.Assembler/Configuration/ConfigurationCloneService.cs b/src/services/Elastic.Documentation.Assembler/Configuration/ConfigurationCloneService.cs index 5dc7daf087..621fecaf42 100644 --- a/src/services/Elastic.Documentation.Assembler/Configuration/ConfigurationCloneService.cs +++ b/src/services/Elastic.Documentation.Assembler/Configuration/ConfigurationCloneService.cs @@ -15,7 +15,7 @@ namespace Elastic.Documentation.Assembler.Configuration; public class ConfigurationCloneService( ILoggerFactory logFactory, AssemblyConfiguration assemblyConfiguration, - IFileSystem fs + FileSystem fs ) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); diff --git a/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs b/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs index 7e83293103..2ca860f1ec 100644 --- a/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs +++ b/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs @@ -10,7 +10,6 @@ using Elastic.Documentation.LinkIndex; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Assembler.ContentSources; @@ -19,7 +18,7 @@ public class RepositoryBuildMatchingService( AssemblyConfiguration configuration, IConfigurationContext configurationContext, ICoreService githubActionsService, - ScopedFileSystem fileSystem + FileSystem fileSystem ) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); diff --git a/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryPublishValidationService.cs b/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryPublishValidationService.cs index 8f11b65b68..2499b886ce 100644 --- a/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryPublishValidationService.cs +++ b/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryPublishValidationService.cs @@ -10,7 +10,6 @@ using Elastic.Documentation.LinkIndex; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Assembler.ContentSources; @@ -18,7 +17,7 @@ public class RepositoryPublishValidationService( ILoggerFactory logFactory, AssemblyConfiguration configuration, IConfigurationContext configurationContext, - ScopedFileSystem fileSystem + FileSystem fileSystem ) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); diff --git a/src/services/Elastic.Documentation.Assembler/Deploying/DeployUpdateRedirectsService.cs b/src/services/Elastic.Documentation.Assembler/Deploying/DeployUpdateRedirectsService.cs index 5004d203cf..c1e5675ab3 100644 --- a/src/services/Elastic.Documentation.Assembler/Deploying/DeployUpdateRedirectsService.cs +++ b/src/services/Elastic.Documentation.Assembler/Deploying/DeployUpdateRedirectsService.cs @@ -12,7 +12,7 @@ namespace Elastic.Documentation.Assembler.Deploying; -public class DeployUpdateRedirectsService(ILoggerFactory logFactory, IFileSystem fileSystem) : IService +public class DeployUpdateRedirectsService(ILoggerFactory logFactory, FileSystem fileSystem) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); diff --git a/src/services/Elastic.Documentation.Assembler/Deploying/IncrementalDeployService.cs b/src/services/Elastic.Documentation.Assembler/Deploying/IncrementalDeployService.cs index f161cd50a5..52ac1160e9 100644 --- a/src/services/Elastic.Documentation.Assembler/Deploying/IncrementalDeployService.cs +++ b/src/services/Elastic.Documentation.Assembler/Deploying/IncrementalDeployService.cs @@ -12,7 +12,6 @@ using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Assembler.Deploying; @@ -21,7 +20,7 @@ public class IncrementalDeployService( AssemblyConfiguration assemblyConfiguration, IConfigurationContext configurationContext, ICoreService githubActionsService, - ScopedFileSystem fileSystem + FileSystem fileSystem ) : IService { private readonly ILogger _logger = logFactory.CreateLogger(); diff --git a/src/services/Elastic.Documentation.Assembler/Elastic.Documentation.Assembler.csproj b/src/services/Elastic.Documentation.Assembler/Elastic.Documentation.Assembler.csproj index 82408eef33..175061e07c 100644 --- a/src/services/Elastic.Documentation.Assembler/Elastic.Documentation.Assembler.csproj +++ b/src/services/Elastic.Documentation.Assembler/Elastic.Documentation.Assembler.csproj @@ -15,7 +15,6 @@ - diff --git a/src/services/Elastic.Documentation.Assembler/Indexing/AssemblerIndexService.cs b/src/services/Elastic.Documentation.Assembler/Indexing/AssemblerIndexService.cs index 6076cf7235..50d94e245f 100644 --- a/src/services/Elastic.Documentation.Assembler/Indexing/AssemblerIndexService.cs +++ b/src/services/Elastic.Documentation.Assembler/Indexing/AssemblerIndexService.cs @@ -9,7 +9,6 @@ using Elastic.Documentation.Configuration.Assembler; using Elastic.Documentation.Diagnostics; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; using static Elastic.Documentation.Exporter; namespace Elastic.Documentation.Assembler.Indexing; @@ -53,7 +52,7 @@ IEnvironmentVariables environmentVariables /// /// public async Task Index(IDiagnosticsCollector collector, - ScopedFileSystem fileSystem, + FileSystem fileSystem, string? endpoint = null, string? environment = null, string? apiKey = null, diff --git a/src/services/Elastic.Documentation.Assembler/Navigation/GlobalNavigationService.cs b/src/services/Elastic.Documentation.Assembler/Navigation/GlobalNavigationService.cs index 56da04d68b..5ec78d011b 100644 --- a/src/services/Elastic.Documentation.Assembler/Navigation/GlobalNavigationService.cs +++ b/src/services/Elastic.Documentation.Assembler/Navigation/GlobalNavigationService.cs @@ -9,7 +9,6 @@ using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Services; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Assembler.Navigation; @@ -17,7 +16,7 @@ public class GlobalNavigationService( ILoggerFactory logFactory, AssemblyConfiguration configuration, IConfigurationContext configurationContext, - ScopedFileSystem fileSystem + IFileSystem fileSystem ) : IService { public async Task Validate(IDiagnosticsCollector collector, Cancel ctx) diff --git a/src/services/Elastic.Documentation.Assembler/Sourcing/AssemblerCloneService.cs b/src/services/Elastic.Documentation.Assembler/Sourcing/AssemblerCloneService.cs index f819ebe18a..92501c490f 100644 --- a/src/services/Elastic.Documentation.Assembler/Sourcing/AssemblerCloneService.cs +++ b/src/services/Elastic.Documentation.Assembler/Sourcing/AssemblerCloneService.cs @@ -25,7 +25,7 @@ public async Task CloneAll(IDiagnosticsCollector collector, bool? strict, var githubEnvironmentInput = githubActionsService.GetInput("environment"); environment ??= !string.IsNullOrEmpty(githubEnvironmentInput) ? githubEnvironmentInput : "dev"; - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, environment, collector, fs, fs, null, null); var cloner = new AssemblerRepositorySourcer(logFactory, assembleContext); diff --git a/src/services/Elastic.Documentation.Isolated/IsolatedBuildService.cs b/src/services/Elastic.Documentation.Isolated/IsolatedBuildService.cs index 180e315b37..bff142bfe5 100644 --- a/src/services/Elastic.Documentation.Isolated/IsolatedBuildService.cs +++ b/src/services/Elastic.Documentation.Isolated/IsolatedBuildService.cs @@ -20,7 +20,6 @@ using Elastic.Markdown.IO; using Elastic.Markdown.Page; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; using static System.StringComparison; namespace Elastic.Documentation.Isolated; @@ -44,7 +43,7 @@ public bool IsStrict(bool? strict) public async Task Build( IDiagnosticsCollector collector, - ScopedFileSystem fileSystem, + IFileSystem fileSystem, string? path = null, string? output = null, string? pathPrefix = null, @@ -54,7 +53,7 @@ public async Task Build( bool? metadataOnly = null, IReadOnlySet? exporters = null, string? canonicalBaseUrl = null, - ScopedFileSystem? writeFileSystem = null, + IFileSystem? writeFileSystem = null, bool skipOpenApi = false, bool skipCrossLinks = false, Cancel ctx = default @@ -100,15 +99,11 @@ public async Task Build( // At some point in the future we can remove this try catch catch (Exception e) when (runningOnCi && e.Message.StartsWith("Can not locate docset.yml file in", OrdinalIgnoreCase)) { - // Derive the default output from `path` so it stays within the write FS scope. - // Using Paths.WorkingDirectoryRoot would be wrong when --path points to a different repo. - var rootFolder = !string.IsNullOrWhiteSpace(path) ? path : Paths.WorkingDirectoryRoot.FullName; - var writeFs = writeFileSystem ?? fileSystem; var outputDirectory = !string.IsNullOrWhiteSpace(output) - ? writeFs.DirectoryInfo.New(output) - : writeFs.DirectoryInfo.New(Path.Join(rootFolder, ".artifacts/docs/html")); + ? fileSystem.DirectoryInfo.New(output) + : fileSystem.DirectoryInfo.New(Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts/docs/html")); // we temporarily do not error when pointed to a non-documentation folder. - _ = writeFs.Directory.CreateDirectory(outputDirectory.FullName); + _ = fileSystem.Directory.CreateDirectory(outputDirectory.FullName); _logger.LogInformation("Skipping build as we are running on a merge commit and the docs folder is out of date and has no docset.yml. {Message}", e.Message); @@ -129,7 +124,7 @@ public async Task Build( else { using var codexReader = context.Configuration.Registry != DocSetRegistry.Public - ? new GitLinkIndexReader(context.Configuration.Registry.ToStringFast(true), FileSystemFactory.AppData) + ? new GitLinkIndexReader(context.Configuration.Registry.ToStringFast(true), fileSystem) : null; var crossLinkFetcher = new DocSetConfigurationCrossLinkFetcher( diff --git a/src/services/Elastic.Documentation.Isolated/IsolatedIndexService.cs b/src/services/Elastic.Documentation.Isolated/IsolatedIndexService.cs index b20980e233..0f710c3fd8 100644 --- a/src/services/Elastic.Documentation.Isolated/IsolatedIndexService.cs +++ b/src/services/Elastic.Documentation.Isolated/IsolatedIndexService.cs @@ -7,7 +7,6 @@ using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; using static Elastic.Documentation.Exporter; namespace Elastic.Documentation.Isolated; @@ -50,7 +49,7 @@ IEnvironmentVariables environmentVariables /// /// public async Task Index(IDiagnosticsCollector collector, - ScopedFileSystem fileSystem, + FileSystem fileSystem, string? path = null, string? endpoint = null, string? apiKey = null, diff --git a/src/tooling/docs-builder/Commands/Assembler/AssemblerCommands.cs b/src/tooling/docs-builder/Commands/Assembler/AssemblerCommands.cs index 0fe505e291..831eb5434c 100644 --- a/src/tooling/docs-builder/Commands/Assembler/AssemblerCommands.cs +++ b/src/tooling/docs-builder/Commands/Assembler/AssemblerCommands.cs @@ -63,7 +63,7 @@ static async (s, collector, state, ctx) => await s.CloneAll(collector, state.str ); var buildService = new AssemblerBuildService(logFactory, assemblyConfiguration, configurationContext, githubActionsService, environmentVariables); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); serviceInvoker.AddCommand(buildService, (strict, environment, metadataOnly, showHints, exporters, assumeBuild, fs), strict ?? false, static async (s, collector, state, ctx) => await s.BuildAll(collector, state.strict, state.environment, state.metadataOnly, state.showHints, state.exporters, state.assumeBuild, state.fs, ctx) @@ -141,7 +141,7 @@ public async Task BuildAll( { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var service = new AssemblerBuildService(logFactory, assemblyConfiguration, configurationContext, githubActionsService, environmentVariables); serviceInvoker.AddCommand(service, (strict, environment, assumeBuild, metadataOnly, showHints, exporters, fs), strict ?? false, static async (s, collector, state, ctx) => diff --git a/src/tooling/docs-builder/Commands/Assembler/AssemblerIndexCommand.cs b/src/tooling/docs-builder/Commands/Assembler/AssemblerIndexCommand.cs index 07569a1f3b..21470e3bc3 100644 --- a/src/tooling/docs-builder/Commands/Assembler/AssemblerIndexCommand.cs +++ b/src/tooling/docs-builder/Commands/Assembler/AssemblerIndexCommand.cs @@ -88,7 +88,7 @@ public async Task Index( ) { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var service = new AssemblerIndexService(logFactory, configuration, configurationContext, githubActionsService, environmentVariables); var state = (fs, // endpoint options diff --git a/src/tooling/docs-builder/Commands/Assembler/AssemblerSitemapCommand.cs b/src/tooling/docs-builder/Commands/Assembler/AssemblerSitemapCommand.cs index 810d790035..eefc396f46 100644 --- a/src/tooling/docs-builder/Commands/Assembler/AssemblerSitemapCommand.cs +++ b/src/tooling/docs-builder/Commands/Assembler/AssemblerSitemapCommand.cs @@ -59,7 +59,7 @@ public async Task Sitemap( ) { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var service = new AssemblerSitemapService(logFactory, configuration, configurationContext, githubActionsService); var state = (fs, endpoint, environment, apiKey, username, password, diff --git a/src/tooling/docs-builder/Commands/Assembler/ConfigurationCommands.cs b/src/tooling/docs-builder/Commands/Assembler/ConfigurationCommands.cs index 0cea37f2cb..bb6c9f8602 100644 --- a/src/tooling/docs-builder/Commands/Assembler/ConfigurationCommands.cs +++ b/src/tooling/docs-builder/Commands/Assembler/ConfigurationCommands.cs @@ -28,7 +28,7 @@ public async Task CloneConfigurationFolder(string? gitRef = null, bool loca { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var service = new ConfigurationCloneService(logFactory, assemblyConfiguration, fs); serviceInvoker.AddCommand(service, (gitRef, local), static async (s, collector, state, ctx) => await s.InitConfigurationToApplicationData(collector, state.gitRef, state.local, ctx)); diff --git a/src/tooling/docs-builder/Commands/Assembler/ContentSourceCommands.cs b/src/tooling/docs-builder/Commands/Assembler/ContentSourceCommands.cs index 21080a6fac..f602232a00 100644 --- a/src/tooling/docs-builder/Commands/Assembler/ContentSourceCommands.cs +++ b/src/tooling/docs-builder/Commands/Assembler/ContentSourceCommands.cs @@ -27,7 +27,7 @@ public async Task Validate(Cancel ctx = default) { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var service = new RepositoryPublishValidationService(logFactory, configuration, configurationContext, fs); serviceInvoker.AddCommand(service, static async (s, collector, ctx) => await s.ValidatePublishStatus(collector, ctx)); @@ -43,7 +43,7 @@ public async Task Match([Argument] string? repository = null, [Argument] st { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var service = new RepositoryBuildMatchingService(logFactory, configuration, configurationContext, githubActionsService, fs); serviceInvoker.AddCommand(service, (repository, branchOrTag), static async (s, collector, state, ctx) => diff --git a/src/tooling/docs-builder/Commands/Assembler/DeployCommands.cs b/src/tooling/docs-builder/Commands/Assembler/DeployCommands.cs index daf4eec188..c6a6d40644 100644 --- a/src/tooling/docs-builder/Commands/Assembler/DeployCommands.cs +++ b/src/tooling/docs-builder/Commands/Assembler/DeployCommands.cs @@ -33,7 +33,7 @@ public async Task Plan(string environment, string s3BucketName, string @out { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var service = new IncrementalDeployService(logFactory, assemblyConfiguration, configurationContext, githubActionsService, fs); serviceInvoker.AddCommand(service, (environment, s3BucketName, @out, deleteThreshold), static async (s, collector, state, ctx) => await s.Plan(collector, state.environment, state.s3BucketName, state.@out, state.deleteThreshold, ctx) @@ -51,7 +51,7 @@ public async Task Apply(string environment, string s3BucketName, string pla { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var service = new IncrementalDeployService(logFactory, assemblyConfiguration, configurationContext, githubActionsService, fs); serviceInvoker.AddCommand(service, (environment, s3BucketName, planFile), static async (s, collector, state, ctx) => await s.Apply(collector, state.environment, state.s3BucketName, state.planFile, ctx) @@ -68,7 +68,7 @@ public async Task UpdateRedirects(string environment, string? redirectsFile { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var service = new DeployUpdateRedirectsService(logFactory, fs); serviceInvoker.AddCommand(service, (environment, redirectsFile), static async (s, collector, state, ctx) => await s.UpdateRedirects(collector, state.environment, state.redirectsFile, ctx: ctx) diff --git a/src/tooling/docs-builder/Commands/Assembler/NavigationCommands.cs b/src/tooling/docs-builder/Commands/Assembler/NavigationCommands.cs index d6ca3075f9..59df5cd89a 100644 --- a/src/tooling/docs-builder/Commands/Assembler/NavigationCommands.cs +++ b/src/tooling/docs-builder/Commands/Assembler/NavigationCommands.cs @@ -26,7 +26,7 @@ IConfigurationContext configurationContext public async Task Validate(Cancel ctx = default) { await using var serviceInvoker = new ServiceInvoker(collector); - var service = new GlobalNavigationService(logFactory, configuration, configurationContext, FileSystemFactory.RealRead); + var service = new GlobalNavigationService(logFactory, configuration, configurationContext, new FileSystem()); serviceInvoker.AddCommand(service, static async (s, collector, ctx) => await s.Validate(collector, ctx)); return await serviceInvoker.InvokeAsync(ctx); } @@ -38,7 +38,7 @@ public async Task Validate(Cancel ctx = default) public async Task ValidateLocalLinkReference([Argument] string? file = null, Cancel ctx = default) { await using var serviceInvoker = new ServiceInvoker(collector); - var service = new GlobalNavigationService(logFactory, configuration, configurationContext, FileSystemFactory.RealRead); + var service = new GlobalNavigationService(logFactory, configuration, configurationContext, new FileSystem()); serviceInvoker.AddCommand(service, file, static async (s, collector, file, ctx) => await s.ValidateLocalLinkReference(collector, file, ctx)); return await serviceInvoker.InvokeAsync(ctx); } diff --git a/src/tooling/docs-builder/Commands/ChangelogCommand.cs b/src/tooling/docs-builder/Commands/ChangelogCommand.cs index dd25d02ea3..002a8482e8 100644 --- a/src/tooling/docs-builder/Commands/ChangelogCommand.cs +++ b/src/tooling/docs-builder/Commands/ChangelogCommand.cs @@ -39,7 +39,7 @@ IEnvironmentVariables environmentVariables [GeneratedRegex(@"^( *output_directory:\s*).+$", RegexOptions.Multiline)] private static partial Regex BundleOutputDirectoryRegex(); - private readonly IFileSystem _fileSystem = FileSystemFactory.RealRead; + private readonly IFileSystem _fileSystem = new FileSystem(); private readonly ILogger _logger = logFactory.CreateLogger(); /// /// Changelog commands. Use 'changelog add' to create a new changelog or 'changelog bundle' to create a consolidated list of changelogs. @@ -91,7 +91,7 @@ public Task Init( var useNonDefaultChangelogDir = changelogDir != null; var useNonDefaultBundlesDir = bundlesDir != null; - var repoRoot = Paths.FindGitRoot(docsFolder)?.FullName ?? docsFolder.FullName; + var repoRoot = Paths.DetermineSourceDirectoryRoot(docsFolder)?.FullName ?? docsFolder.FullName; // Create changelog.yml from example if it does not exist if (!_fileSystem.File.Exists(configPath)) @@ -288,7 +288,7 @@ public async Task Create( // Load changelog config and apply fallbacks for all modes. // Precedence: CLI option > bundle section in changelog.yml > built-in default. // This applies to --prs, --issues, and --release-version alike. - var bundleConfig = await new ChangelogConfigurationLoader(logFactory, configurationContext, _fileSystem) + var bundleConfig = await new ChangelogConfigurationLoader(logFactory, configurationContext, new System.IO.Abstractions.FileSystem()) .LoadChangelogConfiguration(collector, config, ctx); var resolvedRepo = !string.IsNullOrWhiteSpace(repo) ? repo : bundleConfig?.Bundle?.Repo; var resolvedOwner = owner ?? bundleConfig?.Bundle?.Owner ?? "elastic"; @@ -542,7 +542,7 @@ public async Task Bundle( } // Precedence: --repo CLI > bundle.repo config; --owner CLI > bundle.owner config > "elastic" - var bundleConfig = await new ChangelogConfigurationLoader(logFactory, configurationContext, _fileSystem) + var bundleConfig = await new ChangelogConfigurationLoader(logFactory, configurationContext, new System.IO.Abstractions.FileSystem()) .LoadChangelogConfiguration(collector, config, ctx); var resolvedRepo = !string.IsNullOrWhiteSpace(repo) ? repo : bundleConfig?.Bundle?.Repo; var resolvedOwner = owner ?? bundleConfig?.Bundle?.Owner ?? "elastic"; @@ -845,7 +845,7 @@ public async Task Remove( } // Precedence: --repo CLI > bundle.repo config; --owner CLI > bundle.owner config > "elastic" - var bundleConfig = await new ChangelogConfigurationLoader(logFactory, configurationContext, _fileSystem) + var bundleConfig = await new ChangelogConfigurationLoader(logFactory, configurationContext, new System.IO.Abstractions.FileSystem()) .LoadChangelogConfiguration(collector, config, ctx); var resolvedRepo = !string.IsNullOrWhiteSpace(repo) ? repo : bundleConfig?.Bundle?.Repo; var resolvedOwner = owner ?? bundleConfig?.Bundle?.Owner ?? "elastic"; @@ -1104,7 +1104,7 @@ public async Task GitHubRelease( await using var serviceInvoker = new ServiceInvoker(collector); // --output CLI > bundle.directory config > ./changelogs (service default) - var bundleConfig = await new ChangelogConfigurationLoader(logFactory, configurationContext, _fileSystem) + var bundleConfig = await new ChangelogConfigurationLoader(logFactory, configurationContext, new System.IO.Abstractions.FileSystem()) .LoadChangelogConfiguration(collector, config, ctx); var resolvedOutput = !string.IsNullOrWhiteSpace(output) ? output : bundleConfig?.Bundle?.Directory; diff --git a/src/tooling/docs-builder/Commands/Codex/CodexCommands.cs b/src/tooling/docs-builder/Commands/Codex/CodexCommands.cs index a5d62a18cb..6f736a25aa 100644 --- a/src/tooling/docs-builder/Commands/Codex/CodexCommands.cs +++ b/src/tooling/docs-builder/Commands/Codex/CodexCommands.cs @@ -51,7 +51,7 @@ public async Task CloneAndBuild( Cancel ctx = default) { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); // Load codex configuration var configPath = fs.Path.GetFullPath(config); @@ -125,7 +125,7 @@ public async Task Clone( Cancel ctx = default) { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var configPath = fs.Path.GetFullPath(config); var configFile = fs.FileInfo.New(configPath); @@ -173,7 +173,7 @@ public async Task Build( Cancel ctx = default) { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var configPath = fs.Path.GetFullPath(config); var configFile = fs.FileInfo.New(configPath); @@ -226,7 +226,7 @@ public async Task Serve( string? path = null, Cancel ctx = default) { - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var servePath = path ?? fs.Path.Join( Environment.CurrentDirectory, ".artifacts", "codex", "docs"); diff --git a/src/tooling/docs-builder/Commands/Codex/CodexIndexCommand.cs b/src/tooling/docs-builder/Commands/Codex/CodexIndexCommand.cs index 65d2b08ea9..c3e638b836 100644 --- a/src/tooling/docs-builder/Commands/Codex/CodexIndexCommand.cs +++ b/src/tooling/docs-builder/Commands/Codex/CodexIndexCommand.cs @@ -94,7 +94,7 @@ public async Task Index( ) { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var configPath = fs.Path.GetFullPath(config); var configFile = fs.FileInfo.New(configPath); diff --git a/src/tooling/docs-builder/Commands/Codex/CodexUpdateRedirectsCommand.cs b/src/tooling/docs-builder/Commands/Codex/CodexUpdateRedirectsCommand.cs index d888afcfc7..3b8e3ec3d5 100644 --- a/src/tooling/docs-builder/Commands/Codex/CodexUpdateRedirectsCommand.cs +++ b/src/tooling/docs-builder/Commands/Codex/CodexUpdateRedirectsCommand.cs @@ -5,7 +5,6 @@ using System.IO.Abstractions; using ConsoleAppFramework; using Elastic.Documentation.Assembler.Deploying; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.Codex; using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Services; @@ -35,7 +34,7 @@ public async Task Run( { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealRead; + var fs = new FileSystem(); var configPath = fs.Path.GetFullPath(config); var configFile = fs.FileInfo.New(configPath); diff --git a/src/tooling/docs-builder/Commands/DiffCommands.cs b/src/tooling/docs-builder/Commands/DiffCommands.cs index c3d1d01097..895040cf8e 100644 --- a/src/tooling/docs-builder/Commands/DiffCommands.cs +++ b/src/tooling/docs-builder/Commands/DiffCommands.cs @@ -29,7 +29,7 @@ public async Task ValidateRedirects(string? path = null, Cancel ctx = defau await using var serviceInvoker = new ServiceInvoker(collector); var service = new LocalChangeTrackingService(logFactory, configurationContext); - var fs = FileSystemFactory.RealGitRootForPath(path); + var fs = new FileSystem(); serviceInvoker.AddCommand(service, (path, fs), async static (s, collector, state, _) => await s.ValidateRedirects(collector, state.path, state.fs) diff --git a/src/tooling/docs-builder/Commands/FormatCommand.cs b/src/tooling/docs-builder/Commands/FormatCommand.cs index 2849bd3901..7672c74583 100644 --- a/src/tooling/docs-builder/Commands/FormatCommand.cs +++ b/src/tooling/docs-builder/Commands/FormatCommand.cs @@ -43,7 +43,7 @@ public async Task Format( await using var serviceInvoker = new ServiceInvoker(collector); var service = new FormatService(logFactory, configurationContext); - var fs = FileSystemFactory.RealGitRootForPath(path); + var fs = new FileSystem(); serviceInvoker.AddCommand(service, (path, check, fs), async static (s, collector, state, ctx) => await s.Format(collector, state.path, state.check, state.fs, ctx) diff --git a/src/tooling/docs-builder/Commands/InboundLinkCommands.cs b/src/tooling/docs-builder/Commands/InboundLinkCommands.cs index 1bdc3220a7..65e20a419d 100644 --- a/src/tooling/docs-builder/Commands/InboundLinkCommands.cs +++ b/src/tooling/docs-builder/Commands/InboundLinkCommands.cs @@ -4,7 +4,6 @@ using System.IO.Abstractions; using ConsoleAppFramework; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Links.InboundLinks; using Elastic.Documentation.Services; @@ -14,7 +13,7 @@ namespace Documentation.Builder.Commands; internal sealed class InboundLinkCommands(ILoggerFactory logFactory, IDiagnosticsCollector collector) { - private readonly LinkIndexService _linkIndexService = new(logFactory, FileSystemFactory.RealRead); + private readonly LinkIndexService _linkIndexService = new(logFactory, new FileSystem()); /// Validate all published cross_links in all published links.json files. /// diff --git a/src/tooling/docs-builder/Commands/IndexCommand.cs b/src/tooling/docs-builder/Commands/IndexCommand.cs index 556489eb0f..d7c27ea86b 100644 --- a/src/tooling/docs-builder/Commands/IndexCommand.cs +++ b/src/tooling/docs-builder/Commands/IndexCommand.cs @@ -86,7 +86,7 @@ public async Task Index( ) { await using var serviceInvoker = new ServiceInvoker(collector); - var fs = FileSystemFactory.RealGitRootForPath(path); + var fs = new FileSystem(); var service = new IsolatedIndexService(logFactory, configurationContext, githubActionsService, environmentVariables); var state = (fs, path, // endpoint options diff --git a/src/tooling/docs-builder/Commands/IsolatedBuildCommand.cs b/src/tooling/docs-builder/Commands/IsolatedBuildCommand.cs index a1474e3505..4b84218ec3 100644 --- a/src/tooling/docs-builder/Commands/IsolatedBuildCommand.cs +++ b/src/tooling/docs-builder/Commands/IsolatedBuildCommand.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; using Actions.Core.Services; using ConsoleAppFramework; using Documentation.Builder.Arguments; @@ -62,17 +63,15 @@ public async Task Build( await using var serviceInvoker = new ServiceInvoker(collector); var service = new IsolatedBuildService(logFactory, configurationContext, githubActionsService, environmentVariables); - var readFs = inMemory ? FileSystemFactory.InMemory() : FileSystemFactory.RealGitRootForPath(path); - // For real builds supply an explicit write FS without .git access; for in-memory null falls back to readFs - var writeFs = inMemory ? null : FileSystemFactory.RealGitRootForPathWrite(path, output); + IFileSystem fs = inMemory ? new MockFileSystem() : new FileSystem(); var strictCommand = service.IsStrict(strict); serviceInvoker.AddCommand(service, - (path, output, pathPrefix, force, strict, allowIndexing, metadataOnly, exporters, canonicalBaseUrl, readFs, writeFs, skipApi), strictCommand, + (path, output, pathPrefix, force, strict, allowIndexing, metadataOnly, exporters, canonicalBaseUrl, fs, skipApi), strictCommand, async static (s, collector, state, ctx) => await s.Build( - collector, state.readFs, state.path, state.output, state.pathPrefix, + collector, state.fs, state.path, state.output, state.pathPrefix, state.force, state.strict, state.allowIndexing, state.metadataOnly, - state.exporters, state.canonicalBaseUrl, state.writeFs, state.skipApi, false, ctx + state.exporters, state.canonicalBaseUrl, null, state.skipApi, false, ctx ) ); return await serviceInvoker.InvokeAsync(ctx); diff --git a/src/tooling/docs-builder/Commands/MoveCommand.cs b/src/tooling/docs-builder/Commands/MoveCommand.cs index 540e7da3a7..2ce50e6afd 100644 --- a/src/tooling/docs-builder/Commands/MoveCommand.cs +++ b/src/tooling/docs-builder/Commands/MoveCommand.cs @@ -38,7 +38,7 @@ public async Task Move( await using var serviceInvoker = new ServiceInvoker(collector); var service = new MoveFileService(logFactory, configurationContext); - var fs = FileSystemFactory.RealGitRootForPath(path); + var fs = new FileSystem(); serviceInvoker.AddCommand(service, (source, target, dryRun, path, fs), async static (s, collector, state, ctx) => await s.Move(collector, state.source, state.target, state.dryRun, state.path, state.fs, ctx) diff --git a/src/tooling/docs-builder/Commands/ServeCommand.cs b/src/tooling/docs-builder/Commands/ServeCommand.cs index 6b3b3ba883..afc2b1e066 100644 --- a/src/tooling/docs-builder/Commands/ServeCommand.cs +++ b/src/tooling/docs-builder/Commands/ServeCommand.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; using ConsoleAppFramework; using Documentation.Builder.Http; using Elastic.Documentation.Configuration; @@ -27,7 +28,7 @@ internal sealed class ServeCommand(ILoggerFactory logFactory, IConfigurationCont [Command("")] public async Task Serve(string? path = null, int port = 3000, bool watch = false, Cancel ctx = default) { - var host = new DocumentationWebHost(logFactory, path, port, FileSystemFactory.RealGitRootForPath(path), FileSystemFactory.InMemory(), configurationContext, watch); + var host = new DocumentationWebHost(logFactory, path, port, new FileSystem(), new MockFileSystem(), configurationContext, watch); await host.RunAsync(ctx); _logger.LogInformation("Find your documentation at http://localhost:{Port}/{Path}", port, host.GeneratorState.Generator.DocumentationSet.FirstInterestingUrl.TrimStart('/') diff --git a/src/tooling/docs-builder/Filters/CheckForUpdatesFilter.cs b/src/tooling/docs-builder/Filters/CheckForUpdatesFilter.cs index 23eb693ad2..0a246d3090 100644 --- a/src/tooling/docs-builder/Filters/CheckForUpdatesFilter.cs +++ b/src/tooling/docs-builder/Filters/CheckForUpdatesFilter.cs @@ -2,7 +2,6 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information -using System.IO.Abstractions; using System.Reflection; using ConsoleAppFramework; using Elastic.Documentation; @@ -12,9 +11,7 @@ namespace Documentation.Builder.Filters; internal sealed class CheckForUpdatesFilter(ConsoleAppFilter next, GlobalCliArgs cli) : ConsoleAppFilter(next) { - // Only accesses ApplicationData — no workspace access needed - private static readonly IFileSystem Fs = FileSystemFactory.AppData; - private readonly IFileInfo _stateFile = Fs.FileInfo.New(Path.Join(Paths.ApplicationData.FullName, "docs-build-check.state")); + private readonly FileInfo _stateFile = new(Path.Join(Paths.ApplicationData.FullName, "docs-build-check.state")); public override async Task InvokeAsync(ConsoleAppContext context, Cancel ctx) { @@ -66,7 +63,7 @@ private static void CompareWithAssemblyVersion(Uri latestVersionUrl) // only check for new versions once per hour if (_stateFile.Exists && _stateFile.LastWriteTimeUtc >= DateTime.UtcNow.Subtract(TimeSpan.FromHours(1))) { - var url = await Fs.File.ReadAllTextAsync(_stateFile.FullName, ctx); + var url = await File.ReadAllTextAsync(_stateFile.FullName, ctx); if (Uri.TryCreate(url, UriKind.Absolute, out var uri)) return uri; } @@ -79,9 +76,9 @@ private static void CompareWithAssemblyVersion(Uri latestVersionUrl) if (redirectUrl is not null && _stateFile.Directory is not null) { // ensure the 'elastic' folder exists. - if (!Fs.Directory.Exists(_stateFile.Directory.FullName)) - _ = Fs.Directory.CreateDirectory(_stateFile.Directory.FullName); - await Fs.File.WriteAllTextAsync(_stateFile.FullName, redirectUrl.ToString(), ctx); + if (!Directory.Exists(_stateFile.Directory.FullName)) + _ = Directory.CreateDirectory(_stateFile.Directory.FullName); + await File.WriteAllTextAsync(_stateFile.FullName, redirectUrl.ToString(), ctx); } return redirectUrl; } diff --git a/src/tooling/docs-builder/Http/DocumentationWebHost.cs b/src/tooling/docs-builder/Http/DocumentationWebHost.cs index 9fe23eda14..d85303c585 100644 --- a/src/tooling/docs-builder/Http/DocumentationWebHost.cs +++ b/src/tooling/docs-builder/Http/DocumentationWebHost.cs @@ -4,7 +4,6 @@ using System.IO.Abstractions; using System.Net; -using Nullean.ScopedFileSystem; using System.Runtime.InteropServices; using System.Text; using System.Text.Json; @@ -35,15 +34,15 @@ public class DocumentationWebHost private readonly WebApplication _webApplication; private readonly IHostedService _hostedService; - private readonly ScopedFileSystem _writeFileSystem; + private readonly IFileSystem _writeFileSystem; public InMemoryBuildState InMemoryBuildState { get; } public DocumentationWebHost(ILoggerFactory logFactory, string? path, int port, - ScopedFileSystem readFs, - ScopedFileSystem writeFs, + IFileSystem readFs, + IFileSystem writeFs, IConfigurationContext configurationContext, bool isWatchBuild ) diff --git a/src/tooling/docs-builder/Http/InMemoryBuildState.cs b/src/tooling/docs-builder/Http/InMemoryBuildState.cs index 43154396c9..cced222bc1 100644 --- a/src/tooling/docs-builder/Http/InMemoryBuildState.cs +++ b/src/tooling/docs-builder/Http/InMemoryBuildState.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; using System.Text.Json.Serialization; using System.Threading.Channels; using Actions.Core; @@ -14,7 +15,6 @@ using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Isolated; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Documentation.Builder.Http; @@ -54,7 +54,7 @@ public class InMemoryBuildState(ILoggerFactory loggerFactory, IConfigurationCont private readonly List _diagnostics = []; // Reuse MockFileSystem across builds to benefit from caching - private readonly ScopedFileSystem _writeFs = FileSystemFactory.InMemory(); + private readonly MockFileSystem _writeFs = new(); // Broadcast: maintain list of connected client channels private readonly Lock _clientsLock = new(); @@ -169,7 +169,7 @@ private async Task ExecuteBuildAsync(string sourcePath, Cancel ct) // Create a diagnostics collector that streams to our channel var streamingCollector = new StreamingDiagnosticsCollector(_loggerFactory, this); - var readFs = FileSystemFactory.RealGitRootForPath(sourcePath); + var readFs = new FileSystem(); var service = new IsolatedBuildService(_loggerFactory, _configurationContext, new NullCoreService(), SystemEnvironmentVariables.Instance); _logger.LogInformation("Starting in-memory validation build for {Path}", sourcePath); diff --git a/src/tooling/docs-builder/Http/ReloadableGeneratorState.cs b/src/tooling/docs-builder/Http/ReloadableGeneratorState.cs index 104e0aa740..5f9ac5a992 100644 --- a/src/tooling/docs-builder/Http/ReloadableGeneratorState.cs +++ b/src/tooling/docs-builder/Http/ReloadableGeneratorState.cs @@ -45,7 +45,7 @@ bool isWatchBuild ApiPath = context.WriteFileSystem.DirectoryInfo.New(Path.Join(outputPath.FullName, "api")); if (context.Configuration.Registry != DocSetRegistry.Public) - _codexReader = new GitLinkIndexReader(context.Configuration.Registry.ToStringFast(true), FileSystemFactory.AppData); + _codexReader = new GitLinkIndexReader(context.Configuration.Registry.ToStringFast(true), context.ReadFileSystem); _crossLinkFetcher = new DocSetConfigurationCrossLinkFetcher(logFactory, _context.Configuration, codexLinkIndexReader: _codexReader); // we pass NoopCrossLinkResolver.Instance here because `ReloadAsync` will always be called when the is started. diff --git a/src/tooling/docs-builder/Http/StaticWebHost.cs b/src/tooling/docs-builder/Http/StaticWebHost.cs index 36950e2d28..9aa420920b 100644 --- a/src/tooling/docs-builder/Http/StaticWebHost.cs +++ b/src/tooling/docs-builder/Http/StaticWebHost.cs @@ -25,7 +25,7 @@ public class StaticWebHost public StaticWebHost(int port, string? path) { _contentRoot = path ?? Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"); - var fs = FileSystemFactory.RealGitRootForPath(path); + var fs = new FileSystem(); var dir = fs.DirectoryInfo.New(_contentRoot); if (!dir.Exists) throw new Exception($"Can not serve empty directory: {_contentRoot}"); diff --git a/tests-integration/Elastic.Assembler.IntegrationTests/AssemblerConfigurationTests.cs b/tests-integration/Elastic.Assembler.IntegrationTests/AssemblerConfigurationTests.cs index 61775c3e74..9b0581b53c 100644 --- a/tests-integration/Elastic.Assembler.IntegrationTests/AssemblerConfigurationTests.cs +++ b/tests-integration/Elastic.Assembler.IntegrationTests/AssemblerConfigurationTests.cs @@ -9,7 +9,6 @@ using Elastic.Documentation.Configuration.Assembler; using Elastic.Documentation.Diagnostics; using Microsoft.Extensions.Logging.Abstractions; -using Nullean.ScopedFileSystem; namespace Elastic.Assembler.IntegrationTests; @@ -29,8 +28,7 @@ public PublicOnlyAssemblerConfigurationTests() var configurationFileProvider = new ConfigurationFileProvider(NullLoggerFactory.Instance, FileSystem, skipPrivateRepositories: true); var configurationContext = TestHelpers.CreateConfigurationContext(FileSystem, configurationFileProvider: configurationFileProvider); var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); - var scopedFs = FileSystemFactory.ScopeCurrentWorkingDirectory(FileSystem); - Context = new AssembleContext(config, configurationContext, "dev", Collector, scopedFs, scopedFs, CheckoutDirectory.FullName, null); + Context = new AssembleContext(config, configurationContext, "dev", Collector, FileSystem, FileSystem, CheckoutDirectory.FullName, null); } [Fact] @@ -66,8 +64,7 @@ public AssemblerConfigurationTests(DocumentationFixture fixture, ITestOutputHelp Collector = new DiagnosticsCollector([]); var configurationContext = TestHelpers.CreateConfigurationContext(FileSystem); var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); - var scopedFs = FileSystemFactory.ScopeCurrentWorkingDirectory(FileSystem); - Context = new AssembleContext(config, configurationContext, "dev", Collector, scopedFs, scopedFs, CheckoutDirectory.FullName, null); + Context = new AssembleContext(config, configurationContext, "dev", Collector, FileSystem, FileSystem, CheckoutDirectory.FullName, null); } [Fact] diff --git a/tests-integration/Elastic.Assembler.IntegrationTests/DocsSyncTests.cs b/tests-integration/Elastic.Assembler.IntegrationTests/DocsSyncTests.cs index cb8525a4d6..4b6d0750db 100644 --- a/tests-integration/Elastic.Assembler.IntegrationTests/DocsSyncTests.cs +++ b/tests-integration/Elastic.Assembler.IntegrationTests/DocsSyncTests.cs @@ -16,7 +16,6 @@ using Elastic.Documentation.ServiceDefaults.Telemetry; using FakeItEasy; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; using OpenTelemetry; using OpenTelemetry.Trace; @@ -40,14 +39,12 @@ public async Task TestPlan() { "docs/update.md", new MockFileData("# Existing Document") }, }, new MockFileSystemOptions { - CurrentDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"), + CurrentDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly") }); var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem); var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); - var scopedFs = FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem); - var scopedWriteFs = FileSystemFactory.ScopeCurrentWorkingDirectoryForWrite(fileSystem); - var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFs, scopedWriteFs, null, Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly")); + var context = new AssembleContext(config, configurationContext, "dev", collector, fileSystem, fileSystem, null, Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly")); A.CallTo(() => mockS3Client.ListObjectsV2Async(A._, A._)) .Returns(new ListObjectsV2Response { @@ -181,16 +178,14 @@ bool valid var mockS3Client = A.Fake(); var fileSystem = new MockFileSystem(new MockFileSystemOptions { - CurrentDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"), + CurrentDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly") }); foreach (var i in Enumerable.Range(0, localFiles)) fileSystem.AddFile($"docs/file-{i}.md", new MockFileData($"# Local Document {i}")); var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem); var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); - var scopedFs2 = FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem); - var scopedWriteFs2 = FileSystemFactory.ScopeCurrentWorkingDirectoryForWrite(fileSystem); - var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFs2, scopedWriteFs2, null, Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly")); + var context = new AssembleContext(config, configurationContext, "dev", collector, fileSystem, fileSystem, null, Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly")); var s3Objects = new List(); foreach (var i in Enumerable.Range(0, remoteFiles)) @@ -235,14 +230,12 @@ public async Task TestApply() { "docs/update.md", new MockFileData("# Existing Document") }, }, new MockFileSystemOptions { - CurrentDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"), + CurrentDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly") }); var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem); var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); var checkoutDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"); - var scopedFs3 = FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem); - var scopedWriteFs3 = FileSystemFactory.ScopeCurrentWorkingDirectoryForWrite(fileSystem); - var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFs3, scopedWriteFs3, null, checkoutDirectory); + var context = new AssembleContext(config, configurationContext, "dev", collector, fileSystem, fileSystem, null, checkoutDirectory); var plan = new SyncPlan { RemoteListingCompleted = true, diff --git a/tests-integration/Elastic.Assembler.IntegrationTests/NavigationBuildingTests.cs b/tests-integration/Elastic.Assembler.IntegrationTests/NavigationBuildingTests.cs index 7f7276a627..64e26b91af 100644 --- a/tests-integration/Elastic.Assembler.IntegrationTests/NavigationBuildingTests.cs +++ b/tests-integration/Elastic.Assembler.IntegrationTests/NavigationBuildingTests.cs @@ -21,7 +21,6 @@ using Elastic.Documentation.Site.Navigation; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Nullean.ScopedFileSystem; using RazorSlices; namespace Elastic.Assembler.IntegrationTests; @@ -47,7 +46,7 @@ public async Task AssertRealNavigation() var assemblyConfiguration = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); var collector = new TestDiagnosticsCollector(TestContext.Current.TestOutputHelper); var fs = new FileSystem(); - var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, "dev", collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fs), FileSystemFactory.ScopeCurrentWorkingDirectory(new MockFileSystem()), null, null); + var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, "dev", collector, fs, new MockFileSystem(), null, null); var logFactory = new TestLoggerFactory(TestContext.Current.TestOutputHelper); var cloner = new AssemblerRepositorySourcer(logFactory, assembleContext); var checkoutResult = cloner.GetAll(); diff --git a/tests-integration/Elastic.Assembler.IntegrationTests/NavigationRootTests.cs b/tests-integration/Elastic.Assembler.IntegrationTests/NavigationRootTests.cs index 9db9a751e8..35dcbda1fc 100644 --- a/tests-integration/Elastic.Assembler.IntegrationTests/NavigationRootTests.cs +++ b/tests-integration/Elastic.Assembler.IntegrationTests/NavigationRootTests.cs @@ -21,7 +21,6 @@ using Elastic.Documentation.Site.Navigation; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Nullean.ScopedFileSystem; using RazorSlices; namespace Elastic.Assembler.IntegrationTests; @@ -47,7 +46,7 @@ public async Task AssertRealNavigation() var assemblyConfiguration = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); var collector = new TestDiagnosticsCollector(TestContext.Current.TestOutputHelper); var fs = new FileSystem(); - var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, "dev", collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fs), FileSystemFactory.ScopeCurrentWorkingDirectory(new MockFileSystem()), null, null); + var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, "dev", collector, fs, new MockFileSystem(), null, null); var logFactory = new TestLoggerFactory(TestContext.Current.TestOutputHelper); var cloner = new AssemblerRepositorySourcer(logFactory, assembleContext); var checkoutResult = cloner.GetAll(); diff --git a/tests-integration/Elastic.Assembler.IntegrationTests/SiteNavigationTests.cs b/tests-integration/Elastic.Assembler.IntegrationTests/SiteNavigationTests.cs index d89cd503a7..a47e727e68 100644 --- a/tests-integration/Elastic.Assembler.IntegrationTests/SiteNavigationTests.cs +++ b/tests-integration/Elastic.Assembler.IntegrationTests/SiteNavigationTests.cs @@ -15,7 +15,6 @@ using Elastic.Documentation.Navigation.Assembler; using Elastic.Markdown.IO; using Microsoft.Extensions.Logging.Abstractions; -using Nullean.ScopedFileSystem; namespace Elastic.Assembler.IntegrationTests; @@ -44,8 +43,7 @@ public SiteNavigationTests(DocumentationFixture fixture, ITestOutputHelper outpu Collector = new DiagnosticsCollector([]); var configurationContext = TestHelpers.CreateConfigurationContext(FileSystem); var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); - var scopedFs = FileSystemFactory.ScopeCurrentWorkingDirectory(FileSystem); - Context = new AssembleContext(config, configurationContext, "dev", Collector, scopedFs, scopedFs, CheckoutDirectory.FullName, null); + Context = new AssembleContext(config, configurationContext, "dev", Collector, FileSystem, FileSystem, CheckoutDirectory.FullName, null); } private Checkout CreateCheckout(IFileSystem fs, Repository repository) @@ -98,8 +96,7 @@ public async Task ReadAllPathPrefixes() var fileSystem = new FileSystem(); var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem); var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); - var scopedFileSystem = FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem); - var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFileSystem, scopedFileSystem, null, null); + var context = new AssembleContext(config, configurationContext, "dev", collector, fileSystem, fileSystem, null, null); var navigationFileInfo = configurationContext.ConfigurationFileProvider.NavigationFile; var siteNavigationFile = SiteNavigationFile.Deserialize(await FileSystem.File.ReadAllTextAsync(navigationFileInfo.FullName, TestContext.Current.CancellationToken)); @@ -191,8 +188,7 @@ public async Task UriResolving() var fs = new FileSystem(); var configurationContext = TestHelpers.CreateConfigurationContext(fs); var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider); - var scopedFs = FileSystemFactory.ScopeCurrentWorkingDirectory(fs); - var assembleContext = new AssembleContext(config, configurationContext, "prod", collector, scopedFs, scopedFs, null, null); + var assembleContext = new AssembleContext(config, configurationContext, "prod", collector, fs, fs, null, null); var repos = assembleContext.Configuration.AvailableRepositories .Where(kv => !kv.Value.Skip) .Select(kv => kv.Value) @@ -227,7 +223,7 @@ public ValueTask DisposeAsync() GC.SuppressFinalize(this); if (TestContext.Current.TestState?.Result is TestResult.Passed) return default; - foreach (var resource in _fixture.InMemoryLogger.RecordedLogs.ToList()) + foreach (var resource in _fixture.InMemoryLogger.RecordedLogs) _output.WriteLine(resource.Message); return default; } diff --git a/tests/Elastic.ApiExplorer.Tests/Elastic.ApiExplorer.Tests.csproj b/tests/Elastic.ApiExplorer.Tests/Elastic.ApiExplorer.Tests.csproj index 047a2e7df2..f326f6d0cf 100644 --- a/tests/Elastic.ApiExplorer.Tests/Elastic.ApiExplorer.Tests.csproj +++ b/tests/Elastic.ApiExplorer.Tests/Elastic.ApiExplorer.Tests.csproj @@ -9,8 +9,4 @@ - - - - diff --git a/tests/Elastic.ApiExplorer.Tests/ReaderTests.cs b/tests/Elastic.ApiExplorer.Tests/ReaderTests.cs index 7b7946c0a8..5decade2f6 100644 --- a/tests/Elastic.ApiExplorer.Tests/ReaderTests.cs +++ b/tests/Elastic.ApiExplorer.Tests/ReaderTests.cs @@ -8,7 +8,6 @@ using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; using Microsoft.Extensions.Logging.Abstractions; -using Nullean.ScopedFileSystem; namespace Elastic.ApiExplorer.Tests; @@ -20,7 +19,7 @@ public async Task Reads() { var collector = new DiagnosticsCollector([]); var configurationContext = TestHelpers.CreateConfigurationContext(new FileSystem()); - var context = new BuildContext(collector, FileSystemFactory.RealRead, configurationContext); + var context = new BuildContext(collector, new FileSystem(), configurationContext); context.Configuration.OpenApiSpecifications.Should().NotBeNull().And.NotBeEmpty(); @@ -35,7 +34,7 @@ public async Task Navigation() { var collector = new DiagnosticsCollector([]); var configurationContext = TestHelpers.CreateConfigurationContext(new FileSystem()); - var context = new BuildContext(collector, FileSystemFactory.RealRead, configurationContext); + var context = new BuildContext(collector, new FileSystem(), configurationContext); var generator = new OpenApiGenerator(NullLoggerFactory.Instance, context, NoopMarkdownStringRenderer.Instance); context.Configuration.OpenApiSpecifications.Should().NotBeNull().And.NotBeEmpty(); diff --git a/tests/Elastic.Changelog.Tests/Changelogs/BundleAmendTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/BundleAmendTests.cs index 13f6cbb465..78eb99c0c2 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/BundleAmendTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/BundleAmendTests.cs @@ -4,7 +4,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.ReleaseNotes; namespace Elastic.Changelog.Tests.Changelogs; @@ -24,7 +23,7 @@ public BundleAmendTests(ITestOutputHelper output) : base(output) private string CreateChangelogDir() { - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); return changelogDir; } @@ -49,7 +48,7 @@ private async Task CreateResolvedBundle(CancellationToken ct) var changelogFile = FileSystem.Path.Join(_changelogDir, "1755268130-existing.yaml"); await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, ct); - var bundlePath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var bundlePath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); var input = new BundleChangelogsArguments { Directory = _changelogDir, @@ -88,7 +87,7 @@ private async Task CreateUnresolvedBundle(CancellationToken ct) var changelogFile = FileSystem.Path.Join(_changelogDir, "1755268130-existing.yaml"); await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, ct); - var bundlePath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var bundlePath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); var input = new BundleChangelogsArguments { Directory = _changelogDir, @@ -113,7 +112,7 @@ private async Task CreateUnresolvedBundle(CancellationToken ct) /// private async Task CreateNewChangelogFile(CancellationToken ct) { - var newDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var newDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(newDir); // language=yaml diff --git a/tests/Elastic.Changelog.Tests/Changelogs/BundleChangelogsTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/BundleChangelogsTests.cs index d508f5271f..bd2d9eebf9 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/BundleChangelogsTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/BundleChangelogsTests.cs @@ -5,7 +5,6 @@ using System.Text; using AwesomeAssertions; using Elastic.Changelog.Bundling; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; namespace Elastic.Changelog.Tests.Changelogs; @@ -25,7 +24,7 @@ public BundleChangelogsTests(ITestOutputHelper output) : base(output) private string CreateChangelogDir() { - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); return changelogDir; } @@ -66,7 +65,7 @@ public async Task BundleChangelogs_WithAllOption_CreatesValidBundle() { Directory = _changelogDir, All = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -126,7 +125,7 @@ public async Task BundleChangelogs_WithProductsFilter_FiltersCorrectly() { Directory = _changelogDir, InputProducts = [new ProductArgument { Product = "elasticsearch", Target = "9.2.0", Lifecycle = "ga" }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -193,7 +192,7 @@ public async Task BundleChangelogs_WithPrsFilter_FiltersCorrectly() { Directory = _changelogDir, Prs = ["https://github.com/elastic/elasticsearch/pull/100", "https://github.com/elastic/elasticsearch/pull/200"], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -258,7 +257,7 @@ public async Task BundleChangelogs_WithIssuesFilter_FiltersCorrectly() { Directory = _changelogDir, Issues = ["https://github.com/elastic/elasticsearch/issues/100", "https://github.com/elastic/elasticsearch/issues/200"], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -296,7 +295,7 @@ public async Task BundleChangelogs_WithOldPrFormat_StillMatchesWhenFilteringByPr { Directory = _changelogDir, Prs = ["https://github.com/elastic/elasticsearch/pull/999"], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; var result = await Service.BundleChangelogs(Collector, input, TestContext.Current.CancellationToken); @@ -337,7 +336,7 @@ public async Task BundleChangelogs_WithPrsFilterAndUnmatchedPrs_EmitsWarnings() "https://github.com/elastic/elasticsearch/pull/200", "https://github.com/elastic/elasticsearch/pull/300" ], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -389,7 +388,7 @@ public async Task BundleChangelogs_WithPrsFileFilter_FiltersCorrectly() await FileSystem.File.WriteAllTextAsync(file2, changelog2, TestContext.Current.CancellationToken); // Create PRs file - var prsFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var prsFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(prsFile)!); // language=yaml var prsContent = @@ -403,7 +402,7 @@ public async Task BundleChangelogs_WithPrsFileFilter_FiltersCorrectly() { Directory = _changelogDir, Prs = [prsFile], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -444,7 +443,7 @@ public async Task BundleChangelogs_WithPrNumberAndOwnerRepo_FiltersCorrectly() Prs = ["100"], Owner = "elastic", Repo = "elasticsearch", - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -482,7 +481,7 @@ public async Task BundleChangelogs_WithShortPrFormat_FiltersCorrectly() { Directory = _changelogDir, Prs = ["elastic/elasticsearch#133609"], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -505,7 +504,7 @@ public async Task BundleChangelogs_WithNoMatchingFiles_ReturnsError() { Directory = _changelogDir, InputProducts = [new ProductArgument { Product = "elasticsearch", Target = "9.2.0", Lifecycle = "ga" }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -521,13 +520,13 @@ public async Task BundleChangelogs_WithNoMatchingFiles_ReturnsError() public async Task BundleChangelogs_WithInvalidDirectory_ReturnsError() { // Arrange - var invalidDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "nonexistent"); + var invalidDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "nonexistent"); var input = new BundleChangelogsArguments { Directory = invalidDir, All = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -577,7 +576,7 @@ public async Task BundleChangelogs_WithNoFilterOption_ReturnsError() var input = new BundleChangelogsArguments { Directory = _changelogDir, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -599,7 +598,7 @@ public async Task BundleChangelogs_WithMultipleFilterOptions_ReturnsError() Directory = _changelogDir, All = true, InputProducts = [new ProductArgument { Product = "elasticsearch", Target = "9.2.0", Lifecycle = "ga" }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -652,7 +651,7 @@ public async Task BundleChangelogs_WithMultipleProducts_CreatesValidBundle() new ProductArgument { Product = "cloud-serverless", Target = "2025-12-02", Lifecycle = "*" }, new ProductArgument { Product = "cloud-serverless", Target = "2025-12-06", Lifecycle = "*" } ], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -709,7 +708,7 @@ public async Task BundleChangelogs_WithWildcardProductFilter_MatchesAllProducts( { Directory = _changelogDir, InputProducts = [new ProductArgument { Product = "*", Target = "9.2.0", Lifecycle = "ga" }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -763,7 +762,7 @@ public async Task BundleChangelogs_WithWildcardAllParts_EquivalentToAll() { Directory = _changelogDir, InputProducts = [new ProductArgument { Product = "*", Target = "*", Lifecycle = "*" }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -831,7 +830,7 @@ public async Task BundleChangelogs_WithPrefixWildcardTarget_MatchesCorrectly() { Directory = _changelogDir, InputProducts = [new ProductArgument { Product = "elasticsearch", Target = "9.3.*", Lifecycle = "*" }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -853,12 +852,12 @@ public async Task BundleChangelogs_WithNonExistentFileAsPrs_ReturnsError() // Arrange // Provide a non-existent file path - should return error since there are no other PRs - var nonexistentFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "nonexistent.txt"); + var nonexistentFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "nonexistent.txt"); var input = new BundleChangelogsArguments { Directory = _changelogDir, Prs = [nonexistentFile], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -895,7 +894,7 @@ public async Task BundleChangelogs_WithUrlAsPrs_TreatsAsPrIdentifier() { Directory = _changelogDir, Prs = ["https://github.com/elastic/elasticsearch/pull/123"], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -931,12 +930,12 @@ public async Task BundleChangelogs_WithNonExistentFileAndOtherPrs_EmitsWarning() await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, TestContext.Current.CancellationToken); // Provide a non-existent file path along with a valid PR - should emit warning for file but continue with PR - var nonexistentFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "nonexistent.txt"); + var nonexistentFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "nonexistent.txt"); var input = new BundleChangelogsArguments { Directory = _changelogDir, Prs = [nonexistentFile, "https://github.com/elastic/elasticsearch/pull/123"], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -997,7 +996,7 @@ public async Task BundleChangelogs_WithOutputProducts_OverridesChangelogProducts new ProductArgument { Product = "cloud-serverless", Target = "2025-12-02", Lifecycle = "ga" }, new ProductArgument { Product = "cloud-serverless", Target = "2025-12-06", Lifecycle = "beta" } ], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1075,7 +1074,7 @@ public async Task BundleChangelogs_WithMultipleProducts_IncludesAllProducts() { Directory = _changelogDir, All = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1137,7 +1136,7 @@ public async Task BundleChangelogs_WithInputProducts_IncludesLifecycleInProducts new ProductArgument { Product = "elasticsearch", Target = "9.2.0", Lifecycle = "ga" }, new ProductArgument { Product = "elasticsearch", Target = "9.3.0", Lifecycle = "beta" } ], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1185,7 +1184,7 @@ public async Task BundleChangelogs_WithOutputProducts_IncludesLifecycleInProduct new ProductArgument { Product = "cloud-serverless", Target = "2025-12-02", Lifecycle = "ga" }, new ProductArgument { Product = "cloud-serverless", Target = "2025-12-06", Lifecycle = "beta" } ], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1243,7 +1242,7 @@ public async Task BundleChangelogs_ExtractsLifecycleFromChangelogEntries() { Directory = _changelogDir, All = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1291,7 +1290,7 @@ public async Task BundleChangelogs_WithInputProductsWildcardLifecycle_ExtractsAc [ new ProductArgument { Product = "elasticsearch", Target = "9.2.0", Lifecycle = "*" } ], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1365,7 +1364,7 @@ public async Task BundleChangelogs_WithMultipleTargets_WarningIncludesLifecycle( { Directory = _changelogDir, All = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1411,7 +1410,7 @@ public async Task BundleChangelogs_WithResolve_CopiesChangelogContents() Directory = _changelogDir, All = true, Resolve = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1449,7 +1448,7 @@ public async Task BundleChangelogs_WithExplicitResolveFalse_OverridesConfigResol resolve: true """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -1474,7 +1473,7 @@ public async Task BundleChangelogs_WithExplicitResolveFalse_OverridesConfigResol All = true, Resolve = false, Config = configPath, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1520,7 +1519,7 @@ public async Task BundleChangelogs_WithResolve_PreservesSpecialCharactersInUtf8( var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-special-chars.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, Encoding.UTF8, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); var input = new BundleChangelogsArguments { Directory = _changelogDir, @@ -1601,7 +1600,7 @@ public async Task BundleChangelogs_WithDirectoryOutputPath_CreatesDefaultFilenam await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); // Use a directory path with default filename (simulating command layer processing) - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var outputPath = FileSystem.Path.Join(outputDir, "changelog-bundle.yaml"); var input = new BundleChangelogsArguments @@ -1648,7 +1647,7 @@ public async Task BundleChangelogs_WithResolveAndMissingTitle_ReturnsError() Directory = _changelogDir, All = true, Resolve = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1682,7 +1681,7 @@ public async Task BundleChangelogs_WithResolveAndMissingType_ReturnsError() Directory = _changelogDir, All = true, Resolve = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1714,7 +1713,7 @@ public async Task BundleChangelogs_WithResolveAndMissingProducts_ReturnsError() Directory = _changelogDir, All = true, Resolve = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1748,7 +1747,7 @@ public async Task BundleChangelogs_WithResolveAndInvalidProduct_ReturnsError() Directory = _changelogDir, All = true, Resolve = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1786,7 +1785,7 @@ public async Task BundleChangelogs_WithHideFeaturesOption_IncludesHideFeaturesIn Directory = _changelogDir, All = true, HideFeatures = ["feature:hidden-api", "feature:another-hidden"], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1828,7 +1827,7 @@ public async Task BundleChangelogs_WithoutHideFeaturesOption_OmitsHideFeaturesFi Directory = _changelogDir, All = true, // No HideFeatures - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1865,7 +1864,7 @@ public async Task BundleChangelogs_WithHideFeaturesFromFile_IncludesHideFeatures await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); // Create feature IDs file - var featureIdsFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "feature-ids.txt"); + var featureIdsFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "feature-ids.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(featureIdsFile)!); await FileSystem.File.WriteAllTextAsync(featureIdsFile, "feature:from-file\nfeature:another", TestContext.Current.CancellationToken); @@ -1874,7 +1873,7 @@ public async Task BundleChangelogs_WithHideFeaturesFromFile_IncludesHideFeatures Directory = _changelogDir, All = true, HideFeatures = [featureIdsFile], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1916,7 +1915,7 @@ public async Task BundleChangelogs_WithRepoOption_IncludesRepoInBundleProducts() Directory = _changelogDir, All = true, Repo = "cloud", // Set repo to "cloud" - different from product ID "cloud-serverless" - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1957,7 +1956,7 @@ public async Task BundleChangelogs_WithoutRepoOption_OmitsRepoFieldInOutput() Directory = _changelogDir, All = true, // No --repo option - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -1986,7 +1985,7 @@ public async Task BundleChangelogs_WithBundleLevelRepoConfig_UsesConfigRepoWhenO owner: elastic """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2006,7 +2005,7 @@ public async Task BundleChangelogs_WithBundleLevelRepoConfig_UsesConfigRepoWhenO var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-serverless-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -2041,7 +2040,7 @@ public async Task BundleChangelogs_WithRepoOptionAndBundleLevelConfig_CliOptionT repo: wrong-repo """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2061,7 +2060,7 @@ public async Task BundleChangelogs_WithRepoOptionAndBundleLevelConfig_CliOptionT var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-serverless-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -2115,7 +2114,7 @@ public async Task BundleChangelogs_WithOutputProductsAndRepo_IncludesRepoInAllPr new ProductArgument { Product = "cloud-serverless", Target = "2025-12-02", Lifecycle = "ga" }, new ProductArgument { Product = "elasticsearch-serverless", Target = "2025-12-02", Lifecycle = "ga" } ], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -2138,7 +2137,7 @@ public async Task BundleChangelogs_WithConfigOutputDirectory_WhenOutputNotSpecif { // Arrange - When --output is not specified, use bundle.output_directory from config if set - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); // language=yaml @@ -2149,7 +2148,7 @@ public async Task BundleChangelogs_WithConfigOutputDirectory_WhenOutputNotSpecif output_directory: "{outputDir.Replace("\\", "/")}" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, "config-output-dir", "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), "config-output-dir", "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2196,7 +2195,7 @@ public async Task BundleChangelogs_WithConfigDirectory_WhenDirectoryNotSpecified { // Arrange - When --directory is not specified (null), use bundle.directory from config if set - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); // language=yaml @@ -2207,7 +2206,7 @@ public async Task BundleChangelogs_WithConfigDirectory_WhenDirectoryNotSpecified output_directory: "{outputDir.Replace("\\", "/")}" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, "config-dir", "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), "config-dir", "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2255,9 +2254,9 @@ public async Task BundleChangelogs_WithExplicitDirectory_OverridesConfigDirector // Arrange - config has directory pointing elsewhere, but CLI passes --directory explicitly. // The explicit CLI value must win (e.g. --directory . when cwd has changelogs). - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(configDir); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); // language=yaml @@ -2268,7 +2267,7 @@ public async Task BundleChangelogs_WithExplicitDirectory_OverridesConfigDirector output_directory: "{outputDir.Replace("\\", "/")}" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, "config-dir-override", "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), "config-dir-override", "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2325,7 +2324,7 @@ public async Task BundleChangelogs_WithProfileHideFeatures_IncludesHideFeaturesI - feature:another-profile-hidden """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), "config", "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2346,7 +2345,7 @@ public async Task BundleChangelogs_WithProfileHideFeatures_IncludesHideFeaturesI var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -2395,7 +2394,7 @@ public async Task BundleChangelogs_WithProfile_OnlyProfileHideFeaturesAreUsed() - feature:from-profile """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, "config2", "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), "config2", "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2415,7 +2414,7 @@ public async Task BundleChangelogs_WithProfile_OnlyProfileHideFeaturesAreUsed() var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -2462,7 +2461,7 @@ public async Task BundleChangelogs_WithProfileMultipleHideFeatures_AllProfileFea - feature:profile-two """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, "config3", "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), "config3", "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2482,7 +2481,7 @@ public async Task BundleChangelogs_WithProfileMultipleHideFeatures_AllProfileFea var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -2548,7 +2547,7 @@ public async Task BundleChangelogs_WithComments_ProducesNormalizedChecksum() { Directory = _changelogDir, All = true, - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml") }; // Act @@ -2604,24 +2603,24 @@ public async Task BundleChangelogs_WithAndWithoutComments_ProduceSameChecksum() """; // Bundle with comments - var dir1 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var dir1 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(dir1); var file1 = FileSystem.Path.Join(dir1, "1755268130-shared.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelogWithComments, TestContext.Current.CancellationToken); - var output1 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle1.yaml"); + var output1 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle1.yaml"); var result1 = await Service.BundleChangelogs(Collector, new BundleChangelogsArguments { Directory = dir1, All = true, Output = output1 }, TestContext.Current.CancellationToken); // Bundle without comments - var dir2 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var dir2 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(dir2); var file2 = FileSystem.Path.Join(dir2, "1755268130-shared.yaml"); await FileSystem.File.WriteAllTextAsync(file2, changelogWithoutComments, TestContext.Current.CancellationToken); - var output2 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle2.yaml"); + var output2 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle2.yaml"); var result2 = await Service.BundleChangelogs(Collector, new BundleChangelogsArguments { Directory = dir2, All = true, Output = output2 @@ -2672,22 +2671,22 @@ public async Task BundleChangelogs_WithDifferentData_ProducesDifferentChecksum() """; // Bundle first file - var dir1 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var dir1 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(dir1); await FileSystem.File.WriteAllTextAsync(FileSystem.Path.Join(dir1, "1755268130-a.yaml"), changelog1, TestContext.Current.CancellationToken); - var output1 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle1.yaml"); + var output1 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle1.yaml"); await Service.BundleChangelogs(Collector, new BundleChangelogsArguments { Directory = dir1, All = true, Output = output1 }, TestContext.Current.CancellationToken); // Bundle second file - var dir2 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var dir2 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(dir2); await FileSystem.File.WriteAllTextAsync(FileSystem.Path.Join(dir2, "1755268130-b.yaml"), changelog2, TestContext.Current.CancellationToken); - var output2 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle2.yaml"); + var output2 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle2.yaml"); await Service.BundleChangelogs(Collector, new BundleChangelogsArguments { Directory = dir2, All = true, Output = output2 @@ -2710,7 +2709,7 @@ public async Task AmendBundle_WithComments_ProducesNormalizedChecksum() // Arrange - Amend service should also use normalized checksums // Create a base bundle file - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -2725,7 +2724,7 @@ public async Task AmendBundle_WithComments_ProducesNormalizedChecksum() await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); // Create a changelog file with comments - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // language=yaml @@ -2778,7 +2777,7 @@ public async Task AmendBundle_WithResolve_ProducesNormalizedChecksum() // Arrange - Amend with --resolve should also use normalized checksums // Create a base bundle file - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -2793,7 +2792,7 @@ public async Task AmendBundle_WithResolve_ProducesNormalizedChecksum() await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); // Create a changelog file with comments - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // language=yaml @@ -2861,7 +2860,7 @@ public async Task BundleChangelogs_WithProfile_OutputProducts_OverridesProductsA output_products: "elasticsearch {version} ga" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2881,7 +2880,7 @@ public async Task BundleChangelogs_WithProfile_OutputProducts_OverridesProductsA var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -2922,7 +2921,7 @@ public async Task BundleChangelogs_WithProfile_MalformedOutputProducts_EmitsErro output_products: "elasticsearch {version} ga extra-token" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2941,7 +2940,7 @@ public async Task BundleChangelogs_WithProfile_MalformedOutputProducts_EmitsErro var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -2974,7 +2973,7 @@ public async Task BundleChangelogs_WithProfile_MalformedProductsPattern_EmitsErr output: "elasticsearch-{version}.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -2993,7 +2992,7 @@ public async Task BundleChangelogs_WithProfile_MalformedProductsPattern_EmitsErr var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -3035,7 +3034,7 @@ public async Task BundleChangelogs_WithProfile_RepoAndOwner_WritesValuesToProduc owner: elastic """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -3055,7 +3054,7 @@ public async Task BundleChangelogs_WithProfile_RepoAndOwner_WritesValuesToProduc var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-serverless-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -3099,7 +3098,7 @@ public async Task BundleChangelogs_WithProfile_BundleLevelRepo_AppliesWhenProfil output: "elasticsearch-{version}.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -3119,7 +3118,7 @@ public async Task BundleChangelogs_WithProfile_BundleLevelRepo_AppliesWhenProfil var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -3162,7 +3161,7 @@ public async Task BundleChangelogs_WithProfile_ProfileRepoOverridesBundleRepo() repo: elasticsearch """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -3182,7 +3181,7 @@ public async Task BundleChangelogs_WithProfile_ProfileRepoOverridesBundleRepo() var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -3225,7 +3224,7 @@ public async Task BundleChangelogs_WithProfile_NoRepoOwner_PreservesExistingFall output: "elasticsearch-{version}.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -3245,7 +3244,7 @@ public async Task BundleChangelogs_WithProfile_NoRepoOwner_PreservesExistingFall var file1 = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -3282,7 +3281,7 @@ public async Task BundleChangelogs_WithProfileMode_MissingConfig_ReturnsErrorWit currentDirectory: "/empty-project" ); cwdFs.Directory.CreateDirectory("/empty-project"); - var service = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, FileSystemFactory.ScopeCurrentWorkingDirectory(cwdFs)); + var service = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, cwdFs); var input = new BundleChangelogsArguments { @@ -3307,26 +3306,25 @@ public async Task BundleChangelogs_WithProfileMode_MissingConfig_ReturnsErrorWit public async Task BundleChangelogs_WithProfileMode_ConfigAtCurrentDir_LoadsSuccessfully() { // Arrange - changelog.yml is at ./changelog.yml (in the current working directory) - var root = Paths.WorkingDirectoryRoot.FullName; var cwdFs = new System.IO.Abstractions.TestingHelpers.MockFileSystem( null, - currentDirectory: root + currentDirectory: "/test-root" ); - cwdFs.Directory.CreateDirectory(root); - cwdFs.Directory.CreateDirectory(Path.Join(root, "changelogs")); - cwdFs.Directory.CreateDirectory(Path.Join(root, "output")); + cwdFs.Directory.CreateDirectory("/test-root"); + cwdFs.Directory.CreateDirectory("/test-root/changelogs"); + cwdFs.Directory.CreateDirectory("/test-root/output"); // language=yaml var configContent = - $$""" + """ bundle: - directory: {{Path.Join(root, "changelogs")}} + directory: /test-root/changelogs profiles: es-release: products: "elasticsearch {version} {lifecycle}" output: "elasticsearch-{version}.yaml" """; - await cwdFs.File.WriteAllTextAsync(Path.Join(root, "changelog.yml"), configContent, TestContext.Current.CancellationToken); + await cwdFs.File.WriteAllTextAsync("/test-root/changelog.yml", configContent, TestContext.Current.CancellationToken); // language=yaml var changelogContent = @@ -3340,16 +3338,16 @@ public async Task BundleChangelogs_WithProfileMode_ConfigAtCurrentDir_LoadsSucce prs: - https://github.com/elastic/elasticsearch/pull/100 """; - await cwdFs.File.WriteAllTextAsync(Path.Join(root, "changelogs/1755268130-feature.yaml"), changelogContent, TestContext.Current.CancellationToken); + await cwdFs.File.WriteAllTextAsync("/test-root/changelogs/1755268130-feature.yaml", changelogContent, TestContext.Current.CancellationToken); - var service = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, FileSystemFactory.ScopeCurrentWorkingDirectory(cwdFs)); + var service = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, cwdFs); var input = new BundleChangelogsArguments { Profile = "es-release", ProfileArgument = "9.2.0", - OutputDirectory = Path.Join(root, "output") - // Config intentionally omitted — should discover changelog.yml in CWD + OutputDirectory = "/test-root/output" + // Config intentionally omitted — should discover /test-root/changelog.yml }; // Act @@ -3358,35 +3356,34 @@ public async Task BundleChangelogs_WithProfileMode_ConfigAtCurrentDir_LoadsSucce // Assert result.Should().BeTrue($"Expected bundling to succeed. Errors: {string.Join("; ", Collector.Diagnostics.Where(d => d.Severity == Severity.Error).Select(d => d.Message))}"); Collector.Errors.Should().Be(0); - cwdFs.Directory.GetFiles(Path.Join(root, "output"), "*.yaml").Should().NotBeEmpty("Expected output file to be created"); + cwdFs.Directory.GetFiles("/test-root/output", "*.yaml").Should().NotBeEmpty("Expected output file to be created"); } [Fact] public async Task BundleChangelogs_WithProfileMode_ConfigAtDocsSubdir_LoadsSuccessfully() { // Arrange - changelog.yml is at ./docs/changelog.yml (the second discovery candidate) - var root = Paths.WorkingDirectoryRoot.FullName; var cwdFs = new System.IO.Abstractions.TestingHelpers.MockFileSystem( null, - currentDirectory: root + currentDirectory: "/test-root" ); - cwdFs.Directory.CreateDirectory(root); - cwdFs.Directory.CreateDirectory(Path.Join(root, "docs")); - cwdFs.Directory.CreateDirectory(Path.Join(root, "changelogs")); - cwdFs.Directory.CreateDirectory(Path.Join(root, "output")); + cwdFs.Directory.CreateDirectory("/test-root"); + cwdFs.Directory.CreateDirectory("/test-root/docs"); + cwdFs.Directory.CreateDirectory("/test-root/changelogs"); + cwdFs.Directory.CreateDirectory("/test-root/output"); // language=yaml var configContent = - $$""" + """ bundle: - directory: {{Path.Join(root, "changelogs")}} + directory: /test-root/changelogs profiles: es-release: products: "elasticsearch {version} {lifecycle}" output: "elasticsearch-{version}.yaml" """; // Config is in docs/ subdir, not in CWD directly - await cwdFs.File.WriteAllTextAsync(Path.Join(root, "docs/changelog.yml"), configContent, TestContext.Current.CancellationToken); + await cwdFs.File.WriteAllTextAsync("/test-root/docs/changelog.yml", configContent, TestContext.Current.CancellationToken); // language=yaml var changelogContent = @@ -3400,16 +3397,16 @@ public async Task BundleChangelogs_WithProfileMode_ConfigAtDocsSubdir_LoadsSucce prs: - https://github.com/elastic/elasticsearch/pull/100 """; - await cwdFs.File.WriteAllTextAsync(Path.Join(root, "changelogs/1755268130-feature.yaml"), changelogContent, TestContext.Current.CancellationToken); + await cwdFs.File.WriteAllTextAsync("/test-root/changelogs/1755268130-feature.yaml", changelogContent, TestContext.Current.CancellationToken); - var service = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, FileSystemFactory.ScopeCurrentWorkingDirectory(cwdFs)); + var service = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, cwdFs); var input = new BundleChangelogsArguments { Profile = "es-release", ProfileArgument = "9.2.0", - OutputDirectory = Path.Join(root, "output") - // Config intentionally omitted — should discover docs/changelog.yml in CWD + OutputDirectory = "/test-root/output" + // Config intentionally omitted — should discover /test-root/docs/changelog.yml }; // Act @@ -3418,7 +3415,7 @@ public async Task BundleChangelogs_WithProfileMode_ConfigAtDocsSubdir_LoadsSucce // Assert result.Should().BeTrue($"Expected bundling to succeed. Errors: {string.Join("; ", Collector.Diagnostics.Where(d => d.Severity == Severity.Error).Select(d => d.Message))}"); Collector.Errors.Should().Be(0); - cwdFs.Directory.GetFiles(Path.Join(root, "output"), "*.yaml").Should().NotBeEmpty("Expected output file to be created"); + cwdFs.Directory.GetFiles("/test-root/output", "*.yaml").Should().NotBeEmpty("Expected output file to be created"); } // ─── Phase 3: URL list file and combined version+report ───────────────────────────── @@ -3434,7 +3431,7 @@ public async Task BundleChangelogs_WithProfile_UrlListFile_PrUrls_FiltersCorrect release: output: "bundle.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -3468,7 +3465,7 @@ public async Task BundleChangelogs_WithProfile_UrlListFile_PrUrls_FiltersCorrect await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, changelog2, TestContext.Current.CancellationToken); - var urlFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var urlFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(urlFile)!); await FileSystem.File.WriteAllTextAsync( urlFile, @@ -3509,7 +3506,7 @@ public async Task BundleChangelogs_WithProfile_UrlListFile_IssueUrls_FiltersCorr release: output: "bundle.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -3543,7 +3540,7 @@ public async Task BundleChangelogs_WithProfile_UrlListFile_IssueUrls_FiltersCorr await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, changelog2, TestContext.Current.CancellationToken); - var urlFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "issues.txt"); + var urlFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "issues.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(urlFile)!); await FileSystem.File.WriteAllTextAsync( urlFile, @@ -3585,7 +3582,7 @@ public async Task BundleChangelogs_WithProfile_UrlListFile_Numbers_ReturnsError( release: output: "bundle.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -3602,7 +3599,7 @@ await FileSystem.File.WriteAllTextAsync(changelogFile, - https://github.com/elastic/elasticsearch/pull/100 """, TestContext.Current.CancellationToken); - var urlFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var urlFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(urlFile)!); await FileSystem.File.WriteAllTextAsync(urlFile, "100\n200\n", TestContext.Current.CancellationToken); @@ -3638,7 +3635,7 @@ public async Task BundleChangelogs_WithProfile_UrlListFile_MixedPrsAndIssues_Ret release: output: "bundle.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -3655,7 +3652,7 @@ await FileSystem.File.WriteAllTextAsync(changelogFile, - https://github.com/elastic/elasticsearch/pull/100 """, TestContext.Current.CancellationToken); - var urlFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "mixed.txt"); + var urlFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "mixed.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(urlFile)!); await FileSystem.File.WriteAllTextAsync( urlFile, @@ -3696,7 +3693,7 @@ public async Task BundleChangelogs_WithProfile_CombinedVersionAndReport_Substitu output_products: "cloud-serverless {version}" output: "serverless-{version}.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -3730,7 +3727,7 @@ public async Task BundleChangelogs_WithProfile_CombinedVersionAndReport_Substitu await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, changelog2, TestContext.Current.CancellationToken); - var urlFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var urlFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(urlFile)!); await FileSystem.File.WriteAllTextAsync( urlFile, @@ -3738,7 +3735,7 @@ await FileSystem.File.WriteAllTextAsync( TestContext.Current.CancellationToken ); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -3784,16 +3781,16 @@ public async Task BundleChangelogs_WithProfile_CombinedVersion_ReportArgLooksLik serverless-release: output: "serverless-{version}.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); // A "fake" HTML file to act as the profile arg (simulating user accidentally reversing the order) - var reportFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "report.html"); + var reportFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "report.html"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(reportFile)!); await FileSystem.File.WriteAllTextAsync(reportFile, "", TestContext.Current.CancellationToken); - var urlFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var urlFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(urlFile)!); await FileSystem.File.WriteAllTextAsync(urlFile, "https://github.com/elastic/cloud/pull/100\n", TestContext.Current.CancellationToken); @@ -3831,11 +3828,11 @@ public async Task BundleChangelogs_WithProfile_CombinedVersion_ProfileHasProduct products: "elasticsearch 9.2.0 ga" output: "bundle.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); - var urlFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var urlFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(urlFile)!); await FileSystem.File.WriteAllTextAsync(urlFile, "https://github.com/elastic/elasticsearch/pull/100\n", TestContext.Current.CancellationToken); @@ -3872,7 +3869,7 @@ public async Task BundleChangelogs_WithReportOption_ParsesPromotionReportAndFilt PR #200 """; - var reportFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "report.html"); + var reportFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "report.html"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(reportFile)!); await FileSystem.File.WriteAllTextAsync(reportFile, htmlReportContent, TestContext.Current.CancellationToken); @@ -3906,7 +3903,7 @@ public async Task BundleChangelogs_WithReportOption_ParsesPromotionReportAndFilt await FileSystem.File.WriteAllTextAsync(file1, changelog1, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, changelog2, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -3949,7 +3946,7 @@ public async Task BundleChangelogs_WithReportOption_FileNotFound_ReturnsError() public async Task BundleChangelogs_WithPrsFile_ContainingNumbers_ReturnsError() { // Arrange - prs file contains bare numbers (not fully-qualified URLs) - var prsFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var prsFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(prsFile)!); await FileSystem.File.WriteAllTextAsync(prsFile, "100\n200\n", TestContext.Current.CancellationToken); @@ -3970,7 +3967,7 @@ await FileSystem.File.WriteAllTextAsync(changelogFile, { Directory = _changelogDir, Prs = [prsFile], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), "bundle.yaml") }; // Act @@ -3990,7 +3987,7 @@ await FileSystem.File.WriteAllTextAsync(changelogFile, public async Task BundleChangelogs_WithIssuesFile_ContainingShortForms_ReturnsError() { // Arrange - issues file contains short forms (not fully-qualified URLs) - var issuesFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "issues.txt"); + var issuesFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "issues.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(issuesFile)!); await FileSystem.File.WriteAllTextAsync(issuesFile, "elastic/elasticsearch#100\n", TestContext.Current.CancellationToken); @@ -4011,7 +4008,7 @@ await FileSystem.File.WriteAllTextAsync(changelogFile, { Directory = _changelogDir, Issues = [issuesFile], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, "bundle.yaml") + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), "bundle.yaml") }; // Act @@ -4031,7 +4028,7 @@ await FileSystem.File.WriteAllTextAsync(changelogFile, public async Task BundleChangelogs_WithPrsFile_ContainingValidUrls_FiltersCorrectly() { // Verify that a prs file with valid fully-qualified URLs still works correctly - var prsFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var prsFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(prsFile)!); await FileSystem.File.WriteAllTextAsync( prsFile, @@ -4054,7 +4051,7 @@ await FileSystem.File.WriteAllTextAsync( var file = FileSystem.Path.Join(_changelogDir, "1755268130-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file, changelog, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4082,7 +4079,7 @@ public async Task BundleChangelogs_WithRulesBundleExclude_ExcludesMatchingProduc exclude_products: cloud-hosted """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4117,7 +4114,7 @@ public async Task BundleChangelogs_WithRulesBundleExclude_ExcludesMatchingProduc await FileSystem.File.WriteAllTextAsync(file1, elasticsearchChangelog, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, cloudChangelog, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4154,7 +4151,7 @@ public async Task BundleChangelogs_WithRulesBundleInclude_IncludesOnlyMatchingPr include_products: elasticsearch """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4189,7 +4186,7 @@ public async Task BundleChangelogs_WithRulesBundleInclude_IncludesOnlyMatchingPr await FileSystem.File.WriteAllTextAsync(file1, elasticsearchChangelog, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, kibanaChangelog, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4225,7 +4222,7 @@ public async Task BundleChangelogs_WithAllFilter_AppliesRulesBundle() exclude_products: kibana """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4260,7 +4257,7 @@ public async Task BundleChangelogs_WithAllFilter_AppliesRulesBundle() await FileSystem.File.WriteAllTextAsync(file1, elasticsearchChangelog, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, kibanaChangelog, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4296,7 +4293,7 @@ public async Task BundleChangelogs_WithGlobalExcludeProductsMatchConjunction_Exc match_products: conjunction """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4333,7 +4330,7 @@ await FileSystem.File.WriteAllTextAsync( esAndKibana, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4367,7 +4364,7 @@ public async Task BundleChangelogs_WithGlobalIncludeProductsMatchConjunction_Req match_products: conjunction """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4403,7 +4400,7 @@ await FileSystem.File.WriteAllTextAsync( esSec, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4436,7 +4433,7 @@ public async Task BundleChangelogs_WithInputProducts_AppliesBundleRules() exclude_products: elasticsearch """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4457,7 +4454,7 @@ public async Task BundleChangelogs_WithInputProducts_AppliesBundleRules() var file1 = FileSystem.Path.Join(changelogDir, "1755268130-elasticsearch-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, elasticsearchChangelog, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); // Use InputProducts as primary filter — rules.bundle.exclude_products should still apply @@ -4490,7 +4487,7 @@ public async Task BundleChangelogs_WithRulesBundleExcludeType_ExcludesMatchingTy exclude_types: enhancement """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4525,7 +4522,7 @@ public async Task BundleChangelogs_WithRulesBundleExcludeType_ExcludesMatchingTy await FileSystem.File.WriteAllTextAsync(file1, featureChangelog, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, enhancementChangelog, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4561,7 +4558,7 @@ public async Task BundleChangelogs_WithRulesBundleIncludeArea_ExcludesNonMatchin include_areas: "Search" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4600,7 +4597,7 @@ public async Task BundleChangelogs_WithRulesBundleIncludeArea_ExcludesNonMatchin await FileSystem.File.WriteAllTextAsync(file1, searchChangelog, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, internalChangelog, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4638,7 +4635,7 @@ public async Task BundleChangelogs_WithRulesBundlePerProductOverride_AppliesProd include_areas: "Search" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4691,7 +4688,7 @@ public async Task BundleChangelogs_WithRulesBundlePerProductOverride_AppliesProd await FileSystem.File.WriteAllTextAsync(file2, serverlessSearch, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file3, serverlessOther, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4736,7 +4733,7 @@ public async Task BundleChangelogs_WithOutputProducts_SingleProductEntry_UsesMat include_areas: "Detection rules and alerts" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4791,7 +4788,7 @@ public async Task BundleChangelogs_WithOutputProducts_SingleProductEntry_UsesMat await FileSystem.File.WriteAllTextAsync(file2, securityEntry, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file3, securityOtherArea, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4837,7 +4834,7 @@ public async Task BundleChangelogs_WithOutputProducts_SharedProductEntry_UsesAlp include_areas: "Detection rules and alerts" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4877,7 +4874,7 @@ public async Task BundleChangelogs_WithOutputProducts_SharedProductEntry_UsesAlp await FileSystem.File.WriteAllTextAsync(file1, sharedEntry, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, kibanaOtherEntry, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4916,7 +4913,7 @@ public async Task BundleChangelogs_WithoutOutputProducts_FallsBackToEntryProduct exclude_types: docs """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -4950,7 +4947,7 @@ public async Task BundleChangelogs_WithoutOutputProducts_FallsBackToEntryProduct await FileSystem.File.WriteAllTextAsync(file1, kibanaDoc, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(file2, esDoc, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -4989,7 +4986,7 @@ public async Task BundleChangelogs_WithOutputProducts_EntryNotInContext_FallsBac exclude_types: feature """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5009,7 +5006,7 @@ public async Task BundleChangelogs_WithOutputProducts_EntryNotInContext_FallsBac var file1 = FileSystem.Path.Join(changelogDir, "1755268190-es-feature.yaml"); await FileSystem.File.WriteAllTextAsync(file1, esFeature, TestContext.Current.CancellationToken); - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); var input = new BundleChangelogsArguments @@ -5052,7 +5049,7 @@ public async Task BundleChangelogs_WithPerProductIncludeProducts_IncludesOnlyCon match_products: any """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5103,7 +5100,7 @@ public async Task BundleChangelogs_WithPerProductExcludeProducts_ExcludesContext match_products: any """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5175,7 +5172,7 @@ public async Task BundleChangelogs_WithPerProductRules_FallsBackToGlobalWhenNoCo - kibana """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5231,7 +5228,7 @@ public async Task BundleChangelogs_WithPerProductRules_ContextRulesTakePrecedenc - kibana """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5285,7 +5282,7 @@ private async Task CreateTestEntry(string changelogDir, string filename, string private string CreateTempFilePath(string filename) { - var outputPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), filename); + var outputPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), filename); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(outputPath)!); return outputPath; } @@ -5312,7 +5309,7 @@ public async Task BundleChangelogs_WithNoProductsField_FallsBackToGlobalRules() - "docs" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5366,7 +5363,7 @@ public async Task BundleChangelogs_GlobalMode_IncludeProductsAny_IncludesEntryMa - elasticsearch """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5432,7 +5429,7 @@ public async Task BundleChangelogs_GlobalMode_EmptyProducts_IncludesFeatureEntry - elasticsearch """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5479,7 +5476,7 @@ public async Task BundleChangelogs_WithEmptyProductsYamlMap_UsesGlobalRulesWhenG exclude_products: kibana """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5546,7 +5543,7 @@ public async Task BundleChangelogs_WithEmptyProductsList_FallsBackToGlobalRules( - "feature" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5611,7 +5608,7 @@ public async Task BundleChangelogs_WithMultipleProducts_UnifiedProductFiltering_ - "security" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5682,7 +5679,7 @@ public async Task BundleChangelogs_DisjointBundleContext_ProductFilteringFollows - "elasticsearch" # This should NOT apply to disjoint entry (would exclude if used) """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5754,7 +5751,7 @@ public async Task BundleChangelogs_MultiProductDisjoint_UsesGlobalRules() - "cloud-serverless" # This should NOT apply either """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5824,7 +5821,7 @@ public async Task BundleChangelogs_BundleAll_DisjointUsesOwnProductRules() - "kibana" # This SHOULD apply (excludes kibana entries) """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -5917,7 +5914,7 @@ public async Task BundleChangelogs_PartialPerProductRules_AllOrNothingReplacemen # No type/area rules here - global type exclusions are NOT inherited """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); diff --git a/tests/Elastic.Changelog.Tests/Changelogs/BundleProfileGitHubReleaseTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/BundleProfileGitHubReleaseTests.cs index 6efc646c74..02ec3279a6 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/BundleProfileGitHubReleaseTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/BundleProfileGitHubReleaseTests.cs @@ -5,7 +5,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; using Elastic.Changelog.GitHub; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; using FakeItEasy; @@ -25,13 +24,13 @@ public BundleProfileGitHubReleaseTests(ITestOutputHelper output) : base(output) _mockReleaseService = A.Fake(); _service = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, FileSystem, _mockReleaseService); - _changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + _changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(_changelogDir); } private async Task CreateConfigAsync(string configContent) { - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); return configPath; @@ -101,7 +100,7 @@ public async Task ProfileGitHubRelease_BundlesMatchingChangelogs() A.CallTo(() => _mockReleaseService.FetchReleaseAsync("elastic", "elasticsearch", "9.2.0", TestContext.Current.CancellationToken)) .Returns(new GitHubReleaseInfo { TagName = "v9.2.0", Name = "9.2.0", Body = releaseBody }); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -170,7 +169,7 @@ public async Task ProfileGitHubRelease_AutoInfersVersionAndLifecycle_FromRelease A.CallTo(() => _mockReleaseService.FetchReleaseAsync("elastic", "elasticsearch", "9.2.0", TestContext.Current.CancellationToken)) .Returns(new GitHubReleaseInfo { TagName = "v9.2.0", Name = "9.2.0", Body = releaseBody }); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -321,7 +320,7 @@ public async Task ProfileGitHubRelease_Latest_CallsFetchWithLatestTag() A.CallTo(() => _mockReleaseService.FetchReleaseAsync("elastic", "elasticsearch", "latest", TestContext.Current.CancellationToken)) .Returns(new GitHubReleaseInfo { TagName = "v9.2.0", Name = "9.2.0", Body = releaseBody }); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -500,7 +499,7 @@ public async Task ProfileGitHubRelease_InfersBetaLifecycle_FromTagSuffix() A.CallTo(() => _mockReleaseService.FetchReleaseAsync("elastic", "elasticsearch", "9.2.0-beta.1", TestContext.Current.CancellationToken)) .Returns(new GitHubReleaseInfo { TagName = "v9.2.0-beta.1", Name = "9.2.0 beta 1", Body = releaseBody }); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -569,7 +568,7 @@ public async Task ProfileGitHubRelease_InfersPreviewLifecycle_FromTagSuffix() A.CallTo(() => _mockReleaseService.FetchReleaseAsync("elastic", "apm-agent-dotnet", "v1.34.1-preview.1", TestContext.Current.CancellationToken)) .Returns(new GitHubReleaseInfo { TagName = "v1.34.1-preview.1", Name = "1.34.1 preview 1", Body = releaseBody }); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments @@ -638,7 +637,7 @@ public async Task ProfileGitHubRelease_BundleLevelRepo_UsedWhenProfileOmitsRepo( A.CallTo(() => _mockReleaseService.FetchReleaseAsync("elastic", "elasticsearch", "9.2.0", TestContext.Current.CancellationToken)) .Returns(new GitHubReleaseInfo { TagName = "v9.2.0", Name = "9.2.0", Body = releaseBody }); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(outputDir); var input = new BundleChangelogsArguments diff --git a/tests/Elastic.Changelog.Tests/Changelogs/BundleReleaseVersionTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/BundleReleaseVersionTests.cs index e130c3cc5e..05dd3d7781 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/BundleReleaseVersionTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/BundleReleaseVersionTests.cs @@ -6,7 +6,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; using Elastic.Changelog.GitHub; -using Elastic.Documentation.Configuration; using Elastic.Documentation.ReleaseNotes; using FakeItEasy; using Xunit; @@ -27,12 +26,12 @@ public class BundleReleaseVersionTests : ChangelogTestBase public BundleReleaseVersionTests(ITestOutputHelper output) : base(output) { _bundlingService = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, FileSystem); - _changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + _changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(_changelogDir); } private string BundleOutputPath() => - FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); // ----------------------------------------------------------------------- // Core flow: release → PR list → bundle diff --git a/tests/Elastic.Changelog.Tests/Changelogs/ChangelogConfigurationTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/ChangelogConfigurationTests.cs index 78ea1ed0eb..4d0176fa0f 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/ChangelogConfigurationTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/ChangelogConfigurationTests.cs @@ -6,7 +6,6 @@ using Elastic.Changelog.Configuration; using Elastic.Changelog.Serialization; using Elastic.Documentation; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.Changelog; using Elastic.Documentation.Diagnostics; using Elastic.Documentation.ReleaseNotes; @@ -20,7 +19,7 @@ public async Task LoadChangelogConfiguration_WithoutPivot_UsesDefaults() { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -60,7 +59,7 @@ public async Task LoadChangelogConfiguration_WithPivotTypes_UsesConfiguredTypes( { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -110,7 +109,7 @@ public async Task LoadChangelogConfiguration_WithoutAvailableLifecycles_UsesDefa { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -154,7 +153,7 @@ public async Task LoadChangelogConfiguration_WithPivotAreas_ComputesLabelToAreas { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -207,7 +206,7 @@ public async Task LoadChangelogConfiguration_WithPivotTypesLabels_ComputesLabelT { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -256,7 +255,7 @@ public async Task LoadChangelogConfiguration_WithInvalidPivotType_ReturnsError() { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -300,7 +299,7 @@ public async Task LoadChangelogConfiguration_WithMissingRequiredTypes_ReturnsErr { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -341,7 +340,7 @@ public async Task LoadChangelogConfiguration_WithSubtypesOnNonBreakingChange_Ret { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -387,7 +386,7 @@ public async Task LoadChangelogConfiguration_WithSubtypesOnBreakingChange_Succee { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -431,7 +430,7 @@ public async Task LoadChangelogConfiguration_WithInvalidSubtype_ReturnsError() { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -875,7 +874,7 @@ public async Task LoadChangelogConfiguration_MixedStringAndListForms_ParsesCorre private async Task LoadConfig(string yamlContent) { var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -903,7 +902,7 @@ public async Task LoadChangelogConfiguration_BundleSection_ParsesRepoOwnerDirect { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -944,7 +943,7 @@ public async Task LoadChangelogConfiguration_BundleSectionAbsent_BundleIsNull() { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -980,7 +979,7 @@ public async Task LoadChangelogConfiguration_NoConfigFile_ReturnsDefaultWithNull { // Arrange – no changelog.yml on disk; simulates running from a directory without a config var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(configDir); var originalDir = FileSystem.Directory.GetCurrentDirectory(); @@ -1006,7 +1005,7 @@ public async Task LoadChangelogConfiguration_WithPivotProducts_ComputesLabelToPr { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -1054,7 +1053,7 @@ public async Task LoadChangelogConfiguration_WithPivotProducts_ProductSpecWithTa { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -1100,7 +1099,7 @@ public async Task LoadChangelogConfiguration_WithPivotProducts_InvalidProductId_ { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var docsDir = FileSystem.Path.Join(configDir, "docs"); FileSystem.Directory.CreateDirectory(docsDir); var configPath = FileSystem.Path.Join(docsDir, "changelog.yml"); @@ -1141,7 +1140,7 @@ public async Task LoadChangelogConfiguration_WithRulesBundle_LoadsCorrectly() { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); // language=yaml var configContent = @@ -1173,7 +1172,7 @@ public async Task LoadChangelogConfiguration_WithRulesBundle_LoadsCorrectly() public async Task LoadChangelogConfiguration_WithRulesBundle_MatchProductsConjunction_LoadsCorrectly() { var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); var configContent = """ @@ -1198,7 +1197,7 @@ public async Task LoadChangelogConfiguration_WithRulesBundle_BothExcludeAndInclu { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); // language=yaml var configContent = @@ -1269,7 +1268,7 @@ public async Task LoadChangelogConfiguration_WithRulesBundle_UnknownProductId_Re { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); // language=yaml var configContent = @@ -1294,7 +1293,7 @@ public async Task LoadChangelogConfiguration_WithRulesPublish_EmitsDeprecationWa { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); // language=yaml var configContent = @@ -1319,7 +1318,7 @@ public async Task LoadChangelogConfiguration_WithRulesBundle_TypeAreaAndProducts { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); // language=yaml var configContent = @@ -1443,7 +1442,7 @@ public async Task LoadChangelogConfiguration_WithPerProductProductFiltering_Load { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); var configContent = @@ -1491,7 +1490,7 @@ public async Task LoadChangelogConfiguration_WithPerProductProductFiltering_Mutu { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); var configContent = @@ -1521,7 +1520,7 @@ public async Task LoadChangelogConfiguration_WithPerProductProductFiltering_Mode { // Arrange — Mode 3 ignores global rules.bundle product lists; per-product lists need not align with globals. var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); var configContent = @@ -1554,7 +1553,7 @@ public async Task LoadChangelogConfiguration_WithPerProductProductFiltering_Prod { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); var configContent = @@ -1587,7 +1586,7 @@ public async Task LoadChangelogConfiguration_WithPerProductProductFiltering_Inva { // Arrange var configLoader = new ChangelogConfigurationLoader(LoggerFactory, ConfigurationContext, FileSystem); - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); var configContent = diff --git a/tests/Elastic.Changelog.Tests/Changelogs/ChangelogRemoveTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/ChangelogRemoveTests.cs index 6f8d3dd073..f9ae194f1d 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/ChangelogRemoveTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/ChangelogRemoveTests.cs @@ -4,7 +4,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; namespace Elastic.Changelog.Tests.Changelogs; @@ -78,7 +77,7 @@ public ChangelogRemoveTests(ITestOutputHelper output) : base(output) private string CreateChangelogDir() { - var dir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var dir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(dir); return dir; } @@ -383,7 +382,7 @@ public async Task Remove_WithBundlesDirOverride_UsesSpecifiedPath() await WriteFile("1001-es-feature.yaml", ElasticsearchFeatureYaml); // Create a bundles dir in a custom location - var customBundlesDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var customBundlesDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(customBundlesDir); var checksum = ComputeSha1(ElasticsearchFeatureYaml); await FileSystem.File.WriteAllTextAsync( @@ -474,7 +473,7 @@ public async Task Remove_WithProfileAndVersion_DeletesMatchingProducts() products: "elasticsearch {version} {lifecycle}" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -505,7 +504,7 @@ public async Task Remove_WithProfileAndPromotionReport_DeletesMatchingPrs() await WriteFile("2001-kibana-feature.yaml", KibanaFeatureYaml); var reportContent = "https://github.com/elastic/elasticsearch/pull/1001"; - var reportPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, "report.html"); + var reportPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), "report.html"); await FileSystem.File.WriteAllTextAsync(reportPath, reportContent, TestContext.Current.CancellationToken); // language=yaml @@ -517,7 +516,7 @@ public async Task Remove_WithProfileAndPromotionReport_DeletesMatchingPrs() products: "elasticsearch {version} {lifecycle}" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -551,7 +550,7 @@ public async Task Remove_WithProfile_UnknownProfile_ReturnsError() products: "elasticsearch {version} {lifecycle}" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -586,7 +585,7 @@ public async Task Remove_WithProfile_MissingProfileArg_ReturnsError() products: "elasticsearch {version} {lifecycle}" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -617,7 +616,7 @@ public async Task Remove_WithProfileMode_MissingConfig_ReturnsErrorWithAdvice() currentDirectory: "/empty-project" ); cwdFs.Directory.CreateDirectory("/empty-project"); - var service = new ChangelogRemoveService(LoggerFactory, ConfigurationContext, FileSystemFactory.ScopeCurrentWorkingDirectory(cwdFs)); + var service = new ChangelogRemoveService(LoggerFactory, ConfigurationContext, cwdFs); var input = new ChangelogRemoveArguments { @@ -654,7 +653,7 @@ public async Task Remove_WithProfile_NoProductsAndVersionArg_ReturnsSpecificErro output: "release-{version}.yaml" """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -691,12 +690,12 @@ public async Task Remove_WithProfile_UrlListFile_PrUrls_RemovesMatchedFiles() release: """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); // URL file contains only the ES PR - var urlFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var urlFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(urlFile)!); await FileSystem.File.WriteAllTextAsync( urlFile, @@ -736,11 +735,11 @@ public async Task Remove_WithProfile_CombinedVersionAndReport_UsesReportForFilte release: """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); - var urlFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "prs.txt"); + var urlFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "prs.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(urlFile)!); await FileSystem.File.WriteAllTextAsync( urlFile, @@ -778,7 +777,7 @@ public async Task Remove_WithReportOption_ParsesPromotionReportAndFilters() PR 1001 """; - var reportFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "report.html"); + var reportFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "report.html"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(reportFile)!); await FileSystem.File.WriteAllTextAsync(reportFile, htmlReport, TestContext.Current.CancellationToken); @@ -826,7 +825,7 @@ public async Task Remove_WithBundleOwnerConfig_UsesConfigOwnerWhenOptionNotSpeci repo: myrepo """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -874,7 +873,7 @@ public async Task Remove_WithBundleRepoConfig_UsesConfigRepoWhenOptionNotSpecifi owner: myorg """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -909,7 +908,7 @@ public async Task Remove_WithBundleOwnerConfig_CliOwnerTakesPrecedence() repo: elasticsearch """; - var configPath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "changelog.yml"); + var configPath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "changelog.yml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(configPath)!); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); diff --git a/tests/Elastic.Changelog.Tests/Changelogs/ChangelogTestBase.cs b/tests/Elastic.Changelog.Tests/Changelogs/ChangelogTestBase.cs index a52eccddcf..1bc0e1eb7c 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/ChangelogTestBase.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/ChangelogTestBase.cs @@ -13,13 +13,12 @@ using Elastic.Documentation.Configuration.Versions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Nullean.ScopedFileSystem; namespace Elastic.Changelog.Tests.Changelogs; public abstract class ChangelogTestBase : IDisposable { - protected ScopedFileSystem FileSystem { get; } + protected MockFileSystem FileSystem { get; } protected IConfigurationContext ConfigurationContext { get; } protected TestDiagnosticsCollector Collector { get; } protected ILoggerFactory LoggerFactory { get; } @@ -28,8 +27,7 @@ public abstract class ChangelogTestBase : IDisposable protected ChangelogTestBase(ITestOutputHelper output) { Output = output; - var mockFileSystem = new MockFileSystem(new MockFileSystemOptions { CurrentDirectory = Paths.WorkingDirectoryRoot.FullName }); - FileSystem = FileSystemFactory.ScopeCurrentWorkingDirectory(mockFileSystem); + FileSystem = new MockFileSystem(); Collector = new TestDiagnosticsCollector(output); LoggerFactory = new TestLoggerFactory(output); diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Create/CreateChangelogTestBase.cs b/tests/Elastic.Changelog.Tests/Changelogs/Create/CreateChangelogTestBase.cs index 56571efb93..41e47e6899 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Create/CreateChangelogTestBase.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Create/CreateChangelogTestBase.cs @@ -4,7 +4,6 @@ using Elastic.Changelog.Creation; using Elastic.Changelog.GitHub; -using Elastic.Documentation.Configuration; using FakeItEasy; namespace Elastic.Changelog.Tests.Changelogs.Create; @@ -18,7 +17,7 @@ protected ChangelogCreationService CreateService() => protected async Task CreateConfigDirectory(string configContent) { - var configDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var configDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(configDir); var configPath = FileSystem.Path.Join(configDir, "changelog.yml"); await FileSystem.File.WriteAllTextAsync(configPath, configContent, TestContext.Current.CancellationToken); @@ -26,5 +25,5 @@ protected async Task CreateConfigDirectory(string configContent) } protected string CreateOutputDirectory() => - FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); } diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Create/PrIntegrationTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Create/PrIntegrationTests.cs index 0bc0eb04d3..cdf0672ae5 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Create/PrIntegrationTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Create/PrIntegrationTests.cs @@ -5,7 +5,6 @@ using AwesomeAssertions; using Elastic.Changelog.Creation; using Elastic.Changelog.GitHub; -using Elastic.Documentation.Configuration; using FakeItEasy; namespace Elastic.Changelog.Tests.Changelogs.Create; @@ -421,7 +420,7 @@ public async Task CreateChangelog_WithPrsFromFile_ProcessesAllPrsFromFile() A._)) .Returns(pr3Info); - var tempDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var tempDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(tempDir); // Create a file with newline-delimited PRs (simulating what ChangelogCommand would read) @@ -519,7 +518,7 @@ public async Task CreateChangelog_WithMixedPrsFromFileAndCommaSeparated_Processe A._)) .Returns(pr2Info); - var tempDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var tempDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(tempDir); // Create a file with PRs diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Create/ReleaseVersionTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Create/ReleaseVersionTests.cs index aa50df84f7..69c58507e4 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Create/ReleaseVersionTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Create/ReleaseVersionTests.cs @@ -5,7 +5,6 @@ using AwesomeAssertions; using Elastic.Changelog.GitHub; using Elastic.Changelog.GithubRelease; -using Elastic.Documentation.Configuration; using FakeItEasy; using Xunit; @@ -24,7 +23,7 @@ private GitHubReleaseChangelogService CreateService() => new(LoggerFactory, ConfigurationContext, _mockReleaseService, _mockPrService, FileSystem); private string CreateOutputDirectory() => - FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); // ----------------------------------------------------------------------- // Validation: no PR refs in release notes @@ -269,7 +268,7 @@ public async Task ReleaseVersion_OutputNull_ServiceUsesChangelogsDefault() A.CallTo(() => _mockPrService.FetchPrInfoAsync(A._, A._, A._, A._)) .Returns(new GitHubPrInfo { Title = "Fix something", Labels = [] }); - var workDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var workDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(workDir); var originalDir = FileSystem.Directory.GetCurrentDirectory(); try diff --git a/tests/Elastic.Changelog.Tests/Changelogs/RemoveReleaseVersionTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/RemoveReleaseVersionTests.cs index f64aeebf19..14efc00f71 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/RemoveReleaseVersionTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/RemoveReleaseVersionTests.cs @@ -6,7 +6,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; using Elastic.Changelog.GitHub; -using Elastic.Documentation.Configuration; using Elastic.Documentation.ReleaseNotes; using FakeItEasy; @@ -26,7 +25,7 @@ public class RemoveReleaseVersionTests : ChangelogTestBase public RemoveReleaseVersionTests(ITestOutputHelper output) : base(output) { _removeService = new ChangelogRemoveService(LoggerFactory, ConfigurationContext, FileSystem); - _changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + _changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(_changelogDir); } diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Render/BasicRenderTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Render/BasicRenderTests.cs index a3378ce3c7..49d97479af 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Render/BasicRenderTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Render/BasicRenderTests.cs @@ -5,7 +5,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; using Elastic.Changelog.Rendering; -using Elastic.Documentation.Configuration; namespace Elastic.Changelog.Tests.Changelogs.Render; @@ -15,7 +14,7 @@ public class BasicRenderTests(ITestOutputHelper output) : RenderChangelogTestBas public async Task RenderChangelogs_WithValidBundle_CreatesMarkdownFiles() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create test changelog file @@ -36,7 +35,7 @@ public async Task RenderChangelogs_WithValidBundle_CreatesMarkdownFiles() await FileSystem.File.WriteAllTextAsync(changelogFile, changelog1, TestContext.Current.CancellationToken); // Create bundle file - var bundleFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var bundleFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(bundleFile)!); // language=yaml @@ -52,7 +51,7 @@ public async Task RenderChangelogs_WithValidBundle_CreatesMarkdownFiles() """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -80,8 +79,8 @@ public async Task RenderChangelogs_WithValidBundle_CreatesMarkdownFiles() public async Task RenderChangelogs_WithMultipleBundles_MergesAndRenders() { // Arrange - var changelogDir1 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); - var changelogDir2 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir1 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); + var changelogDir2 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir1); FileSystem.Directory.CreateDirectory(changelogDir2); @@ -115,7 +114,7 @@ public async Task RenderChangelogs_WithMultipleBundles_MergesAndRenders() await FileSystem.File.WriteAllTextAsync(file2, changelog2, TestContext.Current.CancellationToken); // Create bundle files - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundle1 = FileSystem.Path.Join(bundleDir, "bundle1.yaml"); @@ -146,7 +145,7 @@ public async Task RenderChangelogs_WithMultipleBundles_MergesAndRenders() """; await FileSystem.File.WriteAllTextAsync(bundle2, bundleContent2, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Render/BundleValidationTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Render/BundleValidationTests.cs index c3d0c6d41f..5d105e1595 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Render/BundleValidationTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Render/BundleValidationTests.cs @@ -4,7 +4,6 @@ using AwesomeAssertions; using Elastic.Changelog.Rendering; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; namespace Elastic.Changelog.Tests.Changelogs.Render; @@ -253,8 +252,8 @@ public async Task AmendFileEntry_CommentedFile_NormalizedChecksum_NoWarning() private (string BundleDir, string ChangelogDir) CreateTestDirs() { - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); FileSystem.Directory.CreateDirectory(changelogDir); return (bundleDir, changelogDir); @@ -284,7 +283,7 @@ private RenderChangelogsArguments CreateRenderInput(string bundleFile, string ch new() { Bundles = [new BundleInput { BundleFile = bundleFile, Directory = changelogDir }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()), + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()), Title = "9.2.0" }; } diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Render/ChecksumValidationTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Render/ChecksumValidationTests.cs index 1ff1e6cab9..db6d9063b4 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Render/ChecksumValidationTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Render/ChecksumValidationTests.cs @@ -4,7 +4,6 @@ using AwesomeAssertions; using Elastic.Changelog.Rendering; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; namespace Elastic.Changelog.Tests.Changelogs.Render; @@ -119,7 +118,7 @@ public async Task ValidateBundle_FileDataChanged_EmitsWarning() public async Task ValidateBundle_ResolvedEntry_SkipsChecksumValidation() { // Arrange — resolved entry has inline data, no file reference needed - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -165,14 +164,14 @@ public void Checksums_WithAndWithoutComments_AreEqual() string fileOnDisk, string storedChecksum) { - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); var changelogFileName = "1755268130-feature.yaml"; var changelogFile = FileSystem.Path.Join(changelogDir, changelogFileName); await FileSystem.File.WriteAllTextAsync(changelogFile, fileOnDisk, TestContext.Current.CancellationToken); - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -196,7 +195,7 @@ private RenderChangelogsArguments CreateRenderInput(string bundleFile, string ch new() { Bundles = [new BundleInput { BundleFile = bundleFile, Directory = changelogDir }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()), + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()), Title = "9.2.0" }; } diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Render/DuplicateHandlingTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Render/DuplicateHandlingTests.cs index 65281e0089..07096b230f 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Render/DuplicateHandlingTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Render/DuplicateHandlingTests.cs @@ -5,7 +5,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; using Elastic.Changelog.Rendering; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; namespace Elastic.Changelog.Tests.Changelogs.Render; @@ -16,8 +15,8 @@ public class DuplicateHandlingTests(ITestOutputHelper output) : RenderChangelogT public async Task RenderChangelogs_WithDuplicateFileName_EmitsWarning() { // Arrange - var changelogDir1 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); - var changelogDir2 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir1 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); + var changelogDir2 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir1); FileSystem.Directory.CreateDirectory(changelogDir2); @@ -41,7 +40,7 @@ public async Task RenderChangelogs_WithDuplicateFileName_EmitsWarning() await FileSystem.File.WriteAllTextAsync(file2, changelog, TestContext.Current.CancellationToken); // Create bundle files - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundle1 = FileSystem.Path.Join(bundleDir, "bundle1.yaml"); @@ -72,7 +71,7 @@ public async Task RenderChangelogs_WithDuplicateFileName_EmitsWarning() """; await FileSystem.File.WriteAllTextAsync(bundle2, bundleContent2, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -100,7 +99,7 @@ public async Task RenderChangelogs_WithDuplicateFileName_EmitsWarning() public async Task RenderChangelogs_WithDuplicateFileNameInSameBundle_EmitsWarning() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create changelog file @@ -121,7 +120,7 @@ public async Task RenderChangelogs_WithDuplicateFileNameInSameBundle_EmitsWarnin await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, TestContext.Current.CancellationToken); // Create bundle file with the same file referenced twice - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -141,7 +140,7 @@ public async Task RenderChangelogs_WithDuplicateFileNameInSameBundle_EmitsWarnin """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -169,8 +168,8 @@ public async Task RenderChangelogs_WithDuplicateFileNameInSameBundle_EmitsWarnin public async Task RenderChangelogs_WithDuplicatePr_EmitsWarning() { // Arrange - var changelogDir1 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); - var changelogDir2 = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir1 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); + var changelogDir2 = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir1); FileSystem.Directory.CreateDirectory(changelogDir2); @@ -204,7 +203,7 @@ public async Task RenderChangelogs_WithDuplicatePr_EmitsWarning() await FileSystem.File.WriteAllTextAsync(file2, changelog2, TestContext.Current.CancellationToken); // Create bundle files - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundle1 = FileSystem.Path.Join(bundleDir, "bundle1.yaml"); @@ -235,7 +234,7 @@ public async Task RenderChangelogs_WithDuplicatePr_EmitsWarning() """; await FileSystem.File.WriteAllTextAsync(bundle2, bundleContent2, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Render/ErrorHandlingTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Render/ErrorHandlingTests.cs index bd72bf9c67..976ce6e65c 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Render/ErrorHandlingTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Render/ErrorHandlingTests.cs @@ -6,7 +6,6 @@ using Elastic.Changelog.Bundling; using Elastic.Changelog.Configuration; using Elastic.Changelog.Rendering; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; namespace Elastic.Changelog.Tests.Changelogs.Render; @@ -17,12 +16,12 @@ public class ErrorHandlingTests(ITestOutputHelper output) : RenderChangelogTestB public async Task RenderChangelogs_WithMissingBundleFile_ReturnsError() { // Arrange - var missingBundle = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "nonexistent.yaml"); + var missingBundle = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "nonexistent.yaml"); var input = new RenderChangelogsArguments { Bundles = [new BundleInput { BundleFile = missingBundle }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()) + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()) }; // Act @@ -38,7 +37,7 @@ public async Task RenderChangelogs_WithMissingBundleFile_ReturnsError() public async Task RenderChangelogs_WithMissingChangelogFile_ReturnsError() { // Arrange - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -58,7 +57,7 @@ public async Task RenderChangelogs_WithMissingChangelogFile_ReturnsError() var input = new RenderChangelogsArguments { Bundles = [new BundleInput { BundleFile = bundleFile, Directory = bundleDir }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()) + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()) }; // Act @@ -74,7 +73,7 @@ public async Task RenderChangelogs_WithMissingChangelogFile_ReturnsError() public async Task RenderChangelogs_WithInvalidBundleStructure_ReturnsError() { // Arrange - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -88,7 +87,7 @@ public async Task RenderChangelogs_WithInvalidBundleStructure_ReturnsError() var input = new RenderChangelogsArguments { Bundles = [new BundleInput { BundleFile = bundleFile }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()) + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()) }; // Act @@ -104,7 +103,7 @@ public async Task RenderChangelogs_WithInvalidBundleStructure_ReturnsError() public async Task RenderChangelogs_WithInvalidChangelogFile_ReturnsError() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create invalid changelog file (missing required fields) @@ -119,7 +118,7 @@ public async Task RenderChangelogs_WithInvalidChangelogFile_ReturnsError() await FileSystem.File.WriteAllTextAsync(changelogFile, invalidChangelog, TestContext.Current.CancellationToken); // Create bundle file - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -139,7 +138,7 @@ public async Task RenderChangelogs_WithInvalidChangelogFile_ReturnsError() var input = new RenderChangelogsArguments { Bundles = [new BundleInput { BundleFile = bundleFile, Directory = changelogDir }], - Output = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()) + Output = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()) }; // Act @@ -155,7 +154,7 @@ public async Task RenderChangelogs_WithInvalidChangelogFile_ReturnsError() public async Task RenderChangelogs_WithResolvedEntry_ValidatesAndRenders() { // Arrange - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -176,7 +175,7 @@ public async Task RenderChangelogs_WithResolvedEntry_ValidatesAndRenders() """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -205,7 +204,7 @@ public async Task RenderChangelogs_WithUnknownType_EmitsError() // Arrange // When an unknown type string is encountered during YAML deserialization, // it should be parsed as Invalid and an error should be emitted. - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create changelog with an unknown type that will be marked as Invalid @@ -224,7 +223,7 @@ public async Task RenderChangelogs_WithUnknownType_EmitsError() await FileSystem.File.WriteAllTextAsync(changelogFile, changelog1, TestContext.Current.CancellationToken); // Create bundle file - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); // language=yaml @@ -240,7 +239,7 @@ public async Task RenderChangelogs_WithUnknownType_EmitsError() """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Render/HideFeaturesTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Render/HideFeaturesTests.cs index 020799bc4f..65ac13b633 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Render/HideFeaturesTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Render/HideFeaturesTests.cs @@ -5,7 +5,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; using Elastic.Changelog.Rendering; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; namespace Elastic.Changelog.Tests.Changelogs.Render; @@ -16,7 +15,7 @@ public class HideFeaturesTests(ITestOutputHelper output) : RenderChangelogTestBa public async Task RenderChangelogs_WithHideFeatures_CommentsOutMatchingEntries() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create changelog with feature-id @@ -54,7 +53,7 @@ public async Task RenderChangelogs_WithHideFeatures_CommentsOutMatchingEntries() await FileSystem.File.WriteAllTextAsync(changelogFile2, changelog2, TestContext.Current.CancellationToken); // Create bundle file - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -74,7 +73,7 @@ public async Task RenderChangelogs_WithHideFeatures_CommentsOutMatchingEntries() """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -112,7 +111,7 @@ public async Task RenderChangelogs_WithHideFeatures_CommentsOutMatchingEntries() public async Task RenderChangelogs_WithHideFeatures_BreakingChange_UsesBlockComments() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // language=yaml @@ -134,7 +133,7 @@ public async Task RenderChangelogs_WithHideFeatures_BreakingChange_UsesBlockComm var changelogFile = FileSystem.Path.Join(changelogDir, "1755268130-breaking.yaml"); await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, TestContext.Current.CancellationToken); - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -151,7 +150,7 @@ public async Task RenderChangelogs_WithHideFeatures_BreakingChange_UsesBlockComm """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -187,7 +186,7 @@ public async Task RenderChangelogs_WithHideFeatures_BreakingChange_UsesBlockComm public async Task RenderChangelogs_WithHideFeatures_Deprecation_UsesBlockComments() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // language=yaml @@ -207,7 +206,7 @@ public async Task RenderChangelogs_WithHideFeatures_Deprecation_UsesBlockComment var changelogFile = FileSystem.Path.Join(changelogDir, "1755268130-deprecation.yaml"); await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, TestContext.Current.CancellationToken); - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -224,7 +223,7 @@ public async Task RenderChangelogs_WithHideFeatures_Deprecation_UsesBlockComment """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -255,7 +254,7 @@ public async Task RenderChangelogs_WithHideFeatures_Deprecation_UsesBlockComment public async Task RenderChangelogs_WithHideFeatures_CommaSeparated_CommentsOutMatchingEntries() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // language=yaml @@ -303,7 +302,7 @@ public async Task RenderChangelogs_WithHideFeatures_CommaSeparated_CommentsOutMa await FileSystem.File.WriteAllTextAsync(changelogFile2, changelog2, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(changelogFile3, changelog3, TestContext.Current.CancellationToken); - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -326,7 +325,7 @@ public async Task RenderChangelogs_WithHideFeatures_CommaSeparated_CommentsOutMa """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -355,7 +354,7 @@ public async Task RenderChangelogs_WithHideFeatures_CommaSeparated_CommentsOutMa public async Task RenderChangelogs_WithHideFeatures_FromFile_CommentsOutMatchingEntries() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // language=yaml @@ -374,7 +373,7 @@ public async Task RenderChangelogs_WithHideFeatures_FromFile_CommentsOutMatching var changelogFile = FileSystem.Path.Join(changelogDir, "1755268130-hidden.yaml"); await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, TestContext.Current.CancellationToken); - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -392,11 +391,11 @@ public async Task RenderChangelogs_WithHideFeatures_FromFile_CommentsOutMatching await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); // Create feature IDs file - var featureIdsFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "feature-ids.txt"); + var featureIdsFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "feature-ids.txt"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(featureIdsFile)!); await FileSystem.File.WriteAllTextAsync(featureIdsFile, "feature:from-file\nfeature:another", TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -422,7 +421,7 @@ public async Task RenderChangelogs_WithHideFeatures_FromFile_CommentsOutMatching public async Task RenderChangelogs_WithHideFeatures_CaseInsensitive_MatchesFeatureIds() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // language=yaml @@ -441,7 +440,7 @@ public async Task RenderChangelogs_WithHideFeatures_CaseInsensitive_MatchesFeatu var changelogFile = FileSystem.Path.Join(changelogDir, "1755268130-hidden.yaml"); await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, TestContext.Current.CancellationToken); - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -458,7 +457,7 @@ public async Task RenderChangelogs_WithHideFeatures_CaseInsensitive_MatchesFeatu """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -485,7 +484,7 @@ public async Task RenderChangelogs_WithHideFeatures_CaseInsensitive_MatchesFeatu public async Task RenderChangelogs_WithBundleHideFeatures_CommentsOutMatchingEntries() { // Arrange - Test that hide-features from bundle metadata are used to hide entries - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // language=yaml @@ -518,7 +517,7 @@ public async Task RenderChangelogs_WithBundleHideFeatures_CommentsOutMatchingEnt await FileSystem.File.WriteAllTextAsync(changelogFile1, changelog1, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(changelogFile2, changelog2, TestContext.Current.CancellationToken); - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -541,7 +540,7 @@ public async Task RenderChangelogs_WithBundleHideFeatures_CommentsOutMatchingEnt """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -571,7 +570,7 @@ public async Task RenderChangelogs_WithBundleHideFeatures_CommentsOutMatchingEnt public async Task RenderChangelogs_MergesCLIAndBundleHideFeatures() { // Arrange - Test that CLI and bundle hide-features are merged - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // language=yaml @@ -619,7 +618,7 @@ public async Task RenderChangelogs_MergesCLIAndBundleHideFeatures() await FileSystem.File.WriteAllTextAsync(changelogFile2, changelog2, TestContext.Current.CancellationToken); await FileSystem.File.WriteAllTextAsync(changelogFile3, changelog3, TestContext.Current.CancellationToken); - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -645,7 +644,7 @@ public async Task RenderChangelogs_MergesCLIAndBundleHideFeatures() """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Render/HighlightsRenderTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Render/HighlightsRenderTests.cs index 2a878fbd1a..4cb3b2197b 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Render/HighlightsRenderTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Render/HighlightsRenderTests.cs @@ -5,7 +5,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; using Elastic.Changelog.Rendering; -using Elastic.Documentation.Configuration; namespace Elastic.Changelog.Tests.Changelogs.Render; @@ -15,7 +14,7 @@ public class HighlightsRenderTests(ITestOutputHelper output) : RenderChangelogTe public async Task RenderChangelogs_WithHighlightedEntries_CreatesHighlightsFile() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create test changelog file with highlight @@ -38,7 +37,7 @@ public async Task RenderChangelogs_WithHighlightedEntries_CreatesHighlightsFile( await FileSystem.File.WriteAllTextAsync(changelogFile, changelog1, TestContext.Current.CancellationToken); // Create bundle file - var bundleFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var bundleFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(bundleFile)!); // language=yaml @@ -54,7 +53,7 @@ public async Task RenderChangelogs_WithHighlightedEntries_CreatesHighlightsFile( """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -90,7 +89,7 @@ public async Task RenderChangelogs_WithHighlightedEntries_CreatesHighlightsFile( public async Task RenderChangelogs_WithoutHighlightedEntries_DoesNotCreateHighlightsFile() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create test changelog file without highlight @@ -110,7 +109,7 @@ public async Task RenderChangelogs_WithoutHighlightedEntries_DoesNotCreateHighli await FileSystem.File.WriteAllTextAsync(changelogFile, changelog1, TestContext.Current.CancellationToken); // Create bundle file - var bundleFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var bundleFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(bundleFile)!); // language=yaml @@ -126,7 +125,7 @@ public async Task RenderChangelogs_WithoutHighlightedEntries_DoesNotCreateHighli """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -150,7 +149,7 @@ public async Task RenderChangelogs_WithoutHighlightedEntries_DoesNotCreateHighli public async Task RenderChangelogs_WithHighlightedEntries_IncludesHighlightsInAsciidoc() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create test changelog file with highlight @@ -172,7 +171,7 @@ public async Task RenderChangelogs_WithHighlightedEntries_IncludesHighlightsInAs await FileSystem.File.WriteAllTextAsync(changelogFile, changelog1, TestContext.Current.CancellationToken); // Create bundle file - var bundleFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var bundleFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(bundleFile)!); // language=yaml @@ -188,7 +187,7 @@ public async Task RenderChangelogs_WithHighlightedEntries_IncludesHighlightsInAs """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -219,7 +218,7 @@ public async Task RenderChangelogs_WithHighlightedEntries_IncludesHighlightsInAs public async Task RenderChangelogs_WithMultipleHighlightedEntries_GroupsByArea() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create test changelog files with highlights @@ -259,7 +258,7 @@ public async Task RenderChangelogs_WithMultipleHighlightedEntries_GroupsByArea() await FileSystem.File.WriteAllTextAsync(file2, changelog2, TestContext.Current.CancellationToken); // Create bundle file - var bundleFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var bundleFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(bundleFile)!); // language=yaml @@ -278,7 +277,7 @@ public async Task RenderChangelogs_WithMultipleHighlightedEntries_GroupsByArea() """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Render/OutputFormatTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Render/OutputFormatTests.cs index 2fe22fb331..edb68c912c 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Render/OutputFormatTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Render/OutputFormatTests.cs @@ -5,7 +5,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; using Elastic.Changelog.Rendering; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; namespace Elastic.Changelog.Tests.Changelogs.Render; @@ -16,7 +15,7 @@ public class OutputFormatTests(ITestOutputHelper output) : RenderChangelogTestBa public async Task RenderChangelogs_WithCustomConfigPath_UsesSpecifiedConfigFile() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create changelog @@ -37,7 +36,7 @@ public async Task RenderChangelogs_WithCustomConfigPath_UsesSpecifiedConfigFile( await FileSystem.File.WriteAllTextAsync(changelogFile1, changelog1, TestContext.Current.CancellationToken); // Create config file in a custom location (not in docs/ subdirectory) - var customConfigDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var customConfigDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(customConfigDir); var customConfigPath = FileSystem.Path.Join(customConfigDir, "custom-changelog.yml"); // language=yaml @@ -54,7 +53,7 @@ public async Task RenderChangelogs_WithCustomConfigPath_UsesSpecifiedConfigFile( await FileSystem.File.WriteAllTextAsync(customConfigPath, configContent, TestContext.Current.CancellationToken); // Create bundle file - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -72,7 +71,7 @@ public async Task RenderChangelogs_WithCustomConfigPath_UsesSpecifiedConfigFile( await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); // Don't change directory - use custom config path via Config property - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -101,7 +100,7 @@ public async Task RenderChangelogs_WithCustomConfigPath_UsesSpecifiedConfigFile( public async Task RenderChangelogs_WithAsciidocFileType_CreatesSingleAsciidocFile() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create test changelog file @@ -122,7 +121,7 @@ public async Task RenderChangelogs_WithAsciidocFileType_CreatesSingleAsciidocFil await FileSystem.File.WriteAllTextAsync(changelogFile, changelog1, TestContext.Current.CancellationToken); // Create bundle file - var bundleFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var bundleFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(bundleFile)!); // language=yaml @@ -138,7 +137,7 @@ public async Task RenderChangelogs_WithAsciidocFileType_CreatesSingleAsciidocFil """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -179,7 +178,7 @@ public async Task RenderChangelogs_WithAsciidocFileType_CreatesSingleAsciidocFil public async Task RenderChangelogs_WithAsciidocFileType_ValidatesAsciidocFormat() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create test changelog files with different types @@ -233,7 +232,7 @@ public async Task RenderChangelogs_WithAsciidocFileType_ValidatesAsciidocFormat( await FileSystem.File.WriteAllTextAsync(breakingFile, breakingChangeChangelog, TestContext.Current.CancellationToken); // Create bundle file - var bundleFile = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml"); + var bundleFile = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml"); FileSystem.Directory.CreateDirectory(FileSystem.Path.GetDirectoryName(bundleFile)!); // language=yaml @@ -255,7 +254,7 @@ public async Task RenderChangelogs_WithAsciidocFileType_ValidatesAsciidocFormat( """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { diff --git a/tests/Elastic.Changelog.Tests/Changelogs/Render/TitleTargetTests.cs b/tests/Elastic.Changelog.Tests/Changelogs/Render/TitleTargetTests.cs index b6bf4c5767..4c90885704 100644 --- a/tests/Elastic.Changelog.Tests/Changelogs/Render/TitleTargetTests.cs +++ b/tests/Elastic.Changelog.Tests/Changelogs/Render/TitleTargetTests.cs @@ -5,7 +5,6 @@ using AwesomeAssertions; using Elastic.Changelog.Bundling; using Elastic.Changelog.Rendering; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; namespace Elastic.Changelog.Tests.Changelogs.Render; @@ -16,7 +15,7 @@ public class TitleTargetTests(ITestOutputHelper output) : RenderChangelogTestBas public async Task RenderChangelogs_WithoutTitleAndNoTargets_EmitsWarning() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create test changelog file without target @@ -35,7 +34,7 @@ public async Task RenderChangelogs_WithoutTitleAndNoTargets_EmitsWarning() await FileSystem.File.WriteAllTextAsync(changelogFile, changelog1, TestContext.Current.CancellationToken); // Create bundle file without target - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -51,7 +50,7 @@ public async Task RenderChangelogs_WithoutTitleAndNoTargets_EmitsWarning() """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { @@ -77,7 +76,7 @@ public async Task RenderChangelogs_WithoutTitleAndNoTargets_EmitsWarning() public async Task RenderChangelogs_WithTitleAndNoTargets_NoWarning() { // Arrange - var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(changelogDir); // Create test changelog file without target @@ -96,7 +95,7 @@ public async Task RenderChangelogs_WithTitleAndNoTargets_NoWarning() await FileSystem.File.WriteAllTextAsync(changelogFile, changelog1, TestContext.Current.CancellationToken); // Create bundle file without target - var bundleDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var bundleDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); FileSystem.Directory.CreateDirectory(bundleDir); var bundleFile = FileSystem.Path.Join(bundleDir, "bundle.yaml"); @@ -112,7 +111,7 @@ public async Task RenderChangelogs_WithTitleAndNoTargets_NoWarning() """; await FileSystem.File.WriteAllTextAsync(bundleFile, bundleContent, TestContext.Current.CancellationToken); - var outputDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString()); + var outputDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString()); var input = new RenderChangelogsArguments { diff --git a/tests/Elastic.Changelog.Tests/Creation/ChangelogCreationServiceTests.cs b/tests/Elastic.Changelog.Tests/Creation/ChangelogCreationServiceTests.cs index eecde62fbe..45d1b68437 100644 --- a/tests/Elastic.Changelog.Tests/Creation/ChangelogCreationServiceTests.cs +++ b/tests/Elastic.Changelog.Tests/Creation/ChangelogCreationServiceTests.cs @@ -33,9 +33,8 @@ public class ChangelogCreationServiceTests(ITestOutputHelper output) : Changelog cloud-serverless: "@Product:ESS" """; - private async Task WriteConfig(string content, string? path = null) + private async Task WriteConfig(string content, string path = "/tmp/config/changelog.yml") { - path ??= Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"); var dir = FileSystem.Path.GetDirectoryName(path)!; FileSystem.Directory.CreateDirectory(dir); await FileSystem.File.WriteAllTextAsync(path, content); @@ -68,7 +67,7 @@ private static IEnvironmentVariables FakeCIEnv( public async Task CreateChangelog_CIWithProducts_SkipsPrFetchAndSucceeds() { await WriteConfig(ConfigWithProductLabels); - FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "output")); + FileSystem.Directory.CreateDirectory("/tmp/output"); var env = FakeCIEnv( prNumber: "153344", @@ -83,8 +82,8 @@ public async Task CreateChangelog_CIWithProducts_SkipsPrFetchAndSucceeds() var input = new CreateChangelogArguments { Products = [], - Config = Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"), - Output = Path.Join(Paths.WorkingDirectoryRoot.FullName, "output"), + Config = "/tmp/config/changelog.yml", + Output = "/tmp/output", Concise = true }; @@ -105,7 +104,7 @@ public async Task CreateChangelog_CIWithProducts_SkipsPrFetchAndSucceeds() public async Task CreateChangelog_CIWithoutProducts_FallsBackToPrFetchForProducts() { await WriteConfig(ConfigWithProductLabels); - FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "output")); + FileSystem.Directory.CreateDirectory("/tmp/output"); A.CallTo(() => _mockGitHub.FetchPrInfoAsync("153344", "elastic", "cloud", A._)) .Returns(new GitHubPrInfo @@ -126,8 +125,8 @@ public async Task CreateChangelog_CIWithoutProducts_FallsBackToPrFetchForProduct var input = new CreateChangelogArguments { Products = [], - Config = Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"), - Output = Path.Join(Paths.WorkingDirectoryRoot.FullName, "output"), + Config = "/tmp/config/changelog.yml", + Output = "/tmp/output", Concise = true }; @@ -148,7 +147,7 @@ public async Task CreateChangelog_CIWithoutProducts_FallsBackToPrFetchForProduct public async Task CreateChangelog_CIWithoutProducts_NoPrProductLabels_FailsWithProductRequired() { await WriteConfig(ConfigWithProductLabels); - FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "output")); + FileSystem.Directory.CreateDirectory("/tmp/output"); A.CallTo(() => _mockGitHub.FetchPrInfoAsync("153344", "elastic", "cloud", A._)) .Returns(new GitHubPrInfo @@ -169,8 +168,8 @@ public async Task CreateChangelog_CIWithoutProducts_NoPrProductLabels_FailsWithP var input = new CreateChangelogArguments { Products = [], - Config = Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"), - Output = Path.Join(Paths.WorkingDirectoryRoot.FullName, "output"), + Config = "/tmp/config/changelog.yml", + Output = "/tmp/output", Concise = true }; diff --git a/tests/Elastic.Changelog.Tests/Elastic.Changelog.Tests.csproj b/tests/Elastic.Changelog.Tests/Elastic.Changelog.Tests.csproj index 20cfca0e69..3f27faeed0 100644 --- a/tests/Elastic.Changelog.Tests/Elastic.Changelog.Tests.csproj +++ b/tests/Elastic.Changelog.Tests/Elastic.Changelog.Tests.csproj @@ -12,7 +12,6 @@ - diff --git a/tests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs b/tests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs index 38f626af09..c32283c9f0 100644 --- a/tests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs +++ b/tests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs @@ -7,7 +7,6 @@ using Elastic.Changelog.Evaluation; using Elastic.Changelog.GitHub; using Elastic.Changelog.Tests.Changelogs; -using Elastic.Documentation.Configuration; using FakeItEasy; namespace Elastic.Changelog.Tests.Evaluation; @@ -76,7 +75,7 @@ private EvaluatePrArguments DefaultArgs( string? config = null ) { - config ??= Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"); + config ??= "/tmp/config/changelog.yml"; return new() { Config = config, @@ -94,9 +93,8 @@ private EvaluatePrArguments DefaultArgs( }; } - private async Task WriteMinimalConfig(string? configPath = null, string? content = null) + private async Task WriteMinimalConfig(string configPath = "/tmp/config/changelog.yml", string? content = null) { - configPath ??= Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"); var dir = FileSystem.Path.GetDirectoryName(configPath)!; FileSystem.Directory.CreateDirectory(dir); await FileSystem.File.WriteAllTextAsync(configPath, content ?? MinimalConfig); @@ -164,8 +162,8 @@ public async Task EvaluatePr_BotCommit_ReturnsSkipped() [Fact] public async Task EvaluatePr_ManuallyEdited_PrFilename_ReturnsManuallyEdited() { - FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog")); - await FileSystem.File.WriteAllTextAsync(Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog/42.yaml"), "title: test", TestContext.Current.CancellationToken); + FileSystem.Directory.CreateDirectory("docs/changelog"); + await FileSystem.File.WriteAllTextAsync("docs/changelog/42.yaml", "title: test", TestContext.Current.CancellationToken); A.CallTo(() => _mockGitHub.FetchLastFileCommitAuthorAsync( "elastic", "test-repo", "docs/changelog/42.yaml", "feature/test", A._)) @@ -183,8 +181,8 @@ public async Task EvaluatePr_ManuallyEdited_PrFilename_ReturnsManuallyEdited() [Fact] public async Task EvaluatePr_ManuallyEdited_TimestampFilename_ReturnsManuallyEdited() { - FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog")); - await FileSystem.File.WriteAllTextAsync(Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog/1735689600-fix-something.yaml"), + FileSystem.Directory.CreateDirectory("docs/changelog"); + await FileSystem.File.WriteAllTextAsync("docs/changelog/1735689600-fix-something.yaml", "title: Fix something\nprs:\n - \"42\"", TestContext.Current.CancellationToken); A.CallTo(() => _mockGitHub.FetchLastFileCommitAuthorAsync( @@ -247,9 +245,9 @@ public async Task EvaluatePr_NoTypeLabel_ReturnsNoLabel() [Fact] public async Task EvaluatePr_NoTypeLabel_WithProductConfig_OutputsProductLabelTable() { - await WriteMinimalConfig(Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"), ConfigWithProducts); + await WriteMinimalConfig("/tmp/config/changelog.yml", ConfigWithProducts); var service = CreateService(); - var args = DefaultArgs(prLabels: ["unrelated-label"], config: Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml")); + var args = DefaultArgs(prLabels: ["unrelated-label"], config: "/tmp/config/changelog.yml"); var result = await service.EvaluatePr(Collector, args, CancellationToken.None); @@ -262,9 +260,9 @@ public async Task EvaluatePr_NoTypeLabel_WithProductConfig_OutputsProductLabelTa [Fact] public async Task EvaluatePr_NoTypeLabel_WithProductLabels_DoesNotOutputProductLabelTable() { - await WriteMinimalConfig(Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"), ConfigWithProducts); + await WriteMinimalConfig("/tmp/config/changelog.yml", ConfigWithProducts); var service = CreateService(); - var args = DefaultArgs(prLabels: ["@Product:ECH"], config: Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml")); + var args = DefaultArgs(prLabels: ["@Product:ECH"], config: "/tmp/config/changelog.yml"); var result = await service.EvaluatePr(Collector, args, CancellationToken.None); @@ -378,8 +376,8 @@ public void BuildMappingTable_UsesCustomHeaders() public async Task EvaluatePr_ExistingTimestampFile_OutputsFilename() { await WriteMinimalConfig(); - FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog")); - await FileSystem.File.WriteAllTextAsync(Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog/1735689600-fix-something.yaml"), + FileSystem.Directory.CreateDirectory("docs/changelog"); + await FileSystem.File.WriteAllTextAsync("docs/changelog/1735689600-fix-something.yaml", "title: Fix something\nprs:\n - \"42\"", TestContext.Current.CancellationToken); var service = CreateService(); @@ -396,8 +394,8 @@ await FileSystem.File.WriteAllTextAsync(Path.Join(Paths.WorkingDirectoryRoot.Ful public async Task EvaluatePr_ExistingPrFile_OutputsFilename() { await WriteMinimalConfig(); - FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog")); - await FileSystem.File.WriteAllTextAsync(Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog/42.yaml"), "title: Fix something", TestContext.Current.CancellationToken); + FileSystem.Directory.CreateDirectory("docs/changelog"); + await FileSystem.File.WriteAllTextAsync("docs/changelog/42.yaml", "title: Fix something", TestContext.Current.CancellationToken); var service = CreateService(); var args = DefaultArgs(); @@ -412,12 +410,11 @@ public async Task EvaluatePr_ExistingPrFile_OutputsFilename() [Fact] public void FindExistingChangelog_PrFilename_FindsByName() { - var dir = Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog"); - FileSystem.Directory.CreateDirectory(dir); - FileSystem.File.WriteAllText(Path.Join(dir, "42.yaml"), "title: test"); + FileSystem.Directory.CreateDirectory("docs/changelog"); + FileSystem.File.WriteAllText("docs/changelog/42.yaml", "title: test"); var service = CreateService(); - var result = service.FindExistingChangelog(dir, 42); + var result = service.FindExistingChangelog("docs/changelog", 42); result.Should().Be("42.yaml"); } @@ -425,13 +422,12 @@ public void FindExistingChangelog_PrFilename_FindsByName() [Fact] public void FindExistingChangelog_TimestampFilename_FindsByContent() { - var dir = Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog"); - FileSystem.Directory.CreateDirectory(dir); - FileSystem.File.WriteAllText(Path.Join(dir, "1735689600-fix.yaml"), + FileSystem.Directory.CreateDirectory("docs/changelog"); + FileSystem.File.WriteAllText("docs/changelog/1735689600-fix.yaml", "title: Fix\nprs:\n - \"42\""); var service = CreateService(); - var result = service.FindExistingChangelog(dir, 42); + var result = service.FindExistingChangelog("docs/changelog", 42); result.Should().Be("1735689600-fix.yaml"); } @@ -439,13 +435,12 @@ public void FindExistingChangelog_TimestampFilename_FindsByContent() [Fact] public void FindExistingChangelog_GitHubUrl_FindsByContent() { - var dir = Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog"); - FileSystem.Directory.CreateDirectory(dir); - FileSystem.File.WriteAllText(Path.Join(dir, "1735689600-fix.yaml"), + FileSystem.Directory.CreateDirectory("docs/changelog"); + FileSystem.File.WriteAllText("docs/changelog/1735689600-fix.yaml", "title: Fix\nprs:\n - \"https://github.com/elastic/test-repo/pull/42\""); var service = CreateService(); - var result = service.FindExistingChangelog(dir, 42); + var result = service.FindExistingChangelog("docs/changelog", 42); result.Should().Be("1735689600-fix.yaml"); } @@ -453,12 +448,11 @@ public void FindExistingChangelog_GitHubUrl_FindsByContent() [Fact] public void FindExistingChangelog_NoMatch_ReturnsNull() { - var dir = Path.Join(Paths.WorkingDirectoryRoot.FullName, "docs/changelog"); - FileSystem.Directory.CreateDirectory(dir); - FileSystem.File.WriteAllText(Path.Join(dir, "99.yaml"), "title: other PR"); + FileSystem.Directory.CreateDirectory("docs/changelog"); + FileSystem.File.WriteAllText("docs/changelog/99.yaml", "title: other PR"); var service = CreateService(); - var result = service.FindExistingChangelog(dir, 42); + var result = service.FindExistingChangelog("docs/changelog", 42); result.Should().BeNull(); } @@ -467,7 +461,7 @@ public void FindExistingChangelog_NoMatch_ReturnsNull() public void FindExistingChangelog_DirectoryMissing_ReturnsNull() { var service = CreateService(); - var result = service.FindExistingChangelog(Path.Join(Paths.WorkingDirectoryRoot.FullName, "nonexistent/path"), 42); + var result = service.FindExistingChangelog("nonexistent/path", 42); result.Should().BeNull(); } @@ -485,11 +479,11 @@ public void ContentReferencesPr_MatchesPrNumberCorrectly(string content, bool ex [Fact] public async Task EvaluatePr_WithProductLabels_OutputsProductsAndNoTable() { - await WriteMinimalConfig(Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"), ConfigWithProducts); + await WriteMinimalConfig("/tmp/config/changelog.yml", ConfigWithProducts); var service = CreateService(); var args = DefaultArgs( prLabels: [">enhancement", "@Product:ECH", "@Product:ESS"], - config: Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml") + config: "/tmp/config/changelog.yml" ); var result = await service.EvaluatePr(Collector, args, CancellationToken.None); @@ -504,11 +498,11 @@ public async Task EvaluatePr_WithProductLabels_OutputsProductsAndNoTable() [Fact] public async Task EvaluatePr_WithoutProductLabels_OutputsProductLabelTable() { - await WriteMinimalConfig(Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"), ConfigWithProducts); + await WriteMinimalConfig("/tmp/config/changelog.yml", ConfigWithProducts); var service = CreateService(); var args = DefaultArgs( prLabels: ["type:feature"], - config: Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml") + config: "/tmp/config/changelog.yml" ); var result = await service.EvaluatePr(Collector, args, CancellationToken.None); diff --git a/tests/Elastic.Documentation.Configuration.Tests/CrossLinkRegistryTests.cs b/tests/Elastic.Documentation.Configuration.Tests/CrossLinkRegistryTests.cs index d1cf66a8f6..8f4331dfdc 100644 --- a/tests/Elastic.Documentation.Configuration.Tests/CrossLinkRegistryTests.cs +++ b/tests/Elastic.Documentation.Configuration.Tests/CrossLinkRegistryTests.cs @@ -6,12 +6,12 @@ using System.IO.Abstractions; using System.IO.Abstractions.TestingHelpers; using AwesomeAssertions; +using Elastic.Documentation; using Elastic.Documentation.Configuration.Builder; using Elastic.Documentation.Configuration.Products; using Elastic.Documentation.Configuration.Toc; using Elastic.Documentation.Configuration.Versions; using Elastic.Documentation.Diagnostics; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Configuration.Tests; @@ -132,8 +132,8 @@ private sealed class MockDocumentationSetContext( : IDocumentationSetContext { public IDiagnosticsCollector Collector => collector; - public ScopedFileSystem ReadFileSystem => WriteFileSystem; - public ScopedFileSystem WriteFileSystem { get; } = FileSystemFactory.ScopeCurrentWorkingDirectoryForWrite(fileSystem); + public IFileSystem ReadFileSystem => fileSystem; + public IFileSystem WriteFileSystem => fileSystem; public IDirectoryInfo OutputDirectory => fileSystem.DirectoryInfo.New(Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts")); public IFileInfo ConfigurationPath => configurationPath; public BuildType BuildType => BuildType.Isolated; diff --git a/tests/Elastic.Documentation.Configuration.Tests/DocumentationSetFileTests.cs b/tests/Elastic.Documentation.Configuration.Tests/DocumentationSetFileTests.cs index 4d537ef51b..e5d8896596 100644 --- a/tests/Elastic.Documentation.Configuration.Tests/DocumentationSetFileTests.cs +++ b/tests/Elastic.Documentation.Configuration.Tests/DocumentationSetFileTests.cs @@ -8,7 +8,6 @@ using Elastic.Documentation.Configuration.Toc; using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Extensions; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Configuration.Tests; @@ -634,7 +633,7 @@ public void LoadAndResolveResolvesIsolatedTocReferences() var docsetPath = fileSystem.FileInfo.New("/docs/docset.yml"); var collector = new DiagnosticsCollector([]); - var result = DocumentationSetFile.LoadAndResolve(collector, docsetPath, new ScopedFileSystem(fileSystem, "/docs")); + var result = DocumentationSetFile.LoadAndResolve(collector, docsetPath, fileSystem); // Verify TOC references have been preserved (not flattened) // We have 3 top-level items: index.md, development TOC, and guides folder @@ -705,7 +704,7 @@ public void LoadAndResolvePrependsParentPathsToFileReferences() var docsetPath = fileSystem.FileInfo.New("/docs/docset.yml"); var collector = new DiagnosticsCollector([]); - var result = DocumentationSetFile.LoadAndResolve(collector, docsetPath, new ScopedFileSystem(fileSystem, "/docs")); + var result = DocumentationSetFile.LoadAndResolve(collector, docsetPath, fileSystem); result.TableOfContents.Should().HaveCount(2); @@ -761,7 +760,7 @@ public void LoadAndResolveSetsContextForAllItems() var docsetPath = fileSystem.FileInfo.New("/docs/docset.yml"); var collector = new DiagnosticsCollector([]); - var result = DocumentationSetFile.LoadAndResolve(collector, docsetPath, new ScopedFileSystem(fileSystem, "/docs")); + var result = DocumentationSetFile.LoadAndResolve(collector, docsetPath, fileSystem); var docset = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:/docs/docset.yml" : "/docs/docset.yml"; var toc = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:/docs/development/toc.yml" : "/docs/development/toc.yml"; @@ -825,7 +824,7 @@ public void LoadAndResolveSetsPathRelativeToContainerCorrectly() var docsetPath = fileSystem.FileInfo.New("/docs/docset.yml"); var collector = new DiagnosticsCollector([]); - var result = DocumentationSetFile.LoadAndResolve(collector, docsetPath, new ScopedFileSystem(fileSystem, "/docs")); + var result = DocumentationSetFile.LoadAndResolve(collector, docsetPath, fileSystem); // Items in docset.yml: PathRelativeToContainer should equal PathRelativeToDocumentationSet result.TableOfContents.ElementAt(0).Should().BeOfType() diff --git a/tests/Elastic.Documentation.Configuration.Tests/GitCommonRootTests.cs b/tests/Elastic.Documentation.Configuration.Tests/GitCommonRootTests.cs new file mode 100644 index 0000000000..ad5d3b0dce --- /dev/null +++ b/tests/Elastic.Documentation.Configuration.Tests/GitCommonRootTests.cs @@ -0,0 +1,98 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using System.IO.Abstractions.TestingHelpers; +using AwesomeAssertions; + +namespace Elastic.Documentation.Configuration.Tests; + +public class GitCommonRootTests +{ + [Fact] + public void NormalRepo_ReturnsWorkingDirectoryRoot() + { + var fs = new MockFileSystem(); + fs.AddDirectory("/repo/.git"); + var root = fs.DirectoryInfo.New("/repo"); + + var result = Paths.ResolveGitCommonRoot(fs, root, isCI: false); + + result.FullName.Should().Be(root.FullName); + } + + [Fact] + public void Worktree_AbsoluteGitDir_ReturnsMainRepoRoot() + { + var fs = new MockFileSystem(); + fs.AddFile("/worktree/.git", new MockFileData("gitdir: /main-repo/.git/worktrees/feature-branch")); + fs.AddDirectory("/main-repo/.git/worktrees/feature-branch"); + var root = fs.DirectoryInfo.New("/worktree"); + + var result = Paths.ResolveGitCommonRoot(fs, root, isCI: false); + + result.FullName.Should().Be(fs.DirectoryInfo.New("/main-repo").FullName); + } + + [Fact] + public void Worktree_RelativeGitDir_ReturnsMainRepoRoot() + { + var fs = new MockFileSystem(); + fs.AddFile("/repos/worktree/.git", new MockFileData("gitdir: ../main-repo/.git/worktrees/feature-branch")); + fs.AddDirectory("/repos/main-repo/.git/worktrees/feature-branch"); + var root = fs.DirectoryInfo.New("/repos/worktree"); + + var result = Paths.ResolveGitCommonRoot(fs, root, isCI: false); + + result.FullName.Should().Be(fs.DirectoryInfo.New("/repos/main-repo").FullName); + } + + [Fact] + public void NoGitPresent_ReturnsWorkingDirectoryRoot() + { + var fs = new MockFileSystem(); + fs.AddDirectory("/repo"); + var root = fs.DirectoryInfo.New("/repo"); + + var result = Paths.ResolveGitCommonRoot(fs, root, isCI: false); + + result.FullName.Should().Be(root.FullName); + } + + [Fact] + public void MalformedGitFile_ReturnsWorkingDirectoryRoot() + { + var fs = new MockFileSystem(); + fs.AddFile("/repo/.git", new MockFileData("not a valid gitdir reference")); + var root = fs.DirectoryInfo.New("/repo"); + + var result = Paths.ResolveGitCommonRoot(fs, root, isCI: false); + + result.FullName.Should().Be(root.FullName); + } + + [Fact] + public void Worktree_GitDirPathHasNoGitAncestor_ReturnsWorkingDirectoryRoot() + { + var fs = new MockFileSystem(); + fs.AddFile("/worktree/.git", new MockFileData("gitdir: /some/path/without/git/ancestor")); + var root = fs.DirectoryInfo.New("/worktree"); + + var result = Paths.ResolveGitCommonRoot(fs, root, isCI: false); + + result.FullName.Should().Be(root.FullName); + } + + [Fact] + public void OnCI_Worktree_ReturnsWorkingDirectoryRoot() + { + var fs = new MockFileSystem(); + fs.AddFile("/worktree/.git", new MockFileData("gitdir: /main-repo/.git/worktrees/feature-branch")); + fs.AddDirectory("/main-repo/.git/worktrees/feature-branch"); + var root = fs.DirectoryInfo.New("/worktree"); + + var result = Paths.ResolveGitCommonRoot(fs, root, isCI: true); + + result.FullName.Should().Be(root.FullName); + } +} diff --git a/tests/Elastic.Markdown.Tests/Assembler/AssemblerHtmxMarkdownLinkTests.cs b/tests/Elastic.Markdown.Tests/Assembler/AssemblerHtmxMarkdownLinkTests.cs index 9698c3f306..e48a189b79 100644 --- a/tests/Elastic.Markdown.Tests/Assembler/AssemblerHtmxMarkdownLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Assembler/AssemblerHtmxMarkdownLinkTests.cs @@ -9,7 +9,6 @@ using Elastic.Documentation.Diagnostics; using Elastic.Markdown.IO; using Elastic.Markdown.Tests.Inline; -using Nullean.ScopedFileSystem; using Xunit; namespace Elastic.Markdown.Tests.Assembler; @@ -21,7 +20,7 @@ protected override BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs/platform/elasticsearch", BuildType = BuildType.Assembler @@ -57,7 +56,7 @@ protected override BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs/platform/elasticsearch", BuildType = BuildType.Assembler @@ -88,7 +87,7 @@ protected override BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs", BuildType = BuildType.Assembler @@ -119,7 +118,7 @@ protected override BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs/platform/elasticsearch", BuildType = BuildType.Assembler @@ -150,7 +149,7 @@ protected override BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs/platform/elasticsearch", BuildType = BuildType.Assembler @@ -189,7 +188,7 @@ protected override BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs/platform/elasticsearch", BuildType = BuildType.Assembler @@ -219,7 +218,7 @@ protected override BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs/platform/elasticsearch", BuildType = BuildType.Assembler diff --git a/tests/Elastic.Markdown.Tests/Codex/CodexHtmxCrossLinkTests.cs b/tests/Elastic.Markdown.Tests/Codex/CodexHtmxCrossLinkTests.cs index 36554b11a5..427484cc39 100644 --- a/tests/Elastic.Markdown.Tests/Codex/CodexHtmxCrossLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Codex/CodexHtmxCrossLinkTests.cs @@ -9,7 +9,6 @@ using Elastic.Documentation.Links.CrossLinks; using Elastic.Markdown.IO; using Elastic.Markdown.Tests.Inline; -using Nullean.ScopedFileSystem; namespace Elastic.Markdown.Tests.Codex; @@ -20,7 +19,7 @@ protected override BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/r/codex-environments", BuildType = BuildType.Codex @@ -63,7 +62,7 @@ protected override BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs", BuildType = BuildType.Isolated diff --git a/tests/Elastic.Markdown.Tests/Directives/CsvIncludeTests.cs b/tests/Elastic.Markdown.Tests/Directives/CsvIncludeTests.cs index 0307f5ff3d..f9ed48745c 100644 --- a/tests/Elastic.Markdown.Tests/Directives/CsvIncludeTests.cs +++ b/tests/Elastic.Markdown.Tests/Directives/CsvIncludeTests.cs @@ -4,7 +4,6 @@ using System.IO.Abstractions.TestingHelpers; using AwesomeAssertions; -using Elastic.Documentation.Configuration; using Elastic.Markdown.Myst.Directives.CsvInclude; namespace Elastic.Markdown.Tests.Directives; @@ -38,7 +37,7 @@ public CsvIncludeTests(ITestOutputHelper output) : base(output, [Fact] public void ParsesCsvDataCorrectly() { - var csvData = CsvReader.ReadCsvFile(Block!.CsvFilePath!, Block.Separator, FileSystemFactory.ScopeCurrentWorkingDirectory(FileSystem)).ToList(); + var csvData = CsvReader.ReadCsvFile(Block!.CsvFilePath!, Block.Separator, FileSystem).ToList(); csvData.Should().HaveCount(4); csvData[0].Should().BeEquivalentTo(["Name", "Age", "City"]); csvData[1].Should().BeEquivalentTo(["John Doe", "30", "New York"]); @@ -72,7 +71,7 @@ public CsvIncludeWithOptionsTests(ITestOutputHelper output) : base(output, [Fact] public void ParsesWithCustomSeparator() { - var csvData = CsvReader.ReadCsvFile(Block!.CsvFilePath!, Block.Separator, FileSystemFactory.ScopeCurrentWorkingDirectory(FileSystem)).ToList(); + var csvData = CsvReader.ReadCsvFile(Block!.CsvFilePath!, Block.Separator, FileSystem).ToList(); csvData.Should().HaveCount(3); csvData[0].Should().BeEquivalentTo(["Name", "Age", "City"]); csvData[1].Should().BeEquivalentTo(["John Doe", "30", "New York"]); @@ -94,7 +93,7 @@ public CsvIncludeWithQuotesTests(ITestOutputHelper output) : base(output, [Fact] public void HandlesQuotedFieldsWithCommas() { - var csvData = CsvReader.ReadCsvFile(Block!.CsvFilePath!, Block.Separator, FileSystemFactory.ScopeCurrentWorkingDirectory(FileSystem)).ToList(); + var csvData = CsvReader.ReadCsvFile(Block!.CsvFilePath!, Block.Separator, FileSystem).ToList(); csvData.Should().HaveCount(3); csvData[0].Should().BeEquivalentTo(["Name", "Description", "Location"]); csvData[1].Should().BeEquivalentTo(["John Doe", "Software Engineer, Senior", "New York"]); @@ -116,7 +115,7 @@ public CsvIncludeWithEscapedQuotesTests(ITestOutputHelper output) : base(output, [Fact] public void HandlesEscapedQuotes() { - var csvData = CsvReader.ReadCsvFile(Block!.CsvFilePath!, Block.Separator, FileSystemFactory.ScopeCurrentWorkingDirectory(FileSystem)).ToList(); + var csvData = CsvReader.ReadCsvFile(Block!.CsvFilePath!, Block.Separator, FileSystem).ToList(); csvData.Should().HaveCount(3); csvData[0].Should().BeEquivalentTo(["Name", "Description"]); csvData[1].Should().BeEquivalentTo(["John Doe", "He said \"Hello World\" today"]); diff --git a/tests/Elastic.Markdown.Tests/Directives/DirectiveBaseTests.cs b/tests/Elastic.Markdown.Tests/Directives/DirectiveBaseTests.cs index 62389d448b..a538b23d87 100644 --- a/tests/Elastic.Markdown.Tests/Directives/DirectiveBaseTests.cs +++ b/tests/Elastic.Markdown.Tests/Directives/DirectiveBaseTests.cs @@ -8,7 +8,6 @@ using Elastic.Markdown.Myst.Directives; using JetBrains.Annotations; using Markdig.Syntax; -using Nullean.ScopedFileSystem; namespace Elastic.Markdown.Tests.Directives; @@ -71,7 +70,7 @@ protected DirectiveTest(ITestOutputHelper output, [LanguageInjection("markdown") Collector = new TestDiagnosticsCollector(output); var configurationContext = TestHelpers.CreateConfigurationContext(FileSystem); - var context = new BuildContext(Collector, FileSystemFactory.ScopeCurrentWorkingDirectory(FileSystem), configurationContext); + var context = new BuildContext(Collector, FileSystem, configurationContext); var linkResolver = new TestCrossLinkResolver(); Set = new DocumentationSet(context, logger, linkResolver); File = Set.TryFindDocument(FileSystem.FileInfo.New("docs/index.md")) as MarkdownFile ?? throw new NullReferenceException(); diff --git a/tests/Elastic.Markdown.Tests/DocSet/NavigationTestsBase.cs b/tests/Elastic.Markdown.Tests/DocSet/NavigationTestsBase.cs index 42ea8a5ff3..f89b75668b 100644 --- a/tests/Elastic.Markdown.Tests/DocSet/NavigationTestsBase.cs +++ b/tests/Elastic.Markdown.Tests/DocSet/NavigationTestsBase.cs @@ -10,7 +10,6 @@ using Elastic.Documentation.Configuration.Builder; using Elastic.Markdown.IO; using Microsoft.Extensions.Logging; -using Nullean.ScopedFileSystem; namespace Elastic.Markdown.Tests.DocSet; @@ -19,12 +18,11 @@ public class NavigationTestsBase : IAsyncLifetime protected NavigationTestsBase(ITestOutputHelper output) { LoggerFactory = new TestLoggerFactory(output); - var mockWriteFs = new MockFileSystem(new MockFileSystemOptions //use in memory mock fs to test generation + ReadFileSystem = new FileSystem(); //use real IO to read docs. + WriteFileSystem = new MockFileSystem(new MockFileSystemOptions //use in memory mock fs to test generation { CurrentDirectory = Paths.WorkingDirectoryRoot.FullName }); - ReadFileSystem = FileSystemFactory.RealRead; - WriteFileSystem = FileSystemFactory.ScopeCurrentWorkingDirectory(mockWriteFs); var collector = new TestDiagnosticsCollector(output); var configurationContext = TestHelpers.CreateConfigurationContext(ReadFileSystem); var context = new BuildContext(collector, ReadFileSystem, WriteFileSystem, configurationContext, ExportOptions.Default) @@ -42,8 +40,8 @@ protected NavigationTestsBase(ITestOutputHelper output) protected ILoggerFactory LoggerFactory { get; } - protected ScopedFileSystem ReadFileSystem { get; set; } - protected ScopedFileSystem WriteFileSystem { get; set; } + protected FileSystem ReadFileSystem { get; set; } + protected IFileSystem WriteFileSystem { get; set; } protected DocumentationSet Set { get; } protected DocumentationGenerator Generator { get; } protected ConfigurationFile? Configuration { get; set; } diff --git a/tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj b/tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj index a2a90aa4d3..3c3a200e32 100644 --- a/tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj +++ b/tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj @@ -7,7 +7,6 @@ - diff --git a/tests/Elastic.Markdown.Tests/Inline/ImagePathResolutionTests.cs b/tests/Elastic.Markdown.Tests/Inline/ImagePathResolutionTests.cs index 07b4a2cd26..385e737789 100644 --- a/tests/Elastic.Markdown.Tests/Inline/ImagePathResolutionTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/ImagePathResolutionTests.cs @@ -15,7 +15,6 @@ using Elastic.Markdown.Myst; using Elastic.Markdown.Myst.InlineParsers; using Elastic.Markdown.Tests; -using Nullean.ScopedFileSystem; using Xunit; namespace Elastic.Markdown.Tests.Inline; @@ -93,7 +92,7 @@ private async Task ResolveUrlForBuildMode(string relativeAssetPath, Bu _ = collector.StartAsync(TestContext.Current.CancellationToken); var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem); - var buildContext = new BuildContext(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + var buildContext = new BuildContext(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs", BuildType = buildType diff --git a/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs index a42ee0ea4e..9053344ac2 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs @@ -10,7 +10,6 @@ using JetBrains.Annotations; using Markdig.Syntax; using Markdig.Syntax.Inlines; -using Nullean.ScopedFileSystem; namespace Elastic.Markdown.Tests.Inline; @@ -133,7 +132,7 @@ protected virtual BuildContext CreateBuildContext( TestDiagnosticsCollector collector, MockFileSystem fileSystem, IConfigurationContext configurationContext) => - new(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext) + new(collector, fileSystem, configurationContext) { UrlPathPrefix = "/docs" }; diff --git a/tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs b/tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs index 82a69f20a5..013366b3e4 100644 --- a/tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs +++ b/tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs @@ -7,7 +7,6 @@ using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; using Elastic.Markdown.IO; -using Nullean.ScopedFileSystem; namespace Elastic.Markdown.Tests; @@ -33,7 +32,7 @@ public async Task CreatesDefaultOutputDirectory() }); await using var collector = new DiagnosticsCollector([]).StartAsync(TestContext.Current.CancellationToken); var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem); - var context = new BuildContext(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext); + var context = new BuildContext(collector, fileSystem, configurationContext); var linkResolver = new TestCrossLinkResolver(); var set = new DocumentationSet(context, logger, linkResolver); var generator = new DocumentationGenerator(set, logger); diff --git a/tests/Elastic.Markdown.Tests/RootIndexValidationTests.cs b/tests/Elastic.Markdown.Tests/RootIndexValidationTests.cs index 4c29e609e7..e3a29bad57 100644 --- a/tests/Elastic.Markdown.Tests/RootIndexValidationTests.cs +++ b/tests/Elastic.Markdown.Tests/RootIndexValidationTests.cs @@ -8,7 +8,6 @@ using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; using Elastic.Markdown.IO; -using Nullean.ScopedFileSystem; namespace Elastic.Markdown.Tests; @@ -34,7 +33,7 @@ public void InternalRegistry_MissingIndexMd_EmitsError() var collector = new TestDiagnosticsCollector(output); _ = collector.StartAsync(TestContext.Current.CancellationToken); var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem); - var context = new BuildContext(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext); + var context = new BuildContext(collector, fileSystem, configurationContext); _ = new DocumentationSet(context, logger, new TestCrossLinkResolver()); collector.Errors.Should().BeGreaterThan(0); @@ -65,7 +64,7 @@ public void InternalRegistry_WithIndexMd_NoError() var collector = new TestDiagnosticsCollector(output); _ = collector.StartAsync(TestContext.Current.CancellationToken); var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem); - var context = new BuildContext(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext); + var context = new BuildContext(collector, fileSystem, configurationContext); _ = new DocumentationSet(context, logger, new TestCrossLinkResolver()); collector.Diagnostics @@ -93,7 +92,7 @@ public void PublicRegistry_MissingIndexMd_NoError() var collector = new TestDiagnosticsCollector(output); _ = collector.StartAsync(TestContext.Current.CancellationToken); var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem); - var context = new BuildContext(collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), configurationContext); + var context = new BuildContext(collector, fileSystem, configurationContext); _ = new DocumentationSet(context, logger, new TestCrossLinkResolver()); collector.Diagnostics diff --git a/tests/Navigation.Tests/Assembler/ComplexSiteNavigationTests.cs b/tests/Navigation.Tests/Assembler/ComplexSiteNavigationTests.cs index b1b1b1eb97..33807f5bf5 100644 --- a/tests/Navigation.Tests/Assembler/ComplexSiteNavigationTests.cs +++ b/tests/Navigation.Tests/Assembler/ComplexSiteNavigationTests.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information using AwesomeAssertions; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.Toc; using Elastic.Documentation.Navigation.Assembler; using Elastic.Documentation.Navigation.Isolated; @@ -52,7 +51,7 @@ public void ComplexNavigationWithMultipleNestedTocsAppliesPathPrefixToRootUrls() ? $"{repo.FullName}/docs/docset.yml" : $"{repo.FullName}/docs/_docset.yml"; - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, fileSystem.FileInfo.New(docsetPath), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, fileSystem.FileInfo.New(docsetPath), fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); documentationSets.Add(navigation); @@ -130,7 +129,7 @@ public void DeeplyNestedNavigationMaintainsPathPrefixThroughoutHierarchy() var platformContext = SiteNavigationTestFixture.CreateAssemblerContext(fileSystem, "/checkouts/current/platform", output); var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, - fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var documentationSets = new List { @@ -181,7 +180,7 @@ public void FileNavigationLeafUrlsReflectPathPrefixInDeeplyNestedStructures() var platformContext = SiteNavigationTestFixture.CreateAssemblerContext(fileSystem, "/checkouts/current/platform", output); var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, - fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var documentationSets = new List { @@ -243,7 +242,7 @@ public void FolderNavigationWithinNestedTocsHasCorrectPathPrefix() var platformContext = SiteNavigationTestFixture.CreateContext( fileSystem, "/checkouts/current/platform", output); var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, - fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var documentationSets = new List { diff --git a/tests/Navigation.Tests/Assembler/IdentifierCollectionTests.cs b/tests/Navigation.Tests/Assembler/IdentifierCollectionTests.cs index 9936f9f569..8e59182b75 100644 --- a/tests/Navigation.Tests/Assembler/IdentifierCollectionTests.cs +++ b/tests/Navigation.Tests/Assembler/IdentifierCollectionTests.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information using AwesomeAssertions; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.Toc; using Elastic.Documentation.Navigation.Isolated; using Elastic.Documentation.Navigation.Isolated.Node; @@ -21,7 +20,7 @@ public void DocumentationSetNavigationCollectsRootIdentifier() var platformContext = SiteNavigationTestFixture.CreateContext( fileSystem, "/checkouts/current/platform", output); var platformDocset = DocumentationSetFile.LoadAndResolve( - platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var platformNav = new DocumentationSetNavigation(platformDocset, platformContext, GenericDocumentationFileFactory.Instance); // Root identifier should be :// @@ -36,7 +35,7 @@ public void DocumentationSetNavigationCollectsNestedTocIdentifiers() // Test platform repository with nested TOCs var platformContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/platform", output); - var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, platformContext.ConfigurationPath, FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, platformContext.ConfigurationPath, fileSystem); var platformNav = new DocumentationSetNavigation(platformDocset, platformContext, GenericDocumentationFileFactory.Instance); // Should collect identifiers from nested TOCs @@ -57,7 +56,7 @@ public void DocumentationSetNavigationWithSimpleStructure() // Test observability repository (no nested TOCs) var observabilityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); - var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); var observabilityNav = new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance); // Should only have root identifier @@ -74,7 +73,7 @@ public void TableOfContentsNavigationHasCorrectIdentifier() var platformContext = SiteNavigationTestFixture.CreateContext( fileSystem, "/checkouts/current/platform", output); var platformDocset = DocumentationSetFile.LoadAndResolve( - platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var platformNav = new DocumentationSetNavigation(platformDocset, platformContext, GenericDocumentationFileFactory.Instance); // Get the deployment-guide TOC @@ -97,13 +96,13 @@ public void MultipleDocumentationSetsHaveDistinctIdentifiers() var platformContext = SiteNavigationTestFixture.CreateContext( fileSystem, "/checkouts/current/platform", output); var platformDocset = DocumentationSetFile.LoadAndResolve( - platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var platformNav = new DocumentationSetNavigation(platformDocset, platformContext, GenericDocumentationFileFactory.Instance); var observabilityContext = SiteNavigationTestFixture.CreateContext( fileSystem, "/checkouts/current/observability", output); var observabilityDocset = DocumentationSetFile.LoadAndResolve( - observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); var observabilityNav = new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance); // Each should have its own set of identifiers diff --git a/tests/Navigation.Tests/Assembler/SiteDocumentationSetsTests.cs b/tests/Navigation.Tests/Assembler/SiteDocumentationSetsTests.cs index 821abe8497..256d8087d1 100644 --- a/tests/Navigation.Tests/Assembler/SiteDocumentationSetsTests.cs +++ b/tests/Navigation.Tests/Assembler/SiteDocumentationSetsTests.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information using AwesomeAssertions; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.Toc; using Elastic.Documentation.Navigation.Assembler; using Elastic.Documentation.Navigation.Isolated; @@ -47,7 +46,7 @@ public void CreatesDocumentationSetNavigationsFromCheckoutFolders() ? $"{repo.FullName}/docs/docset.yml" : $"{repo.FullName}/docs/_docset.yml"; - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, fileSystem.FileInfo.New(docsetPath), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, fileSystem.FileInfo.New(docsetPath), fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); documentationSets.Add(navigation); @@ -84,15 +83,15 @@ public void SiteNavigationIntegratesWithDocumentationSets() var documentationSets = new List(); var observabilityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); - var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); documentationSets.Add(new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance)); var searchContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/serverless-search", output); - var searchDocset = DocumentationSetFile.LoadAndResolve(searchContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-search/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var searchDocset = DocumentationSetFile.LoadAndResolve(searchContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-search/docs/docset.yml"), fileSystem); documentationSets.Add(new DocumentationSetNavigation(searchDocset, searchContext, GenericDocumentationFileFactory.Instance)); var securityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/serverless-security", output); - var securityDocset = DocumentationSetFile.LoadAndResolve(securityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-security/docs/_docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var securityDocset = DocumentationSetFile.LoadAndResolve(securityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-security/docs/_docset.yml"), fileSystem); documentationSets.Add(new DocumentationSetNavigation(securityDocset, securityContext, GenericDocumentationFileFactory.Instance)); // Create site navigation context (using any repository's filesystem) @@ -134,7 +133,7 @@ public void SiteNavigationWithNestedTocs() // Create DocumentationSetNavigation for platform var platformContext = SiteNavigationTestFixture.CreateAssemblerContext(fileSystem, "/checkouts/current/platform", output); - var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var platformNav = new DocumentationSetNavigation(platformDocset, platformContext, GenericDocumentationFileFactory.Instance); platformNav.Url.Should().Be("/"); platformNav.Index.Url.Should().Be("/"); @@ -201,7 +200,7 @@ public void SiteNavigationWithAllRepositories() ? $"{repo.FullName}/docs/docset.yml" : $"{repo.FullName}/docs/_docset.yml"; - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, fileSystem.FileInfo.New(docsetPath), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, fileSystem.FileInfo.New(docsetPath), fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); documentationSets.Add(navigation); @@ -241,7 +240,7 @@ public void DocumentationSetNavigationHasCorrectStructure() // Test observability repository structure var observabilityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); - var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); var observabilityNav = new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance); observabilityNav.NavigationTitle.Should().Be(observabilityNav.NavigationTitle); @@ -270,7 +269,7 @@ public void DocumentationSetWithNestedTocs() // Test platform repository with nested TOCs var platformContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/platform", output); - var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var platformNav = new DocumentationSetNavigation(platformDocset, platformContext, GenericDocumentationFileFactory.Instance); platformNav.NavigationTitle.Should().Be("Platform"); @@ -300,7 +299,7 @@ public void DocumentationSetWithUnderscoreDocset() // Test serverless-security repository with _docset.yml var securityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/serverless-security", output); - var securityDocset = DocumentationSetFile.LoadAndResolve(securityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-security/docs/_docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var securityDocset = DocumentationSetFile.LoadAndResolve(securityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-security/docs/_docset.yml"), fileSystem); var securityNav = new DocumentationSetNavigation(securityDocset, securityContext, GenericDocumentationFileFactory.Instance); securityNav.NavigationTitle.Should().Be("Serverless Security"); @@ -331,7 +330,7 @@ public void SiteNavigationAppliesPathPrefixToAllUrls() var fileSystem = SiteNavigationTestFixture.CreateMultiRepositoryFileSystem(); var observabilityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); - var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); var documentationSets = new List { new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance) }; var siteContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); @@ -368,7 +367,7 @@ public void SiteNavigationWithNestedTocsAppliesCorrectPathPrefixes() var fileSystem = SiteNavigationTestFixture.CreateMultiRepositoryFileSystem(); var platformContext = SiteNavigationTestFixture.CreateAssemblerContext(fileSystem, "/checkouts/current/platform", output); - var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var documentationSets = new List { new DocumentationSetNavigation(platformDocset, platformContext, GenericDocumentationFileFactory.Instance) }; var siteContext = SiteNavigationTestFixture.CreateAssemblerContext(fileSystem, "/checkouts/current/platform", output); @@ -399,7 +398,7 @@ public void SiteNavigationRequiresPathPrefix() var fileSystem = SiteNavigationTestFixture.CreateMultiRepositoryFileSystem(); var observabilityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); - var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); var documentationSets = new List { new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance) }; var siteContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); @@ -422,7 +421,7 @@ public void ObservabilityDocumentationSetNavigationHasNoDiagnostics() var context = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); var docsetPath = fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"); - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); @@ -442,7 +441,7 @@ public void ServerlessSearchDocumentationSetNavigationHasNoDiagnostics() var context = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/serverless-search", output); var docsetPath = fileSystem.FileInfo.New("/checkouts/current/serverless-search/docs/docset.yml"); - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); @@ -462,7 +461,7 @@ public void ServerlessSecurityDocumentationSetNavigationHasNoDiagnostics() var context = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/serverless-security", output); var docsetPath = fileSystem.FileInfo.New("/checkouts/current/serverless-security/docs/_docset.yml"); - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); @@ -482,7 +481,7 @@ public void PlatformDocumentationSetNavigationHasNoDiagnostics() var context = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/platform", output); var docsetPath = fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"); - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); @@ -502,7 +501,7 @@ public void ElasticsearchReferenceDocumentationSetNavigationHasNoDiagnostics() var context = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/elasticsearch-reference", output); var docsetPath = fileSystem.FileInfo.New("/checkouts/current/elasticsearch-reference/docs/docset.yml"); - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); @@ -533,7 +532,7 @@ public void AllDocumentationSetsHaveNoDiagnostics() ? $"{repo.FullName}/docs/docset.yml" : $"{repo.FullName}/docs/_docset.yml"; - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, fileSystem.FileInfo.New(docsetPath), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, fileSystem.FileInfo.New(docsetPath), fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); @@ -554,7 +553,7 @@ public void DocumentationSetNavigationWithNestedTocsHasNoDiagnostics() var context = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/platform", output); var docsetPath = fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"); - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); @@ -580,7 +579,7 @@ public void DocumentationSetNavigationWithFoldersHasNoDiagnostics() var context = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); var docsetPath = fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"); - var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var docset = DocumentationSetFile.LoadAndResolve(context.Collector, docsetPath, fileSystem); var navigation = new DocumentationSetNavigation(docset, context, GenericDocumentationFileFactory.Instance); diff --git a/tests/Navigation.Tests/Assembler/SiteNavigationTests.cs b/tests/Navigation.Tests/Assembler/SiteNavigationTests.cs index c79316636d..d798a88fde 100644 --- a/tests/Navigation.Tests/Assembler/SiteNavigationTests.cs +++ b/tests/Navigation.Tests/Assembler/SiteNavigationTests.cs @@ -4,7 +4,6 @@ using System.IO.Abstractions.TestingHelpers; using AwesomeAssertions; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.Toc; using Elastic.Documentation.Navigation.Assembler; using Elastic.Documentation.Navigation.Isolated; @@ -42,11 +41,11 @@ public void ConstructorCreatesSiteNavigation() // Create DocumentationSetNavigation instances for the referenced repos var observabilityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); - var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); var observabilityNav = new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance); var searchContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/serverless-search", output); - var searchDocset = DocumentationSetFile.LoadAndResolve(searchContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-search/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var searchDocset = DocumentationSetFile.LoadAndResolve(searchContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-search/docs/docset.yml"), fileSystem); var searchNav = new DocumentationSetNavigation(searchDocset, searchContext, GenericDocumentationFileFactory.Instance); var documentationSets = new List { observabilityNav, searchNav }; @@ -80,7 +79,7 @@ public void SiteNavigationWithNestedChildren() // Create DocumentationSetNavigation for platform var platformContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/platform", output); - var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var platformDocset = DocumentationSetFile.LoadAndResolve(platformContext.Collector, fileSystem.FileInfo.New("/checkouts/current/platform/docs/docset.yml"), fileSystem); var platformNav = new DocumentationSetNavigation(platformDocset, platformContext, GenericDocumentationFileFactory.Instance); var documentationSets = new List { platformNav }; @@ -118,7 +117,7 @@ public void SitePrefixNormalizesSlashes(string? sitePrefix, string expectedRootU var fileSystem = SiteNavigationTestFixture.CreateMultiRepositoryFileSystem(); var observabilityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); - var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); var observabilityNav = new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance); var documentationSets = new List { observabilityNav }; @@ -154,7 +153,7 @@ public void SitePrefixAppliedToNavigationItemUrls(string? sitePrefix, string exp var fileSystem = SiteNavigationTestFixture.CreateMultiRepositoryFileSystem(); var observabilityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); - var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); var observabilityNav = new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance); var documentationSets = new List { observabilityNav }; @@ -213,11 +212,11 @@ public void NavigationNodeIdsAreUniqueAcrossDocsets() // Create navigation for both docsets var productAContext = SiteNavigationTestFixture.CreateContext(fileSystem, productADir, output); - var productADocsetFile = DocumentationSetFile.LoadAndResolve(productAContext.Collector, fileSystem.FileInfo.New($"{productADir}/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var productADocsetFile = DocumentationSetFile.LoadAndResolve(productAContext.Collector, fileSystem.FileInfo.New($"{productADir}/docs/docset.yml"), fileSystem); var productANav = new DocumentationSetNavigation(productADocsetFile, productAContext, GenericDocumentationFileFactory.Instance); var productBContext = SiteNavigationTestFixture.CreateContext(fileSystem, productBDir, output); - var productBDocsetFile = DocumentationSetFile.LoadAndResolve(productBContext.Collector, fileSystem.FileInfo.New($"{productBDir}/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var productBDocsetFile = DocumentationSetFile.LoadAndResolve(productBContext.Collector, fileSystem.FileInfo.New($"{productBDir}/docs/docset.yml"), fileSystem); var productBNav = new DocumentationSetNavigation(productBDocsetFile, productBContext, GenericDocumentationFileFactory.Instance); // Get the "getting-started" folders from each docset @@ -285,11 +284,11 @@ public void SitePrefixAppliedToMultipleNavigationItems(string? sitePrefix, strin var fileSystem = SiteNavigationTestFixture.CreateMultiRepositoryFileSystem(); var observabilityContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/observability", output); - var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var observabilityDocset = DocumentationSetFile.LoadAndResolve(observabilityContext.Collector, fileSystem.FileInfo.New("/checkouts/current/observability/docs/docset.yml"), fileSystem); var observabilityNav = new DocumentationSetNavigation(observabilityDocset, observabilityContext, GenericDocumentationFileFactory.Instance); var searchContext = SiteNavigationTestFixture.CreateContext(fileSystem, "/checkouts/current/serverless-search", output); - var searchDocset = DocumentationSetFile.LoadAndResolve(searchContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-search/docs/docset.yml"), FileSystemFactory.ScopeSourceDirectory(fileSystem, "/checkouts")); + var searchDocset = DocumentationSetFile.LoadAndResolve(searchContext.Collector, fileSystem.FileInfo.New("/checkouts/current/serverless-search/docs/docset.yml"), fileSystem); var searchNav = new DocumentationSetNavigation(searchDocset, searchContext, GenericDocumentationFileFactory.Instance); var documentationSets = new List { observabilityNav, searchNav }; diff --git a/tests/Navigation.Tests/Codex/CodexNavigationTestBase.cs b/tests/Navigation.Tests/Codex/CodexNavigationTestBase.cs index 10af19bd52..d424570325 100644 --- a/tests/Navigation.Tests/Codex/CodexNavigationTestBase.cs +++ b/tests/Navigation.Tests/Codex/CodexNavigationTestBase.cs @@ -5,13 +5,11 @@ using System.IO.Abstractions; using System.IO.Abstractions.TestingHelpers; using Elastic.Codex.Navigation; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Configuration.Codex; using Elastic.Documentation.Configuration.Toc; using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Navigation; using Elastic.Documentation.Navigation.Isolated.Node; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Navigation.Tests.Codex; @@ -80,8 +78,8 @@ internal sealed class TestCodexDocumentationContext(IDiagnosticsCollector collec public IFileInfo ConfigurationPath => _fileSystem.FileInfo.New("/codex.yml"); public IDiagnosticsCollector Collector => collector; - public ScopedFileSystem ReadFileSystem => FileSystemFactory.ScopeCurrentWorkingDirectory(_fileSystem); - public ScopedFileSystem WriteFileSystem => FileSystemFactory.ScopeCurrentWorkingDirectoryForWrite(_fileSystem); + public IFileSystem ReadFileSystem => _fileSystem; + public IFileSystem WriteFileSystem => _fileSystem; public IDirectoryInfo OutputDirectory => _fileSystem.DirectoryInfo.New("/output"); public BuildType BuildType => BuildType.Codex; diff --git a/tests/Navigation.Tests/Codex/GroupNavigationTests.cs b/tests/Navigation.Tests/Codex/GroupNavigationTests.cs index f692922cdd..b75b1573f5 100644 --- a/tests/Navigation.Tests/Codex/GroupNavigationTests.cs +++ b/tests/Navigation.Tests/Codex/GroupNavigationTests.cs @@ -4,8 +4,6 @@ using AwesomeAssertions; using Elastic.Codex.Navigation; -using Elastic.Documentation.Configuration; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Navigation.Tests.Codex; @@ -138,8 +136,8 @@ private sealed class MinimalCodexContext : ICodexDocumentationContext private readonly System.IO.Abstractions.TestingHelpers.MockFileSystem _fs = new(); public System.IO.Abstractions.IFileInfo ConfigurationPath => _fs.FileInfo.New("/codex.yml"); public Elastic.Documentation.Diagnostics.IDiagnosticsCollector Collector => new Elastic.Documentation.Diagnostics.DiagnosticsCollector([]); - public ScopedFileSystem ReadFileSystem => FileSystemFactory.ScopeCurrentWorkingDirectory(_fs); - public ScopedFileSystem WriteFileSystem => FileSystemFactory.ScopeCurrentWorkingDirectoryForWrite(_fs); + public System.IO.Abstractions.IFileSystem ReadFileSystem => _fs; + public System.IO.Abstractions.IFileSystem WriteFileSystem => _fs; public System.IO.Abstractions.IDirectoryInfo OutputDirectory => _fs.DirectoryInfo.New("/output"); public BuildType BuildType => BuildType.Codex; public void EmitError(string message) { } diff --git a/tests/Navigation.Tests/Isolation/PhysicalDocsetTests.cs b/tests/Navigation.Tests/Isolation/PhysicalDocsetTests.cs index 4f16c0fcdf..7bc9903e3a 100644 --- a/tests/Navigation.Tests/Isolation/PhysicalDocsetTests.cs +++ b/tests/Navigation.Tests/Isolation/PhysicalDocsetTests.cs @@ -10,7 +10,6 @@ using Elastic.Documentation.Navigation.Isolated.Leaf; using Elastic.Documentation.Navigation.Isolated.Node; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Navigation.Tests.Isolation; @@ -28,7 +27,7 @@ public async Task PhysicalDocsetCanBeNavigated() var configPath = fileSystem.FileInfo.New(docsetPath); var context = new TestDocumentationSetContext(fileSystem, docsDir, outputDir, configPath, output, "docs-builder"); - var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath, context.ReadFileSystem, noSuppress: [HintType.DeepLinkingVirtualFile]); + var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath, fileSystem, noSuppress: [HintType.DeepLinkingVirtualFile]); _ = context.Collector.StartAsync(TestContext.Current.CancellationToken); @@ -75,7 +74,7 @@ public async Task PhysicalDocsetNavigationHasCorrectUrls() var configPath = fileSystem.FileInfo.New(docsetPath); var context = new TestDocumentationSetContext(fileSystem, docsDir, outputDir, configPath, output, "docs-builder"); - var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath, FileSystemFactory.RealRead); + var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath, fileSystem); _ = context.Collector.StartAsync(TestContext.Current.CancellationToken); var navigation = new DocumentationSetNavigation(docSet, context, TestDocumentationFileFactory.Instance); @@ -101,7 +100,7 @@ public async Task PhysicalDocsetNavigationIncludesNestedTocs() var configPath = fileSystem.FileInfo.New(docsetPath); var context = new TestDocumentationSetContext(fileSystem, docsDir, outputDir, configPath, output, "docs-builder"); - var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath, FileSystemFactory.RealRead); + var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath, fileSystem); _ = context.Collector.StartAsync(TestContext.Current.CancellationToken); var navigation = new DocumentationSetNavigation(docSet, context, TestDocumentationFileFactory.Instance); @@ -147,7 +146,7 @@ public async Task PhysicalDocsetNavigationHandlesHiddenFiles() var configPath = fileSystem.FileInfo.New(docsetPath); var context = new TestDocumentationSetContext(fileSystem, docsDir, outputDir, configPath, output, "docs-builder"); - var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath, FileSystemFactory.RealRead); + var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath, fileSystem); _ = context.Collector.StartAsync(TestContext.Current.CancellationToken); var navigation = new DocumentationSetNavigation(docSet, context, TestDocumentationFileFactory.Instance); diff --git a/tests/Navigation.Tests/Navigation.Tests.csproj b/tests/Navigation.Tests/Navigation.Tests.csproj index 8d5c0bca73..8f968026ee 100644 --- a/tests/Navigation.Tests/Navigation.Tests.csproj +++ b/tests/Navigation.Tests/Navigation.Tests.csproj @@ -18,7 +18,6 @@ - diff --git a/tests/Navigation.Tests/TestDocumentationSetContext.cs b/tests/Navigation.Tests/TestDocumentationSetContext.cs index 288dae691f..2bba18396e 100644 --- a/tests/Navigation.Tests/TestDocumentationSetContext.cs +++ b/tests/Navigation.Tests/TestDocumentationSetContext.cs @@ -5,7 +5,6 @@ using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; using Elastic.Documentation; -using Elastic.Documentation.Configuration; using Elastic.Documentation.Diagnostics; using Elastic.Documentation.Extensions; using Elastic.Documentation.Links.CrossLinks; @@ -14,7 +13,6 @@ using Markdig.Parsers; using Markdig.Syntax; using Markdig.Syntax.Inlines; -using Nullean.ScopedFileSystem; namespace Elastic.Documentation.Navigation.Tests; @@ -83,8 +81,8 @@ public TestDocumentationSetContext(IFileSystem fileSystem, TestDiagnosticsCollector? collector = null ) { - ReadFileSystem = FileSystemFactory.ScopeSourceDirectory(fileSystem, sourceDirectory.FullName); - WriteFileSystem = FileSystemFactory.ScopeSourceDirectoryForWrite(fileSystem, outputDirectory.FullName); + ReadFileSystem = fileSystem; + WriteFileSystem = fileSystem; DocumentationSourceDirectory = sourceDirectory; OutputDirectory = outputDirectory; ConfigurationPath = configPath; @@ -102,8 +100,8 @@ public TestDocumentationSetContext(IFileSystem fileSystem, } public IDiagnosticsCollector Collector { get; } - public ScopedFileSystem ReadFileSystem { get; } - public ScopedFileSystem WriteFileSystem { get; } + public IFileSystem ReadFileSystem { get; } + public IFileSystem WriteFileSystem { get; } public IDirectoryInfo OutputDirectory { get; } public IDirectoryInfo DocumentationSourceDirectory { get; } public GitCheckoutInformation Git { get; } diff --git a/tests/authoring/Framework/CrossLinkResolverAssertions.fs b/tests/authoring/Framework/CrossLinkResolverAssertions.fs index 0171ace235..8871376619 100644 --- a/tests/authoring/Framework/CrossLinkResolverAssertions.fs +++ b/tests/authoring/Framework/CrossLinkResolverAssertions.fs @@ -13,7 +13,6 @@ open Elastic.Documentation.Links open Elastic.Documentation.Links.CrossLinks open Elastic.Documentation open Swensen.Unquote -open Elastic.Documentation.Configuration open Elastic.Documentation.Configuration.Builder open authoring @@ -31,8 +30,8 @@ module CrossLinkResolverAssertions = member _.Collector = collector member _.DocumentationSourceDirectory = mockFileSystem.DirectoryInfo.New("/docs") member _.Git = GitCheckoutInformation.Unavailable - member _.ReadFileSystem = FileSystemFactory.ScopeCurrentWorkingDirectory(mockFileSystem) - member _.WriteFileSystem = FileSystemFactory.ScopeCurrentWorkingDirectory(mockFileSystem) + member _.ReadFileSystem = mockFileSystem + member _.WriteFileSystem = mockFileSystem member _.ConfigurationPath = mockFileSystem.FileInfo.New("mock_docset.yml") member _.OutputDirectory = mockFileSystem.DirectoryInfo.New(".artifacts") member _.BuildType = BuildType.Isolated diff --git a/tests/authoring/Framework/Setup.fs b/tests/authoring/Framework/Setup.fs index c997400169..33bb1f2f57 100644 --- a/tests/authoring/Framework/Setup.fs +++ b/tests/authoring/Framework/Setup.fs @@ -305,7 +305,7 @@ type Setup = ) let context = BuildContext( collector, - FileSystemFactory.ScopeCurrentWorkingDirectory(fileSystem), + fileSystem, configurationContext, UrlPathPrefix = (options.UrlPathPrefix |> Option.defaultValue ""), CanonicalBaseUrl = Uri("https://www.elastic.co/")