MCPcopy Create free account
hub / github.com/cli/cli / cleanupSandbox

Function cleanupSandbox

evals/src/core/sandbox.ts:88–118  ·  view source on GitHub ↗
(
  github: GitHub, journal: Journal, journalPath: string, beforeDelete?: () => Promise<void>,
)

Source from the content-addressed store, hash-verified

86 * resources while the repository still exists, so they can be matched to it.
87 */
88export async function cleanupSandbox(
89 github: GitHub, journal: Journal, journalPath: string, beforeDelete?: () => Promise<void>,
90): Promise<void> {
91 if (journal.cleaned) return;
92 if (!sandboxName.test(journal.repo)) throw new Error("Refusing cleanup of an invalid journal repository");
93 let repo: { id: number; private: boolean };
94 try {
95 repo = await github.api("GET", `/repos/${journal.repo}`);
96 } catch (error) {
97 if (!(error instanceof ApiError) || error.status !== 404) throw error;
98 if (!journal.deleting) throw new Error("Fixture repository is no longer accessible; cleanup cannot be confirmed");
99 journal.cleaned = true;
100 await save(journalPath, journal);
101 return;
102 }
103 if (!repo.private || (journal.id !== undefined && journal.id !== repo.id)) {
104 throw new Error("Refusing cleanup: repository identity or privacy changed");
105 }
106 await beforeDelete?.();
107 // Other resources are gone and the repository exists, so a later 404 means this deletion went through, even when
108 // its response was lost or the process stopped before recording it.
109 journal.deleting = true;
110 await save(journalPath, journal);
111 try {
112 await github.api("DELETE", `/repos/${journal.repo}`);
113 } catch (error) {
114 if (!(error instanceof ApiError) || error.status !== 404) throw error;
115 }
116 journal.cleaned = true;
117 await save(journalPath, journal);
118}
119
120/** Finds resource journals under a results root whose cleanup has not completed. */
121export async function unfinishedJournals(root: string): Promise<string[]> {

Callers 2

cleanupSuiteFunction · 0.85
cleanupFunction · 0.85

Calls 2

saveFunction · 0.85
apiMethod · 0.80

Tested by

no test coverage detected