Files
xinmi/internal/agent/tools/shell_env_extract_test.go
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

59 lines
1.8 KiB
Go

package tools
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestExtractExportedEnvFromExportAndPrefixAssignment(t *testing.T) {
command := `unset HTTP_PROXY; export BIGMODEL_API_KEY="sk-abc.def"; cd /workspace && ./run`
got := extractExportedEnv(command)
require.Equal(t, "sk-abc.def", got["BIGMODEL_API_KEY"])
assert.NotContains(t, got, "HTTP_PROXY")
}
func TestExtractExportedEnvKeepsUnquotedAndSingleQuotedValues(t *testing.T) {
command := `export FOO=bare-value; export BAR='quoted value'; BAZ=prefix ./cmd`
got := extractExportedEnv(command)
assert.Equal(t, "bare-value", got["FOO"])
assert.Equal(t, "quoted value", got["BAR"])
assert.Equal(t, "prefix", got["BAZ"])
}
func TestExtractExportedEnvIgnoresFlagsAndURLs(t *testing.T) {
command := `python generate.py --model cogview-4 --size 1792x1024 https://example.com/x`
got := extractExportedEnv(command)
assert.Empty(t, got)
}
func TestCollectUsedSkillEnvOverlaysToolEnvOnExports(t *testing.T) {
command := `export BIGMODEL_API_KEY="from-command"; cd /opt/weknora/tenant/skills/bigmodel-image-video && python x.py`
toolEnv := map[string]string{"BIGMODEL_API_KEY": "from-tool", "EXTRA": "e"}
got := collectUsedSkillEnv(command, toolEnv)
assert.Equal(t, "from-tool", got["BIGMODEL_API_KEY"])
assert.Equal(t, "e", got["EXTRA"])
}
func TestMaskCommandAssignmentsHidesValues(t *testing.T) {
command := `export BIGMODEL_API_KEY="sk-abc.def"; TOKEN=plain ./run --model cogview-4`
got := maskCommandAssignments(command)
assert.NotContains(t, got, "sk-abc.def")
assert.NotContains(t, got, "plain")
assert.Contains(t, got, "BIGMODEL_API_KEY=***")
assert.Contains(t, got, "TOKEN=***")
// Ordinary flags stay readable: a masked log still has to be a usable one.
assert.Contains(t, got, "--model cogview-4")
}