Skip to content

Commit 97dbfad

Browse files
committed
Update property to use loadFailures and create persistence testfile
1 parent 10268f9 commit 97dbfad

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

persistence.tests.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
describe("failure persistence", () => {
2+
// TODO: Add tests for the failure persistence functionality.
3+
});

persistence.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
4750
export 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
*/
8284
const 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
*/
102105
export 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
};

property.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
isTraitReferenceFunction,
2020
getNonTestableTraitFunctions,
2121
} from "./traits";
22-
import { loadFailureStore, persistFailure } from "./persistence";
22+
import { loadFailures, persistFailure } from "./persistence";
2323
import { TestMode } from "./app";
2424
import { ImplementedTraitType } from "./traits.types";
2525
import { EnrichedContractInterfaceFunction } from "./shared.types";
@@ -237,7 +237,7 @@ export const checkProperties = async (
237237
`Loading ${targetContractName} contract regressions...\n`
238238
);
239239

240-
const { test: regressions } = await loadFailureStore(testContractId);
240+
const regressions = await loadFailures(testContractId, "test");
241241

242242
radio.emit(
243243
"logMessage",

0 commit comments

Comments
 (0)