|
| 1 | +import assert from 'assert'; |
| 2 | +import { pathToFileURL } from 'url'; |
| 3 | +import path from 'path'; |
| 4 | +import { fileURLToPath } from 'url'; |
| 5 | + |
| 6 | +const __filename = fileURLToPath(import.meta.url); |
| 7 | +const __dirname = path.dirname(__filename); |
| 8 | +const root = path.join(__dirname, '..', '..'); |
| 9 | + |
| 10 | +const pluginRoot = path.join(root, 'plugins', 'prompt-templates'); |
| 11 | + |
| 12 | +test('prompt template ownership is bound to builtin template id', async () => { |
| 13 | + const templates = [ |
| 14 | + { |
| 15 | + folder: 'comment-polish', |
| 16 | + expectedId: 'builtin_comment_polish' |
| 17 | + }, |
| 18 | + { |
| 19 | + folder: 'rule-ack', |
| 20 | + expectedId: 'builtin_rule_ack' |
| 21 | + } |
| 22 | + ]; |
| 23 | + |
| 24 | + for (const tpl of templates) { |
| 25 | + const buildUrl = pathToFileURL(path.join(pluginRoot, tpl.folder, 'index.mjs')).href; |
| 26 | + const ownershipUrl = pathToFileURL(path.join(pluginRoot, tpl.folder, 'ownership.mjs')).href; |
| 27 | + const ownershipMod = await import(`${ownershipUrl}?t=${Date.now()}`); |
| 28 | + const ownership = tpl.folder === 'comment-polish' ? ownershipMod.commentPolishOwnership : ownershipMod.ruleAckOwnership; |
| 29 | + assert.ok(ownership && typeof ownership === 'object'); |
| 30 | + assert.strictEqual(ownership.templateId, tpl.expectedId); |
| 31 | + assert.ok(typeof ownership.createdBy === 'string' && ownership.createdBy.trim()); |
| 32 | + assert.ok(Array.isArray(ownership.maintainers) && ownership.maintainers.length > 0); |
| 33 | + |
| 34 | + const mod = await import(`${buildUrl}?t=${Date.now()}`); |
| 35 | + const buildFn = tpl.folder === 'comment-polish' ? mod.buildBuiltinCommentPolishTemplate : mod.buildBuiltinRuleAckTemplate; |
| 36 | + const built = buildFn(null); |
| 37 | + assert.strictEqual(built.id, tpl.expectedId); |
| 38 | + assert.strictEqual(built.createdBy, ownership.createdBy); |
| 39 | + } |
| 40 | +}); |
0 commit comments