Files
DongHyeonka 9d65a41d82 chore(ledger): 예측·실측 장부를 두고 이 작업의 착수 예측을 남긴다
작업마다 착수할 때의 예측과 끝날 때의 실측을 남길 곳이 프론트에 없었다.
소유자 결정(2026-11-07 Q11)은 repo마다 docs/ledger/estimates.jsonl이다.

docs/ledger/README.md(백엔드와 같은 형식)와 estimates.jsonl을 두고,
여러 브랜치가 끝에 줄을 더해도 병합이 멈추지 않게 .gitattributes가
merge=union을 준다. 첫 줄은 이 작업(fe-c-harness)의 착수 예측이다.

위험·한계: 복사한 프로젝트는 템플릿의 줄을 받는다. README 지워도 되는
표에 "줄을 비운다"로 적는다(뒤 커밋).

검증: python3 -m unittest scripts/tests/test_ledger.py 통과.

Refs: design-docs harness/01-harness-design.md 10절·13절 Q11
2026-11-08 17:27:39 +09:00

60 lines
2.5 KiB
Python

"""docs/ledger/estimates.jsonl의 줄이 docs/ledger/README.md 형식인지 본다. 빈 파일(복사한 프로젝트)도 통과한다.
python3 -m unittest discover -s scripts/tests
"""
from __future__ import annotations
import json
import unittest
from datetime import datetime
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent.parent
LEDGER = REPO / "docs/ledger/estimates.jsonl"
KINDS = {"estimate", "actual", "retro"}
COMMON = ("schema", "kind", "task", "recorded_at")
RANGES = ("minutes", "calls", "output_tokens")
def lines() -> list[dict]:
if not LEDGER.exists():
return []
return [json.loads(line) for line in LEDGER.read_text(encoding="utf-8").splitlines() if line.strip()]
class LedgerTest(unittest.TestCase):
def test_lines_merge_by_union(self) -> None:
self.assertIn("docs/ledger/estimates.jsonl merge=union",
(REPO / ".gitattributes").read_text(encoding="utf-8").splitlines())
def test_every_line_is_json_with_the_common_fields(self) -> None:
for number, entry in enumerate(lines(), start=1):
self.assertTrue(set(COMMON) <= entry.keys(), f"line {number}: {sorted(set(COMMON) - entry.keys())}")
self.assertEqual(entry["schema"], 1, number)
self.assertIn(entry["kind"], KINDS, number)
datetime.fromisoformat(entry["recorded_at"])
def test_an_estimate_has_ordered_ranges_and_a_basis(self) -> None:
for entry in (e for e in lines() if e["kind"] == "estimate"):
for field in RANGES:
values = entry[field]
self.assertLessEqual(values["p30"], values["p50"], (entry["task"], field))
self.assertLessEqual(values["p50"], values["p80"], (entry["task"], field))
self.assertTrue(entry["basis"].strip(), entry["task"])
def test_an_actual_follows_its_estimate_and_names_the_band_it_fell_in(self) -> None:
entries = lines()
for position, entry in enumerate(entries):
if entry["kind"] != "actual":
continue
estimates = [e for e in entries[:position] if e["kind"] == "estimate" and e["task"] == entry["task"]]
self.assertTrue(estimates, f"{entry['task']}: an actual line needs an earlier estimate line")
bands = estimates[-1]["minutes"]
expected = next((band for band in ("p30", "p50", "p80") if entry["active_minutes"] <= bands[band]), "over")
self.assertEqual(entry["within"], expected, entry["task"])
if __name__ == "__main__":
unittest.main()