Skip to content

fix: auto-detect test service for --exit-code-from#36

Draft
fey wants to merge 2 commits into
masterfrom
fix/exit-code-from-test-container
Draft

fix: auto-detect test service for --exit-code-from#36
fey wants to merge 2 commits into
masterfrom
fix/exit-code-from-test-container

Conversation

@fey

@fey fey commented May 22, 2026

Copy link
Copy Markdown
Collaborator

Проблема

Проекты с отдельным test-контейнером получали ложные FAILED в CI.

Сценарий: test завершается с кодом 0 (тесты прошли) → Docker Compose убивает app, caddy, db через SIGTERM → они возвращают ненулевой код → без --exit-code-from Compose сообщает об ошибке → CI падает.

Цепочки зависимостей в таких проектах: db → app → caddy → test.

Решение

Добавлена функция getTestService(), которая читает docker-compose.yml и возвращает имя сервиса для --exit-code-from:

  • есть сервис test'test'
  • нет → 'app' (текущее поведение для 66% проектов)
const getTestService = (projectSourcePath) => {
  const composePath = path.join(projectSourcePath, 'docker-compose.yml');
  const composeData = yaml.load(fs.readFileSync(composePath).toString());
  return composeData?.services?.test ? 'test' : 'app';
};

js-yaml уже был импортирован в src/index.js.

Контекст

Из 96 проектов Hexlet (ru/en/es):

  • 63 (66%) — один сервис app, тесты запускаются внутри него → --exit-code-from app
  • ~33 (34%) — отдельный сервис test--exit-code-from test

Миграция проектов не требуется — автодетект по имени сервиса покрывает оба паттерна.

Тесты

  • Все 13 существующих тестов проходят (make test)
  • Проверить на реальном проекте с test-контейнером (например, python_l4_task_manager_project)

fey and others added 2 commits May 22, 2026 22:13
…mpose

Projects with a separate `test` container (depends on running `app`) were
getting false CI failures: when `test` exited with code 0, Docker Compose
killed `app` via SIGTERM causing a non-zero exit without --exit-code-from.

Added getTestService() that reads docker-compose.yml and returns 'test' if
that service exists, otherwise falls back to 'app'. The detected service name
is passed to --exit-code-from so CI reliably reflects the test outcome.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant