]> git.giacomolli.uk - onechat/blob - prompt_test.go
Refer to the design without names
[onechat] / prompt_test.go
1 package main
2
3 import (
4         "encoding/json"
5         "maps"
6         "slices"
7         "strings"
8         "testing"
9
10         "github.com/stretchr/testify/require"
11 )
12
13 func TestPromptNamesTheAgent(t *testing.T) {
14         text := prompt("Ada")
15         require.Contains(t, text, "You are Ada, an AI agent")
16         require.Contains(t, text, "- reply: Ada's replies")
17         require.Contains(t, text, "Goal: let Ada work later")
18         require.Contains(t, text, `- work: an agent's report, starting "[Name]"`)
19         require.NotContains(t, text, promptName)
20
21         // The old agent name is built from parts, so the source does not spell
22         // it.
23         require.NotContains(t, strings.ToLower(text), "u"+"nii")
24 }
25
26 func TestPromptLeavesOutAbsentFeatures(t *testing.T) {
27         text := prompt("Ada")
28         for _, absent := range []string{"image", "ubagent", "computer", "device", `zoom("Name")`, "instructions at the end"} {
29                 require.NotContains(t, text, absent)
30         }
31 }
32
33 func TestAgentToolsAreStrictAndStable(t *testing.T) {
34         tools := agentTools()
35         require.Equal(t, []string{"zoom", "date"}, []string{tools[0].Name, tools[1].Name})
36
37         for _, tool := range tools {
38                 schema := tool.Parameters.(map[string]any)
39                 properties := schema["properties"].(map[string]any)
40                 require.True(t, tool.Strict, tool.Name)
41                 require.Equal(t, false, schema["additionalProperties"], tool.Name)
42                 require.Equal(t, slices.Sorted(maps.Keys(properties)), schema["required"], tool.Name)
43         }
44
45         first, err := json.Marshal(tools)
46         require.NoError(t, err)
47
48         for range 10 {
49                 again, err := json.Marshal(agentTools())
50                 require.NoError(t, err)
51                 require.Equal(t, first, again)
52         }
53 }