Skip to content

Add Testing for cxjs Functions#128

Open
Lightning11wins wants to merge 56 commits into
masterfrom
add-cxjs-testing
Open

Add Testing for cxjs Functions#128
Lightning11wins wants to merge 56 commits into
masterfrom
add-cxjs-testing

Conversation

@Lightning11wins

@Lightning11wins Lightning11wins commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This PR creates a new set of test suites using node:test to test the JS client-side Centrallix functions, and also adds make test-js in the centrallix directory to run the new tests.

Stats

tests    1482
suites   33
pass     1482
fail     0
skipped  0
runtime  1.336s

@Lightning11wins Lightning11wins self-assigned this Jun 17, 2026
@Lightning11wins Lightning11wins added testing Includes testing, either new tests or updates to existing tests. size: medium Might be hard to review, usually less than ~5000 lines. labels Jun 17, 2026
@Lightning11wins Lightning11wins marked this pull request as draft June 17, 2026 18:38
@Lightning11wins

Copy link
Copy Markdown
Contributor Author

I haven't reached coverage of all the functions I'd like to test yet, so this will stay a draft until then.

@Lightning11wins Lightning11wins marked this pull request as ready for review June 18, 2026 19:16
@Lightning11wins Lightning11wins added the ai-review Request AI review for PRs. label Jun 18, 2026
@Lightning11wins

Copy link
Copy Markdown
Contributor Author

@greptileai Review please

@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a comprehensive JS test suite (33 test files, 1,482 tests) for the cxjs_* and htr_* client-side functions in ht_render.js, using Node.js node:test and a vm-based sandbox in _setup.js. It also updates ht_render.js to use Array.isArray() and typeof v === "object" && v !== null instead of instanceof for the aggregate functions, and adds make test-js and make test-js-coverage Makefile targets.

  • ht_render.js: Eight instanceof Array/instanceof Object guards in cxjs_min, cxjs_max, cxjs_sum, and cxjs_count are replaced with the more robust Array.isArray() and typeof checks; these improve cross-realm correctness (e.g., arrays from iframes).
  • _setup.js: Creates a minimal vm.createContext sandbox with browser-global stubs so ht_render.js can be loaded and exercised in Node without a real DOM.
  • Makefile / configure: test-js and test-js-coverage targets are added; Node.js is detected by autoconf and falls back to $PATH lookup at runtime.

Confidence Score: 5/5

Safe to merge — the only runtime code change is a minor correctness improvement in four aggregate functions, and the rest is additive test infrastructure.

All eight instanceof replacements in ht_render.js are mechanically equivalent for normal inputs and strictly better for cross-realm arrays. The 1,482 new tests use a well-isolated vm sandbox with no shared mutable state between test files, and the expected values were verified against the actual implementations. The Makefile targets have proper fallback logic and correctly unquoted shell globs.

No files require special attention.

Important Files Changed

Filename Overview
centrallix-os/sys/js/ht_render.js Replaces instanceof Array/instanceof Object with Array.isArray() and typeof checks in four aggregate functions; strictly more correct, no behavioral regression for normal inputs.
centrallix-os/sys/js/tests/_setup.js VM sandbox that loads ht_render.js into a minimal browser-stub context; stubs cover all top-level globals accessed at parse/init time. Approach is sound for this test scope.
centrallix/Makefile.in Adds test-js and test-js-coverage phony targets with runtime NODE fallback; shell glob is unquoted so the shell expands it before Node sees it.
centrallix-os/sys/js/tests/cxjs_getdate.test.js Uses a FakeDate class that remaps local-time methods to UTC, eliminating timezone dependency; clock-offset edge cases (day/month/year boundary crossings) are well covered.
centrallix-os/sys/js/tests/cxjs_round.test.js Exhaustive coverage of the custom rounding algorithm, including negative dec, float precision pitfalls, signed-zero propagation, and overflow/underflow via extreme magnitudes and dec values.
centrallix-os/sys/js/tests/cxjs_convert.test.js Covers integer/double/string conversions including currency-prefix stripping logic; edge cases like 1e3, hex, signed zero, and falsy-but-non-null datatypes are all exercised.
centrallix-os/sys/js/tests/cxjs_count.test.js Tests array, object, and scalar inputs including sparse arrays and inherited enumerable properties; verifies null/undefined/NaN exclusion behavior.
centrallix-os/sys/js/tests/htr_boolean.test.js Covers htr_boolean truthy/falsy paths including string case variants, numeric coercion via ==, and array-to-number coercion edge cases.
centrallix-os/sys/js/tests/cxjs_rand.test.js Validates range, non-determinism, seed-warning behavior, and the null/undefined no-warning path using a captured console.warn counter.
centrallix/configure.ac Adds a single AC_PATH_PROG([NODE], [node], []) line; standard autoconf pattern, consistent with other tool probes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["make test-js"] --> B["Detect node binary\n(configure / PATH fallback)"]
    B --> C["node --test\ncentrallix-os/sys/js/tests/*.test.js"]
    C --> D["Each test file:\nrequire('./_setup')"]
    D --> E["_setup.js\nvm.createContext(sandbox)"]
    E --> F["vm.runInContext(\nht_render.js, sandbox\n)"]
    F --> G["sandbox exports:\ncxjs_* / htr_* functions"]
    G --> H["Test assertions\nassert.equal / assert.ok"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["make test-js"] --> B["Detect node binary\n(configure / PATH fallback)"]
    B --> C["node --test\ncentrallix-os/sys/js/tests/*.test.js"]
    C --> D["Each test file:\nrequire('./_setup')"]
    D --> E["_setup.js\nvm.createContext(sandbox)"]
    E --> F["vm.runInContext(\nht_render.js, sandbox\n)"]
    F --> G["sandbox exports:\ncxjs_* / htr_* functions"]
    G --> H["Test assertions\nassert.equal / assert.ok"]
Loading

Reviews (2): Last reviewed commit: "Update Makefile to find tests in shell c..." | Re-trigger Greptile

Comment thread centrallix-os/sys/js/tests/cxjs_user_name.test.js Outdated
Comment thread centrallix/Makefile.in
Comment thread centrallix-os/sys/js/tests/gen-coverage.sh Outdated
@Lightning11wins

Copy link
Copy Markdown
Contributor Author

This PR is ready for human review.

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

Labels

ai-review Request AI review for PRs. size: medium Might be hard to review, usually less than ~5000 lines. testing Includes testing, either new tests or updates to existing tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant