refactor: extract sessionlog package to unify session log path resolution#507
Merged
Conversation
…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.
7609dd1 to
7813880
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extract a shared
internal/sessionlogpackage 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(), andsessionlog.EnsureDir().What changed
internal/sessionlogpackage withPath(),Mtime(),Read(),EnsureDir()LogDirFnandMtimeFnare exported for test overrides (same pattern asisTmuxAliveFn)sessionLogMtimeFnnow delegates tosessionlog.MtimeFn--rawmode usessessionlog.Read()instead of manualos.Opensessionlog.Path()andsessionlog.EnsureDir()sessionLogDirvariable from CLI peek tests (usessessionlog.LogDirFninstead)This is a follow-up to #506 (heartbeat removal) and does not depend on it being merged first — it builds on the same
sessionLogMtimeFnthat PR already introduced, just moving it to a shared package.