import { execSync } from 'node:child_process'; /** * Guard for tests that can't run in the `unit` target / on the minimal CI * runner — they shell out to external tools (ansible, wg, terraform, docker…) * or assert platform-specific behavior. Such tests are integration tests by * Rule 7.1 and must NOT gate the unit CI. * * Returns `true` (→ skip) when: * - CELILO_UNIT_ONLY=1 is set (the `unit` target forces them off), OR * - a required tool is absent on this host, OR * - we're on the wrong platform. * * Usage: describe.skipIf(skipIntegration({ tools: ['ansible'] }))(...) * test.skipIf(skipIntegration({ platform: 'darwin' }))(...) */ function hasTool(tool: string): boolean { try { execSync(`command -v ${tool}`, { stdio: 'ignore' }); return true; } catch { return false; } } export function skipIntegration( req: { tools?: string[]; platform?: NodeJS.Platform } = {}, ): boolean { if (process.env.CELILO_UNIT_ONLY === '1') return true; if (req.tools?.some((t) => !hasTool(t))) return true; if (req.platform && process.platform !== req.platform) return true; return false; } /** * Quarantine a test that FAILS ON THE CI RUNNER for a reason we have not yet * explained, while keeping it running for developers locally. * * This is the `cele2e-ci-unsafe` device (see `--ci-safe` in the cele2e runner) * applied to the integration suite, and it is deliberately uncomfortable to * use: the caller must pass the tracking issue, and the whole point is that the * skip is legible in the log rather than silent. * * Use this ONLY when the failure is not explained by a missing tool — reach for * `skipIntegration({ tools: [...] })` first, because "which tool" is a real * diagnosis and "quarantined" is an admission that we do not have one yet. * * The alternative is worse in both directions: leaving the test in makes a gate * permanently red, which trains everyone to ignore it — the same disease as a * gate that cannot fail. Deleting it loses the coverage and the evidence. * * Keyed on `GITHUB_ACTIONS`, which the Forgejo runner sets (it is what makes * `bun test` emit `::error` annotations there). * * Usage: test.skipIf(quarantinedInCi('celilo#713'))('...', ...) */ export function quarantinedInCi(_trackingIssue: string): boolean { return process.env.GITHUB_ACTIONS === 'true'; }