Skip to content

Commit 512ec19

Browse files
committed
rename field and add test
Signed-off-by: Grant Linville <[email protected]>
1 parent accfe59 commit 512ec19

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

opts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Options struct {
6666
IncludeEvents bool `json:"includeEvents"`
6767
Prompt bool `json:"prompt"`
6868
CredentialOverrides []string `json:"credentialOverrides"`
69-
CredentialContext []string `json:"credentialContext"`
69+
CredentialContexts []string `json:"credentialContext"` // json tag is left singular to match SDKServer
7070
Location string `json:"location"`
7171
ForceSequential bool `json:"forceSequential"`
7272
}

run_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package gptscript
22

33
import (
44
"context"
5+
"crypto/rand"
56
"runtime"
67
"testing"
8+
9+
"github.com/stretchr/testify/require"
710
)
811

912
func TestRestartingErrorRun(t *testing.T) {
@@ -42,3 +45,41 @@ func TestRestartingErrorRun(t *testing.T) {
4245
t.Errorf("executing run with input of 0 should not fail: %v", err)
4346
}
4447
}
48+
49+
func TestStackedContexts(t *testing.T) {
50+
const name = "testcred"
51+
52+
bytes := make([]byte, 32)
53+
_, err := rand.Read(bytes)
54+
require.NoError(t, err)
55+
56+
context1 := string(bytes)[:16]
57+
context2 := string(bytes)[16:]
58+
59+
run, err := g.Run(context.Background(), "test/credential.gpt", Options{
60+
CredentialContexts: []string{context1, context2},
61+
})
62+
require.NoError(t, err)
63+
64+
_, err = run.Text()
65+
require.NoError(t, err)
66+
67+
// The credential should exist in context1 now.
68+
cred, err := g.RevealCredential(context.Background(), []string{context1, context2}, name)
69+
require.NoError(t, err)
70+
require.Equal(t, cred.Context, context1)
71+
72+
// Now change the context order and run the script again.
73+
run, err = g.Run(context.Background(), "test/credential.gpt", Options{
74+
CredentialContexts: []string{context2, context1},
75+
})
76+
require.NoError(t, err)
77+
78+
_, err = run.Text()
79+
require.NoError(t, err)
80+
81+
// Now make sure the credential exists in context1 still.
82+
cred, err = g.RevealCredential(context.Background(), []string{context2, context1}, name)
83+
require.NoError(t, err)
84+
require.Equal(t, cred.Context, context1)
85+
}

test/credential.gpt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: echocred
2+
credential: mycredentialtool as testcred
3+
4+
#!/usr/bin/env bash
5+
6+
echo $VALUE
7+
8+
---
9+
name: mycredentialtool
10+
11+
#!sys.echo
12+
13+
hello

0 commit comments

Comments
 (0)