Skip to content

Commit 005a301

Browse files
reid-spencerclaude
andcommitted
Add test for entity Id type in included context files
Verify no false warning when Id type is defined in an included file within the containing context (reactive-bbq pattern). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9353a23 commit 005a301

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Types defined in an included file within the context
2+
type ReservationId is Id(FrontOfHouse.Reservation)
3+
type MakeReservation is command { partySize: Number }
4+
type ReservationMade is event { partySize: Number }
5+
type GetReservation is query { id: String }
6+
type ReservationResult is result { partySize: Number }
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
domain Restaurant is {
2+
context FrontOfHouse is {
3+
include "context-types.riddl"
4+
5+
entity Reservation is {
6+
record ReservationFields is { partySize: Number }
7+
state Active of Reservation.ReservationFields
8+
handler ReservationHandler is {
9+
on init { set field Reservation.ReservationFields.partySize to "0" }
10+
on command Restaurant.FrontOfHouse.MakeReservation {
11+
send event Restaurant.FrontOfHouse.ReservationMade
12+
to outlet Restaurant.FrontOfHouse.Events.out
13+
}
14+
on query Restaurant.FrontOfHouse.GetReservation {
15+
reply result Restaurant.FrontOfHouse.ReservationResult
16+
}
17+
}
18+
}
19+
20+
source Events is { outlet out is type ReservationMade }
21+
sink Incoming is {
22+
inlet in is type MakeReservation
23+
handler Dispatch is {
24+
on command Restaurant.FrontOfHouse.MakeReservation {
25+
tell command Restaurant.FrontOfHouse.MakeReservation
26+
to entity Restaurant.FrontOfHouse.Reservation
27+
}
28+
}
29+
}
30+
connector Pipe {
31+
from outlet FrontOfHouse.Events.out
32+
to inlet FrontOfHouse.Incoming.in
33+
}
34+
}
35+
}

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,58 @@ class CompletenessTest extends AbstractValidatingTest {
464464
}
465465
}
466466

467+
"not warn when entity Id type is defined in containing context" in { (td: TestData) =>
468+
val input = RiddlParserInput(
469+
"""domain D is {
470+
| context FrontOfHouse is {
471+
| type ReservationId is Id(FrontOfHouse.Reservation)
472+
| type Evt is event { data: String }
473+
| entity Reservation is {
474+
| record Fields is { data: String }
475+
| state Main of Reservation.Fields
476+
| handler H is {
477+
| on init { set field Reservation.Fields.data to "x" }
478+
| on event D.FrontOfHouse.Evt {
479+
| set field Reservation.Fields.data to "updated"
480+
| }
481+
| }
482+
| }
483+
| }
484+
|}
485+
|""".stripMargin,
486+
td
487+
)
488+
parseAndValidate(input.data, "test", shouldFailOnErrors = false) {
489+
(_, _, msgs) =>
490+
val cw = completenessWarnings(msgs)
491+
val idWarnings = cw.filter(m =>
492+
m.message.contains("Id type") || m.message.contains("Id(")
493+
)
494+
if idWarnings.nonEmpty then {
495+
info(s"Unexpected Id warnings:\n${idWarnings.map(_.format).mkString("\n")}")
496+
}
497+
idWarnings mustBe empty
498+
}
499+
}
500+
501+
"not warn when entity Id type is in an included file within the context" in { (td: TestData) =>
502+
val path = java.nio.file.Path.of("passes/input/id-in-include/main.riddl").toAbsolutePath
503+
val data = java.nio.file.Files.readString(path)
504+
val url = com.ossuminc.riddl.utils.URL.fromFullPath(path.toString)
505+
val rpi = RiddlParserInput(data, url, td.name)
506+
parseAndValidateInput(rpi, shouldFailOnErrors = false) {
507+
(_, _, msgs) =>
508+
val cw = completenessWarnings(msgs)
509+
val idWarnings = cw.filter(m =>
510+
m.message.contains("Id type") || m.message.contains("Id(")
511+
)
512+
if idWarnings.nonEmpty then {
513+
info(s"Unexpected Id warnings:\n${idWarnings.map(_.format).mkString("\n")}")
514+
}
515+
idWarnings mustBe empty
516+
}
517+
}
518+
467519
"warn when entity Id type is defined inside entity body" in { (td: TestData) =>
468520
val input = RiddlParserInput(
469521
"""domain D is {

0 commit comments

Comments
 (0)