package companion import ( "encoding/json" "strings" "testing" ) func TestCompileAICArtifactRoundTripsAndDiffersByBehavior(t *testing.T) { assist := DefaultAIProfile(9) aggressive := assist aggressive.Behavior = "aggressive" a, err := CompileAICArtifact(assist, DefaultStrategyCapabilities()) if err != nil { t.Fatal(err) } b, err := CompileAICArtifact(aggressive, DefaultStrategyCapabilities()) if err != nil { t.Fatal(err) } if a.SHA256 == b.SHA256 || a.AICText == b.AICText { t.Fatal("assist and aggressive artifacts must differ") } values, err := ReadAICArtifact(a.AICText) if err != nil { t.Fatal(err) } if values["[warlike]"] != 0 { t.Fatalf("assist warlike=%d, want 0", values["[warlike]"]) } values, err = ReadAICArtifact(b.AICText) if err != nil { t.Fatal(err) } if values["[warlike]"] != 80 { t.Fatalf("aggressive warlike=%d, want 80", values["[warlike]"]) } } func TestCompileAICArtifactUsesTimeForDestinationRetryAndRejectsMissingPrimitives(t *testing.T) { profile := DefaultAIProfile(4) tuning := DefaultAITuning() tuning.RetryMS = 700 tuning.AssistLeashX = 240 profile.Tuning = &tuning artifact, err := CompileAICArtifact(profile, DefaultStrategyCapabilities()) if err != nil { t.Fatal(err) } values, err := ReadAICArtifact(artifact.AICText) if err != nil { t.Fatal(err) } if values["[destination change term]"] != 700 { t.Fatal("destination change term must use a time value") } if _, err := CompileAICArtifact(profile, StrategyCapabilities{}); err == nil { t.Fatal("missing static AIC primitives unexpectedly accepted") } } func TestPVFOverlayManifestIsStableAndValidatesTampering(t *testing.T) { profile := DefaultAIProfile(15) artifact, err := CompileAICArtifact(profile, DefaultStrategyCapabilities()) if err != nil { t.Fatal(err) } manifest, err := NewPVFOverlayManifest("runtime/data/dnf/Script.pvf", "base-hash", []AICArtifact{artifact}) if err != nil { t.Fatal(err) } if err := ValidatePVFOverlayManifest(manifest); err != nil { t.Fatal(err) } data, err := json.Marshal(manifest) if err != nil { t.Fatal(err) } if !strings.Contains(string(data), "dnf90-companion-pvf-overlay-v1") { t.Fatal("manifest format missing") } manifest.Artifacts[0].AICText = strings.Replace(manifest.Artifacts[0].AICText, "[warlike]\n0", "[warlike]\n80", 1) if err := ValidatePVFOverlayManifest(manifest); err == nil { t.Fatal("tampered artifact unexpectedly validated") } } func TestReadAICArtifactRejectsUnknownAndDuplicateTags(t *testing.T) { profile := DefaultAIProfile(1) artifact, err := CompileAICArtifact(profile, DefaultStrategyCapabilities()) if err != nil { t.Fatal(err) } if _, err := ReadAICArtifact(artifact.AICText + "[custom tag]\n1\n"); err == nil { t.Fatal("unknown tag unexpectedly accepted") } if _, err := ReadAICArtifact(artifact.AICText + "[vision]\n1\n"); err == nil { t.Fatal("duplicate tag unexpectedly accepted") } }