fix(ft546): enforce shuttle motion command gate

This commit is contained in:
zgw
2026-08-11 13:01:21 +08:00
parent de4d166b42
commit ff384cc019
3 changed files with 55 additions and 28 deletions

View File

@@ -37,7 +37,7 @@ class Ft546LegacySrgvAdapterTest {
JsonNode fixture = fixture("srgv-point-to-point.json");
FakePlcSrgvRead runtime = connectedRuntime("1");
Ft546LegacySrgvAdapter adapter = adapter(runtime, pointProfile(),
null, deviceId -> false);
null, (deviceId, commandId) -> false);
SendReceipt receipt = adapter.send(envelope("CMD-1",
fixture.get("payload").asText()));
@@ -54,7 +54,7 @@ class Ft546LegacySrgvAdapterTest {
FakePlcSrgvRead runtime = connectedRuntime("1");
runtime.throwAfterAddress = "4000";
Ft546LegacySrgvAdapter adapter = adapter(runtime, pointProfile(),
null, deviceId -> false);
null, (deviceId, commandId) -> false);
SendReceipt first = adapter.send(envelope("CMD-1",
fixture.get("payload").asText()));
@@ -72,7 +72,7 @@ class Ft546LegacySrgvAdapterTest {
void disconnectedRuntimeIsNotSentWithoutAnyPlcWrite() {
FakePlcSrgvRead runtime = runtime("1");
Ft546LegacySrgvAdapter adapter = adapter(runtime, pointProfile(),
null, deviceId -> false);
null, (deviceId, commandId) -> false);
SendReceipt receipt = adapter.send(envelope("CMD-1",
"taskNo=30001|taskType=1|route=070501>070502"));
@@ -86,7 +86,7 @@ class Ft546LegacySrgvAdapterTest {
FakePlcSrgvRead runtime = connectedRuntime("1");
runtime.returnFalseAfterAddress = "4004";
Ft546LegacySrgvAdapter adapter = adapter(runtime, pointProfile(),
null, deviceId -> false);
null, (deviceId, commandId) -> false);
SendReceipt receipt = adapter.send(envelope("CMD-1",
"taskNo=30001|taskType=1|route=070501>070502"));
@@ -104,7 +104,7 @@ class Ft546LegacySrgvAdapterTest {
profile.getRegisters().put("crossFloorFlag", "4020");
profile.getRegisters().put("crossFloorTarget", "4022");
Ft546LegacySrgvAdapter adapter = adapter(runtime, profile,
null, deviceId -> false);
null, (deviceId, commandId) -> false);
SendReceipt receipt = adapter.send(envelope("CMD-XF",
fixture.get("crossFloorPayload").asText()));
@@ -119,7 +119,7 @@ class Ft546LegacySrgvAdapterTest {
FakePlcSrgvRead runtime = connectedRuntime("1");
Ft546DeviceProfile profile = pointProfile();
Ft546LegacySrgvAdapter adapter = adapter(runtime, profile,
null, deviceId -> false);
null, (deviceId, commandId) -> false);
profile.getRegisters().put("path", "9999");
SendReceipt receipt = adapter.send(envelope("CMD-1",
@@ -130,15 +130,21 @@ class Ft546LegacySrgvAdapterTest {
}
@Test
void coreReportedUnknownCommandRejectsAParallelMove() {
void coreReportedActiveCommandRejectsAParallelMove() {
FakePlcSrgvRead runtime = connectedRuntime("1");
List<String> checkedCommands = new ArrayList<String>();
Ft546LegacySrgvAdapter adapter = adapter(runtime, pointProfile(),
null, deviceId -> true);
null, (deviceId, commandId) -> {
checkedCommands.add(deviceId + ":" + commandId);
return true;
});
SendReceipt receipt = adapter.send(envelope("CMD-1",
"taskNo=30001|taskType=1|route=070501>070502"));
assertEquals(SendReceipt.Status.REJECTED, receipt.getStatus());
assertEquals(Collections.singletonList("1:CMD-1"),
checkedCommands);
assertTrue(runtime.writes.isEmpty());
}
@@ -147,7 +153,8 @@ class Ft546LegacySrgvAdapterTest {
FakePlcSrgvRead runtime = connectedRuntime("1");
assertThrows(IllegalStateException.class, () -> adapter(runtime,
twoStageProfile(), null, deviceId -> false));
twoStageProfile(), null,
(deviceId, commandId) -> false));
assertTrue(runtime.writes.isEmpty());
}
@@ -160,13 +167,13 @@ class Ft546LegacySrgvAdapterTest {
FakePlcSrgvRead stageOneRuntime = connectedRuntime("1");
Ft546LegacySrgvAdapter stageOneAdapter = adapter(stageOneRuntime,
profile, evidence, deviceId -> false);
profile, evidence, (deviceId, commandId) -> false);
SendReceipt stageOne = stageOneAdapter.send(envelope("CMD-STAGE-1",
fixture.get("stageOnePayload").asText()));
FakePlcSrgvRead stageTwoRuntime = connectedRuntime("1");
Ft546LegacySrgvAdapter stageTwoAdapter = adapter(stageTwoRuntime,
profile, evidence, deviceId -> false);
profile, evidence, (deviceId, commandId) -> false);
SendReceipt stageTwo = stageTwoAdapter.send(envelope("CMD-STAGE-2",
fixture.get("stageTwoPayload").asText()));
@@ -176,6 +183,24 @@ class Ft546LegacySrgvAdapterTest {
assertWrites(fixture.get("stageTwoWrites"), stageTwoRuntime.writes);
}
@Test
void evidenceGatedTwoStageProfileDoesNotRequirePointToPointCapability()
throws Exception {
JsonNode fixture = fixture("srgv-two-stage-gate.json");
Ft546DeviceProfile profile = twoStageProfile();
profile.getCapabilities().remove("POINT_TO_POINT_COMMAND");
FakePlcSrgvRead runtime = connectedRuntime("1");
Ft546LegacySrgvAdapter adapter = adapter(runtime, profile,
passingEvidence(profile),
(deviceId, commandId) -> false);
SendReceipt receipt = adapter.send(envelope("CMD-STAGE-ONLY",
fixture.get("stageOnePayload").asText()));
assertEquals(SendReceipt.Status.ACCEPTED, receipt.getStatus());
assertWrites(fixture.get("stageOneWrites"), runtime.writes);
}
@Test
void mapsLegacyFactsWithoutFabricatingDeviceSequenceOrBootSession() {
FakePlcSrgvRead runtime = connectedRuntime("1");
@@ -216,12 +241,12 @@ class Ft546LegacySrgvAdapterTest {
private static Ft546LegacySrgvAdapter adapter(
FakePlcSrgvRead runtime, Ft546DeviceProfile profile,
Ft546CapabilityEvidence evidence,
Ft546LegacySrgvAdapter.UnknownCommandGuard unknownGuard) {
Ft546LegacySrgvAdapter.MotionCommandGuard motionGuard) {
Ft546DeviceRuntimeRegistry registry =
new Ft546DeviceRuntimeRegistry();
registry.register("1", runtime);
return new Ft546LegacySrgvAdapter(registry, profile, evidence,
new Ft546CapabilityGate(() -> NOW), unknownGuard,
new Ft546CapabilityGate(() -> NOW), motionGuard,
deviceId -> new Ft546SrgvSnapshotMapper.Context(
"SNAP-" + deviceId, "KEY-" + deviceId,
9L, 17L, NOW));