Skip to content

refactor: extract sessionlog package to unify session log path resolution#507

Merged
MichielDean merged 1 commit into
mainfrom
extract-sessionlog-package
May 11, 2026
Merged

refactor: extract sessionlog package to unify session log path resolution#507
MichielDean merged 1 commit into
mainfrom
extract-sessionlog-package

Conversation

@MichielDean
Copy link
Copy Markdown
Owner

Summary

Extract a shared internal/sessionlog package so the session log path (~/.cistern/session-logs/<id>.log) is resolved in one place instead of three.

Before: Hard-coded filepath.Join(home, ".cistern", "session-logs", id+".log") in:

  • internal/cataractae/session.go — spawn (writes the log)
  • internal/castellarius/scheduler.go — liveness (reads mtime)
  • cmd/ct/cistern.go — peek --raw (reads content)

After: All three use sessionlog.Path(), sessionlog.Mtime(), sessionlog.Read(), and sessionlog.EnsureDir().

What changed

  • New internal/sessionlog package with Path(), Mtime(), Read(), EnsureDir()
  • LogDirFn and MtimeFn are exported for test overrides (same pattern as isTmuxAliveFn)
  • Scheduler's sessionLogMtimeFn now delegates to sessionlog.MtimeFn
  • CLI peek's --raw mode uses sessionlog.Read() instead of manual os.Open
  • Cataractae spawn uses sessionlog.Path() and sessionlog.EnsureDir()
  • 6 unit tests for the new package
  • Removed sessionLogDir variable from CLI peek tests (uses sessionlog.LogDirFn instead)

This is a follow-up to #506 (heartbeat removal) and does not depend on it being merged first — it builds on the same sessionLogMtimeFn that PR already introduced, just moving it to a shared package.

…tion

The session log path (~/.cistern/session-logs/<id>.log) was resolved in
three separate places with hard-coded strings:
- internal/cataractae/session.go (spawn — writes the log)
- internal/castellarius/scheduler.go (liveness — reads mtime)
- cmd/ct/cistern.go (peek --raw — reads content)

This extracts a shared internal/sessionlog package with Path(), Mtime(),
Read(), and EnsureDir(). All three consumers now use the same path
resolution. Tests override sessionlog.MtimeFn and sessionlog.LogDirFn
instead of package-level function variables.

This also removes the sessionLogDir override variable from the CLI peek
command in favor of sessionlog.LogDirFn, and removes the inline
sessionLogMtimeFn closure from scheduler.go in favor of delegating
to sessionlog.MtimeFn.
@MichielDean MichielDean force-pushed the extract-sessionlog-package branch from 7609dd1 to 7813880 Compare May 11, 2026 22:08
@MichielDean MichielDean merged commit 18c8654 into main May 11, 2026
3 checks passed
@MichielDean MichielDean deleted the extract-sessionlog-package branch May 11, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant