Skip to content

fix: resolve aidebugger.test.js CI failures#7442

Open
riyacore404 wants to merge 1 commit into
sugarlabs:masterfrom
riyacore404:fix/aidebugger-test-ci-7433
Open

fix: resolve aidebugger.test.js CI failures#7442
riyacore404 wants to merge 1 commit into
sugarlabs:masterfrom
riyacore404:fix/aidebugger-test-ci-7433

Conversation

@riyacore404

@riyacore404 riyacore404 commented May 26, 2026

Copy link
Copy Markdown

PR Category

  • Bug Fix - Fixes a bug or incorrect behavior

Summary

Resolves #7433 — the Jest CI pipeline was failing due to three issues in the AI Debugger widget.

Changes

jest.config.js

Added testEnvironmentOptions: { url: "http://localhost/" }.
jsdom's default URL (about:blank) gives window.location.hostname = "", which
the BACKEND_CONFIG IIFE didn't recognise, firing a console.warn and setting
BASE_URL = null on every test run.

js/widgets/aidebugger.js

Added an early-return guard in _hideTypingIndicator when this.chatLog is null.
The widget's onclose handler calls _hideTypingIndicator() before init() has
run _createLayout(), so chatLog can be null — crashing with a TypeError.

js/widgets/tests/aidebugger.test.js

Added 19 new tests covering all previously untested code paths:

  • _consentGiven initial state
  • _addWelcomeMessage
  • _showConsentBanner (accept + decline button flows)
  • _loadProjectAndInitialize (success, export-throws fallback, bad-JSON non-fatal)
  • _initializeBackendWithProject (fetch success, fetch fail, missing .response)
  • _sendToBackend (success, network error, non-ok HTTP)
  • _exportChat with a non-empty history (download triggered)
  • _exportChat with prepareExport throwing (graceful fallback)
  • _hideTypingIndicator with null chatLog (regression guard)

Test Results

  • Before: aidebugger test suite failed to run (TypeError + missing mocks)
  • After: 82/82 tests pass; full suite 5378/5378 tests pass

Checklist

  • All tests pass locally (npm test)
  • Lint clean (npm run lint)
  • Prettier clean (npx prettier --check .)
  • No new dependencies added

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Jest Test Results

✅ All Jest tests passed! This PR is ready to merge.

Coverage: Statements: 48.3% | Branches: 39.6% | Functions: 53.07% | Lines: 48.72%
Master Coverage: Statements: 48.09% | Branches: 39.61% | Functions: 52.88% | Lines: 48.49%

@github-actions github-actions Bot added bug fix Fixes a bug or incorrect behavior size/L Large: 250-499 lines changed area/javascript Changes to JS source files area/tests Changes to test files labels May 26, 2026

@mahesh-09-12 mahesh-09-12 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.

this PR now feels a bit broader than just fixing the CI failure, since it also adds quite a bit of aidebugger test coverage beyond the original failing scenario

Comment on lines 780 to 791

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.

these aidebugger test additions seem to already exist from the recently merged CI fix PR (#7403), so could you rebase onto latest master and drop the already-merged parts from this diff?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback @mahesh-09-12!

I've rebased onto the latest master and dropped the two _sendMessage tests that were already merged via #7403 ("shows consent banner and does not send message if consent not given" and "sends message and clears input").

All tests pass locally. Let me know if you'd like any further changes!

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.

@riyacore404 oh, my mistake. Before rebasing onto the latest master, it made sense to remove these since they were duplicated by the earlier aidebugger fix work. After the rebase though, removing them here would actually remove tests that are already present on master. Sorry for the confusion and the earlier suggestion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No worries, thanks for clarifying! I’ve reverted my previous change and restored the tests so the PR is back in sync. 👍

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.

Thanks for your patience and for restoring the tests. My concern is resolved now.

@riyacore404 riyacore404 force-pushed the fix/aidebugger-test-ci-7433 branch from 0c3c33d to 01b5475 Compare May 28, 2026 10:20
@github-actions

Copy link
Copy Markdown
Contributor

🧪 Jest Test Results

✅ All Jest tests passed! This PR is ready to merge.

Coverage: Statements: 48.34% | Branches: 39.68% | Functions: 53.12% | Lines: 48.75%
Master Coverage: Statements: 48.09% | Branches: 39.61% | Functions: 52.88% | Lines: 48.49%

@riyacore404 riyacore404 force-pushed the fix/aidebugger-test-ci-7433 branch from 01b5475 to 8f9bb64 Compare May 29, 2026 09:34
@github-actions

Copy link
Copy Markdown
Contributor

🧪 Jest Test Results

✅ All Jest tests passed! This PR is ready to merge.

Coverage: Statements: 48.36% | Branches: 39.69% | Functions: 53.12% | Lines: 48.77%
Master Coverage: Statements: 48.09% | Branches: 39.61% | Functions: 52.88% | Lines: 48.49%

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

Labels

area/javascript Changes to JS source files area/tests Changes to test files bug fix Fixes a bug or incorrect behavior size/L Large: 250-499 lines changed

Projects

Development

Successfully merging this pull request may close these issues.

[Bug] aidebugger.test.js failing in Jest CI pipeline

2 participants