Skip to content

Tests: Add unit test coverage for Logging\AI_Request_Log_Page - #1038

Merged
dkotter merged 1 commit into
WordPress:developfrom
noruzzamans:test/ai-request-log-page-unit-tests
Sep 17, 2026
Merged

dkotter merged 1 commit into
WordPress:developfrom
noruzzamans:test/ai-request-log-page-unit-tests

Conversation

@noruzzamans

@noruzzamans noruzzamans commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What?

Adds unit and integration test coverage for WordPress\AI\Logging\AI_Request_Log_Page in tests/Integration/Includes/Logging/AI_Request_Log_PageTest.php.

Why?

The logging component provides comprehensive tests for AI_Request_Log_Manager, AI_Request_Log_Repository, AI_Request_Log_Controller, Log_Data_Extractor, and Logging_Http_Transporter, but lacked dedicated test coverage for AI_Request_Log_Page.

Adding this test suite verifies that:

  • The admin Tools submenu page ai-request-logs is properly registered with capability manage_options and hooks into load-{$page_hook} for authorized users.
  • Unauthorized users (e.g. subscribers or non-logged-in users) do not receive the load-{$page_hook} action.
  • The on_load() method correctly attaches enqueue_assets to admin_enqueue_scripts.
  • enqueue_assets() enqueues the required scripts (ai_ai_request_logs), styles, handles the bundled DataViews fallback stylesheet conditionally, sets script translations, and localizes essential settings (RequestLogsSettings, REST endpoints, initial summary/filter state, connectors URL, and provider metadata).
  • render_page() correctly checks manage_options capability, rendering the root container <div id="ai-request-logs-root"></div> for administrators and outputting nothing for unauthorized users.
  • get_provider_metadata() correctly filters registered connectors for ai_provider entries, identifies client vs. cloud provider types, and extracts logo and credentials URLs.

How?

  • Added tests/Integration/Includes/Logging/AI_Request_Log_PageTest.php covering:
    1. test_constructor_initializes_instance: Verifies constructor instantiates AI_Request_Log_Page.
    2. test_register_menu_adds_submenu_page_for_authorized_user: Verifies submenu page registration under tools.php with manage_options capability and load-{$page_hook} action hook for administrators.
    3. test_register_menu_does_not_hook_on_load_when_user_lacks_capability: Verifies load-{$page_hook} is not registered when user lacks permissions.
    4. test_on_load_hooks_enqueue_assets_action: Verifies admin_enqueue_scripts hook registration.
    5. test_enqueue_assets_enqueues_scripts_and_styles: Verifies script and style enqueuing including the bundled DataViews fallback style.
    6. test_enqueue_assets_does_not_enqueue_dataviews_fallback_if_wp_dataviews_registered: Verifies DataViews fallback style is skipped when wp-dataviews is registered in core.
    7. test_enqueue_assets_localizes_settings_data: Verifies localized JavaScript configuration object and REST route definitions.
    8. test_render_page_renders_container_for_authorized_user: Verifies admin UI container output for authorized administrators.
    9. test_render_page_outputs_nothing_for_unauthorized_user: Verifies empty output for unauthorized roles (subscribers).
    10. test_render_page_outputs_nothing_when_logged_out: Verifies empty output for guests/logged-out visitors.
    11. test_get_provider_metadata_filters_and_formats_connectors: Verifies provider metadata formatting, filtering out non-AI connectors, and distinguishing client vs cloud auth methods.
    12. test_get_provider_metadata_falls_back_to_slug_when_name_missing: Verifies fallback to connector slug when display name is missing.
    13. test_get_provider_metadata_ignores_invalid_connector_data: Verifies graceful omission of malformed connector registry entries.

Use of AI Tools

AI assistance: Yes
Model(s): Gemini 3.8 Flash High
Used for: Analyzing test gaps in the Logging component, scaffolding test structure, and ensuring strict adherence to VIP Go and WordPress coding standards. Final test implementation and assertions were reviewed, refined, and validated by me.

Testing Instructions

  1. Run coding standards:
    composer lint
  2. Run static analysis:
    composer phpstan
  3. Run JS/TS checks:
    npm run typecheck && npm run lint:js
  4. Verify that tests/Integration/Includes/Logging/AI_Request_Log_PageTest.php passes cleanly.

Changelog Entry

Developer - Added unit test coverage for Logging\AI_Request_Log_Page.

Open WordPress Playground Preview

Developer - Added unit test coverage for Logging\AI_Request_Log_Page.

Co-authored-by: noruzzamans <noruzzaman@git.wordpress.org>
@noruzzamans
noruzzamans force-pushed the test/ai-request-log-page-unit-tests branch from 954a4f4 to 04723ee Compare September 17, 2026 04:29
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.72%. Comparing base (a254b06) to head (04723ee).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #1038      +/-   ##
=============================================
+ Coverage      80.23%   80.72%   +0.48%     
  Complexity      2998     2998              
=============================================
  Files            124      124              
  Lines          11978    11978              
=============================================
+ Hits            9611     9669      +58     
+ Misses          2367     2309      -58     
Flag Coverage Δ
unit 80.72% <ø> (+0.48%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@noruzzamans
noruzzamans marked this pull request as ready for review September 17, 2026 04:50
@noruzzamans
noruzzamans requested a review from a team September 17, 2026 04:50
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: noruzzamans <noruzzaman@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@dkotter dkotter added this to the 1.4.0 milestone Sep 17, 2026
@dkotter
dkotter merged commit fb41c70 into WordPress:develop Sep 17, 2026
34 checks passed
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