Python
fix(setup): ship referenced environment example (#7)
Rudy Mizrahi Celeklif193229ec6fe
diff --git a/.env.example b/.env.examplenew file mode 100644index 0000000..1d61adb--- /dev/null+++ b/.env.example@@ -0,0 +1,30 @@+# SPDX-License-Identifier: Apache-2.0+#+# Copy this file to .env, then configure the models available to your account.+# See docs/SETUP.md for authentication and benchmark-specific requirements.+# Values already set in the shell take precedence over this file.++# Vertex AI project and region. The region defaults to global.+GOOGLE_CLOUD_PROJECT=+GOOGLE_CLOUD_LOCATION=global++# Executor: OpenCode provider/model syntax. Judge: bare model ID.+HARNESS2_SOLVER_MODEL=+HARNESS2_JUDGE_MODEL=++# Optional; an empty improver setting uses the executor model.+HARNESS2_IMPROVER_MODEL=++# Optional output root; an empty value keeps the default runs/ location.+HARNESS2_RUNS_DIR=++# Optional Codex Responses API settings. harness2-bridge prints these values;+# see docs/SETUP.md#codex-executor for that workflow or another endpoint.+HARNESS2_CODEX_BASE_URL=+HARNESS2_CODEX_CONTAINER_URL=+HARNESS2_CODEX_API_KEY=+HARNESS2_CODEX_MODEL=++# Optional JobBench judge endpoint override and its access key.+HARNESS2_JUDGE_BASE_URL=+HARNESS2_JUDGE_API_KEY=diff --git a/tests/test_env_example.py b/tests/test_env_example.pynew file mode 100644index 0000000..c3aabe7--- /dev/null+++ b/tests/test_env_example.py@@ -0,0 +1,93 @@+# Copyright 2026 Google LLC+# SPDX-License-Identifier: Apache-2.0+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# https://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Replay the documented .env setup without accounts or model calls."""++import json+import os+import shlex+import shutil+import subprocess+import sys+import tempfile+import unittest+from pathlib import Path++ROOT = Path(__file__).resolve().parents[1]+++class EnvExampleTests(unittest.TestCase):+ def setUp(self):+ temporary = tempfile.TemporaryDirectory()+ self.addCleanup(temporary.cleanup)+ self.root = Path(temporary.name)+ package = self.root / "harness2"+ package.mkdir()+ for name in ("__init__.py", "config.py"):+ shutil.copyfile(ROOT / "harness2" / name, package / name)+ shutil.copyfile(ROOT / "pyproject.toml", self.root / "pyproject.toml")++ def configuration(self, **overrides):+ env = {+ key: value+ for key, value in os.environ.items()+ if key in {"PATH", "HOME", "TMPDIR", "LANG", "LC_ALL", "SYSTEMROOT"}+ }+ env.update(overrides)+ env["PYTHONDONTWRITEBYTECODE"] = "1"+ result = subprocess.run(+ [+ sys.executable,+ "-c",+ "import json; from harness2 import config as c; "+ "print(json.dumps({'project': c.VERTEX_PROJECT, 'region': c.VERTEX_REGION, "+ "'solver': c.SOLVER_MODEL_OC, 'judge': c.JUDGE_MODEL}))",+ ],+ cwd=self.root,+ env=env,+ capture_output=True,+ text=True,+ encoding="utf-8",+ )+ self.assertEqual(result.returncode, 0, result.stderr)+ return json.loads(result.stdout)++ @unittest.skipUnless(shutil.which("cp"), "requires the documented POSIX cp command")+ def test_documented_copy_loads_an_unconfigured_example(self):+ example = ROOT / ".env.example"+ if example.is_file():+ shutil.copyfile(example, self.root / ".env.example")+ command = next(+ line+ for line in (ROOT / "README.md").read_text(encoding="utf-8").splitlines()+ if line == "cp .env.example .env"+ )+ result = subprocess.run(shlex.split(command), cwd=self.root, capture_output=True, text=True)+ self.assertEqual(result.returncode, 0, result.stderr)+ self.assertEqual(+ self.configuration(),+ {+ "project": "",+ "region": "global",+ "solver": "",+ "judge": "",+ },+ )++ def test_existing_file_loading_preserves_shell_precedence(self):+ (self.root / ".env").write_text("GOOGLE_CLOUD_LOCATION=from-file\n", encoding="utf-8")+ self.assertEqual(+ self.configuration(GOOGLE_CLOUD_LOCATION="from-shell")["region"], "from-shell"+ )