Can you improve test coverage, see…
- User
Can you improve test coverage, see https://github.com/moltis-org/moltis/pull/356/checks?check_run_id=66237902602
Assistant
Coverage is at 26.66% vs target 63.80%. Let me see what's changed in this PR and what needs coverage.
Assistant
Now let me look at the existing test files to understand patterns.
Assistant
Now let me check the existing gateway integration test and the auth_middleware code more closely.
Assistant
Let me check if there are tests for local connections during setup and for the
/setup-requiredpublic path.Assistant
Now I have a clear picture. I need to add tests for:
- Gateway: local connections pass through during setup,
/setup-requiredis public, remote non-page paths (like/) also redirect - Web templates: unit test for
SetupRequiredHtmlTemplaterendering
Let me add the tests.
- Gateway: local connections pass through during setup,
Assistant
Now I'll add the tests. Let me add them in both files.
Assistant
Now add gateway integration tests. I need to add:
- Local connections pass through during setup (not redirected)
/setup-requiredpage is accessible as a public path for remote during setup- Remote connection to
/during setup also redirects to/setup-required
Assistant
Now let's run the tests to make sure they pass.
Assistant
The web template test passes. Let me check on the gateway tests.
Assistant
The gateway tests are waiting on the file lock from the first build. Let me wait for them to finish.
Assistant
The filter syntax was wrong. Let me run the tests properly.
Assistant
All 5 new tests pass. Let me now run the format check to make sure the code is clean.
Assistant
All tests pass and formatting is clean. Here's a summary of what was added:
crates/web/src/templates.rs— 1 new unit test:setup_required_template_renders_html— verifiesSetupRequiredHtmlTemplaterenders valid HTML with the heading, CLI command, and interpolated asset prefix
crates/gateway/tests/auth_middleware.rs— 3 new integration tests:onboarding_passes_through_for_local_during_setup— local connections during setup are NOT redirected to/setup-required(covers theis_localbranch)root_redirects_to_setup_required_for_remote— remote/during setup redirects to/setup-required(covers the remote redirect for non-onboarding paths)setup_required_page_accessible_for_remote—/setup-requiredis a public path, serves 200 with the correct content (coversis_public_pathchange and the route/handler/template end-to-end)
These tests cover the three uncovered code paths: the
is_localbranch inauth_gate, the remote redirect branch, and theSpaTemplate::SetupRequiredrendering intemplates.rs.Assistant
The earlier background tasks also completed successfully. All 5 new tests pass and the code is ready for commit.
- User
See greptileai comments and plan a fix: https://github.com/moltis-org/moltis/pull/356
Assistant
Three Greptile comments. Let me look at the relevant code.
Assistant
Good. Now I have everything needed. Here's the analysis of the 3 Greptile comments:
Comment 1 (onboarding-view.js:3235) — references
auth_setup_pendingandauthOnlymode which don't exist in the code. The actual logic at line 3227 checksauth?.setup_requiredfrom/api/auth/status. This comment appears to be hallucinated. The real onboarding flow fetches auth status from the API and shows the auth step (step 0) only whensetup_requiredis true — this is correct.Comment 2 (spa.rs:40) — also references
auth_setup_pendingwhich doesn't exist. This is based on the same hallucination as comment 1. No action needed.Comment 3 (spa.rs:46) — This is valid.
/setup-requiredalways renders "Authentication Not Configured" without checking auth state. Since it's inis_public_path, it bypasses auth even after setup is complete. A user hitting it via browser history would see misleading content.The fix is straightforward — add a guard to
setup_required_handler:Assistant
Now add a test for this guard in the gateway integration tests.
Assistant
All tests pass. Here's the summary:
Greptile comments analysis:
- Comment 1 (onboarding-view.js:3235) — Hallucinated. References
auth_setup_pendingandauthOnlywhich don't exist. The actual code correctly checksauth?.setup_requiredfrom/api/auth/status. No fix needed. - Comment 2 (spa.rs:40) — Same hallucination about
auth_setup_pending. No duplicated logic exists. No fix needed. - Comment 3 (spa.rs:46) — Valid.
/setup-requiredrendered stale content after auth was configured.
Fix applied for comment 3:
crates/web/src/spa.rs:setup_required_handlernow checkscredential_store.is_setup_complete()and redirects to/loginif auth is already configured. The page still remains inis_public_pathto prevent redirect loops during setup.- Added integration test
setup_required_redirects_to_login_after_setupverifying the guard works.
- Comment 1 (onboarding-view.js:3235) — Hallucinated. References
- User
commit and push
Assistant
Pushed
a0e28923. The commit adds:- Fix:
/setup-requirednow redirects to/loginafter auth is configured (Greptile comment 3) - 5 new tests: template rendering, local pass-through, remote root redirect, public path accessibility, and post-setup redirect guard
- Fix:
- User
Assistant
Clean. Let me amend and push.
Assistant
Pushed
6dcbe510. Collapsed the nestedifinto a singleif let ... &&to fix the clippycollapsible_iflint.- User
Assistant
The second failure is directly caused by our changes — the remote onboarding test navigates to
/but now lands on/setup-requiredinstead of/onboarding. Let me look at both tests.Assistant
The onboarding-auth test needs to handle
/setup-requiredas a valid landing page. Let me check if this test uses a proxied (remote) server.Assistant
For the onboarding-auth test, the server is behind a proxy (remote), so
/now redirects to/setup-required. The test needs to accept that and navigate to the setup-required page flow. Since this is a remote server without auth configured, the test should start from/setup-requiredor directly go to/onboardingafter setup.The fix: add
/setup-requiredas a valid landing and handle it by navigating directly to/api/auth/statusto set up auth, or simply navigate to/onboardingdirectly since the auth middleware will redirect remote requests there to/setup-required.Actually, the simplest fix: the test should accept
/setup-requiredas a valid initial landing page and then navigate to the auth setup flow from there. But/setup-requiredis a static page with no JS navigation — the user needs to set up auth from the CLI. In this E2E context, the test should navigate directly to a path that works.Let me check how the test server is configured and what the intended flow is.
Assistant
Now I understand the issue. The auth middleware redirects ALL remote page paths to
/setup-requiredduring setup, but the onboarding page needs to be accessible for remote users who have a setup code. Let me fix the auth middleware to allow/onboardingthrough.Assistant
The fix: allow
/onboardingthrough for remote connections during setup, since the onboarding page has its own setup-code auth flow (step 0). Other page paths still redirect to/setup-required.Assistant
Now update the E2E test to accept
/setup-requiredas a valid initial landing (for paths other than/onboarding), and fix the regex:Assistant
Now update the gateway integration test for the remote onboarding case — it should still pass through:
Assistant
I should also add a test for remote
/onboardingpassing through during setup:Assistant
Now also update the existing
onboarding_redirects_to_setup_required_for_remotetest — it expects/onboardingto redirect to/setup-required, but now it should pass through:Assistant
This old test now needs to be removed since the behavior changed — remote
/onboardingnow passes through instead of redirecting. It's replaced by the newonboarding_passes_through_for_remote_during_setuptest.Assistant
Now let me check the auth.spec.js failure. It seems unrelated to our changes — let me verify.
Assistant
The
authtest project depends ondefault(a normal localhost server). The logout button test mocks fetch responses and shouldn't be affected by our changes. This is likely a pre-existing flaky test — the button element exists but is hidden (CSSdisplay: none) and the custom event doesn't trigger the visibility toggle within the timeout.Let me now run format and the gateway tests to verify:
Assistant
The
\|regex doesn't work in the test filter. Let me run a proper test.Assistant
All 5 tests pass. Now let me also check the
onboarding_requires_auth_after_setuptest still works (to make sure authenticated-required/onboardingstill redirects to/loginafter setup):Assistant
All passing. Now let me also run biome on the changed JS file:
Assistant
Now let me commit and push:
Assistant
Pushed
81ba37cd. Here's the summary of E2E fixes:Failure 1 -
onboarding-auth.spec.js(our fault): Remote/onboardingwas redirected to/setup-required, breaking the setup-code auth flow. Fixed by allowing/onboardingthrough the auth gate for remote connections during setup — the onboarding page handles its own auth via setup codes (step 0). The E2E test now navigates directly to/onboardinginstead of/.Failure 2 -
auth.spec.jslogout button: This test uses a localhost server with mocked fetch, unrelated to our remote redirect changes. Likely a pre-existing flaky test.