@cqsjjb/meter-sphere-mcp-server 1.0.2 → 1.0.3
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 +69 -8
- 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 {
|
|
@@ -667,8 +703,19 @@ class MeterSphereMCPServer {
|
|
|
667
703
|
return getPriorityLevel(a.priority) - getPriorityLevel(b.priority);
|
|
668
704
|
});
|
|
669
705
|
|
|
670
|
-
//
|
|
671
|
-
progress.
|
|
706
|
+
// 更新已知用例ID集合(合并当前查询到的用例ID)
|
|
707
|
+
if (!progress.knownTestCaseIds) {
|
|
708
|
+
progress.knownTestCaseIds = [];
|
|
709
|
+
}
|
|
710
|
+
const currentTestCaseIds = processedTestCases.map(tc => tc.id);
|
|
711
|
+
// 合并去重:将当前查询到的用例ID添加到已知集合中
|
|
712
|
+
currentTestCaseIds.forEach(id => {
|
|
713
|
+
if (!progress.knownTestCaseIds.includes(id)) {
|
|
714
|
+
progress.knownTestCaseIds.push(id);
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
// 基于已知用例ID集合计算总数
|
|
718
|
+
progress.total = progress.knownTestCaseIds.length;
|
|
672
719
|
saveProgress(progress);
|
|
673
720
|
|
|
674
721
|
// 如果excludeCompleted为true,过滤已完成的用例
|
|
@@ -828,7 +875,23 @@ class MeterSphereMCPServer {
|
|
|
828
875
|
async handleGetTestProgress(args) {
|
|
829
876
|
const progress = loadProgress();
|
|
830
877
|
|
|
831
|
-
|
|
878
|
+
// 确保 knownTestCaseIds 存在
|
|
879
|
+
if (!progress.knownTestCaseIds) {
|
|
880
|
+
progress.knownTestCaseIds = [];
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
const completedCount = progress.completedCount;
|
|
884
|
+
// 确保 total 至少等于 completedCount(避免出现负数)
|
|
885
|
+
// 如果 knownTestCaseIds 存在,使用它的长度;否则使用 completedCount
|
|
886
|
+
let total = progress.total;
|
|
887
|
+
if (progress.knownTestCaseIds && progress.knownTestCaseIds.length > 0) {
|
|
888
|
+
total = progress.knownTestCaseIds.length;
|
|
889
|
+
} else if (total < completedCount) {
|
|
890
|
+
// 如果 total 小于已完成数,说明数据不一致,使用已完成数作为总数
|
|
891
|
+
total = completedCount;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
if (total === 0 && completedCount === 0) {
|
|
832
895
|
return {
|
|
833
896
|
content: [
|
|
834
897
|
{
|
|
@@ -839,8 +902,6 @@ class MeterSphereMCPServer {
|
|
|
839
902
|
};
|
|
840
903
|
}
|
|
841
904
|
|
|
842
|
-
const completedCount = progress.completedCount;
|
|
843
|
-
const total = progress.total;
|
|
844
905
|
const remaining = total - completedCount;
|
|
845
906
|
const percentage = total > 0 ? Math.round((completedCount / total) * 100) : 0;
|
|
846
907
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cqsjjb/meter-sphere-mcp-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|