Skip to content

test: add test coverage for storage.ts (saveGraph / loadGraph) #2

@TechPMRyan

Description

@TechPMRyan

Summary

src/graph/storage.ts has zero test coverage. It contains two functions — saveGraph and loadGraph — that are part of the critical path between a completed scan and a usable graph. Neither is tested.

Additionally, loadGraph has a silent failure: it catches a JSON parse error and returns null with no log and no context. A missing file and a corrupted file are indistinguishable to the caller. That is a bug in the contract.

What needs to happen

  • Write a test file for storage.ts
  • Test loadGraph returns null on a missing file path
  • Test loadGraph returns null (or throws with context) on a corrupted JSON file — these two states should be distinguishable
  • Test saveGraph writes a file that loadGraph can read back correctly (round-trip test)
  • Test saveGraph behavior when the target path is not writable

Why this matters

The storage layer is the only persistence mechanism for scan output. Silent failures here mean a user runs a scan, gets no graph, and has no idea why. That is the worst possible failure mode for a tool whose core value is showing you a graph.

Acceptance criteria

  • loadGraph on a missing file: returns null, no error thrown
  • loadGraph on corrupted JSON: distinguishable from missing file (log or structured error)
  • Round-trip test: saveGraph then loadGraph returns the original graph
  • saveGraph error handling on unwritable path is explicit and surfaces to the caller

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions