Skip to content

Conversation

danhellem
Copy link
Contributor

@danhellem danhellem commented Jul 22, 2025

This pull request refactors the handling of work item update operations in src/tools/workitems.ts and enhances the corresponding test coverage in test/src/tools/workitems.test.ts. Key changes include simplifying the transformation of operation strings, removing redundant code, and adding tests for edge cases like API failures, operation transformations, and Markdown formatting.

Refactoring and simplification:

  • Removed the operationToApiString utility function and replaced it with an inline transformation using zod schemas to convert operation strings to lowercase and validate them against allowed values (add, replace, remove) (src/tools/workitems.ts, [1] [2].
  • Simplified the mapping of update operations by directly using the transformed op values instead of calling the removed utility function (src/tools/workitems.ts, src/tools/workitems.tsL480-R475).

Enhanced test coverage:

  • Added a test case to ensure proper error handling when the API fetch call fails, verifying that an appropriate error message is thrown (test/src/tools/workitems.test.ts, test/src/tools/workitems.test.tsR430-R456).
  • Extended tests to validate the transformation of uppercase operation strings (e.g., Add, Replace) to lowercase and their correct usage in API calls (test/src/tools/workitems.test.ts, test/src/tools/workitems.test.tsL608-R653).
  • Introduced a test to verify that updates are grouped by work item ID when batching API requests (test/src/tools/workitems.test.ts, test/src/tools/workitems.test.tsR975-R1060).
  • Added a test to ensure that long text fields are correctly formatted as Markdown when specified, including verifying the addition of a multilineFieldsFormat entry in the API request body (test/src/tools/workitems.test.ts, test/src/tools/workitems.test.tsR975-R1060).

Fixes #323

GitHub issue number #323

Associated Risks

No risks

PR Checklist

  • I have read the contribution guidelines
  • I have read the code of conduct guidelines
  • Title of the pull request is clear and informative.
  • 👌 Code hygiene
  • 🔭 Telemetry added, updated, or N/A
  • 📄 Documentation added, updated, or N/A
  • 🛡️ Automated tests added, or N/A

🧪 How did you test it?

Updated auto tests. Verified the tools works manually and updated cases on operations to account for uppper, lower, and combo

… lowercase operation values ("add", "replace", "remove"): returns error `invalid_enum_value`

Fixes #323
@danhellem danhellem requested a review from a team as a code owner July 22, 2025 15:25
@danhellem danhellem added the Waiting for Merge 🚘 waiting for pull request to merge label Jul 22, 2025
Copy link

github-actions bot commented Jul 22, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Contributor

@polatengin polatengin left a comment

Choose a reason for hiding this comment

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

👍

@danhellem danhellem merged commit d02900b into main Jul 23, 2025
7 checks passed

const result = await handler(params);

// This verifies that the updates are grouped by work item ID as implemented in line 643
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: i think we should remove line references from all comments

@danhellem danhellem deleted the users/danhellem/fix-issue-323 branch August 13, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Waiting for Merge 🚘 waiting for pull request to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wit_update_work_item rejects lowercase operation values ("add", "replace", "remove"): returns error invalid_enum_value

4 participants