@cqsjjb/meter-sphere-mcp-server 1.0.2 → 2026.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mcp-server.mjs +79 -13
- package/package.json +1 -1
package/mcp-server.mjs
CHANGED
|
@@ -143,7 +143,29 @@ function loadProgress() {
|
|
|
143
143
|
try {
|
|
144
144
|
if (fs.existsSync(progressPath)) {
|
|
145
145
|
const content = fs.readFileSync(progressPath, 'utf8');
|
|
146
|
-
|
|
146
|
+
const progress = JSON.parse(content);
|
|
147
|
+
// 向后兼容:如果旧进度文件没有 knownTestCaseIds 字段,初始化它
|
|
148
|
+
if (!progress.knownTestCaseIds) {
|
|
149
|
+
progress.knownTestCaseIds = [];
|
|
150
|
+
// 如果已有已完成用例,将它们添加到 knownTestCaseIds 中
|
|
151
|
+
if (progress.completed && Array.isArray(progress.completed)) {
|
|
152
|
+
progress.completed.forEach(item => {
|
|
153
|
+
if (item.testCaseId && !progress.knownTestCaseIds.includes(item.testCaseId)) {
|
|
154
|
+
progress.knownTestCaseIds.push(item.testCaseId);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// 更新 total 为 knownTestCaseIds 的长度
|
|
159
|
+
progress.total = progress.knownTestCaseIds.length;
|
|
160
|
+
// 保存更新后的进度,确保向后兼容的修改被持久化
|
|
161
|
+
try {
|
|
162
|
+
saveProgress(progress);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
// 如果保存失败,不影响加载,只记录错误
|
|
165
|
+
console.error('保存向后兼容更新失败:', error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return progress;
|
|
147
169
|
}
|
|
148
170
|
} catch (error) {
|
|
149
171
|
console.error('加载进度文件失败:', error);
|
|
@@ -152,7 +174,8 @@ function loadProgress() {
|
|
|
152
174
|
lastUpdate: null,
|
|
153
175
|
completed: [],
|
|
154
176
|
total: 0,
|
|
155
|
-
completedCount: 0
|
|
177
|
+
completedCount: 0,
|
|
178
|
+
knownTestCaseIds: [] // 记录所有已知的用例ID(用于准确计算总数)
|
|
156
179
|
};
|
|
157
180
|
}
|
|
158
181
|
|
|
@@ -188,6 +211,18 @@ function markCompleted(testCaseId, priority, progress) {
|
|
|
188
211
|
completedAt: new Date().toISOString()
|
|
189
212
|
});
|
|
190
213
|
progress.completedCount = progress.completed.length;
|
|
214
|
+
|
|
215
|
+
// 确保 knownTestCaseIds 存在
|
|
216
|
+
if (!progress.knownTestCaseIds) {
|
|
217
|
+
progress.knownTestCaseIds = [];
|
|
218
|
+
}
|
|
219
|
+
// 将已完成的用例ID添加到已知集合中(如果不存在)
|
|
220
|
+
if (!progress.knownTestCaseIds.includes(testCaseId)) {
|
|
221
|
+
progress.knownTestCaseIds.push(testCaseId);
|
|
222
|
+
}
|
|
223
|
+
// 更新总数
|
|
224
|
+
progress.total = progress.knownTestCaseIds.length;
|
|
225
|
+
|
|
191
226
|
saveProgress(progress);
|
|
192
227
|
}
|
|
193
228
|
}
|
|
@@ -200,7 +235,8 @@ function resetProgress() {
|
|
|
200
235
|
lastUpdate: null,
|
|
201
236
|
completed: [],
|
|
202
237
|
total: 0,
|
|
203
|
-
completedCount: 0
|
|
238
|
+
completedCount: 0,
|
|
239
|
+
knownTestCaseIds: []
|
|
204
240
|
};
|
|
205
241
|
|
|
206
242
|
try {
|
|
@@ -510,6 +546,11 @@ class MeterSphereMCPServer {
|
|
|
510
546
|
type: 'boolean',
|
|
511
547
|
description: '是否排除已完成的测试用例。默认为false(显示所有用例)。当用户要求继续测试、跳过已完成用例时,必须设置为true。设置为true后,返回的列表将只包含未完成的测试用例,方便继续测试工作。',
|
|
512
548
|
},
|
|
549
|
+
moduleIds: {
|
|
550
|
+
type: 'array',
|
|
551
|
+
items: { type: 'string' },
|
|
552
|
+
description: '模块ID列表,用于按模块筛选测试用例。可选,未传入时使用环境变量 PLATFORM_MODULE_IDS 的配置。',
|
|
553
|
+
},
|
|
513
554
|
},
|
|
514
555
|
required: [],
|
|
515
556
|
},
|
|
@@ -605,7 +646,7 @@ class MeterSphereMCPServer {
|
|
|
605
646
|
}
|
|
606
647
|
|
|
607
648
|
async handleGetTestList(args) {
|
|
608
|
-
const { excludeCompleted = false } = args || {};
|
|
649
|
+
const { excludeCompleted = false, moduleIds } = args || {};
|
|
609
650
|
|
|
610
651
|
// 从环境变量读取配置
|
|
611
652
|
const platformConfig = getPlatformConfig();
|
|
@@ -634,10 +675,10 @@ class MeterSphereMCPServer {
|
|
|
634
675
|
projectId: platformConfig.project,
|
|
635
676
|
};
|
|
636
677
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
if (
|
|
640
|
-
requestData.moduleIds =
|
|
678
|
+
// 优先从 args 获取 moduleIds,否则从 platformConfig 获取
|
|
679
|
+
const effectiveModuleIds = moduleIds || platformConfig.moduleIds;
|
|
680
|
+
if (effectiveModuleIds && effectiveModuleIds.length > 0) {
|
|
681
|
+
requestData.moduleIds = effectiveModuleIds;
|
|
641
682
|
}
|
|
642
683
|
|
|
643
684
|
const response = await httpPost(targetUrl, headers, requestData);
|
|
@@ -667,8 +708,19 @@ class MeterSphereMCPServer {
|
|
|
667
708
|
return getPriorityLevel(a.priority) - getPriorityLevel(b.priority);
|
|
668
709
|
});
|
|
669
710
|
|
|
670
|
-
//
|
|
671
|
-
progress.
|
|
711
|
+
// 更新已知用例ID集合(合并当前查询到的用例ID)
|
|
712
|
+
if (!progress.knownTestCaseIds) {
|
|
713
|
+
progress.knownTestCaseIds = [];
|
|
714
|
+
}
|
|
715
|
+
const currentTestCaseIds = processedTestCases.map(tc => tc.id);
|
|
716
|
+
// 合并去重:将当前查询到的用例ID添加到已知集合中
|
|
717
|
+
currentTestCaseIds.forEach(id => {
|
|
718
|
+
if (!progress.knownTestCaseIds.includes(id)) {
|
|
719
|
+
progress.knownTestCaseIds.push(id);
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
// 基于已知用例ID集合计算总数
|
|
723
|
+
progress.total = progress.knownTestCaseIds.length;
|
|
672
724
|
saveProgress(progress);
|
|
673
725
|
|
|
674
726
|
// 如果excludeCompleted为true,过滤已完成的用例
|
|
@@ -828,7 +880,23 @@ class MeterSphereMCPServer {
|
|
|
828
880
|
async handleGetTestProgress(args) {
|
|
829
881
|
const progress = loadProgress();
|
|
830
882
|
|
|
831
|
-
|
|
883
|
+
// 确保 knownTestCaseIds 存在
|
|
884
|
+
if (!progress.knownTestCaseIds) {
|
|
885
|
+
progress.knownTestCaseIds = [];
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
const completedCount = progress.completedCount;
|
|
889
|
+
// 确保 total 至少等于 completedCount(避免出现负数)
|
|
890
|
+
// 如果 knownTestCaseIds 存在,使用它的长度;否则使用 completedCount
|
|
891
|
+
let total = progress.total;
|
|
892
|
+
if (progress.knownTestCaseIds && progress.knownTestCaseIds.length > 0) {
|
|
893
|
+
total = progress.knownTestCaseIds.length;
|
|
894
|
+
} else if (total < completedCount) {
|
|
895
|
+
// 如果 total 小于已完成数,说明数据不一致,使用已完成数作为总数
|
|
896
|
+
total = completedCount;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
if (total === 0 && completedCount === 0) {
|
|
832
900
|
return {
|
|
833
901
|
content: [
|
|
834
902
|
{
|
|
@@ -839,8 +907,6 @@ class MeterSphereMCPServer {
|
|
|
839
907
|
};
|
|
840
908
|
}
|
|
841
909
|
|
|
842
|
-
const completedCount = progress.completedCount;
|
|
843
|
-
const total = progress.total;
|
|
844
910
|
const remaining = total - completedCount;
|
|
845
911
|
const percentage = total > 0 ? Math.round((completedCount / total) * 100) : 0;
|
|
846
912
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cqsjjb/meter-sphere-mcp-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2026.3.17",
|
|
4
4
|
"description": "MCP server for MeterSphere test cases platform - Get test cases, generate AI test prompts, track testing progress, and execute browser automation tests",
|
|
5
5
|
"main": "mcp-server.mjs",
|
|
6
6
|
"type": "module",
|