Skip to content

Commit ca203da

Browse files
chore: test on windows
1 parent d9bc9cc commit ca203da

File tree

11 files changed

+100
-25
lines changed

11 files changed

+100
-25
lines changed

.gitattributes

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Set the default behavior to automatically normalize line endings.
2+
* text=auto
3+
4+
# Explicitly declare text files you want to always be normalized and converted to LF.
5+
*.go text eol=lf
6+
*.sh text eol=lf
7+
*.yaml text eol=lf
8+
*.yml text eol=lf
9+
*.md text eol=lf
10+
*.json text eol=lf
11+
*.mod text eol=lf
12+
*.sum text eol=lf
13+
*.golden text eol=lf
14+
15+
# Denote all files that are truly binary and should not be modified.
16+
*.png binary
17+
*.jpg binary
18+
*.jpeg binary
19+
*.gif binary
20+
*.ico binary
21+
*.pdf binary
22+
*.zip binary
23+
*.gz binary
24+
*.tar binary
25+
*.exe binary

.github/workflows/test.yaml

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: test
2+
23
on:
34
push:
45
branches:
@@ -13,7 +14,10 @@ on:
1314

1415
jobs:
1516
test:
16-
runs-on: ubuntu-22.04
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: [ubuntu-22.04, windows-latest]
1721
steps:
1822
- uses: actions/checkout@v4
1923
with:
@@ -23,7 +27,11 @@ jobs:
2327
cache: false
2428
go-version: "1.21"
2529
- name: Build UI
26-
run: make build-ui
30+
run: |
31+
if [ ${{ matrix.os }} != 'windows-latest' ]; then
32+
make build-ui
33+
fi
34+
shell: bash
2735
- name: Validate
2836
run: make validate
2937
- name: Build

pkg/loader/loader.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,23 @@ func openFile(path string) (io.ReadCloser, bool, error) {
7272
}
7373

