Skip to content

Add tests for DuckDB query stack and kg query-organism CLI #543

@turbomam

Description

@turbomam

Context

Surfaced in Copilot's 2026-04-16 review of #531.

PR #531 added a new kg query-organism CLI subcommand and a kg_microbe/query_utils/ module (DuckDB loader, organism queries). None of the new functionality has automated tests. This is a gap that (a) lets correctness bugs sneak in unnoticed — see the predicate/relation inconsistency and CRLF bug filed alongside this issue — and (b) makes later refactors risky.

Suggested minimum coverage

  1. Name resolution (find_organism_by_name):

    • 0 matches → documented behavior (raise or return a sentinel)
    • 1 match → returns the row
    • many matches → documented behavior (raise with candidate list, or return selected + alternatives — see the contract-mismatch issue)
  2. Media preference retrieval (get_media_preferences): confirm the chosen predicate/relation encoding actually returns rows on the expected fixtures. Ideally blocked on resolving the predicate/relation inconsistency issue first so the test isn't written against the wrong schema.

  3. Media composition retrieval (get_media_composition): assert correct rows for a list of medium IDs; use this as the test that pins the parameterized-query fix.

  4. DuckDB loader (duckdb_loader.py): round-trip a small CRLF TSV fixture and assert no trailing \r in the last column (pins the CRLF fix).

  5. CLI smoke test: invoke kg query-organism on a tiny fixture and assert the exit code + key output lines.

Use a small in-memory DuckDB database or a tiny on-disk fixture so tests are hermetic and fast.

Files involved

  • kg_microbe/query_utils/ (new module)
  • kg_microbe/run.py (query-organism CLI entry)
  • tests/ (new test files)

References

  • PR #531
  • Copilot review at commit 1de973d, 2026-04-16T23:15Z

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions