test(opencode): cover subagent permission translation

This commit is contained in:
Labish Bardiya committed 2026-11-19 10:48:49 +05:30
1 parent c24f285190
commit 82ac0f7ba6
3 files changed
+47 -8

No files matched your search

+15 -7
View File
@@ -26,11 +26,7 @@ const agentNames = [
'marketing-agent',
];
fs.mkdirSync(outputDir, { recursive: true });
for (const name of agentNames) {
const sourcePath = path.join(repoRoot, 'agents', `${name}.md`);
const source = fs.readFileSync(sourcePath, 'utf8');
function convertAgent(source, sourcePath) {
const match = source.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
if (!match) throw new Error(`Expected YAML frontmatter in ${sourcePath}`);
@@ -49,6 +45,18 @@ for (const name of agentNames) {
},
};
const output = `---\n${yaml.dump(definition)}---\n${prompt}`;
fs.writeFileSync(path.join(outputDir, `${name}.md`), output);
return `---\n${yaml.dump(definition)}---\n${prompt}`;
}
function buildOpencodeAgents() {
fs.mkdirSync(outputDir, { recursive: true });
for (const name of agentNames) {
const sourcePath = path.join(repoRoot, 'agents', `${name}.md`);
const source = fs.readFileSync(sourcePath, 'utf8');
const output = convertAgent(source, sourcePath);
fs.writeFileSync(path.join(outputDir, `${name}.md`), output);
}
}
module.exports = { buildOpencodeAgents, convertAgent };
+1 -1
View File
@@ -24,4 +24,4 @@ execFileSync(process.execPath, [tscEntrypoint, "-p", path.join(opencodeDir, "tsc
cwd: rootDir,
stdio: "inherit",
})
require("./build-opencode-agents")
require("./build-opencode-agents").buildOpencodeAgents()
+31
View File
@@ -0,0 +1,31 @@
const assert = require('node:assert/strict');
const test = require('node:test');
const yaml = require('js-yaml');
const { convertAgent } = require('../scripts/build-opencode-agents');
const cases = [
['comma-separated read-only tools', 'Read, Grep, Glob', 'deny', 'deny'],
['array with Edit', ['Read', 'Edit'], 'allow', 'deny'],
['comma-separated Write and Bash', 'Read, Write, Bash', 'allow', 'ask'],
['array with Bash and no edit tools', ['Read', 'Bash'], 'deny', 'ask'],
];
for (const [name, tools, edit, bash] of cases) {
test(`converts OpenCode agent permissions for ${name}`, () => {
const prompt = '## Review instructions\n\nKeep the original prompt.\n';
const frontmatter = yaml.dump({
description: 'Example reviewer',
model: 'sonnet',
tools,
});
const output = convertAgent(`---\n${frontmatter}---\n${prompt}`, 'example.md');
const [, generatedFrontmatter, generatedPrompt] = output.split('---\n');
assert.deepEqual(yaml.load(generatedFrontmatter), {
description: 'Example reviewer',
mode: 'subagent',
permission: { edit, bash },
});
assert.equal(generatedPrompt, prompt);
});
}