118 lines
5.3 KiB
Nix
118 lines
5.3 KiB
Nix
# 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";
|
|
|
|
# This test only boots once and copies a few small files locally — it
|
|
# should finish in well under a minute. Bound it far below the framework's
|
|
# 1-hour default so a regression (e.g. a prompt silently blocking on
|
|
# terminal input instead of reading piped stdin) fails fast instead of
|
|
# burning a full hour before being reported.
|
|
globalTimeout = 300;
|
|
|
|
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")
|
|
'';
|
|
}
|