@@ -8,6 +8,8 @@ import { beforeEach, describe, expect, it } from "vitest";
88import { globalServiceRegistry } from "workglow" ;
99import { resetDependencyInjectionsForTesting } from "../../config/TestingDI" ;
1010import { setupAllDatabases } from "../../config/setupAllDatabases" ;
11+ import { S1_CLASSIFICATION_REPOSITORY_TOKEN } from "../../storage/classification/S1ClassificationSchema" ;
12+ import { FILING_REPOSITORY_TOKEN } from "../../storage/filing/FilingSchema" ;
1113import {
1214 SPAC_CANDIDATE_REPOSITORY_TOKEN ,
1315 type SpacCandidate ,
@@ -72,6 +74,42 @@ function minimalSpac(cik: number): Spac {
7274 } ;
7375}
7476
77+ async function putClassification ( args : {
78+ readonly cik : number ;
79+ readonly accession_number : string ;
80+ readonly filing_date : string ;
81+ readonly is_spac : boolean ;
82+ readonly created_at ?: string ;
83+ } ) : Promise < void > {
84+ await globalServiceRegistry . get ( FILING_REPOSITORY_TOKEN ) . put ( {
85+ cik : args . cik ,
86+ accession_number : args . accession_number ,
87+ filing_date : args . filing_date ,
88+ report_date : null ,
89+ acceptance_date : `${ args . filing_date } T12:00:00.000Z` ,
90+ form : "S-1" ,
91+ file_number : null ,
92+ film_number : null ,
93+ primary_doc : "doc.htm" ,
94+ primary_doc_description : null ,
95+ size : null ,
96+ is_xbrl : null ,
97+ is_inline_xbrl : null ,
98+ items : null ,
99+ act : null ,
100+ } ) ;
101+ await globalServiceRegistry . get ( S1_CLASSIFICATION_REPOSITORY_TOKEN ) . put ( {
102+ extractor_id : "S-1" ,
103+ accession_number : args . accession_number ,
104+ cik : args . cik ,
105+ sic : args . is_spac ? 6770 : 6141 ,
106+ sic_description : null ,
107+ is_spac : args . is_spac ,
108+ classifier_source : "sgml-header" ,
109+ created_at : args . created_at ?? "2026-08-17T00:00:00.000Z" ,
110+ } ) ;
111+ }
112+
75113function candidateRow ( cik : number , confidence : SpacCandidate [ "confidence" ] ) : SpacCandidate {
76114 return {
77115 cik,
@@ -132,6 +170,74 @@ describe("listSpacProcessCiks", () => {
132170 await expect ( listKnownSpacCiks ( ) ) . resolves . toEqual ( [ 1 ] ) ;
133171 await expect ( listSpacProcessCiks ( ) ) . resolves . toEqual ( [ 1 , 2 ] ) ;
134172 } ) ;
173+
174+ it ( "drops a medium candidate whose latest registration classified is_spac=false" , async ( ) => {
175+ const candidateRepo = globalServiceRegistry . get ( SPAC_CANDIDATE_REPOSITORY_TOKEN ) ;
176+ await candidateRepo . put ( candidateRow ( 7974 , "medium" ) ) ;
177+ await putClassification ( {
178+ cik : 7974 ,
179+ accession_number : "0000950134-96-000313" ,
180+ filing_date : "1996-02-09" ,
181+ is_spac : false ,
182+ } ) ;
183+
184+ await expect ( listSpacProcessCiks ( ) ) . resolves . toEqual ( [ ] ) ;
185+ } ) ;
186+
187+ it ( "keeps a known SPAC whose later operating registration classified is_spac=false" , async ( ) => {
188+ const spacRepo = globalServiceRegistry . get ( SPAC_REPOSITORY_TOKEN ) ;
189+ const candidateRepo = globalServiceRegistry . get ( SPAC_CANDIDATE_REPOSITORY_TOKEN ) ;
190+ await spacRepo . put ( minimalSpac ( 1848507 ) ) ;
191+ await candidateRepo . put ( candidateRow ( 1848507 , "medium" ) ) ;
192+ await putClassification ( {
193+ cik : 1848507 ,
194+ accession_number : "0001848507-26-000001" ,
195+ filing_date : "2026-01-15" ,
196+ is_spac : false ,
197+ } ) ;
198+
199+ await expect ( listSpacProcessCiks ( ) ) . resolves . toEqual ( [ 1848507 ] ) ;
200+ } ) ;
201+
202+ it ( "keeps a candidate when a later registration classified is_spac=true" , async ( ) => {
203+ const candidateRepo = globalServiceRegistry . get ( SPAC_CANDIDATE_REPOSITORY_TOKEN ) ;
204+ await candidateRepo . put ( candidateRow ( 9001 , "medium" ) ) ;
205+ await putClassification ( {
206+ cik : 9001 ,
207+ accession_number : "0000000000-21-000001" ,
208+ filing_date : "2021-01-01" ,
209+ is_spac : false ,
210+ } ) ;
211+ await putClassification ( {
212+ cik : 9001 ,
213+ accession_number : "0000000000-21-000002" ,
214+ filing_date : "2021-06-01" ,
215+ is_spac : true ,
216+ } ) ;
217+
218+ await expect ( listSpacProcessCiks ( ) ) . resolves . toEqual ( [ 9001 ] ) ;
219+ } ) ;
220+
221+ it ( "uses the later filing date, not process order, as latest" , async ( ) => {
222+ const candidateRepo = globalServiceRegistry . get ( SPAC_CANDIDATE_REPOSITORY_TOKEN ) ;
223+ await candidateRepo . put ( candidateRow ( 9002 , "high" ) ) ;
224+ await putClassification ( {
225+ cik : 9002 ,
226+ accession_number : "0000000000-21-000010" ,
227+ filing_date : "2021-01-01" ,
228+ is_spac : true ,
229+ created_at : "2026-08-20T00:00:00.000Z" ,
230+ } ) ;
231+ await putClassification ( {
232+ cik : 9002 ,
233+ accession_number : "0000000000-21-000011" ,
234+ filing_date : "2021-06-01" ,
235+ is_spac : false ,
236+ created_at : "2026-08-01T00:00:00.000Z" ,
237+ } ) ;
238+
239+ await expect ( listSpacProcessCiks ( ) ) . resolves . toEqual ( [ ] ) ;
240+ } ) ;
135241} ) ;
136242
137243async function recordRun ( args : {
0 commit comments