"""Ordinary evidence fixture: owns synthetic Git checkout and artifacts.""" import json import os import subprocess import sys import tempfile from pathlib import Path from harness.tests._support.paths import ROOT SCRIPT = ROOT / "harness/agents/impl/skills/gitea-issue-rework/scripts/evidence_manifest.py" def run_git(cwd, *args): return subprocess.run(["git", *args], cwd=cwd, text=True, capture_output=True, check=True) class EvidenceManifestFixture: def setup(self): try: self._setup() except BaseException: self.cleanup() raise return self def cleanup(self): if hasattr(self, 'tmp'): self.tmp.cleanup() def _setup(self): self.tmp = tempfile.TemporaryDirectory(dir=os.environ.get('TMPDIR', '/opt/data/cache/scratch')) self.root = Path(self.tmp.name) self.contract = self.root / 'harness/operations/repository-cache.md' self.contract.parent.mkdir(parents=True) self.contract.write_text('# Repository cache 운영 지침\n') self.repo = self.root / 'repositories/owner/project/worktrees/issue-1/checkout' self.artifacts = self.repo.parent / 'verification/run-a' self.repo.mkdir(parents=True) self.artifacts.mkdir(parents=True) for path in (self.root / 'repositories', *self.repo.parents): if path == self.root: break path.chmod(448) self.repo.chmod(448) self.artifacts.parent.chmod(448) self.artifacts.chmod(448) run_git(self.repo, 'init', '-q') run_git(self.repo, 'config', 'user.email', 'test@example.invalid') run_git(self.repo, 'config', 'user.name', 'Test') (self.repo / 'input.txt').write_text('hello\n') run_git(self.repo, 'add', 'input.txt') run_git(self.repo, 'commit', '-qm', 'initial') def invoke(self, *args, env=None): op, *rest = args common = [] if op == 'validate-legacy' else ['--contract-path', str(self.contract), '--artifact-root', str(self.artifacts)] return subprocess.run([sys.executable, str(SCRIPT), str(op), *common, *map(str, rest)], cwd=self.repo, text=True, capture_output=True, env=env) def plan(self, commands=None, **extra): if commands is None: commands = [{'id': 'check', 'purpose': 'show input', 'argv': ['git', 'show', 'HEAD:input.txt'], 'expected_exit_code': 0, 'claims': ['output']}] data = {'hash_paths': ['input.txt'], 'commands': [dict({'timeout_seconds': 5}, **command) for command in commands]} data.update(extra) p = self.artifacts / 'plan.json' p.write_text(json.dumps(data)) p.chmod(384) return p def run_manifest(self, plan=None): if plan is None: plan = self.plan() out = self.artifacts / 'manifest.json' result = self.invoke('run', '--repo-root', self.repo, '--plan', plan.name, '--output', 'manifest.json') return (result, out)