I'm trying to add tests for my pants-plugins, but ...
# plugins
p
I'm trying to add tests for my pants-plugins, but 😵‍💫 What am I missing to resolve these rule graph errors? https://github.com/StackStorm/st2/actions/runs/3718138873/jobs/6306123204#step:6:232 This is the very basic test stub (I'm just trying to get all the boilerplate to run and then I'll figure out what kind of tests actually make sense): https://github.com/StackStorm/st2/pull/5847/files#diff-60810820daf9810eb5fac8d79e7749bcc3eb680e87970275a18596a3d8f42cb9
1
w
Your tests pass locally and fail in CI?
p
No. Same thing happens locally. I pushed it up so that I could have a link to share here.
w
Ahh, okay - sec, I run into these all the time
Given that the first is AddPrefix, my guess is that you're missing the filesystem rules. Trying to recall the name
Also maybe system_binaries?
Maybe give these two a shot and see if they reduce the number of errors?
Copy code
from pants.core.util_rules import system_binaries

from pants.engine.fs import rules as fs_rules

return RuleRunner(
    rules=[
        ...
        *system_binaries.rules(), 
        *fs_rules, 
        ...
Or.. maybe it was
*archive_rules()
from
from pants.core.util_rules.archive import rules as archive_rules
which imports system binaries
Funnily enough, I was going to open a discussion, or thread about this same problem. I'm curious what the use case for specifying rules in the test rule runner (but not exporting them from the production rules.py) is
p
Funnily enough, I was going to open a discussion, or thread about this same problem. I'm curious what the use case for specifying rules in the test rule runner (but not exporting them from the production rules.py) is
In my code or in the core pants code?
w
Pants
I don't know if there is a downside.
p
OK. I registered system_binaries.rules, fs_rules, and archive_rules... which didn't change the error at all.
w
🤯
p
Could it be because my rule is using
PexFromTargetsRequest -> VenvPex
? And the target it is using is not in the pants-plugins resolve?
w
Oh wait, that'll be another rule you have to add at the very least
pex_rules?
from pants.backend.python.util_rules.pex import rules as pex_rules
p
I added that in my rules file, so I shouldn't need to add that in my tests as well, right? https://github.com/StackStorm/st2/pull/5847/files#diff-94c34a04d8154ce26c5db9e472cc7e7946d1b392b4a784fa8a42274629e9707dR103
w
Correct... Hmm
So, I think I saw this in a test once, and kinda cheated by adding it at some point:
from pants.backend.python import target_types_rules
target_type_rules.rules()
p
I think I saw that in the black backend. I'll try adding that.
w
One of these days, I'm going to sit down and figure out EXACTLY which rules I need at any given time. My last bunch of plugins were all copied/pasted from existing ones, which may/may not be ideal
p
😭
Nope same errors
w
Am I able to clone this repo and run that test? I'm so curious now
p
yup. Do you want me to push up the rules I just added locally?
w
Nah, I'll give this a crack while waiting for some other code to compile
p
One of the benefits of working on this in an open-source project is I don't have to worry about whether or not I can share the code. 😛
w
🙂 Yeah it's great, I just wasn't sure if there were any private downloads anywhere
Cool, got the same error - I'll give it a shot for a few mins
p
Nope. 🙂 StackStorm is a project under the Linux Foundation. It's all open. 🙂
w
Oh! Cool, didn't know that
p
The Linux Foundation is apparently a huge umbrella. I have no idea how big 😛
btw: I'm running this to test
./pants test pants-plugins/schemas
You don't want to run pytest on other tests in the repo... That's a painful project for another day.
w
Oh, wait a sec
p
Did you find the simple switch I need to flip to make everything work? Or better yet, the question for the answer to life, the universe, and everything?
w
42 is unfortunately not involved
May have misread something
Terrifyingly, the tests are passing, but I didn't do anything that should pass them
Okay, wow, yeah, I got nothing - back to the errors, nothing I do seems to move the needle. I've tried removing stuff, adding stuff - but it weirdly allllmost feels like a red herring error. Like, an error fundamentally coming from elsewhere. However, the fix should be the same
😩 1
The error crops up after adding this:
QueryRule(FmtResult, (GenerateSchemasViaFmtTargetsRequest,)),
Which is a bit weird
p
That is what I'm supposed to do isn't it? Since that's THE rule in my plugin?
w
Yeah, but I wonder if it doesnt' like something about how it's defined. It's pants 2.14, so I'll need to look back before Josh's formatter partitioning change
p
Yeah. I had to switch to the 2.14.x branch of the pants sources I was consulting
w
So, the only thing different from what I usually do, is this multiplesourcesfield thing. I usually use singlesource, so i need to just read up on that
Okay, yeah, I'm kinda out of ideas. Would have to look at it fresh to come up with something. As mentioned, this feels like a red herring with a problem elsewhere. Or, it's pretty obvious and I've just completely blanked to the real problem
p
I'm stepping back and fixing some other things and then I'll attack it again.
w
👍 Please let me know if you figure it out. I'm so invested in the answer. Specifically with these same rule errors - I've seen them multiple times, with the same set of them (archive + system binaries).
I mean, I'm commenting out code in your format method - and all of a sudden it's complaining that some stuff isn't defined.
Just weird weird behaviour
*the engine is complaining
p
Well, I fixed the interpreter constraints issue I mentioned in #general but that didn't fix it. Hmm.
w
Can you try something? I'm upgrading to 2.16 to see if anything gets fixed, but here in rules_test: "SourceFilesRequest(field_set.source for field_set in field_sets)," can you change that to
field_set.sources
?
👍 1
Also, can you try adding:
Copy code
from pants.backend.python.util_rules import pex_from_targets

*pex_from_targets.rules(),
@proud-dentist-22844 ^^ That seems to get your tests to run for me on 2.16.0.dev3
p
Wow. That was it. At least it gets past those rule graph errors.
👍 1
Now I'm running into the errors I expected. 🙂 building the
PexFromTargetsRequest
in the tests is failing. I suspect that's because those targets are in a different resolve.
Thank you. Now I can go to bed and figure out these errors tomorrow.
w
No prob!