File size: 2,817 Bytes
3dfc93b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""์žฌ์ฑ„์  ๋ฒˆ๋“ค์ด ๋†“์ผ ๊ณณ (๊ณ„ํš 2026-09-26 L3b ยง2.1 "๋ฏธ๋Ÿฌ ๋ฃจํŠธ ์ธต").

- ๋ฏธ๋Ÿฌ ์˜์—ญ = `<mirror_root>/<bucket>/accounts/<a>/<c>/eval/<area>` โ€” `mirror_root` ๋Š” **๋ฒ„ํ‚ท์˜ ๋ถ€๋ชจ**(`poc_bundle.mirror.mirror_bundle(root=)`
  ์™€ ๊ฐ™์€ ๋œป, ๊ธฐ๋ณธ `blob_mirror_root()`). ๊ฒฝ๋กœ ์กฐ๊ฐ์€ `poc_bundle.data.layout` ์˜ ๊ทœ์น™์œผ๋กœ๋งŒ ๋งŒ๋“ ๋‹ค(์Šฌ๋Ÿฌ๊ทธ ๊ฒ€์‚ฌ ํฌํ•จ).
- `<run_bundle_dir>` ๋ชจ๋“œ ๊ธฐ๋ณธ ์ถœ๋ ฅ: ๋ฒˆ๋“ค์ด `โ€ฆ/eval/bundles/<id>` ์— ์žˆ์œผ๋ฉด `โ€ฆ/eval/evaluations`(eval-wrap ๊ณผ ๊ฐ™์€ ๊ทœ์น™),
  ์•„๋‹ˆ๋ฉด ํ˜ธ์ถœ์ž๊ฐ€ `--out` ์„ ์ค˜์•ผ ํ•œ๋‹ค.
"""

from __future__ import annotations

from pathlib import Path

from poc_bundle.data.errors import DataConfigError
from poc_bundle.data.layout import SUBPREFIX, case_prefix
from poc_bundle.home import blob_mirror_root
from poc_bundle.mirror import DEFAULT_BUCKET

BUNDLES_AREA = "bundles"
EVALUATIONS_AREA = "evaluations"


class RescorePathError(ValueError):
    """์žฌ์ฑ„์  ์ž…๋ ฅยท์ถœ๋ ฅ ์œ„์น˜๋ฅผ ์ •ํ•  ์ˆ˜ ์—†๋‹ค(์ž˜๋ชป๋œ case ์Šฌ๋Ÿฌ๊ทธยท๊ธฐ๋ณธ ์ถœ๋ ฅ ์œ„์น˜ ์—†์Œ)."""


def parse_case_key(case_key: str) -> tuple[str, str]:
    """`a/c` โ†’ (account, case). ์Šฌ๋Ÿฌ๊ทธ ๊ทœ์น™์€ `case_prefix` ๊ฐ€ ๋ณธ๋‹ค."""
    parts = case_key.split("/") if isinstance(case_key, str) else []
    if len(parts) != 2:
        raise RescorePathError(f"case must be <account>/<case>, got {case_key!r}")
    account, case = parts
    try:
        case_prefix(account, case)
    except DataConfigError as exc:
        raise RescorePathError(str(exc)) from exc
    return account, case


def mirror_area_dir(
    mirror_root: Path | None, account: str, case: str, area: str, *, bucket: str = DEFAULT_BUCKET
) -> Path:
    """๋ฏธ๋Ÿฌ์˜ ํ•œ case ์˜์—ญ ๋””๋ ‰ํ† ๋ฆฌ(`bundles` ๋˜๋Š” `evaluations`)."""
    if area not in (BUNDLES_AREA, EVALUATIONS_AREA):
        raise RescorePathError(f"unknown mirror area {area!r}")
    try:
        prefix = case_prefix(account, case)
    except DataConfigError as exc:
        raise RescorePathError(str(exc)) from exc
    return resolve_mirror_root(mirror_root) / bucket / prefix / SUBPREFIX[area]


def resolve_mirror_root(mirror_root: Path | None) -> Path:
    """๋ฏธ๋Ÿฌ ๋ฒ„ํ‚ท์˜ ๋ถ€๋ชจ ์ ˆ๋Œ€ ๊ฒฝ๋กœ โ€” None ์ด๋ฉด ๋ฐ์ดํ„ฐ ํ™ˆ์˜ `blob-mirror`."""
    return blob_mirror_root() if mirror_root is None else Path(mirror_root).expanduser().resolve()


def default_evaluations_dir(run_bundle_dir: Path) -> Path | None:
    """`โ€ฆ/eval/bundles/<id>` โ†’ `โ€ฆ/eval/evaluations`. ๊ทธ ๋ชจ์–‘์ด ์•„๋‹ˆ๋ฉด None(ํ˜ธ์ถœ์ž๊ฐ€ `--out` ์„ ์š”๊ตฌํ•œ๋‹ค)."""
    resolved = Path(run_bundle_dir).resolve()
    parent = resolved.parent
    if parent.name == Path(SUBPREFIX[BUNDLES_AREA]).name and parent.parent.name == "eval":
        return parent.parent / Path(SUBPREFIX[EVALUATIONS_AREA]).name
    return None