Skip to content

Tests write a literal :memory: directory into the repo root #39

Description

@eldonm

:memory: is a SQLite sentinel. JsonDB has no such concept, so when it is handed that string as a db_path it does the only thing it can: creates a literal directory named :memory: and writes to it.

That directory lands in the repo root, untracked, and persists after the run:

:memory:/node/n.Root.root.json

Where

tests/api/decorators/test_deferred_registry.py builds its server config with:

database=DatabaseConfig(db_type="json", db_path=":memory:")

...at lines 119, 162, 177, 197, 212, 239, 272, 299.

Why it matters

Two separate problems:

  1. Test isolation. The suite writes into the working directory and leaves the artifact behind. Anyone running pytest locally accumulates a :memory: directory in their checkout, and git status grows a permanent untracked entry that is easy to git add -A by accident.
  2. The tests are not testing what they intend. They are asking for an ephemeral in-memory database and silently getting a persistent on-disk one. State survives within a run, and across runs, in a way the author plainly did not intend.

Repro

git status --short          # clean
pytest tests/api/decorators/test_deferred_registry.py -q
git status --short          # ?? :memory:/

Suggested fix

Use tmp_path for the json path, which is what the tests actually want:

database=DatabaseConfig(db_type="json", db_path=str(tmp_path / "jvdb"))

Worth considering separately: JsonDB could reject ":memory:" outright rather than creating a strangely-named directory. Silently interpreting a sentinel from another backend as a relative path is the part that made this invisible.

Found while running the full suite during #37 / #38.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions