GH#699: test(core): write unit tests for 6 untested Core classes#703
GH#699: test(core): write unit tests for 6 untested Core classes#703superdav42 merged 3 commits intomainfrom
Conversation
Closes #699 Adds PHPUnit tests for: - ChangeLogger (begin/end/is_active, register hooks, log_change, get_changes) - ContextProviders (register, get_context, provider callbacks) - Export (export_data, import_data, format handling) - FreshInstallDetector (is_fresh_install, mark_installed, option management) - OnboardingInterview (question flow, answer storage, completion state) - OnboardingManager (register, run_interview, complete, reset) Each test covers constructor/static init, main public methods, and error paths.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 13 minutes and 27 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR adds comprehensive PHPUnit test suites for six previously untested Core classes: ChangeLogger, ContextProviders, Export, FreshInstallDetector, OnboardingInterview, and OnboardingManager. Each test file validates public methods, error handling paths, state management, and WordPress hook integrations across 2,217 total lines of test code. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~55 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/GratisAiAgent/Core/ChangeLoggerTest.php`:
- Around line 26-36: The tests only call ChangeLogger::end() but never clear the
custom table, so state leaks between tests; update the ChangeLoggerTest set_up()
and tear_down() methods to also truncate/delete all rows from the
gratis_ai_agent_changes_log table (after calling ChangeLogger::end() or before
starting each test) so each test starts with a clean table; reference the
ChangeLoggerTest::set_up, ChangeLoggerTest::tear_down methods and keep the
ChangeLogger::end() calls while adding a DB truncate/delete of
gratis_ai_agent_changes_log to both setup and teardown.
In `@tests/GratisAiAgent/Core/FreshInstallDetectorTest.php`:
- Around line 179-199: The test only asserts
FreshInstallDetector::isFreshInstall() returns a bool but doesn't verify that
default-titled posts/pages are ignored; update the test to call
FreshInstallDetector::getStatus() (or otherwise access the returned status
object) and assert that the has_real_posts and has_real_pages flags are false
after creating the 'Hello world!' post and 'Sample Page' page so the behavior is
explicitly checked; keep the existing factory creation of posts/pages and
replace or augment the final assertion with assertions on
getStatus()->has_real_posts and getStatus()->has_real_pages.
In `@tests/GratisAiAgent/Core/OnboardingInterviewTest.php`:
- Around line 325-363: Update the tests that currently only check the return
value to assert database state: after calling OnboardingInterview::save_answers
in test_save_answers_skips_blank_answers, query the
{$wpdb->prefix}gratis_ai_agent_memories table (using global $wpdb) to assert
that a memory exists for 'primary_goal' with the exact content 'Real answer' and
that no row exists for 'target_audience' (or that stored answer is not
whitespace-only); in test_save_answers_stores_memories assert that at least two
rows were inserted and/or assert presence of specific memories for
'primary_goal' and 'target_audience' with their expected text; in
test_save_answers_uses_fallback_label_for_unknown_id assert that a memory row
was inserted for the unknown_question_id answer and that its label uses the
fallback text (not the key), confirming the fallback label was stored in the
gratis_ai_agent_memories table; use OnboardingInterview::save_answers, $wpdb and
the table name to locate rows and assert their content/counts.
- Around line 26-37: The fixture must also clear the stored memories to prevent
test leakage: in both set_up() and tear_down(), after calling
OnboardingInterview::reset() (and alongside delete_option(
SiteScanner::STATUS_OPTION ) in tear_down()), call
delete_option('gratis_ai_agent_memories') so any memory rows/options written by
save_answers() are removed between tests.
In `@tests/GratisAiAgent/Core/OnboardingManagerTest.php`:
- Around line 189-203: The test currently only asserts
OnboardingManager::TRIGGERED_OPTION was set but doesn't verify the "fresh site"
branch scheduled a scan; after calling OnboardingManager::maybe_trigger() add an
assertion that SiteScanner::CRON_HOOK was scheduled (e.g., check
wp_next_scheduled for SiteScanner::CRON_HOOK is truthy) to prove the cron job
side effect; keep the existing cleanup of SiteScanner::STATUS_OPTION and ensure
the fixture leaves memories empty so the scheduled-cron assertion validates the
fresh-path behavior.
- Around line 27-39: The tests leave rows in the memories table causing
order-dependent failures; update the test setup/teardown to clear the memories
table so each test starts clean: inside set_up() and/or tear_down() (alongside
OnboardingManager::reset() and OnboardingInterview::reset()) execute the code to
truncate or delete all rows from the memories table (e.g., via the memories
model or DB connection used in tests) so
test_maybe_trigger_marks_triggered_when_memories_exist() does not affect other
maybe_trigger() tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fa646499-bc73-4394-9b7d-702dea49d162
📒 Files selected for processing (6)
tests/GratisAiAgent/Core/ChangeLoggerTest.phptests/GratisAiAgent/Core/ContextProvidersTest.phptests/GratisAiAgent/Core/ExportTest.phptests/GratisAiAgent/Core/FreshInstallDetectorTest.phptests/GratisAiAgent/Core/OnboardingInterviewTest.phptests/GratisAiAgent/Core/OnboardingManagerTest.php
- ChangeLoggerTest: truncate changes_log table in setUp/tearDown to prevent row leaks between tests - OnboardingInterviewTest: clear memories table in setUp/tearDown, add DB state assertions to save_answers tests verifying stored memories and blank answer filtering - OnboardingManagerTest: clear memories table in setUp/tearDown to prevent order-dependent failures, assert cron scheduling on fresh site path - FreshInstallDetectorTest: replace weak assertIsBool with specific has_real_posts/has_real_pages flag assertions via getStatus()
…ormat Memory content is stored as 'Label: answer', not raw answer text. Use LIKE queries and assertStringContainsString to match the actual storage format. Also verify fallback label for unknown question IDs.
Closing SummaryWhat was done
Testing Evidence
Key decisions
Files changed
Blockers
Follow-up
Closes #699 aidevops.sh v3.5.466 plugin for OpenCode v1.3.0 with claude-opus-4-6 |
Summary
Files changed
ChangeLoggerTest.phpChangeLoggerContextProvidersTest.phpContextProvidersExportTest.phpExportFreshInstallDetectorTest.phpFreshInstallDetectorOnboardingInterviewTest.phpOnboardingInterviewOnboardingManagerTest.phpOnboardingManagerAcceptance criteria
tests/GratisAiAgent/Core/Runtime Testing
Risk level: Low — test files only; no production code changes.
Testing method:
self-assessed— PHPCS clean; test structure mirrors existing passing test files.Closes #699
aidevops.sh v3.5.463 plugin for OpenCode v1.3.0 with claude-sonnet-4-6
Summary by CodeRabbit