crates/sessions: new crate for session primitives + lifecycle hooks primitive - #230
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR introduces a new ChangesSession Primitives
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
| /// Script body stored inline. | ||
| Inline(String), | ||
| /// Path to a script file on disk. | ||
| External(PathBuf), |
There was a problem hiding this comment.
Over the time of building minimal Ive started to dislike PathBuf, because it leads to confusion/invariants/bugs based on:
- Is this a path relative to the user system, the sandbox fs, or the minimald (in the future) ?
- Is this meant to be interpreted relative to the cwd, if so which of the above contexts?
- More of a grumble, but if you join an absolute path with cwd, it overwrites with the absolute path. I can feel a bug coming from this one day (i.e. if a user specifies an absolute path in the config).
Not sure what the fix is here, but we may want some newtype around paths. Food for thought.
There was a problem hiding this comment.
Yeah, newtypes sound like the right way to go here. I'm using them for paths in the patches stuff I'm working on, where it becomes even more important to keep track of this stuff.
There was a problem hiding this comment.
Actually, they're probably not strictly newtypes as they'll probably need to contain a bit more context in some cases.
|
|
||
| impl std::error::Error for Error {} | ||
|
|
||
| /// A script executed by a lifecycle hook. |
There was a problem hiding this comment.
Whats the constraints aroud what a valid script is? Do we want to just say 'bash v4 or greater compatible?' (I would say POSIX shell except everyone ignores when thats the constraint and uses modern features lol)
There was a problem hiding this comment.
I think it depends on exactly when these run. If it's something like:
Install packages -> Activate Hook -> ... -> Destroy Hook -> Packages are gone
!!! -> Failure Hook -> Destroy Hook -> Packages are Gone
Then we don't really need to constrain it. It could be fish, python, ruby, whatever you want as long as you have the package to run it. Just put in the right shebang.
If they're run when you don't have your packages available then I think some specific version of bash (as long as we can grantee that's available) makes sense.
There was a problem hiding this comment.
Hmmm, at this stage i realize im not fully sure what the context is for lifecycle hooks. Are these basically just activation scripts for a session?
If theres one activation script then it makes sense to have a configurable shell like bash/fish etc. But if we are composing multiple scripts we need the env vars that get exported in one + the background tasks/jobs that get run to stay alive as all the activation scripts run (i.e. Karl's use case of launching postgres, we dont want postgres to die when the activation script finishes), in which case what shell is chosen for interpreting all those scripts?
There was a problem hiding this comment.
Ah, right. In that case I think we just do bash unless we have a good reason not to. I don't think that needs to be encoded here though.
|
Going to merge this now. I've been playing around with more contextful path types a bit, but I don't see much harm in just switching this to them later. |
Adds a
sessionslibrary crate with two types:LifecycleHook— three optional script slots (on_activate,on_destroy,on_failure), at least one required. Invariant enforced in the builder and reused on the serde path viatry_from/into.HookScript— adjacently tagged:{ type = "inline" | "external", value = "..." }.Loadout— stub for now; will grow asminimal2/minimaldneed it.Pedantic clippy on; tests + doctests cover the invariant and serde round-trip.
Summary by CodeRabbit
Release Notes