{{.Occupation.Title}}
{{.Occupation.Summary}}
{{.Reason}}
Try it first: {{.Occupation.TryFirst}}
Review the O*NET occupation profilediff --git a/cmd/nextpath/internal/opportunity/store.go b/cmd/nextpath/internal/opportunity/store.go new file mode 100644 index 0000000..7f39c77 --- /dev/null +++ b/cmd/nextpath/internal/opportunity/store.go @@ -0,0 +1,37 @@ +package opportunity + +import ( + "encoding/json" + "fmt" + "os" +) + +type Snapshot struct { + Version string `json:"version"` + GeneratedAt string `json:"generated_at"` + Occupations map[string]Evidence `json:"occupations"` +} + +// Load reads the latest complete snapshot. A missing cache is an expected +// state: NextPath can still provide interest matches without inventing labor +// evidence. +func Load(path string) (Snapshot, error) { + if path == "" { + return Snapshot{}, nil + } + data, err := os.ReadFile(path) + if os.IsNotExist(err) { + return Snapshot{}, nil + } + if err != nil { + return Snapshot{}, fmt.Errorf("read opportunity cache: %w", err) + } + var snapshot Snapshot + if err := json.Unmarshal(data, &snapshot); err != nil { + return Snapshot{}, fmt.Errorf("decode opportunity cache: %w", err) + } + if snapshot.Version == "" || len(snapshot.Occupations) == 0 { + return Snapshot{}, fmt.Errorf("opportunity cache is empty") + } + return snapshot, nil +} diff --git a/cmd/nextpath/internal/opportunity/store_test.go b/cmd/nextpath/internal/opportunity/store_test.go new file mode 100644 index 0000000..c16d0f3 --- /dev/null +++ b/cmd/nextpath/internal/opportunity/store_test.go @@ -0,0 +1,24 @@ +package opportunity + +import ( + "os" + "path/filepath" + "testing" +) + +func TestLoadMissingSnapshotIsAvailableState(t *testing.T) { + snapshot, err := Load(filepath.Join(t.TempDir(), "missing.json")) + if err != nil || len(snapshot.Occupations) != 0 { + t.Fatalf("Load missing = %#v, %v", snapshot, err) + } +} + +func TestLoadRejectsMalformedSnapshot(t *testing.T) { + path := filepath.Join(t.TempDir(), "opportunity.json") + if err := os.WriteFile(path, []byte(`{"version":"v1","occupations":{}}`), 0o600); err != nil { + t.Fatal(err) + } + if _, err := Load(path); err == nil { + t.Fatal("Load accepted empty snapshot") + } +} diff --git a/cmd/nextpath/internal/web/server.go b/cmd/nextpath/internal/web/server.go index 0fea2a1..68548f7 100644 --- a/cmd/nextpath/internal/web/server.go +++ b/cmd/nextpath/internal/web/server.go @@ -15,6 +15,7 @@ import ( "my-homelab-configs/cmd/nextpath/internal/account" "my-homelab-configs/cmd/nextpath/internal/assessment" "my-homelab-configs/cmd/nextpath/internal/career" + "my-homelab-configs/cmd/nextpath/internal/opportunity" ) const ( @@ -24,9 +25,15 @@ const ( ) type Config struct { - SecureCookies bool - SessionTTL time.Duration - Logger *slog.Logger + SecureCookies bool + SessionTTL time.Duration + Logger *slog.Logger + OpportunityStorePath string +} + +type careerResult struct { + career.Match + Outlook *opportunity.Outlook } type session struct { @@ -216,11 +223,28 @@ func (server *Server) results(writer http.ResponseWriter, request *http.Request) return } matches := career.Rank(result, catalog, 5) + snapshot, err := opportunity.Load(server.config.OpportunityStorePath) + if err != nil { + server.config.Logger.Warn("load NextPath opportunity evidence", "error", err) + } + careerResults := make([]careerResult, 0, len(matches)) + for _, match := range matches { + view := careerResult{Match: match} + if evidence, exists := snapshot.Occupations[match.Occupation.ONETSOC]; exists { + if outlook, calculateErr := opportunity.Calculate(evidence); calculateErr == nil { + view.Outlook = &outlook + } else { + server.config.Logger.Warn("calculate NextPath employability outlook", "occupation", match.Occupation.ONETSOC, "error", calculateErr) + } + } + careerResults = append(careerResults, view) + } server.mu.Lock() csrf := server.sessions[token].CSRFToken server.mu.Unlock() server.render(writer, http.StatusOK, "Your interest profile", resultsPage, map[string]any{ - "Name": user.DisplayName, "Result": result, "Matches": matches, "CSRF": csrf, + "Name": user.DisplayName, "Result": result, "Matches": careerResults, "CSRF": csrf, + "OpportunityGeneratedAt": snapshot.GeneratedAt, }) } diff --git a/cmd/nextpath/internal/web/server_test.go b/cmd/nextpath/internal/web/server_test.go index 89847c6..d7b05e3 100644 --- a/cmd/nextpath/internal/web/server_test.go +++ b/cmd/nextpath/internal/web/server_test.go @@ -6,6 +6,7 @@ import ( "net/http/cookiejar" "net/http/httptest" "net/url" + "os" "path/filepath" "regexp" "strings" @@ -22,7 +23,17 @@ func TestCompletePrivateAssessmentFlow(t *testing.T) { if err != nil { t.Fatal(err) } - testServer := httptest.NewServer(New(accounts, Config{}).Handler()) + opportunityPath := filepath.Join(t.TempDir(), "opportunity.json") + if err := os.WriteFile(opportunityPath, []byte(`{ + "version":"v1","generated_at":"2026-12-05T12:00:00Z","occupations":{"13-2011.00":{ + "arizona_annual_graduates":100,"arizona_projected_annual_openings":100,"active_entry_level_postings":50, + "graduate_academic_year":"latest","projection_period":"2022-2032","postings_observed_at":"2026-12-05T12:00:00Z", + "geography":"Arizona","soc_to_cip_mapping_coverage":0.9, + "graduate_source_url":"https://example.test/graduates","projection_source_url":"https://example.test/projections","posting_source_url":"https://example.test/jobs" + }}}`), 0o600); err != nil { + t.Fatal(err) + } + testServer := httptest.NewServer(New(accounts, Config{OpportunityStorePath: opportunityPath}).Handler()) defer testServer.Close() jar, _ := cookiejar.New(nil) client := &http.Client{Jar: jar, CheckRedirect: func(_ *http.Request, _ []*http.Request) error { return http.ErrUseLastResponse }} @@ -56,7 +67,7 @@ func TestCompletePrivateAssessmentFlow(t *testing.T) { response = get(t, client, testServer.URL+"/results") body := readBody(t, response) - if response.StatusCode != http.StatusOK || !strings.Contains(body, "interest profile") || !strings.Contains(body, "not ability, identity, or employability") || !strings.Contains(body, "Careers to explore next") { + if response.StatusCode != http.StatusOK || !strings.Contains(body, "interest profile") || !strings.Contains(body, "not ability or identity") || !strings.Contains(body, "Careers to explore next") || !strings.Contains(body, "Arizona employability outlook: 88%") { t.Fatalf("unexpected results response %d: %s", response.StatusCode, body) } response = get(t, client, testServer.URL+"/account/export") diff --git a/cmd/nextpath/internal/web/templates.go b/cmd/nextpath/internal/web/templates.go index dc88b9b..dfabc2a 100644 --- a/cmd/nextpath/internal/web/templates.go +++ b/cmd/nextpath/internal/web/templates.go @@ -24,4 +24,4 @@ const loginPage = `{{define "content"}}
Rate the activity itself—not whether you are already good at it.
{{.Answered}} of {{.Total}} answered
Hello {{.Name}}. Your three-letter exploration code is {{.Result.Code}}.
These are personal-interest matches, not employability rankings. Arizona market and education evidence will be scored separately.
{{range .Matches}}{{.Occupation.Summary}}
{{.Reason}}
Try it first: {{.Occupation.TryFirst}}
Review the O*NET occupation profile{{.Result.InstrumentNotice}}
Confidence: {{.Result.Confidence}}. This describes interests, not ability, identity, or employability.
Hello {{.Name}}. Your three-letter exploration code is {{.Result.Code}}.
Interest fit and Arizona market outlook are separate signals. The market percentage is a rough demand-to-completions comparison, not your probability of being hired.
{{range .Matches}}{{.Occupation.Summary}}
{{.Reason}}
{{if .Outlook}}{{.Outlook.Label}} · {{.Outlook.Confidence}} evidence confidence
{{.Outlook.Evidence.ArizonaProjectedOpenings}} projected openings/year and {{.Outlook.Evidence.ActiveEntryLevelPostings}} postings observed, compared with {{.Outlook.Evidence.ArizonaAnnualGraduates}} recent Arizona completions. Demand-to-completions ratio: {{.Outlook.AnnualDemandToGraduateRatio}}.
Formula: 75% projected annual demand coverage + 25% current posting coverage. Posting snapshot {{.Outlook.Evidence.PostingsObservedAt.Format "Jan 2, 2006"}}.
Arizona employability outlook unavailable. Complete source evidence has not been refreshed for this occupation; no percentage is estimated.
{{end}}Try it first: {{.Occupation.TryFirst}}
Review the O*NET occupation profile{{.Result.InstrumentNotice}}
Confidence: {{.Result.Confidence}}. This describes interests, not ability or identity. Market outlook is contextual evidence, not a hiring promise.