Stop inferring machine transitions onto ambiguous triggers
Do not backfill polymorphic events from configured transitions when a trigger is ambiguous without enum-member constraints, and block symbolic inference when the symbolic type simple name is ambiguous across packages. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -231,6 +231,38 @@ class MachineEnumCanonicalizerTest {
|
||||
assertThat(expanded).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotInferMachineTransitionsForAmbiguousTriggerWithoutConstraint(@TempDir Path tempDir)
|
||||
throws IOException {
|
||||
Files.createDirectories(tempDir.resolve("a"));
|
||||
Files.createDirectories(tempDir.resolve("b"));
|
||||
Files.writeString(tempDir.resolve("a/OrderEvent.java"),
|
||||
"package a; public enum OrderEvent { PAY, SHIP }");
|
||||
Files.writeString(tempDir.resolve("b/OrderEvent.java"),
|
||||
"package b; public enum OrderEvent { CANCEL }");
|
||||
|
||||
CodebaseContext context = new CodebaseContext();
|
||||
context.scan(tempDir);
|
||||
|
||||
TriggerPoint trigger = TriggerPoint.builder()
|
||||
.event("OrderEvent.valueOf(eventStr)")
|
||||
.ambiguous(true)
|
||||
.polymorphicEvents(List.of())
|
||||
.build();
|
||||
StateMachineTypeResolver.MachineTypes types =
|
||||
new StateMachineTypeResolver.MachineTypes(null, "a.OrderEvent");
|
||||
|
||||
Transition pay = new Transition();
|
||||
pay.setEvent(Event.of("PAY", "a.OrderEvent.PAY"));
|
||||
pay.setSourceStates(List.of(State.of("NEW", "NEW")));
|
||||
pay.setTargetStates(List.of(State.of("PAID", "PAID")));
|
||||
|
||||
TriggerPoint enriched = MachineEnumCanonicalizer.ensureCallChainPolymorphicEvents(
|
||||
trigger, types, context, List.of(pay), true);
|
||||
|
||||
assertThat(enriched.getPolymorphicEvents()).isNullOrEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldValidateRawNameConsistencyForCanonicalHelpers() {
|
||||
assertThat(MachineEnumCanonicalizer.isRawNameConsistentWithFullIdentifier(
|
||||
|
||||
Reference in New Issue
Block a user