Skip to content

A skill to stop your coding agent from burying the answer. ADHD-friendly output.

Test OpenCode plugin always-on injection and frontmatter stripping

Rimon Hannaeb6e90c25a8e
diff --git a/tests/opencode_plugin_driver.mjs b/tests/opencode_plugin_driver.mjs
new file mode 100644
index 0000000..2f19f28
--- /dev/null
+++ b/tests/opencode_plugin_driver.mjs
@@ -0,0 +1,10 @@
+// Test driver for the OpenCode plugin. Imports the plugin at argv[2], runs its
+// `experimental.chat.system.transform` hook against an empty system prompt, and
+// prints the resulting system text so tests can assert on the injected banner.
+// Nothing is printed when the hook injects nothing (always-on flag absent).
+const pluginPath = process.argv[2];
+const { default: init } = await import(pluginPath);
+const hooks = await init();
+const output = { system: [] };
+await hooks['experimental.chat.system.transform']({}, output);
+process.stdout.write(output.system.join('\n---SEP---\n'));
diff --git a/tests/test_opencode_plugin.py b/tests/test_opencode_plugin.py
new file mode 100644
index 0000000..c1a1c58
--- /dev/null
+++ b/tests/test_opencode_plugin.py
@@ -0,0 +1,70 @@
+import os
+import shutil
+import subprocess
+import tempfile
+import unittest
+from pathlib import Path
+
+
+ROOT = Path(__file__).resolve().parents[1]
+
+
[email protected](shutil.which("node"), "node is required for the OpenCode plugin")
+class OpenCodePluginTest(unittest.TestCase):
+ """Mirror tests/test_always_on_hooks.py for the OpenCode server plugin: the
+ always-on flag gates injection, and frontmatter stripping matches the hooks."""
+
+ def setUp(self):
+ self.temp_dir = tempfile.TemporaryDirectory()
+ self.addCleanup(self.temp_dir.cleanup)
+ self.plugin_root = Path(self.temp_dir.name) / "plugin"
+ shutil.copytree(ROOT / ".opencode", self.plugin_root / ".opencode")
+ shutil.copytree(ROOT / "skills", self.plugin_root / "skills")
+ # The plugin reads its flag from $XDG_CONFIG_HOME/opencode/.i-have-adhd-always.
+ self.config_dir = Path(self.temp_dir.name) / "config"
+ (self.config_dir / "opencode").mkdir(parents=True)
+
+ def run_plugin(self):
+ env = os.environ.copy()
+ env["XDG_CONFIG_HOME"] = str(self.config_dir)
+ return subprocess.run(
+ [
+ "node",
+ str(ROOT / "tests" / "opencode_plugin_driver.mjs"),
+ str(self.plugin_root / ".opencode" / "plugins" / "i-have-adhd.mjs"),
+ ],
+ check=False,
+ capture_output=True,
+ text=True,
+ env=env,
+ )
+
+ def opt_in(self):
+ (self.config_dir / "opencode" / ".i-have-adhd-always").touch()
+
+ def write_skill(self, text):
+ (self.plugin_root / "skills" / "i-have-adhd" / "SKILL.md").write_text(text)
+
+ def test_silent_without_opt_in_flag(self):
+ result = self.run_plugin()
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertEqual("", result.stdout)
+
+ def test_strips_frontmatter_with_trailing_whitespace(self):
+ self.write_skill("--- \nname: fixture\n--- \t\nFixture body.\n")
+ self.opt_in()
+ result = self.run_plugin()
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertNotIn("name: fixture", result.stdout)
+ self.assertIn("\n\nFixture body.", result.stdout)
+
+ def test_keeps_content_when_frontmatter_is_unclosed(self):
+ self.write_skill("---\nname: fixture\nFixture body, fence never closed.\n")
+ self.opt_in()
+ result = self.run_plugin()
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertIn("Fixture body, fence never closed.", result.stdout)
+
+
+if __name__ == "__main__":
+ unittest.main()