test: add basic lib function tests for agents and coding-rules
This commit is contained in:
29
tests/lib/agents-test.nix
Normal file
29
tests/lib/agents-test.nix
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
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
|
||||||
|
assert result.success == false;
|
||||||
|
{result = "pass";};
|
||||||
|
|
||||||
|
# Test 2: loadCanonical extracts loadAgents from input
|
||||||
|
testLoadCanonical = let
|
||||||
|
fakeInput = {lib.loadAgents = {test = {description = "test";};};};
|
||||||
|
result = agentsLib.loadCanonical {agentsInput = fakeInput;};
|
||||||
|
in
|
||||||
|
assert result == {test = {description = "test";};};
|
||||||
|
{result = "pass";};
|
||||||
|
|
||||||
|
in {
|
||||||
|
unknown-tool-throws = testUnknownTool;
|
||||||
|
load-canonical = testLoadCanonical;
|
||||||
|
}
|
||||||
53
tests/lib/coding-rules-test.nix
Normal file
53
tests/lib/coding-rules-test.nix
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
let
|
||||||
|
lib = import <nixpkgs/lib>;
|
||||||
|
codingRulesLib = (import ../../lib {inherit lib;}).coding-rules;
|
||||||
|
|
||||||
|
# Test 1: instructions are generated correctly with custom rulesDir
|
||||||
|
testInstructions = let
|
||||||
|
rules = codingRulesLib.mkCodingRules {
|
||||||
|
agents = "/tmp/fake-agents";
|
||||||
|
languages = ["python"];
|
||||||
|
concerns = ["naming"];
|
||||||
|
rulesDir = ".coding-rules";
|
||||||
|
};
|
||||||
|
in
|
||||||
|
assert rules.instructions == [
|
||||||
|
".coding-rules/concerns/naming.md"
|
||||||
|
".coding-rules/languages/python.md"
|
||||||
|
];
|
||||||
|
{result = "pass";};
|
||||||
|
|
||||||
|
# Test 2: default rulesDir is .opencode-rules
|
||||||
|
testDefaultRulesDir = let
|
||||||
|
rules = codingRulesLib.mkCodingRules {
|
||||||
|
agents = "/tmp/fake-agents";
|
||||||
|
};
|
||||||
|
hasCorrectPrefix = builtins.all (s: builtins.substring 0 15 s == ".opencode-rules") rules.instructions;
|
||||||
|
in
|
||||||
|
assert hasCorrectPrefix == true;
|
||||||
|
{result = "pass";};
|
||||||
|
|
||||||
|
# Test 3: backward-compat alias exists
|
||||||
|
testBackwardCompat =
|
||||||
|
assert codingRulesLib.mkOpencodeRules == codingRulesLib.mkCodingRules;
|
||||||
|
{result = "pass";};
|
||||||
|
|
||||||
|
# Test 4: shellHook contains both the symlink command and the config generation
|
||||||
|
testShellHook = let
|
||||||
|
rules = codingRulesLib.mkCodingRules {
|
||||||
|
agents = "/tmp/fake-agents";
|
||||||
|
};
|
||||||
|
hook = rules.shellHook;
|
||||||
|
hasSymlink = builtins.match ".*ln -sfn.*" hook != null;
|
||||||
|
hasConfigGen = builtins.match ".*coding-rules.json.*" hook != null;
|
||||||
|
in
|
||||||
|
assert hasSymlink;
|
||||||
|
assert hasConfigGen;
|
||||||
|
{result = "pass";};
|
||||||
|
|
||||||
|
in {
|
||||||
|
instructions-correct = testInstructions;
|
||||||
|
default-rules-dir = testDefaultRulesDir;
|
||||||
|
backward-compat = testBackwardCompat;
|
||||||
|
shell-hook = testShellHook;
|
||||||
|
}
|
||||||
4
tests/lib/default.nix
Normal file
4
tests/lib/default.nix
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
coding-rules = import ./coding-rules-test.nix;
|
||||||
|
agents = import ./agents-test.nix;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user