Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Code behavior different from Run Hook #171

Closed
monkbroc opened this issue Nov 7, 2015 · 7 comments
Closed

Test Code behavior different from Run Hook #171

monkbroc opened this issue Nov 7, 2015 · 7 comments

Comments

@monkbroc
Copy link

monkbroc commented Nov 7, 2015

I've seen several difference in behavior between the Test Code button and the running the actual hook.

Here's one:

https://hook.io/admin?owner=monkbroc&name=test-test

module['exports'] = function echoHttp (hook) {
  var res = hook.res, 
      store = hook.datastore;
  // 'counter' is an integer
  store.get('counter', function (err, counter) {
    if (err) { return res.end(err.message); }
    res.end(counter);
  });
};

Running the hook outputs 45

Clicking Test Code outputs [object Object]1111

@Marak
Copy link
Collaborator

Marak commented Nov 7, 2015

Good catch! That's good to know.

First off, all "test hook" code is run through the live code execution gateway. This is a slightly separate code path than normal deployment.

see: https://github.com/bigcompany/hooks/blob/master/gateway-javascript/index.js
see: https://hook.io/Marak/gateway-javascript/source

Secondly, in this case, I believe that the datastore is going to be scoped to the owner of the gateway-javascript hook, which is "anonymous". This means currently you aren't actually able to interact with your own data through the "test code" button.

It's possible datastore is not working correctly for the testing gateway, but it's also likely that the counter variable, which is scoped to "anonymous", has been set to a weird value.

I think it would be best to have all test code gateways be scoped to a general anonymous user when no session, and if a session is present, scoped to that user's data.

@monkbroc
Copy link
Author

monkbroc commented Nov 7, 2015

OK. Thanks. I suppose it means the env is from the anonymous user too. That explains the inconsistencies of the same hook not working in test mode, but working in deployment.

@Marak
Copy link
Collaborator

Marak commented Nov 7, 2015

@monkbroc - For sure. That makes a lot of sense.

I've added a new issue tracking at #172

This is medium priority right now.

@monkbroc monkbroc closed this as completed Nov 7, 2015
@Marak Marak reopened this Nov 7, 2015
@Marak
Copy link
Collaborator

Marak commented Nov 7, 2015

Leaving open for now. It's possible we might find other discrepancies and can track them to this issue.

Once we know they both act the same, we can close.

Marak added a commit that referenced this issue Feb 21, 2016
  * JavaScript hot-code gateway datastore scope
  * Closes #172
Marak added a commit that referenced this issue Feb 21, 2016
  * Scopes hot-code gateway to session env scope
  * Works for all hot-code gateways
  * Adds concept of `hookType` ( internal use )
@Marak
Copy link
Collaborator

Marak commented Feb 21, 2016

This should be resolved locally.

datastore and env properties are now scoped to the currently logged in user for the hot-code / test-code gateways.

The reason there is a scoping issue for the hot-code gateways is that every gateway is owned by user "marak". We could mitigate this issue by having every user fork the existing hot-code gateways to their own account ( since they are just hooks ), and that would ensure the correct scope always exists for the gateways.

Since it's not very convenient for every user to create a copy of the hot-code gateway, I added some special logic for binding the "marak" owned hot-code gateways to the currently logged in session. This should resolve any current issues with testing code.

test code logs are still not scoped to the logged in user, because the hot-code logging out will go the log entry point for the "marak" owned gateway.

@monkbroc I'll let you know when this is deployed and ready for testing.

@monkbroc
Copy link
Author

Thanks @Marak!

@Marak
Copy link
Collaborator

Marak commented Feb 28, 2016

@monkbroc -

I've pushed and deployed this now. Still haven't fully tested it in production, but I assume it's working.

All hot-code gateways should be respect the scope of the currently logged in user.

This should result in no more cross contamination of Datastore or Env data to the anoymous user account.

Thanks again for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants