| 1 | using CascadeIDE.Models; |
| 2 | |
| 3 | namespace CascadeIDE.Features.Agent.Environment; |
| 4 | |
| 5 | public sealed record DevServiceContractCheckResult(bool Ok, string Detail); |
| 6 | |
| 7 | /// <summary>Проверка, что ephemeral substrate задаёт override для dev DB (ADR 0148 §6).</summary> |
| 8 | public static class AgentDevServiceContractValidator |
| 9 | { |
| 10 | private static readonly string[] s_requiredEnvKeys = |
| 11 | [ |
| 12 | AgentSandboxProcessEnvironmentKeys.IntercomDataDirectory, |
| 13 | AgentSandboxProcessEnvironmentKeys.WitDbPath, |
| 14 | AgentSandboxProcessEnvironmentKeys.DevPort, |
| 15 | ]; |
| 16 | |
| 17 | public static DevServiceContractCheckResult ValidateForTestScoped( |
| 18 | AgentDevServiceContractSettings contract, |
| 19 | AgentSandboxProfile profile, |
| 20 | AgentSandboxLease lease) |
| 21 | { |
| 22 | if (!contract.RequireConfigOverride) |
| 23 | return new(true, "dev contract: override not required"); |
| 24 | |
| 25 | if (profile != AgentSandboxProfile.AgentEphemeral) |
| 26 | return new(true, "dev contract: skipped (non-ephemeral profile)"); |
| 27 | |
| 28 | if (lease.Substrate is null) |
| 29 | return contract.GateTestScopedOnViolation |
| 30 | ? new(false, "dev contract: ephemeral run without substrate bundle") |
| 31 | : new(true, $"dev contract: warn — no substrate ({VerifyRung.TestScoped} not gated)"); |
| 32 | |
| 33 | var env = AgentSandboxProcessEnvironmentKeys.ForBundle(lease.Substrate); |
| 34 | foreach (var key in s_requiredEnvKeys) |
| 35 | { |
| 36 | if (!env.ContainsKey(key) || string.IsNullOrWhiteSpace(env[key])) |
| 37 | return new(false, $"dev contract: missing env override '{key}'"); |
| 38 | } |
| 39 | |
| 40 | return new(true, "dev contract: ok"); |
| 41 | } |
| 42 | } |
| 43 | |