The code cited its plan instead of saying why: `E28 review J4`, `(R6 S3b)`, `S1 justified…`,
`deep-review round 5`. That plan lives in the private ops repo, so for every reader of this one the
citation was noise, and a sentence whose subject was the plan step ("round 2 showed…") hid its
lesson behind an id. Each one is gone and the "why" kept: a bare citation is deleted, a sentence
carrying a lesson is reworded around it ("a later attempt showed…").
Measured (`scripts/audit_metrics.py`, product code): 652 lines in 270 files carried an epic code by
the definition the next commit holds (507 / 241 by the old, two-digit-only one) -> 0. Across all
code, tests, scripts and configs: ~1100 epic-code lines plus ~320 sprint/round ids.
Behaviour unchanged, checked mechanically: every changed .py file has the same AST once docstrings
are blanked; css/sh/toml/yml/json files are identical once comments are stripped; the only
non-comment changes in TS/JS are test titles, one description string in a contract table, and five
ESLint messages, whose text is all the gates snapshot diff holds. Not touched: Markdown (docs and
the changelog keep their history), Alembic migrations, TV episode notation (`S2 · E5`), DESIGN.md
ids (`C1`, `B4`, `S3h`), tracker ids (`SEC-16`, `DX-17`).
One stale claim fixed on the way: test_hls_reaper's docstring said the player checkpoints "every
10 s whether or not it is playing", which plex/stream.py calls wrong; it now says what the code does.
80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
"""What an issue from a debug session carries, as files — one definition for the zip export and the
|
|
Gitea upload, so the two cannot drift apart.
|
|
|
|
* `issue.md` — the title and the body the user wrote and reviewed in the composer (rendered there,
|
|
in their language; the server does not rewrite it);
|
|
* `client.log` / `server.log` — the session's evidence (`debugsession.bundle`) minus the rows the
|
|
user took out, one JSON object per line, browser rows and server rows apart. `.log`, not
|
|
`.jsonl`: Gitea refuses that extension (measured);
|
|
* the screenshots, in the order they were taken.
|
|
|
|
Every row is already redacted twice (at capture, and again when stored), and nothing here adds a
|
|
field the review list did not show.
|
|
"""
|
|
|
|
import io
|
|
import json
|
|
import zipfile
|
|
from dataclasses import dataclass
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app import debugsession, logsink
|
|
from app.models import DebugScreenshot, DebugSession
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class IssueFile:
|
|
name: str
|
|
data: bytes
|
|
mime: str
|
|
|
|
|
|
def title_of(session: DebugSession) -> str:
|
|
# Not a sentence of ours: the composer always saves a title in the user's language, and a
|
|
# session exported before it ever saved is named by its date alone, in no language at all.
|
|
title = ((session.draft or {}).get("title") or "").strip()
|
|
return title or f"{session.started_at:%Y-%m-%d %H:%M} · {session.id}"
|
|
|
|
|
|
def body_of(session: DebugSession) -> str:
|
|
return ((session.draft or {}).get("body") or "").strip()
|
|
|
|
|
|
def _lines(rows) -> bytes:
|
|
return "".join(
|
|
json.dumps(logsink.serialize(r), ensure_ascii=False, default=str) + "\n" for r in rows
|
|
).encode()
|
|
|
|
|
|
def files(db: Session, session: DebugSession) -> list[IssueFile]:
|
|
"""The session's issue as files: the text, the two logs, the screenshots."""
|
|
rows, _ = debugsession.bundle(db, session, drop_excluded=True)
|
|
text = f"# {title_of(session)}\n\n{body_of(session)}\n"
|
|
out = [
|
|
IssueFile("issue.md", text.encode(), "text/markdown"),
|
|
IssueFile("client.log", _lines(r for r in rows if r.source == "web"), "text/plain"),
|
|
IssueFile("server.log", _lines(r for r in rows if r.source != "web"), "text/plain"),
|
|
]
|
|
shots = db.scalars(
|
|
select(DebugScreenshot)
|
|
.where(DebugScreenshot.session_id == session.id)
|
|
.order_by(DebugScreenshot.id)
|
|
)
|
|
for n, shot in enumerate(shots, start=1):
|
|
ext = debugsession.IMAGE_TYPES[shot.mime]
|
|
name = f"{debugsession.SCREENSHOT_PREFIX}{n}.{ext}"
|
|
out.append(IssueFile(name, shot.data, shot.mime))
|
|
return out
|
|
|
|
|
|
def zipped(items: list[IssueFile]) -> bytes:
|
|
buf = io.BytesIO()
|
|
with zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) as z:
|
|
for item in items:
|
|
# The images are compressed already: deflating them again costs time and wins nothing.
|
|
method = zipfile.ZIP_STORED if item.mime.startswith("image/") else zipfile.ZIP_DEFLATED
|
|
z.writestr(item.name, item.data, compress_type=method)
|
|
return buf.getvalue()
|