Files
ayghri__i-have-adhd/tests/opencode_plugin_driver.mjs
ayghri d1634a63cb fix(opencode): share JSON command metadata with the native loader
Replace partial YAML parsing with JSON frontmatter accepted by both loading paths. Read asynchronously, preserve metadata types and existing commands, and document the bundled format.

Merge current main, preserving Rule 9 and contributor history. Validation: 50 tests pass; OpenCode 1.18.27 live native/global parity, metadata, and override checks pass. No model calls.

Owner-directed amendment prepared with Codex (GPT-6).
2026-09-10 07:19:14 -06:00

28 lines
1.2 KiB
JavaScript

// Test driver for the OpenCode plugin. Imports the plugin at argv[2] and runs
// one of its hooks depending on argv[3]:
//
// (default) runs `experimental.chat.system.transform` 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).
// config runs the `config` hook twice, seeded by optional JSON at argv[4],
// and prints the resulting config to check registration, overrides,
// and idempotency without a running OpenCode server.
import { pathToFileURL } from 'node:url';
const pluginPath = process.argv[2];
const mode = process.argv[3];
const { default: init } = await import(pathToFileURL(pluginPath).href);
const hooks = await init();
if (mode === 'config') {
const config = JSON.parse(process.argv[4] || "{}");
await hooks.config(config);
await hooks.config(config);
process.stdout.write(JSON.stringify(config));
} else {
const output = { system: [] };
await hooks['experimental.chat.system.transform']({}, output);
process.stdout.write(output.system.join('\n---SEP---\n'));
}