feat: enforce typed legacy probe input roles

This commit is contained in:
codex
2026-08-05 16:12:55 +03:00
parent 02e34186fc
commit 9c49ebf1e2
4 changed files with 36 additions and 7 deletions
+20
View File
@@ -27,12 +27,18 @@ public sealed record ResolvedCatalogRoot
internal ResolvedCatalogRoot(string value) => Value = value;
public string Value { get; }
}
public sealed record ResolvedLegacySettingsPath { internal ResolvedLegacySettingsPath(string value) => Value=value; public string Value { get; } }
public sealed record ResolvedLegacyDownloadListPath { internal ResolvedLegacyDownloadListPath(string value) => Value=value; public string Value { get; } }
public sealed record ResolvedLegacyProbeEvidenceRoot { internal ResolvedLegacyProbeEvidenceRoot(string value) => Value=value; public string Value { get; } }
public interface IPathResolver
{
ResolvedLauncherPaths Resolve(LauncherPathVariables variables, IEnumerable<string>? required = null);
string ResolvePath(string value, LauncherPathVariables variables, string? constrainedRoot = null);
ResolvedCatalogRoot ResolveCatalogRoot(LauncherPathVariables variables);
ResolvedLegacySettingsPath ResolveLegacySettingsPath(LauncherPathVariables variables);
ResolvedLegacyDownloadListPath ResolveLegacyDownloadListPath(LauncherPathVariables variables);
ResolvedLegacyProbeEvidenceRoot ResolveLegacyProbeEvidenceRoot(LauncherPathVariables variables);
}
public sealed class PathResolver(IReadOnlyDictionary<string, string?>? environment = null) : IPathResolver
@@ -92,6 +98,20 @@ public sealed class PathResolver(IReadOnlyDictionary<string, string?>? environme
throw new InvalidOperationException("PATH_ROLE_COLLISION");
return new ResolvedCatalogRoot(catalog);
}
public ResolvedLegacySettingsPath ResolveLegacySettingsPath(LauncherPathVariables variables) => new(ResolveExistingFile("LegacySettingsPath", variables));
public ResolvedLegacyDownloadListPath ResolveLegacyDownloadListPath(LauncherPathVariables variables) => new(ResolveExistingFile("LegacyDownloadListPath", variables));
public ResolvedLegacyProbeEvidenceRoot ResolveLegacyProbeEvidenceRoot(LauncherPathVariables variables)
{
var value=ResolvePath(Resolve(variables,["LegacyProbeEvidenceRoot"]).Require("LegacyProbeEvidenceRoot"),variables);
if(value.StartsWith(@"\\",StringComparison.Ordinal)) throw new InvalidOperationException("LEGACY_PROBE_EVIDENCE_ROOT_NOT_LOCAL");
return new(value);
}
private string ResolveExistingFile(string role, LauncherPathVariables variables)
{
var value=ResolvePath(Resolve(variables,[role]).Require(role),variables);
if(!File.Exists(value) || Directory.Exists(value)) throw new InvalidOperationException("LEGACY_PROBE_INPUT_NOT_FILE");
return value;
}
private string? ResolveVariable(string name, LauncherPathVariables variables, Dictionary<string, string?> resolved, HashSet<string> stack)
{