fix(#1318): list flags uploads decrypted here but never marked seen

A session decrypted three uploads with pull's seen step replaced by a no-op, so their intake issues never got the seen label and retention would never delete them. Nothing showed it.

list now checks debug_logs for a folder named for each unseen upload (old bare-code names, dated names, with a sender, and free_dir's -N copies), flags it, and exits 1. Tests fail on the previous list.

Agent: ScarletForest (session 7ebac884)
pull/1319/head
diffwireauto 2 days ago
parent 092676cd42
commit 1e30fa89d7

@ -9,7 +9,9 @@ C:\Dev\.keys\offband-log-key (with the owner's other keys; OFFBAND_LOG_KEY
overrides the path) and into Bitwarden; without it no upload can ever be read.
The public key goes into the app.
list shows uploads not pulled yet. pull downloads an upload, decrypts it and
list shows uploads not pulled yet. It also flags, and exits 1 for, any of them
that already has a folder in debug_logs: decrypted without the seen step, so
it would never be deleted (#1318). pull downloads an upload, decrypts it and
unpacks it into the main checkout's debug_logs, in a folder named
"YYYY-MM-DD OB-XXXXX <sender's name>" (OFFBAND_LOG_DIR overrides the parent
folder). It is never written inside a worktree, which would lose it when the
@ -60,6 +62,7 @@ MAX_SENDER_BYTES = 4096
MAX_UNPACKED_BYTES = 1024 * 1024 * 1024
UNSAFE_IN_NAME = re.compile(r'[<>:"/\\|?*\x00-\x1f]')
CODE =re.compile(r"^OB-[23456789ABCDEFGHJKMNPQRSTUVWXYZ]{5}$")
CODE_IN_TITLE = re.compile(r"OB-[23456789ABCDEFGHJKMNPQRSTUVWXYZ]{5}(?=:)")
OBJECT = re.compile(r"`(uploads/(OB-[23456789ABCDEFGHJKMNPQRSTUVWXYZ]{5})-[0-9a-f-]{36}\.bin)`")
@ -257,6 +260,37 @@ def unseen(issues: list) -> list:
return [i for i in issues if SEEN_LABEL not in {label["name"] for label in i["labels"]}]
def local_folders(code: str, out_root: Path) -> list:
"""Folders pull has made for this code: "OB-XXXXX" (before #1217's naming),
"YYYY-MM-DD OB-XXXXX[ name]", or either with free_dir's "-N" suffix."""
if not out_root.is_dir():
return []
pattern = re.compile(rf"^(\d{{4}}-\d{{2}}-\d{{2}} )?{re.escape(code)}(-\d+)?( |$)")
return sorted(p.name for p in out_root.iterdir() if p.is_dir() and pattern.match(p.name))
def list_uploads(issues: list, out_root: Path, out=None) -> int:
"""Print the uploads not marked seen. Flag any that already has a folder
here: it was decrypted without the seen step, so retention never starts
(#1318). Returns how many were flagged."""
out = out or sys.stdout
waiting = unseen(issues)
flagged = 0
for issue in waiting:
line = f"#{issue['number']} {issue['createdAt'][:16]} {issue['title']}"
code = CODE_IN_TITLE.match(issue["title"])
folders = local_folders(code.group(0), out_root) if code else []
if folders:
flagged += 1
line += f"\n decrypted here but not marked seen: {', '.join(folders)}"
print(line, file=out)
print(f"{len(waiting)} upload(s) not pulled yet.", file=out)
if flagged:
print(f"{flagged} of them were decrypted without being marked seen, so they will never "
f"be deleted. Pull each again to mark it, or see #1318.", file=out)
return flagged
def pull(code: str, *, key=None, issues=None, fetch=download, seen=mark_seen,
out_root: Path = None, out=sys.stdout) -> list:
if not CODE.match(code):
@ -303,10 +337,8 @@ def main(argv=None) -> int:
if args.command == "keygen":
keygen()
elif args.command == "list":
waiting = unseen(intake_issues("open"))
for issue in waiting:
print(f"#{issue['number']} {issue['createdAt'][:16]} {issue['title']}")
print(f"{len(waiting)} upload(s) not pulled yet.")
if list_uploads(intake_issues("open"), default_out_root()):
return 1
else:
pull(args.code)
return 0

@ -233,6 +233,40 @@ def test_list_leaves_out_uploads_already_seen():
assert [i["number"] for i in ol.unseen(issues)] == [7]
@pytest.mark.parametrize("folder", [
"OB-7K2QX",
"2026-11-28 OB-7K2QX",
"2026-11-28 OB-7K2QX Some Name",
"2026-11-28 OB-7K2QX-2",
])
def test_list_flags_an_unseen_upload_already_decrypted_here(tmp_path, folder):
# #1318: a session decrypted uploads without the seen step, so retention
# never started and nothing showed it.
(tmp_path / folder).mkdir()
out = io.StringIO()
assert ol.list_uploads([ISSUE], tmp_path, out=out) == 1
text = out.getvalue()
assert "OB-7K2QX" in text and "not marked seen" in text and folder in text
def test_list_does_not_flag_an_upload_with_no_folder_here(tmp_path):
(tmp_path / "2026-11-28 OB-9ABCD").mkdir()
(tmp_path / "offband.log").write_text("")
out = io.StringIO()
assert ol.list_uploads([ISSUE], tmp_path, out=out) == 0
assert "not marked seen" not in out.getvalue()
assert ol.list_uploads([ISSUE], tmp_path / "missing", out=io.StringIO()) == 0
def test_list_command_fails_when_an_upload_was_decrypted_but_not_marked(tmp_path, monkeypatch, capsys):
monkeypatch.setenv("OFFBAND_LOG_DIR", str(tmp_path))
monkeypatch.setattr(ol, "intake_issues", lambda state, search="": [ISSUE])
assert ol.main(["list"]) == 0
(tmp_path / "2026-11-28 OB-7K2QX").mkdir()
assert ol.main(["list"]) == 1
assert "not marked seen" in capsys.readouterr().out
@pytest.mark.parametrize("code", ["OB-0O1IL", "ob-7k2qx", "OB-7K2Q", "7K2QX"])
def test_refuses_a_malformed_code(code):
with pytest.raises(SystemExit):

Loading…
Cancel
Save

Powered by TurnKey Linux.