Files
aios/tests/task_plane/test_env_profile.py
T
AIOS Governed Continuation 66adfa9ec9 feat(task_plane): P1 light governors - caller_scan (WP0e), env_profile (WP1), toil_governor (WP2)
- caller_scan.py: read-only AST-based caller/live/orphan/UNKNOWN evidence (V1 spec); PROVEN_ORPHAN only on full coverage + zero live caller; UNKNOWN never downgraded.
- env_profile.py: read-only EnvironmentCapabilityReport (schema aios.environment-profile.v1); no privilege escalation, no secret collection.
- toil_governor.py: Retry/Toil Governor - suppress no-op retry on same blocker, exponential backoff, UNKNOWN -> reconcile not direct retry.
- Tests: test_caller_scan (7), test_env_profile (6), test_toil_governor (8) all green.

Base: agent/annex-2.3-platform-r2-20260914.
2026-09-14 18:07:26 +08:00

73 lines
1.9 KiB
Python

"""env_profile 只读环境画像的测试。"""
from __future__ import annotations
import json
import os
import sys
ROOT = os.getcwd()
for _p in ("active-runtime", "active-runtime/app"):
_q = os.path.join(ROOT, _p)
if _q not in sys.path:
sys.path.append(_q)
from app.task_plane.env_profile import ( # noqa: E402
SCHEMA_VERSION,
build_report,
check_requirements,
)
def test_build_report_returns_complete_structure_never_raises():
rep = build_report()
for field in (
"schema_version",
"host_id",
"os",
"shell",
"posix",
"tools",
"capabilities",
"credential_mechanisms",
"filesystem",
"missing_requirements",
):
assert hasattr(rep, field), f"missing field {field}"
def test_posix_consistent_with_os_name():
rep = build_report()
if os.name == "posix":
assert rep.posix is True
else:
assert rep.posix is False
def test_no_secret_collection_fields():
# 只读:报告里不应出现任何 secret 的明文值字段
rep = build_report()
blob = json.dumps(rep.to_dict())
for secret_marker in ("GIT_SSH_COMMAND=", "AGENT_SSH_KEY_FILE="):
assert secret_marker not in blob
# 凭证机制只记录机制名,不记录值
assert all(isinstance(m, str) for m in rep.credential_mechanisms)
def test_tools_schema_present():
rep = build_report()
for tool in ("git", "python", "python3", "node", "ssh", "docker"):
assert tool in rep.tools
def test_to_dict_json_serializable():
rep = build_report()
json.dumps(rep.to_dict())
def test_check_requirements_never_raises_and_lists_missing():
rep = check_requirements(["git", "python", "python3", "some_unknown_tool"])
assert isinstance(rep.missing_requirements, list)
# 本机大概率有 git;校验结构完整即可
assert "schema_version" in rep.to_dict()