oracle-gaps: expect in a file-level afterAll fails with "Digest already called"

Aberta Para iniciantes
#188 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
82/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
javascript, node.js
Domínio
testing, tooling

Direção de pesquisa

Leia packages/oracles/oracle-gaps/capture-setup.mjs: matcher (por volta das linhas 811-824) é chamado do wrapper Proxy.value do chai para cada asserção, e finishTest finaliza o digest e limpa inTest antes que um afterAll em nível de arquivo seja executado. Comece executando a reprodução standalone no issue (configuração do vitest com capture-setup.mjs como setupFiles mais um teste que faz asserções em afterAll) para ver Digest already called. Pronto significa que a repro e os cinco arquivos oracle listados passam sob o harness de captura, com uma decisão sobre se as asserções em nível de arquivo devem ser puladas ou sofrer hash.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Summary

oracle-gaps reports an oracle file as failing with no mutant active, with Digest already called, when the file has an expect(...) in a file-level afterAll that runs after its last test. All of the file's tests pass.

Reproduction

Standalone reproduction against main at 7b6bae1, verified with Node 24.8.0 and Vitest 5.1.0:

SHA=7b6bae1683a386b9d5e9349bdd77c8bb96b37377
mkdir oracle-gaps-188 && cd oracle-gaps-188
npm init -y
npm i -D --ignore-scripts [email protected]
for file in capture-setup paths; do
  curl -fsSLO "https://raw.githubusercontent.com/TanStack/oracles/$SHA/packages/oracles/oracle-gaps/$file.mjs"
done
cat > vitest.config.mjs <<'CONFIG'
import { defineConfig } from 'vitest/config'
export default defineConfig({ test: { setupFiles: ['./capture-setup.mjs'] } })
CONFIG
cat > repro.test.mjs <<'TEST'
import { afterAll, expect, it } from 'vitest'

it('passes', () => expect(1).toBe(1))
afterAll(() => expect(1).toBe(1))
TEST
echo '{"mutant":null,"select":null,"capture":"capture.jsonl"}' > state.json
ORACLE_GAPS_STATE=state.json npx vitest run

The one test passes, then the file fails:

Error: Digest already called
 ❯ Object.matcher capture-setup.mjs:822:14
    821|     } catch {
    822|       digest.update(`${name}(unrenderable)\n`)
 ❯ Proxy.value capture-setup.mjs:846:15

Adding if (!inTest) return at the top of matcher makes this reproduction pass.

The same failure in real oracle files: under the capture harness, virtual-row-fields-input-oracle had 4,908 tests pass and ordered-work-oracle.property had 690 tests pass. Each file then failed with this stack (line numbers are from e2af13a):

Error: Digest already called
 ❯ Object.matcher capture-setup.mjs:564:14
    563|     } catch {
    564|       digest.update(`${name}(unrenderable)\n`)
 ❯ Proxy.value capture-setup.mjs:588:15
 ❯ tests/query/virtual-row-fields-input-oracle.test.ts:143:7

Cause

In capture-setup.mjs:

  1. finishTest finalizes the test's hash with digest.digest('hex') and sets inTest = false.
  2. A new hash is only created in the next test's beforeEach.
  3. The chai wrapper calls hooks.matcher(name, this) for every assertion, including those in afterAll.
  4. matcher has no inTest guard, so it calls digest.update(rendered) on the finalized hash. That throws inside its try, and its catch calls digest.update(...) again, so the error escapes from the hook.

Instrumentation showed each test's finishTest ran exactly once, so this is not a double finish.

Impact

Vitest fails the file because of the afterAll error. oracle-gaps then treats that oracle file as failing with no mutant active, so every mutant it owns is blocked and the report is provisional.

Five oracle files in packages/db/tests/query/ of TanStack/db were blocked:

  • ordered-work-oracle.property.test.ts (afterAll assertion around line 5391)
  • virtual-row-fields-effect-oracle.test.ts
  • virtual-row-fields-input-oracle.test.ts (afterAll assertion around line 143)
  • virtual-row-fields-oracle.test.ts
  • virtual-row-fields-types-oracle.test.ts

Run directly with Vitest, those five files pass (7,711 tests).

Workaround

Verified in a private copy of the tool:

matcher(name, assertion) {
  // A file-level hook has no test row, and the last row closed its hash.
  if (!inTest) return
  try {

With it, all five files pass under the capture harness (7,711 tests). A complete gap report with this workaround was still running when this issue was filed, so its result is not confirmed.

Maintainers may want to adjust this: it deliberately leaves file-level assertions out of per-test hashes. The assertion itself still runs and can still fail the file.

Environment

  • TanStack/db at 725ba95c85372fd6d7e59a104e586cf23833e290
  • @tanstack/oracles from pkg.pr.new at e2af13a
  • Vitest 5.1.0
  • Node 24.8.0
  • The unguarded matcher is still present on main at 7b6bae1683a386b9d5e9349bdd77c8bb96b37377
Linguagem predominante
JavaScript
Estrelas
13
Forks
1
Merge médio
11h 8min
PRs com merge (30d)
67

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de TanStack/oracles

Todas as issues de TanStack/oracles

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.