@@ -1683,86 +1683,132 @@ describe("CheckpointReactor", () => {
16831683 } ) ,
16841684 ) ;
16851685
1686- it ( "executes provider revert and emits thread.reverted for checkpoint revert requests" , async ( ) => {
1687- const harness = await createHarness ( ) ;
1688- const createdAt = "2026-01-01T00:00:00.000Z" ;
1686+ it . each ( [
1687+ { commandType : "thread.checkpoint.revert" , initializeGit : true } ,
1688+ { commandType : "thread.conversation.revert" , initializeGit : true } ,
1689+ { commandType : "thread.conversation.revert" , initializeGit : false } ,
1690+ ] as const ) (
1691+ "$commandType rewinds history with the requested filesystem behavior (git: $initializeGit)" ,
1692+ async ( { commandType, initializeGit } ) => {
1693+ const harness = await createHarness ( {
1694+ initializeGit,
1695+ seedFilesystemCheckpoints : initializeGit ,
1696+ } ) ;
1697+ const createdAt = "2026-01-01T00:00:00.000Z" ;
16891698
1690- await Effect . runPromise (
1691- harness . engine . dispatch ( {
1692- type : "thread.session.set" ,
1693- commandId : CommandId . make ( "cmd-session-set" ) ,
1694- threadId : ThreadId . make ( "thread-1" ) ,
1695- session : {
1699+ await Effect . runPromise (
1700+ harness . engine . dispatch ( {
1701+ type : "thread.session.set" ,
1702+ commandId : CommandId . make ( "cmd-session-set" ) ,
16961703 threadId : ThreadId . make ( "thread-1" ) ,
1697- status : "ready" ,
1698- providerName : "codex" ,
1699- runtimeMode : "approval-required" ,
1700- activeTurnId : null ,
1701- lastError : null ,
1702- updatedAt : createdAt ,
1703- } ,
1704- createdAt,
1705- } ) ,
1706- ) ;
1704+ session : {
1705+ threadId : ThreadId . make ( "thread-1" ) ,
1706+ status : "ready" ,
1707+ providerName : "codex" ,
1708+ runtimeMode : "approval-required" ,
1709+ activeTurnId : null ,
1710+ lastError : null ,
1711+ updatedAt : createdAt ,
1712+ } ,
1713+ createdAt,
1714+ } ) ,
1715+ ) ;
17071716
1708- await Effect . runPromise (
1709- harness . engine . dispatch ( {
1710- type : "thread.turn.diff.complete" ,
1711- commandId : CommandId . make ( "cmd-diff-1" ) ,
1712- threadId : ThreadId . make ( "thread-1" ) ,
1713- turnId : asTurnId ( "turn-1" ) ,
1714- completedAt : createdAt ,
1715- checkpointRef : checkpointRefForThreadTurn ( ThreadId . make ( "thread-1" ) , 1 ) ,
1716- status : "ready" ,
1717- files : [ ] ,
1718- checkpointTurnCount : 1 ,
1719- createdAt,
1720- } ) ,
1721- ) ;
1722- await Effect . runPromise (
1723- harness . engine . dispatch ( {
1724- type : "thread.turn.diff.complete" ,
1725- commandId : CommandId . make ( "cmd-diff-2" ) ,
1726- threadId : ThreadId . make ( "thread-1" ) ,
1727- turnId : asTurnId ( "turn-2" ) ,
1728- completedAt : createdAt ,
1729- checkpointRef : checkpointRefForThreadTurn ( ThreadId . make ( "thread-1" ) , 2 ) ,
1730- status : "ready" ,
1731- files : [ ] ,
1732- checkpointTurnCount : 2 ,
1733- createdAt,
1734- } ) ,
1735- ) ;
1717+ await Effect . runPromise (
1718+ harness . engine . dispatch ( {
1719+ type : "thread.turn.diff.complete" ,
1720+ commandId : CommandId . make ( "cmd-diff-1" ) ,
1721+ threadId : ThreadId . make ( "thread-1" ) ,
1722+ turnId : asTurnId ( "turn-1" ) ,
1723+ completedAt : createdAt ,
1724+ checkpointRef : initializeGit
1725+ ? checkpointRefForThreadTurn ( ThreadId . make ( "thread-1" ) , 1 )
1726+ : CheckpointRef . make ( "provider-diff:thread-1:turn-1" ) ,
1727+ status : initializeGit ? "ready" : "missing" ,
1728+ files : [ ] ,
1729+ checkpointTurnCount : 1 ,
1730+ createdAt,
1731+ } ) ,
1732+ ) ;
1733+ await Effect . runPromise (
1734+ harness . engine . dispatch ( {
1735+ type : "thread.turn.diff.complete" ,
1736+ commandId : CommandId . make ( "cmd-diff-2" ) ,
1737+ threadId : ThreadId . make ( "thread-1" ) ,
1738+ turnId : asTurnId ( "turn-2" ) ,
1739+ completedAt : createdAt ,
1740+ checkpointRef : initializeGit
1741+ ? checkpointRefForThreadTurn ( ThreadId . make ( "thread-1" ) , 2 )
1742+ : CheckpointRef . make ( "provider-diff:thread-1:turn-2" ) ,
1743+ status : initializeGit ? "ready" : "missing" ,
1744+ files : [ ] ,
1745+ checkpointTurnCount : 2 ,
1746+ createdAt,
1747+ } ) ,
1748+ ) ;
17361749
1737- await Effect . runPromise (
1738- harness . engine . dispatch ( {
1739- type : "thread.checkpoint.revert" ,
1740- commandId : CommandId . make ( "cmd-revert-request" ) ,
1741- threadId : ThreadId . make ( "thread-1" ) ,
1742- turnCount : 1 ,
1743- createdAt,
1744- } ) ,
1745- ) ;
1750+ NodeFS . writeFileSync ( NodePath . join ( harness . cwd , "README.md" ) , "staged edit\n" ) ;
1751+ if ( initializeGit ) {
1752+ NodeChildProcess . execFileSync ( "git" , [ "add" , "README.md" ] , { cwd : harness . cwd } ) ;
1753+ }
1754+ NodeFS . writeFileSync ( NodePath . join ( harness . cwd , "README.md" ) , "unstaged edit\n" ) ;
1755+ NodeFS . writeFileSync ( NodePath . join ( harness . cwd , "scratch.txt" ) , "untracked edit\n" ) ;
1756+ const indexBefore = initializeGit
1757+ ? NodeChildProcess . execFileSync ( "git" , [ "ls-files" , "--stage" ] , {
1758+ cwd : harness . cwd ,
1759+ encoding : "utf8" ,
1760+ } )
1761+ : undefined ;
17461762
1747- await waitForEvent ( harness . engine , ( event ) => event . type === "thread.reverted" ) ;
1748- const thread = await waitForThread (
1749- harness . readModel ,
1750- ( entry ) => entry . checkpoints . length === 1 ,
1751- ) ;
1763+ await Effect . runPromise (
1764+ harness . engine . dispatch ( {
1765+ type : commandType ,
1766+ commandId : CommandId . make ( "cmd-revert-request" ) ,
1767+ threadId : ThreadId . make ( "thread-1" ) ,
1768+ turnCount : 1 ,
1769+ createdAt,
1770+ } ) ,
1771+ ) ;
17521772
1753- expect ( thread . latestTurn ?. turnId ) . toBe ( "turn-1" ) ;
1754- expect ( thread . checkpoints ) . toHaveLength ( 1 ) ;
1755- expect ( thread . checkpoints [ 0 ] ?. checkpointTurnCount ) . toBe ( 1 ) ;
1756- expect ( harness . provider . rollbackConversation ) . toHaveBeenCalledTimes ( 1 ) ;
1757- expect ( harness . provider . rollbackConversation ) . toHaveBeenCalledWith ( {
1758- threadId : ThreadId . make ( "thread-1" ) ,
1759- numTurns : 1 ,
1760- } ) ;
1761- expect ( NodeFS . readFileSync ( NodePath . join ( harness . cwd , "README.md" ) , "utf8" ) ) . toBe ( "v2\n" ) ;
1762- expect (
1763- gitRefExists ( harness . cwd , checkpointRefForThreadTurn ( ThreadId . make ( "thread-1" ) , 2 ) ) ,
1764- ) . toBe ( false ) ;
1765- } ) ;
1773+ await waitForEvent ( harness . engine , ( event ) => event . type === "thread.reverted" ) ;
1774+ const thread = await waitForThread (
1775+ harness . readModel ,
1776+ ( entry ) => entry . checkpoints . length === 1 ,
1777+ ) ;
1778+
1779+ expect ( thread . latestTurn ?. turnId ) . toBe ( "turn-1" ) ;
1780+ expect ( thread . checkpoints ) . toHaveLength ( 1 ) ;
1781+ expect ( thread . checkpoints [ 0 ] ?. checkpointTurnCount ) . toBe ( 1 ) ;
1782+ expect ( harness . provider . rollbackConversation ) . toHaveBeenCalledTimes ( 1 ) ;
1783+ expect ( harness . provider . rollbackConversation ) . toHaveBeenCalledWith ( {
1784+ threadId : ThreadId . make ( "thread-1" ) ,
1785+ numTurns : 1 ,
1786+ } ) ;
1787+ expect ( NodeFS . readFileSync ( NodePath . join ( harness . cwd , "README.md" ) , "utf8" ) ) . toBe (
1788+ commandType === "thread.conversation.revert" ? "unstaged edit\n" : "v2\n" ,
1789+ ) ;
1790+ if ( commandType === "thread.conversation.revert" ) {
1791+ expect ( NodeFS . readFileSync ( NodePath . join ( harness . cwd , "scratch.txt" ) , "utf8" ) ) . toBe (
1792+ "untracked edit\n" ,
1793+ ) ;
1794+ if ( initializeGit ) {
1795+ expect (
1796+ NodeChildProcess . execFileSync ( "git" , [ "ls-files" , "--stage" ] , {
1797+ cwd : harness . cwd ,
1798+ encoding : "utf8" ,
1799+ } ) ,
1800+ ) . toBe ( indexBefore ) ;
1801+ }
1802+ }
1803+ if ( initializeGit ) {
1804+ expect (
1805+ gitRefExists ( harness . cwd , checkpointRefForThreadTurn ( ThreadId . make ( "thread-1" ) , 2 ) ) ,
1806+ ) . toBe ( false ) ;
1807+ } else {
1808+ expect ( NodeFS . existsSync ( NodePath . join ( harness . cwd , ".git" ) ) ) . toBe ( false ) ;
1809+ }
1810+ } ,
1811+ ) ;
17661812
17671813 it ( "executes provider revert and emits thread.reverted for claude sessions" , async ( ) => {
17681814 const harness = await createHarness ( { providerName : ProviderDriverKind . make ( "claudeAgent" ) } ) ;
0 commit comments