You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Shared test helper to enroll a node in API integration tests #295
Six integration tests outside the fleet module enroll a test node by importing fleet/infrastructure/ca/x509 directly to build a certificate signing request:
CLAUDE.md says modules never import each other's infrastructure/. Tests are not production code, but the repeated setup also duplicates the same steps: issue a join token, build a CSR, enroll.
Proposed change
Add a shared helper in apps/api/src/testing/ (for example enroll-test-node.ts) that issues a join token, builds the CSR, enrolls a node and returns what the tests need. Use it in the six tests above and remove their direct fleet/infrastructure imports. The tests inside fleet itself can keep theirs.
Done when
None of the files listed above imports ../fleet/infrastructure/.
pnpm test:integration passes with the same number of tests.
Nothing changes outside src/testing/ and the six tests.
The helper this issue asks for now exists: enrollTestNode (and agentCsr) in apps/api/src/testing/enroll-test-node.ts, added with #318 for a new test.
What remains here is unchanged in spirit and smaller: use it in the six tests listed above and remove their imports of fleet/infrastructure. enrollTestNode(fixture, { facts, name }) issues the join token, builds the CSR, enrolls the node and sends a first heartbeat, then returns the node id. A test that needs a node that is not ready yet can call agentCsr() and enroll by itself.
Activity
samuelmbabhazi commentedon Nov 16, 2026
The helper this issue asks for now exists:
enrollTestNode(andagentCsr) inapps/api/src/testing/enroll-test-node.ts, added with #318 for a new test.What remains here is unchanged in spirit and smaller: use it in the six tests listed above and remove their imports of
fleet/infrastructure.enrollTestNode(fixture, { facts, name })issues the join token, builds the CSR, enrolls the node and sends a first heartbeat, then returns the node id. A test that needs a node that is not ready yet can callagentCsr()and enroll by itself.