Browse Source

fix: missing timezone info (#66)

Yeuoly 1 year ago
parent
commit
d0ac072536

+ 3 - 0
internal/static/config_default_amd64.go

@@ -14,4 +14,7 @@ var DEFAULT_PYTHON_LIB_REQUIREMENTS = []string{
 	"/etc/resolv.conf",
 	"/run/systemd/resolve/stub-resolv.conf",
 	"/run/resolvconf/resolv.conf",
+	"/etc/localtime",
+	"/usr/share/zoneinfo",
+	"/etc/timezone",
 }

+ 3 - 0
internal/static/config_default_arm64.go

@@ -14,4 +14,7 @@ var DEFAULT_PYTHON_LIB_REQUIREMENTS = []string{
 	"/usr/lib/aarch64-linux-gnu/libssl.so.3",
 	"/usr/lib/aarch64-linux-gnu/libcrypto.so.3",
 	"/etc/hosts",
+	"/etc/localtime",
+	"/usr/share/zoneinfo",
+	"/etc/timezone",
 }

+ 27 - 0
tests/integration_tests/nodejs_feature_test.go

@@ -8,6 +8,33 @@ import (
 	"github.com/langgenius/dify-sandbox/internal/service"
 )
 
+func TestNodejsBasicTemplate(t *testing.T) {
+	const code = `// declare main function
+function main({a}) {
+	return {b: a}
+}
+
+// decode and prepare input object
+var inputs_obj = JSON.parse(Buffer.from('eyJhIjoiYSJ9', 'base64').toString('utf-8'))
+
+// execute main function
+var output_obj = main(inputs_obj)
+
+// convert output to json and print
+var output_json = JSON.stringify(output_obj)
+var result = ` + "`<<RESULT>>${output_json}<<RESULT>>`" + `
+console.log(result)`
+
+	runMultipleTestings(t, 30, func(t *testing.T) {
+		resp := service.RunNodeJsCode(code, "", &types.RunnerOptions{
+			EnableNetwork: true,
+		})
+		if resp.Code != 0 {
+			t.Fatal(resp)
+		}
+	})
+}
+
 func TestNodejsBase64(t *testing.T) {
 	// Test case for base64
 	runMultipleTestings(t, 30, func(t *testing.T) {

+ 31 - 0
tests/integration_tests/python_feature_test.go

@@ -3,6 +3,7 @@ package integrationtests_test
 import (
 	"strings"
 	"testing"
+	"time"
 
 	"github.com/langgenius/dify-sandbox/internal/core/runner/types"
 	"github.com/langgenius/dify-sandbox/internal/service"
@@ -76,3 +77,33 @@ print(requests.get("https://www.bilibili.com").content)
 		}
 	})
 }
+
+func TestPythonTimezone(t *testing.T) {
+	// Test case for time
+	runMultipleTestings(t, 1, func(t *testing.T) {
+		resp := service.RunPython3Code(`
+from datetime import datetime
+from zoneinfo import ZoneInfo
+
+print(datetime.now(ZoneInfo("Asia/Shanghai")).isoformat())
+		`, "", &types.RunnerOptions{
+			EnableNetwork: true,
+		})
+		if resp.Code != 0 {
+			t.Fatal(resp)
+		}
+
+		if resp.Data.(*service.RunCodeResponse).Stderr != "" {
+			t.Fatalf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr)
+		}
+
+		stdout := resp.Data.(*service.RunCodeResponse).Stdout
+		// trim \n
+		stdout = strings.TrimSpace(stdout)
+		// check if stdout match time format
+		_, err := time.Parse("2006-01-02T15:04:05.000000+08:00", stdout)
+		if err != nil {
+			t.Fatalf("unexpected output: %s, error: %v\n", stdout, err)
+		}
+	})
+}