Skip to content

Commit eec1cf3

Browse files
committed
chore(templates): bind ownership to template id
1 parent c40bdee commit eec1cf3

8 files changed

Lines changed: 60 additions & 10 deletions

File tree

plugins/prompt-templates/comment-polish/index.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pluginOwnership } from '../ownership.mjs';
1+
import { commentPolishOwnership } from './ownership.mjs';
22

33
export function buildBuiltinCommentPolishTemplate(t) {
44
const tr = (key, fallback, params = null) => (typeof t === 'function' ? t(key, params) : fallback);
@@ -16,7 +16,7 @@ export function buildBuiltinCommentPolishTemplate(t) {
1616
createdAt: timestamp,
1717
updatedAt: timestamp,
1818
isBuiltin: true,
19-
createdBy: pluginOwnership.createdBy,
20-
maintainers: pluginOwnership.maintainers
19+
createdBy: commentPolishOwnership.createdBy,
20+
maintainers: commentPolishOwnership.maintainers
2121
};
2222
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const commentPolishOwnership = {
2+
templateId: 'builtin_comment_polish',
3+
createdBy: 'ymkiux',
4+
maintainers: ['ymkiux']
5+
};

plugins/prompt-templates/manifest.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pluginOwnership } from './ownership.mjs';
1+
import { pluginOwnership } from './plugin-ownership.mjs';
22

33
const baseMeta = {
44
id: 'prompt-templates',

plugins/prompt-templates/ownership.mjs renamed to plugins/prompt-templates/plugin-ownership.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export const pluginOwnership = {
33
createdBy: 'ymkiux',
44
maintainers: ['ymkiux']
55
};
6+

plugins/prompt-templates/rule-ack/index.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pluginOwnership } from '../ownership.mjs';
1+
import { ruleAckOwnership } from './ownership.mjs';
22

33
export function buildBuiltinRuleAckTemplate(t) {
44
const tr = (key, fallback, params = null) => (typeof t === 'function' ? t(key, params) : fallback);
@@ -12,7 +12,7 @@ export function buildBuiltinRuleAckTemplate(t) {
1212
createdAt: timestamp,
1313
updatedAt: timestamp,
1414
isBuiltin: true,
15-
createdBy: pluginOwnership.createdBy,
16-
maintainers: pluginOwnership.maintainers
15+
createdBy: ruleAckOwnership.createdBy,
16+
maintainers: ruleAckOwnership.maintainers
1717
};
1818
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const ruleAckOwnership = {
2+
templateId: 'builtin_rule_ack',
3+
createdBy: 'ymkiux',
4+
maintainers: ['ymkiux']
5+
};

tests/unit/plugins-ownership-contract.test.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ test('each builtin plugin has ownership file matched to plugin id', async () =>
2828
assert.ok(folders.length > 0, 'expected at least one builtin plugin folder');
2929

3030
for (const folder of folders) {
31-
const ownershipPath = path.join(pluginsDir, folder, 'ownership.mjs');
32-
assert.ok(fs.existsSync(ownershipPath), `missing ownership.mjs for plugin: ${folder}`);
31+
const ownershipPath = path.join(pluginsDir, folder, 'plugin-ownership.mjs');
32+
assert.ok(fs.existsSync(ownershipPath), `missing plugin-ownership.mjs for plugin: ${folder}`);
3333

3434
const manifestUrl = pathToFileURL(path.join(pluginsDir, folder, 'manifest.mjs')).href;
3535
const ownershipUrl = pathToFileURL(ownershipPath).href;
@@ -47,4 +47,3 @@ test('each builtin plugin has ownership file matched to plugin id', async () =>
4747
}
4848
}
4949
});
50-
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)