Merge pull request #35 from poli0981/claude/vnext-version-flags
feat(catalog): OS-build version flags (hide non-applicable commands)
This commit is contained in:
9 files changed
+191
-5
No files matched your search
@@ -64,4 +64,23 @@ public sealed record CommandDefinition
|
||||
|
||||
/// <summary>Free-form search tags.</summary>
|
||||
public IReadOnlyList<string> Tags { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Inclusive lowest Windows build this command applies to (e.g. <c>22000</c> for Windows 11+).
|
||||
/// <see langword="null"/> means no lower bound.
|
||||
/// </summary>
|
||||
public int? MinOsBuild { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Inclusive highest Windows build this command applies to (e.g. <c>19045</c> for Windows 10 only).
|
||||
/// <see langword="null"/> means no upper bound.
|
||||
/// </summary>
|
||||
public int? MaxOsBuild { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this command applies to the given OS build. Pure logic (no Win32) so the presentation
|
||||
/// layer can hide commands that do not apply to the current Windows version.
|
||||
/// </summary>
|
||||
public bool AppliesToOsBuild(int build)
|
||||
=> (MinOsBuild is null || build >= MinOsBuild) && (MaxOsBuild is null || build <= MaxOsBuild);
|
||||
}
|
||||
@@ -33,6 +33,8 @@ internal sealed record CommandDto
|
||||
public string? DocUrl { get; init; }
|
||||
public string[]? Tags { get; init; }
|
||||
public RegistryValueDto[]? AffectedRegistryValues { get; init; }
|
||||
public int? MinOsBuild { get; init; }
|
||||
public int? MaxOsBuild { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>JSON shape of a registry-value reference (for before/after comparison).</summary>
|
||||
|
||||
@@ -73,6 +73,9 @@ public static class CatalogLoader
|
||||
if (string.IsNullOrWhiteSpace(dto.DescriptionKey)) { errors.Add($"Command '{dto.Id}' is missing descriptionKey."); continue; }
|
||||
if (string.IsNullOrWhiteSpace(dto.Executable)) { errors.Add($"Command '{dto.Id}' is missing executable."); continue; }
|
||||
if (dto.Restart == RestartPolicy.FromOutputRegex && !IsValidRegex(dto.RestartRegex)) { errors.Add($"Command '{dto.Id}' has an invalid restartRegex."); continue; }
|
||||
if (dto.MinOsBuild is <= 0) { errors.Add($"Command '{dto.Id}' has a non-positive minOsBuild."); continue; }
|
||||
if (dto.MaxOsBuild is <= 0) { errors.Add($"Command '{dto.Id}' has a non-positive maxOsBuild."); continue; }
|
||||
if (dto.MinOsBuild is { } minBuild && dto.MaxOsBuild is { } maxBuild && maxBuild < minBuild) { errors.Add($"Command '{dto.Id}' has maxOsBuild ({maxBuild}) less than minOsBuild ({minBuild})."); continue; }
|
||||
|
||||
commands.Add(new CommandDefinition
|
||||
{
|
||||
@@ -100,6 +103,8 @@ public static class CatalogLoader
|
||||
.Where(r => !string.IsNullOrWhiteSpace(r.Path))
|
||||
.Select(r => new RegistryValueRef { Path = r.Path!, Name = r.Name ?? string.Empty })
|
||||
.ToList(),
|
||||
MinOsBuild = dto.MinOsBuild,
|
||||
MaxOsBuild = dto.MaxOsBuild,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -920,6 +920,7 @@
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.win11.modernmenu",
|
||||
"minOsBuild": 22000,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "context menu", "classic", "registry", "tweak"]
|
||||
@@ -939,6 +940,7 @@
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.win11.classicmenu",
|
||||
"minOsBuild": 22000,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "context menu", "modern", "registry", "tweak"]
|
||||
@@ -1766,6 +1768,7 @@
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.win11.taskbarcenter",
|
||||
"minOsBuild": 22000,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "taskbar", "align", "left", "registry", "tweak"],
|
||||
@@ -1788,6 +1791,7 @@
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.win11.taskbarleft",
|
||||
"minOsBuild": 22000,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "taskbar", "align", "center", "registry", "tweak"],
|
||||
@@ -1810,6 +1814,7 @@
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.clockseconds.off",
|
||||
"minOsBuild": 22621,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "clock", "seconds", "taskbar", "registry", "tweak"],
|
||||
@@ -1832,6 +1837,7 @@
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.clockseconds.on",
|
||||
"minOsBuild": 22621,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "clock", "seconds", "taskbar", "registry", "tweak"],
|
||||
|
||||
@@ -17,7 +17,12 @@ internal sealed record CatalogViewModels(
|
||||
/// </summary>
|
||||
internal static class CatalogViewModelBuilder
|
||||
{
|
||||
public static CatalogViewModels Build(ICatalogProvider catalog)
|
||||
/// <summary>
|
||||
/// Projects the catalog to view-models, hiding commands that do not apply to the current OS build
|
||||
/// (e.g. Windows 11-only tweaks on Windows 10). The hidden commands never reach the list, palette,
|
||||
/// category counts or any dashboard.
|
||||
/// </summary>
|
||||
public static CatalogViewModels Build(ICatalogProvider catalog, int currentOsBuild)
|
||||
{
|
||||
var categoryTitles = catalog.GetCategories()
|
||||
.ToDictionary(c => c.Id, c => Strings.Get(c.TitleKey), StringComparer.Ordinal);
|
||||
@@ -26,6 +31,11 @@ internal static class CatalogViewModelBuilder
|
||||
var searchable = new List<SearchableCommand>();
|
||||
foreach (var command in catalog.GetCommands())
|
||||
{
|
||||
if (!command.AppliesToOsBuild(currentOsBuild))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var title = Strings.Get(command.TitleKey);
|
||||
var description = Strings.Get(command.DescriptionKey);
|
||||
items.Add(new CommandItemViewModel(command, title, description));
|
||||
|
||||
@@ -12,10 +12,11 @@ public sealed partial class CommandPaletteViewModel : ObservableObject
|
||||
private readonly IReadOnlyList<SearchableCommand> _searchable;
|
||||
private readonly Dictionary<string, CommandItemViewModel> _itemsById;
|
||||
|
||||
public CommandPaletteViewModel(ICatalogProvider catalog)
|
||||
public CommandPaletteViewModel(ICatalogProvider catalog, ISystemInfoService systemInfo)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(catalog);
|
||||
var vms = CatalogViewModelBuilder.Build(catalog);
|
||||
ArgumentNullException.ThrowIfNull(systemInfo);
|
||||
var vms = CatalogViewModelBuilder.Build(catalog, systemInfo.GetStatus().OsBuild);
|
||||
_searchable = vms.Searchable;
|
||||
_itemsById = vms.Items.ToDictionary(i => i.Command.Id, StringComparer.Ordinal);
|
||||
ApplyFilter();
|
||||
|
||||
@@ -31,6 +31,7 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
private readonly IRegistryService _registry;
|
||||
private readonly Dictionary<string, CommandItemViewModel> _itemsById;
|
||||
private readonly CommandDefinition? _restorePointCommand;
|
||||
private readonly int _osBuild;
|
||||
private IReadOnlyList<SearchableCommand> _searchable;
|
||||
private IReadOnlyDictionary<string, string> _categoryTitles;
|
||||
|
||||
@@ -89,7 +90,8 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
}
|
||||
};
|
||||
|
||||
var vms = CatalogViewModelBuilder.Build(catalog);
|
||||
_osBuild = systemInfo.GetStatus().OsBuild;
|
||||
var vms = CatalogViewModelBuilder.Build(catalog, _osBuild);
|
||||
_searchable = vms.Searchable;
|
||||
_categoryTitles = vms.CategoryTitles;
|
||||
_itemsById = vms.Items.ToDictionary(i => i.Command.Id, StringComparer.Ordinal);
|
||||
@@ -472,7 +474,7 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
{
|
||||
// Rebuild the search corpus + category-title map in the new language, and refresh the
|
||||
// already-displayed item/category/detail view-models in place.
|
||||
var vms = CatalogViewModelBuilder.Build(_catalog);
|
||||
var vms = CatalogViewModelBuilder.Build(_catalog, _osBuild);
|
||||
_searchable = vms.Searchable;
|
||||
_categoryTitles = vms.CategoryTitles;
|
||||
|
||||
|
||||
@@ -47,4 +47,72 @@ public sealed class CatalogValidationErrorsTests
|
||||
|
||||
Assert.Empty(result.Errors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_MaxOsBuildBelowMinOsBuild_ProducesError()
|
||||
{
|
||||
var categories = new[] { new CategoryDto { Id = "cat", TitleKey = "Cat_K" } };
|
||||
var commands = new[]
|
||||
{
|
||||
new CommandDto
|
||||
{
|
||||
Id = "c1",
|
||||
CategoryId = "cat",
|
||||
TitleKey = "T",
|
||||
DescriptionKey = "D",
|
||||
Executable = "cmd",
|
||||
MinOsBuild = 22000,
|
||||
MaxOsBuild = 19045,
|
||||
},
|
||||
};
|
||||
|
||||
var result = CatalogLoader.Build(categories, commands);
|
||||
|
||||
Assert.Contains(result.Errors, e => e.Contains("c1", StringComparison.Ordinal) && e.Contains("maxOsBuild", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_NonPositiveOsBuild_ProducesError()
|
||||
{
|
||||
var categories = new[] { new CategoryDto { Id = "cat", TitleKey = "Cat_K" } };
|
||||
var commands = new[]
|
||||
{
|
||||
new CommandDto
|
||||
{
|
||||
Id = "c1",
|
||||
CategoryId = "cat",
|
||||
TitleKey = "T",
|
||||
DescriptionKey = "D",
|
||||
Executable = "cmd",
|
||||
MinOsBuild = 0,
|
||||
},
|
||||
};
|
||||
|
||||
var result = CatalogLoader.Build(categories, commands);
|
||||
|
||||
Assert.Contains(result.Errors, e => e.Contains("c1", StringComparison.Ordinal) && e.Contains("minOsBuild", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_ValidOsBuildRange_HasNoErrors()
|
||||
{
|
||||
var categories = new[] { new CategoryDto { Id = "cat", TitleKey = "Cat_K" } };
|
||||
var commands = new[]
|
||||
{
|
||||
new CommandDto
|
||||
{
|
||||
Id = "c1",
|
||||
CategoryId = "cat",
|
||||
TitleKey = "T",
|
||||
DescriptionKey = "D",
|
||||
Executable = "cmd",
|
||||
MinOsBuild = 22000,
|
||||
},
|
||||
};
|
||||
|
||||
var result = CatalogLoader.Build(categories, commands);
|
||||
|
||||
Assert.Empty(result.Errors);
|
||||
Assert.Equal(22000, result.Commands[0].MinOsBuild);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Infrastructure.Catalog;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Verifies the OS-build applicability predicate and the embedded catalog's version gating.</summary>
|
||||
public sealed class CommandDefinitionTests
|
||||
{
|
||||
private static CommandDefinition Command(int? min = null, int? max = null) => new()
|
||||
{
|
||||
Id = "t",
|
||||
CategoryId = "c",
|
||||
TitleKey = "T",
|
||||
DescriptionKey = "D",
|
||||
Executable = "cmd",
|
||||
MinOsBuild = min,
|
||||
MaxOsBuild = max,
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData(19045, true)] // no bounds -> always applies
|
||||
[InlineData(22631, true)]
|
||||
public void AppliesToOsBuild_NoBounds_AlwaysTrue(int build, bool expected)
|
||||
=> Assert.Equal(expected, Command().AppliesToOsBuild(build));
|
||||
|
||||
[Theory]
|
||||
[InlineData(19045, false)] // Windows 10 excluded by min 22000
|
||||
[InlineData(21999, false)]
|
||||
[InlineData(22000, true)] // inclusive lower bound
|
||||
[InlineData(26100, true)]
|
||||
public void AppliesToOsBuild_MinOnly_GatesBelow(int build, bool expected)
|
||||
=> Assert.Equal(expected, Command(min: 22000).AppliesToOsBuild(build));
|
||||
|
||||
[Theory]
|
||||
[InlineData(19045, true)] // inclusive upper bound (Windows 10 only)
|
||||
[InlineData(22000, false)] // Windows 11 excluded by max 19045
|
||||
public void AppliesToOsBuild_MaxOnly_GatesAbove(int build, bool expected)
|
||||
=> Assert.Equal(expected, Command(max: 19045).AppliesToOsBuild(build));
|
||||
|
||||
[Theory]
|
||||
[InlineData(21999, false)]
|
||||
[InlineData(22000, true)]
|
||||
[InlineData(22621, true)]
|
||||
[InlineData(22622, false)]
|
||||
public void AppliesToOsBuild_Range_GatesBothEnds(int build, bool expected)
|
||||
=> Assert.Equal(expected, Command(min: 22000, max: 22621).AppliesToOsBuild(build));
|
||||
|
||||
[Theory]
|
||||
[InlineData("tweak.win11.classicmenu", 22000)]
|
||||
[InlineData("tweak.win11.modernmenu", 22000)]
|
||||
[InlineData("tweak.win11.taskbarleft", 22000)]
|
||||
[InlineData("tweak.win11.taskbarcenter", 22000)]
|
||||
[InlineData("tweak.clockseconds.on", 22621)]
|
||||
[InlineData("tweak.clockseconds.off", 22621)]
|
||||
public void EmbeddedCatalog_Win11Commands_AreGated(string id, int expectedMinBuild)
|
||||
{
|
||||
var catalog = CatalogLoader.LoadEmbedded();
|
||||
var command = catalog.Commands.Single(c => c.Id == id);
|
||||
Assert.Equal(expectedMinBuild, command.MinOsBuild);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmbeddedCatalog_Win11Tweaks_HiddenOnWindows10()
|
||||
{
|
||||
const int windows10Build = 19045;
|
||||
var catalog = CatalogLoader.LoadEmbedded();
|
||||
var hiddenOnWin10 = catalog.Commands.Where(c => !c.AppliesToOsBuild(windows10Build)).Select(c => c.Id).ToHashSet();
|
||||
|
||||
Assert.Contains("tweak.win11.taskbarleft", hiddenOnWin10);
|
||||
Assert.Contains("tweak.clockseconds.on", hiddenOnWin10);
|
||||
Assert.DoesNotContain("dism.checkhealth", hiddenOnWin10); // ungated commands stay visible
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user