Files
qwenpaw/tests/unit/services/test_project_directory.py
agent-radar 1a3a4ccde1
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:01:50 +08:00

83 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
"""Tests for mode-independent project directory resolution."""
from pathlib import Path
import pytest
from qwenpaw.config.config import migrate_project_directory_config
from qwenpaw.services.project_directory import (
normalize_project_dir,
resolve_effective_project_dir,
session_project_dir,
)
def test_resolver_priority(tmp_path: Path) -> None:
"""Fork, request, Session, Agent, then workspace define precedence."""
values = {
"workspace_dir": tmp_path / "workspace",
"agent_project_dir": str(tmp_path / "agent"),
"session_override": str(tmp_path / "session"),
"trusted_override": str(tmp_path / "request"),
"active_mode_override": str(tmp_path / "mode"),
"fork_project_dir": str(tmp_path / "fork"),
}
assert resolve_effective_project_dir(**values) == (
(tmp_path / "fork").resolve(),
"fork",
)
values["fork_project_dir"] = None
assert resolve_effective_project_dir(**values)[1] == "active_mode"
values["active_mode_override"] = None
assert resolve_effective_project_dir(**values)[1] == "request"
values["trusted_override"] = None
assert resolve_effective_project_dir(**values)[1] == "session"
values["session_override"] = None
assert resolve_effective_project_dir(**values)[1] == "agent"
values["agent_project_dir"] = None
assert resolve_effective_project_dir(**values)[1] == "workspace_fallback"
def test_session_project_dir_uses_controlled_namespace() -> None:
"""Unrelated Chat metadata cannot become a directory override."""
assert session_project_dir({"project_dir": "/wrong"}) is None
# The stored value comes back normalized for the running platform:
# on Windows a drive-less path picks up the current drive.
assert session_project_dir(
{"runtime_context": {"project_dir": "/project"}},
) == str(normalize_project_dir("/project"))
@pytest.mark.parametrize(
("top_level", "legacy", "expected"),
[
(None, "/legacy", "/legacy"),
("/top", "/legacy", "/top"),
(None, None, None),
(None, r"C:\Users\Alice\Project", r"C:\Users\Alice\Project"),
(None, r"\\server\share\Project", r"\\server\share\Project"),
(None, "~/Project", "~/Project"),
],
)
def test_legacy_project_directory_migration(
top_level: str | None,
legacy: str | None,
expected: str | None,
) -> None:
"""Migration preserves a top-level value and removes the old field."""
data = {
"coding_mode": {
"enabled": False,
"project_dir": legacy,
},
}
if top_level is not None:
data["project_dir"] = top_level
assert migrate_project_directory_config(data) is True
assert data["project_dir"] == expected
assert "project_dir" not in data["coding_mode"]
assert migrate_project_directory_config(data) is False