mirror of
https://github.com/hotwa/luci-app-openclaw.git
synced 2026-03-30 20:25:44 +00:00
feat(storage): support configurable install root
Add a LuCI install-root input, persist the selected path in UCI, and route install, status, backup, uninstall, and runtime scripts through the configured storage root for new installs. Reference: custom install root flow
This commit is contained in:
37
tests/test_openclaw_paths.lua
Normal file
37
tests/test_openclaw_paths.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
local script_dir = arg[0]:match("^(.*)/[^/]+$")
|
||||
local repo_root = script_dir:gsub("/tests$", "")
|
||||
|
||||
package.path = table.concat({
|
||||
repo_root .. "/luasrc/?.lua",
|
||||
repo_root .. "/luasrc/?/init.lua",
|
||||
repo_root .. "/luasrc/?/?.lua",
|
||||
package.path,
|
||||
}, ";")
|
||||
|
||||
local paths = require("openclaw.paths")
|
||||
|
||||
local function assert_eq(actual, expected, label)
|
||||
if actual ~= expected then
|
||||
error(string.format("%s: expected %q, got %q", label, expected, actual), 2)
|
||||
end
|
||||
end
|
||||
|
||||
local function check_root(input, expected_root, expected_base)
|
||||
local normalized = paths.normalize_install_root(input)
|
||||
local derived = paths.derive_paths(input)
|
||||
|
||||
assert_eq(normalized, expected_root, "normalized root")
|
||||
assert_eq(derived.install_root, expected_root, "derived install root")
|
||||
assert_eq(derived.oc_root, expected_base, "derived OpenClaw root")
|
||||
assert_eq(derived.node_base, expected_base .. "/node", "node base")
|
||||
assert_eq(derived.oc_global, expected_base .. "/global", "global base")
|
||||
assert_eq(derived.oc_data, expected_base .. "/data", "data base")
|
||||
end
|
||||
|
||||
check_root(nil, "/opt", "/opt/openclaw")
|
||||
check_root("", "/opt", "/opt/openclaw")
|
||||
check_root("/mnt/emmc/", "/mnt/emmc", "/mnt/emmc/openclaw")
|
||||
check_root("relative/path", "/opt", "/opt/openclaw")
|
||||
check_root("/", "/", "/openclaw")
|
||||
|
||||
print("ok")
|
||||
30
tests/test_openclaw_paths.sh
Normal file
30
tests/test_openclaw_paths.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
|
||||
REPO_ROOT=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
|
||||
|
||||
. "$REPO_ROOT/root/usr/libexec/openclaw-paths.sh"
|
||||
|
||||
fail() {
|
||||
echo "FAIL: $1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
oc_load_paths "/mnt/emmc/"
|
||||
[ "$OPENCLAW_INSTALL_ROOT" = "/mnt/emmc" ] || fail "normalized install root"
|
||||
[ "$OC_ROOT" = "/mnt/emmc/openclaw" ] || fail "derived OpenClaw root"
|
||||
[ "$NODE_BASE" = "/mnt/emmc/openclaw/node" ] || fail "derived node path"
|
||||
[ "$OC_GLOBAL" = "/mnt/emmc/openclaw/global" ] || fail "derived global path"
|
||||
[ "$OC_DATA" = "/mnt/emmc/openclaw/data" ] || fail "derived data path"
|
||||
|
||||
oc_load_paths "relative/path"
|
||||
[ "$OPENCLAW_INSTALL_ROOT" = "/opt" ] || fail "fallback install root"
|
||||
[ "$OC_ROOT" = "/opt/openclaw" ] || fail "fallback OpenClaw root"
|
||||
|
||||
tmpdir=$(mktemp -d)
|
||||
trap 'rm -rf "$tmpdir"' EXIT INT TERM
|
||||
existing=$(oc_find_existing_path "$tmpdir/missing/nested")
|
||||
[ "$existing" = "$tmpdir" ] || fail "nearest existing path"
|
||||
|
||||
echo "ok"
|
||||
Reference in New Issue
Block a user