Add Daily prompt input preflight
This commit is contained in:
@@ -28,7 +28,7 @@ Options:
|
||||
--config PATH Load configuration from PATH instead of /usr/local/etc/weatherreporter/config.yml.
|
||||
--units VALUE Override weather API units.
|
||||
--tz NAME Override weather API timezone.
|
||||
--out PATH Override report output path or directory.
|
||||
--out PATH Override the generated data package path for generate daily.
|
||||
`
|
||||
|
||||
type Runner struct {
|
||||
@@ -210,7 +210,7 @@ func addCommonFlags(fs *flag.FlagSet, opts *commonOptions, includeOutput bool) {
|
||||
fs.StringVar(&opts.Units, "units", "", "weather API units")
|
||||
fs.StringVar(&opts.Timezone, "tz", "", "weather API timezone")
|
||||
if includeOutput {
|
||||
fs.StringVar(&opts.Output, "out", "", "report output path or directory")
|
||||
fs.StringVar(&opts.Output, "out", "", "generated data package path")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,13 +71,17 @@ func TestRunGenerateReturnsNotImplementedAfterResolution(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunGenerateDailyWritesBriefing(t *testing.T) {
|
||||
func TestRunGenerateDailyWritesDataPackageAndRunsPreflight(t *testing.T) {
|
||||
server := dailyServer(t)
|
||||
configPath := filepath.Join(t.TempDir(), "config.yml")
|
||||
if err := os.WriteFile(configPath, []byte("weather_api:\n base_url: "+server.URL+"/\n timezone: America/Chicago\n"), 0o600); err != nil {
|
||||
tempDir := t.TempDir()
|
||||
scriptoriumPath := writeFakeScriptorium(t, tempDir)
|
||||
configPath := filepath.Join(tempDir, "config.yml")
|
||||
workspaceRoot := filepath.Join(tempDir, "workspace")
|
||||
configBody := "weather_api:\n base_url: " + server.URL + "/\n timezone: America/Chicago\nscriptorium:\n binary: " + scriptoriumPath + "\nworkspace:\n root: " + workspaceRoot + "\n"
|
||||
if err := os.WriteFile(configPath, []byte(configBody), 0o600); err != nil {
|
||||
t.Fatalf("write config: %v", err)
|
||||
}
|
||||
outPath := filepath.Join(t.TempDir(), "daily.briefing.json")
|
||||
outPath := filepath.Join(tempDir, "daily.data_package.json")
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
runner := Runner{Clock: fixedClock()}
|
||||
@@ -93,10 +97,24 @@ func TestRunGenerateDailyWritesBriefing(t *testing.T) {
|
||||
}
|
||||
data, err := os.ReadFile(outPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read briefing: %v", err)
|
||||
t.Fatalf("read data package: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(data), `"schemaVersion"`) || !strings.Contains(string(data), `"daily_today"`) {
|
||||
t.Fatalf("briefing output missing expected content:\n%s", string(data))
|
||||
if !strings.Contains(string(data), `data_package.v1`) || !strings.Contains(string(data), `"daily_today"`) {
|
||||
t.Fatalf("data package output missing expected content:\n%s", string(data))
|
||||
}
|
||||
preflightMatches, err := filepath.Glob(filepath.Join(workspaceRoot, "preflight", "daily", "2026-05-29", "*.render.json"))
|
||||
if err != nil {
|
||||
t.Fatalf("glob preflight: %v", err)
|
||||
}
|
||||
if len(preflightMatches) != 1 {
|
||||
t.Fatalf("preflight files = %#v, want one render output", preflightMatches)
|
||||
}
|
||||
preflight, err := os.ReadFile(preflightMatches[0])
|
||||
if err != nil {
|
||||
t.Fatalf("read preflight: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(preflight), `ok`) {
|
||||
t.Fatalf("preflight missing fake render output:\n%s", string(preflight))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,3 +265,13 @@ func dailyServer(t *testing.T) *httptest.Server {
|
||||
t.Cleanup(server.Close)
|
||||
return server
|
||||
}
|
||||
|
||||
func writeFakeScriptorium(t *testing.T, dir string) string {
|
||||
t.Helper()
|
||||
path := filepath.Join(dir, "scriptorium")
|
||||
body := "#!/bin/sh\nprintf '{\"ok\":true,\"argv\":\"%s\"}' \"$*\"\n"
|
||||
if err := os.WriteFile(path, []byte(body), 0o700); err != nil {
|
||||
t.Fatalf("write fake scriptorium: %v", err)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user