fix env variables exposure

This commit is contained in:
Michael Ingvarsson
2026-07-16 11:54:22 +02:00
parent cf1e33474e
commit 64db2efa38
3 changed files with 18 additions and 7 deletions
-6
View File
@@ -35,11 +35,5 @@ SEARXNG_URL: str = _agent_settings.searxng_url
SEARXNG_USERNAME: str = _agent_settings.searxng_username
SEARXNG_PASSWORD: str = _agent_settings.searxng_password
import os
os.environ["GITEA_SERVER_URL"] = GITEA_URL
os.environ["GITEA_SERVER_TOKEN"] = GITEA_TOKEN
os.environ["SEARXNG_URL"] = SEARXNG_URL
os.environ["SEARXNG_USERNAME"] = SEARXNG_USERNAME
os.environ["SEARXNG_PASSWORD"] = SEARXNG_PASSWORD
+12 -1
View File
@@ -132,6 +132,15 @@ class CodingTools:
return commands
def _get_subprocess_env(self) -> dict[str, str]:
from gitea.config import GITEA_URL, GITEA_TOKEN
env = os.environ.copy()
if GITEA_URL:
env["GITEA_SERVER_URL"] = GITEA_URL
if GITEA_TOKEN:
env["GITEA_SERVER_TOKEN"] = GITEA_TOKEN
return env
def run_verification(self) -> tuple[bool, str]:
commands = self._parse_verification_commands()
if not commands:
@@ -143,7 +152,8 @@ class CodingTools:
try:
res = subprocess.run(
cmd, shell=True, cwd=self.repo_path,
capture_output=True, text=True, timeout=120
capture_output=True, text=True, timeout=120,
env=self._get_subprocess_env()
)
if res.returncode != 0:
log_output.append(
@@ -213,6 +223,7 @@ class CodingTools:
stderr=subprocess.PIPE,
text=True,
cwd=self.repo_path,
env=self._get_subprocess_env(),
)
stdout: str
stderr: str
+6
View File
@@ -140,6 +140,12 @@ class TestFormatResults:
class TestSearchSearxng:
@pytest.fixture(autouse=True)
def mock_searxng_url(self) -> "Generator[None, None, None]":
from typing import Generator
with patch("gitea.tools.research_tools._SEARXNG_URL", "http://localhost"):
yield
def _make_searxng_response(self, results: list[dict]) -> MagicMock:
mock_resp = MagicMock()
mock_resp.json.return_value = {"results": results}