mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-10 22:20:25 +00:00
feat(task): replace built-in task adaptors with a sandboxed JS plugin system (#7076)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -33,3 +34,50 @@ func TestFormatUserLogsStripsQuotaSaturation(t *testing.T) {
|
||||
// Non-admin billing fields remain visible.
|
||||
require.Contains(t, parsed, "model_price")
|
||||
}
|
||||
|
||||
func TestTaskPluginLogVisibilityIsRoleSeparated(t *testing.T) {
|
||||
other := common.MapToJsonStr(map[string]interface{}{
|
||||
"model_price": 1.25,
|
||||
"admin_info": map[string]interface{}{
|
||||
"task_plugin": map[string]interface{}{
|
||||
"key": "document-parser",
|
||||
"name": "Document Parser",
|
||||
"version": "1.2.3",
|
||||
},
|
||||
},
|
||||
"root_info": map[string]interface{}{
|
||||
"upstream_task_id": "upstream-private",
|
||||
"task_plugin": map[string]interface{}{
|
||||
"generation": 42,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
t.Run("user", func(t *testing.T) {
|
||||
logs := []*Log{{Other: other}}
|
||||
formatUserLogs(logs, 0)
|
||||
|
||||
parsed, err := common.StrToMap(logs[0].Other)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, parsed, "admin_info")
|
||||
assert.NotContains(t, parsed, "root_info")
|
||||
assert.Equal(t, 1.25, parsed["model_price"])
|
||||
})
|
||||
|
||||
t.Run("admin", func(t *testing.T) {
|
||||
logs := []*Log{{Other: other}}
|
||||
FormatAdminLogs(logs)
|
||||
|
||||
parsed, err := common.StrToMap(logs[0].Other)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, parsed, "admin_info")
|
||||
assert.NotContains(t, parsed, "root_info")
|
||||
})
|
||||
|
||||
t.Run("root", func(t *testing.T) {
|
||||
parsed, err := common.StrToMap(other)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, parsed, "admin_info")
|
||||
assert.Contains(t, parsed, "root_info")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user