better test + migration
This commit is contained in:
1 parent
27b713affa
commit
ab8260a5d0
8 files changed
+202
-34
No files matched your search
@@ -827,6 +827,41 @@ sudo tar -C /path/to/HERMES_HOME/.hermes -cf - . \
|
||||
| hermenix vm ssh 'mkdir -p /var/lib/hermes/.hermes-old && tar -C /var/lib/hermes/.hermes-old -xf -'
|
||||
```
|
||||
|
||||
### `hermes setup` fails with "docker not found on PATH. Cannot route to container"
|
||||
|
||||
`hermenix migrate` automatically excludes `.local/bin` and `.hermes-installed`
|
||||
from the migration tar, so this should not happen with current versions.
|
||||
If you see it after a migration with an older build, the source's
|
||||
`.local/bin/hermes` (a Docker-routing launcher from the previous environment)
|
||||
was copied into the guest and is shadowing the native install.
|
||||
|
||||
Fix inside the guest:
|
||||
|
||||
```bash
|
||||
# Remove the stale launcher
|
||||
rm -f ~/.local/bin/hermes
|
||||
|
||||
# Reinstall the native hermes binary
|
||||
curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh \
|
||||
| bash -s -- --non-interactive --skip-setup
|
||||
|
||||
# Verify it's a real binary, not a shell script
|
||||
file ~/.local/bin/hermes
|
||||
|
||||
# Now proceed with setup
|
||||
hermes setup
|
||||
```
|
||||
|
||||
If `hermes-install.service` never ran because `.hermes-installed` was also
|
||||
migrated from the source, you may instead let systemd do it:
|
||||
|
||||
```bash
|
||||
rm -f ~/.local/bin/hermes ~/.hermes-installed
|
||||
sudo systemctl start hermes-install
|
||||
journalctl -fu hermes-install # watch until complete
|
||||
hermes setup
|
||||
```
|
||||
|
||||
|
||||
## Hacking on this repo
|
||||
|
||||
|
||||
+7
-2
@@ -13,6 +13,11 @@
|
||||
# Not run for you automatically: this needs a real build, which agents in
|
||||
# this repo don't run (see GUIDELINES.md). You (or CI) run this by hand.
|
||||
|
||||
def main [] {
|
||||
^nix build ".#checks.x86_64-linux.guest-vm" --impure -L
|
||||
def main [
|
||||
suite?: string # which check to run: guest-vm (default) or migrate-connections-vm
|
||||
] {
|
||||
let check = $suite | default "guest-vm"
|
||||
let attr = $".#checks.x86_64-linux.($check)"
|
||||
print $"running ($attr)"
|
||||
^nix build $attr --impure -L
|
||||
}
|
||||
+7
-2
@@ -14,7 +14,12 @@
|
||||
# reads /etc/hermenix/local.nix if present). Not run for you automatically
|
||||
# — needs a real build, which agents in this repo don't run.
|
||||
|
||||
def main [] {
|
||||
^nix build ".#checks.x86_64-linux.guest-vm.driverInteractive" --impure -L
|
||||
def main [
|
||||
suite?: string # which check to debug: guest-vm (default) or migrate-connections-vm
|
||||
] {
|
||||
let check = $suite | default "guest-vm"
|
||||
let attr = $".#checks.x86_64-linux.($check).driverInteractive"
|
||||
print $"building interactive driver for ($attr)"
|
||||
^nix build $attr --impure -L
|
||||
^./result/bin/nixos-test-driver
|
||||
}
|
||||
@@ -121,6 +121,10 @@
|
||||
# nix build .#checks.x86_64-linux.guest-vm --impure -L
|
||||
checks.${system} = {
|
||||
guest-vm = import ./guest/vm-test.nix { inherit pkgs determinate; };
|
||||
migrate-connections-vm = import ./guest/migrate-connections-test.nix {
|
||||
inherit pkgs;
|
||||
hermenix = self.packages.${system}.hermenix;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -70,6 +70,7 @@ let
|
||||
gnused
|
||||
gawk
|
||||
findutils
|
||||
neovim
|
||||
];
|
||||
in
|
||||
{
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
# VM test for `hermenix migrate connections` — local (folder-to-folder) mode.
|
||||
#
|
||||
# Boots a minimal NixOS VM with the hermenix binary available, creates a fake
|
||||
# source HERMES_HOME from Nix-store fixtures, runs the command, and asserts:
|
||||
#
|
||||
# 1. Every requested file lands in the destination.
|
||||
# 2. Hostname rewrites are applied in the destination.
|
||||
# 3. The source is completely untouched.
|
||||
# 4. Identity files (SOUL.md) are NOT copied.
|
||||
# 5. Absent optional files are silently skipped without crashing.
|
||||
# 6. Subdirectories (--extra-dirs) are copied recursively.
|
||||
#
|
||||
# Run with:
|
||||
# nix build .#checks.x86_64-linux.migrate-connections-vm -L
|
||||
#
|
||||
# Fixture files are defined as pkgs.writeText values so their content lives
|
||||
# entirely in Nix string literals — no heredocs in the testScript. This
|
||||
# keeps every line in the testScript at consistent indentation so Nix's ''
|
||||
# string stripping produces valid top-level Python.
|
||||
{ pkgs, hermenix }:
|
||||
|
||||
let
|
||||
# Source fixtures — contain the stale Docker hostname that should be
|
||||
# rewritten in the destination but preserved in the source.
|
||||
srcConfigYaml = pkgs.writeText "src-config.yaml" ''
|
||||
model:
|
||||
provider: openai
|
||||
connections:
|
||||
- name: desktop
|
||||
host: host.docker.internal
|
||||
port: 3000
|
||||
'';
|
||||
srcAuthJson = pkgs.writeText "src-auth.json" ''
|
||||
{"endpoint": "http://host.docker.internal:8080/auth"}
|
||||
'';
|
||||
srcDotEnv = pkgs.writeText "src-dot-env" ''
|
||||
OPENAI_API_KEY=sk-test
|
||||
GATEWAY_URL=http://host.docker.internal:9000
|
||||
'';
|
||||
srcMcpJson = pkgs.writeText "src-mcp.json" ''
|
||||
{"url":"http://host.docker.internal:5000"}
|
||||
'';
|
||||
# Identity file — must never be copied by migrate connections.
|
||||
srcSoulMd = pkgs.writeText "src-SOUL.md" ''
|
||||
I am Hermes.
|
||||
'';
|
||||
in
|
||||
|
||||
pkgs.testers.runNixOSTest {
|
||||
name = "hermenix-migrate-connections";
|
||||
|
||||
nodes.machine = {
|
||||
environment.systemPackages = [ hermenix ];
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
# ------------------------------------------------------------------ setup
|
||||
# Copy Nix-store fixtures into a writable fake source HERMES_HOME so that
|
||||
# sed -i (which needs a writable file) works during the rewrite step.
|
||||
machine.succeed("mkdir -p /tmp/src/connections")
|
||||
machine.succeed("install -m644 ${srcConfigYaml} /tmp/src/config.yaml")
|
||||
machine.succeed("install -m644 ${srcAuthJson} /tmp/src/auth.json")
|
||||
machine.succeed("install -m644 ${srcDotEnv} /tmp/src/.env")
|
||||
machine.succeed("install -m644 ${srcMcpJson} /tmp/src/connections/mcp.json")
|
||||
machine.succeed("install -m644 ${srcSoulMd} /tmp/src/SOUL.md")
|
||||
|
||||
# ------------------------------------------------------- run the command
|
||||
# `echo copy` satisfies the confirm-word prompt non-interactively.
|
||||
# Default --files=[config.yaml auth.json .env] and --extra-dirs=[connections]
|
||||
# are used; list-typed flags cannot be passed from bash to a Nu binary.
|
||||
machine.succeed("echo copy | hermenix migrate connections /tmp/src /tmp/dst")
|
||||
|
||||
# ------------------------------------------- 1. files land in destination
|
||||
machine.succeed("test -f /tmp/dst/config.yaml")
|
||||
machine.succeed("test -f /tmp/dst/auth.json")
|
||||
machine.succeed("test -f /tmp/dst/.env")
|
||||
machine.succeed("test -f /tmp/dst/connections/mcp.json")
|
||||
|
||||
# --------------------------------------- 2. hostname rewrites applied
|
||||
machine.succeed("grep -q '10.77.0.1' /tmp/dst/config.yaml")
|
||||
machine.fail( "grep -q 'host.docker.internal' /tmp/dst/config.yaml")
|
||||
machine.succeed("grep -q '10.77.0.1' /tmp/dst/auth.json")
|
||||
machine.fail( "grep -q 'host.docker.internal' /tmp/dst/auth.json")
|
||||
machine.succeed("grep -q '10.77.0.1' /tmp/dst/.env")
|
||||
machine.fail( "grep -q 'host.docker.internal' /tmp/dst/.env")
|
||||
machine.succeed("grep -q '10.77.0.1' /tmp/dst/connections/mcp.json")
|
||||
machine.fail( "grep -q 'host.docker.internal' /tmp/dst/connections/mcp.json")
|
||||
|
||||
# ------------------------------------------ 3. source is completely untouched
|
||||
machine.succeed("grep -q 'host.docker.internal' /tmp/src/config.yaml")
|
||||
machine.succeed("grep -q 'host.docker.internal' /tmp/src/auth.json")
|
||||
machine.succeed("grep -q 'host.docker.internal' /tmp/src/.env")
|
||||
machine.succeed("grep -q 'host.docker.internal' /tmp/src/connections/mcp.json")
|
||||
|
||||
# ------------------------------------ 4. identity file was NOT copied
|
||||
machine.fail("test -f /tmp/dst/SOUL.md")
|
||||
|
||||
# ------------------- 5. absent optional files are silently skipped
|
||||
# Use a minimal source that only has config.yaml; auth.json and .env are
|
||||
# absent. The command must succeed and must not create the missing files.
|
||||
machine.succeed("mkdir -p /tmp/src2")
|
||||
machine.succeed("install -m644 ${srcConfigYaml} /tmp/src2/config.yaml")
|
||||
machine.succeed("echo copy | hermenix migrate connections /tmp/src2 /tmp/dst2")
|
||||
machine.succeed("test -f /tmp/dst2/config.yaml")
|
||||
machine.fail( "test -f /tmp/dst2/auth.json")
|
||||
machine.fail( "test -f /tmp/dst2/.env")
|
||||
'';
|
||||
}
|
||||
+16
-6
@@ -55,7 +55,19 @@ def "main migrate" [
|
||||
# leftovers from a prior rootless-container deployment) without that
|
||||
# aborting an otherwise-successful migration - tar still warns about it,
|
||||
# it just doesn't fail the whole pipeline over it.
|
||||
^tar --ignore-failed-read -C $source -cf - . | run-argv ($ssh_base ++ [$"mkdir -p '($dest)' && tar -C '($dest)' -xf -"])
|
||||
#
|
||||
# --exclude='./.local/bin': launcher scripts in .local/bin are
|
||||
# environment-specific (Docker wrappers, old arch builds, etc.) and must
|
||||
# never be carried into the guest. hermes-install.service installs the
|
||||
# correct native binary there on first boot; an overwritten launcher from
|
||||
# the source would shadow it and fail with "docker not found on PATH".
|
||||
#
|
||||
# --exclude='./.hermes-installed': this sentinel tells hermes-install to
|
||||
# skip the native install. Migrating it from the source would prevent the
|
||||
# guest from ever installing hermes if the source's .local/bin/hermes is
|
||||
# also excluded (above). Let the install service run and place a fresh
|
||||
# binary instead.
|
||||
^tar --ignore-failed-read --exclude='./.local/bin' --exclude='./.hermes-installed' -C $source -cf - . | run-argv ($ssh_base ++ [$"mkdir -p '($dest)' && tar -C '($dest)' -xf -"])
|
||||
|
||||
step 3 "rewriting stale hostnames in the guest"
|
||||
let last_idx = ($rewrite_from | length) - 1
|
||||
@@ -168,12 +180,10 @@ def "main migrate connections" [
|
||||
gssh "true"
|
||||
|
||||
step 2 $"streaming connection files ($source) -> guest:($guest_dest)"
|
||||
# Build an include list for tar: individual files + full dir trees.
|
||||
let file_args = $existing_files | each {|f| ["--include" $f] } | flatten
|
||||
let dir_args = $existing_dirs | each {|d| ["--include" $"($d)/**"] } | flatten
|
||||
let tar_args = $file_args | append $dir_args | append ["--no-recursion" "-cf" "-" "."]
|
||||
# Pass files and dirs as positional tar arguments — no --include needed.
|
||||
let tar_targets = $existing_files | append $existing_dirs
|
||||
(
|
||||
^tar --ignore-failed-read -C $source ...$tar_args
|
||||
^tar --ignore-failed-read -C $source -cf - ...$tar_targets
|
||||
| run-argv ($ssh_base ++ [$"mkdir -p '($guest_dest)' && tar -C '($guest_dest)' -xf -"])
|
||||
)
|
||||
|
||||
|
||||
+22
-24
@@ -18,11 +18,9 @@ def build-sed-expr [from: list<string>, to: list<string>] {
|
||||
| str join "; ")
|
||||
}
|
||||
|
||||
# Reproduce the tar-args assembly (everything after `tar -C $source`).
|
||||
def build-tar-args [files: list<string>, dirs: list<string>] {
|
||||
let file_args = $files | each {|f| ["--include" $f] } | flatten
|
||||
let dir_args = $dirs | each {|d| ["--include" $"($d)/**"] } | flatten
|
||||
$file_args | append $dir_args | append ["--no-recursion" "-cf" "-" "."]
|
||||
# Reproduce the tar-targets assembly (positional args after `tar -cf -`).
|
||||
def build-tar-targets [files: list<string>, dirs: list<string>] {
|
||||
$files | append $dirs
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -42,31 +40,25 @@ def "sed expr pairs are joined with semicolons" [] {
|
||||
}
|
||||
|
||||
@test
|
||||
def "tar args: flat files produce paired --include entries" [] {
|
||||
let args = build-tar-args [config.yaml .env] []
|
||||
assert ("--include" in $args)
|
||||
assert ("config.yaml" in $args)
|
||||
assert (".env" in $args)
|
||||
def "tar targets: contains all files and dirs" [] {
|
||||
let targets = build-tar-targets [config.yaml auth.json .env] [connections]
|
||||
assert ("config.yaml" in $targets)
|
||||
assert ("auth.json" in $targets)
|
||||
assert (".env" in $targets)
|
||||
assert ("connections" in $targets)
|
||||
}
|
||||
|
||||
@test
|
||||
def "tar args: dirs produce glob --include entries" [] {
|
||||
let args = build-tar-args [] [connections]
|
||||
assert ("connections/**" in $args)
|
||||
def "tar targets: no --include flags or globs" [] {
|
||||
let targets = build-tar-targets [config.yaml] [connections]
|
||||
assert (not ("--include" in $targets))
|
||||
assert (not (($targets | any {|x| $x | str contains "**" })))
|
||||
}
|
||||
|
||||
@test
|
||||
def "tar args: always end with --no-recursion -cf - ." [] {
|
||||
let args = build-tar-args [config.yaml] [connections]
|
||||
let tail = $args | last 4
|
||||
assert equal $tail ["--no-recursion" "-cf" "-" "."]
|
||||
}
|
||||
|
||||
@test
|
||||
def "tar args: result is a flat list of strings spreadable with spread operator" [] {
|
||||
let args = build-tar-args [config.yaml auth.json] [connections]
|
||||
# Every element must be a string so `...$args` works with ^tar.
|
||||
let all_strings = $args | all {|x| ($x | describe) == "string" }
|
||||
def "tar targets: result is a flat list of strings spreadable with spread operator" [] {
|
||||
let targets = build-tar-targets [config.yaml auth.json] [connections]
|
||||
let all_strings = $targets | all {|x| ($x | describe) == "string" }
|
||||
assert $all_strings
|
||||
}
|
||||
|
||||
@@ -75,3 +67,9 @@ def "migrate connections is registered in the command tree" [] {
|
||||
let names = scope commands | where name =~ '^main' | get name
|
||||
assert ("main migrate connections" in $names)
|
||||
}
|
||||
|
||||
@test
|
||||
def "main migrate is registered in the command tree" [] {
|
||||
let names = scope commands | where name =~ '^main' | get name
|
||||
assert ("main migrate" in $names)
|
||||
}
|
||||
Reference in new issue
Block a user