fsm: generate and verify static address diagrams#1179
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the reliability and coverage of the project's state machine documentation. By enforcing deterministic sorting during diagram generation and adding a verification step to the CI pipeline, the changes ensure that documentation remains synchronized with the implementation. Furthermore, the scope of the generated diagrams has been expanded to include critical static address components, improving overall project transparency. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces automated checks and generation for FSM (Finite State Machine) Mermaid diagrams, including new diagrams for static address deposits and loop-ins. It refactors the state parser to sort transition keys deterministically and support the new FSM selectors. Feedback on the changes includes defining a reusable variable in the Makefile to avoid duplicating the list of FSM files, renaming a local variable in the state parser to prevent shadowing an imported package, and building the parser binary once in the generation script instead of executing go run multiple times to improve performance.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| fsm-check: fsm | ||
| @$(call print, "Verifying generated state machine docs") | ||
| if test -n "$$(git status --porcelain -- \ | ||
| fsm/example_fsm.md \ | ||
| instantout/fsm.md \ | ||
| instantout/reservation/fsm.md \ | ||
| staticaddr/deposit/fsm.md \ | ||
| staticaddr/loopin/fsm.md)"; then \ | ||
| echo "Generated FSM diagrams are not up-to-date!"; \ | ||
| git status --porcelain -- \ | ||
| fsm/example_fsm.md \ | ||
| instantout/fsm.md \ | ||
| instantout/reservation/fsm.md \ | ||
| staticaddr/deposit/fsm.md \ | ||
| staticaddr/loopin/fsm.md; \ | ||
| git diff -- \ | ||
| fsm/example_fsm.md \ | ||
| instantout/fsm.md \ | ||
| instantout/reservation/fsm.md \ | ||
| staticaddr/deposit/fsm.md \ | ||
| staticaddr/loopin/fsm.md; \ | ||
| exit 1; \ | ||
| fi |
There was a problem hiding this comment.
The list of FSM files is duplicated three times in the fsm-check target. Defining a variable FSM_FILES to hold this list improves maintainability and readability, making it easier to add or remove FSM files in the future.
FSM_FILES := \
fsm/example_fsm.md \
instantout/fsm.md \
instantout/reservation/fsm.md \
staticaddr/deposit/fsm.md \
staticaddr/loopin/fsm.md
fsm-check: fsm
@$(call print, "Verifying generated state machine docs")
if test -n "$$(git status --porcelain -- $(FSM_FILES))"; then \
echo "Generated FSM diagrams are not up-to-date!"; \
git status --porcelain -- $(FSM_FILES); \
git diff -- $(FSM_FILES); \
exit 1; \
fi
| case "instantout": | ||
| instantout := &instantout.FSM{} | ||
| err = writeMermaidFile(fp, instantout.GetV1ReservationStates()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return instantout.GetV1ReservationStates(), nil |
There was a problem hiding this comment.
The variable name instantout shadows the imported package name instantout. It is a best practice in Go to avoid shadowing package names to prevent confusion and potential compilation issues. Renaming it to instantOutFSM aligns with the naming pattern used for other FSM variables in this switch block.
| case "instantout": | |
| instantout := &instantout.FSM{} | |
| err = writeMermaidFile(fp, instantout.GetV1ReservationStates()) | |
| if err != nil { | |
| return err | |
| } | |
| return instantout.GetV1ReservationStates(), nil | |
| case "instantout": | |
| instantOutFSM := &instantout.FSM{} | |
| return instantOutFSM.GetV1ReservationStates(), nil |
| go run ./fsm/stateparser/stateparser.go --out ./fsm/example_fsm.md --fsm example | ||
| go run ./fsm/stateparser/stateparser.go --out ./reservation/reservation_fsm.md --fsm reservation | ||
| go run ./fsm/stateparser/stateparser.go --out ./instantout/fsm.md --fsm instantout No newline at end of file | ||
| go run ./fsm/stateparser/stateparser.go --out ./instantout/reservation/fsm.md --fsm reservation | ||
| go run ./fsm/stateparser/stateparser.go --out ./instantout/fsm.md --fsm instantout | ||
| go run ./fsm/stateparser/stateparser.go --out ./staticaddr/deposit/fsm.md --fsm staticaddr-deposit | ||
| go run ./fsm/stateparser/stateparser.go --out ./staticaddr/loopin/fsm.md --fsm staticaddr-loopin |
There was a problem hiding this comment.
Running go run multiple times compiles the stateparser tool repeatedly, which introduces unnecessary overhead and slows down the script execution. Building the binary once into a temporary directory and executing it multiple times is much more efficient.
| go run ./fsm/stateparser/stateparser.go --out ./fsm/example_fsm.md --fsm example | |
| go run ./fsm/stateparser/stateparser.go --out ./reservation/reservation_fsm.md --fsm reservation | |
| go run ./fsm/stateparser/stateparser.go --out ./instantout/fsm.md --fsm instantout | |
| \ No newline at end of file | |
| go run ./fsm/stateparser/stateparser.go --out ./instantout/reservation/fsm.md --fsm reservation | |
| go run ./fsm/stateparser/stateparser.go --out ./instantout/fsm.md --fsm instantout | |
| go run ./fsm/stateparser/stateparser.go --out ./staticaddr/deposit/fsm.md --fsm staticaddr-deposit | |
| go run ./fsm/stateparser/stateparser.go --out ./staticaddr/loopin/fsm.md --fsm staticaddr-loopin | |
| BIN_DIR=$(mktemp -d) | |
| trap 'rm -rf "$BIN_DIR"' EXIT | |
| go build -o "$BIN_DIR/stateparser" ./fsm/stateparser/stateparser.go | |
| "$BIN_DIR/stateparser" --out ./fsm/example_fsm.md --fsm example | |
| "$BIN_DIR/stateparser" --out ./instantout/reservation/fsm.md --fsm reservation | |
| "$BIN_DIR/stateparser" --out ./instantout/fsm.md --fsm instantout | |
| "$BIN_DIR/stateparser" --out ./staticaddr/deposit/fsm.md --fsm staticaddr-deposit | |
| "$BIN_DIR/stateparser" --out ./staticaddr/loopin/fsm.md --fsm staticaddr-loopin |
Summary
fsm.mdconsistentlymake fsm-checkand run it in CI to detect stale generated diagramsTest
make fsm-check