From 5646eca119f80f8f45ebec9fcbe666ca614ebf5d Mon Sep 17 00:00:00 2001 From: James O'Doherty Date: Sat, 13 Jun 2026 13:50:25 -0400 Subject: feat: implement system preflight checks and health diagnostics Introduced a tiered system verification mechanism to improve reliability and provide actionable feedback to users, avoiding false positives in the critical execution path. Key changes: - Implement `CheckSystemRequirements` for critical, non-ambiguous requirements (e.g., TUN device availability) to ensure fatal environment issues are caught immediately during bootstrap. - Implement a user-facing `healthcheck` command that provides comprehensive diagnostics and actionable configuration hints for common misconfigurations (e.g., unprivileged user namespaces, subuid/subgid mappings, and kernel sysctls). - Refactor the `FileSystem` interface to support full mockability, allowing for exhaustive unit testing of diagnostic logic. - Add comprehensive unit tests in `internal/namespace/preflight_test.go` covering various Linux distributions, privilege levels, and hardware availability scenarios. - Ensure code quality through formatting, static analysis (golangci-lint), and validation of all existing unit, integration, and E2E tests. --- internal/namespace/namespace.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'internal/namespace/namespace.go') diff --git a/internal/namespace/namespace.go b/internal/namespace/namespace.go index 368775f..3f27faf 100644 --- a/internal/namespace/namespace.go +++ b/internal/namespace/namespace.go @@ -58,6 +58,8 @@ type FileSystem interface { CreateTemp(dir, pattern string) (*os.File, error) MkdirTemp(dir, pattern string) (string, error) Remove(name string) error + ReadFile(name string) ([]byte, error) + Open(name string) (*os.File, error) } // realFS is the production implementation using the os package. @@ -73,7 +75,9 @@ func (r *realFS) CreateTemp(dir, pattern string) (*os.File, error) { func (r *realFS) MkdirTemp(dir, pattern string) (string, error) { return os.MkdirTemp(dir, pattern) } -func (r *realFS) Remove(name string) error { return os.Remove(name) } +func (r *realFS) Remove(name string) error { return os.Remove(name) } +func (r *realFS) ReadFile(name string) ([]byte, error) { return os.ReadFile(name) } +func (r *realFS) Open(name string) (*os.File, error) { return os.Open(name) } // DefaultFS is the global instance used by the package functions. var DefaultFS FileSystem = &realFS{} -- cgit v1.2.3