From 2218eb273bfbffed0e5e6c69944b6ee5965b7ea7 Mon Sep 17 00:00:00 2001 From: 54L1M Date: Wed, 25 Nov 2026 09:40:51 +0100 Subject: [PATCH] feat: scan only posts jobs at or above a minimum fit score --- README.md | 1 + main.go | 24 +++++++++++++----------- scan.go | 19 ++++++++++++++++--- scan_test.go | 32 +++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 862ea82..04c607f 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ All through the environment: | `JOBHUNT_DISCORD_CHANNEL` | channel ID | | `JOBHUNT_DISCORD_OWNER` | the only user ID the bot listens to | | `JOBHUNT_SCAN_MAX` | postings assessed per scan run (default 10) | +| `JOBHUNT_SCAN_MIN_FIT` | the scan only posts fit scores at or above this (default 60) | | `JOBHUNT_MODEL`, `JOBHUNT_CLAUDE` | model override, path to the CLI | ## Development diff --git a/main.go b/main.go index 8f06158..bb453be 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,8 @@ type Config struct { OwnerID string // the only Discord user the bot listens to Poll time.Duration - ScanMax int // postings assessed per scan run + ScanMax int // postings assessed per scan run + ScanMinFit int // the scan stays silent about postings scoring below this } func env(key, fallback string) string { @@ -56,16 +57,17 @@ func envInt(key string, fallback int) int { func loadConfig() Config { notes := env("JOBHUNT_NOTES_DIR", ".") return Config{ - NotesDir: notes, - CVPath: env("JOBHUNT_CV", notes+"/CV.md"), - StateDir: env("JOBHUNT_STATE_DIR", os.TempDir()), - ClaudeBin: env("JOBHUNT_CLAUDE", "claude"), - Model: os.Getenv("JOBHUNT_MODEL"), - TokenFile: os.Getenv("JOBHUNT_DISCORD_TOKEN_FILE"), - ChannelID: os.Getenv("JOBHUNT_DISCORD_CHANNEL"), - OwnerID: os.Getenv("JOBHUNT_DISCORD_OWNER"), - Poll: 5 * time.Second, - ScanMax: envInt("JOBHUNT_SCAN_MAX", 10), + NotesDir: notes, + CVPath: env("JOBHUNT_CV", notes+"/CV.md"), + StateDir: env("JOBHUNT_STATE_DIR", os.TempDir()), + ClaudeBin: env("JOBHUNT_CLAUDE", "claude"), + Model: os.Getenv("JOBHUNT_MODEL"), + TokenFile: os.Getenv("JOBHUNT_DISCORD_TOKEN_FILE"), + ChannelID: os.Getenv("JOBHUNT_DISCORD_CHANNEL"), + OwnerID: os.Getenv("JOBHUNT_DISCORD_OWNER"), + Poll: 5 * time.Second, + ScanMax: envInt("JOBHUNT_SCAN_MAX", 10), + ScanMinFit: envInt("JOBHUNT_SCAN_MIN_FIT", 60), } } diff --git a/scan.go b/scan.go index 668d300..5561c4a 100644 --- a/scan.go +++ b/scan.go @@ -16,7 +16,8 @@ import ( // Scanner is the scheduled half: it reads the company feeds, keeps the jobs // that match the search profile and have not been seen before, and runs each // through the same assessment the bot uses. Postings that require a language -// the CV does not list are dropped silently. +// the CV does not list, or that score below the minimum fit, get no note and +// no package: they only show up in the one-line summary of the run. type Scanner struct { cfg Config sources []Source @@ -129,6 +130,7 @@ func (s *Scanner) run(ctx context.Context) error { jobs, failedFeeds := s.candidates(ctx, seen) var posted, dropped int + var lowFit []string var stopped error done := 0 for _, j := range jobs { @@ -144,6 +146,9 @@ func (s *Scanner) run(ctx context.Context) error { break } done++ + if fit, ok := strings.CutPrefix(outcome, "low fit "); ok { + lowFit = append(lowFit, fmt.Sprintf("%s, %s (%s)", j.Company, j.Title, fit)) + } seen[j.Key] = s.now().Format(time.DateOnly) + " " + outcome if err := s.saveSeen(seen); err != nil { return fmt.Errorf("saving seen jobs: %w", err) // or the next run posts duplicates @@ -156,11 +161,16 @@ func (s *Scanner) run(ctx context.Context) error { } } - slog.Info("scan finished", "matches", len(jobs), "posted", posted, "dropped_language", dropped, "queued", len(jobs)-done) + slog.Info("scan finished", "matches", len(jobs), "posted", posted, "dropped_language", dropped, + "dropped_low_fit", len(lowFit), "queued", len(jobs)-done) if done == 0 && stopped == nil && len(failedFeeds) == 0 { return nil // nothing new: stay quiet } - line := fmt.Sprintf("Scan: %d posted, %d dropped for a language requirement, %d still queued.", posted, dropped, len(jobs)-done) + line := fmt.Sprintf("Scan: %d posted, %d dropped for a language requirement, %d below fit %d, %d still queued.", + posted, dropped, len(lowFit), s.cfg.ScanMinFit, len(jobs)-done) + if len(lowFit) > 0 { + line += "\nBelow the cutoff: " + strings.Join(lowFit, "; ") + "." + } if len(failedFeeds) > 0 { line += " Feeds that failed: " + strings.Join(failedFeeds, ", ") + "." } @@ -198,6 +208,9 @@ func (s *Scanner) handle(ctx context.Context, j Job) (string, error) { case pkg.LanguageBlocker: slog.Info("dropped: language requirement", "company", j.Company, "title", j.Title, "why", pkg.DutchRequirement) return "language", nil + case pkg.FitScore < s.cfg.ScanMinFit: + slog.Info("dropped: low fit", "company", j.Company, "title", j.Title, "fit", pkg.FitScore, "why", pkg.VerdictReason) + return fmt.Sprintf("low fit %d", pkg.FitScore), nil } note := renderNote(pkg, j.URL, s.now()) diff --git a/scan_test.go b/scan_test.go index be37d7a..1171e12 100644 --- a/scan_test.go +++ b/scan_test.go @@ -150,7 +150,7 @@ func newScanFixture(t *testing.T, jobs []Job, assess func(Posting) (*Package, er t.Helper() f := &scanFixture{} f.Scanner = &Scanner{ - cfg: Config{NotesDir: t.TempDir(), StateDir: t.TempDir(), ScanMax: 10}, + cfg: Config{NotesDir: t.TempDir(), StateDir: t.TempDir(), ScanMax: 10, ScanMinFit: 60}, sources: []Source{{"Acme", "greenhouse", "acme"}, {"Broken", "greenhouse", "broken"}}, list: func(_ context.Context, s Source) ([]Job, error) { if s.Slug == "broken" { @@ -227,6 +227,36 @@ func TestScanRun(t *testing.T) { } }) + t.Run("stays silent about postings below the minimum fit", func(t *testing.T) { + jobs := []Job{scanJob("1", "Backend Engineer"), scanJob("2", "Software Engineer"), scanJob("3", "Fullstack Engineer")} + f := newScanFixture(t, jobs, func(p Posting) (*Package, error) { + pkg, _ := okPackage(p) + pkg.FitScore = map[string]int{"1": 60, "2": 59, "3": 41}[filepath.Base(p.URL)] + return pkg, nil + }) + f.sources = f.sources[:1] + if err := f.run(t.Context()); err != nil { + t.Fatal(err) + } + notes, _ := filepath.Glob(filepath.Join(f.cfg.NotesDir, "*.md")) + if len(f.files) != 1 || len(notes) != 1 || !strings.Contains(f.posts[0], "Fit 60/100") { + t.Fatalf("only the job at the cutoff should be posted and filed: files %v notes %v", f.files, notes) + } + summary := f.posts[len(f.posts)-1] + for _, want := range []string{"1 posted", "2 below fit 60", "Acme, Software Engineer (59)", "Acme, Fullstack Engineer (41)"} { + if !strings.Contains(summary, want) { + t.Errorf("summary %q should contain %q", summary, want) + } + } + f.assessed = nil + if err := f.run(t.Context()); err != nil { + t.Fatal(err) + } + if len(f.assessed) != 0 { + t.Errorf("low-fit jobs were assessed again: %v", f.assessed) + } + }) + t.Run("caps a run and leaves the rest for the next one", func(t *testing.T) { jobs := []Job{scanJob("1", "Backend Engineer"), scanJob("2", "Backend Engineer"), scanJob("3", "Backend Engineer")} f := newScanFixture(t, jobs, okPackage)