Skip to content

Commit 6f3669e

Browse files
SavioBS629claude
andcommitted
feat(testmanagement): stamp "MCP generated" tag on createTestCase
Manual test cases created via the MCP server carried no origin marker, so they were missing from the Test Case Activity Report (PMAA-166). Stamp the "MCP generated" tag on the create payload, preserving and de-duping any user-supplied tags. "AI Generated" stays reserved for TCG Agent output. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent aa87b00 commit 6f3669e

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

src/tools/testmanagement-utils/create-testcase.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ export async function createTestCase(
318318
): Promise<CallToolResult> {
319319
const testCaseParams: TestCaseCreateRequest = { ...params };
320320

321+
testCaseParams.tags = Array.from(
322+
new Set([...(testCaseParams.tags ?? []), "MCP generated"]),
323+
);
324+
321325
if (testCaseParams.priority !== undefined) {
322326
testCaseParams.priority = await normalizePriority(
323327
params.project_identifier,
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { beforeEach, describe, it, expect, vi, Mock } from 'vitest';
2+
import { apiClient } from '../../src/lib/apiClient';
3+
import {
4+
createTestCase,
5+
TestCaseCreateRequest,
6+
} from '../../src/tools/testmanagement-utils/create-testcase';
7+
8+
// Reach the real createTestCase implementation; stub only its external deps so
9+
// we can assert on the payload it builds (PMAA-166: MCP-origin tag stamping).
10+
vi.mock('../../src/lib/apiClient', () => ({
11+
apiClient: { get: vi.fn(), post: vi.fn() },
12+
}));
13+
vi.mock('../../src/lib/tm-base-url', () => ({
14+
getTMBaseURL: vi.fn(async () => 'https://test-management.browserstack.com'),
15+
}));
16+
vi.mock('../../src/lib/get-auth', () => ({
17+
getBrowserStackAuth: vi.fn(() => 'fake-user:fake-key'),
18+
}));
19+
vi.mock('../../src/tools/testmanagement-utils/TCG-utils/api', () => ({
20+
projectIdentifierToId: vi.fn(async () => '999'),
21+
fetchFormFields: vi.fn(),
22+
normalizeDefaultFieldValue: vi.fn(),
23+
}));
24+
vi.mock('../../src/logger', () => ({
25+
default: { error: vi.fn(), warn: vi.fn(), info: vi.fn(), debug: vi.fn() },
26+
}));
27+
28+
const mockConfig = {
29+
'browserstack-username': 'fake-user',
30+
'browserstack-access-key': 'fake-key',
31+
} as any;
32+
33+
const baseArgs: TestCaseCreateRequest = {
34+
project_identifier: 'proj-123',
35+
folder_id: 'fold-456',
36+
name: 'Sample Test Case',
37+
test_case_steps: [{ step: 'Step 1', result: 'Result 1' }],
38+
};
39+
40+
function mockCreateSuccess() {
41+
(apiClient.post as Mock).mockResolvedValue({
42+
data: {
43+
data: {
44+
success: true,
45+
test_case: {
46+
identifier: 'TC-001',
47+
title: 'Sample Test Case',
48+
template: undefined,
49+
},
50+
},
51+
},
52+
});
53+
}
54+
55+
function sentTags(): string[] {
56+
const req = (apiClient.post as Mock).mock.calls[0][0];
57+
return req.body.test_case.tags;
58+
}
59+
60+
describe('createTestCase MCP-origin tag (PMAA-166)', () => {
61+
beforeEach(() => {
62+
vi.clearAllMocks();
63+
mockCreateSuccess();
64+
});
65+
66+
it('stamps "MCP generated" when the caller passes no tags', async () => {
67+
await createTestCase({ ...baseArgs }, mockConfig);
68+
expect(sentTags()).toEqual(['MCP generated']);
69+
});
70+
71+
it('preserves user tags and appends "MCP generated"', async () => {
72+
await createTestCase({ ...baseArgs, tags: ['smoke', 'regression'] }, mockConfig);
73+
expect(sentTags()).toEqual(['smoke', 'regression', 'MCP generated']);
74+
});
75+
76+
it('does not duplicate "MCP generated" if already present', async () => {
77+
await createTestCase({ ...baseArgs, tags: ['MCP generated'] }, mockConfig);
78+
expect(sentTags()).toEqual(['MCP generated']);
79+
});
80+
});

0 commit comments

Comments
 (0)