Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Conversation

@alex-mcgovern
Copy link
Contributor

This is a supporting PR for #287 — while refactoring mocking, I noticed a few issues with our use of MSW, specifically around overly permissive wildcards, and aprtial path matches.

This PR introduces a type-safe helper, mswEndpoint() that uses the paths defined in the OpenAPI json to limit the user input.

@alex-mcgovern alex-mcgovern enabled auto-merge (squash) February 11, 2025 09:00
http.get("*/api/v1/workspaces/:name/custom-instructions", () => {
return HttpResponse.json({ prompt: "initial prompt from server" });
}),
http.get(
Copy link
Member

Choose a reason for hiding this comment

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

Not a required change for this PR, but I am kinda wondering if we could even make a single wrapper function that can be used like this:

mockEndpoint("..etc...", () => {
   return HttpResponse.json(...etc...)
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably yes, I didn't want to dive too deep in on this attempt — it's a little fussy because MSW's http has methods for each HTTP method (put,post,get) etc, and we'd have to do a little glue work to support all of them correctly, but eventually it would be possible.

@alex-mcgovern alex-mcgovern merged commit 7529f73 into main Feb 11, 2025
7 checks passed
@alex-mcgovern alex-mcgovern deleted the chore/safe-msw-endpoint-access branch February 11, 2025 09:09
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 13259167234

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 28 of 34 (82.35%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 68.676%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/mocks/msw/handlers.ts 12 18 66.67%
Totals Coverage Status
Change from base Build 13243072761: 0.3%
Covered Lines: 828
Relevant Lines: 1136

💛 - Coveralls

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants