feat: system-agnostic package manager — 5 inits, 2 bootloaders, parallel scheduler

Complete rewrite of kappa from a sequential build tool into a
system-agnostic package manager with runtime init switching.

Core additions:
- 5 init system backends: systemd, openrc, s6, runit, dinit
  (service file generation, enable/disable, init_paths)
- 2 bootloader backends: grub, limine (config generation, fallback entries)
- Parallel scheduler with worker pool, depth-based priority (Beta/Alpha/Zeta),
  atomic claiming, dependency tracking, deduplication, and failure propagation
- Init-switch impact analysis: only rebuild packages using ${enabledinit}
- Init-agnostic service definitions: flat NamedService blocks replace
  per-init nesting
- Package conflicts: mutual incompatibility detection in resolver
- System groups: init-agnostic group creation in DSL
- Init-agnostic hostname/timezone: direct /etc/hostname and /etc/localtime writes
- Source tarball caching at /kappa/cache/ with atomic write-then-rename
- Package recipe caching with remote fetching and version comparison
- remotes = [...] block in system config for package repositories
- Auto-fetch: rebuild resolves missing packages from remotes
- uninstall phase in package definitions
- ${enabledinit} eval variable for init-conditional builds
- Shared util module (to_lower, shell_escape)
- 54 integration tests across two shell test suites
- Comprehensive README and CONTRIBUTING guide

