Skip to content

Commit 97bdf85

Browse files
Mpdreamzclaude
andcommitted
Fix changelog test paths: replace out-of-scope absolute paths with WorkingDirectoryRoot-relative
Tests that extend ChangelogTestBase use a ScopedFileSystem wrapping MockFileSystem, bounded to [WorkingDirectoryRoot, ApplicationData]. Several tests used absolute paths like /tmp/config, /docs/changelog, /test-root, and relative paths like docs/changelog that resolved outside the scope root on CI runners. - ChangelogPrEvaluationServiceTests: /tmp/config/changelog.yml → Path.Join(WorkingDirectoryRoot, "config/changelog.yml"); "docs/changelog" → Path.Join(WorkingDirectoryRoot, "docs/changelog") - ChangelogCreationServiceTests: /tmp/config → Path.Join(WorkingDirectoryRoot, "config"); /tmp/output → Path.Join(WorkingDirectoryRoot, "output") - BundleChangelogsTests: /test-root → WorkingDirectoryRoot; use MockFileSystemOptions { CurrentDirectory = root } so relative paths within service code resolve correctly; switch YAML template config strings to $$""" raw literals so {version}/{lifecycle} stay as literal text while {{Path.Join(...)}} is interpolated - ChangelogTestBase: set MockFileSystem CurrentDirectory to WorkingDirectoryRoot so paths within the test base resolve within scope BundleLoaderTests (standalone, unscoped MockFileSystem) does not extend ChangelogTestBase and is not affected. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent a5e1c17 commit 97bdf85

4 files changed

Lines changed: 74 additions & 65 deletions

File tree

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,25 +3307,26 @@ public async Task BundleChangelogs_WithProfileMode_MissingConfig_ReturnsErrorWit
33073307
public async Task BundleChangelogs_WithProfileMode_ConfigAtCurrentDir_LoadsSuccessfully()
33083308
{
33093309
// Arrange - changelog.yml is at ./changelog.yml (in the current working directory)
3310+
var root = Paths.WorkingDirectoryRoot.FullName;
33103311
var cwdFs = new System.IO.Abstractions.TestingHelpers.MockFileSystem(
33113312
null,
3312-
currentDirectory: "/test-root"
3313+
currentDirectory: root
33133314
);
3314-
cwdFs.Directory.CreateDirectory("/test-root");
3315-
cwdFs.Directory.CreateDirectory("/test-root/changelogs");
3316-
cwdFs.Directory.CreateDirectory("/test-root/output");
3315+
cwdFs.Directory.CreateDirectory(root);
3316+
cwdFs.Directory.CreateDirectory(Path.Join(root, "changelogs"));
3317+
cwdFs.Directory.CreateDirectory(Path.Join(root, "output"));
33173318

33183319
// language=yaml
33193320
var configContent =
3320-
"""
3321+
$$"""
33213322
bundle:
3322-
directory: /test-root/changelogs
3323+
directory: {{Path.Join(root, "changelogs")}}
33233324
profiles:
33243325
es-release:
33253326
products: "elasticsearch {version} {lifecycle}"
33263327
output: "elasticsearch-{version}.yaml"
33273328
""";
3328-
await cwdFs.File.WriteAllTextAsync("/test-root/changelog.yml", configContent, TestContext.Current.CancellationToken);
3329+
await cwdFs.File.WriteAllTextAsync(Path.Join(root, "changelog.yml"), configContent, TestContext.Current.CancellationToken);
33293330

