Implement fallback draft generation in AuthorAgent and add unit tests… - #24
Merged
Conversation
… for draft handling
There was a problem hiding this comment.
🟡 Changes recommended
The new empty-draft handling can still treat whitespace-only model output as a valid draft, which can leave an effectively empty/unreviewable draft unless the checks are tightened.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR ensures the Author stage always leaves the workflow with a reviewable draft by generating a fallback draft when the model returns no content and no prior draft exists, and adds unit tests to validate this behavior.
Changes:
- Add fallback draft generation in
AuthorAgent.AuthorNodeAsyncwhen the model output is empty andstate.Draftis also empty. - Add
EmptyChatClienttest double to simulate a model returning an empty response. - Add
AuthorAgentTeststo cover fallback behavior, keeping an existing draft, and using model-generated content.
File summaries
| File | Description |
|---|---|
| AuthorAgent.cs | Adds last-resort fallback draft construction when no draft can be generated or retained. |
| BlogWriter.Tests/TestChatClients.cs | Adds EmptyChatClient to simulate empty model responses in tests. |
| BlogWriter.Tests/AuthorAgentTests.cs | Adds unit tests validating fallback and non-clobbering behavior in the author stage. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
106
to
+109
| if (string.IsNullOrEmpty(draft)) | ||
| { | ||
| // Keep whatever draft already exists rather than clobbering it with a | ||
| // placeholder — an empty/failed generation shouldn't erase real content. | ||
| _logger.LogWarning("Author agent produced no draft; keeping the previous draft (if any)."); | ||
| if (string.IsNullOrEmpty(state.Draft)) | ||
| { |
|
|
||
| state = await CreateAgent(new EmptyChatClient()).AuthorNodeAsync(state); | ||
|
|
||
| Assert.False(string.IsNullOrEmpty(state.Draft)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… for draft handling