@@ -2,8 +2,11 @@ package gptscript
2
2
3
3
import (
4
4
"context"
5
+ "crypto/rand"
5
6
"runtime"
6
7
"testing"
8
+
9
+ "github.com/stretchr/testify/require"
7
10
)
8
11
9
12
func TestRestartingErrorRun (t * testing.T ) {
@@ -42,3 +45,41 @@ func TestRestartingErrorRun(t *testing.T) {
42
45
t .Errorf ("executing run with input of 0 should not fail: %v" , err )
43
46
}
44
47
}
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
+ }
0 commit comments