功能:完善云管助手与GPU故障恢复核对
This commit is contained in:
1 parent
b6026f9759
commit
9f7b01e4db
42 files changed
+3576
-120
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package server
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestAssistantPlanRequiresExplicitDesktopAndExecutesWithRecheck(t *testing.T) {
|
||||
f := newFixtureWorker(t, false)
|
||||
admin := f.login("admin")
|
||||
code, out := f.request("POST", "/assistant/plan", admin, map[string]any{"text": "给王工分配一台桌面"}, "")
|
||||
expect(t, 200, code, out)
|
||||
if out["status"] != "blocked" {
|
||||
t.Fatalf("unexpected plan status: %#v", out)
|
||||
}
|
||||
plan := out["plan"].(map[string]any)
|
||||
if plan["kind"] != "blocked" || plan["reason"] != "没有唯一匹配到桌面" {
|
||||
t.Fatalf("assistant selected a desktop without confirmation: %#v", plan)
|
||||
}
|
||||
code, out = f.request("POST", "/assistant/plan", admin, map[string]any{"text": "给王工分配国产办公桌面"}, "")
|
||||
expect(t, 200, code, out)
|
||||
if out["status"] != "planned" || out["plan"].(map[string]any)["kind"] != "action" {
|
||||
t.Fatalf("unexpected executable plan: %#v", out)
|
||||
}
|
||||
runID := out["runId"].(string)
|
||||
code, out = f.request("POST", "/assistant/execute", admin, map[string]any{"runId": runID}, "assistant-test-1")
|
||||
expect(t, 200, code, out)
|
||||
var exists bool
|
||||
if err := f.db.Get(&exists, `SELECT EXISTS(SELECT 1 FROM bindings b JOIN users u ON u.id=b.user_id JOIN desktops d ON d.id=b.desktop_id WHERE u.display_name='王工' AND d.name='国产办公桌面')`); err != nil || !exists {
|
||||
t.Fatalf("assistant did not create binding: %v", err)
|
||||
}
|
||||
code, out = f.request("POST", "/assistant/execute", admin, map[string]any{"runId": runID}, "assistant-test-2")
|
||||
if code != 200 || out["idempotent"] != true {
|
||||
t.Fatalf("assistant execution was not idempotent: %d %#v", code, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssistantPlanBlocksAmbiguousUser(t *testing.T) {
|
||||
f := newFixtureWorker(t, false)
|
||||
admin := f.login("admin")
|
||||
code, out := f.request("POST", "/assistant/plan", admin, map[string]any{"text": "请分配研发办公桌面"}, "")
|
||||
expect(t, 200, code, out)
|
||||
plan := out["plan"].(map[string]any)
|
||||
if plan["kind"] != "blocked" || plan["reason"] != "没有唯一匹配到员工" {
|
||||
t.Fatalf("missing employee was not blocked: %#v", plan)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user