Skip to content

Feature ETP-4959: Add component test runner to etendo-go-core - #138

Open
sebastianbarrozo wants to merge 2 commits into
epic/ETP-3504from
feature/ETP-4959
Open

Feature ETP-4959: Add component test runner to etendo-go-core#138
sebastianbarrozo wants to merge 2 commits into
epic/ETP-3504from
feature/ETP-4959

Conversation

@sebastianbarrozo

Copy link
Copy Markdown
Collaborator

ETP-4959 — Component test runner for etendo-go-core + LoginStep auth-continuation coverage

https://etendoproject.atlassian.net/browse/ETP-4959

Stacked on #137 (ETP-4958). Branched from feature/ETP-4958 because these tests assert the contract that PR introduces. Merge #137 first; this diff then reduces to the test infrastructure alone.

Why

ETP-4958 fixed a user-visible dead end: LoginStep's SSO branch silently skipped the caller-owned onAuthenticated continuation. Its unit tests cover the extracted completeAuthentication() helper, but nothing asserted that the two authentication branches actually route through it — you could re-inline the buggy logic into either branch and every test would still pass.

The blocker was infrastructure. packages/etendo-go-core ran only node --test, which cannot parse .jsx, so the original regression test degraded into a source-text assert.match() against LoginStep.jsx. That is what let the bug ship.

Changes

File Change
packages/etendo-go-core/vitest.config.js New. Vitest + jsdom, mirroring packages/app-shell-core. Includes src/**/*.vitest.{js,jsx}.
packages/etendo-go-core/test/vitest-setup.js New. jest-dom matchers + jsdom scroll stubs. Lives under test/ so it stays out of the published tarball (files: ["src", …]).
packages/etendo-go-core/package.json test:vitest script + Testing Library / jsdom / vitest devDependencies.
…/src/onboarding/steps/__tests__/LoginStep.vitest.jsx New. 6 component tests rendering the real LoginStep.
.github/workflows/test.yml New step running the suite.
Makefile make test now also runs both etendo-go-core suites (it previously ran neither).
CLAUDE.md Documented the two-runner split, when to reach for each, and the rule that every Vitest suite needs its own CI step.

What the tests cover

The real component is rendered; only genuine external boundaries are stubbed — the SSO provider SDK (sso.js) and the HTTP layer (api.js). The SSO mock captures the onCredential callback the component hands the provider, so a test can fire a successful credential without a real Google button.

  • SSO + onAuthenticated → callback invoked with (token, account), routeByEnvironments not called.
  • SSO → session persisted to localStorage (token and sf_platform_auth_method: 'sso') before the caller is handed control.
  • SSO without a caller → default routeByEnvironments(token) preserved.
  • Password + onAuthenticated → same continuation as SSO.
  • Password without a caller → default routing preserved.
  • Both branches produce an identical outcome — the regression was precisely that they diverged, so this asserts ssoCaller.mock.calls equals passwordCaller.mock.calls rather than testing each in isolation.

Verification

  • npm run test:vitest --workspace=packages/etendo-go-core: 6 passed.
  • npm test --workspace=packages/etendo-go-core: 188 passed (unchanged).
  • Mutation-checked. Re-inlining the exact pre-fix SSO call (handleAuthSuccess(data.token, data.account, { authMethod: 'sso' }), bypassing the helper) makes 3 of the 6 fail, including the divergence test. Restored → 6/6. This is the guarantee the old source-text test could not give.
  • Pre-push gate green (conflict check, data-testid, SonarQube).

Note on scope — app-shell-core is deliberately not wired in

While wiring CI I found that no automated gate in this repo has ever run Vitest: test.yml runs npm test per workspace (node --test only), no workflow invokes make test, and .githooks/pre-push runs no unit tests at all. packages/app-shell-core's 687-test suite has consequently rotted and is red on epic/ETP-3504 today — 3 orphaned files importing components that no longer exist, plus 2 real AddLineButton failures.

Wiring it in here would block this PR on unrelated breakage, so only the new etendo-go-core suite is added to CI. The app-shell-core cleanup is ETP-4961.

LoginStep carried two independent copies of the post-authentication
continuation, one per authentication branch. When the caller-owned
onAuthenticated prop was introduced only the password copy was updated, so
an SSO login on the invitation page persisted the session and then stopped:
the caller never got its callback and the user was stranded on the login
form with an unconsumed invitation token.

Extract the continuation into a single exported helper that both branches
call, so the two paths can no longer diverge. Add the missing onAuthenticated
entry to the handleSsoProviderLogin dependency array, which otherwise
captured a stale callback for any caller that memoizes config.

Replace the previous source-text assert.match regression test with
behavioural unit tests covering routing suppression, persistence-before-
handover ordering, forwarded arguments, error propagation and the
no-continuation default.
packages/etendo-go-core ran only node --test, which cannot parse .jsx. That
is why the ETP-4958 regression test degraded into a source-text
assert.match against LoginStep.jsx: a change detector that passes even
when the code path is unreachable, and that asserts nothing about the
wiring between the two authentication branches and the shared
continuation helper.

Add a Vitest + jsdom + Testing Library setup mirroring app-shell-core, and
cover the ETP-4958 contract at component level by rendering the real
LoginStep and driving each branch to a successful login: caller-owned
continuation invoked with the authenticated session, no environment
routing when the caller takes over, default routing preserved otherwise,
and both branches producing an identical outcome.

Wire the suite into .github/workflows/test.yml and make test. The workflow
runs npm test per workspace, which is node --test only, so a Vitest suite
without its own step would never execute. Only this package's suite is
wired in; app-shell-core has the same gap but is red on the epic and is
tracked separately under ETP-4961.
@github-actions

Copy link
Copy Markdown
Contributor

Copilot PR Review

Outcome: Comment only
No merge-blocking issues detected, but the warnings below should be reviewed.

Warnings

  • New npm dependency added (NEW_DEPENDENCY)
    packages/etendo-go-core/package.json adds:
  • @testing-library/dom@^10.4.1 (devDependencies)
  • @testing-library/jest-dom@^6.9.1 (devDependencies)
  • @testing-library/react@^16.3.2 (devDependencies)
  • @testing-library/user-event@^14.6.1 (devDependencies)
  • @vitejs/plugin-react@^4.3.0 (devDependencies)
  • jsdom@^29.1.1 (devDependencies)
  • vitest@^4.1.5 (devDependencies)
    Justify new dependencies in the PR description and prefer Node.js built-ins where possible.

@sonarscanetendo

Copy link
Copy Markdown

Passed Quality Gate passed

Issues

Measures

Project ID: etendosoftware_schema_forge_core_976a1e0b-4b24-4757-a2f4-8afa9a5e0289

View in SonarQube

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.

1 participant