(argv = process.argv.slice(2))
| 12 | |
| 13 | /** Housekeeping outside vally eval: retrying a trial's cleanup, and finding trials that need it. */ |
| 14 | export async function main(argv = process.argv.slice(2)): Promise<void> { |
| 15 | if (argv[0] === "--unfinished" && argv[1]) { |
| 16 | const journals = await unfinishedJournals(resolve(argv[1])); |
| 17 | if (!journals.length) return; |
| 18 | console.error(`${journals.length} trial(s) have unfinished cleanup. Leftover resources can count toward account ` |
| 19 | + "limits (event subscriptions do for 24 hours). If no other run is using them, clean up with:"); |
| 20 | for (const path of journals) console.error(` evals/cleanup ${path}`); |
| 21 | return; |
| 22 | } |
| 23 | if (argv.length !== 1 || argv[0]!.startsWith("-")) throw new Error(usage); |
| 24 | const token = process.env.GH_EVAL_TOKEN; |
| 25 | if (!token?.trim()) throw new Error("GH_EVAL_TOKEN must be the same user token the trial ran with"); |
| 26 | const path = await realpath(argv[0]!); |
| 27 | const request: typeof fetch = fetch; |
| 28 | const journal = await parseJournalFile(path); |
| 29 | const suite = Object.hasOwn(suites, journal.suite) ? suites[journal.suite] : undefined; |
| 30 | if (!suite) throw new Error(`The journal names an unknown suite: ${journal.suite}`); |
| 31 | await cleanupSuite(suite, journal, path, { token, fixtureToken: process.env.GH_EVAL_FIXTURE_TOKEN || token, request }); |
| 32 | console.log("Resource cleanup complete."); |
| 33 | } |
| 34 | |
| 35 | if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { |
| 36 | main().catch(error => { |
no test coverage detected