Implements B2 from docs/Extra.md Part 1 (Macro / recipe). - Domain: Recipe (named, ordered list of catalog command ids). - Application: IRecipeStore port + pure RecipeFlow.ShouldStop (stop on failure / cancel / reboot-required). - Infrastructure: JsonRecipeStore -> %AppData%\CommandForge\recipes.json (source-gen, schema version, corrupt-file fallback). No telemetry; recipes reference only vetted catalog ids. - WPF: ExecutionViewModel.RunRecipeAsync runs steps sequentially through the same broker session (one UAC for an all-admin chain), streaming a per-step header and stopping per RecipeFlow. New Recipes shell section (sidebar + View menu) with RecipesViewModel/RecipesView: build/reorder/remove steps from the catalog, save/delete recipes, and Run with a single aggregated confirmation (warns on dangerous steps). Each finished step is recorded in the execution history. - EN/VI .resx keys; tests for RecipeFlow and the recipe store. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using CommandForge.Domain;
|
|
using CommandForge.Infrastructure.Recipes;
|
|
|
|
namespace CommandForge.Tests;
|
|
|
|
/// <summary>Verifies the recipe store round-trips, overwrites by name, and falls back on corruption.</summary>
|
|
public sealed class RecipeStoreTests
|
|
{
|
|
[Fact]
|
|
public void Save_Get_Delete_Persists()
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), $"cf-recipes-{Guid.NewGuid():N}.json");
|
|
try
|
|
{
|
|
var store = new JsonRecipeStore(path);
|
|
store.Save(new Recipe { Name = "Maintenance", CommandIds = ["dism.checkhealth", "sfc.scannow"] });
|
|
store.Save(new Recipe { Name = "Network", CommandIds = ["net.flushdns"] });
|
|
|
|
Assert.Equal(["Maintenance", "Network"], store.GetAll().Select(r => r.Name));
|
|
|
|
// Reload from disk — recipes persist with their ordered steps.
|
|
var reloaded = new JsonRecipeStore(path);
|
|
Assert.Equal(2, reloaded.GetAll().Count);
|
|
Assert.Equal(
|
|
["dism.checkhealth", "sfc.scannow"],
|
|
reloaded.GetAll().First(r => r.Name == "Maintenance").CommandIds);
|
|
|
|
reloaded.Delete("Network");
|
|
Assert.Single(reloaded.GetAll());
|
|
Assert.DoesNotContain(new JsonRecipeStore(path).GetAll(), r => r.Name == "Network");
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Save_OverwritesByName_CaseInsensitive()
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), $"cf-recipes-{Guid.NewGuid():N}.json");
|
|
try
|
|
{
|
|
var store = new JsonRecipeStore(path);
|
|
store.Save(new Recipe { Name = "Maint", CommandIds = ["a"] });
|
|
store.Save(new Recipe { Name = "maint", CommandIds = ["b", "c"] });
|
|
|
|
Assert.Single(store.GetAll());
|
|
Assert.Equal(["b", "c"], store.GetAll()[0].CommandIds);
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void CorruptFile_FallsBackToEmpty()
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), $"cf-recipes-{Guid.NewGuid():N}.json");
|
|
try
|
|
{
|
|
File.WriteAllText(path, "{ not json ");
|
|
Assert.Empty(new JsonRecipeStore(path).GetAll());
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
}
|