Files
LocalAI/pkg/addons/packaging/host_policy_test.go
T
Ettore Di Giacinto bab8a605cc feat(addons): add the PiKVM add-on
Chats and agents can check a PiKVM (kvmd) device and, when a person
confirms each call, press the power buttons of the machine it controls
and use its keyboard.

Read tools: get-info (model, versions, no serial or host name),
get-power-state (ATX LEDs) and get-keyboard-state. Write tools:
power-action (on, off, reset; off_hard, reset_hard and long_press only
with a per-device switch), type-text (bounded, no control characters,
refuses key, token and password-list shapes) and send-key (a short
allowlist, no Windows or Meta chords). All three declare approval
always. The preview reads the power state; apply reads it again and
rejects a stale operation. The add-on journals before it sends, never
retries and reports unknown when the connection drops.

One connection is one device: the address is the single resource of the
connection and the one sealed credential holds user:password, split at
the first colon. A one-time code is not supported. The add-on speaks
only to that address, refuses redirects, uses no proxy and accepts a
self-signed certificate only through a #sha256= pin in the address.
Typing, the text length and hard power actions are per-device switches
that an administrator sets on the add-on page; all start off. Snapshots,
mass storage, GPIO and the mouse are left out.

The add-on ships a skill, a connection page with a Test button and
approval cards, the package files, the library entry and the docs, and
joins the package workflow and the case inventory.

PiKVM API reference: https://docs.pikvm.org/api/

Assisted-by: Claude:claude-sonnet-5-5 go node
2026-11-04 17:20:57 +00:00

36 lines
1.5 KiB
Go

// SPDX-License-Identifier: MIT
package packaging_test
import (
"os"
"path/filepath"
"strings"
"github.com/mudler/LocalAI/core/config"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("official host policy deployment", func() {
It("loads exactly the historical grants through the actual host loader", func() {
root, err := filepath.Abs(filepath.Join("..", "..", ".."))
Expect(err).NotTo(HaveOccurred())
grants, err := config.LoadAddonHostPolicy(filepath.Join(root, "deploy", "addons", "host-policy.json"))
Expect(err).NotTo(HaveOccurred())
// Deployment-owned exception: historical identity grants, not core defaults.
legacy := "fine-tuning=finetune.,quantization=quantize.,sandbox=workspace.,sandbox=egress.,office=workspace.,web=workspace.,home-assistant=workspace.,pikvm=workspace.,telegram=connector.,slack=connector.,discord=connector."
want, err := config.ParseAddonHostOps(legacy)
Expect(err).NotTo(HaveOccurred())
Expect(grants).To(Equal(want))
})
It("explicitly selects the shipped policy in the final Docker runtime stage", func() {
data, err := os.ReadFile(filepath.Join("..", "..", "..", "Dockerfile"))
Expect(err).NotTo(HaveOccurred())
start := strings.LastIndex(string(data), "\nFROM ")
Expect(start).To(BeNumerically(">=", 0))
runtime := string(data[start:])
Expect(runtime).To(ContainSubstring("COPY deploy/addons/host-policy.json /etc/localai/addons/host-policy.json"))
Expect(runtime).To(ContainSubstring("ENV LOCALAI_ADDON_HOST_POLICY=/etc/localai/addons/host-policy.json"))
})
})