Skip to content

Two demo tests scan the shared tmpdir, so a concurrent worker turns them red #364

Description

@MongLong0214

Reproduced independently in two separate worktrees during a full-suite run, with different leftover directory names each time.

Measured

FAIL test/demo.test.ts > commitlore demo > temporary directory does not exist after successful completion
  expected [ 'commitlore-demo-WZjX8a' ] to deeply equal []

FAIL test/demo.test.ts > commitlore demo > temporary directory is gone after a simulated crash (safety property)

Both pass in isolation (7/7). Both fail under npx vitest run when another worker happens to hold a demo directory during the assertion window.

Cause

test/demo.test.ts:53-60 and :62-73 both read the process-wide tmpdir():

const leftover = readdirSync(tmpRoot).filter((d) => d.startsWith('commitlore-demo'));
expect(leftover).toEqual([]);

The first takes a before/after delta, which narrows the window but does not close it — a directory created by another worker after the before snapshot and still alive at the after snapshot counts as leftover. The second takes no delta at all and fails if any commitlore-demo* directory exists anywhere in the shared tmpdir, whoever made it.

Why it is worth fixing rather than tolerating

The property under test is real and worth keeping: runDemo must not leave its temp directory behind, including after a crash. The defect is that the test asserts it against a namespace it does not own. A test that goes red for a reason unrelated to the code under test is the most expensive kind of failure this repository can carry — it trains a reader to discount red, which is the one signal the commit gate depends on.

Shape of the fix

runDemo should create its directory under a root the test controls, and the test should assert emptiness of that root. Whether that means a tmpRoot option on runDemo or an env override is a design call — the current signature is runDemo({ cwd, crashTest }).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions