Each real file's project, fetched once and kept in a cache. Null when it cannot be had.
()
| 147 | |
| 148 | /** Each real file's project, fetched once and kept in a cache. Null when it cannot be had. */ |
| 149 | async function realFileProjects() { |
| 150 | const cache = process.env.CODEGRAPH_REGRESSION_CACHE ?? join(homedir(), '.cache', 'codegraph-regression'); |
| 151 | mkdirSync(cache, { recursive: true }); |
| 152 | const projects = []; |
| 153 | for (const real of REAL_FILES) { |
| 154 | const tarball = join(cache, `${real.sha1}.tgz`); |
| 155 | try { |
| 156 | if (!existsSync(tarball) || sha('sha1', readFileSync(tarball)) !== real.sha1) { |
| 157 | const response = await fetch(real.tarball); |
| 158 | if (!response.ok) throw new Error(`${real.tarball}: ${response.status}`); |
| 159 | const bytes = Buffer.from(await response.arrayBuffer()); |
| 160 | if (sha('sha1', bytes) !== real.sha1) throw new Error(`${real.tarball} is not the file this gate was written against`); |
| 161 | writeFileSync(tarball, bytes); |
| 162 | } |
| 163 | const unpacked = join(work, 'unpacked', real.sha1); |
| 164 | mkdirSync(unpacked, { recursive: true }); |
| 165 | if (run('tar', ['-xzf', tarball, '-C', unpacked, ...Object.keys(real.files)]).status !== 0) throw new Error(`could not unpack ${tarball}`); |
| 166 | const dir = join(work, real.project); |
| 167 | mkdirSync(dir, { recursive: true }); |
| 168 | for (const [path, sha256] of Object.entries(real.files)) { |
| 169 | const bytes = readFileSync(join(unpacked, path)); |
| 170 | if (sha('sha256', bytes) !== sha256) throw new Error(`${path} is not the file this gate was written against`); |
| 171 | writeFileSync(join(dir, path.split('/').pop()), bytes); |
| 172 | } |
| 173 | projects.push({ id: real.project, dir, real: true, noQuestions: true }); |
| 174 | } catch (error) { |
| 175 | projects.push({ id: real.project, missing: String(error?.message ?? error) }); |
| 176 | } |
| 177 | } |
| 178 | return projects; |
| 179 | } |
| 180 | |
| 181 | // --------------------------------------------------------------------------------------------- |
| 182 | // Graph and speed |