diff --git a/internal/static/config_default_amd64.go b/internal/static/config_default_amd64.go index e70802a..23593e6 100644 --- a/internal/static/config_default_amd64.go +++ b/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", } diff --git a/internal/static/config_default_arm64.go b/internal/static/config_default_arm64.go index 7034e9f..36ed07b 100644 --- a/internal/static/config_default_arm64.go +++ b/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", } diff --git a/tests/integration_tests/nodejs_feature_test.go b/tests/integration_tests/nodejs_feature_test.go index 05c91d4..12aa3e6 100644 --- a/tests/integration_tests/nodejs_feature_test.go +++ b/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 = ` + "`<>${output_json}<>`" + ` +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) { diff --git a/tests/integration_tests/python_feature_test.go b/tests/integration_tests/python_feature_test.go index dfa1449..bc15983 100644 --- a/tests/integration_tests/python_feature_test.go +++ b/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) + } + }) +}