Skip to content

chore: test on windows #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
12 changes: 10 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: test

on:
push:
branches:
Expand All @@ -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:
Expand All @@ -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
Expand Down
24 changes: 14 additions & 10 deletions pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
}

Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions pkg/repos/runtimes/golang/golang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package golang

import (
"context"
"errors"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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)
}
21 changes: 18 additions & 3 deletions pkg/repos/runtimes/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,39 @@ 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"
)

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",
}

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) {
Expand All @@ -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)
}
14 changes: 12 additions & 2 deletions pkg/repos/runtimes/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@ 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"
)

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",
}

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)
}
8 changes: 8 additions & 0 deletions pkg/tests/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"os"
"runtime"
"testing"

"github.com/gptscript-ai/gptscript/pkg/tests/tester"
Expand Down Expand Up @@ -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"
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/testdata/TestContext/call1.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
Expand Down
4 changes: 2 additions & 2 deletions pkg/tests/testdata/TestContext/test.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ This is from tool
---
name: fromcontext

#!/bin/bash
echo this is from context
#!sys.echo
this is from context
2 changes: 1 addition & 1 deletion pkg/tests/testdata/TestExportContext/call1.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
Expand Down
8 changes: 4 additions & 4 deletions pkg/tests/testdata/TestExportContext/test.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,5 +26,5 @@ Dummy body
---
name: fromexportcontext

#!/bin/bash
echo this is from external context
#!sys.echo
this is from external context