Skip to content

Shared test helper to enroll a node in API integration tests #295

Closed

Description

@samuelmbabhazi

What

Six integration tests outside the fleet module enroll a test node by importing fleet/infrastructure/ca/x509 directly to build a certificate signing request:

  • apps/api/src/modules/apps/application-domains-http.integration.spec.ts
  • apps/api/src/modules/confirmations/confirmation-http.integration.spec.ts
  • apps/api/src/modules/deployments/agent-actions-http.integration.spec.ts
  • apps/api/src/modules/deployments/allocation-observations.integration.spec.ts
  • apps/api/src/modules/deployments/deployment-pipeline.integration.spec.ts
  • apps/api/src/modules/deployments/pipeline-store.integration.spec.ts

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.

Raised in the review of #290.

Activity

  1. samuelmbabhazi commented on Nov 16, 2026

    @samuelmbabhazi
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions