|
2 | 2 | // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
3 | 3 | // See the LICENSE file in the project root for more information |
4 | 4 |
|
| 5 | +using System.IO.Abstractions.TestingHelpers; |
5 | 6 | using AwesomeAssertions; |
6 | 7 | using Elastic.Changelog.Creation; |
7 | 8 | using Elastic.Changelog.GitHub; |
@@ -183,4 +184,50 @@ public async Task CreateChangelog_CIWithoutProducts_NoPrProductLabels_FailsWithP |
183 | 184 | Collector.Errors.Should().Be(1); |
184 | 185 | Collector.Diagnostics.Should().Contain(d => d.Message.Contains("At least one product is required")); |
185 | 186 | } |
| 187 | + |
| 188 | + /// <summary> |
| 189 | + /// When --output points to a temp directory (e.g. /tmp/changelog-staging in CI), |
| 190 | + /// the service must use a write-scoped filesystem that allows temp paths. |
| 191 | + /// Regression test for ScopedFileSystemException on temp output. |
| 192 | + /// </summary> |
| 193 | + [Fact] |
| 194 | + public async Task CreateChangelog_TempOutputDirectory_Succeeds() |
| 195 | + { |
| 196 | + var mockFs = new MockFileSystem(new MockFileSystemOptions { CurrentDirectory = Paths.WorkingDirectoryRoot.FullName }); |
| 197 | + var writeFs = FileSystemFactory.ScopeCurrentWorkingDirectoryForWrite(mockFs); |
| 198 | + |
| 199 | + var configPath = Path.Join(Paths.WorkingDirectoryRoot.FullName, "config", "changelog.yml"); |
| 200 | + writeFs.Directory.CreateDirectory(writeFs.Path.GetDirectoryName(configPath)!); |
| 201 | + await writeFs.File.WriteAllTextAsync(configPath, ConfigWithProductLabels, TestContext.Current.CancellationToken); |
| 202 | + |
| 203 | + // Use the real system temp path so AllowedSpecialFolder.Temp matches cross-platform. |
| 204 | + // MockFileSystem's GetTempPath() returns a hardcoded "C:\temp" that diverges from the |
| 205 | + // real temp on Windows CI (D:\Temp), causing scope validation to fail. |
| 206 | + var tempOutput = Path.Join(Path.GetTempPath(), "changelog-staging"); |
| 207 | + |
| 208 | + var env = FakeCIEnv( |
| 209 | + prNumber: "1044", |
| 210 | + title: "move upstream update script to .ci", |
| 211 | + type: "bug-fix", |
| 212 | + owner: "elastic", |
| 213 | + repo: "elastic-otel-java", |
| 214 | + products: "elasticsearch" |
| 215 | + ); |
| 216 | + |
| 217 | + var service = new ChangelogCreationService(LoggerFactory, ConfigurationContext, _mockGitHub, writeFs, env); |
| 218 | + var input = new CreateChangelogArguments |
| 219 | + { |
| 220 | + Products = [], |
| 221 | + Config = configPath, |
| 222 | + Output = tempOutput, |
| 223 | + Concise = true |
| 224 | + }; |
| 225 | + |
| 226 | + var result = await service.CreateChangelog(Collector, input, TestContext.Current.CancellationToken); |
| 227 | + |
| 228 | + result.Should().BeTrue(); |
| 229 | + Collector.Errors.Should().Be(0); |
| 230 | + writeFs.Directory.Exists(tempOutput).Should().BeTrue(); |
| 231 | + writeFs.Directory.GetFiles(tempOutput, "*.yaml").Should().NotBeEmpty(); |
| 232 | + } |
186 | 233 | } |
0 commit comments