Skip to content

fix(testmanagement): send mimeType and mcp source for test case generation, limit file types - #569

Merged
gaurav-singh-9227 merged 4 commits into
browserstack:mainfrom
SavioBS629:fix/tcg-v1-mime-type
Nov 11, 2026
Merged

gaurav-singh-9227 merged 4 commits into
browserstack:mainfrom
SavioBS629:fix/tcg-v1-mime-type

Conversation

@SavioBS629

@SavioBS629 SavioBS629 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

createTestCasesFromFile sent the uploaded document for generation without a mimeType, so every file was treated as a PDF and anything else failed to parse, including plain .txt. uploadProductRequirementFile also accepted file types that test case generation can't read (.md, .doc, .xls, .json, .html, .gif, .zip), so those uploads only failed later, at generation. Generation requests also identified themselves as jira-on-prem; they now use source mcp.

This PR:

  • adds TEST_CASE_GENERATION_MIME_TYPES, the file types generation reads mapped to their MIME types: .pdf, .txt, .png, .jpg, .jpeg, .docx, .xlsx, .csv, .rtf
  • limits uploadProductRequirementFile to those extensions, so unsupported files are rejected at upload with the allowed list in the error
  • stores each file's mimeType with its document id and sends it as mimeType on the generation request
  • identifies these requests with the mcp request source instead of jira-on-prem, on generation, test case details and the bulk save

TEST_MANAGEMENT_ATTACHMENT_EXTENSIONS is unchanged; it still describes generic test management attachments, and the capability test asserts against it. The uploadProductRequirementFile description now lists the accepted types.

Tests

  • tests/tools/uploadFile.test.ts: unsupported types are rejected before any request; each supported type stores the right mimeType, including an upper-case extension
  • tests/tools/tcg-trigger.test.ts: the generation request carries mimeType and the mcp source; the bulk save sends the mcp request source
  • npm run build passes (Node 22)
  • End to end on this head: a .txt requirements file generates and saves test cases, with every generation, details and save request sent as source mcp; .docx, .xlsx, .csv and .rtf files also generate and save test cases; a .doc upload is rejected with the allowed list

🤖 Generated with Claude Code

… file types

createTestCasesFromFile sent documents for generation without a mimeType,
so every file was treated as a PDF and other types failed to parse.
uploadProductRequirementFile also accepted file types that test case
generation cannot read (.md, .doc/.docx, .csv, .xls/.xlsx, .json, .html,
.gif, .zip).

Limit the upload to .pdf, .txt, .png, .jpg and .jpeg, store each file's
mimeType with its document id, and send it on the generation request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited), Workspace UI (inherited); Enforced overrides: Organization
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: d4772d78-b28f-4e77-af17-8511369f78dc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sarve-shreyas sarve-shreyas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff main...2e4e3033. npm run build passes and the full vitest run passes locally (exit 0). The four touched test files pass 42/42.

The core fix is correct. I traced the request end to end: TM's tcg#suggest_test_cases (v1, build_suggest_test_cases_params) forwards the body as is. bstack_parser routes/testGeneration.js destructures mimeType = "application/pdf", and testGenerationProcessor hands it to processDocumentV2. Without mimeType every file was parsed as a PDF, so sending it fixes .txt. The fallback for older map entries with no mimeType stays safe: the key is dropped from the JSON and the backend defaults to PDF.

Main point (inline on upload-validator.ts): the allow-list is narrower than what generation actually reads. processDocumentV2 also converts DOCX/DOC, XLSX/XLS, PPTX, CSV and RTF (Document_MIME_Types in document_test_generation/constants.js, plus the documentMimeValidator). Those uploads failed before only because no mimeType was sent, which is exactly what this PR fixes. So the PR description's claim that generation can't read .doc/.docx/.csv/.xls/.xlsx doesn't match the backend. I'd map them instead of rejecting them.

Smaller items:

  • TEST_MANAGEMENT_ATTACHMENT_EXTENSIONS is now unused in src/ (only upload-validator.test.ts imports it). Either drop it or leave a comment saying who it's for.
  • The uploadProductRequirementFile tool description (testmanagement.ts, outside the diff) still says "e.g., PDRs, PDFs". It's worth listing the accepted types there too, because that's what the model reads when picking a file.

".txt": "text/plain",
".png": "image/png",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix: this list is narrower than what generation reads.

The v1 path (processDocumentV2 in bstack_parser/test_selection_workers/services/document_test_generation/index.js) handles DOCX/DOC (converted to PDF), XLSX/XLS, PPTX, CSV and RTF, not just PDF/TXT/PNG/JPEG. See Document_MIME_Types in document_test_generation/constants.js. Those types failed before only because no mimeType was sent, so everything was parsed as a PDF, and this PR fixes that.

Scenario: a user uploads requirements.docx, which is probably the most common PRD format. Before this PR the upload succeeded and generation failed. After it, the upload is rejected outright, although generation would now work if the mime type were sent.

Suggestion: add the extra mappings using the exact strings the backend compares with ===:

".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
".doc": "application/msword",
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
".xls": "application/vnd.ms-excel",
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
".csv": "text/csv",
".rtf": "application/rtf",

Then keep rejecting .md, .json, .html, .gif and .zip. If some of these were deliberately left out (for example a known conversion problem), please say so in the PR description.

