feat: scan only posts jobs at or above a minimum fit score

This commit is contained in:
2026-11-25 09:40:51 +01:00
parent f7dcbb9c14
commit 2218eb273b
4 changed files with 61 additions and 15 deletions
+1
View File
@@ -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
+2
View File
@@ -37,6 +37,7 @@ type Config struct {
Poll time.Duration
ScanMax int // postings assessed per scan run
ScanMinFit int // the scan stays silent about postings scoring below this
}
func env(key, fallback string) string {
@@ -66,6 +67,7 @@ func loadConfig() Config {
OwnerID: os.Getenv("JOBHUNT_DISCORD_OWNER"),
Poll: 5 * time.Second,
ScanMax: envInt("JOBHUNT_SCAN_MAX", 10),
ScanMinFit: envInt("JOBHUNT_SCAN_MIN_FIT", 60),
}
}
+16 -3
View File
@@ -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())
+31 -1
View File
@@ -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)