From e2fce29e0f91e9dc51c1212c50ab813593fdfd07 Mon Sep 17 00:00:00 2001 From: Arlo Kharod <42082766+firegiant9000@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:19:43 -0600 Subject: [PATCH 1/7] Show the duplicate and repost facts when making an application from a form --- core/src/form-application.test.ts | 43 +++++++++++++++++++++++++++++++ core/src/form-application.ts | 38 ++++++++++++++++++++++++--- shell/ui/Popup.tsx | 28 ++++++++++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/core/src/form-application.test.ts b/core/src/form-application.test.ts index 6704ecc..2d0df10 100644 --- a/core/src/form-application.test.ts +++ b/core/src/form-application.test.ts @@ -50,6 +50,49 @@ function stores(ops: WriteOp[], store: string): WriteOp[] { return ops.filter((o) => o.kind === 'put' && o.store === store); } +describe('newApplicationFromFormOps facts', () => { + const archivedJob: Job = { + id: 'oldjob', + source: 'paste', + title: 'Dev', + companyName: 'Acme', + canonicalUrl: 'https://jobs.lever.co/acme/1', + createdAt: '2025-12-01T00:00:00.000Z', + } as Job; + + it('reports a duplicate and a repost of an earlier job at the form key', () => { + const data: Snapshot = { + ...emptySnapshot(), + jobs: [archivedJob], + applications: [ + { + id: 'oldapp', + jobId: 'oldjob', + title: 'Dev', + createdAt: '2025-12-01T00:00:00.000Z', + } as Application, + ], + }; + const built = newApplicationFromFormOps( + data, + { source: 'paste', url: URL, title: 'Dev', companyName: 'Acme' }, + makeDeps(), + ); + expect(built.match).toBe('already_applied'); + expect(built.repost).toMatch(/^You saved this posting on /); + }); + + it('reports nothing for a new posting and never counts itself', () => { + const built = newApplicationFromFormOps( + emptySnapshot(), + { source: 'paste', url: URL, title: 'Dev', companyName: 'Acme' }, + makeDeps(), + ); + expect(built.match).toBeUndefined(); + expect(built.repost).toBeUndefined(); + }); +}); + describe('newApplicationFromFormOps', () => { it('makes one job and one linked interested application', () => { const { ops, applicationId, record } = newApplicationFromFormOps( diff --git a/core/src/form-application.ts b/core/src/form-application.ts index 28c8c74..f21f9fb 100644 --- a/core/src/form-application.ts +++ b/core/src/form-application.ts @@ -1,3 +1,10 @@ +import { toLocalDate } from './dates'; +import { + findApplicationMatch, + repostFact, + type ApplicationMatch, + type JobCandidate, +} from './duplicates'; import type { FillResult } from './fill/result'; import { fillRecordOps, type FillRecord } from './fill-records'; import { formUrlKey, linkFormOps } from './form-link'; @@ -48,7 +55,13 @@ export function newApplicationFromFormOps( input: JobInput, deps: Deps, held?: FillResult, -): { ops: WriteOp[]; applicationId: Id; record?: FillRecord } { +): { + ops: WriteOp[]; + applicationId: Id; + record?: FillRecord; + match?: ApplicationMatch['kind']; + repost?: string; +} { const saved = saveJobOps(input, deps); const jobPut = saved.ops[0]; if (jobPut?.kind !== 'put' || jobPut.store !== 'jobs') { @@ -68,7 +81,26 @@ export function newApplicationFromFormOps( const ops: WriteOp[] = [...created.ops]; ops.splice(companyIndex + 1, 0, jobOp); - if (held === undefined) return { ops, applicationId: created.applicationId }; + // Facts only inform, as in Save job: computed on the data before this write, + // for a candidate stored the way the job is (form key as its canonical URL). + const candidate: JobCandidate = {}; + if (job.canonicalUrl !== undefined) candidate.canonicalUrl = job.canonicalUrl; + if (job.companyName !== undefined) candidate.companyName = job.companyName; + if (job.title !== undefined) candidate.title = job.title; + const match = findApplicationMatch(data, candidate)?.kind; + const repost = repostFact( + data, + { ...candidate, excludeJobId: job.id }, + toLocalDate(new Date(deps.now())), + )?.text; + const facts = { + ...(match !== undefined ? { match } : {}), + ...(repost !== undefined ? { repost } : {}), + }; + + if (held === undefined) { + return { ops, applicationId: created.applicationId, ...facts }; + } const next: Snapshot = { ...data, @@ -88,5 +120,5 @@ export function newApplicationFromFormOps( } const record = fillRecordOps(next, held, created.applicationId, deps); ops.push(...record.ops); - return { ops, applicationId: created.applicationId, record }; + return { ops, applicationId: created.applicationId, record, ...facts }; } diff --git a/shell/ui/Popup.tsx b/shell/ui/Popup.tsx index c5f56d1..dbe9534 100644 --- a/shell/ui/Popup.tsx +++ b/shell/ui/Popup.tsx @@ -155,6 +155,10 @@ export function Popup(): VNode { const [recordNotice, setRecordNotice] = useState( undefined, ); + // Duplicate and repost facts for the application just made from this form. + const [newFacts, setNewFacts] = useState< + { match: Facts['match']; repost: string | undefined } | undefined + >(undefined); const linkingRef = useRef(false); const linkedIdRef = useRef(undefined); @@ -289,6 +293,8 @@ export function Popup(): VNode { id: Id; name: string; record?: FillRecord; + match?: Facts['match']; + repost?: string; }, ): Promise => { if (linkingRef.current) return Promise.resolve(false); @@ -300,6 +306,8 @@ export function Popup(): VNode { name: string; record?: FillRecord; held?: FillResult; + match?: Facts['match']; + repost?: string; } = { name: '' }; return app .apply((d) => { @@ -309,6 +317,8 @@ export function Popup(): VNode { got.id = built.id; got.name = built.name; got.record = built.record; + got.match = built.match; + got.repost = built.repost; if (built.record?.missing) throw new Error(MISSING); return built.ops; }) @@ -317,6 +327,11 @@ export function Popup(): VNode { linkingRef.current = false; setChosenId(got.id); setLinking(false); + setNewFacts( + got.match !== undefined || got.repost !== undefined + ? { match: got.match, repost: got.repost } + : undefined, + ); if (got.record !== undefined) { // Clear only the result this link recorded; a Fill that finished // during the write has replaced it and must survive. @@ -425,6 +440,8 @@ export function Popup(): VNode { id: built.applicationId, name: displayName(names.companyName, names.title), record: built.record, + match: built.match, + repost: built.repost, }; }); @@ -604,6 +621,17 @@ export function Popup(): VNode { recordLine={recordLine} /> ) : null} + {newFacts?.match === 'already_applied' ? ( + Already applied here. + ) : null} + {newFacts?.match === 'possible_match' ? ( + + Possible match: an application for the same company and title. + + ) : null} + {newFacts?.repost ? ( + {newFacts.repost} + ) : null} {fillStatus === 'ready' && linkedId !== undefined ? ( Date: Sat, 21 Nov 2026 17:20:20 -0600 Subject: [PATCH 2/7] Match a job saved from a form when saving it again from the apply page --- core/src/duplicates.test.ts | 33 +++++++++++++++++++++++++++++++++ core/src/duplicates.ts | 13 +++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/core/src/duplicates.test.ts b/core/src/duplicates.test.ts index 9850c5e..92ab8f3 100644 --- a/core/src/duplicates.test.ts +++ b/core/src/duplicates.test.ts @@ -206,6 +206,39 @@ describe('findApplicationMatch', () => { }); }); +describe('form apply-page addresses', () => { + const stored = 'https://jobs.lever.co/example/abc'; + const data = snap({ + jobs: [{ id: 'j1', createdAt: `2026-06-12${AT}`, canonicalUrl: stored }], + applications: [{ id: 'a1', createdAt: `2026-06-13${AT}`, jobId: 'j1' }], + }); + + it('findApplicationMatch matches the /apply address of a stored job', () => { + expect( + findApplicationMatch(data, { canonicalUrl: `${stored}/apply` }), + ).toEqual({ kind: 'already_applied', applicationId: 'a1' }); + expect( + findApplicationMatch(data, { + canonicalUrl: 'https://jobs.lever.co/example/other/apply', + }), + ).toBeUndefined(); + }); + + it('repostFact matches the /apply address of a stored job', () => { + expect( + repostFact(data, { canonicalUrl: `${stored}/apply` }, '2026-11-15') + ?.firstSavedOn, + ).toBe('2026-06-12'); + expect( + repostFact( + data, + { canonicalUrl: 'https://jobs.lever.co/example/other/apply' }, + '2026-11-15', + ), + ).toBeUndefined(); + }); +}); + describe('repostFact', () => { const job = (id: string, day: string, extra: Partial = {}): Job => ({ id, diff --git a/core/src/duplicates.ts b/core/src/duplicates.ts index 4259da0..735c4cf 100644 --- a/core/src/duplicates.ts +++ b/core/src/duplicates.ts @@ -1,5 +1,6 @@ import { normalizeName } from './application-ops'; import { isLocalDate, toLocalDate } from './dates'; +import { formUrlKey } from './form-link'; import type { Application, Id, Job, LocalDate, Snapshot } from './types'; import { canonicalizeUrl } from './url'; @@ -45,6 +46,14 @@ function safeCanonical(url: string): string | undefined { } } +// Equal, or both the same posting once a form's apply segment is dropped. +function urlsMatch(have: string | undefined, want: string): boolean { + if (have === undefined) return false; + if (have === want) return true; + const key = formUrlKey(want); + return key !== undefined && key === formUrlKey(have); +} + function applicationCanonicalUrl( app: Application, jobsById: Map, @@ -110,7 +119,7 @@ export function findApplicationMatch( const appTitle = nameKey(app.title); if ( wantUrl !== undefined && - url === wantUrl && + urlsMatch(url, wantUrl) && !contradicts(wantCompany, company, wantTitle, appTitle) ) { if ( @@ -169,7 +178,7 @@ export function repostFact( const jobTitle = nameKey(job.title); const sameUrl = wantUrl !== undefined && - str(job.canonicalUrl) === wantUrl && + urlsMatch(str(job.canonicalUrl), wantUrl) && !contradicts(wantCompany, jobCompany, wantTitle, jobTitle); const sameName = wantCompany !== undefined && From ce9957bbbf88c251b21d8d8a1ec68a090b1527fc Mon Sep 17 00:00:00 2001 From: Arlo Kharod <42082766+firegiant9000@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:20:57 -0600 Subject: [PATCH 3/7] Keep a fill result the popup still offers to record --- shell/ui/Popup.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/shell/ui/Popup.tsx b/shell/ui/Popup.tsx index dbe9534..6626fb7 100644 --- a/shell/ui/Popup.tsx +++ b/shell/ui/Popup.tsx @@ -160,6 +160,7 @@ export function Popup(): VNode { { match: Facts['match']; repost: string | undefined } | undefined >(undefined); const linkingRef = useRef(false); + const keepHeldRef = useRef(false); const linkedIdRef = useRef(undefined); useEffect(() => { @@ -169,11 +170,15 @@ export function Popup(): VNode { // A match linked the form without the owner's click: drop the stale held // fill rather than let a later Choose… record it. The owner's own link // path records and clears held itself, and is excluded while in flight. + // Exception: onFilled holds a result on two recoverable paths (application + // gone, write rejected) where the popup still offers to record it; those + // keep it until the owner's next link (runLink resets this). useEffect(() => { if ( linkedIdRef.current !== undefined && heldRef.current !== undefined && - !linkingRef.current + !linkingRef.current && + !keepHeldRef.current ) { heldRef.current = undefined; setHeld(undefined); @@ -299,6 +304,7 @@ export function Popup(): VNode { ): Promise => { if (linkingRef.current) return Promise.resolve(false); linkingRef.current = true; + keepHeldRef.current = false; setLinking(true); setLinkError(undefined); const got: { @@ -327,6 +333,7 @@ export function Popup(): VNode { linkingRef.current = false; setChosenId(got.id); setLinking(false); + setRecordNotice(undefined); setNewFacts( got.match !== undefined || got.repost !== undefined ? { match: got.match, repost: got.repost } @@ -338,7 +345,6 @@ export function Popup(): VNode { if (got.held !== undefined && heldRef.current === got.held) { setHeld(undefined); } - setRecordNotice(undefined); setRecordLine( got.record.recorded > 0 ? { @@ -398,12 +404,14 @@ export function Popup(): VNode { const record = got.record; if (record === undefined) return; if (record.missing) { + keepHeldRef.current = true; heldRef.current = result; setHeld(result); setChosenId(undefined); setRecordNotice(MISSING); return; } + keepHeldRef.current = false; setHeld(undefined); if (record.recorded > 0) { setRecordLine({ @@ -413,7 +421,12 @@ export function Popup(): VNode { }); } }, - (err: unknown) => setLinkError(messageOf(err)), + (err: unknown) => { + keepHeldRef.current = true; + heldRef.current = result; + setHeld(result); + setLinkError(messageOf(err)); + }, ); }; const linkNew = (names: { From a5336e9081c3e56da3de2fa9c00eeeda3a45135c Mon Sep 17 00:00:00 2001 From: Arlo Kharod <42082766+firegiant9000@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:21:00 -0600 Subject: [PATCH 4/7] Ignore overlong form URLs --- core/src/form-link.test.ts | 9 +++++++++ core/src/form-link.ts | 3 +++ 2 files changed, 12 insertions(+) diff --git a/core/src/form-link.test.ts b/core/src/form-link.test.ts index 6b2875b..80c5b64 100644 --- a/core/src/form-link.test.ts +++ b/core/src/form-link.test.ts @@ -26,6 +26,15 @@ function app(id: string, day: string, extra: object = {}): Application { const KEY = 'https://example.com/jobs/1'; describe('formUrlKey', () => { + it('ignores an address longer than the capture cap', () => { + const long = `https://example.com/${'a'.repeat(8_001 - 20)}`; + expect(long).toHaveLength(8_001); + expect(formUrlKey(long)).toBeUndefined(); + expect(formUrlKey('https://example.com/jobs/1')).toBe( + 'https://example.com/jobs/1', + ); + }); + it('strips the Lever apply segment', () => { expect(formUrlKey('https://jobs.lever.co/acme/123/apply')).toBe( formUrlKey('https://jobs.lever.co/acme/123'), diff --git a/core/src/form-link.ts b/core/src/form-link.ts index bdc0310..7e46f34 100644 --- a/core/src/form-link.ts +++ b/core/src/form-link.ts @@ -11,6 +11,8 @@ interface UrlLike { declare const URL: { new (url: string, base?: string): UrlLike }; export const MAX_FORM_URLS = 20; +// Matches the capture URL cap (shell/capture MAX_CAPTURE_URL); core cannot import it. +export const MAX_FORM_URL = 8_000; // Hosts whose application form lives one path segment below the posting. const TRAILING_SEGMENTS: Readonly> = { @@ -24,6 +26,7 @@ export function formUrlKey( url: string, relCanonical?: string, ): string | undefined { + if (url.length > MAX_FORM_URL) return undefined; try { const parsed = new URL(url.trim()); if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') { From b2fac8dc35ee4459622f3cffc0b8d10e1fed8455 Mon Sep 17 00:00:00 2001 From: Arlo Kharod <42082766+firegiant9000@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:22:46 -0600 Subject: [PATCH 5/7] Drop unneeded casts in the form application tests --- core/src/form-application.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/form-application.test.ts b/core/src/form-application.test.ts index 2d0df10..62f58e7 100644 --- a/core/src/form-application.test.ts +++ b/core/src/form-application.test.ts @@ -58,7 +58,7 @@ describe('newApplicationFromFormOps facts', () => { companyName: 'Acme', canonicalUrl: 'https://jobs.lever.co/acme/1', createdAt: '2025-12-01T00:00:00.000Z', - } as Job; + }; it('reports a duplicate and a repost of an earlier job at the form key', () => { const data: Snapshot = { @@ -70,7 +70,7 @@ describe('newApplicationFromFormOps facts', () => { jobId: 'oldjob', title: 'Dev', createdAt: '2025-12-01T00:00:00.000Z', - } as Application, + }, ], }; const built = newApplicationFromFormOps( From a00d039ef93dc10231b159e6954eb763328e4acc Mon Sep 17 00:00:00 2001 From: Arlo Kharod <42082766+firegiant9000@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:24:51 -0600 Subject: [PATCH 6/7] Keep a held fill result when the owner's link fails --- shell/ui/Popup.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shell/ui/Popup.tsx b/shell/ui/Popup.tsx index 6626fb7..9cdbfea 100644 --- a/shell/ui/Popup.tsx +++ b/shell/ui/Popup.tsx @@ -304,7 +304,6 @@ export function Popup(): VNode { ): Promise => { if (linkingRef.current) return Promise.resolve(false); linkingRef.current = true; - keepHeldRef.current = false; setLinking(true); setLinkError(undefined); const got: { @@ -331,6 +330,9 @@ export function Popup(): VNode { .then( () => { linkingRef.current = false; + // Only a successful owner link ends the keep; a failed one leaves + // the held result offered for a retry. + keepHeldRef.current = false; setChosenId(got.id); setLinking(false); setRecordNotice(undefined); @@ -388,6 +390,7 @@ export function Popup(): VNode { // Read when the fill completes, not at the click (FillSection is fixed). const id = linkedIdRef.current; if (id === undefined) { + keepHeldRef.current = false; setHeld(result); return; } From b6262e62591046f427a830aaa6f2000079133efd Mon Sep 17 00:00:00 2001 From: Arlo Kharod <42082766+firegiant9000@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:24:53 -0600 Subject: [PATCH 7/7] Test the Ashby application page match --- core/src/duplicates.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/src/duplicates.test.ts b/core/src/duplicates.test.ts index 92ab8f3..848e7f9 100644 --- a/core/src/duplicates.test.ts +++ b/core/src/duplicates.test.ts @@ -224,6 +224,29 @@ describe('form apply-page addresses', () => { ).toBeUndefined(); }); + it('matches the Ashby /application address of a stored job', () => { + const ashby = 'https://jobs.ashbyhq.com/example/abc'; + const ashbyData = snap({ + jobs: [{ id: 'j2', createdAt: `2026-06-12${AT}`, canonicalUrl: ashby }], + applications: [{ id: 'a2', createdAt: `2026-06-13${AT}`, jobId: 'j2' }], + }); + expect( + findApplicationMatch(ashbyData, { canonicalUrl: `${ashby}/application` }), + ).toEqual({ kind: 'already_applied', applicationId: 'a2' }); + expect( + repostFact( + ashbyData, + { canonicalUrl: `${ashby}/application` }, + '2026-11-15', + )?.firstSavedOn, + ).toBe('2026-06-12'); + expect( + findApplicationMatch(ashbyData, { + canonicalUrl: 'https://jobs.ashbyhq.com/example/zzz/application', + }), + ).toBeUndefined(); + }); + it('repostFact matches the /apply address of a stored job', () => { expect( repostFact(data, { canonicalUrl: `${stored}/apply` }, '2026-11-15')