I’m working on a plugin to package rpms using envi...
# plugins
b
I’m working on a plugin to package rpms using environments (because building rpms takes a lot of dependencies). My plugin is working and now I am trying to write some tests for it. I am getting this error which I am trying to figure out:
Copy code
Exception: No installed QueryRules can compute BuiltPackage given input Params(RPMFieldSet), but it can be produced using:
  Params((EnvironmentName, RPMFieldSet))
my test code is pretty similar to how I see other packaging rules (like go_binary and debian) being tested:
Copy code
@pytest.fixture
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *rpm_rules(),
            *source_files_rules(),
            *environment_rules(),
            *package_rules(),
        ],
        target_types=[RPMTarget],
        inherent_environment=None,
    )


def build_package(rule_runner: RuleRunner, target: RPMTarget) -> BuiltPackage:
    field_set = RPMFieldSet.create(target)
    result = rule_runner.request(BuiltPackage, [field_set])
    rule_runner.write_digest(result.digest)
    return result
The main difference being I need to run inside my environment. If I remove the
inherent_environment=None,
then it runs but fails because it can’t run the build outside of the environment. I’ve tried a bunch of things but I can’t get the test to figure out the environment. Does anyone have any ideas or see what I am doing wrong?
🙌 1
c
do you have the
QueryRule(BuiltPackage, (RPMFieldSet,)),
from any of those rules methods?
b
I do not. I have a rule:
Copy code
async def build_rpm(field_set: RPMFieldSet) -> BuiltPackage:
and
Copy code
def rules():
    return [*collect_rules(), UnionRule(PackageFieldSet, RPMFieldSet)]
and that is all. This works when using pants though and I am allowing all of the package rules in my test so I am confused about what is different
c
you need the
QueryRule
in your test in order to use
rule_runner.request(…)
as an entry point into the rule graph.
so, we usually add those QueryRules directly to the
rules
param when creating the test RuleRunner
b
when I add the QueryRule then I get:
Copy code
ValueError: Encountered 21 rule graph errors:
No installed rules return the type EnvironmentAwarePackageRequest,
👀 1
c
ah, seems you need to use it like:
Copy code
result = rule_runner.request(BuiltPackage, [EnvironmentAwarePackageRequest(field_set)])
shooting from the hip here…
as the above may result in the need to adjust the QueryRule, potentially…
b
yeah that gives me the same error still
so the query rule should have EnvironmentAwarePackageRequest in it
c
yes, I think so
I’ve not been using the package API extensively since the introduction of environments so I’m a bit hazy on how it works in that area…
b
QueryRule(BuiltPackage, (EnvironmentAwarePackageRequest,)),
with this I am now getting an error about the environment I want not being found which is progress!
c
sweet
b
hmmm still running into issues. but I unblocked myself to write a full on integration test so I am going down that path now