Files
beads/cmd/bd/tips_example_test.go
Steve Yegge 5f310bc7c2 Add tip system infrastructure (bd-d4i)
Implements a smart contextual hint system that shows helpful messages
to users after successful commands. Tips are filtered by conditions,
priority, frequency limits, and probability rolls to provide useful
information without being annoying.

Core Features:
- Tip struct with condition, message, frequency, priority, probability
- selectNextTip() filters eligible tips and applies probability
- Metadata storage tracks when tips were last shown
- Respects --json and --quiet flags
- Deterministic testing via BEADS_TIP_SEED env var

Integration Points:
- bd list: Shows tip after listing issues
- bd ready: Shows tip after showing ready work (or no work)
- bd create: Shows tip after creating issue
- bd show: Shows tip after showing issue details

Testing:
- Unit tests for tip selection logic
- Tests for frequency limits and probability
- Tests for metadata tracking
- Example tip definitions for documentation

Next Steps:
- bd-81a: Add programmatic tip injection API
- bd-tne: Add Claude setup tip with dynamic priority

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 10:56:14 -08:00

100 lines
3.1 KiB
Go

package main
import (
"testing"
"time"
)
// This file demonstrates example tip definitions for documentation purposes
func TestExampleTipDefinitions(t *testing.T) {
// Example 1: High priority, high probability tip
// Shows frequently when condition is met
highPriorityTip := Tip{
ID: "example_high_priority",
Condition: func() bool { return true },
Message: "This is an important tip that shows often",
Frequency: 24 * time.Hour, // Show at most once per day
Priority: 100, // Highest priority
Probability: 0.8, // 80% chance when eligible
}
// Example 2: Medium priority, medium probability tip
// General feature discovery
mediumPriorityTip := Tip{
ID: "example_medium_priority",
Condition: func() bool { return true },
Message: "Try using 'bd ready' to see available work",
Frequency: 7 * 24 * time.Hour, // Show at most once per week
Priority: 50, // Medium priority
Probability: 0.5, // 50% chance when eligible
}
// Example 3: Low priority, low probability tip
// Nice-to-know information
lowPriorityTip := Tip{
ID: "example_low_priority",
Condition: func() bool { return true },
Message: "You can filter issues by label with --label flag",
Frequency: 30 * 24 * time.Hour, // Show at most once per month
Priority: 10, // Low priority
Probability: 0.2, // 20% chance when eligible
}
// Example 4: Conditional tip
// Only shows when specific condition is true
conditionalTip := Tip{
ID: "example_conditional",
Condition: func() bool {
// Example: Only show if some condition is met
// In real usage, this might check for specific state
return false // Disabled for this example
},
Message: "This tip only shows when condition is met",
Frequency: 24 * time.Hour,
Priority: 80,
Probability: 0.6,
}
// Verify tips are properly structured (basic validation)
tips := []Tip{highPriorityTip, mediumPriorityTip, lowPriorityTip, conditionalTip}
for _, tip := range tips {
if tip.ID == "" {
t.Error("Tip ID should not be empty")
}
if tip.Message == "" {
t.Error("Tip message should not be empty")
}
if tip.Condition == nil {
t.Error("Tip condition function should not be nil")
}
if tip.Frequency < 0 {
t.Error("Tip frequency should not be negative")
}
if tip.Probability < 0 || tip.Probability > 1 {
t.Errorf("Tip probability should be between 0 and 1, got %f", tip.Probability)
}
}
}
// Example showing probability guidelines
func TestProbabilityGuidelines(t *testing.T) {
examples := []struct {
name string
probability float64
useCase string
}{
{"Critical", 1.0, "Security alerts, breaking changes"},
{"High", 0.8, "Important updates, major features"},
{"Medium", 0.5, "General tips, workflow improvements"},
{"Low", 0.2, "Nice-to-know, advanced features"},
}
for _, ex := range examples {
if ex.probability < 0 || ex.probability > 1 {
t.Errorf("%s: probability %f out of range", ex.name, ex.probability)
}
}
}