chore: 初始化仓库(零源工具箱 0.1.0 基线)

- Go 主进程 cmd/zerorigin(托盘常驻 + 触发器/规则/动作引擎)
- Wails v3 设置进程 cmd/settings(独立 module)
- 监督进程 cmd/watchdog(-supervise 异常重启)
- 构建脚本 build.bat / NSIS 安装包 deploy/、便携版 portable/
- 架构与 MVP 计划文档 docs/、阶段 0-4 验收记录 deploy/acceptance-0-4.md
This commit is contained in:
zerorigin2019 committed 2026-08-05 00:42:45 +08:00
commit 0a1c1e82ea
188 files changed
+19926

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
package main
import (
"encoding/json"
"strings"
"testing"
)
func TestValidateConfig(t *testing.T) {
cfg := &Config{Rules: []Rule{
{ID: "r1", Name: "好规则", Trigger: TriggerConfig{Type: "mouse_corner"}, Actions: []ActionConfig{{Type: "volume_up"}}},
{ID: "r2", Name: "坏触发器", Trigger: TriggerConfig{Type: "nope"}, Actions: []ActionConfig{{Type: "volume_up"}}},
{ID: "r3", Name: "空动作", Trigger: TriggerConfig{Type: "hotkey"}},
{ID: "r1", Name: "重复ID", Trigger: TriggerConfig{Type: "hotkey"}, Actions: []ActionConfig{{Type: "open_url"}}},
{ID: "r5", Name: "坏动作", Trigger: TriggerConfig{Type: "hotkey"}, Actions: []ActionConfig{{Type: "evil"}}},
}}
errs := ValidateConfig(cfg)
if len(errs) != 4 {
t.Fatalf("errs = %d, want 4: %v", len(errs), errs)
}
joined := strings.Join(errs, "\n")
for _, want := range []string{"未知触发器", "至少需要一个动作", "id 重复", "未知动作类型"} {
if !strings.Contains(joined, want) {
t.Errorf("missing error %q in: %s", want, joined)
}
}
}
func TestTriggerConfigRoundTrip(t *testing.T) {
src := `{"type":"mouse_corner","corner":"bottom_left","screen":"all","threshold_px":32}`
var tc TriggerConfig
if err := json.Unmarshal([]byte(src), &tc); err != nil {
t.Fatal(err)
}
if tc.Type != "mouse_corner" || tc.Params["corner"] != "bottom_left" {
t.Fatalf("unmarshal wrong: %+v", tc)
}
out, err := json.Marshal(&tc)
if err != nil {
t.Fatal(err)
}
var back TriggerConfig
if err := json.Unmarshal(out, &back); err != nil {
t.Fatal(err)
}
if back.Type != "mouse_corner" || back.Params["threshold_px"] != float64(32) {
t.Fatalf("round trip lost data: %s", out)
}
}
func TestSanitizeRule(t *testing.T) {
r := &Rule{
Trigger: TriggerConfig{Type: "hotkey", Params: map[string]any{"hotkey": " ctrl+alt+d "}},
Actions: []ActionConfig{{Type: "volume_up"}}, // params nil
}
sanitizeRule(r)
if r.Trigger.Params["hotkey"] != "ctrl+alt+d" {
t.Fatalf("hotkey not trimmed: %v", r.Trigger.Params)
}
if r.Actions[0].Params == nil {
t.Fatal("action params should be initialized")
}
}