-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrpc_lua_test.go
More file actions
109 lines (92 loc) · 2.47 KB
/
Copy pathrpc_lua_test.go
File metadata and controls
109 lines (92 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"context"
"os/exec"
"strings"
"testing"
"time"
"github.com/unxed/f4/vfs"
"github.com/unxed/vtui"
)
// mockHostAPI captures logs from the plugin for verification
type mockHostAPI struct {
coreAPI
logs []string
}
func (m *mockHostAPI) Log(msg string) {
m.logs = append(m.logs, msg)
}
func TestLuaPluginIntegration(t *testing.T) {
// 1. Environmental Check: do we even have Lua?
_, err := exec.LookPath("lua")
if err != nil {
t.Skip("Skipping Lua integration test: 'lua' interpreter not found in PATH")
}
// 2. Dependency Check: does Lua have MessagePack?
checkCmd := exec.Command("lua", "-e", "require('MessagePack')")
if err := checkCmd.Run(); err != nil {
t.Skip("Skipping Lua integration test: Lua module 'MessagePack' not installed")
}
vtui.FrameManager.Init(vtui.NewSilentScreenBuf())
// 3. Initialize the real RPC plugin pointing to the dummy script
pluginPath := "plugins/dummy_lua/plugin.lua"
p := NewRPCPlugin(pluginPath)
host := &mockHostAPI{}
// We need to run Init in a timeout because it's a blocking RPC call
done := make(chan error, 1)
go func() {
done <- p.Init(host)
}()
select {
case err := <-done:
if err != nil {
t.Fatalf("Failed to initialize Lua plugin: %v", err)
}
case <-time.After(5 * time.Second):
t.Fatal("Timeout waiting for Lua plugin initialization")
}
// 4. Verify Handshake results
foundDrive := false
for _, drv := range DriveRegistry {
// The dummy plugin registers "Lua Virtual Drive"
if strings.Contains(drv.Name, "Lua") {
foundDrive = true
break
}
}
if !foundDrive {
t.Error("Lua plugin failed to register its VFS drive in the global registry")
}
// 5. Verify VFS Communication
luaVfs := NewRPCVFS(p.sess, "Lua Virtual Drive")
var items []vfs.VFSItem
err = luaVfs.ReadDir(context.Background(), "/", func(chunk []vfs.VFSItem) {
items = append(items, chunk...)
})
if err != nil {
t.Fatalf("VFS.ReadDir failed over Lua RPC: %v", err)
}
// Check if we got our virtual files from plugin.lua
foundReadme := false
for _, itm := range items {
if itm.Name == "readme.txt" {
foundReadme = true
break
}
}
if !foundReadme {
t.Errorf("VFS.ReadDir didn't return expected files. Got: %v", items)
}
// 6. Verify Host Callbacks (Logging)
foundLog := false
for _, l := range host.logs {
if strings.Contains(l, "Lua Plugin: Initializing") {
foundLog = true
break
}
}
if !foundLog {
t.Error("Host.Log callback from Lua was not captured by Go side")
}
p.Close()
}