Skip to content

Commit 58f5136

Browse files
reid-spencerclaude
andcommitted
Fix entity handler validation for state-level handlers
Entity handler validation now checks per-state rather than only at entity level. States can contain their own handlers, so the old check that errored when an entity had states but no entity-level handlers was incorrect. New behavior: - Each state without handlers errors individually (unless entity has entity-level handlers that cover it) - Entities with no states and no handlers but other content get a guidance error suggesting adding a handler or a state with a handler - Pending institutional-commerce tests until that repo adds handlers Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4ef9261 commit 58f5136

9 files changed

Lines changed: 29 additions & 7 deletions

File tree

passes/input/check/saga/saga.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ passes/input/check/saga/saga.riddl(12:5->16):
1010
passes/input/check/saga/saga.riddl(12:5->16):
1111
Metadata in Entity 'blah' should not be empty:
1212
entity blah is {
13+
passes/input/check/saga/saga.riddl(12:5->16):
14+
Entity 'blah' has no handlers and no states with handlers. Add a handler to the entity or add a state with a handler.:
15+
entity blah is {
1316
passes/input/check/saga/saga.riddl(13:26->34):
1417
Inlet 'in' is not connected:
1518
sink trashCan is { inlet in is command Something }

passes/jvm-native/src/test/scala/com/ossuminc/riddl/passes/validate/EntityValidatorTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class EntityValidatorTest extends AbstractValidatingTest {
9292
assertValidationMessage(
9393
msgs,
9494
Error,
95-
"Entity 'Hamburger' has 1 state but no handlers."
95+
"State 'foo' in Entity 'Hamburger' has no handlers."
9696
)
9797
assertValidationMessage(
9898
msgs,

passes/jvm-native/src/test/scala/com/ossuminc/riddl/passes/validate/FunctionValidatorTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class FunctionValidatorTest extends AbstractValidatingTest with Inside {
2222
| returns {r: Integer }
2323
| ???
2424
| }
25+
| handler x is { ??? }
2526
|}
2627
|""".stripMargin) { (e, rpi, msgs) =>
2728
inside(e.functions.head) { (f: Function) =>

passes/jvm-native/src/test/scala/com/ossuminc/riddl/passes/validate/InvariantValidator.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class InvariantValidator extends AbstractValidatingTest {
1919
"""
2020
|entity user is {
2121
| invariant small is ??? with { described as { "self explanatory!" } }
22+
| handler x is { ??? }
2223
|}
2324
|""".stripMargin
2425
) { (_, _, msgs) =>
@@ -44,6 +45,7 @@ class InvariantValidator extends AbstractValidatingTest {
4445
"""
4546
|entity user is {
4647
| invariant large is "x must be greater or equal to 10"
48+
| handler x is { ??? }
4749
|}
4850
|""".stripMargin
4951
) { (_, _, msgs) =>
@@ -58,6 +60,7 @@ class InvariantValidator extends AbstractValidatingTest {
5860
parseAndValidateInContext[AST.Entity]("""
5961
|entity user is {
6062
| invariant large is "true"
63+
| handler x is { ??? }
6164
|}
6265
|""".stripMargin) { (_, _, msgs) =>
6366
assertValidationMessage(

passes/shared/src/main/scala/com/ossuminc/riddl/passes/validate/ValidationPass.scala

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,14 +728,25 @@ case class ValidationPass(
728728
s"${entity.identify} is declared as a finite-state-machine but its handlers contain no morph or become statements"
729729
)
730730
}
731-
if entity.states.nonEmpty && entity.handlers.isEmpty then {
731+
if entity.states.nonEmpty then {
732+
val statesWithoutHandlers = entity.states.filter { state =>
733+
state.handlers.isEmpty && entity.handlers.isEmpty
734+
}
735+
for state <- statesWithoutHandlers do
736+
messages.add(
737+
Message(
738+
state.errorLoc,
739+
s"${state.identify} in ${entity.identify} has no handlers.",
740+
Messages.Error
741+
)
742+
)
743+
end for
744+
} else if entity.handlers.isEmpty && !entity.isEmpty then {
732745
messages.add(
733746
Message(
734747
entity.errorLoc,
735-
s"${entity.identify} has ${entity.states.size} state${
736-
if entity.states.size != 1 then "s"
737-
else ""
738-
} but no handlers.",
748+
s"${entity.identify} has no handlers and no states with handlers. " +
749+
"Add a handler to the entity or add a state with a handler.",
739750
Messages.Error
740751
)
741752
)

passes/shared/src/test/scala/com/ossuminc/riddl/passes/validate/SharedAdaptorTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ trait SharedAdaptorTest(using PlatformContext) extends AbstractValidatingTest {
6969
|
7070
| entity MyEntity is {
7171
| sink phum is { inlet commands is command LetsDoIt }
72+
| handler x is { ??? }
7273
| }
7374
| connector only is {
7475
| from outlet Foo.PaymentAdapter.foo.forMyEntity

riddlc/jvm/src/test/scala/com/ossuminc/riddl/RunRiddlcOnRemoteTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class RunRiddlcOnRemoteTest extends RunCommandSpecBase {
5858

5959
"riddlc" should {
6060
"validate on ossuminc/institutional-commerce" in {
61+
pending // entities in institutional-commerce need handlers or states with handlers
6162
runOnGitHubProject(
6263
"ossuminc",
6364
"institutional-commerce",

riddlc/shared/src/test/scala/com/ossuminc/riddl/ReportedIssuesTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ class ReportedIssuesTest extends JVMAbstractValidatingTest {
6464
// info(messages.format)
6565
val errors = messages.justErrors
6666
info(errors.format)
67-
errors.length must be(3)
67+
errors.length must be(4)
6868
val f = errors.map(_.format)
6969
f contains "Path 'FooExamplexxx.garbage' was not resolved,"
7070
f contains "Path 'FooExamplexxxx.garbage' was not resolved"
7171
f contains "Path 'Examplexxxx.Foo' was not resolved,"
72+
f contains "Entity 'OtherEntity' has no handlers and no states with handlers."
7273
val usage = messages.justUsage
7374
usage.length must be(0)
7475
val u = usage.map(_.format)

riddlc/shared/src/test/scala/com/ossuminc/riddl/RunRiddlcOnLocalTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class RunRiddlcOnLocalTest extends RunCommandSpecBase {
4646
runOnLocalProject(cwd, config, "validate")
4747
}
4848
"validate on ossuminc/institutional-commerce" in {
49+
pending // entities in institutional-commerce need handlers or states with handlers
4950
val cwd = "/Users/reid/Code/ossuminc/institutional-commerce"
5051
val config = "src/main/riddl/ImprovingApp.conf"
5152
runOnLocalProject(cwd, config, "validate")

0 commit comments

Comments
 (0)