7474
func loadLocal(base *source, name string) (*source, bool, error) {
75-
path := filepath.Join(base.Path, name)
75+
// We want to keep all strings in / format, and only convert to platform specific when reading
76+
filePath := path.Join(base.Path, name)
7677

77-
if s, err := os.Stat(path); err == nil && s.IsDir() {
78-
toolPath := filepath.Join(base.Path, name, "tool.gpt")
79-
if s, err := os.Stat(toolPath); err == nil && !s.IsDir() {
80-
path = toolPath
78+
if s, err := os.Stat(filepath.Clean(filePath)); err == nil && s.IsDir() {
79+
toolPath := path.Join(filePath, "tool.gpt")
80+
if s, err := os.Stat(filepath.Clean(toolPath)); err == nil && !s.IsDir() {
81+
filePath = toolPath
8182
}
8283
}
8384

84-
content, ok, err := openFile(path)
85+
content, ok, err := openFile(filepath.Clean(filePath))
8586
if err != nil {
8687
return nil, false, err
8788
} else if !ok {
8889
return nil, false, nil
8990
}
90-
log.Debugf("opened %s", path)
91+
log.Debugf("opened %s", filePath)
9192

9293
defer content.Close()
9394

@@ -99,9 +100,9 @@ func loadLocal(base *source, name string) (*source, bool, error) {
99100
return &source{
100101
Content: data,
101102
Remote: false,
102-
Path: filepath.Dir(path),
103-
Name: filepath.Base(path),
104-
Location: path,
103+
Path: path.Dir(filePath),
104+
Name: path.Base(filePath),
105+
Location: filePath,
105106
}, true, nil
106107
}
107108

@@ -398,6 +399,9 @@ func complete(opts ...Options) (result Options) {
398399
}
399400

400401
func Program(ctx context.Context, name, subToolName string, opts ...Options) (types.Program, error) {
402+
// We want all paths to have / not \
403+
name = strings.ReplaceAll(name, "\\", "/")
404+
401405
if log.IsDebug() {
402406
start := time.Now()
403407
defer func() {

pkg/repos/runtimes/golang/golang_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package golang
22

33
import (
44
"context"
5+
"errors"
6+
"io/fs"
57
"os"
68
"path/filepath"
79
"strings"
@@ -31,5 +33,8 @@ func TestRuntime(t *testing.T) {
3133
v, _, _ = strings.Cut(v, string(filepath.ListSeparator))
3234
assert.Equal(t, "PATH", p)
3335
_, err = os.Stat(filepath.Join(v, "gofmt"))
36+
if errors.Is(err, fs.ErrNotExist) {
37+
_, err = os.Stat(filepath.Join(v, "gofmt.exe"))
38+
}
3439
assert.NoError(t, err)
3540
}

pkg/repos/runtimes/node/node_test.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,39 @@ package node
22

33
import (
44
"context"
5+
"errors"
6+
"io/fs"
57
"os"
8+
"path/filepath"
69
"strings"
710
"testing"
811

912
"github.com/adrg/xdg"
1013
"github.com/samber/lo"
11-
"github.com/stretchr/testify/assert"
1214
"github.com/stretchr/testify/require"
1315
)
1416

1517
var (
1618
testCacheHome = lo.Must(xdg.CacheFile("gptscript-test-cache/runtime"))
1719
)
1820

21+
func firstPath(s []string) string {
22+
_, p, _ := strings.Cut(s[0], "=")
23+
return strings.Split(p, string(os.PathListSeparator))[0]
24+
}
25+
1926
func TestRuntime(t *testing.T) {
2027
r := Runtime{
2128
Version: "20",
2229
}
2330

2431
s, err := r.Setup(context.Background(), testCacheHome, "testdata", os.Environ())
2532
require.NoError(t, err)
26-
assert.True(t, strings.HasSuffix(s[0], "/bin"), "missing /bin: %s", s)
33+
_, err = os.Stat(filepath.Join(firstPath(s), "node.exe"))
34+
if errors.Is(err, fs.ErrNotExist) {
35+
_, err = os.Stat(filepath.Join(firstPath(s), "node"))
36+
}
37+
require.NoError(t, err)
2738
}
2839

2940
func TestRuntime21(t *testing.T) {
@@ -33,5 +44,9 @@ func TestRuntime21(t *testing.T) {
3344

3445
s, err := r.Setup(context.Background(), testCacheHome, "testdata", os.Environ())
3546
require.NoError(t, err)
36-
assert.True(t, strings.HasSuffix(s[0], "/bin"), "missing /bin: %s", s)
47+
_, err = os.Stat(filepath.Join(firstPath(s), "node.exe"))
48+
if errors.Is(err, fs.ErrNotExist) {
49+
_, err = os.Stat(filepath.Join(firstPath(s), "node"))
50+
}
51+
require.NoError(t, err)
3752
}

pkg/repos/runtimes/python/python_test.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,36 @@ package python
22

33
import (
44
"context"
5+
"errors"
56
"os"
7+
"path/filepath"
68
"strings"
79
"testing"
810

911
"github.com/adrg/xdg"
1012
"github.com/samber/lo"
11-
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314
)
1415

1516
var (
1617
testCacheHome = lo.Must(xdg.CacheFile("gptscript-test-cache/runtime"))
1718
)
1819

20+
func firstPath(s []string) string {
21+
_, p, _ := strings.Cut(s[0], "=")
22+
return strings.Split(p, string(os.PathListSeparator))[0]
23+
}
24+
1925
func TestRuntime(t *testing.T) {
2026
r := Runtime{
2127
Version: "3.12",
2228
}
2329

2430
s, err := r.Setup(context.Background(), testCacheHome, "testdata", os.Environ())
2531
require.NoError(t, err)
26-
assert.True(t, strings.HasSuffix(s[0], "/bin"), "missing /bin: %s", s)
32+
_, err = os.Stat(filepath.Join(firstPath(s), "python.exe"))
33+
if errors.Is(err, os.ErrNotExist) {
34+
_, err = os.Stat(filepath.Join(firstPath(s), "python"))
35+
}
36+
require.NoError(t, err)
2737
}

pkg/tests/runner_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"os"
7+
"runtime"
78
"testing"
89

910
"github.com/gptscript-ai/gptscript/pkg/tests/tester"
@@ -726,6 +727,9 @@ func TestGlobalErr(t *testing.T) {
726727
}
727728

728729
func TestContextArg(t *testing.T) {
730+
if runtime.GOOS == "windows" {
731+
t.Skip()
732+
}
729733
runner := tester.NewRunner(t)
730734
x, err := runner.Run("", `{
731735
"file": "foo.db"
@@ -742,6 +746,10 @@ func TestToolAs(t *testing.T) {
742746
}
743747

744748
func TestCwd(t *testing.T) {
749+
if runtime.GOOS == "windows" {
750+
t.Skip()
751+
}
752+
745753
runner := tester.NewRunner(t)
746754

747755
runner.RespondWith(tester.Result{

pkg/tests/testdata/TestContext/call1.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"role": "system",
66
"content": [
77
{
8-
"text": "this is from context\n\nThis is from tool"
8+
"text": "this is from context\nThis is from tool"
99
}
1010
],
1111
"usage": {}

pkg/tests/testdata/TestContext/test.gpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ This is from tool
44
---
55
name: fromcontext
66

7-
#!/bin/bash
8-
echo this is from context
7+
#!sys.echo
8+
this is from context

pkg/tests/testdata/TestExportContext/call1.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"role": "system",
4242
"content": [
4343
{
44-
"text": "this is from external context\n\nthis is from context\n\nThis is from tool"
44+
"text": "this is from external context\nthis is from context\nThis is from tool"
4545
}
4646
],
4747
"usage": {}

pkg/tests/testdata/TestExportContext/test.gpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ name: fromcontext
88
export: sampletool
99
export context: fromexportcontext
1010

11-
#!/bin/bash
12-
echo this is from context
11+
#!sys.echo
12+
this is from context
1313

1414
---
1515
name: sampletool
@@ -26,5 +26,5 @@ Dummy body
2626
---
2727
name: fromexportcontext
2828

29-
#!/bin/bash
30-
echo this is from external context
29+
#!sys.echo
30+
this is from external context

0 commit comments

Comments
 (0)