Skip to content

Commit f02d11e

Browse files
chore: only allow global params in first tool
1 parent b17c321 commit f02d11e

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

pkg/loader/loader.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
221221
return types.Tool{}, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, fmt.Errorf("only the first tool in a file can have no name"))
222222
}
223223

224+
if i != 0 && tool.Parameters.GlobalModelName != "" {
225+
return types.Tool{}, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, fmt.Errorf("only the first tool in a file can have global model name"))
226+
}
227+
228+
if i != 0 && len(tool.Parameters.GlobalTools) > 0 {
229+
return types.Tool{}, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, fmt.Errorf("only the first tool in a file can have global tools"))
230+
}
231+
224232
if targetToolName != "" && strings.EqualFold(tool.Parameters.Name, targetToolName) {
225233
mainTool = tool
226234
}

pkg/tests/runner_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,15 @@ func TestCase2(t *testing.T) {
669669
assert.Equal(t, "TEST RESULT CALL: 1", x)
670670
}
671671

672+
func TestGlobalErr(t *testing.T) {
673+
runner := tester.NewRunner(t)
674+
_, err := runner.Run("", "")
675+
autogold.Expect("line testdata/TestGlobalErr/test.gpt:4: only the first tool in a file can have global model name").Equal(t, err.Error())
676+
677+
_, err = runner.Run("test2.gpt", "")
678+
autogold.Expect("line testdata/TestGlobalErr/test2.gpt:4: only the first tool in a file can have global tools").Equal(t, err.Error())
679+
}
680+
672681
func TestContextArg(t *testing.T) {
673682
runner := tester.NewRunner(t)
674683
x, err := runner.Run("", `{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
first
2+
3+
---
4+
name: second
5+
global model name: foo
6+
7+
second
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
first
2+
3+
---
4+
name: second
5+
global tools: asdf
6+
7+
second

0 commit comments

Comments
 (0)