@@ -11,6 +11,7 @@ import {
1111 closeDefaultPortfolioQueueStore ,
1212} from "../../packages/loopover-miner/lib/portfolio-queue.js" ;
1313import { initRunStateStore , closeDefaultRunStateStore } from "../../packages/loopover-miner/lib/run-state.js" ;
14+ import { initPolicyVerdictCacheStore } from "../../packages/loopover-miner/lib/policy-verdict-cache.js" ;
1415import { initAttemptLog , closeDefaultAttemptLog } from "../../packages/loopover-miner/lib/attempt-log.js" ;
1516import {
1617 ATTEMPT_LOG_NOT_PURGEABLE_NOTE ,
@@ -76,7 +77,7 @@ describe("parsePurgeArgs (#5564)", () => {
7677} ) ;
7778
7879describe ( "runPurge --dry-run (#5564, #6599)" , ( ) => {
79- it ( "counts matching rows across the six real stores without writing anything, and reports attempt-log as not-purgeable" , async ( ) => {
80+ it ( "counts matching rows across the seven real stores without writing anything, and reports attempt-log as not-purgeable" , async ( ) => {
8081 const root = tempDir ( ) ;
8182 const claimDbPath = join ( root , "claim-ledger.sqlite3" ) ;
8283 const eventDbPath = join ( root , "event-ledger.sqlite3" ) ;
@@ -128,13 +129,20 @@ describe("runPurge --dry-run (#5564, #6599)", () => {
128129 runState . setRunState ( "acme/other" , "idle" ) ;
129130 runState . close ( ) ;
130131
132+ const policyVerdictDbPath = join ( root , "policy-verdict-cache.sqlite3" ) ;
133+ const policyVerdict = initPolicyVerdictCacheStore ( policyVerdictDbPath ) ;
134+ policyVerdict . put ( "acme/widgets" , "AI-USAGE.md" , '"v1"' , { allowed : true , matchedPhrase : null , source : "AI-USAGE.md" } ) ;
135+ policyVerdict . put ( "acme/other" , "AI-USAGE.md" , '"v1"' , { allowed : true , matchedPhrase : null , source : "AI-USAGE.md" } ) ;
136+ policyVerdict . close ( ) ;
137+
131138 const resolveDbPaths = {
132139 "claim-ledger" : ( ) => claimDbPath ,
133140 "event-ledger" : ( ) => eventDbPath ,
134141 "governor-ledger" : ( ) => governorDbPath ,
135142 "prediction-ledger" : ( ) => predictionDbPath ,
136143 "portfolio-queue" : ( ) => portfolioDbPath ,
137144 "run-state" : ( ) => runStateDbPath ,
145+ "policy-verdict-cache" : ( ) => policyVerdictDbPath ,
138146 "attempt-log" : ( ) => attemptLogDbPath ,
139147 } ;
140148
@@ -151,6 +159,7 @@ describe("runPurge --dry-run (#5564, #6599)", () => {
151159 { store : "prediction-ledger" , wouldPurge : 0 } ,
152160 { store : "portfolio-queue" , wouldPurge : 2 } ,
153161 { store : "run-state" , wouldPurge : 1 } ,
162+ { store : "policy-verdict-cache" , wouldPurge : 1 } ,
154163 ] ,
155164 attemptLogNote : ATTEMPT_LOG_NOT_PURGEABLE_NOTE ,
156165 attemptLogTotalRows : 0 ,
@@ -180,12 +189,13 @@ describe("runPurge --dry-run (#5564, #6599)", () => {
180189 "prediction-ledger" : ( ) => join ( root , "prediction-ledger.sqlite3" ) ,
181190 "portfolio-queue" : ( ) => join ( root , "portfolio-queue.sqlite3" ) ,
182191 "run-state" : ( ) => join ( root , "run-state.sqlite3" ) ,
192+ "policy-verdict-cache" : ( ) => join ( root , "policy-verdict-cache.sqlite3" ) ,
183193 "attempt-log" : ( ) => join ( root , "attempt-log.sqlite3" ) ,
184194 } ;
185195 const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => undefined ) ;
186196 expect ( runPurge ( [ "--repo" , "acme/widgets" , "--dry-run" , "--json" ] , { resolveDbPaths } ) ) . toBe ( 0 ) ;
187197 const result = JSON . parse ( String ( log . mock . calls [ 0 ] ?. [ 0 ] ) ) ;
188- expect ( result . stores ) . toHaveLength ( 6 ) ;
198+ expect ( result . stores ) . toHaveLength ( 7 ) ;
189199 expect ( result . stores . every ( ( entry : { wouldPurge : number } ) => entry . wouldPurge === 0 ) ) . toBe ( true ) ;
190200 expect ( result . attemptLogTotalRows ) . toBe ( 0 ) ;
191201 for ( const resolve of Object . values ( resolveDbPaths ) ) {
@@ -283,6 +293,7 @@ describe("runPurge --dry-run (#5564, #6599)", () => {
283293 LOOPOVER_MINER_PREDICTION_LEDGER_DB : process . env . LOOPOVER_MINER_PREDICTION_LEDGER_DB ,
284294 LOOPOVER_MINER_PORTFOLIO_QUEUE_DB : process . env . LOOPOVER_MINER_PORTFOLIO_QUEUE_DB ,
285295 LOOPOVER_MINER_RUN_STATE_DB : process . env . LOOPOVER_MINER_RUN_STATE_DB ,
296+ LOOPOVER_MINER_POLICY_VERDICT_CACHE_DB : process . env . LOOPOVER_MINER_POLICY_VERDICT_CACHE_DB ,
286297 LOOPOVER_MINER_ATTEMPT_LOG_DB : process . env . LOOPOVER_MINER_ATTEMPT_LOG_DB ,
287298 } ;
288299 process . env . LOOPOVER_MINER_CLAIM_LEDGER_DB = join ( root , "claim-ledger.sqlite3" ) ;
@@ -291,12 +302,13 @@ describe("runPurge --dry-run (#5564, #6599)", () => {
291302 process . env . LOOPOVER_MINER_PREDICTION_LEDGER_DB = join ( root , "prediction-ledger.sqlite3" ) ;
292303 process . env . LOOPOVER_MINER_PORTFOLIO_QUEUE_DB = join ( root , "portfolio-queue.sqlite3" ) ;
293304 process . env . LOOPOVER_MINER_RUN_STATE_DB = join ( root , "run-state.sqlite3" ) ;
305+ process . env . LOOPOVER_MINER_POLICY_VERDICT_CACHE_DB = join ( root , "policy-verdict-cache.sqlite3" ) ;
294306 process . env . LOOPOVER_MINER_ATTEMPT_LOG_DB = join ( root , "attempt-log.sqlite3" ) ;
295307 try {
296308 const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => undefined ) ;
297309 expect ( runPurge ( [ "--repo" , "acme/widgets" , "--dry-run" , "--json" ] ) ) . toBe ( 0 ) ;
298310 const result = JSON . parse ( String ( log . mock . calls [ 0 ] ?. [ 0 ] ) ) ;
299- expect ( result . stores ) . toHaveLength ( 6 ) ;
311+ expect ( result . stores ) . toHaveLength ( 7 ) ;
300312 expect ( result . stores . every ( ( entry : { wouldPurge : number } ) => entry . wouldPurge === 0 ) ) . toBe ( true ) ;
301313 // Nothing was created — dry run against nonexistent default-path stores makes zero writes.
302314 expect ( existsSync ( process . env . LOOPOVER_MINER_CLAIM_LEDGER_DB ) ) . toBe ( false ) ;
@@ -323,13 +335,15 @@ describe("runPurge (real, #5564, #6599)", () => {
323335 const prediction = fakeStore ( 3 ) ;
324336 const portfolio = fakeStore ( 4 ) ;
325337 const runState = fakeStore ( 1 ) ;
338+ const policyVerdict = fakeStore ( 1 ) ;
326339 const options = {
327340 openClaimLedger : ( ) => claim ,
328341 initEventLedger : ( ) => event ,
329342 initGovernorLedger : ( ) => governor ,
330343 initPredictionLedger : ( ) => prediction ,
331344 initPortfolioQueueStore : ( ) => portfolio ,
332345 initRunStateStore : ( ) => runState ,
346+ initPolicyVerdictCacheStore : ( ) => policyVerdict ,
333347 } ;
334348
335349 const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => undefined ) ;
@@ -338,14 +352,15 @@ describe("runPurge (real, #5564, #6599)", () => {
338352 expect ( summary ) . toMatchObject ( {
339353 outcome : "purged" ,
340354 repoFullName : "acme/widgets" ,
341- totalPurged : 11 ,
355+ totalPurged : 12 ,
342356 stores : [
343357 { store : "claim-ledger" , purged : 2 } ,
344358 { store : "event-ledger" , purged : 1 } ,
345359 { store : "governor-ledger" , purged : 0 } ,
346360 { store : "prediction-ledger" , purged : 3 } ,
347361 { store : "portfolio-queue" , purged : 4 } ,
348362 { store : "run-state" , purged : 1 } ,
363+ { store : "policy-verdict-cache" , purged : 1 } ,
349364 { store : "attempt-log" , purged : null , note : ATTEMPT_LOG_NOT_PURGEABLE_NOTE } ,
350365 ] ,
351366 } ) ;
@@ -361,7 +376,7 @@ describe("runPurge (real, #5564, #6599)", () => {
361376 log . mockClear ( ) ;
362377 expect ( runPurge ( [ "--repo" , "acme/widgets" ] , options as never ) ) . toBe ( 0 ) ;
363378 const text = String ( log . mock . calls [ 0 ] ?. [ 0 ] ) ;
364- expect ( text ) . toContain ( "Purged 11 row(s) for acme/widgets" ) ;
379+ expect ( text ) . toContain ( "Purged 12 row(s) for acme/widgets" ) ;
365380 expect ( text ) . toContain ( "claim-ledger=2" ) ;
366381 expect ( text ) . toContain ( "portfolio-queue=4" ) ;
367382 expect ( text ) . toContain ( "run-state=1" ) ;
0 commit comments