-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Next attempt to pull Agents into gems #1366
Conversation
linking to discussion in #60 |
Very cool! I'll dig into this soon. |
I added a generator to the |
Ah, just for the record... the problems you're associating with that approach are a byproduct of unit testing code, not of the approach to abstracting out the code into a base class. Even when I've written agents or contributed code to projects, I've had to use that same mock/stub/abstract approach to building my test scenarios. Like this: https://github.com/cantino/huginn/pull/1209/files#diff-026ea14cf5cd2e2f57acd81960c31114R30 It's just my personal position on testing, and a conclusion I've come to after writing thousands upon thousands of tests. I know it's not shared by most Rails developers (Rails testing starts and ends with integration tests, even to the point that its concept of "unit tests" still hit the database), which is fine. We all pay the consequences of our own decisions, and I'm learning not to get worked up over these differences of view. 😄 I think that mocking and stubbing is great, as it frees me from the details that I don't care about -- like active record's serialization of hashes and the like. I'm using the framework, so I'm going to assume they work and instead focus on my code. I gain flexibility and simplicity in my tests, at the cost of the coverage that integration testing gives me. Anyway, I just wanted to explain that bit. I really enjoyed the work I put into those pull requests, as they gave me a new look into abstracting by "projecting" an one thing (like my Rails-free BaseAgent) into an entirely different thing (like the Rails agent). Ruby is a very powerful and fun language! ⚡ ⚡ ⚡ I like your approach, it's a very neat idea. Good luck! 😄 |
I'm on vacation next week and looking forward to digging into this :) |
46ec385
to
ce9ad90
Compare
This took surprisingly little code! |
@cantino I was surprised as well, do you think the approach is worth pursuing? |
It seems like it. The only real downside is that we lose the ability to update all Agents with a single commit, but since people may have private Agents, we don't really have that now anyway. |
I think we should keep our current agents in this repository and maybe move some with big dependencies into a What I am still uncertain about is how we will let the user add additional agent gems to the |
You mean adding Agents in the Docker context? |
Yes for docker users the gems have to be configurable via the environment. For the other installation methods it would still be helpful otherwise you would need to maintain a small fork (even if the changes would just be in |
Hmm, good question. I might suggest parens for the version strings.
|
That should work, maybe optional square brackets for a path or git url?
|
Torn between that and something like
or even
because we can probably detect a GIT / URL vs a version. |
ce9ad90
to
1d19353
Compare
I went with a more verbose version which allows possible arguments of the |
135231c
to
0485164
Compare
GEM_SEPARATOR = '\s*(?:,|\z)'.freeze | ||
GEM_REGULAR_EXPRESSION = /(#{GEM_NAME})(?:\(#{GEM_OPTIONS}\)){0,1}#{GEM_SEPARATOR}/ | ||
|
||
def parse_agent_gems(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe parse_each_agent_gem(string)
?
I would consider this feature complete now. Most of the changes are in huginn/huginn_agent#2. Maybe we should move the discussion over there and continue here after |
@@ -192,3 +193,7 @@ end | |||
if_true(ENV['DATABASE_ADAPTER'].strip == 'mysql2') do | |||
gem 'mysql2', '~> 0.3.20' | |||
end | |||
|
|||
GemfileHelper.parse_each_agent_gem(ENV['ADDITIOANL_GEMS']) do |args| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsander Just in case... should this be ADDITIONAL_GEMS
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 😊, thanks!
2d392c6
to
708106a
Compare
708106a
to
65ba4b4
Compare
0d24f5d
to
d830459
Compare
The specs are only failing because I bumped the |
@@ -19,8 +19,33 @@ def load_dotenv | |||
) | |||
end | |||
|
|||
GEM_NAME = '[A-Za-z0-9\.\-\_]+'.freeze | |||
GEM_OPTIONS = '(.+?)\s*(?:,\s*(.+?)){0,1}'.freeze | |||
GEM_SEPARATOR = '\s*(?:,|\z)'.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be \s*(?:,\s*|\z)
in case there are spaces after the comma?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not needed, spaces are not valid in the GEM_NAME expression they will be .scan
will skip over them and start the next match when any character that is allowed in GEM_NAME is found. In the specs gem are separated with spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay!
d830459
to
222f3a4
Compare
Merged! Thanks for the feedback and reviews! |
The work is based on #920 and cantino/huginn_agent.
While I generally liked the idea of #1012 to add a "base agent" class which decouples the agent gems from active record it also added problems, for the specs to pass every method call that needs active record has to be mocked, stubbed or abstracted in the base agent class.
This attempt follows #920 by only moving the agent classes and specs into a gem and load them on startup. To ensure the agent gem works with Huginn I added a (at the moment messy) rake task which clones Huginn, injects the agent gem and runs the specs of the gem.
Running the tests on travis works as well: https://travis-ci.org/kreuzwerker/DKT.huginn_nlp_agents
The source of the gem can be viewed here, the only change needed was adding
require 'huginn_agent/spec_helper'
(which requires all files inspec/support/
) to the agent specs.The pull request to
huginn_agent
can be viewed here: huginn/huginn_agent#2If we agree to follow this approach I am planning to make rake task universal and output more useful by shelling out using
open3
. Additionally adding a generator which creates the needed file structure for a new agent by runninghuginn_agent new awesome_agent
would be cool.Thanks to kreuzwerker.de who are paying me to work on this in the context of the research project 'Digitale Kuratierungstechnologien' of which they are a part of.