Skip to content

Commit 8355aac

Browse files
Mpdreamzclaude
andcommitted
Fix remaining CI failures
Three issues: 1. Changelog tests used FileSystem.Path.GetTempPath() to generate unique paths within MockFileSystem. Since MockFS is in-memory, the paths can be anything in scope — replace with Paths.WorkingDirectoryRoot.FullName as the base so they stay within the ScopedFileSystem scope bounds. No real filesystem is touched; all operations remain in-memory. 2. DocsSyncTests.TestApply passed the same WrapToRead FS for both read and write in AssembleContext. AwsS3SyncApplyStrategy uses context.WriteFileSystem and needs AllowedSpecialFolders.Temp (present in WriteOptions). Fix by using WrapToWrite for the write FS. 3. IsolatedBuildService CI fallback defaulted the output path to Paths.WorkingDirectoryRoot/.artifacts/docs/html. When --path points to a different repo the write FS is scoped to that repo's root, not WorkingDirectoryRoot. Derive the default output from `path` instead so it stays within the write FS scope (same logic as BuildContext uses for the normal build path). FileSystemFactory.RealForPathWrite: replace StartsWith string check with IDirectoryInfo.IsSubPathOf from Nullean.ScopedFileSystem which does a proper directory-tree walk, preventing sibling-prefix false positives. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent db59cf1 commit 8355aac

22 files changed

Lines changed: 346 additions & 321 deletions

src/Elastic.Documentation.Configuration/FileSystemFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ public static ScopedFileSystem RealForPathWrite(string? path, string? output = n
133133
if (output is not null)
134134
{
135135
var absOutput = Path.IsPathRooted(output) ? output : Path.GetFullPath(output);
136-
if (!absOutput.StartsWith(gitRoot, StringComparison.OrdinalIgnoreCase))
136+
var plain = new FileSystem();
137+
if (!plain.DirectoryInfo.New(absOutput).IsSubPathOf(plain.DirectoryInfo.New(gitRoot)))
137138
roots.Add(absOutput);
138139
}
139140

src/services/Elastic.Documentation.Isolated/IsolatedBuildService.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,15 @@ public async Task<bool> Build(
100100
// At some point in the future we can remove this try catch
101101
catch (Exception e) when (runningOnCi && e.Message.StartsWith("Can not locate docset.yml file in", OrdinalIgnoreCase))
102102
{
103+
// Derive the default output from `path` so it stays within the write FS scope.
104+
// Using Paths.WorkingDirectoryRoot would be wrong when --path points to a different repo.
105+
var rootFolder = !string.IsNullOrWhiteSpace(path) ? path : Paths.WorkingDirectoryRoot.FullName;
106+
var writeFs = writeFileSystem ?? fileSystem;
103107
var outputDirectory = !string.IsNullOrWhiteSpace(output)
104-
? fileSystem.DirectoryInfo.New(output)
105-
: fileSystem.DirectoryInfo.New(Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts/docs/html"));
108+
? writeFs.DirectoryInfo.New(output)
109+
: writeFs.DirectoryInfo.New(Path.Join(rootFolder, ".artifacts/docs/html"));
106110
// we temporarily do not error when pointed to a non-documentation folder.
107-
_ = fileSystem.Directory.CreateDirectory(outputDirectory.FullName);
111+
_ = writeFs.Directory.CreateDirectory(outputDirectory.FullName);
108112

109113
_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}",
110114
e.Message);

tests-integration/Elastic.Assembler.IntegrationTests/DocsSyncTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public async Task TestPlan()
4646
var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem);
4747
var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider);
4848
var scopedFs = FileSystemFactory.WrapToRead(fileSystem);
49-
var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFs, scopedFs, null, Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"));
49+
var scopedWriteFs = FileSystemFactory.WrapToWrite(fileSystem);
50+
var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFs, scopedWriteFs, null, Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"));
5051
A.CallTo(() => mockS3Client.ListObjectsV2Async(A<ListObjectsV2Request>._, A<Cancel>._))
5152
.Returns(new ListObjectsV2Response
5253
{
@@ -188,7 +189,8 @@ bool valid
188189
var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem);
189190
var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider);
190191
var scopedFs2 = FileSystemFactory.WrapToRead(fileSystem);
191-
var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFs2, scopedFs2, null, Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"));
192+
var scopedWriteFs2 = FileSystemFactory.WrapToWrite(fileSystem);
193+
var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFs2, scopedWriteFs2, null, Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly"));
192194

193195
var s3Objects = new List<S3Object>();
194196
foreach (var i in Enumerable.Range(0, remoteFiles))
@@ -239,7 +241,8 @@ public async Task TestApply()
239241
var config = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider);
240242
var checkoutDirectory = Path.Join(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly");
241243
var scopedFs3 = FileSystemFactory.WrapToRead(fileSystem);
242-
var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFs3, scopedFs3, null, checkoutDirectory);
244+
var scopedWriteFs3 = FileSystemFactory.WrapToWrite(fileSystem);
245+
var context = new AssembleContext(config, configurationContext, "dev", collector, scopedFs3, scopedWriteFs3, null, checkoutDirectory);
243246
var plan = new SyncPlan
244247
{
245248
RemoteListingCompleted = true,

tests/Elastic.Changelog.Tests/Changelogs/BundleAmendTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using AwesomeAssertions;
66
using Elastic.Changelog.Bundling;
7+
using Elastic.Documentation.Configuration;
78
using Elastic.Documentation.Configuration.ReleaseNotes;
89

910
namespace Elastic.Changelog.Tests.Changelogs;
@@ -23,7 +24,7 @@ public BundleAmendTests(ITestOutputHelper output) : base(output)
2324

2425
private string CreateChangelogDir()
2526
{
26-
var changelogDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString());
27+
var changelogDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString());
2728
FileSystem.Directory.CreateDirectory(changelogDir);
2829
return changelogDir;
2930
}
@@ -48,7 +49,7 @@ private async Task<string> CreateResolvedBundle(CancellationToken ct)
4849
var changelogFile = FileSystem.Path.Join(_changelogDir, "1755268130-existing.yaml");
4950
await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, ct);
5051

51-
var bundlePath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml");
52+
var bundlePath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml");
5253
var input = new BundleChangelogsArguments
5354
{
5455
Directory = _changelogDir,
@@ -87,7 +88,7 @@ private async Task<string> CreateUnresolvedBundle(CancellationToken ct)
8788
var changelogFile = FileSystem.Path.Join(_changelogDir, "1755268130-existing.yaml");
8889
await FileSystem.File.WriteAllTextAsync(changelogFile, changelog, ct);
8990

90-
var bundlePath = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString(), "bundle.yaml");
91+
var bundlePath = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString(), "bundle.yaml");
9192
var input = new BundleChangelogsArguments
9293
{
9394
Directory = _changelogDir,
@@ -112,7 +113,7 @@ private async Task<string> CreateUnresolvedBundle(CancellationToken ct)
112113
/// </summary>
113114
private async Task<string> CreateNewChangelogFile(CancellationToken ct)
114115
{
115-
var newDir = FileSystem.Path.Join(FileSystem.Path.GetTempPath(), Guid.NewGuid().ToString());
116+
var newDir = FileSystem.Path.Join(Paths.WorkingDirectoryRoot.FullName, Guid.NewGuid().ToString());
116117
FileSystem.Directory.CreateDirectory(newDir);
117118

118119
// language=yaml

0 commit comments

Comments
 (0)