Api Resources seed

This commit is contained in:
Paul Schneider 2026-06-25 20:22:41 +01:00
commit 99f4361e2d
5 changed files with 75 additions and 40 deletions

View file

@ -64,8 +64,6 @@ public partial class App : Application
DataContext = new MainPageViewModel(client, settings)
};
}
else
throw new NotSupportedException("ApplicationLifetime not supported.");
}

View file

@ -96,6 +96,20 @@ public partial class Settings : ObservableObject
internal void Load()
{
if (Loaded) return;
// Trust an already-populated Authority: tests pre-fill Settings
// with the OIDC stub's random loopback port, and programmatic
// callers (CLI flags, integration tests) wire their own. If we
// fall through to the disk / embedded read here we'd silently
// overwrite their value with the bundled default
// (yavsc.pschneider.fr), break the stubbed discovery URL, and
// turn a passing login into an invalid_grant.
if (!string.IsNullOrWhiteSpace(Authentication?.Authority))
{
Loaded = true;
return;
}
string configDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"PostIt"
@ -109,16 +123,14 @@ public partial class Settings : ObservableObject
if (!configFileInfo.Exists)
{
Console.Error.WriteLine($"🩎 Settings file not found at {configFileInfo.FullName}");
// Only fall back to the embedded default when the in-memory
// settings haven't been populated yet. This protects callers
// (notably tests) that pre-load Settings with explicit values
// from being silently overwritten by the bundled default.
if (string.IsNullOrWhiteSpace(this.Authentication?.Authority)
&& !TryLoadEmbeddedFallback())
// No user-level config: fall back to the embedded default.
// We only get here when Authentication.Authority is empty
// (the early-return above) so the redundant guard is gone.
if (!TryLoadEmbeddedFallback())
{
Console.Error.WriteLine("🩎 No embedded default settings; running with empty configuration.");
}
return; // no user settings file
return;
}
Console.WriteLine($"🔎 Loading settings from {configFileInfo.FullName}");