TypeScript: a test that imports its module as '.' or '..' is linked, not copied, so its mutants are reported SURVIVED

Aperta Adatta ai principianti
#29 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, typescript
Ambito
testing-qa

Direzione di ricerca

Inizia in workers.py ed esamina il pattern dello specificatore di importazione e _candidates, che, secondo quanto indica l’issue, risolve già '.' e '..' in un file indice. Esegui la riproduzione Vitest fornita prima e dopo la modifica, quindi esegui la suite di test di mutator. Il lavoro è completato quando la riproduzione segnala il mutante come KILLED e la suite continua a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Thanks for mutator. It found real gaps in our TypeScript suite. While using it I hit one case where it reports mutants as surviving when the tests do kill them.

workers.py copies a module into the worker when it imports the mutated file through a relative path, so Node loads the mutant. The specifier pattern needs at least one character after the dot:

r"""(?:from|import|require)\s*\(?\s*['"](\.[^'"]+)['"]"""

So '.' and '..' (a directory's index) never match. A test that imports its module that way stays a symlink, Node resolves it to the project, and the test runs against the original file.

Repro (mutator a5a0cb8, macOS 27.0.1, Node 22.23.4, Vitest 3.2.4, no Vitest config)

src/calc/index.ts:

export function big(x: number): boolean {
  return x > 10;
}

src/calc/index.test.ts:

import { expect, it } from 'vitest';
import { big } from '.';

it('eleven is big', () => expect(big(11)).toBe(true));
it('ten is not big', () => expect(big(10)).toBe(false));
$ ./node_modules/.bin/vitest run
      Tests  2 passed (2)
$ mutator --no-coverage --test-command "./node_modules/.bin/vitest run" src/calc/index.ts
SURVIVED  src/calc/index.ts:2 > -> >=
big      calc.index       0         1          0      1   0.0%

Applying the same mutant by hand (x >= 10) gives 1 failed | 1 passed, so it should be KILLED.

Possible fix

Let the dot stand alone. _candidates already resolves . and .. to index.<ext>:

-    r"""(?:from|import|require)\s*\(?\s*['"](\.[^'"]+)['"]""",
+    r"""(?:from|import|require)\s*\(?\s*['"](\.[^'"]*)['"]""",

With that change the repro reports KILLED (100%), and mutator's own suite still passes (76 passed). In our project, one file went from 0 of 25 mutants killed to 19 of 25, and a hand-applied spot check agreed.

Related: #19 (same cause, reached through a linked directory or a path alias).

Lingua principale
Python
Stelle
112
Fork
53
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di unclebob/mutator

Tutte le issue di unclebob/mutator

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.