mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-19 18:54:32 +01:00
feedback_inbox and app_errors guessed kuhyx/<folder> for a task's repo, which filed cleanup-plate under kuhyx/cleanup-plate (real: Sepci0/cleanup-plate) and showed phantom repos on the board. Both now read the GitHub owner/name from ~/src/<folder>'s origin remote (https or ssh forms) and fall back to the guess only when there is no checkout or its origin is not on GitHub. app-errors 0.1.2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZfgt44aEKxvGBJkwP
116 lines
3.7 KiB
Python
116 lines
3.7 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
"""Builders for fake feedback bundles and a fake todo client."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
import json
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
from typing import TYPE_CHECKING
|
|
|
|
from feedback_inbox._todo import TaskRef, TodoError
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
STAMP = "2026-11-11T13-52-33-162"
|
|
NOTE = "I would like to see the painting IN FULL\n\nsecond paragraph"
|
|
|
|
|
|
def entry_text(bundle: Path, note: str = NOTE, game: str = "museum") -> str:
|
|
"""The markdown entry a game appends for ``bundle``."""
|
|
head = note.splitlines()[0][:70] if note else ""
|
|
parts = [f"## 2026-11-11T13:52:33: {head}", ""]
|
|
if note:
|
|
parts += [note, ""]
|
|
parts += [
|
|
f"- Screenshot: `{bundle}/annotated.png`",
|
|
f"- Report: `{bundle}/report.json`",
|
|
f"- Game `{game}`, combo `loop=P2,carry=d,id=c`, build abc, session `s`",
|
|
"",
|
|
"Task: Read the annotated screenshot and fix it.",
|
|
"",
|
|
]
|
|
return "\n".join(parts)
|
|
|
|
|
|
def make_bundle(
|
|
data_root: Path,
|
|
*,
|
|
game: str = "cleanup-plate",
|
|
stamp: str = STAMP,
|
|
note: str = NOTE,
|
|
report: str | None = "ok",
|
|
entry: bool = True,
|
|
age: float = 60.0,
|
|
now: float = 1_000_000.0,
|
|
) -> Path:
|
|
"""Create ``<game>_binaries/feedback/<stamp>/`` and its md entry."""
|
|
feedback = data_root / f"{game}_binaries" / "feedback"
|
|
bundle = feedback / stamp
|
|
bundle.mkdir(parents=True, exist_ok=True)
|
|
if report is not None:
|
|
path = bundle / "report.json"
|
|
if report == "ok":
|
|
body = json.dumps({"note": note, "game": "museum", "combo": "loop=P2"})
|
|
else:
|
|
body = report
|
|
path.write_text(body, encoding="utf-8")
|
|
os.utime(path, (now - age, now - age))
|
|
if entry:
|
|
md = feedback / f"feedback-{stamp[:10]}.md"
|
|
with md.open("a", encoding="utf-8") as handle:
|
|
handle.write(entry_text(bundle, note))
|
|
return bundle
|
|
|
|
|
|
@dataclass
|
|
class FakeTodo:
|
|
"""A todo server stand-in that stores notes the way the real one does."""
|
|
|
|
calls: list[tuple[str, str, str]] = field(default_factory=list)
|
|
stored: dict[str, str] = field(default_factory=dict)
|
|
fail: bool = False
|
|
fail_update: bool = False
|
|
merged: bool = False
|
|
updated: list[str] = field(default_factory=list)
|
|
|
|
def add_task(self, repo: str, title: str, body: str) -> TaskRef:
|
|
if self.fail:
|
|
msg = "todo down"
|
|
raise TodoError(msg)
|
|
self.calls.append((repo, title, body))
|
|
task_id = f"id{len(self.calls):04d}" + "0" * 28
|
|
# A new_note task: title "<name> todos: <title>", then a "## <title>"
|
|
# section holding the body.
|
|
name = repo.rsplit("/", maxsplit=1)[-1]
|
|
self.stored[task_id] = f"{name} todos: {title}\n\n## {title}\n{body}"
|
|
return TaskRef(task_id=task_id, merged=self.merged)
|
|
|
|
def update_task(self, task_id: str, title: str, body: str) -> None:
|
|
if self.fail_update:
|
|
msg = "update refused"
|
|
raise TodoError(msg)
|
|
self.updated.append(task_id)
|
|
self.stored[task_id] = f"{title}\n\n{body}"
|
|
|
|
|
|
GIT = shutil.which("git") or "git"
|
|
|
|
|
|
def make_checkout(path: Path, origin: str | None) -> Path:
|
|
"""A real git repo at ``path`` (origin ``origin`` unless None), no real config."""
|
|
env = {
|
|
"PATH": os.environ["PATH"],
|
|
"HOME": str(path.parent),
|
|
"GIT_CONFIG_NOSYSTEM": "1",
|
|
}
|
|
path.mkdir(parents=True)
|
|
subprocess.run([GIT, "init", "-q", str(path)], check=True, env=env)
|
|
if origin is not None:
|
|
git = [GIT, "-C", str(path), "remote", "add", "origin", origin]
|
|
subprocess.run(git, check=True, env=env)
|
|
return path
|