Files
picoclaw/pkg/config/removed_hardware_test.go
T
loveuer b11c2c31ad refactor: remove built-in serial hardware support
Remove serial tools and platform implementations.
Drop tool registration, defaults, and example settings.
Ignore legacy tools.serial settings and remove them on save.
Update documentation and config compatibility tests.
2026-11-13 10:17:09 +08:00

51 lines
1.5 KiB
Go

package config
import (
"encoding/json"
"os"
"path/filepath"
"strconv"
"testing"
"github.com/stretchr/testify/require"
)
func TestLoadConfig_IgnoresRemovedHardwareSettings(t *testing.T) {
for version := 0; version <= CurrentVersion; version++ {
t.Run(strconv.Itoa(version), func(t *testing.T) {
mustSetupSSHKey(t)
path := filepath.Join(t.TempDir(), "config.json")
data, err := json.Marshal(map[string]any{
"version": version,
"devices": map[string]bool{"enabled": true, "monitor_usb": true},
"tools": map[string]any{
"i2c": map[string]bool{"enabled": true},
"spi": map[string]bool{"enabled": true},
"serial": map[string]bool{"enabled": true},
"read_file": map[string]bool{"enabled": false},
},
"gateway": map[string]int{"port": 18799},
})
require.NoError(t, err)
require.NoError(t, os.WriteFile(path, data, 0o600))
cfg, err := LoadConfig(path)
require.NoError(t, err)
require.False(t, cfg.Tools.ReadFile.Enabled)
require.Equal(t, 18799, cfg.Gateway.Port)
require.NoError(t, SaveConfig(path, cfg))
data, err = os.ReadFile(path)
require.NoError(t, err)
var saved map[string]any
require.NoError(t, json.Unmarshal(data, &saved))
require.NotContains(t, saved, "devices")
savedTools, ok := saved["tools"].(map[string]any)
require.True(t, ok)
require.NotContains(t, savedTools, "i2c")
require.NotContains(t, savedTools, "spi")
require.NotContains(t, savedTools, "serial")
require.Contains(t, savedTools, "read_file")
})
}
}