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
+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)