Repository navigation
Point a project at a library its push renamed - #760
Conversation
When a push renames a referenced library's directory to a valid name, the projects pushed after it in the same batch now update their reference to the new directory, so they upload with the library's cloud id instead of failing on the missing old path. Closes #741 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Approving. When the push renames a library, the projects and libraries pushed after it in the same batch now follow it to its new directory. The rewritten reference uses the same name/path form that lean library add writes, and the path is resolved against the working directory, as the rest of the push already does. The lookup keys line up: get_project_libraries and this method both build them with .expanduser().resolve(). A library that references a renamed library is fixed the same way, because libraries are pushed dependency-first. I ran the new test locally: it fails with master's push_manager.py and passes with this change. The full test_push_manager.py passes too.
The description's limits are fair, and none of them is worse than on master: a project pushed before its library in a lean cloud push of all projects, and the .csproj references.
Label risk:low: a small, easily reverted change that only acts when a library was renamed in the same push, which failed before. It has a regression test that fails without it, an end-to-end run, and green CI.
There was a problem hiding this comment.
Requesting changes for the C# reference inconsistency below: persisting the renamed path makes a previously working lean library add repair stop working.
The Python path passed end to end, including a second push and verification of the cloud library link. The focused tests passed (80 passed, 3 skipped). The full suite reproduced the description's installed-version mismatch (2,891 passed, 81 skipped, 1 failed), which also occurs with the base implementation.
Setting risk:high: the change removes a working C# recovery path and leaves local builds broken after re-adding the library. C# regression coverage is needed alongside the Python test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Approving e84db5c. It fixes the C# finding from the earlier review: after the push renames a library, the project's config.json and its .csproj ProjectReference now both point to the renamed library. A later lean library add of that library therefore finds it already referenced in both places, and the project still builds.
What I checked:
- The
.csprojis rewritten only for a reference that points inside the library's old directory, and only when that library was renamed in this push. A Python project, or a library without a.csproj, is left unchanged..csprojfiles are not uploaded, so it doesn't matter that the files are collected before the rewrite. - The new C# test passes. With the
update_csharp_library_referencecall removed it fails, and the rest oftest_push_manager.pystill passes. - I ran the push with the real managers and a mocked API on a C# project that uses a type from a C# library in
Library/MyLib.. After the push, the config and the.csprojboth point toLibrary/MyLib, the cloud update carries the library's id, re-adding the library reports it already added and leaves a singleProjectReference, anddotnet buildsucceeds.
Label risk:low: a small, easily reverted change that acts only when the same push renamed a library, which failed before. It has regression tests for Python and C# that fail without it, end-to-end runs, and green CI.
Instead of rewriting the references it can interpret, which missed valid backslash-separated paths, the push now makes sure the project's .csproj references the renamed library's .csproj, as adding the library does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Requesting changes for one finding in 859b32f: the new ProjectManager.add_csharp_library_reference copies the reference-adding code that lean library add already has, instead of reusing it. Details inline.
Adding the reference instead of rewriting existing ones does fix the backslash case from the earlier review. The C# project's config and .csproj now agree whatever form the old Include had. I ran test_push_manager.py and the library command tests: they pass (90 passed, 3 skipped). With the new call removed from PushManager, both C# test cases fail. CI is green.
risk:high stays for now. Apart from this finding, the evidence supports risk:low: regression tests for Python and C# that fail without the fix, end-to-end runs, and green CI.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Approving 8831326. It resolves my last finding: the push now adds the renamed library's ProjectReference through LibraryManager.add_csharp_library_to_csproj. That method uses the same two helpers as lean library add (get_csharp_lean_library_path_for_csproj_file and _add_csharp_project_to_csproj), and the copy in ProjectManager is gone. The container builds LibraryManager before PushManager. For a Python project or library, the new method returns before it touches any file.
The push, library and cloud command tests pass (263 passed, 3 skipped). With the new call removed, both C# push tests fail.
Label risk:low: a small change that is easy to revert and only acts when the same push renamed a library, a case that failed before. Regression tests for Python and C# (forward-slash and backslash references) fail without it. The description has end-to-end runs, and CI is green.
There was a problem hiding this comment.
Approving. The earlier C# consistency finding is resolved for both slash styles: the push ensures the renamed library's ProjectReference through the existing library-add helpers.
Tested end to end for forward-slash and backslash references: the project builds before push, after push, after re-adding the library, and after a second push. The config and cloud library link are correct, and the second push renames nothing. The retained old reference produces a missing-project warning, as documented. Removing the replacement reference makes clean builds fail in both cases.
The focused push, library and cloud tests passed (263 passed, 3 skipped); disabling the new reference addition makes both C# regression tests fail. Static analysis passes.
risk:low: the earlier recovery-path regression is fixed, and this narrow, easily reverted change has regression coverage and end-to-end evidence.
Closes #741
What changed
PushManagerpushes a project's referenced libraries before the project. When a library's directory name isn't valid (for example it ends with a period, or contains a character such as:), the push renames the directory, but the project'sconfig.jsonkept the old path. Pushing the project then read the cloud id from the missing directory and failed withint() argument must be ... not 'NoneType'; every later push failed the same way and renamed the library again (to... 2)._get_local_libraries_cloud_idsnow looks up each referenced library inpushed_project_paths(where every project and library pushed earlier in the batch ended up). A reference to a library the push renamed is rewritten to the new directory, with the samename/pathformatlean library addwrites, and the project is uploaded with that library's cloud id. References to libraries that weren't renamed are left exactly as they are, and the config file is only written when a reference changed.For a C# project, the same rewrite also adds a
ProjectReferenceto the library's renamed.csprojto the project's.csprojunless it already has one, through the same helperlean library adduses to write that reference (LibraryManagergains a publicadd_csharp_library_to_csproj, andPushManagernow receives the container'sLibraryManager). So the config and the.csprojstay consistent: the project builds locally after the push, and a laterlean library addof the renamed library finds it already referenced in both. The.csproj's existing reference to the old directory is left as it is, aslean library addleaves it, whatever form its path takes (forward slashes or backslashes).Not changed here:
Tests
test_push_project_updates_reference_to_library_renamed_by_the_push: a Python project referencesLibrary/Unsafe:Lib; pushing the project renames the library toLibrary/Unsafe Lib, rewrites the project's reference to it, and updates the project in the cloud with the library's id. It fails onmaster(the reference keeps the old path) and passes with the change. Skipped on Windows, which can't create that directory.test_push_project_adds_csproj_reference_to_csharp_library_renamed_by_the_push, for a.csprojreference to the library written with forward slashes and with backslashes: the same for a C# project and library; the project's.csprojgains the reference../Library/Unsafe Lib/Unsafe Lib.csproj, and adding the renamed library again leaves the config and.csprojunchanged. Both cases fail without the.csprojupdate.python static_analysis.py: passes.python -m pytest -s -rs: 2893 passed, 81 skipped, 1 failed. The failure,tests/ui/test_app.py::test_command_process_runs_the_cli_as_a_child_process, compares against the installedleanpackage version in my environment ('lean 1.0.234' == 'lean 0.0.0-dev') and fails the same way onmaster.Tested end to end with a Python project referencing a Python library whose directory name ends with a period (
Library/MyLib.), runninglean cloud push --project <project>twice:master: the library was renamed toLibrary/MyLiband uploaded, then the project failed withCannot push '<project>': int() argument must be a string, a bytes-like object or a real number, not 'NoneType'; its reference still pointed atLibrary/MyLib.. The second push renamed the library again toLibrary/MyLib 2, and both failed.{"name": "MyLib", "path": "Library/MyLib"}, and the cloud project lists the library. The second push updated both without renaming anything.Also tested end to end with a C# project referencing a C# library (
Library/CsLib.) whose class the project uses: afterlean cloud push --project <project>, the config and.csprojboth point toLibrary/CsLib,dotnet buildsucceeds,lean library add <project> Library/CsLib --no-localreports it already added and the build still succeeds, and a second push renames nothing.The C# end-to-end runs were on the previous commit, whose own copy of the reference-adding code wrote the same
Include(../Library/CsLib/CsLib.csproj) that the shared helper writes now; the C# unit test checks that exact reference.The same with the project's
.csprojreferencing the library with a backslash path (..\Library\CsLib.\CsLib..csproj), which builds before the push: after the push the config points toLibrary/CsLib, the.csprojalso references../Library/CsLib/CsLib.csproj, anddotnet buildsucceeds; re-adding the library reports it already added and the build still succeeds; a second push renames nothing and the project still builds.