Skip to content

Commit 6f14fc7

Browse files
committed
Fix file_change in-progress parsing
1 parent 4596cc9 commit 6f14fc7

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

CodexSharpSDK.Tests/Performance/ThreadEventParserPerformanceTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class ThreadEventParserPerformanceTests
2020
"""{"type":"item.completed","item":{"id":"cmd_1","type":"command_execution","command":"ls","aggregated_output":"","status":"in_progress"}}""",
2121
"""{"type":"item.completed","item":{"id":"cmd_2","type":"command_execution","command":"ls","aggregated_output":"done","exit_code":0,"status":"completed"}}""",
2222
"""{"type":"item.completed","item":{"id":"cmd_3","type":"command_execution","command":"ls","aggregated_output":"boom","exit_code":1,"status":"failed"}}""",
23+
"""{"type":"item.started","item":{"id":"change_0","type":"file_change","changes":[{"path":"progress.txt","kind":"add"}],"status":"in_progress"}}""",
2324
"""{"type":"item.completed","item":{"id":"change_1","type":"file_change","changes":[{"path":"a.txt","kind":"add"},{"path":"b.txt","kind":"update"},{"path":"c.txt","kind":"delete"}],"status":"completed"}}""",
2425
"""{"type":"item.completed","item":{"id":"change_2","type":"file_change","changes":[{"path":"d.txt","kind":"update"}],"status":"failed"}}""",
2526
"""{"type":"item.completed","item":{"id":"mcp_1","type":"mcp_tool_call","server":"srv","tool":"tool","arguments":{"x":1},"result":{"content":[{"type":"text","text":"ok"}],"structured_content":{"ok":true}},"status":"in_progress"}}""",
@@ -114,6 +115,7 @@ await Assert.That(commandStatuses).IsEquivalentTo(
114115
]);
115116
await Assert.That(patchStatuses).IsEquivalentTo(
116117
[
118+
PatchApplyStatus.InProgress,
117119
PatchApplyStatus.Completed,
118120
PatchApplyStatus.Failed,
119121
]);

CodexSharpSDK.Tests/Unit/ThreadEventParserTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ public async Task Parse_RecognizesAllItemKinds()
6767
await Assert.That(parsedItems[8]).IsTypeOf<CollabToolCallItem>();
6868
}
6969

70+
[Test]
71+
public async Task Parse_FileChangeStartedWithInProgressStatus_IsSupported()
72+
{
73+
var parsed = ThreadEventParser.Parse(
74+
"{\"type\":\"item.started\",\"item\":{\"id\":\"item_1\",\"type\":\"file_change\",\"changes\":[{\"path\":\"C:/git/CodexSandbox/apple.txt\",\"kind\":\"add\"},{\"path\":\"C:/git/CodexSandbox/banana.txt\",\"kind\":\"add\"}],\"status\":\"in_progress\"}}");
75+
76+
var item = (FileChangeItem)((ItemStartedEvent)parsed).Item;
77+
78+
await Assert.That(item.Id).IsEqualTo("item_1");
79+
await Assert.That(item.Status).IsEqualTo(PatchApplyStatus.InProgress);
80+
await Assert.That(item.Changes.Select(change => change.Path))
81+
.IsEquivalentTo(["C:/git/CodexSandbox/apple.txt", "C:/git/CodexSandbox/banana.txt"]);
82+
await Assert.That(item.Changes.Select(change => change.Kind))
83+
.IsEquivalentTo([PatchChangeKind.Add, PatchChangeKind.Add]);
84+
}
85+
7086
[Test]
7187
public async Task Parse_ParsesCollabToolCallDetails()
7288
{

CodexSharpSDK/Internal/ThreadEventParser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ private static PatchApplyStatus ParsePatchApplyStatus(string status)
256256
{
257257
return status switch
258258
{
259+
CodexProtocolConstants.Statuses.InProgress => PatchApplyStatus.InProgress,
259260
CodexProtocolConstants.Statuses.Completed => PatchApplyStatus.Completed,
260261
CodexProtocolConstants.Statuses.Failed => PatchApplyStatus.Failed,
261262
_ => throw new InvalidOperationException($"Unsupported patch apply status: {status}"),

CodexSharpSDK/Models/Items.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum PatchChangeKind
1919

2020
public enum PatchApplyStatus
2121
{
22+
InProgress,
2223
Completed,
2324
Failed,
2425
}

docs/Features/thread-run-flow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Provide deterministic thread-based execution over Codex CLI so C# consumers can
4040
- Invalid JSONL event lines must fail fast with parse context.
4141
- Protocol tokens are parsed via constants, not inline literals.
4242
- Parser must support `collab_tool_call` items emitted by multi-agent operations.
43+
- Parser must accept `file_change` lifecycle statuses across started/completed events, including `in_progress` payloads emitted before patch application finishes.
4344
- Optional `ILogger` (`Microsoft.Extensions.Logging`) receives process lifecycle diagnostics (start/success/failure/cancellation).
4445
- Structured output uses typed `StructuredOutputSchema` models (including DTO property selectors) that are serialized to CLI JSON schema files.
4546
- `LocalImageInput` accepts image path, `FileInfo`, or `Stream`; stream inputs are materialized to temp files and cleaned after run.

0 commit comments

Comments
 (0)