Add near-term generate command
This commit is contained in:
@@ -21,6 +21,7 @@ the managed Markdown report after final metadata is saved.
|
|||||||
weatherreporter --help
|
weatherreporter --help
|
||||||
weatherreporter generate daily [--config PATH] [--units VALUE] [--tz NAME] [--out PATH] [--date YYYY-MM-DD]
|
weatherreporter generate daily [--config PATH] [--units VALUE] [--tz NAME] [--out PATH] [--date YYYY-MM-DD]
|
||||||
weatherreporter generate tomorrow [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
weatherreporter generate tomorrow [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
||||||
|
weatherreporter generate near-term [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
||||||
weatherreporter generate three-day [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
weatherreporter generate three-day [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
||||||
weatherreporter generate weekend [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
weatherreporter generate weekend [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
||||||
weatherreporter generate storm [--config PATH] [--units VALUE] [--tz NAME] [--out PATH] --start TIME --end TIME
|
weatherreporter generate storm [--config PATH] [--units VALUE] [--tz NAME] [--out PATH] --start TIME --end TIME
|
||||||
@@ -37,8 +38,10 @@ weatherreporter inspect sources [--config PATH] RUN_ID
|
|||||||
`generate` commands write a JSON module snapshot, YAML data package, preflight
|
`generate` commands write a JSON module snapshot, YAML data package, preflight
|
||||||
artifact, managed Markdown report, and metadata under the configured workspace.
|
artifact, managed Markdown report, and metadata under the configured workspace.
|
||||||
`--out` writes an extra Markdown copy for the operator; distributor
|
`--out` writes an extra Markdown copy for the operator; distributor
|
||||||
notification uses the managed report path, not the extra copy. `generate storm`
|
notification uses the managed report path, not the extra copy. `generate
|
||||||
requires explicit event-window bounds with `--start` and `--end`.
|
near-term` uses the current generation time and does not accept date or event
|
||||||
|
window flags. `generate storm` requires explicit event-window bounds with
|
||||||
|
`--start` and `--end`.
|
||||||
|
|
||||||
`run morning` generates Daily Today and the 3-Day Outlook, plus Weekend Outlook
|
`run morning` generates Daily Today and the 3-Day Outlook, plus Weekend Outlook
|
||||||
except on Sunday. `run evening` generates the Tomorrow Planning Brief. Batch
|
except on Sunday. `run evening` generates the Tomorrow Planning Brief. Batch
|
||||||
@@ -76,6 +79,7 @@ are no distributor-specific CLI flags.
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
weatherreporter generate tomorrow --out ./tomorrow.md
|
weatherreporter generate tomorrow --out ./tomorrow.md
|
||||||
|
weatherreporter generate near-term --out ./near-term.md
|
||||||
weatherreporter generate three-day --out ./three-day.md
|
weatherreporter generate three-day --out ./three-day.md
|
||||||
weatherreporter generate weekend --out ./weekend.md
|
weatherreporter generate weekend --out ./weekend.md
|
||||||
weatherreporter generate storm --start 2026-05-29T18:00 --end 2026-05-30T06:00 --out ./storm.md
|
weatherreporter generate storm --start 2026-05-29T18:00 --end 2026-05-30T06:00 --out ./storm.md
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type ReportKind string
|
|||||||
const (
|
const (
|
||||||
ReportDaily ReportKind = "daily"
|
ReportDaily ReportKind = "daily"
|
||||||
ReportTomorrow ReportKind = "tomorrow"
|
ReportTomorrow ReportKind = "tomorrow"
|
||||||
|
ReportNearTerm ReportKind = "near-term"
|
||||||
ReportThreeDay ReportKind = "three-day"
|
ReportThreeDay ReportKind = "three-day"
|
||||||
ReportWeekend ReportKind = "weekend"
|
ReportWeekend ReportKind = "weekend"
|
||||||
ReportStorm ReportKind = "storm"
|
ReportStorm ReportKind = "storm"
|
||||||
@@ -386,6 +387,8 @@ func reportIDForCommand(kind ReportKind) (report.ID, error) {
|
|||||||
return report.DailyToday, nil
|
return report.DailyToday, nil
|
||||||
case ReportTomorrow:
|
case ReportTomorrow:
|
||||||
return report.DailyTomorrow, nil
|
return report.DailyTomorrow, nil
|
||||||
|
case ReportNearTerm:
|
||||||
|
return report.NearTerm, nil
|
||||||
case ReportThreeDay:
|
case ReportThreeDay:
|
||||||
return report.ThreeDay, nil
|
return report.ThreeDay, nil
|
||||||
case ReportWeekend:
|
case ReportWeekend:
|
||||||
|
|||||||
@@ -1162,23 +1162,59 @@ func TestInspectMissingMetadata(t *testing.T) {
|
|||||||
func TestResolveGenerateMapsCommandToReportDefinition(t *testing.T) {
|
func TestResolveGenerateMapsCommandToReportDefinition(t *testing.T) {
|
||||||
cfg := config.Defaults()
|
cfg := config.Defaults()
|
||||||
cfg.WeatherAPI.Timezone = "America/Chicago"
|
cfg.WeatherAPI.Timezone = "America/Chicago"
|
||||||
now := mustParse("2026-05-29T18:00:00-05:00")
|
now := mustParse("2026-05-29T08:00:00-05:00")
|
||||||
|
|
||||||
resolved, err := ResolveGenerate(GenerateRequest{
|
tests := []struct {
|
||||||
Config: cfg,
|
name string
|
||||||
Report: ReportTomorrow,
|
kind ReportKind
|
||||||
}, now)
|
wantID report.ID
|
||||||
if err != nil {
|
wantPrompt string
|
||||||
t.Fatalf("ResolveGenerate() error = %v", err)
|
wantStart string
|
||||||
|
wantEnd string
|
||||||
|
requestDate time.Time
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "tomorrow",
|
||||||
|
kind: ReportTomorrow,
|
||||||
|
wantID: report.DailyTomorrow,
|
||||||
|
wantPrompt: "weather.daily_report",
|
||||||
|
wantStart: "2026-05-30T00:00:00-05:00",
|
||||||
|
wantEnd: "2026-05-31T00:00:00-05:00",
|
||||||
|
requestDate: time.Time{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "near-term",
|
||||||
|
kind: ReportNearTerm,
|
||||||
|
wantID: report.NearTerm,
|
||||||
|
wantPrompt: "weather.near_term_report",
|
||||||
|
wantStart: "2026-05-29T08:00:00-05:00",
|
||||||
|
wantEnd: "2026-05-29T14:00:00-05:00",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if resolved.Definition.ID != report.DailyTomorrow {
|
|
||||||
t.Fatalf("ID = %q, want daily_tomorrow", resolved.Definition.ID)
|
for _, tt := range tests {
|
||||||
}
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if resolved.Definition.PromptID != "weather.daily_report" {
|
resolved, err := ResolveGenerate(GenerateRequest{
|
||||||
t.Fatalf("PromptID = %q, want weather.daily_report", resolved.Definition.PromptID)
|
Config: cfg,
|
||||||
}
|
Report: tt.kind,
|
||||||
if got := resolved.ValidPeriod.Start.Format("2006-01-02"); got != "2026-05-30" {
|
Date: tt.requestDate,
|
||||||
t.Fatalf("valid start date = %s, want 2026-05-30", got)
|
}, now)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ResolveGenerate() error = %v", err)
|
||||||
|
}
|
||||||
|
if resolved.Definition.ID != tt.wantID {
|
||||||
|
t.Fatalf("ID = %q, want %q", resolved.Definition.ID, tt.wantID)
|
||||||
|
}
|
||||||
|
if resolved.Definition.PromptID != tt.wantPrompt {
|
||||||
|
t.Fatalf("PromptID = %q, want %q", resolved.Definition.PromptID, tt.wantPrompt)
|
||||||
|
}
|
||||||
|
if got := resolved.ValidPeriod.Start.Format(time.RFC3339); got != tt.wantStart {
|
||||||
|
t.Fatalf("valid start = %s, want %s", got, tt.wantStart)
|
||||||
|
}
|
||||||
|
if got := resolved.ValidPeriod.End.Format(time.RFC3339); got != tt.wantEnd {
|
||||||
|
t.Fatalf("valid end = %s, want %s", got, tt.wantEnd)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ Usage:
|
|||||||
weatherreporter --help
|
weatherreporter --help
|
||||||
weatherreporter generate daily [--config PATH] [--units VALUE] [--tz NAME] [--out PATH] [--date YYYY-MM-DD]
|
weatherreporter generate daily [--config PATH] [--units VALUE] [--tz NAME] [--out PATH] [--date YYYY-MM-DD]
|
||||||
weatherreporter generate tomorrow [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
weatherreporter generate tomorrow [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
||||||
|
weatherreporter generate near-term [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
||||||
weatherreporter generate three-day [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
weatherreporter generate three-day [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
||||||
weatherreporter generate weekend [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
weatherreporter generate weekend [--config PATH] [--units VALUE] [--tz NAME] [--out PATH]
|
||||||
weatherreporter generate storm [--config PATH] [--units VALUE] [--tz NAME] [--out PATH] --start TIME --end TIME
|
weatherreporter generate storm [--config PATH] [--units VALUE] [--tz NAME] [--out PATH] --start TIME --end TIME
|
||||||
@@ -386,6 +387,8 @@ func reportKind(value string) (app.ReportKind, bool) {
|
|||||||
return app.ReportDaily, true
|
return app.ReportDaily, true
|
||||||
case string(app.ReportTomorrow):
|
case string(app.ReportTomorrow):
|
||||||
return app.ReportTomorrow, true
|
return app.ReportTomorrow, true
|
||||||
|
case string(app.ReportNearTerm):
|
||||||
|
return app.ReportNearTerm, true
|
||||||
case string(app.ReportThreeDay):
|
case string(app.ReportThreeDay):
|
||||||
return app.ReportThreeDay, true
|
return app.ReportThreeDay, true
|
||||||
case string(app.ReportWeekend):
|
case string(app.ReportWeekend):
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ func TestRunHelpLongFlag(t *testing.T) {
|
|||||||
if !strings.Contains(stdout.String(), "generate daily") {
|
if !strings.Contains(stdout.String(), "generate daily") {
|
||||||
t.Fatalf("help output missing generate command:\n%s", stdout.String())
|
t.Fatalf("help output missing generate command:\n%s", stdout.String())
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(stdout.String(), "weatherreporter generate near-term") {
|
||||||
|
t.Fatalf("help output missing near-term generate command:\n%s", stdout.String())
|
||||||
|
}
|
||||||
removedInspectCommand := "inspect " + "briefing"
|
removedInspectCommand := "inspect " + "briefing"
|
||||||
if !strings.Contains(stdout.String(), "inspect modules") || strings.Contains(stdout.String(), removedInspectCommand) {
|
if !strings.Contains(stdout.String(), "inspect modules") || strings.Contains(stdout.String(), removedInspectCommand) {
|
||||||
t.Fatalf("help output has wrong inspect commands:\n%s", stdout.String())
|
t.Fatalf("help output has wrong inspect commands:\n%s", stdout.String())
|
||||||
@@ -809,6 +812,7 @@ func TestResolveGenerateCommands(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{name: "daily", args: []string{"daily", "--date", "2026-05-29"}, want: app.ReportDaily},
|
{name: "daily", args: []string{"daily", "--date", "2026-05-29"}, want: app.ReportDaily},
|
||||||
{name: "tomorrow", args: []string{"tomorrow"}, want: app.ReportTomorrow},
|
{name: "tomorrow", args: []string{"tomorrow"}, want: app.ReportTomorrow},
|
||||||
|
{name: "near-term", args: []string{"near-term"}, want: app.ReportNearTerm},
|
||||||
{name: "three-day", args: []string{"three-day"}, want: app.ReportThreeDay},
|
{name: "three-day", args: []string{"three-day"}, want: app.ReportThreeDay},
|
||||||
{name: "weekend", args: []string{"weekend"}, want: app.ReportWeekend},
|
{name: "weekend", args: []string{"weekend"}, want: app.ReportWeekend},
|
||||||
{name: "storm", args: []string{"storm", "--start", "2026-05-29T18:00", "--end", "2026-05-30T06:00"}, want: app.ReportStorm},
|
{name: "storm", args: []string{"storm", "--start", "2026-05-29T18:00", "--end", "2026-05-30T06:00"}, want: app.ReportStorm},
|
||||||
@@ -827,6 +831,53 @@ func TestResolveGenerateCommands(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResolveGenerateNearTermAppliesSharedFlags(t *testing.T) {
|
||||||
|
runner := Runner{Clock: fixedClock()}
|
||||||
|
configPath := filepath.Join(t.TempDir(), "config.yml")
|
||||||
|
if err := os.WriteFile(configPath, []byte("weather_api:\n units: metric\n timezone: UTC\n"), 0o600); err != nil {
|
||||||
|
t.Fatalf("write config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := runner.resolveGenerate([]string{"near-term", "--config", configPath, "--units", "us", "--tz", "America/Chicago", "--out", "./near-term.md"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("resolveGenerate() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Report != app.ReportNearTerm {
|
||||||
|
t.Fatalf("Report = %q, want near-term", req.Report)
|
||||||
|
}
|
||||||
|
if req.Config.WeatherAPI.Units != "us" {
|
||||||
|
t.Fatalf("Units = %q, want us", req.Config.WeatherAPI.Units)
|
||||||
|
}
|
||||||
|
if req.Config.WeatherAPI.Timezone != "America/Chicago" {
|
||||||
|
t.Fatalf("Timezone = %q, want America/Chicago", req.Config.WeatherAPI.Timezone)
|
||||||
|
}
|
||||||
|
if req.OutputPath != "./near-term.md" {
|
||||||
|
t.Fatalf("OutputPath = %q, want ./near-term.md", req.OutputPath)
|
||||||
|
}
|
||||||
|
if !req.Date.IsZero() || !req.StormStart.IsZero() || !req.StormEnd.IsZero() {
|
||||||
|
t.Fatalf("date/storm bounds = %s/%s/%s, want unset for near-term", req.Date, req.StormStart, req.StormEnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolveGenerateNearTermRejectsDateAndStormBounds(t *testing.T) {
|
||||||
|
runner := Runner{Clock: fixedClock()}
|
||||||
|
|
||||||
|
for _, args := range [][]string{
|
||||||
|
{"near-term", "--date", "2026-05-29"},
|
||||||
|
{"near-term", "--start", "2026-05-29T18:00"},
|
||||||
|
{"near-term", "--end", "2026-05-29T20:00"},
|
||||||
|
} {
|
||||||
|
_, err := runner.resolveGenerate(args)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("resolveGenerate(%v) error = nil, want flag error", args)
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "flag provided but not defined") {
|
||||||
|
t.Fatalf("resolveGenerate(%v) error = %q, want undefined flag error", args, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestResolveGenerateDailyDefaultsDateInConfiguredTimezone(t *testing.T) {
|
func TestResolveGenerateDailyDefaultsDateInConfiguredTimezone(t *testing.T) {
|
||||||
runner := Runner{Clock: fixedClock()}
|
runner := Runner{Clock: fixedClock()}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user