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:
2026-07-14 05:43:12 +02:00
parent fb3218e1a2
commit 828f1260cd
2 changed files with 59 additions and 3 deletions

View File

@@ -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(