From b708b2a05fb933c24a97671cdfa5a6a92d723946 Mon Sep 17 00:00:00 2001 From: Chiron Date: Wed, 15 Apr 2026 18:43:00 +0000 Subject: [PATCH] test: add basic lib function tests for agents and coding-rules --- tests/lib/agents-test.nix | 29 ++++++++++++++++++ tests/lib/coding-rules-test.nix | 53 +++++++++++++++++++++++++++++++++ tests/lib/default.nix | 4 +++ 3 files changed, 86 insertions(+) create mode 100644 tests/lib/agents-test.nix create mode 100644 tests/lib/coding-rules-test.nix create mode 100644 tests/lib/default.nix diff --git a/tests/lib/agents-test.nix b/tests/lib/agents-test.nix new file mode 100644 index 0000000..6e3b3c0 --- /dev/null +++ b/tests/lib/agents-test.nix @@ -0,0 +1,29 @@ +let + lib = import ; + 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; +} diff --git a/tests/lib/coding-rules-test.nix b/tests/lib/coding-rules-test.nix new file mode 100644 index 0000000..433b270 --- /dev/null +++ b/tests/lib/coding-rules-test.nix @@ -0,0 +1,53 @@ +let + lib = import ; + 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; +} diff --git a/tests/lib/default.nix b/tests/lib/default.nix new file mode 100644 index 0000000..dc12cad --- /dev/null +++ b/tests/lib/default.nix @@ -0,0 +1,4 @@ +{ + coding-rules = import ./coding-rules-test.nix; + agents = import ./agents-test.nix; +}