Skip to content

Fix quality gate silently passing when historyPath is set (fixes #895) - #924

Open
d-braun wants to merge 1 commit into
allure-framework:mainfrom
d-braun:fix/895-quality-gate-history-deadlock
Open

Fix quality gate silently passing when historyPath is set (fixes #895)#924
d-braun wants to merge 1 commit into
allure-framework:mainfrom
d-braun:fix/895-quality-gate-history-deadlock

Conversation

@d-braun

@d-braun d-braun commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Context

Fixes #895.

When historyPath is configured, allure quality-gate exits with code 0 and prints nothing, no matter how many rules the results violate. The only trace it leaves is an allure-report/ directory containing a single test-results.json and no quality-gate.json, exactly as reported in the issue. allure generate and allure run hit the same defect; there it goes mostly unnoticed because the report has already been written by the time the process stalls.

Root cause. AllureLocalHistory opens streams on a FileHandle with autoClose: false and then awaits FileHandle.close() in a finally block without ever destroying them. Such streams are never destroyed on their own, and the handle stays referenced until they emit "close" — so FileHandle.close() waits for a reference that is never released and never settles. As a consequence AllureReport.done() never returns, the event loop drains, and Node exits with code 0 before the quality gate is ever validated.

This is why the issue looks like the config file is ignored: the reporter's config sets historyPath, while the --max-failures run they compared against was made without --config and therefore without history. Rule parsing was never the problem.

Note that running the CLI through yarn allure … hides the defect — Yarn PnP preloads .pnp.cjs, which shifts the timing enough for close() to settle. Under plain node / npx, which is what users run, it deadlocks. Vitest masks it as well. The numbers below come from a clean npm i allure@3.16.0 with the built history.js swapped in and run under plain node:

Scenario Before After
quality-gate with historyPath exit 0, no output, no quality-gate.json exit 1, both rule violations reported
4 consecutive runs, also with historyLimit deadlock exit 1, history appended and trimmed
generate with historyPath exit 0, but done() never returned exit 0, history grows as expected

Changes.

  • packages/core/src/history.ts — destroy every stream opened on the history file handle before closing it, in the order the streams were opened: destroying a reader that shares its handle with a still open writer never completes, whereas destroying the writer closes the reader along with it. Closing the handle tolerates EBADF, because a destroyed stream may already have closed the descriptor depending on the runtime.
  • packages/cli/src/commands/qualityGate.ts — safety net: a quality gate must never pass silently. If the process is about to exit before the validation has finished, the command now reports it and exits with code 1 instead of leaving the caller with a successful exit code. Checked against the unfixed deadlock, it turns the silent exit 0 into a loud failure.

Tests.

  • packages/core/test/history.streams.test.ts (new) — asserts that every stream opened on the history file handle is closed, for the new-file, existing-file and read paths. All three fail without the fix.
  • packages/cli/test/commands/qualityGate.test.ts — two tests for the new safety net: it fires on an interrupted run and stays silent on a completed one.

yarn format:check, oxlint and the @allurereport/core (528) and allure (217) suites pass.

Checklist

@d-braun
d-braun force-pushed the fix/895-quality-gate-history-deadlock branch from 69929d8 to 688a816 Compare September 3, 2026 11:50
@d-braun
d-braun force-pushed the fix/895-quality-gate-history-deadlock branch from 688a816 to a372d01 Compare September 4, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allure Quality Gate doesn't work with the config file anymore

1 participant