Skip to content

test: add unit and E2E tests for settings toggles - #850

Closed
oyi77 wants to merge 5 commits into
cheaper-inference:mainfrom
oyi77:feat/cache-page-prompt-cache-tracking
Closed

oyi77 wants to merge 5 commits into
cheaper-inference:mainfrom
oyi77:feat/cache-page-prompt-cache-tracking

Conversation

@oyi77

@oyi77 oyi77 commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add tests for debug mode and sidebar visibility settings toggles, plus bug fix for issue #848.

Files Changed

Test Coverage

  • Unit tests: PATCH debugMode=true/false, hiddenSidebarItems array, combined updates
  • E2E tests: Debug toggle on/off, Sidebar visibility toggle, Settings persistence after reload

Bug Fix Issue #848

  • Problem: NVIDIA API returned 400 Validation error for prompt_cache_key
  • Cause: prompt_cache_key was being injected for ALL OpenAI-format providers
  • Fix: Added providerSupportsCaching check before injecting prompt_cache_key
  • Only providers in CACHING_PROVIDERS set receive prompt_cache_key: claude anthropic zai qwen deepseek

Related

oyi77 added 2 commits March 31, 2026 05:54
Tests cover:
- PATCH debugMode=true/false
- PATCH hiddenSidebarItems with array values
- Combined updates with both fields
Tests cover:
- Debug mode toggle on/off
- Sidebar visibility toggle
- Settings persistence after page reload

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces new end-to-end tests for settings toggles and unit tests for the settings API. The review feedback highlights several critical issues: unit tests contain incorrect assertions and missing await calls for asynchronous functions, and they lack proper state isolation between tests. Additionally, the E2E tests should be refactored to remove conditional logic and hardcoded timeouts, utilizing Playwright's web-first assertions instead for better reliability.

Comment on lines +8 to +12
const result = await updateSettings({ debugMode: true });
assert.strictEqual(result.ok, true, "updateSettings should return ok: true");

const settings = getSettings();
assert.strictEqual(settings.debugMode, true, "debugMode should be true");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test has two correctness issues that will cause it to fail:

  1. updateSettings returns the updated settings object directly (as seen in src/app/api/settings/route.ts), so result.ok will be undefined and the assertion will fail.
  2. getSettings() is an asynchronous function but is called here without await. This returns a Promise, making settings.debugMode undefined.

This pattern is repeated throughout the file and should be corrected in all test cases.

Suggested change
const result = await updateSettings({ debugMode: true });
assert.strictEqual(result.ok, true, "updateSettings should return ok: true");
const settings = getSettings();
assert.strictEqual(settings.debugMode, true, "debugMode should be true");
const result = await updateSettings({ debugMode: true });
assert.strictEqual(result.debugMode, true, "updateSettings should return the updated settings");
const settings = await getSettings();
assert.strictEqual(settings.debugMode, true, "debugMode should be true");

Comment thread tests/e2e/settings-toggles.spec.ts Outdated
Comment on lines +12 to +18
if (await debugToggle.isVisible({ timeout: 3000 }).catch(() => false)) {
const initialState = await debugToggle.isChecked();
await debugToggle.click();
await page.waitForTimeout(500);
const newState = await debugToggle.isChecked();
expect(newState).not.toBe(initialState);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Avoid using conditional logic (if) to wrap assertions in E2E tests. If the element is not found, the test should fail to indicate a regression or UI change. Additionally, replace page.waitForTimeout with Playwright's web-first assertions like toBeChecked(), which automatically wait for the expected state and are more resilient to timing issues.

      await expect(debugToggle).toBeVisible();
      const initialState = await debugToggle.isChecked();
      await debugToggle.click();
      await expect(debugToggle).toBeChecked({ checked: !initialState });

import assert from "node:assert/strict";
import { getSettings, updateSettings } from "../../src/lib/localDb.ts";

describe("Settings API - debugMode and hiddenSidebarItems", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The unit tests modify the global settings state in the database without resetting it between tests. This can lead to test interference and non-deterministic results. Consider adding a beforeEach hook to reset the settings to a default state before each test.

@kilo-code-bot

kilo-code-bot Bot commented Mar 31, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 3
Issue Details (click to expand)

WARNING

File Line Issue
tests/unit/settings-api.test.mjs 5 Tests modify global settings state without resetting between tests, causing potential test interference and non-deterministic results.

SUGGESTION

File Line Issue
tests/e2e/settings-toggles.spec.ts 13 Unused variable initialState - consider removing or using it for assertions
tests/e2e/settings-toggles.spec.ts 29 Unused variable initialState - consider removing or using it for assertions
tests/e2e/settings-toggles.spec.ts 43 Unused variable wasChecked - consider removing or using it for assertions
Resolved Issues

The following issues from the previous review have been fixed:

File Line Previous Issue Status
tests/unit/settings-api.test.mjs 12 result.ok undefined and missing await on getSettings() ✅ Fixed
tests/e2e/settings-toggles.spec.ts 18 Conditional if wrappers around assertions ✅ Fixed
Files Reviewed (4 files)
  • CONTRIBUTING.md - documentation added
  • open-sse/handlers/chatCore.ts - 1 fix (caching logic improvement)
  • tests/unit/settings-api.test.mjs - 1 issue (warning)
  • tests/e2e/settings-toggles.spec.ts - 3 suggestions

Fix Link

Fix these issues in Kilo Cloud

- Unit tests: fix async/await for getSettings, use direct db functions
- E2E tests: remove conditional logic, use Playwright auto-waiting assertions
import assert from "node:assert/strict";
import { getSettings, updateSettings } from "../../src/lib/db/settings.ts";

describe("Settings API - debugMode and hiddenSidebarItems", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Tests modify global settings state without resetting between tests - this can cause test interference and non-deterministic results. Consider adding a beforeEach hook to reset settings to a default state before each test.

oyi77 added 2 commits March 31, 2026 11:21
Add section documenting:
- Debug Mode toggle (Settings → Advanced)
- Sidebar Visibility toggle (Settings → General)
Only inject prompt_cache_key for providers that support prompt caching
(Claude, Anthropic, ZAI, Qwen, DeepSeek). This fixes issue cheaper-inference#848 where
NVIDIA API rejected the parameter.

await expect(debugToggle).toBeVisible({ timeout: 5000 });

const initialState = await debugToggle.isChecked();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Unused variable initialState - consider removing or using it for assertions


await expect(sidebarToggle).toBeVisible({ timeout: 5000 });

const initialState = await sidebarToggle.isChecked();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Unused variable initialState - consider removing or using it for assertions


await expect(debugToggle).toBeVisible({ timeout: 5000 });

const wasChecked = await debugToggle.isChecked();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Unused variable wasChecked - consider removing or using it for assertions

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks @oyi77 for this great contribution! 🎉 The improvements have been integrated into the release/v3.4.0 branch and will be part of the next release. We appreciate your effort!

@diegosouzapw diegosouzapw mentioned this pull request Apr 22, 2026
This was referenced Apr 30, 2026
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
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.

2 participants