cofree-coffee / cofree-bot

A library for building bots compositionally.
41 stars 8 forks source link

Bot Test Scripts #59

Closed solomon-b closed 1 year ago

solomon-b commented 2 years ago

Resolves #8

Conversational bot integration tests such as:

calculatorBotSpec :: Spec
calculatorBotSpec =
  describe "Calculator Bot" $ do
    let bot = simplifyCalculatorBot calculatorBot
    it "performs arithmetic" $ do
      let scenario =
            [mkScript|
            >>>(1 + 2)
            <<<1 + 2 = 3
            >>>(2 * 3)
            <<<2 * 3 = 6
            >>>((2 * 3) + 1)
            <<<2 * 3 + 1 = 7
            |]
      result <- runTestScript scenario $ fixBot bot mempty
      result `shouldBe` scenario

I'm really happy with this API but the internal implementation of the test server could use some work:

testServer :: Monad m => Server (StateT ([i], [(i, [o])]) m) o (Maybe i)

I store the remaining inputs and the result as ([i], [(i, [o])]) in State and produce a Maybe i for the next input to indicate when we have reached the end of the script. Is State a good choice here?

We need to have a way to short circuit the annihilation step when we hit the end of the script. AFAICT this requires a special cased annihilation function. I would love it if this isn't needed.