Skip to content

Commit b908050

Browse files
authored
Fix AssemblyConfigurationMatchTests for versioned branch logic (#2228)
The `AssemblyConfiguration.Match()` method now has two code paths for handling version branches: 1. **When `current` is a versioned branch** (e.g., `8.15`): - Build if branch >= current - Build if branch equals the previous minor of current (e.g., `8.14` when current is `8.15`) 2. **When `current` is NOT a versioned branch** (e.g., `main`): - Build if branch >= anchored product version - Do NOT build for previous minor versions - **`VersionBranchSpeculativeBuildBasedOnProductVersion`**: Changed expectation for branch `8.14` with product version `8.15` from `true` to `false`, since `current` is `"main"` and previous minor logic should not apply. - **`VersionBranchSpeculativeBuildWhenMatchesPreviousMinorVersion`**: Changed tests to use versioned `current` branches (e.g., `current: "9.2"`) instead of `current: "main"`, since this test specifically validates previous minor version logic. - **`VersionBranchPreviousMinorCalculationHandlesEdgeCases`**: Changed to use versioned `current` branches (e.g., `current: "8.1"`) to properly test edge cases in previous minor calculation. ### Test Results All 41 tests in `AssemblyConfigurationMatchTests` now pass ✓
1 parent 85ecc44 commit b908050

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public ContentSourceMatch Match(ILoggerFactory logFactory, string repository, st
204204
if (SemVersion.TryParse(current + ".0", out var currentVersion))
205205
{
206206
logger.LogInformation("Current is already using versioned branches {Current}", currentVersion);
207+
var previousCurrentVersion = new SemVersion(currentVersion.Major, Math.Max(currentVersion.Minor - 1, 0), 0);
207208
if (v >= currentVersion)
208209
{
209210
logger.LogInformation("Speculative build because {Branch} is gte current {Current}", branchOrTag, currentVersion);
@@ -212,6 +213,14 @@ public ContentSourceMatch Match(ILoggerFactory logFactory, string repository, st
212213
Speculative = true
213214
};
214215
}
216+
else if (v == previousCurrentVersion)
217+
{
218+
logger.LogInformation("Speculative build {Branch} is the previous minor '{ProductPreviousMinor}' of current {Current}", branchOrTag, previousCurrentVersion, currentVersion);
219+
match = match with
220+
{
221+
Speculative = true
222+
};
223+
}
215224
else
216225
logger.LogInformation("NO speculative build because {Branch} is lt {Current}", branchOrTag, currentVersion);
217226
}
@@ -221,7 +230,6 @@ public ContentSourceMatch Match(ILoggerFactory logFactory, string repository, st
221230
logger.LogInformation("Current is not using versioned branches checking product info");
222231
var productVersion = versioningSystem.Current;
223232
var anchoredProductVersion = new SemVersion(productVersion.Major, productVersion.Minor, 0);
224-
var previousMinorVersion = new SemVersion(productVersion.Major, Math.Max(productVersion.Minor - 1, 0), 0);
225233
if (v >= anchoredProductVersion)
226234
{
227235
logger.LogInformation("Speculative build {Branch} is gte product current '{ProductCurrent}' anchored at {ProductAnchored}", branchOrTag, productVersion, anchoredProductVersion);
@@ -230,14 +238,6 @@ public ContentSourceMatch Match(ILoggerFactory logFactory, string repository, st
230238
Speculative = true
231239
};
232240
}
233-
else if (v == previousMinorVersion)
234-
{
235-
logger.LogInformation("Speculative build {Branch} is gte product current previous minor '{ProductPreviousMinor}'", branchOrTag, previousMinorVersion);
236-
match = match with
237-
{
238-
Speculative = true
239-
};
240-
}
241241
else
242242
logger.LogInformation("NO speculative build {Branch} is lte product current '{ProductCurrent}'", branchOrTag, productVersion);
243243
}

src/Elastic.Markdown/IO/IPositionalNavigation.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public interface IPositionalNavigation
1616

1717
INavigationItem? GetPrevious(MarkdownFile current)
1818
{
19-
if (!MarkdownNavigationLookup.TryGetValue(current, out var currentNavigation))
20-
return null;
19+
var currentNavigation = GetCurrent(current);
2120
var index = currentNavigation.NavigationIndex;
2221
do
2322
{
@@ -32,8 +31,7 @@ public interface IPositionalNavigation
3231

3332
INavigationItem? GetNext(MarkdownFile current)
3433
{
35-
if (!MarkdownNavigationLookup.TryGetValue(current, out var currentNavigation))
36-
return null;
34+
var currentNavigation = GetCurrent(current);
3735
var index = currentNavigation.NavigationIndex;
3836
do
3937
{

tests/Elastic.Documentation.Configuration.Tests/AssemblyConfigurationMatchTests.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void VersionBranchSpeculativeBuildBasedOnCurrentVersion(string branch, st
166166
[Theory]
167167
[InlineData("8.16", "8.15", true)] // Greater than product version
168168
[InlineData("8.15", "8.15", true)] // Equal to product version
169-
[InlineData("8.14", "8.15", true)] // Previous minor version
169+
[InlineData("8.14", "8.15", false)] // Previous minor version - but current is not versioned, so no previous minor logic
170170
[InlineData("8.13", "8.15", false)] // Less than previous minor
171171
[InlineData("8.0", "8.0", true)] // Edge case: minor version 0
172172
public void VersionBranchSpeculativeBuildBasedOnProductVersion(string branch, string productVersion, bool shouldBeSpeculative)
@@ -305,20 +305,18 @@ public void VersionBranchNoSpeculativeBuildWhenLessThanAnchoredProductVersionAnd
305305
}
306306

307307
[Theory]
308-
[InlineData("9.1", "9.2.0")] // Previous minor version
309-
[InlineData("8.14", "8.15.1")] // Previous minor version with patch
310-
[InlineData("10.0", "10.1.0")] // Previous minor version at major boundary
311-
public void VersionBranchSpeculativeBuildWhenMatchesPreviousMinorVersion(string branch, string productVersion)
308+
[InlineData("9.1", "9.2")] // Previous minor version - current is versioned branch
309+
[InlineData("8.14", "8.15")] // Previous minor version - current is versioned branch
310+
[InlineData("10.0", "10.1")] // Previous minor version at major boundary - current is versioned branch
311+
public void VersionBranchSpeculativeBuildWhenMatchesPreviousMinorVersion(string branch, string currentVersion)
312312
{
313313
var repositories = new Dictionary<string, Repository>
314314
{
315-
["test-repo"] = CreateRepository(current: "main", next: "main", edge: "main")
315+
["test-repo"] = CreateRepository(current: currentVersion, next: "main", edge: "main")
316316
};
317317
var config = CreateConfiguration(repositories);
318-
var versionParts = productVersion.Split('.');
319-
var product = CreateProduct(new SemVersion(int.Parse(versionParts[0], null), int.Parse(versionParts[1], null), int.Parse(versionParts[2], null)));
320318

321-
var result = config.Match(LoggerFactory, "elastic/test-repo", branch, product);
319+
var result = config.Match(LoggerFactory, "elastic/test-repo", branch, null);
322320

323321
result.Speculative.Should().BeTrue();
324322
}
@@ -378,23 +376,21 @@ public void VersionBranchAnchorsProductVersionToMinorZero(string branch, string
378376
}
379377

380378
[Theory]
381-
[InlineData("8.0", "8.1.0")] // Previous minor when current is 8.1
382-
[InlineData("7.17", "8.0.0")] // Previous minor when current is 8.0 (floor at 0)
383-
public void VersionBranchPreviousMinorCalculationHandlesEdgeCases(string branch, string productVersion)
379+
[InlineData("8.0", "8.1")] // Previous minor when current is 8.1
380+
[InlineData("7.17", "8.0")] // NOT previous minor when current is 8.0 (previous would be 7.0, not 7.17)
381+
public void VersionBranchPreviousMinorCalculationHandlesEdgeCases(string branch, string currentVersion)
384382
{
385383
var repositories = new Dictionary<string, Repository>
386384
{
387-
["test-repo"] = CreateRepository(current: "main", next: "main", edge: "main")
385+
["test-repo"] = CreateRepository(current: currentVersion, next: "main", edge: "main")
388386
};
389387
var config = CreateConfiguration(repositories);
390-
var versionParts = productVersion.Split('.');
391-
var product = CreateProduct(new SemVersion(int.Parse(versionParts[0], null), int.Parse(versionParts[1], null), int.Parse(versionParts[2], null)));
392388

393-
var result = config.Match(LoggerFactory, "elastic/test-repo", branch, product);
389+
var result = config.Match(LoggerFactory, "elastic/test-repo", branch, null);
394390

395391
// 8.0 should match previous minor of 8.1 (which is 8.0)
396-
// 7.17 should NOT match previous minor of 8.0 (which is Math.Max(0-1, 0) = 8.0, not 7.17)
397-
var expectedSpeculative = branch == "8.0" && productVersion == "8.1.0";
392+
// 7.17 should NOT match previous minor of 8.0 (which is Math.Max(8-1, 0).0 = 7.0, not 7.17)
393+
var expectedSpeculative = branch == "8.0" && currentVersion == "8.1";
398394
result.Speculative.Should().Be(expectedSpeculative);
399395
}
400396
}

0 commit comments

Comments
 (0)