Skip to content

Conversation

@mayagbarnes
Copy link
Collaborator

@mayagbarnes mayagbarnes commented May 25, 2023

📚 Description

Refactor our withHostCommunication HOC into a HostCommunicationManager class in an effort to simplify the current code & future extension.

Tech Spec: link

  • What kind of change does this PR introduce?
    • Refactoring

🧪 Testing Done

  • Added/Updated unit tests
  • Added/Updated e2e tests

@streamlit streamlit deleted a comment from sfc-gh-mbarnes May 26, 2023
@mayagbarnes mayagbarnes marked this pull request as ready for review May 30, 2023 17:49
@mayagbarnes
Copy link
Collaborator Author

mayagbarnes commented May 30, 2023

Notes on outstanding/followup items:

  • Explored some avenues to convert our hostComm manual testing setup (hostframe.html) to automated e2e tests and have it working, but going to separate that into another mini project since it will require adjustments to allowedOrigins and want to run that by security
  • Noticed that the CLOSE_MODAL host message works on all the MainMenu items with the exception of the screencast modal - not a result of this PR, its also the case on develop - just want to confirm this isn't an intentional exception?

@tconkling tconkling self-requested a review May 30, 2023 22:10
Copy link
Contributor

@tconkling tconkling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really fantastic. Most of my feedback is just nitpicking, but there are a few correctness issues I want to make sure we nail before merging.

(Also I think it's probably worth having @vdonato and/or @lukasmasuch give a second review afterwards, to make sure I didn't miss anything important.)

/**
* Register a function to handle a message from the Host
*/
public receiveHostMessage = (event: MessageEvent): void => {

Check warning

Code scanning / CodeQL

Missing origin verification in `postMessage` handler

Postmessage handler has no origin check.
@tconkling tconkling self-requested a review May 31, 2023 23:16
Copy link
Contributor

@tconkling tconkling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a few unimplemented test stubs that should be filled in before merging.

I also left some questions about some App.test.tsx tests that seem to have been removed, but it's quite likely they're made obsolete with these changes? Just want to verify.

(And I also noted a bunch of tests that were just rearranged in App.test.tsx - these are just notes to myself for future reviews, so that I don't go looking for them again. No need to respond to those ones!)

currentPageScriptHash: "hash1",
})
})
it("plumbs appPages and currentPageScriptHash to the AppView component", () => {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this test go?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake - added back 👍🏼

})
})

it("responds to page change requests", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this covered elsewhere?

Copy link
Collaborator Author

@mayagbarnes mayagbarnes May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! this test forces update to HostCom HOC state (same thing as receiving REQUEST_PAGE_CHANGE message from host) to test onPageChange firing. This logic has moved to HostCommMgr -> the parallel test is on line 165 of HostCommunicationManager.test.tsx here

expect(onModalReset).toBeCalled()
})

it("changes scriptRunState and fires withHostCommunication callback when scriptStopRequested signal has been received", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test obsolete?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, these are part of that loop pattern we eliminated and this callback firing is tested in HostCommunicationManager instead.

onClose: () => {},
})

it("changes scriptRunState and fires withHostCommunication callback when scriptRerunRequested signal has been received", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test obsolete? (I think the answer is yes, just noting where I see a test removal so I don't accidentally re-review tests that we expect to be removed.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! Ditto to above

"stopScript"
)

it("fires withHostCommunication callback when cacheClearRequested signal has been received", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verifying this is intended to be removed

})
)

it("updates state.appPages when it receives a PagesChanged msg", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Tim note: test was moved)

expect(instance.clearAppState).not.toHaveBeenCalled()
})

it("sets hideSidebarNav based on the server config option and host setting", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Tim note: test was moved)

expect(wrapper.find("DeployButton")).toHaveLength(0)
})

it("button should be hidden for cloud environment", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this test go?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was moved to line 591 - title Deploy button should be hidden for cloud environment


expect(wrapper.instance().openClearCacheDialog).not.toBeCalled()
})
it("Tests dev menu shortcuts cannot be accessed as a viewer", () => {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added back!

Copy link
Contributor

@tconkling tconkling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a few unimplemented test stubs that should be filled in before merging.

I also left some questions about some App.test.tsx tests that seem to have been removed, but it's quite likely they're made obsolete with these changes? Just want to verify.

(And I also noted a bunch of tests that were just rearranged in App.test.tsx - these are just notes to myself for future reviews, so that I don't go looking for them again. No need to respond to those ones!)

Copy link
Collaborator

@vdonato vdonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this LGTM!

I left some comments, but they're more or less a bunch of nits / small things (and a good number of them seem to overlap with Tim's recent review so may be outdated now). I don't think I have any concerns about the overall approach here / things look more or less like I would have guessed

@vdonato
Copy link
Collaborator

vdonato commented Jun 1, 2023

Another thing that I think needs to be done (possibly even after a merge to develop assuming the release timeline doesn't mean that we'd immediately release this before thorough testing can be finished) would be to take some very thorough testing passes on Community Cloud, etc, potentially with the help of the QA team

Not sure how much we can fully test auth-token related things, but I have a small toy app that I used to test those changes locally that I can clean up and send your way with instructions tomorrow

@mayagbarnes mayagbarnes added the security-assessment-completed Security assessment has been completed for PR label Jun 1, 2023
Copy link
Contributor

@tconkling tconkling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff!

@mayagbarnes mayagbarnes merged commit 8750679 into develop Jun 2, 2023
@mayagbarnes mayagbarnes deleted the feature/host-com branch June 2, 2023 22:09
tconkling added a commit to tconkling/streamlit that referenced this pull request Jun 6, 2023
* develop:
  Remove tensorflow and pytorch from test requirements (streamlit#6807)
  Fix readme links (streamlit#6800)
  Update PR template to be simpler and more approachable (streamlit#6679)
  README updated with links to docs (streamlit#6780)
  Refactor: withHostCommunication -> HostCommunicationManager (streamlit#6746)
  Add python 3.11 to classifiers list. (streamlit#6786)
  Release/1.23.1 (streamlit#6777)
  We depend on typing-extensions 4.0.1 (streamlit#6776)
  Release/1.23.0 (streamlit#6773)
  Fix typo in data_editor docstring and deprecation msg: `edited_rows` -> `edited_cells` (streamlit#6770)
  Fix: Remove flaky date input calendar snapshot test (streamlit#6769)
  Fix 3218, patch pydantic in_ipython function (streamlit#6664)
  Upgrade react-range to fix memory usage of sliders (streamlit#6764)
  Make st.write pretty-print dataclasses using st.help (streamlit#6750)
  Replace curly with straightquotes in docstring examples (streamlit#6757)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants