|
| 1 | +package tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/replicate/cog-runtime/internal/server" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | +) |
| 10 | + |
| 11 | +func TestPredictionDataclassCoderSucceeded(t *testing.T) { |
| 12 | + if *legacyCog { |
| 13 | + // Compat: legacy Cog does not support custom coder |
| 14 | + t.SkipNow() |
| 15 | + } |
| 16 | + ct := NewCogTest(t, "dataclass") |
| 17 | + assert.NoError(t, ct.Start()) |
| 18 | + |
| 19 | + hc := ct.WaitForSetup() |
| 20 | + assert.Equal(t, server.StatusReady.String(), hc.Status) |
| 21 | + assert.Equal(t, server.SetupSucceeded, hc.Setup.Status) |
| 22 | + |
| 23 | + resp := ct.Prediction(map[string]any{ |
| 24 | + "account": map[string]any{ |
| 25 | + "id": 0, |
| 26 | + "name": "John", |
| 27 | + "address": map[string]any{"street": "Smith", "zip": 12345}, |
| 28 | + "credentials": map[string]any{"password": "foo", "pubkey": b64encode("bar")}, |
| 29 | + }, |
| 30 | + }) |
| 31 | + |
| 32 | + output := map[string]any{ |
| 33 | + "account": map[string]any{ |
| 34 | + "id": 100.0, |
| 35 | + "name": "JOHN", |
| 36 | + "address": map[string]any{"street": "SMITH", "zip": 22345.0}, |
| 37 | + "credentials": map[string]any{"password": "**********", "pubkey": b64encode("*bar*")}, |
| 38 | + }, |
| 39 | + } |
| 40 | + ct.AssertResponse(resp, server.PredictionSucceeded, output, "") |
| 41 | + |
| 42 | + ct.Shutdown() |
| 43 | + assert.NoError(t, ct.Cleanup()) |
| 44 | +} |
| 45 | + |
| 46 | +func TestPredictionChatCoderSucceeded(t *testing.T) { |
| 47 | + if *legacyCog { |
| 48 | + // Compat: legacy Cog does not support custom coder |
| 49 | + t.SkipNow() |
| 50 | + } |
| 51 | + ct := NewCogTest(t, "chat") |
| 52 | + assert.NoError(t, ct.Start()) |
| 53 | + |
| 54 | + hc := ct.WaitForSetup() |
| 55 | + assert.Equal(t, server.StatusReady.String(), hc.Status) |
| 56 | + assert.Equal(t, server.SetupSucceeded, hc.Setup.Status) |
| 57 | + |
| 58 | + resp := ct.Prediction(map[string]any{"msg": map[string]any{"role": "assistant", "content": "bar"}}) |
| 59 | + output := map[string]any{"role": "assistant", "content": "*bar*"} |
| 60 | + ct.AssertResponse(resp, server.PredictionSucceeded, output, "") |
| 61 | + |
| 62 | + ct.Shutdown() |
| 63 | + assert.NoError(t, ct.Cleanup()) |
| 64 | +} |
0 commit comments