-
Notifications
You must be signed in to change notification settings - Fork 1
fix: return 409 from set-workspace when multiple WSGI workers are in use #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clean6378-max-it
wants to merge
3
commits into
master
Choose a base branch
from
fix/multiworker-set-workspace-honesty
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| """POST /api/set-workspace behavior under multi-worker WSGI deployments.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import shutil | ||
| import tempfile | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| from tests.test_workspace_path_validation import _make_cursor_workspace_dir | ||
|
|
||
|
|
||
| class TestSetWorkspaceMultiWorker(unittest.TestCase): | ||
| def setUp(self): | ||
| from flask import Flask | ||
|
|
||
| from api.config_api import bp as config_bp | ||
| from utils.workspace_path import set_workspace_path_override | ||
|
|
||
| self.tmp = tempfile.mkdtemp(prefix="cursor-multiworker-test-") | ||
| self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True) | ||
| self.addCleanup(set_workspace_path_override, None) | ||
|
|
||
| app = Flask(__name__) | ||
| app.config["TESTING"] = True | ||
| app.register_blueprint(config_bp) | ||
| self.client = app.test_client() | ||
| self.storage = _make_cursor_workspace_dir(self.tmp) | ||
|
|
||
| def test_multi_worker_returns_409_with_stable_code(self): | ||
| with patch( | ||
| "api.config_api.is_multi_worker_process_deployment", | ||
| return_value=True, | ||
| ): | ||
| resp = self.client.post( | ||
| "/api/set-workspace", | ||
| json={"path": self.storage}, | ||
| ) | ||
| self.assertEqual(resp.status_code, 409) | ||
| body = resp.get_json() | ||
| self.assertEqual(body["code"], "set_workspace_multi_worker_unsupported") | ||
| self.assertIn("WORKSPACE_PATH", body["error"]) | ||
|
clean6378-max-it marked this conversation as resolved.
|
||
|
|
||
| from utils.workspace_path import get_workspace_path_override | ||
|
|
||
| self.assertIsNone(get_workspace_path_override()) | ||
|
|
||
| def test_single_process_still_succeeds_when_not_multi_worker(self): | ||
| with patch( | ||
| "api.config_api.is_multi_worker_process_deployment", | ||
| return_value=False, | ||
| ): | ||
| resp = self.client.post( | ||
| "/api/set-workspace", | ||
| json={"path": self.storage}, | ||
| ) | ||
| self.assertEqual(resp.status_code, 200) | ||
| self.assertTrue(resp.get_json()["success"]) | ||
|
|
||
|
|
||
| class TestMultiWorkerDetection(unittest.TestCase): | ||
| def test_explicit_env_flag(self): | ||
| from utils.workspace_path import is_multi_worker_process_deployment | ||
|
|
||
| with patch.dict(os.environ, {"CURSOR_BROWSER_MULTI_WORKER": "1"}, clear=False): | ||
| self.assertTrue(is_multi_worker_process_deployment()) | ||
| with patch.dict(os.environ, {"CURSOR_BROWSER_MULTI_WORKER": "0"}, clear=False): | ||
| self.assertFalse(is_multi_worker_process_deployment()) | ||
|
|
||
| def test_web_concurrency_gt_one(self): | ||
| from utils.workspace_path import is_multi_worker_process_deployment | ||
|
|
||
| with patch.dict( | ||
| os.environ, | ||
| {"WEB_CONCURRENCY": "4", "CURSOR_BROWSER_MULTI_WORKER": ""}, | ||
| clear=False, | ||
| ): | ||
| self.assertTrue(is_multi_worker_process_deployment()) | ||
|
|
||
| def test_gunicorn_cmd_args_workers(self): | ||
| from utils.workspace_path import is_multi_worker_process_deployment | ||
|
|
||
| with patch.dict( | ||
| os.environ, | ||
| { | ||
| "GUNICORN_CMD_ARGS": "app:create_app --bind :5000 --workers 3", | ||
| "CURSOR_BROWSER_MULTI_WORKER": "", | ||
| }, | ||
| clear=False, | ||
| ): | ||
| self.assertTrue(is_multi_worker_process_deployment()) | ||
|
|
||
| def test_web_concurrency_one_does_not_block_later_multi_worker_signals(self): | ||
| from utils.workspace_path import is_multi_worker_process_deployment | ||
|
|
||
| with patch.dict( | ||
| os.environ, | ||
| { | ||
| "WEB_CONCURRENCY": "1", | ||
| "GUNICORN_WORKERS": "4", | ||
| "CURSOR_BROWSER_MULTI_WORKER": "", | ||
| }, | ||
| clear=False, | ||
| ): | ||
| self.assertTrue(is_multi_worker_process_deployment()) | ||
|
|
||
| with patch.dict( | ||
| os.environ, | ||
| { | ||
| "WEB_CONCURRENCY": "1", | ||
| "GUNICORN_CMD_ARGS": "app:create_app --workers 2", | ||
| "CURSOR_BROWSER_MULTI_WORKER": "", | ||
| }, | ||
| clear=False, | ||
| ): | ||
| self.assertTrue(is_multi_worker_process_deployment()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.