Skip to content

Commit e82f624

Browse files
authored
Skip hidden folders on codex builds (#3068)
1 parent 6140fa5 commit e82f624

3 files changed

Lines changed: 96 additions & 2 deletions

File tree

src/Elastic.Codex/Elastic.Codex.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<StartupHookSupport Condition="'$(Configuration)' == 'Debug'">true</StartupHookSupport>
1313
</PropertyGroup>
1414

15+
<ItemGroup>
16+
<InternalsVisibleTo Include="Navigation.Tests"/>
17+
</ItemGroup>
18+
1519
<ItemGroup>
1620
<PackageReference Include="RazorSlices"/>
1721
</ItemGroup>

src/Elastic.Codex/Sourcing/CodexCloneService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information
44

55
using System.IO.Abstractions;
6+
using System.Security;
67
using Elastic.Documentation.Configuration.Codex;
78
using Elastic.Documentation.Configuration.Toc;
89
using Elastic.Documentation.Diagnostics;
@@ -268,9 +269,9 @@ await context.WriteFileSystem.File.WriteAllTextAsync(
268269
return found;
269270
}
270271
}
271-
catch (UnauthorizedAccessException)
272+
catch (Exception ex) when (ex is UnauthorizedAccessException or SecurityException)
272273
{
273-
// Skip directories we can't access
274+
// Skip directories we can't access (including ScopedFileSystem-blocked hidden dirs)
274275
}
275276

276277
return null;
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.IO.Abstractions.TestingHelpers;
6+
using AwesomeAssertions;
7+
using Elastic.Codex.Sourcing;
8+
using Elastic.Documentation.Configuration;
9+
using Nullean.ScopedFileSystem;
10+
11+
namespace Elastic.Documentation.Navigation.Tests.Codex;
12+
13+
public class FindDocsetFileTests
14+
{
15+
private static readonly string RepoRoot = Path.Join(Paths.WorkingDirectoryRoot.FullName, "repo");
16+
17+
private static ScopedFileSystem CreateScopedFs(MockFileSystem mockFs) =>
18+
FileSystemFactory.ScopeCurrentWorkingDirectory(mockFs);
19+
20+
[Fact]
21+
public void StandardPath_Found()
22+
{
23+
var mockFs = new MockFileSystem(new Dictionary<string, MockFileData>
24+
{
25+
{ Path.Join(RepoRoot, "docs/docset.yml"), new MockFileData("project: test") }
26+
});
27+
28+
var result = CodexCloneService.FindDocsetFile(mockFs, mockFs.DirectoryInfo.New(RepoRoot));
29+
30+
result.Should().NotBeNull();
31+
result.Name.Should().Be("docset.yml");
32+
}
33+
34+
[Fact]
35+
public void NonStandardPath_FoundViaRecursion()
36+
{
37+
var mockFs = new MockFileSystem(new Dictionary<string, MockFileData>
38+
{
39+
{ Path.Join(RepoRoot, "docs-codex/docset.yml"), new MockFileData("project: test") }
40+
});
41+
42+
var result = CodexCloneService.FindDocsetFile(mockFs, mockFs.DirectoryInfo.New(RepoRoot));
43+
44+
result.Should().NotBeNull();
45+
result.Name.Should().Be("docset.yml");
46+
}
47+
48+
[Fact]
49+
public void HiddenDirectory_SkippedByScopedFileSystem()
50+
{
51+
var mockFs = new MockFileSystem(new Dictionary<string, MockFileData>
52+
{
53+
{ Path.Join(RepoRoot, ".github/workflows/ci.yml"), new MockFileData("name: CI") },
54+
{ Path.Join(RepoRoot, "docs-codex/docset.yml"), new MockFileData("project: test") }
55+
});
56+
var scopedFs = CreateScopedFs(mockFs);
57+
58+
var result = CodexCloneService.FindDocsetFile(scopedFs, scopedFs.DirectoryInfo.New(RepoRoot));
59+
60+
result.Should().NotBeNull();
61+
result.Name.Should().Be("docset.yml");
62+
}
63+
64+
[Fact]
65+
public void NoDocset_ReturnsNull()
66+
{
67+
var mockFs = new MockFileSystem(new Dictionary<string, MockFileData>
68+
{
69+
{ Path.Join(RepoRoot, "src/main.py"), new MockFileData("print('hello')") }
70+
});
71+
72+
var result = CodexCloneService.FindDocsetFile(mockFs, mockFs.DirectoryInfo.New(RepoRoot));
73+
74+
result.Should().BeNull();
75+
}
76+
77+
[Fact]
78+
public void NodeModules_Skipped()
79+
{
80+
var mockFs = new MockFileSystem(new Dictionary<string, MockFileData>
81+
{
82+
{ Path.Join(RepoRoot, "node_modules/some-pkg/docset.yml"), new MockFileData("project: fake") }
83+
});
84+
85+
var result = CodexCloneService.FindDocsetFile(mockFs, mockFs.DirectoryInfo.New(RepoRoot));
86+
87+
result.Should().BeNull();
88+
}
89+
}

0 commit comments

Comments
 (0)