Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 109x 109x 109x 109x 37x 37x 37x 37x 37x 37x 37x 37x 37x 109x 25x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 1x 37x 37x 37x 37x 37x 37x 37x 37x 3x 3x 3x 37x 37x 37x 8x 37x 7x 7x 7x 3x 3x 1x 37x 37x 37x 37x 37x 37x 37x 37x 8x 34x 3x 3x 1x 1x 1x 34x 4x 3x 3x 37x 3x 3x 37x 1x 37x 37x 37x 37x 37x 37x 37x 9x 37x 37x 4x 4x 4x 37x 2x 2x 2x 34x 2x 2x 37x 1x 37x 37x 37x 37x 37x 37x 37x 34x 2x 2x 2x 4x 4x 37x 37x 37x | import type { JobAnalysisPayload } from "../../../shared/types/job";
import {
PREFERENCE_SENIORITIES,
seniorityRangeLabel,
type Preferences,
} from "../../../shared/types/profile";
/**
* Deterministic preference checks (research R11, FR-016): arrangement, office
* days, salary and seniority. Locations and visa sponsorship are judged by the
* model and reach the banner through the dealbreaker judge, so they are never
* checked here. A violation needs a stated fact: an unstated one becomes an
* "Unverified: …" weakness instead. Never reads or writes `score` (FR-005).
*/
const WEAKNESSES_MAX = 5;
export function applyPreferences(
payload: JobAnalysisPayload,
preferences: Preferences | null | undefined
): JobAnalysisPayload {
if (!preferences || !payload.fit) return payload;
const violations: string[] = [];
const unverified: string[] = [];
const arrangementViolated = checkArrangement(payload, preferences, violations, unverified);
checkOfficeDays(payload, preferences, arrangementViolated, violations, unverified);
checkSalary(payload, preferences, violations, unverified);
checkSeniority(payload, preferences, violations, unverified);
if (violations.length === 0 && unverified.length === 0) return payload;
const existing = payload.fit.dealbreakersViolated ?? [];
const dealbreakersViolated = [
...existing,
...violations.filter((v) => !existing.includes(v)),
];
const covered = unverified.map(topicOf);
const modelWeaknesses = (payload.fit.weaknesses ?? []).filter(
(w) => !/^unverified/i.test(w) || !covered.some((topic) => topic?.test(w))
);
const weaknesses = [...unverified, ...modelWeaknesses].slice(0, WEAKNESSES_MAX);
return { ...payload, fit: { ...payload.fit, dealbreakersViolated, weaknesses } };
}
/** What each code-written "Unverified" note is about, to spot the model repeating it (#31). */
const NOTE_TOPICS: [RegExp, RegExp][] = [
[/^Unverified: arrangement/, /arrangement|on-?site|remote|hybrid/i],
[/^Unverified: office days/, /office days|days in (the )?office/i],
[/^Unverified: salary/, /salary|compensation|pay\b/i],
[/^Unverified: seniority/, /seniority|level/i],
];
function topicOf(note: string): RegExp | undefined {
return NOTE_TOPICS.find(([prefix]) => prefix.test(note))?.[1];
}
function checkArrangement(
payload: JobAnalysisPayload,
{ arrangements }: Preferences,
violations: string[],
unverified: string[]
): boolean {
if (!arrangements?.length) return false;
if (payload.arrangement === "unspecified") {
unverified.push("Unverified: arrangement not stated");
return false;
}
const offered = [payload.arrangement, ...(payload.alsoOffers ?? [])];
if (
!offered.some((a) => arrangements.includes(a)) &&
payload.arrangementConfidence !== "none"
) {
violations.push(`Arrangement: ${arrangements.join(" or ")} only`);
return true;
}
return false;
}
function checkOfficeDays(
payload: JobAnalysisPayload,
{ maxOfficeDays }: Preferences,
arrangementViolated: boolean,
violations: string[],
unverified: string[]
): void {
if (maxOfficeDays === undefined) return;
let days: number | null = null;
if (payload.arrangement === "hybrid") {
days = payload.daysInOffice;
if (days === null) {
unverified.push("Unverified: office days not stated");
return;
}
} else if (payload.arrangement === "onsite" && payload.arrangementConfidence !== "none") {
if (arrangementViolated) return;
days = 5;
}
if (days !== null && days > maxOfficeDays) {
violations.push(`Office days: at most ${maxOfficeDays} per week`);
}
}
function checkSalary(
payload: JobAnalysisPayload,
{ minSalary }: Preferences,
violations: string[],
unverified: string[]
): void {
if (!minSalary) return;
const posted = payload.salary;
const top = posted ? (posted.max ?? posted.min) : null;
if (!posted || top === null) {
unverified.push("Unverified: salary not stated");
return;
}
if (posted.currency !== minSalary.currency || posted.period !== minSalary.period) {
unverified.push("Unverified: salary currency or period differs from your minimum");
return;
}
if (top < minSalary.amount) {
violations.push(`Minimum salary: ${minSalary.amount} ${minSalary.currency} per ${minSalary.period}`);
}
}
function checkSeniority(
payload: JobAnalysisPayload,
{ seniority }: Preferences,
violations: string[],
unverified: string[]
): void {
if (!seniority || (!seniority.min && !seniority.max)) return;
if (payload.seniority === "unspecified") {
unverified.push("Unverified: seniority not stated");
return;
}
const rank = PREFERENCE_SENIORITIES.indexOf(payload.seniority);
const below = seniority.min && rank < PREFERENCE_SENIORITIES.indexOf(seniority.min);
const above = seniority.max && rank > PREFERENCE_SENIORITIES.indexOf(seniority.max);
if (below || above) violations.push(`Seniority: ${seniorityRangeLabel(seniority)}`);
}
|