Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion corp_codex_pool/mcodex.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@
"MULTICA_WORKSPACE_ID",
)

VERSION_PROBE_ARGS = {"--version", "-V"}


class McodexError(RuntimeError):
pass


def is_version_probe(args: list[str]) -> bool:
"""Return true only for the side-effect-free daemon runtime probe."""
return len(args) == 1 and args[0] in VERSION_PROBE_ARGS


def mcodex_home() -> Path:
"""mcodex 自己的家目录。可用 MCODEX_HOME 覆盖。"""
override = os.environ.get("MCODEX_HOME")
Expand Down Expand Up @@ -327,8 +334,12 @@ def main(argv: list[str] | None = None) -> int:
)

try:
updates = prepare_env(spec, settings.pool_session_url)
real_codex = find_real_codex(mcodex_home())
updates = (
{}
if is_version_probe(args)
else prepare_env(spec, settings.pool_session_url)
)
except McodexError as exc:
print(f"mcodex: {exc}", file=sys.stderr)
return 1
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "corp-codex-pool"
version = "0.2.0"
version = "0.2.1"
description = "Codex 号池与 multica 运行时的集成层:provider 注入、密钥下发、用量对账"
requires-python = ">=3.11"
dependencies = [
Expand Down
10 changes: 10 additions & 0 deletions tests/test_mcodex.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
McodexError,
find_real_codex,
init_home,
is_version_probe,
mcodex_home,
prepare_env,
read_key,
Expand Down Expand Up @@ -247,6 +248,15 @@ def test_task_mode_rejects_standalone_use(self, tmp_path, monkeypatch, spec):
prepare_env(spec, "https://pool.example/session-key")


class TestVersionProbe:
def test_only_exact_version_probe_bypasses_task_context(self):
assert is_version_probe(["--version"])
assert is_version_probe(["-V"])
assert not is_version_probe([])
assert not is_version_probe(["--version", "app-server"])
assert not is_version_probe(["app-server", "--version"])


class TestRequestSessionKey:
def test_requires_complete_task_context(self):
with pytest.raises(McodexError, match="MULTICA_TOKEN"):
Expand Down
Loading