2026-04-15 18:43:00 +00:00
|
|
|
let
|
|
|
|
|
lib = import <nixpkgs/lib>;
|
|
|
|
|
agentsLib = (import ../../lib {inherit lib;}).agents;
|
|
|
|
|
|
|
|
|
|
# Test 1: renderForTool throws for unknown tools
|
|
|
|
|
testUnknownTool = let
|
|
|
|
|
result = builtins.tryEval (
|
|
|
|
|
agentsLib.renderForTool {
|
|
|
|
|
pkgs = {};
|
|
|
|
|
agentsInput = {};
|
|
|
|
|
tool = "unknown-tool";
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
in
|
2026-04-18 10:05:59 +00:00
|
|
|
assert result.success == false; {result = "pass";};
|
2026-04-15 18:43:00 +00:00
|
|
|
|
|
|
|
|
# Test 2: loadCanonical extracts loadAgents from input
|
|
|
|
|
testLoadCanonical = let
|
|
|
|
|
fakeInput = {lib.loadAgents = {test = {description = "test";};};};
|
|
|
|
|
result = agentsLib.loadCanonical {agentsInput = fakeInput;};
|
|
|
|
|
in
|
2026-04-18 10:05:59 +00:00
|
|
|
assert result == {test = {description = "test";};}; {result = "pass";};
|
2026-04-21 20:24:38 +02:00
|
|
|
|
|
|
|
|
# Test 3: renderForPi accepts codingRules parameter without error (null case)
|
|
|
|
|
# Verifies that passing codingRules = null produces the same result as omitting it.
|
|
|
|
|
# Uses a minimal fake canonical set instead of a real agents repo.
|
|
|
|
|
testPiNullCodingRules = let
|
|
|
|
|
pkgs = import <nixpkgs> {};
|
|
|
|
|
canonical = {
|
|
|
|
|
chiron = {
|
|
|
|
|
mode = "primary";
|
|
|
|
|
description = "Test primary agent";
|
|
|
|
|
display_name = "Chiron";
|
|
|
|
|
systemPrompt = "You are a test agent.";
|
|
|
|
|
permissions = {};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
result = agentsLib.renderForPi {
|
|
|
|
|
inherit pkgs canonical;
|
|
|
|
|
codingRules = null;
|
|
|
|
|
};
|
|
|
|
|
agentsMd = builtins.readFile "${result}/AGENTS.md";
|
|
|
|
|
hasMarkers = builtins.match ".*CODING-RULES:START.*" agentsMd != null;
|
|
|
|
|
in
|
|
|
|
|
assert hasMarkers == false; {result = "pass";};
|
|
|
|
|
|
|
|
|
|
# Test 4: renderForPi with codingRules includes rules in AGENTS.md
|
|
|
|
|
# Uses the real AGENTS repo to read rule files (requires --impure or local path)
|
|
|
|
|
testPiWithCodingRules = let
|
|
|
|
|
agentsPath = /home/sascha.koenig/p/AI/AGENTS;
|
|
|
|
|
pkgs = import <nixpkgs> {};
|
|
|
|
|
canonical = {
|
|
|
|
|
chiron = {
|
|
|
|
|
mode = "primary";
|
|
|
|
|
description = "Test primary agent";
|
|
|
|
|
display_name = "Chiron";
|
|
|
|
|
systemPrompt = "You are a test agent.";
|
|
|
|
|
permissions = {};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
result = agentsLib.renderForPi {
|
|
|
|
|
inherit pkgs canonical;
|
|
|
|
|
codingRules = {
|
|
|
|
|
agents = agentsPath;
|
|
|
|
|
concerns = ["coding-style"];
|
|
|
|
|
languages = [];
|
|
|
|
|
frameworks = [];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
agentsMd = builtins.readFile "${result}/AGENTS.md";
|
|
|
|
|
hasStartMarker = builtins.match ".*CODING-RULES:START.*" agentsMd != null;
|
|
|
|
|
hasEndMarker = builtins.match ".*CODING-RULES:END.*" agentsMd != null;
|
|
|
|
|
hasCodingStyle = builtins.match ".*Coding Style.*" agentsMd != null;
|
|
|
|
|
# Also verify agent descriptions are still present
|
|
|
|
|
hasAgentInstructions = builtins.match ".*Agent Instructions.*" agentsMd != null;
|
|
|
|
|
in
|
|
|
|
|
assert hasStartMarker == true;
|
|
|
|
|
assert hasEndMarker == true;
|
|
|
|
|
assert hasCodingStyle == true;
|
|
|
|
|
assert hasAgentInstructions == true; {result = "pass";};
|
2026-04-15 18:43:00 +00:00
|
|
|
in {
|
|
|
|
|
unknown-tool-throws = testUnknownTool;
|
|
|
|
|
load-canonical = testLoadCanonical;
|
2026-04-21 20:24:38 +02:00
|
|
|
pi-null-coding-rules = testPiNullCodingRules;
|
|
|
|
|
pi-with-coding-rules = testPiWithCodingRules;
|
2026-04-15 18:43:00 +00:00
|
|
|
}
|