fix: 恢复 gittool 条件逻辑,修复 has_files 检查 git status
CI / Lint, Typecheck & Test (push) Successful in 1m56s
CI / Lint, Typecheck & Test (push) Successful in 1m56s
将 gitt a/i 命令改用 fn job 包装(git_add_commit/git_init_add_commit), 内部检查 has_files() 和 not_has_git_repo() 条件,避免无更改时 git commit 报错。修正 has_files() 实现为检查 git status --porcelain 而非目录文件。
This commit is contained in:
@@ -93,10 +93,12 @@ _INIT_VERSION_PATTERN = re.compile(
|
||||
PACKAGE_DIR = "packages"
|
||||
REQUIREMENTS_FILE = "requirements.txt"
|
||||
|
||||
_PROTECTED_PACKAGES: frozenset[str] = frozenset({
|
||||
"pyflowx",
|
||||
"bitool",
|
||||
})
|
||||
_PROTECTED_PACKAGES: frozenset[str] = frozenset(
|
||||
{
|
||||
"pyflowx",
|
||||
"bitool",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
|
||||
@@ -136,13 +136,15 @@ _ENV_VAR_EQUALS_RE = re.compile(r"^env\.(\w+)\s*==\s*['\"]([^'\"]*)['\"]$")
|
||||
_ENV_VAR_NOT_EQUALS_RE = re.compile(r"^env\.(\w+)\s*!=\s*['\"]([^'\"]*)['\"]$")
|
||||
|
||||
# 支持的 job 字段名(连字符形式)
|
||||
_JOB_FIELDS_HYPHEN = frozenset({
|
||||
"continue-on-error",
|
||||
"skip-if-missing",
|
||||
"allow-upstream-skip",
|
||||
"concurrency-key",
|
||||
"runs-on",
|
||||
})
|
||||
_JOB_FIELDS_HYPHEN = frozenset(
|
||||
{
|
||||
"continue-on-error",
|
||||
"skip-if-missing",
|
||||
"allow-upstream-skip",
|
||||
"concurrency-key",
|
||||
"runs-on",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class YamlLoadError(px.PyFlowXError):
|
||||
|
||||
+17
-11
@@ -48,19 +48,25 @@ class TestNotHasGitRepo:
|
||||
class TestHasFiles:
|
||||
"""Test has_files function."""
|
||||
|
||||
def test_has_files_true(self, tmp_path: Path) -> None:
|
||||
"""Should return True when files exist."""
|
||||
(tmp_path / "test.txt").write_text("test")
|
||||
def test_has_files_true(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Should return True when there are uncommitted changes."""
|
||||
|
||||
with patch.object(Path, "cwd", return_value=tmp_path):
|
||||
result = dev.has_files()
|
||||
assert result is True
|
||||
class _FakeResult:
|
||||
stdout = " M test.txt\n"
|
||||
|
||||
def test_has_files_false(self, tmp_path: Path) -> None:
|
||||
"""Should return False when no files."""
|
||||
with patch.object(Path, "cwd", return_value=tmp_path):
|
||||
result = dev.has_files()
|
||||
assert result is False
|
||||
monkeypatch.setattr("subprocess.run", lambda *_, **__: _FakeResult())
|
||||
result = dev.has_files()
|
||||
assert result is True
|
||||
|
||||
def test_has_files_false(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Should return False when no uncommitted changes."""
|
||||
|
||||
class _FakeResult:
|
||||
stdout = ""
|
||||
|
||||
monkeypatch.setattr("subprocess.run", lambda *_, **__: _FakeResult())
|
||||
result = dev.has_files()
|
||||
assert result is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------- #
|
||||
|
||||
@@ -237,11 +237,11 @@ class TestOpsModules:
|
||||
assert px.has_fn(name), f"{module.__name__}.{name} 未注册"
|
||||
|
||||
def test_total_function_count(self) -> None:
|
||||
"""注册函数总数 = 16+15+18+11 = 60."""
|
||||
"""注册函数总数 = 18+15+18+11 = 62."""
|
||||
from pyflowx.cli._ops import dev, files, media, system # noqa: F401
|
||||
|
||||
all_names = px.FnRegistry.names()
|
||||
assert len(all_names) == 60
|
||||
assert len(all_names) == 62
|
||||
|
||||
def test_specific_functions_callable(self) -> None:
|
||||
"""关键注册函数可调用."""
|
||||
|
||||
Reference in New Issue
Block a user