Files
AutoZero/tools/computer_windows_test.go
T
Sakurasan d5dac5a6fc feat: AutoZero 通用 Agent 框架(从 AutoGo 五阶段拆分完成)
llm(三协议 Provider)/ session(JSONL 持久化)/ tools(Registry、围栏、
builtin、computer)/ cdp(browser)/ skills / mcp / agent(循环、两级压缩、
编排、审批门控)+ 底座 jsonl/textx/execx/diag/scratch/spill/imagecache。

产品装配代码(config 桥接、schedule 工具、memory/plan/retro/prompt)
留在 AutoGo,宿主接入方式见 MIGRATION.md。
2026-10-26 00:54:46 +08:00

72 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build windows
package tools
import (
"context"
"testing"
)
// 这份用例只在 Windows 上编译,且**只有真的起得来 PowerShell 时才执行**:
// 没有 PowerShell 的机器(Server Core、被裁掉的镜像)应当跳过,而不是把
// "跑不起来" 报成 "后端坏了"。可用性问题走 Available(),不在这里重述。
func TestRunScript(t *testing.T) {
b := newGuiBackend()
if err := b.Available(); err != nil {
t.Skipf("PowerShell 不可用:%v", err)
}
w := b.(*windowsBackend)
out, err := w.runScript("Write-Output 'hello'")
if err != nil {
t.Fatalf("runScript 失败:%v", err)
}
if out != "hello" {
t.Fatalf("got %q, want hello", out)
}
}
func TestRunScriptError(t *testing.T) {
b := newGuiBackend()
if err := b.Available(); err != nil {
t.Skipf("PowerShell 不可用:%v", err)
}
if _, err := b.(*windowsBackend).runScript("throw 'test error'"); err == nil {
t.Fatal("失败的脚本该返回错误")
}
}
// 截图返回的是文件路径:这一条把"注入 user32 → 落到一个真实存在的 png"整条链
// 走完,是这套后端能用的最短证明。
func TestScreenshotWritesFile(t *testing.T) {
b := newGuiBackend()
if err := b.Available(); err != nil {
t.Skipf("PowerShell 不可用:%v", err)
}
path, err := b.Screenshot(context.Background(), "")
if err != nil {
t.Fatalf("Screenshot 失败:%v", err)
}
if path == "" {
t.Fatal("没有返回文件路径")
}
}
func TestPSUser32Constant(t *testing.T) {
if psUser32 == "" {
t.Fatal("psUser32 should not be empty")
}
}
func TestMouseConstants(t *testing.T) {
if meLeftDown != "2" || meLeftUp != "4" {
t.Fatal("left mouse constants incorrect")
}
if meRightDown != "8" || meRightUp != "16" {
t.Fatal("right mouse constants incorrect")
}
if meWheel != "2048" || wheelNotch != "120" {
t.Fatal("wheel constants incorrect")
}
}