({
projectRoot,
probeId,
DatabaseClass = Database,
fsImpl = fs,
env = process.env
} = {})
| 150 | * @returns {Object} Structured probe result. |
| 151 | */ |
| 152 | export function runCodexSandboxProbe({ |
| 153 | projectRoot, |
| 154 | probeId, |
| 155 | DatabaseClass = Database, |
| 156 | fsImpl = fs, |
| 157 | env = process.env |
| 158 | } = {}) { |
| 159 | const paths = buildProbePaths({projectRoot, probeId, fsImpl}); |
| 160 | const dirExistedBefore = fsImpl.existsSync(paths.logicalDir); |
| 161 | const sandboxMode = detectSandboxMode(env); |
| 162 | |
| 163 | let db = null; |
| 164 | |
| 165 | try { |
| 166 | fsImpl.mkdirSync(paths.logicalDir, {recursive: true}); |
| 167 | db = new DatabaseClass(paths.probePath); |
| 168 | db.exec?.('CREATE TABLE IF NOT EXISTS codex_sandbox_probe (id INTEGER PRIMARY KEY);'); |
| 169 | db.close?.(); |
| 170 | db = null; |
| 171 | |
| 172 | const cleanup = cleanupProbeArtifacts({ |
| 173 | probePath : paths.probePath, |
| 174 | logicalDir : paths.logicalDir, |
| 175 | removeCreatedDir: !dirExistedBefore, |
| 176 | fsImpl |
| 177 | }); |
| 178 | |
| 179 | return {ok: true, paths, sandboxMode, cleanup}; |
| 180 | } catch (error) { |
| 181 | try { |
| 182 | db?.close?.(); |
| 183 | } catch {} |
| 184 | |
| 185 | const cleanup = cleanupProbeArtifacts({ |
| 186 | probePath : paths.probePath, |
| 187 | logicalDir : paths.logicalDir, |
| 188 | removeCreatedDir: !dirExistedBefore, |
| 189 | fsImpl |
| 190 | }); |
| 191 | |
| 192 | return { |
| 193 | ok: false, |
| 194 | paths, |
| 195 | sandboxMode, |
| 196 | cleanup, |
| 197 | error: { |
| 198 | code : error.code || error.name || 'UNKNOWN', |
| 199 | message: error.message || String(error) |
| 200 | } |
| 201 | }; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * @summary Format the probe result for operator-facing CLI output. |
no test coverage detected