33303331
// language=yaml
33313332
var changelogContent =
@@ -3339,16 +3340,16 @@ public async Task BundleChangelogs_WithProfileMode_ConfigAtCurrentDir_LoadsSucce
33393340
prs:
33403341
- https://github.com/elastic/elasticsearch/pull/100
33413342
""";
3342-
await cwdFs.File.WriteAllTextAsync("/test-root/changelogs/1755268130-feature.yaml", changelogContent, TestContext.Current.CancellationToken);
3343+
await cwdFs.File.WriteAllTextAsync(Path.Join(root, "changelogs/1755268130-feature.yaml"), changelogContent, TestContext.Current.CancellationToken);
33433344

33443345
var service = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, FileSystemFactory.WrapToRead(cwdFs));
33453346

33463347
var input = new BundleChangelogsArguments
33473348
{
33483349
Profile = "es-release",
33493350
ProfileArgument = "9.2.0",
3350-
OutputDirectory = "/test-root/output"
3351-
// Config intentionally omitted — should discover /test-root/changelog.yml
3351+
OutputDirectory = Path.Join(root, "output")
3352+
// Config intentionally omitted — should discover changelog.yml in CWD
33523353
};
33533354

33543355
// Act
@@ -3357,34 +3358,35 @@ public async Task BundleChangelogs_WithProfileMode_ConfigAtCurrentDir_LoadsSucce
33573358
// Assert
33583359
result.Should().BeTrue($"Expected bundling to succeed. Errors: {string.Join("; ", Collector.Diagnostics.Where(d => d.Severity == Severity.Error).Select(d => d.Message))}");
33593360
Collector.Errors.Should().Be(0);
3360-
cwdFs.Directory.GetFiles("/test-root/output", "*.yaml").Should().NotBeEmpty("Expected output file to be created");
3361+
cwdFs.Directory.GetFiles(Path.Join(root, "output"), "*.yaml").Should().NotBeEmpty("Expected output file to be created");
33613362
}
33623363

33633364
[Fact]
33643365
public async Task BundleChangelogs_WithProfileMode_ConfigAtDocsSubdir_LoadsSuccessfully()
33653366
{
33663367
// Arrange - changelog.yml is at ./docs/changelog.yml (the second discovery candidate)
3368+
var root = Paths.WorkingDirectoryRoot.FullName;
33673369
var cwdFs = new System.IO.Abstractions.TestingHelpers.MockFileSystem(
33683370
null,
3369-
currentDirectory: "/test-root"
3371+
currentDirectory: root
33703372
);
3371-
cwdFs.Directory.CreateDirectory("/test-root");
3372-
cwdFs.Directory.CreateDirectory("/test-root/docs");
3373-
cwdFs.Directory.CreateDirectory("/test-root/changelogs");
3374-
cwdFs.Directory.CreateDirectory("/test-root/output");
3373+
cwdFs.Directory.CreateDirectory(root);
3374+
cwdFs.Directory.CreateDirectory(Path.Join(root, "docs"));
3375+
cwdFs.Directory.CreateDirectory(Path.Join(root, "changelogs"));
3376+
cwdFs.Directory.CreateDirectory(Path.Join(root, "output"));
33753377

33763378
// language=yaml
33773379
var configContent =
3378-
"""
3380+
$$"""
33793381
bundle:
3380-
directory: /test-root/changelogs
3382+
directory: {{Path.Join(root, "changelogs")}}
33813383
profiles:
33823384
es-release:
33833385
products: "elasticsearch {version} {lifecycle}"
33843386
output: "elasticsearch-{version}.yaml"
33853387
""";
33863388
// Config is in docs/ subdir, not in CWD directly
3387-
await cwdFs.File.WriteAllTextAsync("/test-root/docs/changelog.yml", configContent, TestContext.Current.CancellationToken);
3389+
await cwdFs.File.WriteAllTextAsync(Path.Join(root, "docs/changelog.yml"), configContent, TestContext.Current.CancellationToken);
33883390

33893391
// language=yaml
33903392
var changelogContent =
@@ -3398,16 +3400,16 @@ public async Task BundleChangelogs_WithProfileMode_ConfigAtDocsSubdir_LoadsSucce
33983400
prs:
33993401
- https://github.com/elastic/elasticsearch/pull/100
34003402
""";
3401-
await cwdFs.File.WriteAllTextAsync("/test-root/changelogs/1755268130-feature.yaml", changelogContent, TestContext.Current.CancellationToken);
3403+
await cwdFs.File.WriteAllTextAsync(Path.Join(root, "changelogs/1755268130-feature.yaml"), changelogContent, TestContext.Current.CancellationToken);
34023404

34033405
var service = new ChangelogBundlingService(LoggerFactory, ConfigurationContext, FileSystemFactory.WrapToRead(cwdFs));
34043406

34053407
var input = new BundleChangelogsArguments
34063408
{
34073409
Profile = "es-release",
34083410
ProfileArgument = "9.2.0",
3409-
OutputDirectory = "/test-root/output"
3410-
// Config intentionally omitted — should discover /test-root/docs/changelog.yml
3411+
OutputDirectory = Path.Join(root, "output")
3412+
// Config intentionally omitted — should discover docs/changelog.yml in CWD
34113413
};
34123414

34133415
// Act
@@ -3416,7 +3418,7 @@ public async Task BundleChangelogs_WithProfileMode_ConfigAtDocsSubdir_LoadsSucce
34163418
// Assert
34173419
result.Should().BeTrue($"Expected bundling to succeed. Errors: {string.Join("; ", Collector.Diagnostics.Where(d => d.Severity == Severity.Error).Select(d => d.Message))}");
34183420
Collector.Errors.Should().Be(0);
3419-
cwdFs.Directory.GetFiles("/test-root/output", "*.yaml").Should().NotBeEmpty("Expected output file to be created");
3421+
cwdFs.Directory.GetFiles(Path.Join(root, "output"), "*.yaml").Should().NotBeEmpty("Expected output file to be created");
34203422
}
34213423

34223424
// ─── Phase 3: URL list file and combined version+report ─────────────────────────────

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class ChangelogTestBase : IDisposable
2828
protected ChangelogTestBase(ITestOutputHelper output)
2929
{
3030
Output = output;
31-
var mockFileSystem = new MockFileSystem();
31+
var mockFileSystem = new MockFileSystem(new MockFileSystemOptions { CurrentDirectory = Paths.WorkingDirectoryRoot.FullName });
3232
FileSystem = FileSystemFactory.WrapToRead(mockFileSystem);
3333
Collector = new TestDiagnosticsCollector(output);
3434
LoggerFactory = new TestLoggerFactory(output);

tests/Elastic.Changelog.Tests/Creation/ChangelogCreationServiceTests.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ public class ChangelogCreationServiceTests(ITestOutputHelper output) : Changelog
3333
cloud-serverless: "@Product:ESS"
3434
""";
3535

