Skip to content

PDX-510: feat(mcp): allocate testCase id from project context#217

Merged
mrdailey99 merged 1 commit into
developfrom
feature/generate-testcase-id-allocation
Jun 5, 2026
Merged

PDX-510: feat(mcp): allocate testCase id from project context#217
mrdailey99 merged 1 commit into
developfrom
feature/generate-testcase-id-allocation

Conversation

@mrdailey99
Copy link
Copy Markdown
Collaborator

Summary

provar_testcase_generate hard-coded id="1" on every generated <testCase>. This change allocates the id from the surrounding project context: highest in-use numeric id + 1 when writing into an existing Provar project, falling back to 1 when there is no project context.

Resolves PDX-510 (follow-up flagged in #213, the TC_010 corpus fix).

Why (corpus + backend research)

A read-only sweep of AllPOCProjects (651 real .testcase files) and the Quality Hub backend established:

  • id is not a uniqueness key — it duplicates freely within a single project (e.g. id="0" 9× in one project). The unique identifier is the guid, which the generator already emits.
  • No "next id" counter file exists anywhere in a project.
  • The QH backend requires only one of id/guid/registryId and never checks id uniqueness or integer-ness.

So this is convention alignment / hygiene — avoid a misleading duplicate id="1" label — not a correctness fix. No customer-facing contract breaks; id was never a guaranteed value.

Changes

  • New src/mcp/utils/testCaseId.tsallocateTestCaseId(outputPath, allowedPaths):
    Situation Result
    Overwriting a file that already has a numeric id preserve it (stable regeneration, no drift)
    Output inside a reachable .testproject (within allowed roots) highest project id + 1
    Preview/dry_run, or output outside the allowed roots default 1
  • testCaseGenerate.ts — allocate only on the write path (after the path policy passes), thread the id into the XML, return it as test_case_id, log idBasis. Misleading "always 1 / required by runtime" comment + tool description corrected.
  • Scan reads only an 8 KB prefix per file; non-numeric (UUID) ids are ignored; the walk never leaves --allowed-paths.
  • docs/mcp.md — generator section: id semantics + new test_case_id output field.

Testing

  • node_modules/.bin/nyc mocha "test/**/*.test.ts"1472 passing, 0 failing (incl. new allocateTestCaseId suite of 8 + 3 handler-level tests).
  • yarn compile clean · yarn lint clean · node scripts/mcp-smoke.cjs60/60 PASS (no new tool, TOTAL_EXPECTED unchanged).
  • Adversarial check on the root-id regex confirms it ignores guid (ends in "id"), registryId, and non-numeric ids.

Docs / rollout

  • Internal docs/mcp.md updated. No public-doc change requiredid was never a documented guaranteed value — but flagging for awareness since the generated XML's id attribute now varies.

🤖 Generated with Claude Code

Req: provar_testcase_generate hard-coded id="1" on every generated test case, but a 651-file corpus sweep proved id is a human label not a uniqueness key (guid is) and duplicate ids occur freely within a real project, so id="1" landing in an existing project is misleading hygiene.

Fix: add allocateTestCaseId(outputPath, allowedPaths) which, on the write path, finds the enclosing .testproject root (bounded by the allowed roots) and emits highest-in-use + 1, preserves an existing numeric id on overwrite, and defaults to 1 for preview/no-project; surfaced as test_case_id with docs and unit tests. Closes PDX-510.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

Quality Orchestrator

🟢 LOW · 14 / 100 · Touches: utils. All changed files have mapped tests.


🧪 Tests to Run · Running 2 of 57 tests

  • unit/mcp/testCaseGenerate.test.ts
  • unit/mcp/testCaseId.test.ts
▶ Run command
npx vitest run \
  unit/mcp/testCaseGenerate.test.ts \
  unit/mcp/testCaseId.test.ts

⚡ quality-orchestrator  ·  /qo stub <file>  ·  qo analyze-local

@mrdailey99 mrdailey99 merged commit 57ba461 into develop Jun 5, 2026
4 checks passed
@mrdailey99 mrdailey99 deleted the feature/generate-testcase-id-allocation branch June 5, 2026 13:28
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.

1 participant