hiero-ledger / hiero-ledger/hiero-sdk-cpp

[Intermediate]: Migrate bot script tests to Jest with auto-discovery

Open
#1,609 6 comments 0 reactions 0 assignees View on GitHub
priority: medium scope: ci scope: tests skill: intermediate status: ready for dev
Dominant language
C++
Stars
42
Forks
108
Avg merge
11h 45m
Merged PRs (30d)
2

Description

### 🧩 Intermediate Friendly

This issue is a good fit for contributors who are already familiar with the Hiero C++ SDK and feel comfortable navigating the codebase.

Intermediate Issues often involve:
- Exploring existing implementations
- Understanding how different components work together
- Making thoughtful changes that follow established patterns

The goal is to support deeper problem-solving while keeping the task clear, focused, and enjoyable to work on.

> [!IMPORTANT]
> ### 🧭 About Intermediate Issues
>
> Intermediate Issues are a great next step for contributors who enjoy digging into the codebase and reasoning about how things work.
>
> These issues often:
> - Involve multiple related files or components
> - Encourage investigation and understanding of existing behavior
> - Leave room for thoughtful implementation choices
> - Stay focused on a clearly defined goal
>
> Other kinds of contributions — from beginner-friendly tasks to large system-level changes — are just as valuable and use different labels.

### 👾 Description of the Task

The bot-script test suite under `.github/scripts/tests/` uses a custom `runTestSuite` runner. Each new test file has to be wired explicitly into the test workflow at `.github/workflows/zxc-test-bot-scripts.yaml`. The pattern is fragile — it is easy to add a new test file and forget to add it to the workflow, in which case the new tests silently never run in CI.

PR #1492 surfaced this concern. Maintainer comment:

> *"Honestly, Jest would be the better long-term approach for this test suite — auto-discovery would eliminate the recurring 'add a new test file, forget to wire it into the workflow' problem… that's a broader change that deserves its own issue and PR."*

Verified at the v0.55.0 release commit: `.github/scripts/tests/` still uses the custom runner; `package.json` does not yet depend on Jest; tests are still wired one-by-one in the workflow YAML.

Relevant files:

```
.github/scripts/tests/
.github/scripts/package.json (or wherever the bot scripts' package.json lives)
.github/workflows/zxc-test-bot-scripts.yaml
.github/workflows/zxc-lint-workflows.yaml (in case it interacts with the test runner)
```

### 💡 Proposed Approach

1. Add Jest as a dev dependency for the bot-scripts package and configure it for the existing CommonJS source layout (the bot scripts use `require(...)` / `module.exports`).
2. Convert the existing custom-runner test files in `.github/scripts/tests/` to Jest test files (`*.test.js`). The actual test bodies should stay almost identical — the diff is mostly the runner-glue (`runTestSuite(...)` → Jest `describe(...)` / `test(...)`).
3. Replace the per-file enumeration in `zxc-test-bot-scripts.yaml` with a single Jest invocation (e.g. `npx jest --ci`) that picks up every `*.test.js` automatically.
4. Confirm the suite passes locally and in CI, and that the workflow surfaces individual test names on failure (so a regression points at the right file).
5. Document the new flow in any contributor-facing notes about how to add a bot test (one or two lines is enough).

This is a focused infrastructure change; resist the temptation to also reorganize tests, rename files, or change assertion shapes in the same PR.

### 👩‍💻 Implementation Steps

- [ ] Inventory the existing custom-runner contract: read `.github/scripts/tests/test-api.js` (or whichever file contains `runTestSuite`) and list the helper functions Jest will need to replace (e.g. assertions, test grouping, lifecycle hooks).
- [ ] Add Jest to the bot-scripts `package.json` as a dev dependency. Configure it via `jest.config.js` (or `package.json`'s `jest` field) for the existing CommonJS layout.
- [ ] Convert each existing test file in `.github/scripts/tests/` from the custom runner to Jest. Keep test names identical so failure messages stay greppable.
- [ ] If there is a custom assertion / spy helper, prefer Jest's built-in `expect()` and `jest.fn()`; only retain the custom helpers if they encode logic that does not exist in Jest.
- [ ] Replace the test invocation block in `.github/workflows/zxc-test-bot-scripts.yaml` with a single `npx jest --ci` step (or equivalent). Remove the per-file enumeration.
- [ ] Confirm local: `npm install && npx jest` (in the bot-scripts package directory) runs the full suite and all tests pass.
- [ ] Confirm CI: open a draft PR and verify the workflow runs and reports per-test names on failure.
- [ ] Add or update a short note (one or two paragraphs in the relevant `docs/` page or in a new `.github/scripts/tests/README.md`) describing how to add a new bot test under the new flow.

### ✅ Acceptance Criteria

- [ ] All existing bot-script tests run under Jest with no behavior change.
- [ ] The CI workflow runs all tests via a single Jest invocation; new test files do not need to be added to the workflow YAML.
- [ ] Adding a new `*.test.js` file under `.github/scripts/tests/` is sufficient to have it picked up by CI.
- [ ] Per-test failure output in CI clearly identifies the failing test name and file.
- [ ] No bot-script production logic is changed in this PR.
- [ ] All previously-passing tests continue to pass.

---

### 📋 Step-by-Step Contribution Guide

To help keep contributions consistent and easy to review, we recommend following these steps:

- [ ] Comment `/assign` to request the issue
- [ ] Wait for assignment
- [ ] Fork the repository and create a branch
- [ ] Set up the project using the instructions in `README.md`
- [ ] Make the requested changes
- [ ] Sign each commit using `-s -S`
- [ ] Push your branch and open a pull request

Read [Workflow Guide](https://github.com/hiero-ledger/hiero-sdk-cpp/blob/main/docs/training/workflow.md) for step-by-step workflow guidance.
Read [README.md](https://github.com/hiero-ledger/hiero-sdk-cpp/blob/main/README.md) for setup instructions.

❗ Pull requests **cannot be merged** without `S` and `s` signed commits.
See the [Signing Guide](https://github.com/hiero-ledger/hiero-sdk-cpp/blob/main/docs/training/signing.md).

### 🤔 Additional Information

- Originating PR: [#1492](https://github.com/hiero-ledger/hiero-sdk-cpp/pull/1492).
- Related but distinct: [#1471](https://github.com/hiero-ledger/hiero-sdk-cpp/pull/1471) added ESLint for bot scripts. This issue is the test-runner counterpart.
- The bot scripts use CommonJS (`require(...)`) — Jest works with that layout out of the box; no Babel/ESM gymnastics required.

If you have questions while working on this issue, feel free to ask! [Hiero-SDK-C++ Discord](https://discord.com/channels/905194001349627914/1337424839761465364)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.