Skip to content

test(api): reuse node enrollment helper - #320

Merged
samuelmbabhazi merged 1 commit into
shipkeepdev:mainfrom
iyuzhang:chore/shared-node-enrollment
Nov 16, 2026
Merged

samuelmbabhazi merged 1 commit into
shipkeepdev:mainfrom
iyuzhang:chore/shared-node-enrollment

Conversation

@iyuzhang

@iyuzhang iyuzhang commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Task

Closes #295.

What changed

Use enrollTestNode in the six integration specs and remove their duplicated CSR and enrollment code. Add ready: false for setups that previously enrolled without a heartbeat.

Why

Keeps fleet infrastructure imports inside the shared test helper while preserving node facts, tenant ownership and readiness.

How it was tested

  • The six specs pass on both unchanged main and this branch: 16 tests each, against disposable PostgreSQL 17.
  • pnpm lint, pnpm test, pnpm proto:lint and Prettier checks pass with Node 22.
  • Full pnpm test:integration: 348 passed, one password-authentication test failed because the disposable server used trust. After switching it to SCRAM authentication, all 20 tests in provision-runtime.integration.spec.ts passed. The full suite was not rerun after that environment correction.
  • Go unit tests and browser acceptance were not run for this test-only refactor.

Security considerations

Test setup only. Enrollment still uses real join tokens, CSRs and application services. No production code or contracts changed.

Summary by CodeRabbit

  • Tests
    • Standardized node setup across integration tests for application domains, confirmations, agent actions, deployment pipelines, and allocation observations.
    • Added coverage for nodes that have enrolled but have not yet sent an initial heartbeat, including deployment placement scenarios.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Six API integration tests now use the shared enrollTestNode helper instead of creating certificate signing requests and enrolling nodes locally. The helper accepts an optional ready value and skips its first heartbeat when that value is false.

Changes: API test node enrollment

Layer / File(s) Summary
Optional initial heartbeat
apps/api/src/testing/enroll-test-node.ts
The helper adds an optional ready option. It sends the first heartbeat unless ready is false.
Integration test enrollment setup
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
The six tests replace their local CSR and node enrollment setup with calls to enrollTestNode.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Other

Possibly related PRs

  • shipkeepdev/shipkeep#318: Its placement-concurrency integration test uses the shared enrollTestNode helper introduced here.
Merge Risk: Minimal · up to 828dc

This is a test-only refactor with no production behavior change. The remaining risk is small: the full integration suite was not rerun after the environment fix.

Security architecture risk: Minimal · up to 828dc

This is a test-setup refactor. Enrollment keeps the same organization scope, join-token authority, and certificate requests. Tests that previously sent a heartbeat still do; those that did not explicitly skip it.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "test(api): reuse node enrollment helper" matches the main change. The PR replaces duplicated CSR creation and node-enrollment setup in six API integration specs with the shared enrollTestNo…
Linked Issues check Passed [#295] Requirement: add a shared helper in apps/api/src/testing/ that issues a join token, builds the CSR, enrolls the node, and returns its ID; use it in the six listed specs and remove their direct …
Out of Scope Changes check Passed The PR summary lists changes only in apps/api/src/testing/enroll-test-node.ts and the six named integration specs. The helper change adds an optional ready flag and documents the skipped heartbeat. Th…
Full details: Title check

Explanation

The title "test(api): reuse node enrollment helper" matches the main change. The PR replaces duplicated CSR creation and node-enrollment setup in six API integration specs with the shared enrollTestNode helper. The helper gains an optional ready flag, which the title does not mention, but that detail is secondary. The title is short, specific, and follows the conventional-commit style.

Full details: Linked Issues check

Explanation

[#295] Requirement: add a shared helper in apps/api/src/testing/ that issues a join token, builds the CSR, enrolls the node, and returns its ID; use it in the six listed specs and remove their direct fleet/infrastructure imports. Evidence at head: apps/api/src/testing/enroll-test-node.ts exists and performs IssueJoinToken, agentCsr() and EnrollNode, then returns nodeId. The helper's fleet/infrastructure/ca/x509 import is in src/testing/, which the issue allows. deployment-pipeline.integration.spec.ts and pipeline-store.integration.spec.ts at head import enrollTestNode from ../../testing/enroll-test-node and no longer import fleet/infrastructure. The PR summary reports the same for the other four specs; I did not read those four files. The ready flag preserves the old no-heartbeat setups (pipeline-store uses ready: false; the helper skips the heartbeat when ready is false). Unresolved: the acceptance criterion 'pnpm test:integration passes with the same number of tests' is supported only by author-reported results. The full suite was not rerun after the environment correction (SCRAM authentication). The one failure was attributed to the disposable server's trust authentication, not to this change.

Full details: Out of Scope Changes check

Explanation

The PR summary lists changes only in apps/api/src/testing/enroll-test-node.ts and the six named integration specs. The helper change adds an optional ready flag and documents the skipped heartbeat. This supports the issue's requirement for the shared helper and the ready: false setups. No production code, contracts, or fleet tests are reported as changed. I could not run a whole-PR diff (the diff operation failed because changed blobs were unavailable), so the file list relies on the supplied summary. The file contents I read at head are consistent with that list.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 34872a7 and 828dc1b.

Files selected for processing: 7

  • 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
  • apps/api/src/testing/enroll-test-node.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

samuelmbabhazi commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @iyuzhang, welcome to Shipkeep, and thank you for this contribution.

The change does what #295 asked for: the six specs no longer import fleet/infrastructure, behavior is preserved, and the affected specs pass on this branch. Thank you as well for stating clearly in the description what was run and what was not.

The CI and security workflows are now running. I will merge once they are green.

Feel free to pick up any other issue that interests you. The ones labelled good first issue are a good place to continue, and you are welcome to comment on any issue you would like to take.

@samuelmbabhazi
samuelmbabhazi merged commit 811b214 into shipkeepdev:main Nov 16, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shared test helper to enroll a node in API integration tests

2 participants