Skip to content

Commit b7ba220

Browse files
test(set-workspace): segment-aware .. assert + reset override after API tests
Two test-hygiene follow-ups from a structured re-review of PR #22; no production code changes. 1. tests/test_workspace_path_validation.py — test_returns_canonical_path_collapsing_dotdot The canonical-path assertion was a substring check against `..` on the raw realpath string. That would spuriously fail if the OS-supplied tempdir name ever embedded `..` in a folder component — substring presence is the wrong primitive for the invariant we actually care about, which is "no `..` *segment* in the canonical path." Switched to `Path(result).parts`, which handles `\` vs `/` natively and asserts on path components. 2. tests/test_workspace_path_validation.py — TestSetWorkspaceApi.setUp The 200-path test mutates the module-global _workspace_path_override in utils/workspace_path.py via the API, and the tempdir it then points at is rmtree'd by the existing cleanup. Without an explicit reset, the global stays pinned at a now-deleted path across tests. Added addCleanup(set_workspace_path_override, None) so any future sibling test inspecting the override sees a clean None. Full suite: 152/152 OK (skipped=2 POSIX-only symlink tests on Windows). No behaviour change; ReadLints clean. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a3b89bf commit b7ba220

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

tests/test_workspace_path_validation.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import tempfile
1717
import unittest
18+
from pathlib import Path
1819

1920
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
2021
sys.path.insert(0, REPO_ROOT)
@@ -56,7 +57,10 @@ def test_returns_canonical_path_collapsing_dotdot(self):
5657
traversal_input = os.path.join(storage, "..", os.path.basename(storage))
5758
result = validate_workspace_path(traversal_input)
5859
self.assertEqual(result, os.path.realpath(storage))
59-
self.assertNotIn("..", result)
60+
# Assert no `..` *segment* in the canonical path (vs. a substring check
61+
# on the raw string, which would spuriously fail if the OS-supplied
62+
# tempdir name ever embedded `..` in a folder name).
63+
self.assertNotIn(os.pardir, Path(result).parts)
6064

6165
# ─── Hard rejects ──────────────────────────────────────────────
6266

@@ -149,9 +153,15 @@ class TestSetWorkspaceApi(unittest.TestCase):
149153
def setUp(self):
150154
from flask import Flask
151155
from api.config_api import bp as config_bp
156+
from utils.workspace_path import set_workspace_path_override
152157

153158
self.tmp = tempfile.mkdtemp(prefix="cursor-validate-api-test-")
154159
self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True)
160+
# Reset the module-global workspace override after each test. The
161+
# 200-path test below mutates it via the API and the tempdir is then
162+
# rmtree'd by the cleanup above — without this, a future sibling test
163+
# inspecting the override would see a stale, now-deleted path.
164+
self.addCleanup(set_workspace_path_override, None)
155165

156166
app = Flask(__name__)
157167
app.config["TESTING"] = True

0 commit comments

Comments
 (0)