Repository navigation
Human Confidence web example in client side and server side modes - #271
Draft
jwrosewell wants to merge 8 commits into
Draft
jwrosewell wants to merge 8 commits into
jwrosewell wants to merge 8 commits into
Conversation
The page shows HumanConfidenceSource and HumanConfidence in a table whose rows are in place from the start, each with a running timer until its level arrives, so nothing on the page moves. Client side, the browser loads the 51Degrees client script from the cloud and this server redeems the sealed result with the License Key. There is no passive row client side, because a passive result passed on by the browser could have been changed. Server side, the browser never calls the cloud. This server serves the client script with every cloud address pointed at itself and sends the calls on through the cloud request engine. The passive row comes from the visitor's request. A toggle reloads the page in the other mode, and the choice is kept in a cookie. Under the table are two curl commands that replay the passive data and the active data from a terminal, and a link to the Configurator. The third party cookie check in the client script is pointed at the cloud named in _51DEGREES_CLOUD_ENDPOINT, as it otherwise goes to the public cloud.
The page recorded the browser test answers only when they were sent to a 51degrees.com address, and server side only 51degrees.com addresses in the client script were pointed back at this server. With a private cloud, such as one in Docker at a localhost address, the active replay never filled, and server side the browser sent the test answers to its own machine. Both checks now take the host of the endpoint in use as well as the 51Degrees cloud hosts, and a call sent on to the endpoint's own host keeps the endpoint's scheme, so a plain http private cloud works.
The page redeemed every HumanConfidence value the 51Degrees script gave through fod.onChange. The first one comes before the browser tests have run and is a plain level, which the cloud can't open, so the redeem answered unreadable and the page showed Active Low. When the test answers then didn't arrive, or the page was left early, Low stayed on the page for tests that never ran. The page now redeems only a value that isn't a plain level (High, Medium, Low, or Unknown), so Active shows a level only once the tests have run and their result is sealed.
Now that only a sealed value is redeemed, a page whose test answers never reach the cloud waited for ever, with the Active timer running on. After 30 seconds with no sealed value the row now says No result. A sealed value that arrives later still replaces it.
After it starts, the Human Confidence web example writes nothing to the console. /redeem no longer prints each outcome, the web server no longer logs each request, and /hc/script.js answers 502 with an empty script when the cloud can't be reached, so the page shows Active Low. The cloud request engine is built with the example's 10 second timeout, its evidence keys give the headers passed on, and its answer is read under cloud-response. The address sent as client-ip is the connection's own, when it is a public one, and the replay command shows the form the engine sent. The start-up error shows the Resource Key as <Resource Key>, and the header comment says what redeeming needs and gives. The three test files now test the example as it is. 88 pass, and the 4 live tests skip with no keys set.
The web demo page showed Low for Unknown and for a passive call that gave no level. Unknown now shows as Unknown, in the neutral style. A passive answer that is not a level, a failed fetch, a client script that does not load and a failed redeem fetch show No result. A line under the table says that Active Low is also given when the sealed value cannot be redeemed. The /redeem route is unchanged, so a value that does not redeem still gives Low. At the 30 second limit the page shows No result only when no redeem is still running, so a redeem that is under way can still give its level. The live Basic key test no longer accepts an answer with no HumanConfidence. It asks the cloud whether the key carries the property. If it does, the passive answer must be a level. If it does not, the example must stop at start with the contact link. Offline tests run the live test against the stand-in cloud for a pass and a failure of each.
The /redeem route gave Low for every failure, so a cloud without the redeem call showed Active Low on every visit. Low is now given only when the cloud answers 200 or 400 with no level, which is how it refuses a sealed value. Any other answer, or none at all, gives no level, and the page shows No result, as the .NET and Rust examples do. The page also stops waiting for /redeem after 15 seconds. The comments, the start-up message and the line under the table say the same. The live Basic key test makes the passive call itself, naming HumanConfidence and HumanConfidenceSource, as the .NET and Rust live tests do. It expects humanconfidencesource to be present and null and humanconfidencesourcenullreason to be a string. The passive level test accepts only High, Medium and Low, also as in .NET and Rust. Offline tests run the Basic key test against the stand-in cloud.
This merge takes rc into the branch. Only tests/test_cloud_humanconfidence_web.py conflicted, where rc moved the HumanConfidenceSource tests to the staging cloud and the branch had changed the same tests. The two tests of the source are now marked staging and call the cloud CLOUD_STAGING_ENDPOINT names. The Bespoke test uses the key in RESOURCE_KEY_BESPOKE_STAGING. As /passive gives only a level, it reads HumanConfidenceSource from the cloud's recorded answer and expects Passive, and it checks the level and the address the example describes without printing the key. The Basic key test keeps the branch's direct call to the cloud. rc's own Basic key test, and the checks at the end of the file that read a source from the example, are gone. The fixture that names the two properties matches the address without its query, as the engine posts to <key>.json?, and records the cloud's answers. An offline test checks that both source tests carry the staging mark, so the Cloud Human Confidence workflow has tests to run.
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
The Human Confidence web example reworked as a demo, for work to continue on it.
?mode=client). The browser loads the 51Degrees client script from the cloud and this server redeems the sealed result with the License Key. Client side has no passive row, as the passive level is read by this server, so it is shown server side.?mode=server). The browser never calls the cloud. This server serves the client script with every cloud address pointed at itself and sends the calls on through the cloud request engine. The passive row comes from the visitor's request._51DEGREES_CLOUD_ENDPOINTby settingwindow.fodTpcEndpoint, because it otherwise goes to the public cloud.Files:
app.pyandtemplates/index.html.How to run it
Set
_51DEGREES_RESOURCE_KEYto a key that carries HumanConfidence and HumanConfidenceSource,_51DEGREES_LICENSE_KEYto a License Key on the same account, and_51DEGREES_CLOUD_ENDPOINTto a cloud that offers the redeem call (POST /api/v4/hc/redeem), which the public cloud does not offer yet. Then open http://localhost:5151/.How it was checked
By hand, against a cloud that offers the redeem call, in headless Edge.
_51DEGREES_CLOUD_ENDPOINTor to this server.Still to do
The redeem belongs in the package, not the example. The cloud request engine should redeem the sealed value itself and give HumanConfidence directly, so the example only reads HumanConfidenceSource and HumanConfidence. The
/redeemroute inapp.pyis the stand-in until then. FIX: Redeem a sealed Human Confidence value in the cloud request engine #274, opened against this branch, does this.The example's tests are in line with this version. Locally 101 pass and 4 skip. The 4 are the live tests, which need
_51DEGREES_RESOURCE_KEY_BESPOKEand_51DEGREES_RESOURCE_KEY_BASIC, and they were not run.No workflow runs these tests on a pull request that touches only the examples, so the checks here say nothing about them. Run them by hand from
pipeline/fiftyone_pipeline_cloudrequestengine/examples:Since 8357555
Two commits on top of 8357555.
The first:
The second:
/redeemgives Low only when the cloud answers 200 or 400 with no level, which is how it refuses a sealed value. An unreachable cloud, a timeout, any other status, or an answer that is not a JSON object gives no level, and the page shows No result, as the .NET and Rust pages do. Before, a cloud without the redeem call, which today includeshttps://cloud.51degrees.com/api/v4/, gave Active Low on every visit./redeemafter 15 seconds and shows No result.humanconfidencesourceto be present and null with a stringhumanconfidencesourcenullreason, as the .NET and Rust live tests do. The passive level test accepts only High, Medium and Low, also as they do.On Windows with Python 3.12, the three test files above give 101 passed and 4 skipped, where they gave 88 passed and 4 skipped at 8357555. The 4 are the live tests, which need keys. The page script was also run under Node with a stand-in page.
Since 4daa4eb
A merge of rc (6e5c98c). Only
tests/test_cloud_humanconfidence_web.pyconflicted.stagingand call the cloud thatCLOUD_STAGING_ENDPOINTnames, socloud-human-confidence.yml(pytest -m staging) runs both. The Bespoke test usesRESOURCE_KEY_BESPOKE_STAGING, reads the source from the cloud's recorded answer, as/passivegives only the level, and expects Passive. It also checks the level and the address the example describes, without printing the key. The Basic key test keeps this branch's direct call to the cloud._51DEGREES_CLOUD_ENDPOINTnames is now part of the Bespoke staging test, as rc had done with its own. rc's Basic key test, and the checks at the end of the file that read a source from the example, are gone.stagingmark.Before this leaves draft
Not ready to merge until these are done.
app.py,templates/index.htmlandtests/test_cloud_humanconfidence_web_offline.py, and has to take these changes.