Bug fixes from review:
- CRITICAL: Replace std::system() with fork+execvp (command injection)
- CRITICAL: Fix scheduler deadlock on successful completion
- CRITICAL: Fix rebuild init/kernel/bootloader change detection
- HIGH: Fix path traversal via unsanitized package names in cache
- HIGH: Fix TOCTOU race in cache write with atomic rename
- HIGH: Fix formatter dropping remotes/imports blocks
- HIGH: Fix formatter stripping empty-string assert values
- HIGH: Fix formatter non-idempotent output (sorted key iteration)
- HIGH: Populate ${enabledinit} from boot.init in BuildStep
- MEDIUM: Fix data race on non-atomic scheduler stop flag
- MEDIUM: Fix compute_depths() traversal direction
- MEDIUM: Add runit to doctor supported-init warning
- MEDIUM: Extract to_lower/shell_escape to shared kappa::util
- MEDIUM: Consolidate generator declarations in headers
This commit is contained in:
2026-07-31 05:32:57 -04:00
parent d6612d0a4a
commit dd984f96d4
40 changed files with 3047 additions and 117 deletions
Executable
+230
View File
@@ -0,0 +1,230 @@
#!/bin/sh
# $KAPPA integration test suite
# Run: docker run --rm -v $(pwd):/opt/$KAPPA kappa-test ./test.sh
set -e
KAPPA="${KAPPA_BIN:-./build/kappa}"
PASS=0
FAIL=0
check() {
local desc="$1" cmd="$2" expect="$3"
local out
out=$(eval "$cmd" 2>&1) || true
if echo "$out" | grep -q "$expect"; then
echo " ✓ $desc"
PASS=$((PASS + 1))
else
echo " ✗ $desc"
echo " expected: $expect"
echo " got: $(echo "$out" | head -3)"
FAIL=$((FAIL + 1))
fi
}
echo ""
echo "=== Package DSL tests ==="
echo ""
check "parse foo.kap" \
"$KAPPA parse-package examples/foo.kap" \
'package "foo" 1.2.3 — valid'
check "parse postgres.kap (multi-service)" \
"$KAPPA parse-package examples/postgres.kap" \
'package "postgresql" 16.3 — valid'
check "format foo.kap round-trips service block" \
"$KAPPA format examples/foo.kap" \
'service {'
check "format shows conflicts when present" \
"$KAPPA format /tmp/test_conflict.kap" \
'conflicts ='
check "format postgres.kap shows named services" \
"$KAPPA format examples/postgres.kap" \
'service checkpointer {'
echo ""
echo "=== Config DSL tests ==="
echo ""
check "parse config.kap" \
"$KAPPA parse-config examples/config.kap" \
'system config — valid'
check "config.kap shows init description" \
"$KAPPA parse-config examples/config.kap" \
's6 — s6 supervision suite'
check "config.kap shows bootloader description" \
"$KAPPA parse-config examples/config.kap" \
'Limine — modern multiprotocol bootloader'
echo ""
echo "=== Doctor tests ==="
echo ""
check "doctor foo.kap" \
"$KAPPA doctor examples/foo.kap" \
'no issues found'
echo ""
echo "=== Validate tests ==="
echo ""
check "validate foo.kap" \
"$KAPPA validate examples/foo.kap" \
'valid package'
echo ""
echo "=== Rebuild tests ==="
echo ""
check "rebuild detects new packages" \
"$KAPPA rebuild examples/config.kap" \
'packages to rebuild'
echo ""
echo "=== Init system recognition tests ==="
echo ""
# Create temp config with each init system
for init in systemd openrc s6 runit dinit; do
cat > /tmp/test_init.kap << KAPEOF
system { hostname = "test" }
packages {}
services {}
boot {
kernel = "linux"
init = "$init"
root = "/dev/sda1"
bootloader = "limine"
}
users { root { shell = "/bin/sh" } }
KAPEOF
check "recognizes init=$init" \
"$KAPPA parse-config /tmp/test_init.kap" \
"$init"
check "doctor accepts init=$init" \
"$KAPPA doctor /tmp/test_init.kap 2>&1" \
""
done
# Test unknown init
cat > /tmp/test_badinit.kap << 'KAPEOF'
system { hostname = "test" }
packages {}
services {}
boot {
kernel = "linux"
init = "fakething"
root = "/dev/sda1"
bootloader = "limine"
}
users { root { shell = "/bin/sh" } }
KAPEOF
check "warns on unknown init" \
"$KAPPA doctor /tmp/test_badinit.kap 2>&1" \
'not a recognized init system'
echo ""
echo "=== Bootloader recognition tests ==="
echo ""
for bl in grub limine; do
cat > /tmp/test_bl.kap << KAPEOF
system { hostname = "test" }
packages {}
services {}
boot {
kernel = "linux"
init = "s6"
root = "/dev/sda1"
bootloader = "$bl"
}
users { root { shell = "/bin/sh" } }
KAPEOF
check "recognizes bootloader=$bl" \
"$KAPPA parse-config /tmp/test_bl.kap" \
"$bl"
done
echo ""
echo "=== Service generation tests ==="
echo ""
# Test that format output contains service fields for each backend type hint
check "service format includes type field" \
"$KAPPA format examples/foo.kap" \
'type = "forking"'
check "service format includes ports" \
"$KAPPA format examples/foo.kap" \
'ports = \['
check "service format includes description" \
"$KAPPA format examples/foo.kap" \
'description = "Foo web server"'
echo ""
echo "=== Groups DSL tests ==="
echo ""
cat > /tmp/test_groups.kap << 'KAPEOF'
system { hostname = "test" }
packages {}
services {}
boot {
kernel = "linux"
init = "s6"
root = "/dev/sda1"
bootloader = "limine"
}
groups {
wheel { gid = 998 }
audio {}
docker { gid = 995 }
}
users { root { shell = "/bin/sh" } }
KAPEOF
check "parse groups block" \
"$KAPPA parse-config /tmp/test_groups.kap" \
'valid'
check "format groups round-trips" \
"$KAPPA format /tmp/test_groups.kap" \
'wheel {'
echo ""
echo "=== Conflicts tests ==="
echo ""
cat > /tmp/test_conflict.kap << 'KAPEOF'
package "systemd" {
version = "255"
source = "https://example.com/systemd-255.tar.gz"
provides = ["udev", "logind"]
conflicts = ["eudev", "elogind"]
build { make }
install { make install }
}
KAPEOF
check "parse conflicts in package def" \
"$KAPPA parse-package /tmp/test_conflict.kap" \
'valid'
check "format shows conflicts" \
"$KAPPA format /tmp/test_conflict.kap" \
'conflicts ='
echo ""
echo "=========================================="
echo " Results: $PASS passed, $FAIL failed"
echo "=========================================="
[ "$FAIL" -eq 0 ] || exit 1