Repository navigation
fix(cloud): push project libraries when using --push in cloud commands - #725
pcbeingused333 wants to merge 4 commits into
Conversation
|
Thanks @pcbeingused333. Your fix commit is cherry-picked, with your authorship, into #749. That PR adapts the test to the current resolver, which now follows a project directory renamed by the push (#734), and adds tests that run the real push path for a changed library and for a failed library upload. |
…cloud copy A library the user can only read rejects every projects.update, so --push on cloud backtest/optimize/live deploy failed for projects referencing one even when the library had no local changes. Libraries whose files and metadata already match the cloud copy are now left alone; a changed library that fails to upload still stops the command.
…d push The cloud commands now push through PushManager.push_project, the same path as `lean cloud push`: a referenced library that cannot be pushed only gets a warning, and only a failed push of the project itself stops the command. push_project returns whether the project was pushed. The check that skips libraries already matching their cloud copy now leaves out the files of the library's own libraries, which files/read lists with the library's files, and accepts a local file that is what `lean cloud pull` wrote for the cloud copy (unix line endings and a final newline). Pull's conversion moves into get_pulled_file_content so both use the same code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8913a6f to
7b53b71
Compare
|
Thanks for this fix. I rebased the branch on master (which now includes #687) and added a commit (7b53b71) with the decision on the open question from #749, about libraries the user can only read:
New tests in
Each of the skip and warning tests fails when its fix is reverted. Full suite: 2949 passed, 75 skipped, 0 failed. |
There was a problem hiding this comment.
Requesting changes: the code looks right, but the change has no end-to-end run yet, and the tests don't check the case where the library check gets it wrong.
What I checked. Both --push branches of get_cloud_project now go through push_project, the same as lean cloud push --project. A library that can't be pushed only gets a warning, and only a failed push of the project itself stops the command, as decided on #749. CI is green. I checked the skip against real API responses, using the released CLI and my own script. I don't run code from pull requests by outside contributors. Two libraries match their cloud copy on name, libraries, metadata and files, so both would be skipped: one the CLI pushed, and one created in the cloud and then pulled (CRLF, no final newline). files/read lists a nested library's Library.py under the same name with isLibrary set, so filtering those files out is needed.
1. No end-to-end run. The description has only mocked tests, but both the skip and the warning depend on the real API. Please run these and put the outcomes in the description:
lean cloud backtest <project> --pushwith an unchanged library: the library isn't updated, and the backtest runs.- The same with a changed library: the library is pushed before the project, and the backtest runs the new library code.
- The same with a changed library whose push fails: a warning, and the command goes on.
2. Tests skip the case that does harm. If the check wrongly treats a changed library as unchanged, the cloud runs the old library code with no warning. Of the things that must force a push, the tests only cover changed file content. Please add tests where the files match but something else differs, such as a local file added or deleted, a changed library reference, or a changed description. Also, test_get_cloud_project_push_warns_and_continues_when_changed_library_cannot_be_pushed doesn't assert that the warning is logged.
I set risk:high: the change alters what lean cloud push --project and every --push command write to the cloud for each referenced library, and there's no end-to-end run yet. The run above and the tests in item 2 are what would lower it.
…nged Covers each check that must force a library push even though its files match the cloud copy: a local file added or deleted, a library reference removed, and a changed description or parameters. The warning test now asserts the warning for the library that could not be pushed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. Both points are addressed in 5c106f1 and the description. 1. End-to-end run. I ran it from this branch against the real API. The full table is in the description's "End-to-end" section:
One limit: the account I used has a single user, so I couldn't get a real read-only share. I made the library push fail locally instead, by marking the library 2. Tests for a wrong skip. New
I removed each part of the check in |
There was a problem hiding this comment.
Approving: both findings from my last review are resolved, and CI is green.
- End-to-end run: the description now covers an unchanged library (skipped, and the backtest runs), a library in the form a pull writes (skipped), a changed library (pushed before the project, and the backtest runs the new code), and a library push that fails (a warning, the project is still pushed, and the command goes on). A real read-only refusal wasn't reproduced. That's fine: the skip returns before any write request, and a refused update goes through the same
exceptin_push_projectsas the forced failure. - Tests for a wrong skip:
test_get_cloud_project_push_pushes_library_whose_files_match_when_something_else_changedcovers a file added, a file deleted, a library reference removed, a changed description and changed parameters. Each case needs its own part of_is_cloud_project_up_to_date. The warning test now asserts the exact warning.
I changed the label from risk:high to risk:low. The change is small and easy to revert: about 70 lines in PushManager, CloudProjectManager and pull_manager. --push now pushes the way lean cloud push --project already does. The evidence is tests that run the real push path for every skip and push case, green CI, and an end-to-end run against the API.
There was a problem hiding this comment.
Requesting changes before merging:
- Keep implicit library sync from changing cloud encryption, and make the comparison read-only. The comparison should fetch only the library’s own files and recognize byte-identical CRLF files without a final newline.
- Keep a library failure from breaking an otherwise valid project push. I verified that the base resolver uploads the project with the existing library ID when the library is symlinked outside the workspace or has an invalid nested reference. The new path can abort before the project update. I also reproduced a refused library update after a local rename: the directory is moved but the reference still points to the old path, so the project fails too.
- Verify removal of the last nested reference. The new test observes
libraries=[]at the mock, but that field is missing on the wire. The cloud keeps the removed reference.
@Martin-Molinero Decision needed: Should --push stop before compiling when a library upload has already modified some cloud files?
The agreed warning-only behavior works for a refused write that leaves the library intact. The existing file-by-file fallback can also succeed on one file and fail on the next; the new path logs the warning and can continue into a backtest or live deploy with mixed library code.
- A. Stop on a known partial upload (recommended): continue after refusals that didn't change the library, but don't run against a known partial upload. Distinguish those outcomes and test both.
- B. Continue after either outcome: keep exact
lean cloud pushparity, but document that a run can use mixed library code and test that behavior explicitly.
Reply with the option you choose, or another way to go.
risk:high: this can change a library’s encryption or leave a cloud run using a partially uploaded dependency. The end-to-end results in the description cover the normal sync path and a failure before any write; they don't cover these cases. Please include regression tests and report the end-to-end outcome for a write refusal and for the chosen partial-upload behavior.
| encryption_key_id = get_project_key_hash(encryption_key) | ||
| update_args["encryption_key"] = encryption_key_id | ||
|
|
||
| if skip_if_unchanged and self._is_cloud_project_up_to_date(cloud_project, update_args, expected_correct_project_name): |
There was a problem hiding this comment.
Please preserve the cloud library’s encryption state on an implicit push, even when the local copy differs. If it can’t be uploaded in that state, warn and leave the library untouched. Add a regression test for an encrypted cloud library with a differently configured local copy, asserting that no library write is sent.
|
|
||
| try: | ||
| # Library files come with their own names, and belong to the project's libraries, not to the project | ||
| cloud_files = {file.name: file.content for file in self._api_client.files.get_all(cloud_project.projectId) |
There was a problem hiding this comment.
Please use a non-mutating listing scoped to this library’s own files. files/read includes transitive files by default; dropping them after the response still downloads 55 library file sets for a chain of 10 unchanged libraries, instead of 10. Send includeLibraries=false for this comparison, and verify that the read leaves cloud files untouched.
|
|
||
| # A file is unchanged when it is the one pushed, or the one a pull of the cloud copy wrote | ||
| from lean.components.cloud.pull_manager import get_pulled_file_content | ||
| return all(content in (cloud_files[name], get_pulled_file_content(cloud_files[name])) |
There was a problem hiding this comment.
An unchanged file with identical # first\r\n# second bytes on both sides still triggers an update. Path.read_text() converts the local CRLF to LF without adding a final newline, so it matches neither raw cloud content nor the pull form (which adds a newline). Compare the cloud content using universal newlines before also checking the pull form, and test this exact-copy case.
| """ | ||
| libraries = self._project_manager.get_project_libraries(project) | ||
| self.push_projects([project], libraries, encryption_action, encryption_key, force) | ||
| return project not in self._push_projects([project], libraries, encryption_action, encryption_key, force) |
There was a problem hiding this comment.
Treat errors in dependency discovery and path formatting as library warnings when the main project can still resolve its references. A library with a valid cloud ID but a malformed nested reference raises during get_project_libraries() before the handler; a library symlinked outside the workspace raises at relative_to() before the handler too. The base resolver can push the main project in both cases. Keep per-library discovery errors isolated and use an absolute path fallback for logging.
| self._logger.info(f"[{index}/{len(all_projects_to_push)}] Pushing '{relative_path}'") | ||
| # A library whose cloud copy already matches the local one needs no update, so it is not | ||
| # rejected when the user can only read it. | ||
| self.pushed_project_paths[path] = self._push_project(path, organization_id, encryption_action_value, |
There was a problem hiding this comment.
The new path is recorded only after _push_project returns. With local Library/Café pointing to an existing read-only cloud library, the local rename to Library/Caf happens first. The rejected library write leaves the project config pointing at the missing Library/Café; the main push then fails reading its cloud ID. Record the move even when the cloud update fails, or roll it back, and test refused updates after a rename.
| # a changed description | ||
| lambda path, cloud: _set_library_config(path, "description", "A changed description"), | ||
| # changed parameters | ||
| lambda path, cloud: _set_library_config(path, "parameters", {"period": "10"}), |
There was a problem hiding this comment.
This removes the only nested reference. ProjectClient.update puts libraries=[] into form data, but requests omits empty lists and the API only reconciles libraries when that field is present. So the mock sees a push while the old reference remains. Please make removal of the last reference persist and cover it at the request boundary, not just by asserting the library project ID was updated.
Fixes #719
lean cloud backtest/optimize/live deploy <project> --pushresolve the project throughCloudProjectManager.get_cloud_project, which pushed only the project and not the libraries it references. So the cloud compiled and ran the project against the libraries' older cloud code.lean cloud pushdoesn't have this problem, becausePushManager.push_projectpushes the project's libraries too.Change
--pushnow pushes likelean cloud push. Both push branches ofget_cloud_project(a local project directory, and a cloud name or id resolved to a local directory) callPushManager.push_project, the same methodlean cloud pushuses. It pushes the project's libraries, nested ones included, before the project. As inlean cloud push, a library that can't be pushed gets a warning and the command goes on. Only a failed push of the project itself raisesPushFailedErrorand stops the command before it compiles.push_projectnow returns whether the project was pushed.push_projectsis unchanged.Libraries that already match their cloud copy are not updated. Every push sends
projects/update, which the cloud refuses from a user who can't write to the project, for example a library shared read-only or locked by another collaborator. Before updating a library,PushManagernow compares its name, libraries, other metadata and files with the cloud copy, and leaves the library alone when nothing would change. An unchanged library the user can only read therefore no longer warns or fails. The file comparison:files/readlists with the library's files (isLibrary)lean cloud pullwrites for the cloud copy (unix line endings and a final newline). Pull's conversion moved intoget_pulled_file_contentinpull_manager.py, so pull and this check use the same code.A library with any change, or with an encryption key, is always pushed. The check also applies to
lean cloud push.Known limitation, same as
lean cloud push: if a library has local changes the user can't push, the command warns and the cloud runs with the library's current cloud code.Tests
tests/components/cloud/test_cloud_project_manager.py, through the real push path with a mocked API:Cannot pushwarning, and the project is still pushedPushFailedErrorThe existing
get_cloud_projectpush tests now assert thepush_projectcall. Each test above fails when the check it covers is removed. Full suite: 2954 passed, 75 skipped, 0 failed.static_analysis.pypasses.End-to-end
Run from this branch against the real API. A Python project
LeanCli725E2Ereferences the Python libraryLibrary/LeanCli725E2ELib, whoseVERSIONthe algorithm reports as a runtime statistic. Both were pushed once withlean cloud push, then:lean cloud backtest LeanCli725E2E --pushv1)'Library/LeanCli725E2ELib' is already up to date in the cloud, not pushing it, project pushed, backtest completed withLibrary Version: v1lean cloud pulllean cloud push --project LeanCli725E2Eskipped the library as up to date, and the cloud file kept its web IDE formv2[1/2]library updated,[2/2]project updated, backtest completed withLibrary Version: v2v3, push failsCannot push 'Library\LeanCli725E2ELib': ...warning, project still pushed, exit code 0, backtest completed withLibrary Version: v2, the library's cloud codeIn run 3 the library push was made to fail locally, by marking the library
encryptedwithout a key, which the CLI refuses before any request. The account used has a single user, so a cloud refusal of a read-only library wasn't reproduced. Both go through the sameexceptinPushManager. The throwaway projects were deleted afterwards.Supersedes #749.
This change was prepared with the help of an AI assistant (Claude), and the submitter is responsible for it.
🤖 Generated with Claude Code