Ensure the OpenAPI schema on disk is up to date. To update the schema, run `go run main.go server --print-openapi dummy > openapi.json`.
(t *testing.T)
| 25 | // Ensure the OpenAPI schema on disk is up to date. |
| 26 | // To update the schema, run `go run main.go server --print-openapi dummy > openapi.json`. |
| 27 | func TestOpenAPISchema(t *testing.T) { |
| 28 | t.Parallel() |
| 29 | |
| 30 | ctx := logctx.WithLogger(context.Background(), slog.New(slog.NewTextHandler(os.Stdout, nil))) |
| 31 | srv, err := httpapi.NewServer(ctx, httpapi.ServerConfig{ |
| 32 | AgentType: msgfmt.AgentTypeClaude, |
| 33 | AgentIO: nil, |
| 34 | Port: 0, |
| 35 | ChatBasePath: "/chat", |
| 36 | AllowedHosts: []string{"*"}, |
| 37 | AllowedOrigins: []string{"*"}, |
| 38 | }) |
| 39 | require.NoError(t, err) |
| 40 | currentSchemaStr := srv.GetOpenAPI() |
| 41 | var currentSchema any |
| 42 | if err := json.Unmarshal([]byte(currentSchemaStr), ¤tSchema); err != nil { |
| 43 | t.Fatalf("failed to unmarshal current schema: %s", err) |
| 44 | } |
| 45 | |
| 46 | diskSchemaFile, err := os.OpenFile("../../openapi.json", os.O_RDONLY, 0) |
| 47 | if err != nil { |
| 48 | t.Fatalf("failed to open disk schema: %s", err) |
| 49 | } |
| 50 | defer func() { |
| 51 | _ = diskSchemaFile.Close() |
| 52 | }() |
| 53 | |
| 54 | diskSchemaBytes, err := io.ReadAll(diskSchemaFile) |
| 55 | if err != nil { |
| 56 | t.Fatalf("failed to read disk schema: %s", err) |
| 57 | } |
| 58 | var diskSchema any |
| 59 | if err := json.Unmarshal(diskSchemaBytes, &diskSchema); err != nil { |
| 60 | t.Fatalf("failed to unmarshal disk schema: %s", err) |
| 61 | } |
| 62 | |
| 63 | require.Equal(t, currentSchema, diskSchema) |
| 64 | } |
| 65 | |
| 66 | func TestServer_redirectToChat(t *testing.T) { |
| 67 | cases := []struct { |
nothing calls this directly
no test coverage detected