Fix Prometheus metric f-string and add YAML helper
This commit is contained in:
@@ -56,7 +56,7 @@ class MetricsRegistry:
|
|||||||
lines.append("# TYPE aegis_tool_calls_total counter")
|
lines.append("# TYPE aegis_tool_calls_total counter")
|
||||||
for (tool_name, status), count in sorted(self._tool_calls_total.items()):
|
for (tool_name, status), count in sorted(self._tool_calls_total.items()):
|
||||||
lines.append(
|
lines.append(
|
||||||
"aegis_tool_calls_total" f'{{tool="{tool_name}",status="{status}"}} {count}'
|
f'aegis_tool_calls_total{{tool="{tool_name}",status="{status}"}} {count}'
|
||||||
)
|
)
|
||||||
|
|
||||||
lines.append(
|
lines.append(
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ def _set_base_env(
|
|||||||
monkeypatch.setenv("POLICY_FILE_PATH", str(policy_path))
|
monkeypatch.setenv("POLICY_FILE_PATH", str(policy_path))
|
||||||
|
|
||||||
|
|
||||||
|
def _yaml_with_trailing_newline(content: str) -> str:
|
||||||
|
return content.strip() + "\n"
|
||||||
|
|
||||||
|
|
||||||
def test_automation_job_denied_when_disabled(
|
def test_automation_job_denied_when_disabled(
|
||||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path, allow_oauth: None
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path, allow_oauth: None
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -61,7 +65,7 @@ def test_automation_job_executes_when_enabled(
|
|||||||
"""Dependency scan job should execute when automation is enabled and policy allows it."""
|
"""Dependency scan job should execute when automation is enabled and policy allows it."""
|
||||||
policy_path = tmp_path / "policy.yaml"
|
policy_path = tmp_path / "policy.yaml"
|
||||||
policy_path.write_text(
|
policy_path.write_text(
|
||||||
"""
|
_yaml_with_trailing_newline("""
|
||||||
defaults:
|
defaults:
|
||||||
read: allow
|
read: allow
|
||||||
write: deny
|
write: deny
|
||||||
@@ -69,7 +73,7 @@ tools:
|
|||||||
allow:
|
allow:
|
||||||
- automation_dependency_hygiene_scan
|
- automation_dependency_hygiene_scan
|
||||||
- automation_webhook_ingest
|
- automation_webhook_ingest
|
||||||
""".strip() + "\n",
|
"""),
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
_set_base_env(monkeypatch, automation_enabled=True, policy_path=policy_path)
|
_set_base_env(monkeypatch, automation_enabled=True, policy_path=policy_path)
|
||||||
@@ -95,14 +99,14 @@ def test_automation_webhook_policy_denied(
|
|||||||
"""Webhook ingestion must respect policy deny rules."""
|
"""Webhook ingestion must respect policy deny rules."""
|
||||||
policy_path = tmp_path / "policy.yaml"
|
policy_path = tmp_path / "policy.yaml"
|
||||||
policy_path.write_text(
|
policy_path.write_text(
|
||||||
"""
|
_yaml_with_trailing_newline("""
|
||||||
defaults:
|
defaults:
|
||||||
read: allow
|
read: allow
|
||||||
write: deny
|
write: deny
|
||||||
tools:
|
tools:
|
||||||
deny:
|
deny:
|
||||||
- automation_webhook_ingest
|
- automation_webhook_ingest
|
||||||
""".strip() + "\n",
|
"""),
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
_set_base_env(monkeypatch, automation_enabled=True, policy_path=policy_path)
|
_set_base_env(monkeypatch, automation_enabled=True, policy_path=policy_path)
|
||||||
@@ -126,14 +130,14 @@ def test_auto_issue_creation_denied_without_write_mode(
|
|||||||
"""Auto issue creation job should be denied unless write mode is enabled."""
|
"""Auto issue creation job should be denied unless write mode is enabled."""
|
||||||
policy_path = tmp_path / "policy.yaml"
|
policy_path = tmp_path / "policy.yaml"
|
||||||
policy_path.write_text(
|
policy_path.write_text(
|
||||||
"""
|
_yaml_with_trailing_newline("""
|
||||||
defaults:
|
defaults:
|
||||||
read: allow
|
read: allow
|
||||||
write: allow
|
write: allow
|
||||||
tools:
|
tools:
|
||||||
allow:
|
allow:
|
||||||
- automation_auto_issue_creation
|
- automation_auto_issue_creation
|
||||||
""".strip() + "\n",
|
"""),
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
_set_base_env(monkeypatch, automation_enabled=True, policy_path=policy_path)
|
_set_base_env(monkeypatch, automation_enabled=True, policy_path=policy_path)
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ def _set_base_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
monkeypatch.setenv("MCP_API_KEYS", "a" * 64)
|
monkeypatch.setenv("MCP_API_KEYS", "a" * 64)
|
||||||
|
|
||||||
|
|
||||||
|
def _yaml_with_trailing_newline(content: str) -> str:
|
||||||
|
return content.strip() + "\n"
|
||||||
|
|
||||||
|
|
||||||
def test_default_policy_allows_read_and_denies_write(
|
def test_default_policy_allows_read_and_denies_write(
|
||||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -35,14 +39,14 @@ def test_policy_global_deny(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) ->
|
|||||||
_set_base_env(monkeypatch)
|
_set_base_env(monkeypatch)
|
||||||
policy_path = tmp_path / "policy.yaml"
|
policy_path = tmp_path / "policy.yaml"
|
||||||
policy_path.write_text(
|
policy_path.write_text(
|
||||||
"""
|
_yaml_with_trailing_newline("""
|
||||||
defaults:
|
defaults:
|
||||||
read: allow
|
read: allow
|
||||||
write: deny
|
write: deny
|
||||||
tools:
|
tools:
|
||||||
deny:
|
deny:
|
||||||
- list_repositories
|
- list_repositories
|
||||||
""".strip() + "\n",
|
"""),
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,7 +64,7 @@ def test_repository_path_restriction(monkeypatch: pytest.MonkeyPatch, tmp_path:
|
|||||||
_set_base_env(monkeypatch)
|
_set_base_env(monkeypatch)
|
||||||
policy_path = tmp_path / "policy.yaml"
|
policy_path = tmp_path / "policy.yaml"
|
||||||
policy_path.write_text(
|
policy_path.write_text(
|
||||||
"""
|
_yaml_with_trailing_newline("""
|
||||||
repositories:
|
repositories:
|
||||||
acme/app:
|
acme/app:
|
||||||
tools:
|
tools:
|
||||||
@@ -69,7 +73,7 @@ repositories:
|
|||||||
paths:
|
paths:
|
||||||
allow:
|
allow:
|
||||||
- src/*
|
- src/*
|
||||||
""".strip() + "\n",
|
"""),
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user