.body.find((p: { type: string }) => p.type === "file");
expect(file.accept).toEqual(
expect.arrayContaining([...TEST_MANAGEMENT_ATTACHMENT_EXTENSIONS]),
expect.arrayContaining(Object.keys(TEST_CASE_GENERATION_MIME_TYPES)),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this weakens the guard. Before, the test asserted that upload_generic_attachments accepts every generic TM attachment type. Now it only checks the five generation types, so the index could drop e.g. .zip or .xlsx and nothing would catch it. If the intent is still "the capability accepts at least what uploadFile accepts", that's fine. Consider keeping a second assertion against TEST_MANAGEMENT_ATTACHMENT_EXTENSIONS, since the capability is a generic attachment upload, not a TCG-only one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sarve-shreyas sarve-shreyas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 2e4e3033..f4bc7e69 (one commit: send mcp as the request source). npm run build passes, and the four touched test files pass 43/43.

The code change itself is clean. source now reaches the trigger body, the request-source header on trigger and poll, and the new bulk-create header. The new test covers both. The bulk-create header has no side effects on TM: test_cases_helper only creates a polling key for jira-on-prem, and MCP doesn't poll after bulk create.

Still open from my last round (no code change or reply yet):

  1. The allow-list is narrower than what generation reads: DOCX/DOC/XLSX/XLS/PPTX/CSV/RTF are rejected at upload even though processDocumentV2 handles them once mimeType is sent. See the inline comment on upload-validator.ts.
  2. The capabilityRegistryFileUpload guard is weaker.
  3. TEST_MANAGEMENT_ATTACHMENT_EXTENSIONS is unused in src/, and the uploadProductRequirementFile tool description still says "e.g., PDRs, PDFs".

New: the mcp source needs the server side deployed first (inline on testcase-from-file.ts). Please also add the source change to the PR description. It currently only covers the mimeType work.

const mimeType = (documentObj as { mimeType?: string }).mimeType;

const source = "jira-on-prem";
const source = "mcp";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (release order): mcp only works once the server side is live in every prod region.

TM support is browserstack/teststack#17380 (PTMAA-1026), which merged into main today. Its own rollout order lists this change as step 3, after ai-tm#411 (the TCM_MCP product whitelist) and ai-tm-infra-ops#219 (the prod GRR bypass).

Scenario if this ships first:

  • TM without #17380: suggest_test_cases only creates the polling key for [jira-on-prem, azure]. The TCG webhook stores results only if that key exists (test_cases_helper.rb, ai_request_exists?), so results are dropped. createTestCasesFromFile then polls until TCG_POLL_MAX_WAIT_MS, 10 minutes, and returns nothing.
  • TM with #17380 but ai-tm without feat(security): require MCP_UPLOAD_BASE_DIR for the upload-PRD tool #411: TM sends x-bstack-product: TCM_MCP, and per #17380 ai-tm rejects unknown products. So generation fails at trigger.

I can't see the ai-tm repos with my access, so I couldn't check #411 or #219 myself. Can you confirm all three are deployed to prod (all regions) before this is merged or released? Also, bstack_parser on misc-services main doesn't list TCM_MCP in documentTestCaseGenerationSupportedProducts or productGRRBypass. If ai-tm forwards that header to it, that's a fourth dependency.

Suggestion: hold the merge until those are confirmed. The other option is to split this commit into its own PR, so the mimeType fix can ship now without waiting on the rollout.

…eration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SavioBS629 SavioBS629 changed the title fix(testmanagement): send mimeType for test case generation and limit file types fix(testmanagement): send mimeType and mcp source for test case generation, limit file types Nov 10, 2026

@sarve-shreyas sarve-shreyas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed f4bc7e69..53518fce. npm run build passes, and the four touched test files pass 47/47.

Resolved:

  • Allow-list: .docx, .xlsx, .csv and .rtf are added with MIME strings that match the backend's Document_MIME_Types exactly. They're also all in TM's VALID_AI_CONTENT_TYPE, so the AI upload accepts them. Leaving out .doc (prod returns 400 Invalid file type for AI uploads) and the untested .xls/.pptx is a sensible, conservative choice. One side note: application/msword is in TM's VALID_AI_CONTENT_TYPE, so the .doc 400 is probably content-type sniffing (legacy OLE files are often detected as something else). That's not an issue for this PR.
  • Capability test: it asserts the full TEST_MANAGEMENT_ATTACHMENT_EXTENSIONS again, which also gives that constant a clear owner.
  • Tool description: it lists the accepted types, and the PR description now covers the mcp source change.
  • mcp source rollout: verified on prod US by the author. It was a .txt run of 145 test cases, with every suggest, details and bulk call sent as request-source: mcp.

Remaining caveat (question, not a code change): the prod check was US only. If any other TM region (EU/APS/USW) isn't yet on teststack#17380 and ai-tm#411, MCP users there would hit the 10-minute empty poll. It's worth a quick confirmation that those deploys are global before the next mcp-server release.

Nit: the file_path schema description became "Full path to the file". The types are in the tool description now, so that's fine.

No further code findings from me.

@gaurav-singh-9227
gaurav-singh-9227 merged commit 366d974 into browserstack:main Nov 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants