mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-28 16:58:31 +01:00
Update Help guides (with byte-for-byte in-app mirrors in frontend-modern/public/docs/) and add source-bound doc regression tests: - Scheduler and Alerting Help (docs/ALERTING.md, docs/API.md, docs/api/SCHEDULER_HEALTH.md, docs/monitoring/ADAPTIVE_POLLING.md, docs/monitoring/PROMETHEUS_METRICS.md, docs/operations/ADAPTIVE_POLLING_ROLLOUT.md, scripts/tests/test_watchdog_help_docs.py): document the shared worker execution-boundary fence landed in #5379 so operators know both local per-monitor workers and the POLL_TASK_WORKERS process dispatcher skip provider setup for claims retired after dequeue or slot admission while preserving any explicit replacement's own due time. - Server update, teardown, and agent-capabilities API Help (docs/API.md, docs/AUTO_UPDATE.md, scripts/tests/test_api_reference_routes.py): document POST /api/updates/rollback, GET /api/updates/release-notes and its asset route, POST /api/auto-unregister, GET /api/agent/capabilities, and the exact scopes, body limits, cache headers, and status codes of the update API routes. - Security registration Help CI repair (SECURITY.md, frontend-modern/public/docs/SECURITY.md, scripts/tests/test_security_docs.py): move the command-enabled install token agent:exec ceiling note out of the two-item Auto-Registration Security bullet list into a standalone paragraph so registrationSecurityGuide.test.ts passes again on main after #5383, and guard the two-bullet list shape in Python doc tests. Contract-Neutral: Documentation, shipped in-app Help mirrors, and doc verification tests aligned with already-landed runtime behavior; no runtime, API, schema, or UI contract changes. Change-source: pulse-maintainer
302 lines
16 KiB
Python
302 lines
16 KiB
Python
#!/usr/bin/env python3
|
|
"""Keep External watchdog Help aligned with AlertDeadManDestinationSection.tsx.
|
|
|
|
Static source/document checks only: no watchdog URL, network request, or live
|
|
alert operation is performed.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
DOC = ROOT / "docs/AVAILABILITY.md"
|
|
MIRROR = ROOT / "frontend-modern/public/docs/AVAILABILITY.md"
|
|
COMPONENT = ROOT / "frontend-modern/src/features/alerts/AlertDeadManDestinationSection.tsx"
|
|
|
|
|
|
def plain(text: str) -> str:
|
|
return " ".join(text.replace("**", "").replace("`", "").split())
|
|
|
|
|
|
class WatchdogHelpDocsTest(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
self.doc = DOC.read_text(encoding="utf-8")
|
|
self.guide = plain(self.doc)
|
|
self.component = COMPONENT.read_text(encoding="utf-8")
|
|
|
|
def test_shipped_guide_matches(self) -> None:
|
|
self.assertEqual(DOC.read_bytes(), MIRROR.read_bytes())
|
|
|
|
def test_watchdog_status_badges_match_runtime_presentation(self) -> None:
|
|
for label in (
|
|
"Heartbeat healthy",
|
|
"No recent heartbeat",
|
|
"Status read overdue",
|
|
"Status unavailable",
|
|
"Delivery failing",
|
|
"Monitoring stalled",
|
|
"Starting",
|
|
"Not configured",
|
|
"Configuration invalid",
|
|
"Configuration unavailable",
|
|
):
|
|
with self.subTest(label=label):
|
|
self.assertIn(f"'{label}'", self.component)
|
|
self.assertIn(label, self.guide)
|
|
|
|
def test_watchdog_polling_and_interruption_details_match_component(self) -> None:
|
|
self.assertIn("DEAD_MAN_STATUS_POLL_MS = 30_000", self.component)
|
|
self.assertIn("DEAD_MAN_STATUS_READ_OVERDUE_MS = 2 * DEAD_MAN_STATUS_POLL_MS", self.component)
|
|
self.assertIn("recommendedGraceSeconds", self.component)
|
|
self.assertIn("Last interruption", self.component)
|
|
self.assertIn("clean restart", self.component)
|
|
self.assertIn("unexpected stop", self.component)
|
|
|
|
for phrase in (
|
|
"Alerts → Notifications → External watchdog",
|
|
"3-minute grace period",
|
|
"A live status read does not mean a heartbeat was sent",
|
|
"two 30-second poll intervals (60 seconds)",
|
|
"Use Refresh to retry",
|
|
"last known snapshot",
|
|
"Last interruption",
|
|
"clean restart",
|
|
"unexpected stop",
|
|
):
|
|
with self.subTest(phrase=phrase):
|
|
self.assertIn(phrase, self.guide)
|
|
|
|
def test_availability_lifecycle_truthfulness_matches_poller_source(self) -> None:
|
|
poller = (ROOT / "internal/monitoring/availability_poller.go").read_text(encoding="utf-8")
|
|
probe_agent = (ROOT / "internal/monitoring/availability_probe_agent.go").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
staleness = (ROOT / "internal/monitoring/staleness_tracker.go").read_text(encoding="utf-8")
|
|
|
|
for token in (
|
|
"availabilityRefreshMu",
|
|
"currentLocalAvailabilityTarget",
|
|
"pausedIDs",
|
|
"context.Canceled",
|
|
):
|
|
with self.subTest(poller_token=token):
|
|
self.assertIn(token, poller)
|
|
self.assertIn("Rejecting probe availability result for disabled target", probe_agent)
|
|
self.assertIn("func (t *StalenessTracker) Remove(", staleness)
|
|
|
|
for phrase in (
|
|
"clears its scheduler health, retry, failure, dead-letter and staleness entries",
|
|
"Local probes cancelled during a server reload or shutdown are discarded",
|
|
"in-flight local or remote results for a check that was paused, deleted, edited or reassigned to remote-only locations are dropped",
|
|
"clears its pre-pause observations and external-probe grace tracking without raising stale-probe errors while paused",
|
|
"starts a fresh first-report grace window instead of immediately reporting an unavailable probe",
|
|
):
|
|
with self.subTest(phrase=phrase):
|
|
self.assertIn(phrase, self.guide)
|
|
|
|
def test_watchdog_recovery_and_replacement_truthfulness_matches_deadman_source(self) -> None:
|
|
deadman = (ROOT / "internal/monitoring/deadman.go").read_text(encoding="utf-8")
|
|
for token in (
|
|
"func (d *deadManRuntime) recordHealthyProgress(",
|
|
"func (d *deadManRuntime) recordSignalFailure(",
|
|
"func (d *deadManRuntime) notifyConfigChangedFor(",
|
|
"d.status.LastSuccessAt = nil",
|
|
"d.status.LastAttemptAt = nil",
|
|
"if d.stopping || ctx.Err() != nil {",
|
|
):
|
|
with self.subTest(deadman_token=token):
|
|
self.assertIn(token, deadman)
|
|
|
|
self.assertIn("Last success", self.component)
|
|
self.assertNotIn("Last attempt", self.component)
|
|
self.assertIn('json:"lastAttemptAt,omitempty"', deadman)
|
|
for phrase in (
|
|
"Monitoring stalled clears immediately and moves to Starting or Delivery failing if the recovery heartbeat fails to deliver",
|
|
"Replacing, removing, or saving an invalid watchdog URL clears prior Last success and API lastAttemptAt timestamps",
|
|
"clears prior delivery alerts on replacement",
|
|
"re-saving the same configured URL preserves its Last success",
|
|
"Concurrent shutdown or configuration replacement cancels superseded watchdog cycles",
|
|
"cannot overwrite a clean shutdown record or the new destination's status",
|
|
):
|
|
with self.subTest(phrase=phrase):
|
|
self.assertIn(phrase, self.guide)
|
|
|
|
def test_poll_planning_retirement_and_panic_logging_help_matches_runtime(self) -> None:
|
|
alerting_path = ROOT / "docs/ALERTING.md"
|
|
alerting_mirror = ROOT / "frontend-modern/public/docs/ALERTING.md"
|
|
self.assertEqual(alerting_path.read_bytes(), alerting_mirror.read_bytes())
|
|
|
|
schedule_src = (ROOT / "internal/monitoring/monitor_polling_schedule.go").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
progress_src = (ROOT / "internal/monitoring/poll_work_progress.go").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
workers_src = (ROOT / "internal/monitoring/poll_task_workers.go").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
|
|
for token in (
|
|
"func (m *Monitor) planScheduledPolls(ctx context.Context, now time.Time)",
|
|
"id := progress.beginPlanning(time.Now())",
|
|
"defer progress.finishPlanning(id)",
|
|
"m.taskQueue.upsertPlan(task, revision)",
|
|
"m.state.UpdatePollStats(",
|
|
"m.syncAlertsToState()",
|
|
):
|
|
with self.subTest(schedule_token=token):
|
|
self.assertIn(token, schedule_src)
|
|
|
|
# The roster read uses the monitor context but can still return after
|
|
# cancellation. Check that its result is discarded before publishing.
|
|
self.assertRegex(
|
|
schedule_src,
|
|
r"descriptors := m\.describeInstancesForScheduler\(ctx\)\s*"
|
|
r"(?://[^\n]*\n\s*)*if ctx\.Err\(\) != nil \{\s*return\s*\}",
|
|
)
|
|
|
|
for token in (
|
|
'"pulse_scheduler_poll_planning_age_seconds"',
|
|
'"pulse_scheduler_claimed_poll_overdue_seconds"',
|
|
'"waiting_for_slot", "running"',
|
|
):
|
|
with self.subTest(progress_token=token):
|
|
self.assertIn(token, progress_src)
|
|
|
|
for token in (
|
|
"defer progress.finish(work)",
|
|
'Msg("Recovered from panic in scheduled poll task")',
|
|
"defer func() { m.taskQueue.completeClaim(task, next, reschedule) }()",
|
|
):
|
|
with self.subTest(workers_token=token):
|
|
self.assertIn(token, workers_src)
|
|
self.assertLess(
|
|
workers_src.index("defer progress.finish(work)"),
|
|
workers_src.index('Msg("Recovered from panic in scheduled poll task")'),
|
|
)
|
|
self.assertLess(
|
|
workers_src.index('Msg("Recovered from panic in scheduled poll task")'),
|
|
workers_src.index(
|
|
"defer func() { m.taskQueue.completeClaim(task, next, reschedule) }()"
|
|
),
|
|
)
|
|
|
|
docs_checks = (
|
|
(
|
|
"docs/ALERTING.md",
|
|
(
|
|
'stage="running"',
|
|
"panic recovery logging after releasing its queue claim",
|
|
"Unfinished poll planning:",
|
|
"pulse_scheduler_poll_planning_age_seconds",
|
|
"reading provider rosters, building the plan, or queuing tasks",
|
|
"When a monitor is retired during a planning pass, Pulse abandons the returned plan once cancellation is observed instead of queuing tasks or running post-plan statistics and alert reconciliation",
|
|
"keeping any still-running roster read visible in pulse_scheduler_poll_planning_age_seconds until it returns",
|
|
),
|
|
),
|
|
(
|
|
"docs/monitoring/PROMETHEUS_METRICS.md",
|
|
(
|
|
"stays visible in this stage while occupied in panic recovery logging even after releasing its queue claim",
|
|
"When a monitor is retired while a planning pass is reading rosters, Pulse abandons the returned plan once cancellation is observed instead of queuing tasks or running post-plan statistics and alert reconciliation",
|
|
"keeping the still-running pass visible in pulse_scheduler_poll_planning_age_seconds until it returns",
|
|
),
|
|
),
|
|
(
|
|
"docs/api/SCHEDULER_HEALTH.md",
|
|
(
|
|
'releases its queue claim during panic recovery logging stays visible under stage="running" until logging finishes',
|
|
"When a monitor is retired during poll planning, Pulse abandons the returned plan once cancellation is observed instead of queuing tasks or running post-plan statistics and alert reconciliation",
|
|
"keeping any still-running roster read visible in pulse_scheduler_poll_planning_age_seconds until it returns",
|
|
"For Availability checks, Scheduler Health describes every enabled check from one catalog snapshot, including remote-only checks run by external agents, without reloading the catalog to look up local-only tasks",
|
|
"Once cancellation is observed, the retired planner also stops starting further provider roster or cadence reads between providers without pretending to cancel a callback already in flight",
|
|
),
|
|
),
|
|
)
|
|
for rel_path, phrases in docs_checks:
|
|
text = plain((ROOT / rel_path).read_text(encoding="utf-8"))
|
|
for phrase in phrases:
|
|
with self.subTest(doc=rel_path, phrase=phrase):
|
|
self.assertIn(phrase, text)
|
|
|
|
avail_poller = (ROOT / "internal/monitoring/availability_poller.go").read_text(encoding="utf-8")
|
|
poll_providers = (ROOT / "internal/monitoring/poll_providers.go").read_text(encoding="utf-8")
|
|
task_queue_src = (ROOT / "internal/monitoring/task_queue.go").read_text(encoding="utf-8")
|
|
self.assertIn("func (availabilityPollProvider) describesCompleteHealthRoster() {}", avail_poller)
|
|
self.assertIn("type completeInstanceInfoPollProvider interface {", poll_providers)
|
|
self.assertIn("func (m *Monitor) describeInstancesForScheduler(ctx context.Context) []InstanceDescriptor {", schedule_src)
|
|
|
|
for token in (
|
|
"func (l *pollTaskWorkerLimiter) acquireClaim(",
|
|
"if !limiter.acquireClaim(ctx, m.taskQueue, task) {",
|
|
"retired := q.watchClaimRetirement(task)",
|
|
"if ctx.Err() != nil || !q.canStartClaim(task) {",
|
|
"if ctx.Err() != nil || !m.taskQueue.canStartClaim(task) {",
|
|
):
|
|
with self.subTest(retired_claim_worker_token=token):
|
|
self.assertIn(token, workers_src)
|
|
|
|
for token in (
|
|
"func (q *TaskQueue) watchClaimRetirement(",
|
|
"func (q *TaskQueue) canStartClaim(",
|
|
"entry.claimRetired = true",
|
|
"close(entry.retirement)",
|
|
):
|
|
with self.subTest(retired_claim_queue_token=token):
|
|
self.assertIn(token, task_queue_src)
|
|
|
|
retired_claim_docs_checks = (
|
|
(
|
|
"docs/ALERTING.md",
|
|
(
|
|
'Under POLL_TASK_WORKERS, a confirmed removal releases a claim still waiting under stage="waiting_for_slot" without starting provider setup or changing the worker limit so another due target can run',
|
|
'preserving any explicit replacement\'s due time while already-admitted stage="running" polls keep their claim until they return',
|
|
"Both default per-monitor workers and the process dispatcher also check claim retirement again at the execution boundary before provider setup, so a target removed or replaced after dequeue or slot admission skips starting an obsolete poll while keeping any saved replacement's own due time",
|
|
),
|
|
),
|
|
(
|
|
"docs/monitoring/PROMETHEUS_METRICS.md",
|
|
(
|
|
"If the connection or check is removed while its claim is still waiting for a slot, the dispatcher releases the retired claim without starting provider setup or changing the POLL_TASK_WORKERS limit and moves on to another due target",
|
|
"An explicit replacement keeps its own due time, while a poll already admitted to running keeps its claim until it returns",
|
|
"Both local per-monitor workers and the process dispatcher also re-check claim retirement at the execution boundary before provider setup, so a target removed or replaced after dequeue or slot admission skips starting an obsolete poll while keeping the replacement's own schedule",
|
|
),
|
|
),
|
|
(
|
|
"docs/api/SCHEDULER_HEALTH.md",
|
|
(
|
|
'Under POLL_TASK_WORKERS, a confirmed removal also retires a claim still waiting for a process worker slot (stage="waiting_for_slot"): the dispatcher releases that claim without starting provider setup or changing the concurrency cap and moves on to another due target',
|
|
'preserving any explicit replacement\'s due time while an already-admitted stage="running" poll keeps its claim until it returns',
|
|
"Both local per-monitor workers and the process dispatcher also check claim retirement at the execution boundary before provider setup, so retirement after dequeue or slot admission skips starting an obsolete poll while keeping the replacement's own due time",
|
|
),
|
|
),
|
|
(
|
|
"docs/monitoring/ADAPTIVE_POLLING.md",
|
|
(
|
|
"Both local per-monitor workers and the process dispatcher also re-check claim retirement at the execution boundary before provider setup, so a target removed or replaced after dequeue or slot admission skips starting an obsolete poll and preserves the replacement's own due time",
|
|
),
|
|
),
|
|
(
|
|
"docs/operations/ADAPTIVE_POLLING_ROLLOUT.md",
|
|
(
|
|
"Both local per-monitor workers and the process dispatcher also check claim retirement at the execution boundary before provider setup, skipping obsolete polls retired after dequeue or slot admission while preserving any explicit replacement's due time",
|
|
),
|
|
),
|
|
(
|
|
"docs/API.md",
|
|
(
|
|
"Both local per-monitor workers and the process dispatcher also re-check claim retirement at the execution boundary before provider setup, so a target removed or replaced after dequeue or slot admission skips starting an obsolete poll while preserving any explicit replacement's own due time",
|
|
),
|
|
),
|
|
)
|
|
for rel_path, phrases in retired_claim_docs_checks:
|
|
text = plain((ROOT / rel_path).read_text(encoding="utf-8"))
|
|
for phrase in phrases:
|
|
with self.subTest(retired_claim_doc=rel_path, phrase=phrase):
|
|
self.assertIn(phrase, text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|