Two things fall out of one principle: a test that asserts against a hand-written file is testing an artifact a human or an agent may legitimately rewrite at any moment, so only generated output is a valid target. install.sh generated config.toml two ways -- a full heredoc for the self-host path and an awk splice of the [forge] block into config.example.toml -- with a forge_block shell helper feeding both. That is the arrangement docs/architecture/configuration.md decided against: it "must stop generating config.toml; archied setup owns it", because the installer hand-rolling TOML already drifted once (choosing Gitea produced a config naming a token the installer never wrote). Both generators and forge_block are gone; install.sh collects its answers as before and passes them to archied setup as parameters, with secrets passed as REFERENCES to the env keys it just wrote rather than as values, which would put them on a command line. The installer also now asks for a cloud model, which archied setup requires and the old path never emitted. deployment_contract_test.go tested the removed generators by parsing install.sh's shell text, reconstructing the heredoc and asserting on its content. It broke the instant install.sh stopped generating config -- "install.sh has no heredoc declaring the daemon config's [nats] table" -- which is the failure mode in miniature: the test was coupled to an artifact, not to behaviour. Deleted. What it actually protected is kept, asserted on the GENERATED config instead: TestRunSetup_GeneratedConfigSatisfiesDaemonRequirements runs archied setup and loads what it wrote, requiring services.state.target and bot_user. A test against generated output fails when generation breaks and passes when a human merely tidies the template. Found by an adversarial package sweep (temp tracker: config-1, repo-root-deployment-1, repo-root-deployment-2).
106 lines
3.3 KiB
Go
106 lines
3.3 KiB
Go
package configtemplate
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
|
)
|
|
|
|
func readDeploymentFile(t *testing.T, path string) string {
|
|
t.Helper()
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return string(data)
|
|
}
|
|
|
|
func TestExternalNATSProfileLoadsWithManagedWorkers(t *testing.T) {
|
|
doc, err := configuration.New(nil).File("deployments/docker-nats-stack.toml")
|
|
if err != nil {
|
|
t.Fatalf("load external NATS deployment: %v", err)
|
|
}
|
|
if doc.Config.NATS.Mode != config.NATSModeExternal {
|
|
t.Errorf("NATS mode = %q, want %q", doc.Config.NATS.Mode, config.NATSModeExternal)
|
|
}
|
|
if doc.Config.Containers.Image == "" {
|
|
t.Error("managed worker image is empty")
|
|
}
|
|
legacy := doc.Config.LegacyAgent
|
|
if legacy.Mode != "" || legacy.Command != "" || len(legacy.Env) != 0 {
|
|
t.Errorf("legacy agent selector decoded from supported profile: %#v", doc.Config.LegacyAgent)
|
|
}
|
|
}
|
|
|
|
func TestInstallerUsesNativeDaemonAndManagedWorkerImage(t *testing.T) {
|
|
source := readDeploymentFile(t, "install.sh")
|
|
for _, forbidden := range []string{
|
|
"[agent]",
|
|
`go build -o "${ARCHIE_BIN_DIR}/archie-agent"`,
|
|
`- archie-agent`,
|
|
"required only for NATS container mode",
|
|
} {
|
|
if strings.Contains(source, forbidden) {
|
|
t.Errorf("install.sh contains removed deployment behavior %q", forbidden)
|
|
}
|
|
}
|
|
for _, required := range []string{
|
|
`ExecStart=${ARCHIE_BIN_DIR}/archied`,
|
|
"Docker is required for autonomous workflows",
|
|
} {
|
|
if !strings.Contains(source, required) {
|
|
t.Errorf("install.sh is missing deployment contract %q", required)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestWorkerImageIsNotDocumentedAsAStandaloneExecutor(t *testing.T) {
|
|
source := readDeploymentFile(t, "Dockerfile")
|
|
if strings.Contains(source, "docker run -e NATS_URL") {
|
|
t.Error("Dockerfile documents an unsupported manually started worker")
|
|
}
|
|
if !strings.Contains(source, "launched only by archied") {
|
|
t.Error("Dockerfile does not state that archied owns worker lifecycle")
|
|
}
|
|
}
|
|
|
|
func TestSupportedProfilesUseOneExecutionTopology(t *testing.T) {
|
|
profiles := []string{
|
|
"deployments/single-forge-github.toml",
|
|
"deployments/multi-forge-github-gitea.toml",
|
|
"deployments/local-ollama-standalone.toml",
|
|
"deployments/docker-nats-stack.toml",
|
|
}
|
|
for _, path := range profiles {
|
|
source := readDeploymentFile(t, path)
|
|
if strings.Contains(source, "\n[agent]\n") {
|
|
t.Errorf("%s still selects a legacy agent executor", path)
|
|
}
|
|
}
|
|
|
|
for _, path := range profiles[:2] {
|
|
source := readDeploymentFile(t, path)
|
|
for _, required := range []string{`mode = "embedded"`, "[containers]"} {
|
|
if !strings.Contains(source, required) {
|
|
t.Errorf("%s is missing default topology marker %q", path, required)
|
|
}
|
|
}
|
|
}
|
|
|
|
external := readDeploymentFile(t, "deployments/docker-nats-stack.toml")
|
|
if !strings.Contains(external, `mode = "external"`) {
|
|
t.Error("docker-nats-stack.toml does not explicitly select external NATS")
|
|
}
|
|
|
|
systemd := readDeploymentFile(t, "deployments/systemd-user-service.md")
|
|
if !strings.Contains(systemd, "Embedded NATS is the default") {
|
|
t.Error("systemd runbook does not identify embedded NATS as the default")
|
|
}
|
|
if strings.Contains(systemd, "still needs NATS") {
|
|
t.Error("systemd runbook still requires an external Compose NATS service")
|
|
}
|
|
}
|