Operational instructions for AI agents working on this repository.
Production-grade WordPress plugin for operational monitoring with health checks, admin dashboard, WP-Cron scheduling, and alerting.
- No singleton pattern.
- No static methods/properties.
- No
finalclasses/methods. - Use constructor dependency injection.
- Use DI container
share()for shared instances (not global singletons).
- Interface-first design (
*Interface+ concrete implementations). - Function-based bootstrap (
config/bootstrap.php), not static factory bootstrap. - Inject WordPress dependencies (for example
$wpdb) and avoid direct global access in business logic.
- Always follow TDD: RED -> GREEN -> REFACTOR.
- Unit tests in
tests/Unit/with Brain\Monkey for isolated logic. - Integration tests in
tests/Integration/when real WordPress behavior is touched. - Add pattern-enforcement tests for
final/staticviolations. - Before closing changes, run:
composer testcomposer phpcscomposer analyse
- Sanitize input (
sanitize_text_field,sanitize_email,esc_url_raw,absint, etc.). - Escape output (
esc_html,esc_attr,esc_url,esc_js). - Verify admin capabilities (
current_user_can('manage_options')). - Use and verify nonce in forms/AJAX.
- Apply anti-SSRF protections for outbound webhook/HTTP requests.
- Follow WordPress Coding Standards (WPCS).
- Use tab indentation.
- Use Allman brace style.
- Complete PHPDoc for classes/public methods.
- Naming:
- Classes: PascalCase
- Methods: snake_case
- Constants: UPPER_SNAKE_CASE
- Global keys/options:
ops_health_prefix
- Write/update tests.
- Implement the minimum code needed.
- Refactor while keeping tests green.
- Run
composer test,composer phpcs,composer analyse. - Use conventional commits (
feat,fix,docs,refactor,test,chore).
Milestones M1-M6 completed (Core Checks + Storage + Cron + Error Log + Redis + Alerting + DiskCheck + VersionsCheck + DashboardWidget + E2E Testing + WordPress.org Readiness + HealthScreen UI). 574 unit tests, 1336 assertions. 322 integration tests, 655 assertions (single-site) / 684 assertions (multisite). Coverage: 100% classes, methods, lines (unit + integration + multisite combined). 46 E2E scenarios x 3 viewports = 138 test executions (Playwright + wp-env). PHPCS 100% clean, PHPStan level 6: 0 errors. 31 source files, 55 PHP test files (31 unit + 24 integration), 5 E2E spec files, 2 CSS files. Plugin WordPress.org ready with uninstall.php, readme.txt, ABSPATH guards. HealthScreen with card grid, summary banner, and dedicated CSS. See DEVELOPMENT_PLAN.md and CHANGELOG.md for up-to-date status.
Architecture points to preserve:
- Plugin bootstrap in
ops-health-dashboard.phpwith fail-safe autoloader and admin notice whenvendor/autoload.phpis missing. - Main orchestration in
src/Core/Plugin.phpwith idempotent init. - Custom DI container in
src/Core/Container.php(bind,share,instance,make). - Activation/deactivation lifecycle in
src/Core/Activator.phpwith options setup and cron hookops_health_run_checks. - Periodic scheduling in
src/Services/Scheduler.php(every 15 minutes) with throttled self-healing via transientops_health_cron_check. - Checks registered in
config/bootstrap.php:DatabaseCheck,ErrorLogCheck,RedisCheck,DiskCheck,VersionsCheck. - Admin action flow in
src/Admin/HealthScreen.phpviaprocess_actions()with nonce + capability checks and PRG redirect; isolateddo_exit()for testability. - Sensitive data redaction centralized in
src/Services/Redaction.php, injected intoCheckRunner,DatabaseCheck,ErrorLogCheck,RedisCheck. RedisCheckuses per-run unique smoke-test key (ops_health_smoke_test_<uniqid>) to avoid race conditions.CheckRunnerInterfaceincludesclear_results()used by admin flow (Run Now/Clear Cache).- Alerting pipeline via
AlertManagerwith state-change detection, multi-channel dispatch, per-check cooldown, max 50 alert log entries, integrated inScheduler::run_checks(). - Anti-SSRF
HttpClientprotections: private IP blocking, DNS validation, DNS pinning (CURLOPT_RESOLVE), scheme/port restrictions, no redirects, 5s timeout, IPv6 safe-fail rejection, 2xx validation. - Alert settings page at
Ops -> Alert Settingswith PRG, nonceops_health_alert_settings, per-channel enable/disable and masked credentials not exposed in DOM. - Channel-level security: Telegram HTML escaping, Slack mrkdwn escaping, Email
is_email(), WhatsApp E.164 validation. - AlertManager resilience: cooldown set before dispatch, status constants, per-channel
try/catch \Throwable, Scheduler wrappingprocess()withcatch (\Throwable). - Dashboard widget in
src/Admin/DashboardWidget.phpregistered inPlugin::init()with capability check and worst-status logic. - Health screen UI with
register_hooks(), guardedenqueue_styles(),SCREEN_ID, overall-status priority map, card-grid + summary banner CSS. - Disk check thresholds (
WARNING_THRESHOLD = 20,CRITICAL_THRESHOLD = 10) and wrappers for testability. - Versions check with
RECOMMENDED_PHP_VERSION = '8.3'; core updates critical, plugin/theme updates warning. - Local quality gates:
composer test,composer phpcs,composer analyse(PHPStan level 6 withphpstan.neon). - CI in
.github/workflows/ci.yml: dedicated PHPCS, PHPStan, PHPUnit matrix (PHP 7.4-8.5, coverage on 8.3), E2E Playwright (Chromium, desktop-only in CI, wp-env,timeout-minutes: 15). Codecov with separate flagsunit/integration(codecov.yml,CODECOV_TOKENsecret). - E2E Testing: Playwright +
@wordpress/envin Docker. 46 scenarios x 3 viewports locally (desktop/tablet/mobile), desktop-only in CI (46 tests, ~8 min). CI: 1 worker, timeout 60s, login timeout 30s, health check wait,line+githubreporter. Centralized selectors intests/e2e/helpers/selectors.ts. Login helpers for admin/subscriber/editor.bin/e2e-setup.shcreates test users. - Local Test Matrix:
bin/test-matrix.shreplicates CI locally: PHPCS + PHPStan + PHPUnit (PHP 7.4-8.5) + E2E Playwright. Flags--e2e-only,--no-e2e,--tests-only,--phpcs-only,--parallel. E2E integrated with lifecycle management (wp-env start/stop, test users, npm/docker prerequisites).composer.jsonprocess-timeout: 0for long-running executions.
Operational note:
- Avoid dated sections or "one-shot" checklists in this file.
- Update this section only when the technical baseline changes (version, bootstrap, scheduler, main contracts).
Before closing PR/commit:
- Review
git diff --name-onlyandgit difffor touched files. - Ensure test coverage reflects every changed behavior.
- Confirm no cron/scheduler regressions.
- Confirm tooling compatibility in sequential and parallel runs.
- Execute:
composer test:unitcomposer test:integration(with DB available)composer phpcscomposer analyse
- If integration tests cannot run in sandbox/local env, explicitly report concrete failure (for example DB unreachable), not as passed.
README.mdCONTRIBUTING.mdDEVELOPMENT_PLAN.mdCHANGELOG.mdCLAUDE.mdSECURITY.md