fix(ephemerals): don't cache empty ephemerals - #2174
Conversation
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2174 +/- ##
==========================================
+ Coverage 61.29% 61.42% +0.12%
==========================================
Files 164 164
Lines 20568 20572 +4
Branches 3575 3575
==========================================
+ Hits 12607 12636 +29
+ Misses 7089 7069 -20
+ Partials 872 867 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
aa10016 to
6707d24
Compare
|
I didn't add any test yet because I'm unsure where it should be added in the test suite, and how the test package should be created. A good candidate seemed to be in the TestContext class: rez/src/rez/tests/test_context.py Line 23 in aa10016 Also, the test requires a package with specific attributes, and I'm not sure if the package should be created inline in the test or stored somewhere under |
I would agree. The bug is about ephemerals being empty inside
IMHO ( @JeanChristopheMorinPerso might disagree), an inline-package created into a tempdir, resolving against it, and checking the environ is preferable to a fixture under A few specifics to help guide you to a working test that tests what you want it to test:
I would also advise a second test that goes without the late-function as a control, which should also see the ephemeral, but is what proves the fix doesn't break the normal path while demonstrating that the late function was the trigger for the bug. |
maxnbk
left a comment
There was a problem hiding this comment.
I am just marking this "Request Changes" so that review can be re-requested when updates are made, so that I'll see it again.
FYI @maxnbk I'm usually in the camp of "no test data file and everything must be inline with the test to easily see what's being tested". Though, I know that this can sometimes incur some costs, but I don't think there's any costs involved here. |
6707d24 to
10a0a8b
Compare
|
Hi, and thanks for your answers! I'm resuming work on this and just added the test case, is there anything else worth adding (CHANGELOG.md maybe, or is that an automatic process) ? EDIT: sorry for the multiple force-push, I fixed a formatting issue, updated the tests to take your suggestions into account, and signed-off the commits. |
3f7e4c5 to
d71f08a
Compare
This commit adds a test case to catch a bug in the `ephemerals` binding. This binding should contain the list of ephemerals passed to the command line, as well as any ephemeral package found during resolution. A recent change to how `ephemeral` was bound introduced an edge case where the list was initialized empty _and cached_, but never updated during the resolution. This regression is caught by this test, and should be fixed in an upcoming commit. Signed-off-by: Aphosis <aphosis.github@gmail.com>
d71f08a to
daff438
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression where the ephemerals binding could become permanently empty in commands() when a late-bound function caused ephemerals to be evaluated (and cached) before resolution completed. It adjusts how ephemerals is bound so command execution always sees the resolved ephemerals, and adds tests covering the regression scenario described in #2173.
Changes:
- Stop caching
ephemeralsas part ofResolvedContextpre-resolve bindings; bind it later fromresolved_ephemerals. - Ensure late-bound function evaluation gets an
ephemeralsobject based on the context when available. - Add regression tests ensuring
commands()observes ephemerals both with and without a late function.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/rez/tests/test_context.py | Adds regression tests that validate ephemerals is visible in commands() even when late functions run during solve. |
| src/rez/resolved_context.py | Moves ephemerals out of cached pre-resolve bindings and binds it later from the resolved context. |
| src/rez/packages.py | Sets up ephemerals for late-bound function evaluation depending on whether a context is available. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ephemerals were initially exposed to package commands as an `ephemerals` binding. Since dcf77a2, they are also exposed to late-bound functions using the same strategy: reusing the existing list of resolved ephemerals. The issue lies in the difference in timing between late-bound functions and package commands: - Package commands are executed after the context have been resolved, so we get a properly resolved list of ephemerals - Late-bound functions are executed _during_ a solve, which means we don't have access to the resolved ephemerals yet The previous implementation did not crash when accessing `ephemerals` in late-bound functions: instead, it defaulted to an empty list. This behavior leads to a second issue: ephemerals were added and **cached** as part of the list of pre-resolve bindings. This can lead to the following scenario: - A package late-bound function accesses the `ephemerals` binding - Since the context is not resolve yet, no resolved ephemerals is found and an empty list is returned and cached - Later, in the package commands, we also access `ephemerals` - The cached empty list is returned, meaning that most queries will likely fail This commit addresses these issues the following way: - Move `ephemerals` out of pre-resolve bindings for commands, so that they are always retrieved from the resolved context - For late-bound functions, use resolved ephemerals only if a context is available Signed-off-by: Aphosis <aphosis.github@gmail.com>
aa87ecf to
52ba3b0
Compare
Closes #2173
Ephemerals were initially exposed to package commands as an
ephemeralsbinding.Since dcf77a2, they are also exposed to late-bound functions using the same strategy: reusing the existing list of resolved ephemerals.
The issue lies in the difference in timing between late-bound functions and package commands:
The previous implementation did not crash when accessing
ephemeralsin late-bound functions: instead, it defaulted to an empty list.This behavior leads to a second issue: ephemerals were added and cached as part of the list of pre-resolve bindings.
This can lead to the following scenario:
ephemeralsbindingephemeralsThis commit addresses these issues the following way:
ephemeralsout of pre-resolve bindings for commands, so that they are always retrieved from the resolved context