Automated validation
Automated validation checks that the tutorial works across its Rails pages, browser flows, React components, asset setup, source style rules, and release workflow contracts. Ruby and JavaScript checks run as separate layers, while the full local command builds the generated assets before it runs tests and lint checks.
Validation layers
The validation model uses each test type for a different system boundary. Browser checks cover user-visible behavior, request checks cover HTTP and server output, and JavaScript checks cover client components and build-related helpers in isolation.
Ruby application behavior
RSpec validates the Rails side of the tutorial through request, system, and repository contract examples. Request examples check successful page responses, server-rendered HTML, and the streamed React Server Components payload. System examples drive Chrome through Capybara to check routes, comment creation, editing, deletion, form errors, Turbo and Stimulus tabs, ReScript forms, and the Server Components demo.
The ReScript page checks tab changes, safe Markdown output, successful comment submission, and the fact that invalid forms do not add comments. These examples connect the ReScript comment demo to the same browser-level validation used by the other tutorial pages.
The suite also checks that server rendering appears only where the page enables it. A separate contract example checks that release workflow files, their security boundaries, and the pinned local cpflow dependency stay aligned with the expected release. This makes the Ruby suite the main guard for the contract between Rails routes, rendered pages, browser behavior, backing comment data, and review-app automation.
References: spec/rails_helper.rb• L3-46 spec/…/server_render_check_spec.rb• L5-26 spec/…/server_components_spec.rb• L5-97 spec/…/add_new_comment_spec.rb• L6-174 spec/…/edit_comment_spec.rb• L6-36 spec/…/destroy_comment_spec.rb• L6-25 spec/…/rescript_spec.rb• L5-102 spec/cpflow_review_app_contract_spec.rb• L11-31 spec/cpflow_review_app_contract_spec.rb• L130-204
Workflow release contracts
The workflow contract checks protect the release and security rules that support review-app automation. They compare deploy and delete callers with the released source, reject stale dependency resolution, and exercise workflow guards, permissions, immutable references, checkout credentials, and shell input handling.
These examples run the contract checker with isolated Ruby and command environments. They also verify that the older workflow group stays on its immutable release and that promotion actions, source checkout, and setup references use the same release. The checks therefore validate the release boundary without calling external services. They complement page and browser specs because they protect the automation that creates and removes review environments rather than the tutorial pages themselves.
The local cpflow gem is pinned to version 6.0.1 in both the Gemfile and the lockfile. The contract spec treats that pin as part of the workflow contract, so a workflow release change is incomplete when the Ruby dependency resolution still points to another release.
References: spec/cpflow_review_app_contract_spec.rb• L15-119 spec/cpflow_review_app_contract_spec.rb• L130-204 bin/check-cpflow-review-app-contract• L7-29 bin/check-cpflow-review-app-contract• L31-75 Gemfile• L6-10 Gemfile.lock• L142-146 Gemfile.lock• L515-560
Browser coverage
System examples run real page flows in a headless Chrome session. The shared RSpec setup uses the same driver for JavaScript and system examples, saves failed-page evidence under tmp/capybara, and resets the browser session after each example.
CI adds a virtual display for Chrome. A local system-spec failure therefore usually points to a page flow, generated asset, browser driver, or server process rather than to a Ruby-only unit check.
References: spec/rails_helper.rb• L40-97 spec/…/driver_registration.rb• L30-47 .github/…/rspec_test.yml• L19-35 .github/…/rspec_test.yml• L112-117
JavaScript behavior
Jest runs JavaScript and JSX examples in a browser-like jsdom environment. React Testing Library checks the visible output of comment components, while other examples check bundler selection and the source transform rules that support Stimulus and React rendering.
Jest uses Babel for the test files and also transforms the parser packages required by the client test path instead of treating all dependencies as ready-to-run code. The JavaScript suite is intentionally smaller than the browser suite. It checks reusable client behavior without starting Rails or a browser, so a passing Jest run does not replace the RSpec system checks. The package requires Node 22 or newer and uses Yarn 1.22.22, which keeps the local JavaScript validation environment aligned with CI. The current client checks run against the React 19.3.1 and React on Rails 17.2.1 RC dependency set declared in the package manifest.
References: package.json• L5-7 package.json• L81-92 package.json• L165-181 client/…/testHelper.js• L1-5 client/…/CommentList.spec.jsx• L13-53 client/…/Comment.spec.jsx• L5-31 client/…/bundlerUtils.spec.js• L21-118 client/…/swc-config.spec.jsx• L8-43 yarn.lock• L1-8
Build and test workflow
The test flow treats generated output as part of the validation input. ReScript output, translated locale data, generated React on Rails packs, and test asset bundles must exist before checks that depend on them can give a useful result.
Local full validation
The root package.json defines yarn test as the broad local check. It first removes and rebuilds test packs, then runs linting, and then starts Jest. The test build also builds ReScript code and creates locale data and generated packs through Rails tasks before Shakapacker creates the test bundle.
This full command does not replace the Ruby suite. Run bundle exec rspec or a focused RSpec path when the change affects Rails behavior. Use yarn test:client for a faster JavaScript-only run after the needed generated inputs are already present.
References: package.json• L19-34 lib/…/ci.rake• L6-19 lib/…/ci.rake• L21-62
Continuous integration stages
CI runs three jobs with Ruby 3.4.6 and Node 22. The RSpec job prepares PostgreSQL, loads the test schema, builds the locale and pack inputs, builds ReScript and Shakapacker assets, starts the Node renderer, and runs the Ruby checks under a virtual display. The JavaScript and lint jobs prepare the shared locale and pack inputs before they run their focused task.
The Rake tasks preserve the intended order. ci:rspec builds ReScript before RSpec, ci:js builds ReScript before Jest, and ci:all runs the ReScript build, RSpec, linting, and JavaScript checks as one local CI sequence.
The asset stages are shared with the development build model described in JavaScript and asset build pipeline. The process relationship between Rails, the asset watchers, and the Node renderer is described in Development runtime orchestration.
References: .github/…/rspec_test.yml• L9-18 .github/…/rspec_test.yml• L19-41 .github/…/rspec_test.yml• L73-117 .github/…/js_test.yml• L9-22 .github/…/js_test.yml• L44-56 .github/…/lint_test.yml• L9-22 .github/…/lint_test.yml• L43-55 lib/…/ci.rake• L21-60
Focused test runs
Focused runs help separate a product failure from a missing build or environment input. Use the smallest command that matches the changed boundary, then use the full command before treating the change as complete.
| Goal | Command |
|---|---|
| Run all local JavaScript build, lint, and Jest checks | yarn test |
| Run Jest only | yarn test:client |
| Run all Ruby examples | bundle exec rspec |
| Run the CI-shaped Ruby task | bundle exec rake ci:rspec |
| Run the CI-shaped JavaScript task | bundle exec rake ci:js |
| Run every local CI task | bundle exec rake ci:all |
| Run one Ruby file or example group | bundle exec rspec spec/system/pages_spec.rb |
References: package.json• L26-31 lib/…/ci.rake• L6-14 lib/…/ci.rake• L21-60 .rspec• L1-3
Linting
Linting checks source style and catches problems before they reach the behavior suites. The Rake entry point runs the ReScript build first, then Ruby, JavaScript, and stylesheet checks.
Ruby and stylesheet linting
RuboCop checks Ruby and Rake source with the Rails, RSpec, and performance rule sets. SCSS-Lint checks the client stylesheet tree. The root rake lint command runs both through the grouped lint task, along with the JavaScript lint task.
RuboCop can auto-correct when its task receives the fix option. Treat that mode as a source change and review the result before running validation again.
References: lib/…/linters.rake• L3-33 lib/…/linters.rake• L50-59 .rubocop.yml• L4-27 Gemfile• L73-80 Gemfile.lock• L387-410 Gemfile.lock• L430
JavaScript linting
JavaScript linting has two parts. ESLint checks client JavaScript and JSX while excluding generated output and a few generated or external integration files. Prettier checks JavaScript and JSX formatting.
Run bundle exec rake lint for the CI entry point. For a direct client check, use yarn lint:eslint or yarn lint:prettier. The yarn lint script enables ESLint auto-fix and Prettier write mode, so use the read-only commands when you want validation without edits.
References: package.json• L26-29 lib/…/linters.rake• L35-59 .github/…/lint_test.yml• L43-55
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to ReScript sources must keep the ReScript build before RSpec, Jest, and linting. Generated JavaScript is an input to more than one validation layer.
- Changes to React on Rails registrations, locale generation, or generated packs must keep the Rails generation steps aligned in package.json and the CI workflows.
- Changes to server-rendered pages or React Server Components must be checked at both the HTML or HTTP boundary and the browser boundary. The RSpec request and system suites do not assert the same contract.
- Changes to browser flows must preserve the headless Chrome and virtual-display setup used by system specs in local and CI environments.
- Changes to client source paths must preserve the ESLint exclusions for generated files. Otherwise generated output can create lint failures that do not represent source changes.
- Changes to review-app workflow callers or the
cpflowpin must keep the release SHA, workflow security rules, and lockfile resolution aligned. The contract spec checks these as one release boundary.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Tests run before locale files or generated packs exist | Rails examples can fail during page setup or asset lookup | Run the build steps through yarn test, ci:rspec, or the matching CI job |
| Shakapacker output is stale or absent | System specs can show missing scripts or fail before browser assertions | Rebuild test assets and ReScript output before a focused browser run |
| Node renderer is not ready on port 3800 | Server-rendering checks fail even when Rails routes respond | The RSpec CI job starts the renderer and waits for its port before running RSpec |
| Chrome cannot start without a display or compatible headless mode | System specs fail before they test application behavior | Use the registered headless Chrome driver locally and the Xvfb wrapper in CI |
| A server-rendered route loses its render mode | HTTP checks can pass while the expected HTML is empty or present on the wrong page | Keep request checks for both enabled and disabled server-rendering paths |
| A malformed RSC frame length is emitted | The streamed payload cannot be parsed into usable chunks | Request specs validate the media type, chunk framing, and presence of HTML payload data |
A review-app workflow drifts from the released cpflow contract | Deploy or delete automation can use a stale source or unsafe admission and permission rules | Run the contract spec and keep the cpflow Gemfile and lockfile pins at the released version |
| A promotion action or source checkout uses a different immutable release | Promotion can combine actions and source from different workflow versions | Keep promotion action refs, checkout refs, and setup refs on the same release and run the contract spec |
Key files
| File | Why to read it |
|---|---|
| package.json | Defines the JavaScript test, build, and lint commands and the Jest boundary. |
Gemfile | Pins the Ruby runtime, validation tools, and the cpflow release used by the workflow contract check. |
| Gemfile.lock | Records the resolved Ruby validation toolchain and dependency versions used by the checks. |
| yarn.lock | Records the resolved JavaScript validation toolchain used by the frozen CI install. |
lib/tasks/ci.rake | Defines the ordered Rake tasks used by local CI-shaped validation. |
lib/tasks/linters.rake | Connects Ruby, JavaScript, and stylesheet linting to rake lint. |
| spec/rails_helper.rb | Defines the Rails test environment, asset compilation hook, browser driver, and session cleanup. |
| spec/…/server_render_check_spec.rb | Shows the HTTP contract for server-rendered and client-only pages. |
| spec/…/server_components_spec.rb | Shows the HTTP and stream-format contract for React Server Components. |
| spec/…/add_new_comment_spec.rb | Shows cross-rendering-mode browser coverage for the main comment submission flow. |
| spec/…/rescript_spec.rb | Shows browser coverage for ReScript tabs, safe comment rendering, and valid and invalid form submission. |
| spec/…/server_components_demo_spec.rb | Shows browser coverage for live activity, error recovery, and the Server Components page. |
| spec/cpflow_review_app_contract_spec.rb | Shows the Ruby checks for release workflow alignment and security boundaries. |
| client/…/CommentList.spec.jsx | Shows isolated React component coverage for list output and error display. |
bin/check-cpflow-review-app-contract | Defines the release and workflow contract that the RSpec examples exercise. |
| .github/…/rspec_test.yml | Shows the full environment and build order required for browser and server-rendering checks. |
| .github/…/js_test.yml | Shows the focused JavaScript CI preparation and execution path. |
| .github/…/lint_test.yml | Shows the focused lint CI preparation and execution path. |