qase-mcp-server
Version:
Model Context Protocol server for Qase TMS - Enables AI assistants to manage test cases, runs, and defects in Qase
93 lines (92 loc) • 3.42 kB
JavaScript
import { z } from 'zod';
import { toResult } from '../utils.js';
import { apply, pipe } from 'ramda';
import { client } from '../utils.js';
// Schema for getting failed results from a specific project
export const GetFailedResultsSchema = z.object({
code: z.string().describe('Project code'),
runId: z
.string()
.or(z.number())
.optional()
.describe('Specific run ID to filter by'),
limit: z
.string()
.or(z.number())
.optional()
.describe('Number of results to return (1-100)'),
offset: z
.string()
.or(z.number())
.optional()
.describe('Number of results to skip'),
fromEndTime: z
.string()
.optional()
.describe('From end time in format Y-m-d H:i:s'),
toEndTime: z
.string()
.optional()
.describe('To end time in format Y-m-d H:i:s'),
});
/**
* Debug version of getResults that uses the same pattern as existing operations
*/
const getResultsWithFilters = pipe(apply(client.results.getResults.bind(client.results)), (promise) => toResult(promise));
/**
* Simple debug function to test the API call
*/
export const getFailedResults = (args) => {
const { code, runId, limit, offset, fromEndTime, toEndTime } = args;
// Get all results by setting a high limit (default is probably 10-20)
return getResultsWithFilters([
code,
limit ? String(limit) : '100', // Increase limit to ensure we get all results
offset ? String(offset) : undefined,
runId ? `run=${runId}` : undefined, // Add run filter if specified
]).map((response) => {
// Process the response
const entities = response.data.result?.entities || [];
// First, let's see what status values we actually have in the data
const statusCounts = {};
entities.forEach((entity) => {
const status = entity.status;
statusCounts[status] = (statusCounts[status] || 0) + 1;
});
// Filter for failed results - try multiple possible values
const failedResults = entities
.filter((entity) => entity.status === 'failed' ||
entity.status === 'FAILED' ||
entity.status === 2 || // Sometimes status is numeric
entity.status === 'fail')
.map((entity) => ({
hash: entity.hash,
runId: entity.run_id,
caseId: entity.case_id,
status: entity.status,
comment: entity.comment,
stacktrace: entity.stacktrace,
timeSpentMs: entity.time_spent_ms,
endTime: entity.end_time,
}));
return {
...response,
data: {
...response.data,
result: {
total: response.data.result?.total || 0,
filtered: response.data.result?.filtered || 0,
count: failedResults.length,
failedResults,
// Add debug info to see what status values exist
statusBreakdown: statusCounts,
sampleEntities: entities.slice(0, 3).map((e) => ({
status: e.status,
hash: e.hash,
statusType: typeof e.status
}))
},
},
};
});
};