"""hub 대상 판정 — 한 곳 (계획 2026-09-27 L6 §2.3 · D-L6-1 · D-L6-10 · C-L6-8 · C-L6-9). `resolve_target(cfg, project)` 은 `Target` 이나 `Skip(code)` 를 돌려준다. 조건(순서대로): 1. `cfg.repo_root` 없음 → `is_repo_managed` 도 거짓이면 `standalone`(조용히), 참이면 `no_repo_root`. 2. `is_repo_managed(project)` 거짓 → `not_repo_managed`(번역·요약 등). 3. `project_contexts(cfg.projects_dir, cfg.repo_root, only=[project])` 가 case 를 못 준다 → `case_unmapped`. 4. resolve 한 `cfg.projects_dir` ≠ resolve 한 `data_home()/solar-eval-projects` → `data_home_mismatch`(검토 F4 — `cfg.projects_dir` 는 resolve 되지 않은 경로다. 심볼릭 링크 홈은 양쪽을 풀어 같다). 5. 훅이 **직접** 쓰는 루트(`hub_reports_dir()` — 잠금·상태 파일·색인 키)가 레포(링크된 워크트리면 메인 작업 트리도) 안 → `data_home_inside_repo`(검토 F10 — PB 미러·사이드카 쓰기는 PB 가 막지만 이 셋은 PB 검사를 거치지 않는다). `poc_bundle` 은 함수 안에서만 import 한다(D-L6-14 — `solar-eval --help` 가 백필·미러를 로딩하지 않게). """ from __future__ import annotations from collections.abc import Mapping from pathlib import Path from typing import TYPE_CHECKING, Any from solar_eval.hub_hook.types import ( PROJECTS_DIRNAME, SKIP_CASE_UNMAPPED, SKIP_DATA_HOME_INSIDE_REPO, SKIP_DATA_HOME_MISMATCH, SKIP_NO_REPO_ROOT, SKIP_NOT_REPO_MANAGED, SKIP_STANDALONE, Skip, Target, ) if TYPE_CHECKING: from solar_eval.cli.config import CLIConfig #: pnpm 워크스페이스 표식 — `workspace_root` 가 코드 체크아웃 루트를 찾는다(C-L6-9). WORKSPACE_MARKER = "pnpm-workspace.yaml" #: 훅 쓰기 위치가 레포 안인지 볼 때 `require_outside_repo` 에 주는 이름표. HOOK_WRITE_LABEL = "hook state" def resolve_target( cfg: CLIConfig, project: str, env: Mapping[str, str] | None = None ) -> Target | Skip: """hub 대상 case 인가(§2.3). 레거시 적재는 어느 결과에서도 부르지 않는다(D-M2-4 (b)).""" repo_root = cfg.repo_root if repo_root is None: return Skip(SKIP_NO_REPO_ROOT if cfg.is_repo_managed(project) else SKIP_STANDALONE) if not cfg.is_repo_managed(project): return Skip(SKIP_NOT_REPO_MANAGED) context = _project_context(cfg.projects_dir, repo_root, project) if context is None or context.case_ref is None: return Skip(SKIP_CASE_UNMAPPED) mismatch = _data_home_mismatch(cfg.projects_dir, env) if mismatch is not None: return mismatch inside = _hook_root_inside_repo(repo_root, env) if inside is not None: return inside return Target( project=project, account=context.account, case=context.case, context=context, repo_root=Path(repo_root), projects_dir=Path(cfg.projects_dir), # 설정 파일 `hub:` 절 — opt-in 해석은 `hook.gated_hub_leg` → `optin.resolve_hub_optin`(L10 §2.6). hub_config=getattr(cfg, "hub", None), ) def _project_context(projects_dir: Path, repo_root: Path, project: str) -> Any | None: from poc_bundle.census.scan import project_contexts contexts = project_contexts(Path(projects_dir), Path(repo_root), only=[project]) return contexts[0] if contexts else None def _data_home_mismatch(projects_dir: Path, env: Mapping[str, str] | None) -> Skip | None: from poc_bundle.home import data_home actual = Path(projects_dir).expanduser().resolve() expected = (data_home(env) / PROJECTS_DIRNAME).resolve() if actual == expected: return None return Skip(SKIP_DATA_HOME_MISMATCH, {"projects_dir": str(actual), "expected": str(expected)}) def _hook_root_inside_repo(repo_root: Path, env: Mapping[str, str] | None) -> Skip | None: from poc_bundle.home import HomeError, hub_reports_dir, require_outside_repo from poc_bundle.mirror import linked_main_work_tree root = hub_reports_dir(env) main = linked_main_work_tree(Path(repo_root)) for tree in (Path(repo_root),) if main is None else (Path(repo_root), main): try: require_outside_repo(root, tree, HOOK_WRITE_LABEL) except HomeError: return Skip(SKIP_DATA_HOME_INSIDE_REPO, {"hub_reports_dir": str(root)}) return None def case_ref_hint(cfg: CLIConfig, project: str) -> str | None: """`--no-ingest` 안내용 case 이름 — `poc_bundle` 없이 config 디렉토리 모양(`accounts///03-evaluation`)에서. 판정이 아니라 문구용이다. 레포를 모르면 None. """ if cfg.repo_root is None: return None config_dir = cfg.config_dirs.get(project) if config_dir is None: return None case_dir = Path(config_dir).parent return f"{case_dir.parent.name}/{case_dir.name}" def workspace_root() -> Path | None: """pnpm 을 돌릴 **코드 체크아웃** 루트 — `solar_eval` 패키지 파일에서 위로 `pnpm-workspace.yaml`(C-L6-9). hub 의 `--repo` 는 config 루트 `cfg.repo_root` 다 — 합성 레포(`SOLAR_EVAL_CONFIG_ROOT`)는 pnpm 워크스페이스가 아니다. """ import solar_eval for parent in Path(solar_eval.__file__).resolve().parents: if (parent / WORKSPACE_MARKER).is_file(): return parent return None def is_smoke_run(source: Any) -> bool: """`--limit` 스모크 run 인가(D-L6-10). `source` 는 `RunPlan`(`.selection.limit` — `runs start`)이나 run.json 매핑(`dataset.selection.limit` — `runs resume`). 양의 정수 limit 만 스모크다(불리언·음수·문자열은 아니다). """ if isinstance(source, Mapping): dataset = source.get("dataset") selection = dataset.get("selection") if isinstance(dataset, Mapping) else None limit = selection.get("limit") if isinstance(selection, Mapping) else None else: selection = getattr(source, "selection", None) limit = getattr(selection, "limit", None) return isinstance(limit, int) and not isinstance(limit, bool) and limit > 0 def snapshot_evaluator_type(run_json: Mapping[str, Any]) -> str | None: """run.json 스냅샷 `config.evaluator_config.config.type` — 모양이 하나라도 다르면 None(D-L6-8). `poc_bundle.legacy_run._snapshot_evaluator_type` 과 같은 경로다(비공개 함수라 import 하지 않고 같은 규칙을 둔다). """ node: Any = run_json.get("snapshot") for key in ("config", "evaluator_config", "config", "type"): if not isinstance(node, Mapping): return None node = node.get(key) return node if isinstance(node, str) and node else None