test(e2e): add ListAreaIdsByNamePrefixAsync CLI helper for UI-created area teardown

Adds CliRunner.ListAreaIdsByNamePrefixAsync so Playwright tests can locate
and delete areas they created through the UI without needing the id returned
from a CLI create call. Mirrors ListTemplateIdsByNamePrefixAsync. Round-trip
test verifies create → list-by-prefix → delete against the live cluster.
This commit is contained in:
Joseph Doherty
2026-06-06 13:20:11 -04:00
parent b4b38fe52a
commit 1afb3670c5
2 changed files with 73 additions and 0 deletions
@@ -237,6 +237,52 @@ public static partial class CliRunner
}
}
/// <summary>
/// Returns the ids of all areas on <paramref name="siteId"/> whose <c>name</c>
/// starts with <paramref name="prefix"/>, via <c>site area list --site-id</c>.
/// Used to delete areas a test created through the UI (where the new id is never
/// surfaced to the test).
///
/// <para>
/// Response shape: each element of the returned JSON array carries an integer
/// <c>id</c> and a string <c>name</c> (empirically verified against the dev
/// cluster — same shapes as the other create/list helpers in this file).
/// </para>
/// </summary>
/// <param name="siteId">Owning site id.</param>
/// <param name="prefix">
/// Name prefix to filter by (ordinal comparison). Typically the full unique name
/// produced by <see cref="UniqueName"/> so exactly one id is returned.
/// </param>
/// <returns>
/// The ids of every area on <paramref name="siteId"/> whose name starts with
/// <paramref name="prefix"/>; empty if no areas match.
/// </returns>
public static async Task<IReadOnlyList<int>> ListAreaIdsByNamePrefixAsync(int siteId, string prefix)
{
using var doc = await RunJsonAsync(
"site", "area", "list",
"--site-id", siteId.ToString(System.Globalization.CultureInfo.InvariantCulture));
var ids = new List<int>();
if (doc.RootElement.ValueKind == JsonValueKind.Array)
{
foreach (var area in doc.RootElement.EnumerateArray())
{
if (area.TryGetProperty("name", out var name)
&& name.ValueKind == JsonValueKind.String
&& (name.GetString()?.StartsWith(prefix, StringComparison.Ordinal) ?? false)
&& area.TryGetProperty("id", out var id)
&& id.TryGetInt32(out var areaId))
{
ids.Add(areaId);
}
}
}
return ids;
}
/// <summary>
/// Best-effort delete of a site via <c>site delete</c> for teardown; swallows
/// any failure.