feat: implement NATS-based NixOS deployment system
Implement the complete homelab-deploy system with three operational modes: - Listener mode: Runs on NixOS hosts as a systemd service, subscribes to NATS subjects with configurable templates, executes nixos-rebuild on deployment requests with concurrency control - MCP mode: MCP server exposing deploy, deploy_admin, and list_hosts tools for AI assistants with tiered access control - CLI mode: Manual deployment commands with subject alias support via environment variables Key components: - internal/messages: Request/response types with validation - internal/nats: Client wrapper with NKey authentication - internal/deploy: Executor with timeout and lock for concurrency - internal/listener: Subject template expansion and request handling - internal/cli: Deploy logic with alias resolution - internal/mcp: MCP server with mcp-go integration - nixos/module.nix: NixOS module with hardened systemd service Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
43
internal/mcp/server_test.go
Normal file
43
internal/mcp/server_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package mcp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
cfg := ServerConfig{
|
||||
NATSUrl: "nats://localhost:4222",
|
||||
NKeyFile: "/path/to/key",
|
||||
EnableAdmin: false,
|
||||
AdminNKeyFile: "",
|
||||
DiscoverSubject: "deploy.discover",
|
||||
Timeout: 10 * time.Minute,
|
||||
}
|
||||
|
||||
s := New(cfg)
|
||||
|
||||
if s == nil {
|
||||
t.Fatal("New() returned nil")
|
||||
}
|
||||
if s.server == nil {
|
||||
t.Error("server should not be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNew_WithAdmin(t *testing.T) {
|
||||
cfg := ServerConfig{
|
||||
NATSUrl: "nats://localhost:4222",
|
||||
NKeyFile: "/path/to/key",
|
||||
EnableAdmin: true,
|
||||
AdminNKeyFile: "/path/to/admin/key",
|
||||
DiscoverSubject: "deploy.discover",
|
||||
Timeout: 10 * time.Minute,
|
||||
}
|
||||
|
||||
s := New(cfg)
|
||||
|
||||
if s == nil {
|
||||
t.Fatal("New() returned nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user