Update sandbox integration tests and enhance JSON field parsing

- Modify the sandbox integration test to load a different assistant configuration, ensuring accurate testing of sandbox capabilities.
- Refactor JSON field parsing in the Xun store to handle both string and byte slice types, improving robustness in data processing and ensuring proper unmarshalling of JSON fields.
This commit is contained in:
Max 2026-02-24 11:16:45 +08:00
parent b4ded8a3ed
commit c3ba59a41b
2 changed files with 13 additions and 4 deletions

View file

@ -181,8 +181,8 @@ func TestHasSandboxMethod(t *testing.T) {
require.NoError(t, err)
assert.True(t, astWithSandbox.HasSandbox(), "Assistant with sandbox config should return true")
// Test assistant without sandbox (fullfields doesn't have sandbox)
astWithoutSandbox, err := assistant.LoadPath("/assistants/tests/fullfields")
// Test assistant without sandbox
astWithoutSandbox, err := assistant.LoadPath("/assistants/tests/simple-greeting")
require.NoError(t, err)
assert.False(t, astWithoutSandbox.HasSandbox(), "Assistant without sandbox config should return false")
}

View file

@ -168,9 +168,18 @@ func (store *Xun) getAssistantTable() string {
func (store *Xun) parseJSONFields(data map[string]interface{}, fields []string) {
for _, field := range fields {
if val := data[field]; val != nil {
if strVal, ok := val.(string); ok && strVal != "" {
var jsonStr string
switch v := val.(type) {
case string:
jsonStr = v
case []byte:
jsonStr = string(v)
default:
continue
}
if jsonStr != "" {
var parsed interface{}
if err := jsoniter.UnmarshalFromString(strVal, &parsed); err == nil {
if err := jsoniter.UnmarshalFromString(jsonStr, &parsed); err == nil {
data[field] = parsed
}
}