Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/nix/module-eval/agent-plugins.nix
atlas 18ed3f5040 module-eval: evaluate shared fixture configs once
Thirty-three module-eval fixtures were a second (or later) full
`nixosSystem` evaluation of a config another fixture already evaluated:
16 shapes defined identically in two to seven cluster files, plus
duplicates inside agent-queue-bao, core-toggle and
swarm-services-switch. Each cluster imports ./lib.nix itself, so nothing
was shared between them.

nix/module-eval/shared.nix now defines each of those 16 shapes once.
nix/checks.nix instantiates it a single time and passes it as `shared`
to the 23 clusters that read one, and each cluster rebinds the fixture
under its existing local name. Assertions are unchanged. Case text
changes only in core-toggle, where two cases built the forge-host
fixture inline and now read the file's `forgeHere`, and in two inline
`let` bindings (bao-otel-collector, grafana) that now take the shared
fixture.

Six folds are value-equal rather than textually equal: they drop an
explicit `deploy.hive-controller.enable = false` or
`deploy.swarm-otel.enable = false` that equals what the option already
resolves to for that config. Nothing under nix/host-modules sets either
option apart from the `mkDefault allSwarmServices` on swarm-otel, and
the only option-priority read there is `domain.highestPrio`.

Part of #5171.
2026-10-13 08:14:50 +02:00

90 lines
3.2 KiB
Nix

# `checks.module-eval-agent-plugins` — see ./lib.nix for the shared
# rationale (why this suite exists, naming convention, "evaluates
# not executes").
{
pkgs,
lib,
self,
nixosSystem,
shared,
}:
let
inherit
(import ./lib.nix {
inherit
pkgs
lib
self
nixosSystem
;
})
agent
runGroup
;
# `claudePlugins`'s additive-merge shape: a plain per-agent
# definition must ADD to the module's own base-set definition rather than
# replacing it, while `lib.mkForce` must still replace the whole list
# outright — the two arms below plus the unset default (read directly off
# `bare`-shaped `agent { }`, no fixture of its own needed) are the three
# cases that shape has to hold.
agentPluginsDefault = shared.agentBare;
agentPluginsAdded = agent { claudePlugins = [ "foo@bar" ]; };
agentPluginsForced = agent { claudePlugins = lib.mkForce [ "foo@bar" ]; };
# The de-dup arm: an agent that names a base-set entry explicitly must not
# get it installed twice.
agentPluginsDuplicate = agent { claudePlugins = [ "base@hyperhive" ]; };
agentPlugins = machine: machine.services.hyperhive.agent.claudePlugins;
cases = [
{
# Case 1 of the additive-merge shape: an agent that declares
# nothing gets exactly the module's base set, no more and no less.
name = "an agent with no claudePlugins definition gets exactly the base set";
ok =
agentPlugins agentPluginsDefault == [
"skill-creator@claude-plugins-official"
"base@hyperhive"
];
}
{
# Case 2: a plain per-agent definition ADDS to the base set (list-typed
# options at equal priority concatenate) rather than replacing it —
# the property the operator ruling asked for instead of `mkDefault`.
# Sorted before comparing: concatenation order between two same-
# priority definitions is a module-system implementation detail this
# case isn't about — membership and count are.
name = "an agent's own claudePlugins definition adds to the base set";
ok =
builtins.sort builtins.lessThan (agentPlugins agentPluginsAdded) == [
"base@hyperhive"
"foo@bar"
"skill-creator@claude-plugins-official"
];
}
{
# Case 3: `lib.mkForce` is still the escape hatch — an operator who
# wants the base set gone, not extended, can still say so outright.
name = "an agent's mkForce claudePlugins replaces the base set outright";
ok = agentPlugins agentPluginsForced == [ "foo@bar" ];
}
{
# De-dup arm: an agent that names a base-set entry itself must not get
# it installed twice — `lib.unique` at the JSON-render site, not the
# option's merge (the merge is a plain concatenation on purpose, so
# the un-deduped list stays readable for `agentPlugins` above).
name = "an agent repeating a base-set plugin does not get it installed twice";
ok =
builtins.sort builtins.lessThan (
builtins.fromJSON agentPluginsDuplicate.environment.etc."hyperhive/claude-plugins.json".text
) == [
"base@hyperhive"
"skill-creator@claude-plugins-official"
];
}
];
in
runGroup "agent-plugins" cases