@@ -43,6 +43,9 @@ const DEFAULT_CONFIG: Required<PersistenceConfig> = {
4343/**
4444 * Gets the file path for a contract's failure store.
4545 * Uses contractId as filename (e.g., "ST1...ADDR.counter.json")
46+ * @param contractId The contract identifier being tested
47+ * @param baseDir The base directory for storing regression files
48+ * @returns The file path for the failure store
4649 */
4750export const getFailureFilePath = (
4851 contractId : string ,
@@ -53,8 +56,11 @@ export const getFailureFilePath = (
5356
5457/**
5558 * Loads the failure store for a contract, or creates an empty one.
59+ * @param contractId The contract identifier being tested
60+ * @param baseDir The base directory for storing regression files
61+ * @returns A promise that resolves when the failure store is loaded
5662 */
57- export const loadFailureStore = async (
63+ const loadFailureStore = async (
5864 contractId : string ,
5965 baseDir : string = DEFAULT_CONFIG . baseDir
6066) : Promise < FailureStore > => {
@@ -64,27 +70,23 @@ export const loadFailureStore = async (
6470 const content = await promises . readFile ( filePath , "utf-8" ) ;
6571 return JSON . parse ( content ) ;
6672 } catch ( error : any ) {
67- if ( error . code === "ENOENT" ) {
68- // File doesn't exist - return empty store.
69- return { invariant : [ ] , test : [ ] } ;
70- }
71- console . warn (
72- `Warning: Could not read ${ filePath } , starting fresh:` ,
73- error . message
74- ) ;
7573 return { invariant : [ ] , test : [ ] } ;
7674 }
7775} ;
7876
7977/**
8078 * Saves the failure store for a contract.
79+ * @param contractId The contract identifier being tested
80+ * @param baseDir The base directory for storing regression files
81+ * @param store The failure store to save
82+ * @returns A promise that resolves when the failure store is saved
8183 */
8284const saveFailureStore = async (
8385 contractId : string ,
8486 baseDir : string ,
8587 store : FailureStore
8688) : Promise < void > => {
87- // Ensure the base directory exists
89+ // Ensure the base directory exists.
8890 await promises . mkdir ( baseDir , { recursive : true } ) ;
8991
9092 const filePath = getFailureFilePath ( contractId , baseDir ) ;
@@ -98,6 +100,7 @@ const saveFailureStore = async (
98100 * @param type The type of test that failed
99101 * @param contractId The contract identifier being tested
100102 * @param config Optional configuration for persistence behavior
103+ * @returns A promise that resolves when the failure is persisted
101104 */
102105export const persistFailure = async (
103106 runDetails : RunDetails ,
@@ -141,7 +144,6 @@ export const persistFailure = async (
141144 await saveFailureStore ( contractId , baseDir , store ) ;
142145} ;
143146
144- // TODO: Useful for loading failures in the beginning of the test run.
145147/**
146148 * Loads persisted failures for a given contract and test type.
147149 *
@@ -150,14 +152,13 @@ export const persistFailure = async (
150152 * @param config Optional configuration
151153 * @returns Array of failure records, or empty array if none exist
152154 */
153- const loadFailures = async (
155+ export const loadFailures = async (
154156 contractId : string ,
155157 type : "invariant" | "test" ,
156158 config ?: PersistenceConfig
157159) : Promise < FailureRecord [ ] > => {
158160 const { baseDir } = { ...DEFAULT_CONFIG , ...config } ;
159161 const store = await loadFailureStore ( contractId , baseDir ) ;
160162
161- // O(1) lookup by type
162163 return store [ type ] ;
163164} ;
0 commit comments