Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions test/aspire-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { trace, metrics } from '@opentelemetry/api';
import { NodeSDK, resources, metrics as sdkMetrics } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
import { dockerSkipReason } from './helpers/skip-guards.js';

const { Resource } = resources;
const { PeriodicExportingMetricReader } = sdkMetrics;
Expand All @@ -23,20 +24,7 @@ const { PeriodicExportingMetricReader } = sdkMetrics;
// Skip guard — bail early if Docker is unavailable or tests disabled
// ============================================================================

function dockerAvailable(): boolean {
try {
execSync('docker --version', { stdio: 'ignore' });
return true;
} catch {
return false;
}
}

const SKIP_REASON = process.env['SKIP_DOCKER_TESTS'] === '1'
? 'SKIP_DOCKER_TESTS=1'
: !dockerAvailable()
? 'Docker not available'
: null;
const SKIP_REASON = dockerSkipReason();

const CONTAINER_NAME = 'squad-aspire-dashboard';
const DASHBOARD_URL = 'http://localhost:18888';
Expand Down
12 changes: 11 additions & 1 deletion test/cli/aspire.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import { describe, it, expect, vi, afterEach } from 'vitest';
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { join } from 'path';
import { dockerSkipReason } from '../helpers/skip-guards.js';

// ===========================================================================
// Skip guard — bail early if Docker is unavailable or tests disabled
// ===========================================================================

const SKIP_REASON = dockerSkipReason();

// ===========================================================================
// Docker availability helpers (mockable)
Expand Down Expand Up @@ -66,7 +73,10 @@ function buildAspireStopCommands(name = 'squad-aspire-dashboard'): string[][] {
// Docker availability
// ===========================================================================

describe('CLI: squad aspire — Docker availability', { timeout: 30_000 }, () => {
describe.skipIf(SKIP_REASON !== null)(
`CLI: squad aspire — Docker availability (${SKIP_REASON ?? 'enabled'})`,
{ timeout: 30_000 },
() => {
it('checkDockerAvailability returns version string when Docker is present', () => {
const result = checkDockerAvailability();
if (result === null) {
Expand Down
36 changes: 36 additions & 0 deletions test/helpers/skip-guards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Shared test helpers for skip guards and environment detection.
*
* Provides reusable functions for detecting Docker availability,
* shell module availability, and other environment conditions
* that determine whether certain test suites should run.
*/

Comment on lines +4 to +8
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File header comment says this helper provides detection for "shell module availability" and "other environment conditions", but the file currently only implements Docker helpers. Either implement the additional guards or trim the comment to match the actual exports to avoid misleading future contributors.

Suggested change
* Provides reusable functions for detecting Docker availability,
* shell module availability, and other environment conditions
* that determine whether certain test suites should run.
*/
* Provides reusable functions for detecting Docker availability
* and determining whether Docker-dependent test suites should run.
*/

Copilot uses AI. Check for mistakes.
import { execSync } from 'node:child_process';

/**
* Check if Docker is available on this machine.
* Returns true if `docker --version` succeeds within 5 seconds.
*/
export function isDockerAvailable(): boolean {
try {
execSync('docker --version', { stdio: 'ignore', timeout: 5000 });
return true;
} catch {
return false;
}
Comment on lines +11 to +21
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isDockerAvailable() uses docker --version, which only validates that the Docker CLI exists; it will still succeed when the Docker daemon/engine is stopped (the common failure case mentioned in #582). This means dockerSkipReason() may return null and Docker-dependent tests can still run and fail on docker pull/run/rm. Consider switching the probe to a daemon-requiring command (e.g., docker info or docker version that contacts the server) so the guard actually skips when Docker Desktop isn't running.

Copilot uses AI. Check for mistakes.
}

/**
* Determine skip reason for Docker-dependent tests.
* Returns null if tests should run, or a string reason to skip.
*/
export function dockerSkipReason(): string | null {
if (process.env['SKIP_DOCKER_TESTS'] === '1') {
return 'SKIP_DOCKER_TESTS=1';
}
if (!isDockerAvailable()) {
return 'Docker not available';
}
return null;
}
2 changes: 1 addition & 1 deletion test/template-sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('sync-templates.mjs script execution', () => {
const output = execSync('node scripts/sync-templates.mjs', {
cwd: ROOT,
encoding: 'utf-8',
timeout: 30_000,
timeout: 60_000,
});
expect(output).toContain('Synced');
});
Expand Down
Loading