Skip to content

fix: refactor graphwriter to separate dot rendering from file i/o - #444

Merged
cdsap merged 1 commit into
mainfrom
issue/443-hermes-refactor-graphwriter-to-separate-dot-a1
Sep 5, 2026
Merged

fix: refactor graphwriter to separate dot rendering from file i/o#444
cdsap merged 1 commit into
mainfrom
issue/443-hermes-refactor-graphwriter-to-separate-dot-a1

Conversation

@cdsap

@cdsap cdsap commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Summary

Problem

project-generator/src/main/kotlin/io/github/cdsap/projectgenerator/writer/GraphWriter.kt mixes pure dependency-graph → DOT string construction with filesystem side effects (File.createNewFile(), writeText, println). There is no unit test of the DOT content—only ProjectGeneratorTest asserts that graph.dot exists. Elsewhere the repo already separates content builders from writers (SettingsGradle.get(), AndroidToml.toml(), CLI GenerateVersionsYaml.render()).

Why this matters

Graph edge labels and include paths depend on NameMappings; regressions in DOT output are hard to catch without spinning up full project generation. Coupling rendering to disk also blocks testing naming/edge cases in isolation and blurs the writer adapter vs. domain presentation boundary.

Proposed change

Extract a pure render(nodes: List<ProjectGraph>): String (or equivalent) on GraphWriter that builds the digraph body; keep write() as a thin adapter that creates $path/graph.dot and writes that string. Add a focused unit test asserting edge lines for a small fixed graph (with controlled NameMappings like ProjectWriterTest already does). Do not change DOT format, file path, or call sites in ProjectGenerator.

Notes

Clean architecture: treat DOT serialization as a pure presentation of the ProjectGraph domain model; leave java.io.File in the infrastructure adapter. This is a single-boundary, incremental step—not a rewrite of the writer layer.

Fixes #443

Changes

  • project-generator/src/main/kotlin/io/github/cdsap/projectgenerator/writer/GraphWriter.kt
  • project-generator/src/test/kotlin/io/github/cdsap/projectgenerator/writer/GraphWriterTest.kt

Verification

  • ./gradlew :project-generator:unitTest
  • ./gradlew :cli:test
  • ./gradlew ktlintCheck

@cdsap
cdsap merged commit 9906e76 into main Sep 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor GraphWriter to separate DOT rendering from file I/O

1 participant