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
+1
View File
@@ -34,3 +34,4 @@ PRecAnnot*.dll
appsettings.Local.json
*.secrets.json
.env
launcher.legacy-configuration-probe.json
@@ -4,20 +4,19 @@ using Launcher.Next.Core;
namespace Launcher.Next.Application;
public sealed record LegacyConfigurationProbeRequest(LauncherPathVariables Paths, string PatternName, LegacyCompatibilityOverlay Overlay, string OperationId);
public sealed record LegacyConfigurationProbeRequest(ResolvedLegacySettingsPath Settings, ResolvedLegacyDownloadListPath DownloadList, ResolvedLegacyProbeEvidenceRoot EvidenceRoot, string PatternName, LegacyCompatibilityOverlay Overlay, string OperationId);
public sealed record LegacyConfigurationProbeResult(string TerminalState, IReadOnlyList<PackageRequirement> Requirements, string EvidencePath, IReadOnlyList<string> Diagnostics);
/// <summary>Read-only configuration inspection. It intentionally has no package,
/// activation, process, or Autodesk dependency.</summary>
public sealed class LegacyConfigurationProbe(LegacyConfigurationAdapter adapter, IPathResolver resolver)
public sealed class LegacyConfigurationProbe(LegacyConfigurationAdapter adapter)
{
public async Task<LegacyConfigurationProbeResult> RunAsync(LegacyConfigurationProbeRequest request, CancellationToken cancellationToken = default)
{
var paths = resolver.Resolve(request.Paths, ["LegacySettingsPath", "LegacyDownloadListPath", "LegacyProbeEvidenceRoot"]);
var settingsPath = resolver.ResolvePath(paths.Require("LegacySettingsPath"), request.Paths);
var selectionPath = resolver.ResolvePath(paths.Require("LegacyDownloadListPath"), request.Paths);
var evidenceRoot = resolver.ResolvePath(paths.Require("LegacyProbeEvidenceRoot"), request.Paths);
if (!File.Exists(settingsPath) || !File.Exists(selectionPath) || Path.GetFullPath(evidenceRoot).StartsWith(@"\\", StringComparison.Ordinal)) throw new InvalidOperationException("LEGACY_PROBE_INPUT_PATH_INVALID");
var settingsPath = request.Settings.Value;
var selectionPath = request.DownloadList.Value;
var evidenceRoot = request.EvidenceRoot.Value;
if (!File.Exists(settingsPath) || !File.Exists(selectionPath)) throw new InvalidOperationException("LEGACY_PROBE_INPUT_PATH_INVALID");
if (Path.GetDirectoryName(settingsPath)!.Equals(evidenceRoot, StringComparison.OrdinalIgnoreCase) || Path.GetDirectoryName(selectionPath)!.Equals(evidenceRoot, StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException("PATH_ROLE_COLLISION");
Directory.CreateDirectory(evidenceRoot);
var before = await Snapshot(settingsPath, selectionPath, cancellationToken);
+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)
{
@@ -0,0 +1,9 @@
{
"schemaVersion": 1,
"mode": "LegacyConfigurationProbe",
"settingsXml": "${LEGACY_PROBE_ROOT}\\Settings.xml",
"downloadListXml": "${LEGACY_PROBE_ROOT}\\download_list.xml",
"compatibilityOverlay": "${LEGACY_PROBE_ROOT}\\legacy-package-overlay.json",
"selectedPattern": "Exact Pattern Name",
"evidenceOutputRoot": "${LEGACY_PROBE_EVIDENCE_ROOT}"
}