Skip to content

Commit ec4a171

Browse files
committed
refactor(templates): centralize ownership map
1 parent eec1cf3 commit ec4a171

9 files changed

Lines changed: 42 additions & 29 deletions

File tree

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

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

33
export function buildBuiltinCommentPolishTemplate(t) {
44
const tr = (key, fallback, params = null) => (typeof t === 'function' ? t(key, params) : fallback);
55
const line1 = tr('plugins.builtin.commentPolish.line1', '轻微收敛以下代码注释');
66
const timestamp = new Date().toISOString();
7+
const ownership = templateOwnershipById && templateOwnershipById.builtin_comment_polish
8+
? templateOwnershipById.builtin_comment_polish
9+
: null;
710
return {
811
id: 'builtin_comment_polish',
912
name: tr('plugins.builtin.commentPolish.name', '代码注释润色'),
@@ -16,7 +19,7 @@ export function buildBuiltinCommentPolishTemplate(t) {
1619
createdAt: timestamp,
1720
updatedAt: timestamp,
1821
isBuiltin: true,
19-
createdBy: commentPolishOwnership.createdBy,
20-
maintainers: commentPolishOwnership.maintainers
22+
createdBy: ownership && typeof ownership.createdBy === 'string' ? ownership.createdBy : '',
23+
maintainers: ownership && Array.isArray(ownership.maintainers) ? ownership.maintainers : []
2124
};
2225
}

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

Lines changed: 0 additions & 5 deletions
This file was deleted.

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 './plugin-ownership.mjs';
1+
import { pluginOwnership } from './ownership.mjs';
22

33
const baseMeta = {
44
id: 'prompt-templates',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const pluginOwnership = {
2+
pluginId: 'prompt-templates',
3+
createdBy: 'ymkiux',
4+
maintainers: ['ymkiux']
5+
};
6+
7+
export const templateOwnershipById = {
8+
builtin_comment_polish: {
9+
templateId: 'builtin_comment_polish',
10+
createdBy: 'ymkiux',
11+
maintainers: ['ymkiux']
12+
},
13+
builtin_rule_ack: {
14+
templateId: 'builtin_rule_ack',
15+
createdBy: 'ymkiux',
16+
maintainers: ['ymkiux']
17+
}
18+
};
19+

plugins/prompt-templates/plugin-ownership.mjs

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { ruleAckOwnership } from './ownership.mjs';
1+
import { templateOwnershipById } from '../ownership.mjs';
22

33
export function buildBuiltinRuleAckTemplate(t) {
44
const tr = (key, fallback, params = null) => (typeof t === 'function' ? t(key, params) : fallback);
55
const line1 = tr('plugins.builtin.ruleAck.line1', '请根据【{{rule}}】,收到请回复');
66
const timestamp = new Date().toISOString();
7+
const ownership = templateOwnershipById && templateOwnershipById.builtin_rule_ack
8+
? templateOwnershipById.builtin_rule_ack
9+
: null;
710
return {
811
id: 'builtin_rule_ack',
912
name: tr('plugins.builtin.ruleAck.name', '规则确认回复'),
@@ -12,7 +15,7 @@ export function buildBuiltinRuleAckTemplate(t) {
1215
createdAt: timestamp,
1316
updatedAt: timestamp,
1417
isBuiltin: true,
15-
createdBy: ruleAckOwnership.createdBy,
16-
maintainers: ruleAckOwnership.maintainers
18+
createdBy: ownership && typeof ownership.createdBy === 'string' ? ownership.createdBy : '',
19+
maintainers: ownership && Array.isArray(ownership.maintainers) ? ownership.maintainers : []
1720
};
1821
}

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

Lines changed: 0 additions & 5 deletions
This file was deleted.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ 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, 'plugin-ownership.mjs');
32-
assert.ok(fs.existsSync(ownershipPath), `missing plugin-ownership.mjs for plugin: ${folder}`);
31+
const ownershipPath = path.join(pluginsDir, folder, 'ownership.mjs');
32+
assert.ok(fs.existsSync(ownershipPath), `missing ownership.mjs for plugin: ${folder}`);
3333

3434
const manifestUrl = pathToFileURL(path.join(pluginsDir, folder, 'manifest.mjs')).href;
3535
const ownershipUrl = pathToFileURL(ownershipPath).href;
3636
const { pluginMeta } = await import(`${manifestUrl}?t=${Date.now()}`);
37-
const { pluginOwnership } = await import(`${ownershipUrl}?t=${Date.now()}`);
37+
const mod = await import(`${ownershipUrl}?t=${Date.now()}`);
38+
const pluginOwnership = mod && mod.pluginOwnership ? mod.pluginOwnership : null;
3839

3940
assert.ok(pluginMeta && typeof pluginMeta === 'object', `invalid pluginMeta for plugin: ${folder}`);
4041
assert.strictEqual(pluginMeta.id, folder, `pluginMeta.id must match folder name: ${folder}`);

tests/unit/prompt-templates-ownership-contract.test.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ test('prompt template ownership is bound to builtin template id', async () => {
2121
}
2222
];
2323

24+
const ownershipUrl = pathToFileURL(path.join(pluginRoot, 'ownership.mjs')).href;
25+
const ownershipMod = await import(`${ownershipUrl}?t=${Date.now()}`);
26+
const templateOwnershipById = ownershipMod && ownershipMod.templateOwnershipById ? ownershipMod.templateOwnershipById : null;
27+
assert.ok(templateOwnershipById && typeof templateOwnershipById === 'object');
28+
2429
for (const tpl of templates) {
2530
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;
31+
const ownership = templateOwnershipById[tpl.expectedId] || null;
2932
assert.ok(ownership && typeof ownership === 'object');
3033
assert.strictEqual(ownership.templateId, tpl.expectedId);
3134
assert.ok(typeof ownership.createdBy === 'string' && ownership.createdBy.trim());

0 commit comments

Comments
 (0)