'}}'
exit 0
;;
- *'make build-'*)
+ *'make build-'*|*'make test-'*)
$GUIX_BIN/echo \
'{"hookSpecificOutput": {' \
' "hookEventName": "PreToolUse",' \
build-vps: build-vps-system build-vps-home
+test-vps: build-vps-system build-vps-home
+ @out=$$(GUIX_PACKAGE_PATH=$(CURDIR) guix build -L $(CURDIR) \
+ -e '(@ (tests base) %vps-system-test)' 2>/dev/null); \
+ if [ -n "$$out" ] && [ -e "$$out" ]; then \
+ echo "📋 Cached: $$out"; \
+ echo " Run 'make test-vps-fresh' to re-execute."; \
+ else \
+ GUIX_PACKAGE_PATH=$(CURDIR) guix build -L $(CURDIR) \
+ -e '(@ (tests base) %vps-system-test)'; \
+ fi
+
+test-vps-fresh: build-vps-system build-vps-home
+ @out=$$(GUIX_PACKAGE_PATH=$(CURDIR) guix build -L $(CURDIR) \
+ -e '(@ (tests base) %vps-system-test)' 2>/dev/null); \
+ [ -n "$$out" ] && [ -e "$$out" ] \
+ && guix gc --delete "$$out" 2>/dev/null; \
+ GUIX_PACKAGE_PATH=$(CURDIR) guix build -L $(CURDIR) \
+ -e '(@ (tests base) %vps-system-test)'
+
tags:
find $(guix-store) -wholename "*guix-$(guix-version)*.scm" -or \
-wholename "*guix-module-union*.scm" -or \
--- /dev/null
+;; Copyright (c) 2026 Jakub Czajka <jakub@ekhem.eu.org>
+;; License: GPL-3.0 or later.
+;;
+;; The VPS VM test harness.
+
+(define-module (tests base)
+ #:use-module (gnu tests)
+ #:use-module (gnu system vm)
+ #:use-module (guix gexp)
+ #:use-module (tests vps-home)
+ #:use-module (tests vps-system)
+ #:export (%vps-system-test))
+
+(define (run-vps-test test-cases)
+ (let* ((vm (virtual-machine (operating-system
+ %vps-test-os)
+ (memory-size 1024)))
+ (builder #~(begin
+ (use-modules (gnu build marionette)
+ (srfi srfi-64))
+ ;; -cpu host requires KVM.
+ (define marionette
+ (make-marionette (list #$vm "-cpu" "host")))
+ (marionette-eval '(use-modules (gnu services herd))
+ marionette)
+ (test-runner-current (system-test-runner #$output))
+ (test-begin "vps")
+ #$@(map (lambda (test-case)
+ (test-case #~marionette)) test-cases)
+ (test-end "vps"))))
+ (gexp->derivation "vps-test" builder
+ #:modules '((gnu build marionette)))))
+
+(define %vps-system-test
+ (system-test (name "vps")
+ (description "VPS test suite.")
+ (value (run-vps-test (list sshd-test-cases daemons-test-cases
+ vps-home-test-cases)))))
--- /dev/null
+;; Copyright (c) 2026 Jakub Czajka <jakub@ekhem.eu.org>
+;; License: GPL-3.0 or later.
+;;
+;; Run the Guix Home activate script and then the home tests.
+
+(define-module (tests vps-home)
+ #:use-module (gnu packages admin)
+ #:use-module (gnu packages base)
+ #:use-module (conf home claude)
+ #:use-module (conf home paseo)
+ #:use-module (guix gexp)
+ #:use-module (tests vps-system)
+ #:use-module (vps-home)
+ #:export (vps-home-test-cases))
+
+(define %activate
+ (file-append vps-home-environment "/activate"))
+(define %timeout
+ (file-append coreutils "/bin/timeout"))
+
+(define %home-prelude
+ `(begin
+ (use-modules (ice-9 popen)
+ (ice-9 rdelim))
+
+ (define (run-command-output command)
+ (let* ((port (open-input-pipe command))
+ (output (read-string port)))
+ (list (eqv? 0
+ (status:exit-val (close-pipe port))) output)))
+
+ (define runtime-dir
+ (format #f "/run/user/~a"
+ (passwd:uid (getpwnam ,%test-user))))
+ (system* ,(file-append coreutils "/bin/install") "--directory"
+ "--mode=700"
+ ,(string-append "--owner=" %test-user) runtime-dir)
+ (define (run command)
+ (let ((prefix (format #f
+ "~a 90 ~a -n -u ~a -- ~a XDG_RUNTIME_DIR="
+ ,%timeout
+ ,(file-append sudo "/bin/sudo")
+ ,%test-user
+ ,(file-append coreutils "/bin/env"))))
+ (run-command-output (string-append prefix runtime-dir " " command
+ " 2>&1"))))))
+
+(define %home-activation-body
+ `(let ((result (run (string-append ,%activate " > /tmp/home-activate.log"))))
+ (unless (car result)
+ (format (current-error-port) "~a"
+ (call-with-input-file "/tmp/home-activate.log"
+ read-string)))
+ (car result)))
+
+(define (assert-home marionette label body)
+ #~(test-assert #$label
+ (let ((result (marionette-eval '#$body
+ #$marionette)))
+ (or (eq? result #t)
+ (begin
+ (format (current-error-port) "~a: ~s~%"
+ #$label result) #f)))))
+
+(define (vps-home-test-cases marionette)
+ #~(begin
+ (marionette-eval '#$%home-prelude
+ #$marionette)
+ #$(assert-home marionette "home: vps-home activates"
+ %home-activation-body)
+ (test-assert "home: dak user exists"
+ (marionette-eval '(file-exists? "/home/dak")
+ #$marionette))
+ (test-assert "home: claude binary exists"
+ (marionette-eval '(file-exists? (string-append #$claude-code
+ "/bin/claude"))
+ #$marionette))
+ (test-assert "home: paseo binary exists"
+ (marionette-eval '(file-exists? (string-append #$paseo
+ "/bin/paseo"))
+ #$marionette))
+ (test-assert "home: .guile exists"
+ (marionette-eval '(file-exists? "/home/dak/.guile")
+ #$marionette))))
--- /dev/null
+;; Copyright (c) 2026 Jakub Czajka <jakub@ekhem.eu.org>
+;; License: GPL-3.0 or later.
+;;
+;; System tests and the VM test operating system.
+
+(define-module (tests vps-system)
+ #:use-module (gnu tests)
+ #:use-module (gnu system)
+ #:use-module ((gnu services)
+ #:select ((delete . remove-service) service modify-services))
+ #:use-module (gnu services base)
+ #:use-module (gnu services ssh)
+ #:use-module (gnu services networking)
+ #:use-module (gnu packages ssh)
+ #:use-module (conf vps sshd)
+ #:use-module (guix gexp)
+ #:use-module (vps-system)
+ #:export (%vps-test-os %test-user daemons-test-cases sshd-test-cases))
+
+(define %test-user
+ "dak")
+
+(define %sshd-login-keypair
+ (computed-file "sshd-login-keypair"
+ #~(begin
+ (mkdir #$output)
+ (chdir #$output)
+ (let ((keygen #$(file-append openssh "/bin/ssh-keygen"))
+ (args '("-t" "ed25519" "-f" "login-key" "-N" "")))
+ (unless (zero? (apply system* keygen args))
+ (exit 1))))))
+
+(define %sshd-key-auth-body
+ `(let ((ssh ,(file-append openssh "/bin/ssh"))
+ (key "/tmp/login-key"))
+ (copy-file ,(file-append %sshd-login-keypair "/login-key") key)
+ (chmod key #o600)
+ (zero? (system* ssh "-n" "-i" key
+ ,@(append '("-oStrictHostKeyChecking=no"
+ "-oUserKnownHostsFile=/dev/null"
+ "-oBatchMode=yes" "-oConnectTimeout=10" "-p")
+ (list (number->string %sshd-port)
+ (string-append %test-user "@localhost")
+ "true"))))))
+
+(define (sshd-test-cases marionette)
+ #~(test-assert "sshd: shell command via key auth"
+ (begin
+ (marionette-eval '(start-service 'ssh-daemon)
+ #$marionette)
+ (wait-for-tcp-port #$%sshd-port
+ #$marionette)
+ (marionette-eval '#$%sshd-key-auth-body
+ #$marionette))))
+
+;; QEMU's default e1000 NIC is ens3, not eth0.
+(define %static-network-config-to-avoid-qemu-dhcp-hang
+ (let ((addr (network-address (device "ens3")
+ (value "10.0.2.15/24")))
+ (route (network-route (destination "default")
+ (gateway "10.0.2.2"))))
+ (static-networking (addresses (list addr))
+ (routes (list route)))))
+
+(define %static-networking
+ (service static-networking-service-type
+ (list %static-network-config-to-avoid-qemu-dhcp-hang)))
+
+(define (authorize-login config)
+ (let ((public-key (file-append %sshd-login-keypair "/login-key.pub")))
+ (openssh-configuration (inherit config)
+ (authorized-keys `((,%test-user ,public-key))))))
+
+(define %test-services
+ (cons %static-networking
+ (modify-services (operating-system-user-services vps-operating-system)
+ (remove-service dhcpcd-service-type)
+ (openssh-service-type config =>
+ (authorize-login config)))))
+
+(define (daemons-test-cases marionette)
+ #~(test-assert "services: NTP is up"
+ (marionette-eval '(start-service 'ntpd)
+ #$marionette)))
+
+(define %vps-test-os
+ (marionette-operating-system (operating-system
+ (inherit vps-operating-system)
+ (services
+ %test-services))
+ #:imported-modules '((gnu services herd))))