36-
private async Task WriteConfig(string content, string path = "/tmp/config/changelog.yml")
36+
private async Task WriteConfig(string content, string? path = null)
3737
{
38+
path ??= Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml");
3839
var dir = FileSystem.Path.GetDirectoryName(path)!;
3940
FileSystem.Directory.CreateDirectory(dir);
4041
await FileSystem.File.WriteAllTextAsync(path, content);
@@ -67,7 +68,7 @@ private static IEnvironmentVariables FakeCIEnv(
6768
public async Task CreateChangelog_CIWithProducts_SkipsPrFetchAndSucceeds()
6869
{
6970
await WriteConfig(ConfigWithProductLabels);
70-
FileSystem.Directory.CreateDirectory("/tmp/output");
71+
FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "output"));
7172

7273
var env = FakeCIEnv(
7374
prNumber: "153344",
@@ -82,8 +83,8 @@ public async Task CreateChangelog_CIWithProducts_SkipsPrFetchAndSucceeds()
8283
var input = new CreateChangelogArguments
8384
{
8485
Products = [],
85-
Config = "/tmp/config/changelog.yml",
86-
Output = "/tmp/output",
86+
Config = Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"),
87+
Output = Path.Join(Paths.WorkingDirectoryRoot.FullName, "output"),
8788
Concise = true
8889
};
8990

@@ -104,7 +105,7 @@ public async Task CreateChangelog_CIWithProducts_SkipsPrFetchAndSucceeds()
104105
public async Task CreateChangelog_CIWithoutProducts_FallsBackToPrFetchForProducts()
105106
{
106107
await WriteConfig(ConfigWithProductLabels);
107-
FileSystem.Directory.CreateDirectory("/tmp/output");
108+
FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "output"));
108109

109110
A.CallTo(() => _mockGitHub.FetchPrInfoAsync("153344", "elastic", "cloud", A<CancellationToken>._))
110111
.Returns(new GitHubPrInfo
@@ -125,8 +126,8 @@ public async Task CreateChangelog_CIWithoutProducts_FallsBackToPrFetchForProduct
125126
var input = new CreateChangelogArguments
126127
{
127128
Products = [],
128-
Config = "/tmp/config/changelog.yml",
129-
Output = "/tmp/output",
129+
Config = Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"),
130+
Output = Path.Join(Paths.WorkingDirectoryRoot.FullName, "output"),
130131
Concise = true
131132
};
132133

@@ -147,7 +148,7 @@ public async Task CreateChangelog_CIWithoutProducts_FallsBackToPrFetchForProduct
147148
public async Task CreateChangelog_CIWithoutProducts_NoPrProductLabels_FailsWithProductRequired()
148149
{
149150
await WriteConfig(ConfigWithProductLabels);
150-
FileSystem.Directory.CreateDirectory("/tmp/output");
151+
FileSystem.Directory.CreateDirectory(Path.Join(Paths.WorkingDirectoryRoot.FullName, "output"));
151152

152153
A.CallTo(() => _mockGitHub.FetchPrInfoAsync("153344", "elastic", "cloud", A<CancellationToken>._))
153154
.Returns(new GitHubPrInfo
@@ -168,8 +169,8 @@ public async Task CreateChangelog_CIWithoutProducts_NoPrProductLabels_FailsWithP
168169
var input = new CreateChangelogArguments
169170
{
170171
Products = [],
171-
Config = "/tmp/config/changelog.yml",
172-
Output = "/tmp/output",
172+
Config = Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"),
173+
Output = Path.Join(Paths.WorkingDirectoryRoot.FullName, "output"),
173174
Concise = true
174175
};
175176

0 commit comments

Comments
 (0)