JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
test(git): keep tracked-change branch guard
guozirui1fdcdd753f3ba
diff --git a/tests/unit_tests/server/test_project_git_safe_directory.py b/tests/unit_tests/server/test_project_git_safe_directory.pyindex 465d53a843..3dfa3708ef 100644--- a/tests/unit_tests/server/test_project_git_safe_directory.py+++ b/tests/unit_tests/server/test_project_git_safe_directory.py@@ -397,6 +397,56 @@ def test_switch_branch_allows_untracked_files_when_clean_is_required(monkeypatchassert ["checkout", "feature"] in calls[email protected]("tracked_state", ["staged", "unstaged", "conflicted"])+def test_switch_branch_still_rejects_tracked_changes_when_clean_is_required(+ monkeypatch,+ tmp_path,+ tracked_state,+):+ """放宽 untracked 后仍必须拦截已跟踪文件的未提交修改。"""+ from jiuwenswarm.server.runtime.session import project_git++ project_dir = tmp_path / "project"+ project_dir.mkdir()+ project = Project(+ project_id="proj_test",+ name="test",+ project_dir=str(project_dir),+ work_mode="code",+ )+ status_kwargs = {tracked_state: 1}+ pre_status = project_git.GitRepoStatus(+ is_git=True,+ repo_root=str(project_dir),+ branch="main",+ is_dirty=True,+ untracked=1,+ local_branches=["feature", "main"],+ **status_kwargs,+ )+ def fake_run_git(args, *, cwd, timeout=project_git.GIT_COMMAND_TIMEOUT_SEC):+ if args == ["check-ref-format", "--branch", "feature"]:+ return _cp(["git", *args], 0, stdout="feature\n")+ pytest.fail(f"unexpected git call after dirty-worktree guard: {args}")++ monkeypatch.setattr(project_git, "_run_git", fake_run_git)+ monkeypatch.setattr(+ project_git,+ "_git_to_repo_status",+ lambda project, *, persist=False: pre_status,+ )++ result = project_git.ProjectGitService.switch_branch(+ project,+ "feature",+ require_clean=True,+ )++ assert result.success is False+ assert result.error is not None+ assert result.error.code == "WORKTREE_DIRTY"++def test_create_branch_checkout_filenotfound_returns_pre_status(monkeypatch, tmp_path):"""Bug 修复:FileNotFoundError 路径不再二次探测(git 已消失,二次探测必再失败)。"""from jiuwenswarm.server.runtime.session import project_git