Add unit tests for core GEP modules#63
Conversation
Add test suite using Node.js built-in test runner (node:test) covering: - contentHash: canonicalize, computeAssetId, verifyAssetId - a2aProtocol: message builders, validation, asset unwrapping - mutation: buildMutation, category selection, safety downgrades - selector: gene selection, capsule matching, drift intensity 61 tests, zero external dependencies. Run with: npm test
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
test/mutation.test.js
Outdated
|
|
||
| it('returns 0 for non-finite input', () => { | ||
| assert.equal(clamp01(NaN), 0); | ||
| assert.equal(clamp01(Infinity), 0); |
There was a problem hiding this comment.
Test asserts wrong expected value for clamp01(Infinity)
Low Severity
The test asserts clamp01(Infinity) returns 0, but a function named clamp01 (clamp to [0, 1]) would correctly return 1 for Infinity, since Infinity > 1. The source code treats all non-finite values uniformly as 0, which is correct for NaN and undefined but incorrect for positive infinity. Grouping Infinity together with NaN/undefined as "returns 0" cements this inconsistency — clamp01(1e308) returns 1 but clamp01(Infinity) returns 0, a surprising discontinuity. This test codifies that potentially incorrect behavior.
There was a problem hiding this comment.
Good catch. The test is intentionally documenting the current behavior — clamp01 rejects all non-finite values early via Number.isFinite(), so Infinity returns 0 rather than being clamped to 1.
Whether that's the right behavior is a fair question (mathematically clamp(Inf, 0, 1) should be 1), but changing it would be a separate fix in the source. Happy to open a follow-up issue if the maintainers want to revisit it.
- PR #68 (hendrixAIDev): guard performMaintenance with IS_DRY_RUN - PR #26 (onthebigtree): hash hostname in env fingerprint, portable validation paths - PR #63 (voidborne-d): add 61 unit tests for core GEP modules - PR #21 (LKCY33): add dotenv path rewrite for public build - PR #25 (onthebigtree): already applied (currentSleepMs, matchPatternToSignals, max_files) - Update public.manifest.json: include test/*.test.js, add index.js dotenv rewrite Co-authored-by: Cursor <cursoragent@cursor.com>


Hey! I have been reading through the codebase and noticed there are no unit tests yet for the core modules. Figured I would put together a starter test suite.
What this adds
61 tests covering 4 core modules:
contentHash— canonicalize, computeAssetId, verifyAssetId, tamper detectiona2aProtocol— all 6 message builders, validation, asset unwrappingmutation— category selection logic, safety downgrades, personality constraintsselector— gene scoring, capsule matching, drift intensitynpm testscript in package.jsonDetails
node:test+node:assert(no external dependencies)Happy to adjust scope or style if needed.
Note
Low Risk
Test-only additions plus a new
npm testscript; no production logic changes beyond enabling a test command.Overview
Adds a Node built-in (
node:test) unit test suite covering core GEP modules:contentHash(canonicalization + asset ID hashing/verification),a2aProtocol(message builders/validation and publish asset unwrapping),mutation(category/risk selection and personality safety constraints), andselector(gene/capsule selection, drift intensity, and memory preference behavior).Updates
package.jsonto exposenpm testvianode --test test/*.test.js(no new dependencies).Written by Cursor Bugbot for commit b76cb18. This will update automatically on new commits. Configure here.