Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions fleetwatch/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def derive(self, holds):
self.helpers.setdefault(data.clean(r["name"]), r)
self.grouping = views.Grouping(
{x["name"]: self.groups.of(x["name"], x["r"]["cwd"], x["r"]["sessionId"]) for x in self.view["rows"]},
self.groups.names())
self.groups.names(), fallback=lambda name: self.groups.of(
name, (self.gone.get(name) or {}).get("cwd"), (self.gone.get(name) or {}).get("sessionId")))
bad = len(index_health.problem_rows(self.indexes.rows, now))
self.header = views.header_text(self.view, self.counts, now, self.warnings, False, bad, len(self.watches))
self.header_mid = views.header_text(self.view, self.counts, now, self.warnings, False, bad,
Expand Down Expand Up @@ -1482,13 +1483,18 @@ def action_regroup(self):
names = snap.groups.names()
current = snap.grouping.of(name)

# A session that is not running has no live record; its Needs-you row
# carries the folder and session id when its status file names them, so
# the move updates the same pins a live move wrote. With neither, the
# session is pinned by name alone and its paths give no group (Other).
rec = snap.records.get(name) or snap.gone.get(name) or {}

def chosen(group):
if group is None:
return
try:
config.set_override(config.groups_path(), name, group,
snap.groups.by_path(snap.records[name]["cwd"]),
snap.records[name]["sessionId"])
snap.groups.by_path(rec.get("cwd")), rec.get("sessionId"))
except (OSError, ValueError) as exc:
self.say("could not save the group: %s" % (data.clean(exc)[:70] or type(exc).__name__))
return
Expand Down
5 changes: 4 additions & 1 deletion fleetwatch/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,12 @@ def gone_row(r, name, now):
"""A Needs-you row for a session with no live row, so its due items stay visible."""
sf = r["status"] or {}
upd = to_epoch(sf.get("updated"))
# A file-only record carries no session id; the status file names it, and a
# group pin written while the session ran is keyed by it.
sid = r.get("sessionId") or (sf.get("sessionId") if isinstance(sf.get("sessionId"), str) else None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOW: this also changes how Enter reopens a session that is not running. offer_reopen (fleetwatch/app.py:1648-1651) matches a Resume entry by rec["sessionId"] first and only falls back to the name when that finds nothing. Before this change, a file-only record had sessionId=None here, so reopen always matched by name. Now it matches by the status file's id first.

That is usually the better match. If the status file is stale, though, its id can point at an older transcript than the one the name match would find. One way this happens: the session got a new id (after /clear, say) and never rewrote its status file. I'm not sure this happens in practice. If the id should only feed the group pins, the narrowest fix is to keep it out of r["sessionId"] and give gone_row a separate field for the pin lookup. Otherwise, a line in the PR body saying reopen now prefers this id would cover it.

return {
"r": {"name": r["name"], "status": None, "children": [], "live": False, "state": "gone",
"cwd": r.get("cwd"), "sessionId": r.get("sessionId"), "last": r.get("last")},
"cwd": r.get("cwd"), "sessionId": sid, "last": r.get("last")},
"name": name, "persona": clean(sf["persona"]) if sf.get("persona") else None,
"stuck": None, "helper_stuck": [], "qs": [], "working": False, "busy_helpers": 0,
"quiet": None, "updated": upd if upd is not None else r.get("last"), "renamed_from": None,
Expand Down
10 changes: 7 additions & 3 deletions fleetwatch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ def sort_label(tab, current):
class Grouping:
"""Which group each top-level session is in, and the order groups are shown."""

def __init__(self, by_name, order):
self.by_name, self.order = dict(by_name), list(order)
def __init__(self, by_name, order, fallback=None):
self.by_name, self.order, self.fallback = dict(by_name), list(order), fallback

def of(self, name):
return self.by_name.get(name, OTHER)
# A session with no live row (only a status file) has no folder to match;
# `fallback` still applies the overrides pinned to its name.
if name in self.by_name:
return self.by_name[name]
return self.fallback(name) if self.fallback else OTHER

def present(self, names):
seen = {self.of(n) for n in names}
Expand Down
43 changes: 43 additions & 0 deletions tests/test_gone_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,49 @@ async def body(app, pilot):
self.assertEqual(len(calls), 1)
self.assertIn("resume %s --here" % s, calls[0][0])

def test_m_moves_a_session_that_is_not_running(self):
# Its only row is on Needs you and it has no live record. The move updates
# the pins a live move wrote (by name and by session id), the grouped board
# shows it in the chosen group, and moving it back to Other removes both.
from fleetwatch import config
s, _ = self.transcript("Gone Session")
self.gone(sessionId=s)
path = config.groups_path()
config.load_groups() # writes the default file
config.set_override(path, "Gone Session", "Work", session_id=s) # a pin from when it ran

async def body(app, pilot):
await pilot.press("G")
await pilot.pause(0.1)
app.current.move_to("needs:Gone Session")
self.assertNotIn("Gone Session", app.snapshot.records)
await pilot.press("m")
await pilot.pause(0.2)
self.assertEqual(type(app.screen).__name__, "GroupPicker")
picker = app.screen.query_one("#choices")
picker.highlighted = app.screen.names.index("Personal")
await pilot.press("enter")
await self.settle(pilot, lambda: "moved Gone Session to Personal" in (app.status_text or ""))
groups, _w = config.load_groups(create=False)
self.assertEqual(groups.overrides.get("Gone Session"), "Personal")
self.assertEqual(groups.override_ids.get(s), "Personal")
await self.settle(pilot, lambda: app.snapshot.grouping.of("Gone Session") == "Personal")
await self.settle(pilot, lambda: "needs:Gone Session" in app.current._order)
order = app.current._order
heads = [k for k in order[:order.index("needs:Gone Session")] if k.startswith("grp:")]
self.assertTrue(heads and heads[-1].endswith(":Personal"), heads)
app.current.move_to("needs:Gone Session")
await pilot.press("m")
await pilot.pause(0.2)
picker = app.screen.query_one("#choices")
picker.highlighted = app.screen.names.index("Other")
await pilot.press("enter")
await self.settle(pilot, lambda: "moved Gone Session to Other" in (app.status_text or ""))
groups, _w = config.load_groups(create=False)
self.assertNotIn("Gone Session", groups.overrides)
self.assertNotIn(s, groups.override_ids)
self.drive_needs(body)

def test_escape_calls_nothing(self):
s, _ = self.transcript("Gone Session")
self.gone(sessionId=s)
Expand Down
Loading