Add DOCX, XLSX and PPTX skills with upstream scripts and licenses. Provide a version-locked Docker environment, diagnostics and smoke tests. Install embedded skills by name while preserving existing workspace content. Validate all Go tests and office workflows on home-dev; document setup.
47 lines
1.6 KiB
Go
47 lines
1.6 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// Opt in on a machine with the installed office runtime. Uses the same restricted
|
|
// execution tool as the gateway without relaxing its default command policies.
|
|
func TestOfficeRuntimeViaExecTool(t *testing.T) {
|
|
workspace := os.Getenv("PICOCLAW_OFFICE_TEST_WORKSPACE")
|
|
if workspace == "" {
|
|
t.Skip("set PICOCLAW_OFFICE_TEST_WORKSPACE to test the installed Docker runtime")
|
|
}
|
|
workspace, err := filepath.Abs(workspace)
|
|
require.NoError(t, err)
|
|
tool, err := NewExecTool(workspace, true)
|
|
require.NoError(t, err)
|
|
quote := func(value string) string { return "'" + strings.ReplaceAll(value, "'", "'\\''") + "'" }
|
|
wrapper := quote(filepath.Join(workspace, "tools", "office", "office.sh"))
|
|
result := tool.Execute(
|
|
context.Background(),
|
|
map[string]any{"action": "run", "command": "bash " + wrapper + " check"},
|
|
)
|
|
require.False(t, result.IsError, result.ForLLM)
|
|
require.Contains(t, result.ForLLM, "Office runtime ready")
|
|
result = tool.Execute(
|
|
context.Background(),
|
|
map[string]any{
|
|
"action": "run",
|
|
"command": "bash " + wrapper + " run -- python -c " + quote(
|
|
"from pathlib import Path; Path('office-exec-check.txt').write_text('办公工具执行成功', encoding='utf-8')",
|
|
),
|
|
},
|
|
)
|
|
require.False(t, result.IsError, result.ForLLM)
|
|
data, err := os.ReadFile(filepath.Join(workspace, "office-exec-check.txt"))
|
|
require.NoError(t, err)
|
|
require.Equal(t, "办公工具执行成功", string(data))
|
|
require.NoError(t, os.Remove(filepath.Join(workspace, "office-exec-check.txt")))
|
|
}
|