From 1e4d12db1b92f02182f80d4635d3d15903d0ddbc Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Fri, 31 May 2024 15:36:59 -0700 Subject: [PATCH] chore: test on windows --- .gitattributes | 25 +++++++++++++++++++ .github/workflows/test.yaml | 12 +++++++-- pkg/loader/loader.go | 24 ++++++++++-------- pkg/repos/runtimes/golang/golang_test.go | 5 ++++ pkg/repos/runtimes/node/node_test.go | 21 +++++++++++++--- pkg/repos/runtimes/python/python_test.go | 14 +++++++++-- pkg/tests/runner_test.go | 8 ++++++ pkg/tests/testdata/TestContext/call1.golden | 2 +- pkg/tests/testdata/TestContext/test.gpt | 4 +-- .../testdata/TestExportContext/call1.golden | 2 +- pkg/tests/testdata/TestExportContext/test.gpt | 8 +++--- 11 files changed, 100 insertions(+), 25 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..582c3b06 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,25 @@ +# Set the default behavior to automatically normalize line endings. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted to LF. +*.go text eol=lf +*.sh text eol=lf +*.yaml text eol=lf +*.yml text eol=lf +*.md text eol=lf +*.json text eol=lf +*.mod text eol=lf +*.sum text eol=lf +*.golden text eol=lf + +# Denote all files that are truly binary and should not be modified. +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.ico binary +*.pdf binary +*.zip binary +*.gz binary +*.tar binary +*.exe binary diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 02dd1cb8..039d8d4d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,4 +1,5 @@ name: test + on: push: branches: @@ -13,7 +14,10 @@ on: jobs: test: - runs-on: ubuntu-22.04 + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-22.04, windows-latest] steps: - uses: actions/checkout@v4 with: @@ -23,7 +27,11 @@ jobs: cache: false go-version: "1.21" - name: Build UI - run: make build-ui + run: | + if [ ${{ matrix.os }} != 'windows-latest' ]; then + make build-ui + fi + shell: bash - name: Validate run: make validate - name: Build diff --git a/pkg/loader/loader.go b/pkg/loader/loader.go index 5749885e..06370440 100644 --- a/pkg/loader/loader.go +++ b/pkg/loader/loader.go @@ -72,22 +72,23 @@ func openFile(path string) (io.ReadCloser, bool, error) { } func loadLocal(base *source, name string) (*source, bool, error) { - path := filepath.Join(base.Path, name) + // We want to keep all strings in / format, and only convert to platform specific when reading + filePath := path.Join(base.Path, name) - if s, err := os.Stat(path); err == nil && s.IsDir() { - toolPath := filepath.Join(base.Path, name, "tool.gpt") - if s, err := os.Stat(toolPath); err == nil && !s.IsDir() { - path = toolPath + if s, err := os.Stat(filepath.Clean(filePath)); err == nil && s.IsDir() { + toolPath := path.Join(filePath, "tool.gpt") + if s, err := os.Stat(filepath.Clean(toolPath)); err == nil && !s.IsDir() { + filePath = toolPath } } - content, ok, err := openFile(path) + content, ok, err := openFile(filepath.Clean(filePath)) if err != nil { return nil, false, err } else if !ok { return nil, false, nil } - log.Debugf("opened %s", path) + log.Debugf("opened %s", filePath) defer content.Close() @@ -99,9 +100,9 @@ func loadLocal(base *source, name string) (*source, bool, error) { return &source{ Content: data, Remote: false, - Path: filepath.Dir(path), - Name: filepath.Base(path), - Location: path, + Path: path.Dir(filePath), + Name: path.Base(filePath), + Location: filePath, }, true, nil } @@ -398,6 +399,9 @@ func complete(opts ...Options) (result Options) { } func Program(ctx context.Context, name, subToolName string, opts ...Options) (types.Program, error) { + // We want all paths to have / not \ + name = strings.ReplaceAll(name, "\\", "/") + if log.IsDebug() { start := time.Now() defer func() { diff --git a/pkg/repos/runtimes/golang/golang_test.go b/pkg/repos/runtimes/golang/golang_test.go index e559e833..5f71fb50 100644 --- a/pkg/repos/runtimes/golang/golang_test.go +++ b/pkg/repos/runtimes/golang/golang_test.go @@ -2,6 +2,8 @@ package golang import ( "context" + "errors" + "io/fs" "os" "path/filepath" "strings" @@ -31,5 +33,8 @@ func TestRuntime(t *testing.T) { v, _, _ = strings.Cut(v, string(filepath.ListSeparator)) assert.Equal(t, "PATH", p) _, err = os.Stat(filepath.Join(v, "gofmt")) + if errors.Is(err, fs.ErrNotExist) { + _, err = os.Stat(filepath.Join(v, "gofmt.exe")) + } assert.NoError(t, err) } diff --git a/pkg/repos/runtimes/node/node_test.go b/pkg/repos/runtimes/node/node_test.go index 774b8f3d..50ef1e0a 100644 --- a/pkg/repos/runtimes/node/node_test.go +++ b/pkg/repos/runtimes/node/node_test.go @@ -2,13 +2,15 @@ package node import ( "context" + "errors" + "io/fs" "os" + "path/filepath" "strings" "testing" "github.com/adrg/xdg" "github.com/samber/lo" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -16,6 +18,11 @@ var ( testCacheHome = lo.Must(xdg.CacheFile("gptscript-test-cache/runtime")) ) +func firstPath(s []string) string { + _, p, _ := strings.Cut(s[0], "=") + return strings.Split(p, string(os.PathListSeparator))[0] +} + func TestRuntime(t *testing.T) { r := Runtime{ Version: "20", @@ -23,7 +30,11 @@ func TestRuntime(t *testing.T) { s, err := r.Setup(context.Background(), testCacheHome, "testdata", os.Environ()) require.NoError(t, err) - assert.True(t, strings.HasSuffix(s[0], "/bin"), "missing /bin: %s", s) + _, err = os.Stat(filepath.Join(firstPath(s), "node.exe")) + if errors.Is(err, fs.ErrNotExist) { + _, err = os.Stat(filepath.Join(firstPath(s), "node")) + } + require.NoError(t, err) } func TestRuntime21(t *testing.T) { @@ -33,5 +44,9 @@ func TestRuntime21(t *testing.T) { s, err := r.Setup(context.Background(), testCacheHome, "testdata", os.Environ()) require.NoError(t, err) - assert.True(t, strings.HasSuffix(s[0], "/bin"), "missing /bin: %s", s) + _, err = os.Stat(filepath.Join(firstPath(s), "node.exe")) + if errors.Is(err, fs.ErrNotExist) { + _, err = os.Stat(filepath.Join(firstPath(s), "node")) + } + require.NoError(t, err) } diff --git a/pkg/repos/runtimes/python/python_test.go b/pkg/repos/runtimes/python/python_test.go index ecfd4fdd..fc2ededc 100644 --- a/pkg/repos/runtimes/python/python_test.go +++ b/pkg/repos/runtimes/python/python_test.go @@ -2,13 +2,14 @@ package python import ( "context" + "errors" "os" + "path/filepath" "strings" "testing" "github.com/adrg/xdg" "github.com/samber/lo" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -16,6 +17,11 @@ var ( testCacheHome = lo.Must(xdg.CacheFile("gptscript-test-cache/runtime")) ) +func firstPath(s []string) string { + _, p, _ := strings.Cut(s[0], "=") + return strings.Split(p, string(os.PathListSeparator))[0] +} + func TestRuntime(t *testing.T) { r := Runtime{ Version: "3.12", @@ -23,5 +29,9 @@ func TestRuntime(t *testing.T) { s, err := r.Setup(context.Background(), testCacheHome, "testdata", os.Environ()) require.NoError(t, err) - assert.True(t, strings.HasSuffix(s[0], "/bin"), "missing /bin: %s", s) + _, err = os.Stat(filepath.Join(firstPath(s), "python.exe")) + if errors.Is(err, os.ErrNotExist) { + _, err = os.Stat(filepath.Join(firstPath(s), "python")) + } + require.NoError(t, err) } diff --git a/pkg/tests/runner_test.go b/pkg/tests/runner_test.go index 8cf5dfa5..1f74beca 100644 --- a/pkg/tests/runner_test.go +++ b/pkg/tests/runner_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "os" + "runtime" "testing" "github.com/gptscript-ai/gptscript/pkg/tests/tester" @@ -726,6 +727,9 @@ func TestGlobalErr(t *testing.T) { } func TestContextArg(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip() + } runner := tester.NewRunner(t) x, err := runner.Run("", `{ "file": "foo.db" @@ -742,6 +746,10 @@ func TestToolAs(t *testing.T) { } func TestCwd(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip() + } + runner := tester.NewRunner(t) runner.RespondWith(tester.Result{ diff --git a/pkg/tests/testdata/TestContext/call1.golden b/pkg/tests/testdata/TestContext/call1.golden index ccb2b718..4e5c3149 100644 --- a/pkg/tests/testdata/TestContext/call1.golden +++ b/pkg/tests/testdata/TestContext/call1.golden @@ -5,7 +5,7 @@ "role": "system", "content": [ { - "text": "this is from context\n\nThis is from tool" + "text": "this is from context\nThis is from tool" } ], "usage": {} diff --git a/pkg/tests/testdata/TestContext/test.gpt b/pkg/tests/testdata/TestContext/test.gpt index 1b276653..3b0ad53f 100644 --- a/pkg/tests/testdata/TestContext/test.gpt +++ b/pkg/tests/testdata/TestContext/test.gpt @@ -4,5 +4,5 @@ This is from tool --- name: fromcontext -#!/bin/bash -echo this is from context \ No newline at end of file +#!sys.echo +this is from context \ No newline at end of file diff --git a/pkg/tests/testdata/TestExportContext/call1.golden b/pkg/tests/testdata/TestExportContext/call1.golden index 2b7105dd..5476a745 100644 --- a/pkg/tests/testdata/TestExportContext/call1.golden +++ b/pkg/tests/testdata/TestExportContext/call1.golden @@ -41,7 +41,7 @@ "role": "system", "content": [ { - "text": "this is from external context\n\nthis is from context\n\nThis is from tool" + "text": "this is from external context\nthis is from context\nThis is from tool" } ], "usage": {} diff --git a/pkg/tests/testdata/TestExportContext/test.gpt b/pkg/tests/testdata/TestExportContext/test.gpt index 02daec54..e171ae24 100644 --- a/pkg/tests/testdata/TestExportContext/test.gpt +++ b/pkg/tests/testdata/TestExportContext/test.gpt @@ -8,8 +8,8 @@ name: fromcontext export: sampletool export context: fromexportcontext -#!/bin/bash -echo this is from context +#!sys.echo +this is from context --- name: sampletool @@ -26,5 +26,5 @@ Dummy body --- name: fromexportcontext -#!/bin/bash -echo this is from external context +#!sys.echo +this is from external context