Fix: include sub-app Towerfiles in packages#220
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
crates/tower-package/src/lib.rs
Outdated
| } | ||
|
|
||
| async fn resolve_path(path: &PathBuf, base_dir: &Path, file_paths: &mut HashMap<PathBuf, PathBuf>) { | ||
| async fn resolve_path(path: &PathBuf, base_dir: &Path, file_paths: &mut HashMap<PathBuf, PathBuf>, exclude_path: Option<&Path>) { |
There was a problem hiding this comment.
I feel it really doesn't make sense to pass in exclude_path and change all the call sites of this function just to exclude the root towerfile because
- Calling a function called
should_ignore_filethen literally passing in a path to ignore feels like a weird separation of concerns where you both want it to tell you whether you should ignore a file, but you also happen to know what one file you should ignore in advance is called - There's only one
exclude_path, which makes sense since there's only one path we care to remove atm (i.e. the baseTowerfile) but the name suggests like it should be some kinda generic thing, so it's weird to be singular (or weird to be generic) - We're already passing in
base_dirhere which is derived data from the path of the Towerfile, so we could do something likebase_dir.join("Towerfile")instead
Also, not sure why it's Option<>, since presumably we'll always have a base Towerfile?
6acf00f to
13ab0c7
Compare
|
Good call @socksy — threading |
6e2f77c to
5fe3d05
Compare
Previously, should_ignore excluded every file named 'Towerfile' from the package. This broke apps that contain sub-apps with their own Towerfiles, since those files were silently dropped. The fix introduces FileResolver, a struct that owns the base_dir and the root Towerfile path, and uses it to make all resolution decisions. Only the exact Towerfile used to build the package is excluded; any Towerfile living in a sub-directory is included as normal app content. Changes: - FileResolver struct owns base_dir and root_towerfile - Resolution logic lives on FileResolver as async methods (resolve_glob, resolve_path) rather than standalone free functions - should_ignore compares by path identity, not by file name - Package::build canonicalizes spec.towerfile_path and delegates to FileResolver for both the glob loop and the import-path loop - New integration test it_includes_subapp_towerfiles_but_excludes_root_towerfile verifies the exact scenario described above
5fe3d05 to
9e49e97
Compare
Problem
Packages containing sub-apps with their own
Towerfiles were broken:should_ignore_filematched any file namedTowerfileand dropped it from the package, not just the root one used to drive the build.Solution
Thread the specific
Towerfilepath through the packaging pipeline so only that exact file is excluded. Towerfiles in sub-directories are now treated as ordinary app content.What changed:
should_ignore_filenow acceptsOption<&Path>(the exact file to exclude) instead of matching by name aloneresolve_pathandresolve_glob_pathaccept and forward the sameOption<&Path>Package::buildcanonicalizesspec.towerfile_pathand passes it through both the glob loop and the import-path loopTests:
it_includes_subapp_towerfiles_but_excludes_root_towerfileverifies that given a layout like:main.py,subapp/Towerfile, andsubapp/main.py, but not the rootTowerfileunderapp/.