Skip to content

Commit 94d6b91

Browse files
committed
refactor(fetch): Use constants for LLM task names and add salary filter tests
Signed-off-by: wallentx <william.allentx@gmail.com>
1 parent e6d6594 commit 94d6b91

5 files changed

Lines changed: 57 additions & 15 deletions

File tree

internal/fetcher/job_fetcher.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ func fetchAllJobsWithCandidateCache(ctx context.Context, appCfg *AppConfig, crit
9494
// 1. Fetch via LLM job search when enabled.
9595
if appCfg.LLM.Enabled && appCfg.LLM.JobSearch {
9696
llmSvc := getLLMService(ctx)
97-
if !llmSvc.IsAvailable(ctx, "llm_job_search") {
97+
if !llmSvc.IsAvailable(ctx, LLMTaskJobSearch) {
9898
mu.Lock()
9999
setFetchSearchStatus(&summary, fetchSearchLLM, "disabled: LLM job search runner unavailable")
100100
mu.Unlock()
101101
} else {
102102
reportFetchProgress(progress, "Preparing LLM job search...")
103-
llm, restoreAuth, initErr := llmSvc.InitConfiguredLLM(ctx, appCfg, llmTaskJobSearch)
103+
llm, restoreAuth, initErr := llmSvc.InitConfiguredLLM(ctx, appCfg, LLMTaskJobSearch)
104104
if initErr == nil {
105105
defer restoreAuth()
106106
promptBytes, err := fetchAllJobsReadFile(runtimeSearchPromptPath)
@@ -156,7 +156,7 @@ func fetchAllJobsWithCandidateCache(ctx context.Context, appCfg *AppConfig, crit
156156
switch {
157157
case !appCfg.LLM.Enabled:
158158
setFetchSearchStatus(&summary, fetchSearchLLMWeb, "disabled: LLM is disabled in config")
159-
case !getLLMService(ctx).IsAvailable(ctx, "llm_web_search"):
159+
case !getLLMService(ctx).IsAvailable(ctx, LLMTaskWebSearch):
160160
setFetchSearchStatus(&summary, fetchSearchLLMWeb, "disabled: LLM search runner unavailable")
161161
case len(effectiveSources.LLMWebTargets) == 0:
162162
setFetchSearchStatus(&summary, fetchSearchLLMWeb, "enabled, but no llm_web targets were configured or resolved")

internal/fetcher/job_fetcher_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ func TestFetchAllJobsLLMWebParseErrorIsSkipped(t *testing.T) {
378378
prevSearch := fetchAllJobsExecuteLLMSearch
379379
prevWebSearch := fetchAllJobsExecuteLLMWebSearch
380380
fetchAllJobsInitConfiguredLLM = func(ctx context.Context, appCfg *AppConfig, task string) (llms.Model, func(), error) {
381-
if task != llmTaskJobSearch {
382-
t.Fatalf("fetchAllJobsInitConfiguredLLM task = %q, want %q", task, llmTaskJobSearch)
381+
if task != LLMTaskJobSearch {
382+
t.Fatalf("fetchAllJobsInitConfiguredLLM task = %q, want %q", task, LLMTaskJobSearch)
383383
}
384384
return fakeLLMModel{}, func() {}, nil
385385
}
@@ -634,8 +634,8 @@ func TestFetchAllJobsLLMSearchRepairsIdentityBeforeValidation(t *testing.T) {
634634
if applyGETRequests == 0 {
635635
t.Fatal("fetchAllJobs() did not fetch the apply page for llm_job_search identity repair")
636636
}
637-
if len(initTasks) != 1 || initTasks[0] != llmTaskJobSearch {
638-
t.Fatalf("fetchAllJobs() initialized LLM tasks %#v, want only %q", initTasks, llmTaskJobSearch)
637+
if len(initTasks) != 1 || initTasks[0] != LLMTaskJobSearch {
638+
t.Fatalf("fetchAllJobs() initialized LLM tasks %#v, want only %q", initTasks, LLMTaskJobSearch)
639639
}
640640
if got, want := jobs[0].CompanyWebsite, "https://www.acme.com"; got != want {
641641
t.Fatalf("jobs[0].CompanyWebsite = %q, want %q", got, want)
@@ -2249,8 +2249,8 @@ func TestFetchAllJobsCombinesLLMAndRSSSources(t *testing.T) {
22492249
prevIdentity := fetchAllJobsEnrichJobIdentity
22502250
prevReadFile := fetchAllJobsReadFile
22512251
fetchAllJobsInitConfiguredLLM = func(ctx context.Context, appCfg *AppConfig, task string) (llms.Model, func(), error) {
2252-
if task != llmTaskJobSearch && task != llmTaskJobIdentity {
2253-
t.Fatalf("fetchAllJobsInitConfiguredLLM task = %q, want %q or %q", task, llmTaskJobSearch, llmTaskJobIdentity)
2252+
if task != LLMTaskJobSearch && task != llmTaskJobIdentity {
2253+
t.Fatalf("fetchAllJobsInitConfiguredLLM task = %q, want %q or %q", task, LLMTaskJobSearch, llmTaskJobIdentity)
22542254
}
22552255
return fakeLLMModel{}, func() {}, nil
22562256
}

internal/fetcher/job_filter_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@ package fetcher
22

33
import "testing"
44

5+
func TestExtractAndCheckSalary(t *testing.T) {
6+
tests := []struct {
7+
text string
8+
minBase int
9+
want bool
10+
}{
11+
{
12+
text: "Competitive / DOE",
13+
minBase: 120000,
14+
want: true,
15+
},
16+
{
17+
text: "$90K - $150K",
18+
minBase: 120000,
19+
want: true,
20+
},
21+
{
22+
text: "$80K - $95K",
23+
minBase: 120000,
24+
want: false,
25+
},
26+
{
27+
text: "$118,000 - $231,000 USD/year",
28+
minBase: 120000,
29+
want: true,
30+
},
31+
}
32+
33+
for _, tt := range tests {
34+
t.Run(tt.text, func(t *testing.T) {
35+
if got := extractAndCheckSalary(tt.text, tt.minBase); got != tt.want {
36+
t.Fatalf("extractAndCheckSalary(%q, %d) = %t; want %t", tt.text, tt.minBase, got, tt.want)
37+
}
38+
})
39+
}
40+
}
41+
542
func TestJobMatchesWorkSettings(t *testing.T) {
643
tests := []struct {
744
name string

internal/fetcher/job_identity_enricher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func newJobIdentityLLMEnricher(ctx context.Context, appCfg *AppConfig) (jobIdentityPageEnrichFunc, func(), string) {
1010
llmSvc := getLLMService(ctx)
11-
if appCfg == nil || !appCfg.LLM.Enabled || !llmSvc.IsAvailable(ctx, "llm_job_enrichment") {
11+
if appCfg == nil || !appCfg.LLM.Enabled || !llmSvc.IsAvailable(ctx, LLMTaskJobEnrichment) {
1212
return nil, nil, ""
1313
}
1414
llm, restoreAuth, err := llmSvc.InitConfiguredLLM(ctx, appCfg, llmTaskJobIdentity)

internal/fetcher/llm_hooks.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import (
88
"github.com/tmc/langchaingo/llms"
99
)
1010

11-
const llmTaskJobSearch = "llm_job_search"
11+
const (
12+
LLMTaskJobSearch = "llm_job_search"
13+
LLMTaskWebSearch = "llm_web_search"
14+
LLMTaskJobEnrichment = "llm_job_enrichment"
15+
)
16+
1217
const llmTaskJobIdentity = "job_identity"
1318

1419
type InitLLMFunc func(ctx context.Context, appCfg *AppConfig, task string) (llms.Model, func(), error)
@@ -78,7 +83,7 @@ func (fallbackLLMService) ExecuteWebSearch(ctx context.Context, appCfg *AppConfi
7883
if fetchAllJobsInitConfiguredLLM == nil || fetchAllJobsExecuteLLMSearch == nil {
7984
return nil, fmt.Errorf("LLM web search hook not configured")
8085
}
81-
llm, restoreAuth, err := fetchAllJobsInitConfiguredLLM(ctx, appCfg, llmTaskJobSearch)
86+
llm, restoreAuth, err := fetchAllJobsInitConfiguredLLM(ctx, appCfg, LLMTaskJobSearch)
8287
if err != nil {
8388
return nil, fmt.Errorf("failed to initialize: %w", err)
8489
}
@@ -94,13 +99,13 @@ func (fallbackLLMService) EnrichJobIdentity(ctx context.Context, llm llms.Model,
9499
}
95100

96101
func (fallbackLLMService) IsAvailable(ctx context.Context, task string) bool {
97-
if task == "llm_web_search" {
102+
if task == LLMTaskWebSearch {
98103
return fetchAllJobsExecuteLLMWebSearch != nil || (fetchAllJobsInitConfiguredLLM != nil && fetchAllJobsExecuteLLMSearch != nil)
99104
}
100-
if task == "llm_job_search" {
105+
if task == LLMTaskJobSearch {
101106
return fetchAllJobsInitConfiguredLLM != nil && fetchAllJobsExecuteLLMSearch != nil
102107
}
103-
if task == "llm_job_enrichment" {
108+
if task == LLMTaskJobEnrichment {
104109
return fetchAllJobsInitConfiguredLLM != nil && fetchAllJobsEnrichJobIdentity != nil
105110
}
106111
return false

0 commit comments

Comments
 (0)