feat: Implement dynamic FSM transition resolution from callback response#179
Conversation
Summary of ChangesHello @mushrafmim, 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 refactors the Finite State Machine (FSM) transition logic to be dynamically configurable rather than hardcoded. It introduces a new Highlights
Changelog
Activity
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 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 counter productive. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully implements dynamic FSM transition resolution from callback responses, replacing hardcoded logic with a configurable TransitionConfig. This is a significant improvement for flexibility and maintainability, especially for the Phytosanitary Certificate workflow node. The new TransitionConfig and its comprehensive unit tests demonstrate a robust solution. The removal of hardcoded validation in the OGA handler also aligns well with the new dynamic approach. While there are a couple of minor areas related to hardcoded strings, these have been identified as deferrable refactoring tasks, with a recommendation to create tracking issues for future resolution.
b6ad482 to
70027f0
Compare
e6fdad7 to
48dee6b
Compare
6a29f99 to
dd850cb
Compare
23a8162 to
eae0851
Compare
sthanikan2000
left a comment
There was a problem hiding this comment.
Need to do a rebase to the main branch after merging the #183
Because there are some bugs in the unit tests of workflow manager which is fixed in that PR, and will remove the CI failure
eae0851 to
5719830
Compare
5719830 to
86a5f57
Compare
Summary
Replaces the hardcoded
decision == "APPROVED"check in the OGA callback flow with a configurableTransitionConfigthat maps arbitrary response field values to FSM actions. This removes the TODO workarounds in both the backend plugin and the OGA handler, and wires the Phytosanitary Certificate workflow node to use the new config.Type of Change
Changes Made
backend/internal/task/plugin/transition.go— NewTransitionConfigstruct with aResolve(data)method. Reads a dot-path field from the callback response, looks it up in a string→action mapping, and falls back to an optionalDefaultaction.backend/internal/task/plugin/simple_form.go—CallbackConfiggains aTransition *TransitionConfigfield.resolveActionnow delegates toTransitionConfig.Resolvewhen present, keeping the legacy hardcoded path as a fallback for unconfigured nodes.backend/internal/task/plugin/transition_test.go— 11 table-driven unit tests covering: happy-path mapping, multi-entry mapping, missing field with/without default, unmapped value with/without default, non-string field values, dot-path nested fields, and empty data.backend/internal/database/migrations/010_add_conditional_state_identification.sql— Updates the Phytosanitary Certificate workflow node config to use the newcallback.transitionblock: mapsAPPROVEDandMANUAL_REVIEW→OGA_VERIFICATION_APPROVED, withOGA_VERIFICATION_REJECTEDas the default.oga/internal/handler.go— Removes the hardcodeddecisionfield validation fromHandleReviewApplication. Validation is now the responsibility of the backend FSM viaTransitionConfig, so the OGA handler simply forwards the raw body.Testing
OGA App Setup
The OGA app must have a form definition file present for the Phytosanitary Certificate review flow to work.
Place a file at the following path inside the OGA service:
Content of the file:
{ "schema": { "type": "object", "required": [ "decision", "phytosanitaryClearance" ], "properties": { "decision": { "type": "string", "title": "Decision", "oneOf": [ { "const": "APPROVED", "title": "Approved" }, { "const": "MANUAL_REVIEW", "title": "Manual Inspection Required" }, { "const": "REJECTED", "title": "Rejected" } ] }, "phytosanitaryClearance": { "type": "string", "title": "Phytosanitary Clearance Status", "oneOf": [ { "const": "CLEARED", "title": "Cleared for Export" }, { "const": "CONDITIONAL", "title": "Cleared with Conditions" }, { "const": "REJECTED", "title": "Rejected - Non Compliance" } ] }, "inspectionReference": { "type": "string", "title": "Inspection / Certificate Reference No" }, "remarks": { "type": "string", "title": "NPQS Remarks" } } }, "uiSchema": { "type": "VerticalLayout", "elements": [ { "type": "Control", "scope": "#/properties/decision" }, { "type": "Control", "scope": "#/properties/phytosanitaryClearance" }, { "type": "Control", "scope": "#/properties/inspectionReference" }, { "type": "Control", "scope": "#/properties/remarks", "options": { "multi": true } } ] } }This file provides the review form rendered by the OGA app when processing a phytosanitary certificate verification request. Without it, the OGA handler will not be able to serve the form for review.
Checklist
Related Issues
Closes #178
Additional Notes
The
TransitionConfig.Defaultfield acts as a catch-all — if the callback response contains a field value not present in the mapping (e.g. a new decision type added by the OGA service), the FSM will still transition predictably rather than returning an error.