@@ -11,6 +11,52 @@ import {
1111
1212import { getSocketFixBranchName } from './git.mts'
1313
14+ export type GhsaFixRecord = {
15+ branch : string
16+ fixedAt : string // ISO 8601
17+ ghsaId : string
18+ prNumber ?: number
19+ }
20+
21+ export type GhsaTracker = {
22+ fixed : GhsaFixRecord [ ]
23+ version : 1
24+ }
25+
26+ const TRACKER_FILE = '.socket/fixed-ghsas.json'
27+
28+ /**
29+ * Get all fixed GHSA records from the tracker.
30+ */
31+ export async function getFixedGhsas ( cwd : string ) : Promise < GhsaFixRecord [ ] > {
32+ try {
33+ const tracker = await loadGhsaTracker ( cwd )
34+ return tracker . fixed
35+ /* c8 ignore next 5 - loadGhsaTracker already returns a safe fallback on read failure */
36+ } catch ( e ) {
37+ debug ( 'ghsa-tracker: failed to get fixed GHSAs' )
38+ debugDir ( e )
39+ return [ ]
40+ }
41+ }
42+
43+ /**
44+ * Check if a GHSA has been fixed according to the tracker.
45+ */
46+ export async function isGhsaFixed (
47+ cwd : string ,
48+ ghsaId : string ,
49+ ) : Promise < boolean > {
50+ try {
51+ const tracker = await loadGhsaTracker ( cwd )
52+ return tracker . fixed . some ( r => r . ghsaId === ghsaId )
53+ } catch ( e ) {
54+ debug ( `ghsa-tracker: failed to check if ${ ghsaId } is fixed` )
55+ debugDir ( e )
56+ return false
57+ }
58+ }
59+
1460/**
1561 * Check if a process with the given PID is still running.
1662 */
@@ -28,20 +74,6 @@ export function isPidAlive(pid: number): boolean {
2874 }
2975}
3076
31- export type GhsaFixRecord = {
32- branch : string
33- fixedAt : string // ISO 8601
34- ghsaId : string
35- prNumber ?: number
36- }
37-
38- export type GhsaTracker = {
39- fixed : GhsaFixRecord [ ]
40- version : 1
41- }
42-
43- const TRACKER_FILE = '.socket/fixed-ghsas.json'
44-
4577/**
4678 * Load the GHSA tracker from the repository.
4779 * Creates a new tracker if the file doesn't exist.
@@ -58,23 +90,6 @@ export async function loadGhsaTracker(cwd: string): Promise<GhsaTracker> {
5890 }
5991}
6092
61- /**
62- * Save the GHSA tracker to the repository.
63- * Creates the .socket directory if it doesn't exist.
64- */
65- export async function saveGhsaTracker (
66- cwd : string ,
67- tracker : GhsaTracker ,
68- ) : Promise < void > {
69- const trackerPath = path . join ( cwd , TRACKER_FILE )
70-
71- // Ensure .socket directory exists.
72- await safeMkdir ( path . dirname ( trackerPath ) , { recursive : true } )
73-
74- await writeJson ( trackerPath , tracker , { spaces : 2 } )
75- debug ( `ghsa-tracker: saved ${ tracker . fixed . length } records to ${ trackerPath } ` )
76- }
77-
7893/**
7994 * Mark a GHSA as fixed in the tracker.
8095 * Removes any existing record for the same GHSA before adding the new one.
@@ -161,33 +176,18 @@ export async function markGhsaFixed(
161176}
162177
163178/**
164- * Check if a GHSA has been fixed according to the tracker.
179+ * Save the GHSA tracker to the repository.
180+ * Creates the .socket directory if it doesn't exist.
165181 */
166- export async function isGhsaFixed (
182+ export async function saveGhsaTracker (
167183 cwd : string ,
168- ghsaId : string ,
169- ) : Promise < boolean > {
170- try {
171- const tracker = await loadGhsaTracker ( cwd )
172- return tracker . fixed . some ( r => r . ghsaId === ghsaId )
173- } catch ( e ) {
174- debug ( `ghsa-tracker: failed to check if ${ ghsaId } is fixed` )
175- debugDir ( e )
176- return false
177- }
178- }
184+ tracker : GhsaTracker ,
185+ ) : Promise < void > {
186+ const trackerPath = path . join ( cwd , TRACKER_FILE )
179187
180- /**
181- * Get all fixed GHSA records from the tracker.
182- */
183- export async function getFixedGhsas ( cwd : string ) : Promise < GhsaFixRecord [ ] > {
184- try {
185- const tracker = await loadGhsaTracker ( cwd )
186- return tracker . fixed
187- /* c8 ignore next 5 - loadGhsaTracker already returns a safe fallback on read failure */
188- } catch ( e ) {
189- debug ( 'ghsa-tracker: failed to get fixed GHSAs' )
190- debugDir ( e )
191- return [ ]
192- }
188+ // Ensure .socket directory exists.
189+ await safeMkdir ( path . dirname ( trackerPath ) , { recursive : true } )
190+
191+ await writeJson ( trackerPath , tracker , { spaces : 2 } )
192+ debug ( `ghsa-tracker: saved ${ tracker . fixed . length } records to ${ trackerPath } ` )
193193}
0 commit comments