Skip to content

Replace service_escalation_policies with default silent policy#283

Merged
clcollins merged 14 commits into
mainfrom
worktree-phase4-silent-policy
Jun 7, 2026
Merged

Replace service_escalation_policies with default silent policy#283
clcollins merged 14 commits into
mainfrom
worktree-phase4-silent-policy

Conversation

@clcollins

Copy link
Copy Markdown
Owner

Summary

Closes #269 (Phase 4)

Re-escalation already uses the incident's own escalation policy — no config needed. Only silencing needs a target policy. This replaces the full service_escalation_policies mapping (~500 services, 30s startup) with:

  • default_silent_escalation_policy — single policy ID, 1 API call at startup
  • custom_service_escalation_policies — optional per-service silent policy overrides

What changed

  • Added ListEscalationPoliciesWithContext to PD interface (lightweight — returns ~5 policies per team vs ~500 services)
  • Added GetTeamEscalationPolicies() for paginated policy fetch by team
  • Updated NewConfigWithClient with three paths: old deprecated (service_escalation_policies), new (default_silent_escalation_policy + custom overrides), empty (silencing disabled with warning)
  • Extended --pick-teams to auto-discover silent policies and present huh.Select for user confirmation
  • Deprecated service_escalation_policies

Backward compatible

Old service_escalation_policies config still works — emits deprecation warning on startup.

Test plan

  • 17 new/updated tests (GetTeamEscalationPolicies, NewConfig paths, deprecation)
  • All existing tests pass
  • make test-all passes (fmt, vet, lint, test, race)
  • Binary built for manual testing at ~/srepd

🤖 Generated with Claude Code

Re-escalation uses the incident's own policy — no config needed. Only
silencing needs a target policy. Replace the full service-to-policy
mapping with a single default_silent_escalation_policy key (1 API call
at startup) plus optional custom_service_escalation_policies overrides.

--pick-teams now auto-discovers silent policies via
ListEscalationPoliciesWithContext and presents them for selection.
Old service_escalation_policies config still works with deprecation
warning.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.39819% with 465 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.34%. Comparing base (6c1be60) to head (10fd6ea).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/tui/tui.go 0.00% 171 Missing and 2 partials ⚠️
pkg/config/config.go 82.07% 41 Missing and 35 partials ⚠️
pkg/tui/commands.go 0.00% 72 Missing ⚠️
pkg/tui/msgHandlers.go 10.60% 56 Missing and 3 partials ⚠️
cmd/config.go 17.02% 39 Missing ⚠️
cmd/root.go 0.00% 15 Missing ⚠️
pkg/pd/ratelimit.go 0.00% 8 Missing ⚠️
pkg/pd/pd.go 85.10% 5 Missing and 2 partials ⚠️
pkg/tui/views.go 66.66% 3 Missing and 2 partials ⚠️
pkg/pd/dev.go 0.00% 4 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #283      +/-   ##
==========================================
- Coverage   67.56%   65.34%   -2.22%     
==========================================
  Files          34       35       +1     
  Lines        5210     5901     +691     
==========================================
+ Hits         3520     3856     +336     
- Misses       1470     1791     +321     
- Partials      220      254      +34     

☔ 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.

clcollins and others added 13 commits June 6, 2026 12:12
ListEscalationPolicies(TeamIDs) misses silent policies not directly
tagged on the team. Replace auto-discovery with explicit user prompts:
text input for default silent policy ID (validated via API) and optional
comma-separated service:policy custom mappings. Remove launchTUI() call
after setup to avoid terminal glitch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Work in progress — merging token/teams/policies into single huh.Form
using OptionsFunc for dynamic team loading. Still needs the two-form
merge completed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the standalone huh form in cmd/config.go with an inline
config mode inside the srepd TUI, following the existing team picker
pattern. The wizard now renders inside the same tea.Program with
srepd's styles, header, footer, and help system.

Key changes:
- Extract pure config functions to pkg/config/ package
- Add configMode to TUI model with full huh form (token, teams,
  silent policy, custom mappings, summary+confirm)
- Simplify cmd/config.go to thin launcher that sets configMode flag
- Auto-detect missing config file in cmd/root.go and enter wizard
- Initialize PD client asynchronously after config save
- Forward non-key messages to huh form for proper rendering
- Defer config form creation until WindowSizeMsg arrives

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use pointer-based configFormState struct so huh form Value() bindings
survive bubbletea's model copying. Previously form writes went to stale
model copies, causing teams/silent/custom values to be lost on save.

Also fix form completion detection: check StateCompleted in the
catch-all message forwarding path, not just the key message handler,
since the form may complete on non-key messages.

Additionally initialize PD client asynchronously after config save
and trigger window resize to render the incident table.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Show "(unchanged)" label on all summary fields, not just token
- Uppercase custom policy keys from Viper (which lowercases map keys)
- Remove "No config file found" stdout message (invisible under alt-screen)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fetch team names eagerly in prepareConfigWizardCmd so they display
  in the summary even when teams are kept (bug #24)
- Add token validation via PD API on the token input field — prevents
  advancing to team selection with an invalid token (bug #27)
- Detect old-format config (service_escalation_policies) and force
  writing new-format keys on save even when values are unchanged,
  triggering migration to default_silent_escalation_policy and
  custom_service_escalation_policies (bug #28)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fetch escalation policy names from PD API during wizard preparation.
Display team and policy names alongside IDs in keep prompts and
summary (e.g., "Silent Test (PCGXUDY)" instead of bare "PCGXUDY").

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Show "Loading configuration..." instead of the incident table while
configModeRequested is true but the config form hasn't been built yet.
This prevents a brief flash of the empty table view before the wizard
appears.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The completion handler cleared configMode but not configModeRequested,
causing View() to show "Loading configuration..." permanently after
the wizard saved. Now both flags are cleared on completion and abort.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- CommentOutOldPolicies() comments out service_escalation_policies
  block with a deprecation note when new-format keys are written
- BuildSummary shows policy names in custom mappings display
  (e.g., "P5LAB5Y → DMS Silent Test (PVBANNN)")

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace default huh keymap with one that removes misleading "esc back"
help text (esc is disabled in huh) and adds ctrl+q to quit binding.
Only shift+tab for back, enter for next — matches actual behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Suppress srepd's own help bar (with "esc back", "h help") while in
config mode. The huh form renders its own contextual help internally.
After the wizard exits, srepd's normal help bar returns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Each wizard prompt now includes guidance on where to find the required
data in PagerDuty:
- Token: how to create an API key
- Teams: select teams whose incidents you monitor
- Silent policy: where to find escalation policy IDs
- Custom mappings: where to find service and policy IDs

Also set form width to windowSize.Width for proper text wrapping.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@clcollins clcollins merged commit f2920e3 into main Jun 7, 2026
10 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.

"IgnoredUsers" should be replaced with a filter based on EscalationPolicy

2 participants