Spaces:
Running
Running
File size: 5,713 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | """pnpm ์คํ โ ํ ๊ณณ (๊ณํ 2026-09-27 L6 ยง2.6 ยท D-L6-13 ยท ๊ฒํ F8).
`run_pnpm` ์ ํ
์ด pnpm ์ ๋ถ๋ฅด๋ **์ ์ผํ** ์ง์
์ ์ด๋ค. ๋ ๊ฐ์ง๋ฅผ ์ฌ๊ธฐ์ ๊ณ ์ ํ๋ค:
- **ํ๋ก์ธ์ค ๊ทธ๋ฃน์งธ ์ฃฝ์ด๊ธฐ.** `subprocess.run(timeout=)` ์ ์ง๊ณ pnpm ๋ง ์ฃฝ์ฌ `tsx` ์์๊ฐ hub ์ธ์
advisory lock ์ ์ฅ ์ฑ
๋จ๋๋ค. ์ ์ธ์
(`start_new_session=True`)์ผ๋ก ๋์ฐ๊ณ ํ๋๋ฅผ ๋๊ธฐ๋ฉด `os.killpg`(SIGTERM โ ์ ์ ๋ค SIGKILL) ํ ๋ค
`TimeoutExpired` ๋ฅผ ๋ธ๋ค โ ์ฐ๊ฒฐ์ด ๋ซํ ์๋ฒ๊ฐ ์ ๊ธ์ ํผ๋ค.
- **ํ์ฉ ๋ชฉ๋ก(๋ฆฌ๋ทฐ ์ง์ 2).** argv ๋ `hub_leg.build_hub_argv` ๊ฐ ๋ง๋๋ ๋ชจ์ ๊ทธ๋๋ก์ฌ์ผ ํ๋ค โ ๊ณ ์ ๋จธ๋ฆฌ
`pnpm --silent --fail-if-no-match --filter @poc/eval-store hub ingest` ๋ค์ ์๋ ค์ง ์ ์ฌ ์ต์
(`--case`ยท`--expect-run`ยท
`--repo`ยท`--mirror`ยท`--index` ๊ฐ ํ๋์ฉ, ํ์ธ ํ๋๊ทธ)๋ง. ๋ค๋ฅธ ํจํค์งยท`exec`ยท๋ค๋ฅธ hub ํ์ ๋ช
๋ น(ํ๊ดด ๋ช
๋ น ํฌํจ)ยท๋ ๊ฑฐ์ ์ ์ฌ
์ต์
ยท๋ ๋ฒ์งธ `hub` ๋ ๋ชจ๋ `ValueError` ๋ค. ํ
์ ์ ์ฌ ํ๋๋ง ๋ถ๋ฅธ๋ค(D-M2-4 (b) ยท ๊ณํ ยง0.4-6).
- **์คํ๋ถ๋ ๋น๊ณต๊ฐ**(`_run_group`, ๋ฆฌ๋ทฐ ์ง์ 3ยท6) โ ํ์ฉ ๋ชฉ๋ก ์์ด argv ๋ฅผ ๋๋ฆฌ๋ฏ๋ก ์ด ๋ชจ๋ ๋ฐ์์ ๋ถ๋ฅด์ง ์๋๋ค
(`test_scaffold.py` ๊ฐ ์์ค๋ก ๋ง๋๋ค). ์ํ์ ๊ทธ๋ฃน kill ํ์ธ์๋ง ์ด๋ค.
ํ
์คํธ tripwire(D-L6-13): `SE/tests/conftest.py` ๊ฐ ์ด ๋ชจ๋์ `run_pnpm` ์ "ํธ์ถ๋๋ฉด `pytest.fail`" ๋ก ๋ฐ๊พผ๋ค. ๊ทธ๋ฌ๋ ํธ์ถ์๋
๋ฐ๋์ **๋ชจ๋ ์์ฑ์ผ๋ก** ๋ถ๋ฅธ๋ค โ `from solar_eval.hub_hook import proc; proc.run_pnpm(...)`. ํจ์๋ฅผ ์ด๋ฆ์ผ๋ก import ํ๋ฉด
ํจ์น๋ฅผ ๋น์ผ ๊ฐ๋ค(`test_scaffold.py` ๊ฐ ์์ค ํ
์คํธ๋ก ๋ง๋๋ค).
"""
from __future__ import annotations
import os
import signal
import subprocess
from collections.abc import Mapping, Sequence
from pathlib import Path
from solar_eval.hub_hook.optin import CONFIRM_FLAG
from solar_eval.hub_hook.types import HUB_PACKAGE_FILTER
PNPM = "pnpm"
#: ํ
์ด ๋ถ๋ฅผ ์ ์๋ ์ ์ผํ ๋ช
๋ น ๋จธ๋ฆฌ โ pnpm ์ ์ญ ์ต์
+ ์ ์ฌ ํ๋(ยง2.6 argv).
ALLOWED_ARGV_HEAD = (
PNPM, "--silent", "--fail-if-no-match", "--filter", HUB_PACKAGE_FILTER, "hub", "ingest",
) # fmt: skip
#: ๋จธ๋ฆฌ ๋ค์ ์ฌ ์ ์๋ ๊ฐ ์ต์
(๊ฐ ํ๋์ฉ โ ๊ฐ์ `-` ๋ก ์์ํ์ง ์๋๋ค).
ALLOWED_VALUE_OPTIONS = frozenset({"--case", "--expect-run", "--repo", "--mirror", "--index"})
#: ๋จธ๋ฆฌ ๋ค์ ์ฌ ์ ์๋ ํ๋๊ทธ.
ALLOWED_FLAGS = frozenset({CONFIRM_FLAG})
#: SIGTERM ๋ค SIGKILL ๊น์ง ๊ธฐ๋ค๋ฆฌ๋ ์ด.
KILL_GRACE_SECONDS = 5.0
def run_pnpm(
argv: Sequence[str],
*,
cwd: Path,
env: Mapping[str, str] | None = None,
timeout: float,
) -> subprocess.CompletedProcess[str]:
"""ํ์ฉ ๋ชฉ๋ก์ ํต๊ณผํ pnpm argv ๋ฅผ ์ ์ธ์
์ผ๋ก ๋๋ฆฐ๋ค. ํ๋ ์ด๊ณผ๋ ๊ทธ๋ฃน์งธ ์ฃฝ์ด๊ณ `TimeoutExpired`.
`FileNotFoundError`(pnpm ์์)๋ ๊ทธ๋๋ก ๋ธ๋ค โ ํธ์ถ์(hub ๋ค๋ฆฌ)๊ฐ `pnpm_missing` ์ผ๋ก ๋ฐ๊พผ๋ค.
"""
check_pnpm_argv(argv)
return _run_group(argv, cwd=cwd, env=env, timeout=timeout)
def check_pnpm_argv(argv: Sequence[str]) -> None:
"""๊ณ ์ ๋จธ๋ฆฌ + ์๋ ค์ง ์ ์ฌ ์ต์
๋ง์ธ argv ๊ฐ ์๋๋ฉด `ValueError`(๋ฌธ๊ตฌ์ ๊ฐ์ ์ฃ์ง ์๋๋ค)."""
args = list(argv)
head = len(ALLOWED_ARGV_HEAD)
if tuple(args[:head]) != ALLOWED_ARGV_HEAD:
raise ValueError("run_pnpm: argv must start with the fixed eval-store 'hub ingest' head")
rest = args[head:]
index = 0
while index < len(rest):
token = rest[index]
if token in ALLOWED_FLAGS:
index += 1
continue
if token not in ALLOWED_VALUE_OPTIONS:
raise ValueError(f"run_pnpm: argument #{head + index} is not an allowed ingest option")
value = rest[index + 1] if index + 1 < len(rest) else None
if not value or value.startswith("-"):
raise ValueError(f"run_pnpm: option {token} needs a value")
index += 2
def _run_group(
argv: Sequence[str],
*,
cwd: Path,
env: Mapping[str, str] | None = None,
timeout: float,
) -> subprocess.CompletedProcess[str]:
"""argv ๋ฅผ ์ ํ๋ก์ธ์ค ๊ทธ๋ฃน์ผ๋ก ๋๋ฆฌ๊ณ ์ถ๋ ฅ์ ๋ชจ์๋ค(ํ์ฉ ๋ชฉ๋ก ์์ โ `run_pnpm` ์ ์คํ๋ถ, ๋ชจ๋ ๋ฐ์์ ๋ถ๋ฅด์ง ์๋๋ค)."""
process = subprocess.Popen(
list(argv),
cwd=str(cwd),
env=None if env is None else dict(env),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
start_new_session=True,
)
try:
stdout, stderr = process.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
stdout, stderr = _kill_group(process)
raise subprocess.TimeoutExpired(list(argv), timeout, stdout, stderr) from None
except BaseException:
# KeyboardInterrupt ๋ฑ โ ์์๊ฐ ์ ๊ธ์ ์ฅ ์ฑ ๋จ์ง ์๊ฒ ๊ทธ๋ฃน์ ์ ๋ฆฌํ๊ณ ๊ทธ๋๋ก ์ฌ๋ฆฐ๋ค.
_kill_group(process)
raise
return subprocess.CompletedProcess(list(argv), process.returncode, stdout, stderr)
def _kill_group(process: subprocess.Popen[str]) -> tuple[str, str]:
"""SIGTERM โ ์ ์ โ SIGKILL. ๋จ์ ์ถ๋ ฅ์ ๋๋ ค์ค๋ค."""
_signal_group(process, signal.SIGTERM)
try:
return process.communicate(timeout=KILL_GRACE_SECONDS)
except subprocess.TimeoutExpired:
_signal_group(process, signal.SIGKILL)
return process.communicate()
def _signal_group(process: subprocess.Popen[str], sig: signal.Signals) -> None:
try:
os.killpg(process.pid, sig)
except ProcessLookupError:
# ์ด๋ฏธ ๋๋ ๊ทธ๋ฃน โ ๋ณด๋ผ ๊ณณ์ด ์๋ค.
return
|