perf(deployment): staleness/comparison paths no longer Roslyn-compile every script — deploy gate remains the authoritative compile
Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
@@ -520,7 +520,7 @@ public class DeploymentServiceTests : TestKit
|
||||
_repo.GetDeployedSnapshotByInstanceIdAsync(1).Returns(snapshot);
|
||||
|
||||
var currentConfig = deployedConfig with { };
|
||||
_pipeline.FlattenAndValidateAsync(1, Arg.Any<CancellationToken>())
|
||||
_pipeline.FlattenAndValidateAsync(1, Arg.Any<CancellationToken>(), Arg.Any<bool>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(currentConfig, sameHash, ValidationResult.Success())));
|
||||
|
||||
@@ -557,7 +557,7 @@ public class DeploymentServiceTests : TestKit
|
||||
Attributes = [new ResolvedAttribute { CanonicalName = "Setpoint", Value = "9", DataType = "Int32" }]
|
||||
};
|
||||
var currentHash = new RevisionHashService().ComputeHash(currentConfig);
|
||||
_pipeline.FlattenAndValidateAsync(1, Arg.Any<CancellationToken>())
|
||||
_pipeline.FlattenAndValidateAsync(1, Arg.Any<CancellationToken>(), Arg.Any<bool>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(currentConfig, currentHash, ValidationResult.Success())));
|
||||
|
||||
@@ -567,6 +567,72 @@ public class DeploymentServiceTests : TestKit
|
||||
Assert.True(result.Value.IsStale);
|
||||
}
|
||||
|
||||
// ── PLAN-05 Task 16: read-only paths skip Roslyn script compilation ──
|
||||
|
||||
[Fact]
|
||||
public async Task GetDeploymentComparisonAsync_RequestsValidateScriptsFalse()
|
||||
{
|
||||
// The comparison page only needs the revision hash for staleness — the
|
||||
// expensive Roslyn compile must be skipped (validateScripts: false).
|
||||
var deployedConfig = new FlattenedConfiguration
|
||||
{
|
||||
InstanceUniqueName = "TestInst",
|
||||
Attributes = [new ResolvedAttribute { CanonicalName = "Setpoint", Value = "5", DataType = "Int32" }]
|
||||
};
|
||||
var hash = new RevisionHashService().ComputeHash(deployedConfig);
|
||||
var snapshot = new DeployedConfigSnapshot(
|
||||
"dep1", hash, System.Text.Json.JsonSerializer.Serialize(deployedConfig))
|
||||
{
|
||||
InstanceId = 1,
|
||||
DeployedAt = DateTimeOffset.UtcNow
|
||||
};
|
||||
_repo.GetDeployedSnapshotByInstanceIdAsync(1).Returns(snapshot);
|
||||
_pipeline.FlattenAndValidateAsync(1, Arg.Any<CancellationToken>(), Arg.Any<bool>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(deployedConfig with { }, hash, ValidationResult.Success())));
|
||||
|
||||
var result = await _service.GetDeploymentComparisonAsync(1);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
await _pipeline.Received(1).FlattenAndValidateAsync(1, Arg.Any<CancellationToken>(), false);
|
||||
await _pipeline.DidNotReceive().FlattenAndValidateAsync(1, Arg.Any<CancellationToken>(), true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeployInstanceAsync_RequestsValidateScriptsTrue()
|
||||
{
|
||||
// The deploy gate stays the authoritative compile — validateScripts defaults to true.
|
||||
var instance = new Instance("TestInst") { Id = 1, SiteId = 1, State = InstanceState.NotDeployed };
|
||||
_repo.GetInstanceByIdAsync(1).Returns(instance);
|
||||
|
||||
var validationResult = new ValidationResult
|
||||
{
|
||||
Errors = [ValidationEntry.Error(ValidationCategory.ScriptCompilation, "Compile error")]
|
||||
};
|
||||
_pipeline.FlattenAndValidateAsync(1, Arg.Any<CancellationToken>(), Arg.Any<bool>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(new FlattenedConfiguration(), "hash1", validationResult)));
|
||||
|
||||
await _service.DeployInstanceAsync(1, "admin");
|
||||
|
||||
await _pipeline.Received().FlattenAndValidateAsync(1, Arg.Any<CancellationToken>(), true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StaleInstanceProbe_RequestsValidateScriptsFalse()
|
||||
{
|
||||
// The Transport stale-instance probe also only needs the hash — same skip.
|
||||
_pipeline.FlattenAndValidateAsync(5, Arg.Any<CancellationToken>(), Arg.Any<bool>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(new FlattenedConfiguration(), "sha256:probe", ValidationResult.Success())));
|
||||
var probe = new StaleInstanceProbe(_pipeline);
|
||||
|
||||
var hash = await probe.GetCurrentRevisionHashAsync(5);
|
||||
|
||||
Assert.Equal("sha256:probe", hash);
|
||||
await _pipeline.Received(1).FlattenAndValidateAsync(5, Arg.Any<CancellationToken>(), false);
|
||||
}
|
||||
|
||||
// ── DeploymentManager-007: comparison must produce a structured diff ──
|
||||
|
||||
[Fact]
|
||||
@@ -594,7 +660,7 @@ public class DeploymentServiceTests : TestKit
|
||||
InstanceUniqueName = "DiffInst",
|
||||
Attributes = [new ResolvedAttribute { CanonicalName = "NewAttr", DataType = "Int" }]
|
||||
};
|
||||
_pipeline.FlattenAndValidateAsync(40, Arg.Any<CancellationToken>())
|
||||
_pipeline.FlattenAndValidateAsync(40, Arg.Any<CancellationToken>(), Arg.Any<bool>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(currentConfig, "sha256:new", ValidationResult.Success())));
|
||||
|
||||
@@ -668,7 +734,7 @@ public class DeploymentServiceTests : TestKit
|
||||
]
|
||||
};
|
||||
var nativeHash = hasher.ComputeHash(nativeConfig);
|
||||
_pipeline.FlattenAndValidateAsync(50, Arg.Any<CancellationToken>())
|
||||
_pipeline.FlattenAndValidateAsync(50, Arg.Any<CancellationToken>(), Arg.Any<bool>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(nativeConfig, nativeHash, ValidationResult.Success())));
|
||||
|
||||
@@ -736,7 +802,7 @@ public class DeploymentServiceTests : TestKit
|
||||
]
|
||||
};
|
||||
var currentHash = hasher.ComputeHash(currentConfig);
|
||||
_pipeline.FlattenAndValidateAsync(51, Arg.Any<CancellationToken>())
|
||||
_pipeline.FlattenAndValidateAsync(51, Arg.Any<CancellationToken>(), Arg.Any<bool>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(currentConfig, currentHash, ValidationResult.Success())));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user