File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -107,6 +107,33 @@ describe("diff file reconciliation", () => {
107107 expect ( buildFileDiffRenderKey ( file ) ) . toBe ( key ) ;
108108 } ) ;
109109
110+ it ( "gives a type change its own identity per block" , ( ) => {
111+ const patch = [
112+ "diff --git a/AGENTS.md b/AGENTS.md" ,
113+ "deleted file mode 100644" ,
114+ "--- a/AGENTS.md" ,
115+ "+++ /dev/null" ,
116+ "@@ -1 +0,0 @@" ,
117+ "-duplicated instructions" ,
118+ "diff --git a/AGENTS.md b/AGENTS.md" ,
119+ "new file mode 120000" ,
120+ "--- /dev/null" ,
121+ "+++ b/AGENTS.md" ,
122+ "@@ -0,0 +1 @@" ,
123+ "+CLAUDE.md" ,
124+ ] . join ( "\n" ) ;
125+ const parsed = getRenderablePatch ( patch , "type-change" ) ;
126+ expect ( parsed ?. kind ) . toBe ( "files" ) ;
127+ if ( parsed ?. kind !== "files" ) return ;
128+ const [ deleted , added ] = parsed . files ;
129+ expect ( deleted ?. type ) . toBe ( "deleted" ) ;
130+ expect ( added ?. type ) . toBe ( "new" ) ;
131+ if ( ! deleted || ! added ) return ;
132+
133+ expect ( buildFileDiffIdentityKey ( deleted ) ) . not . toBe ( buildFileDiffIdentityKey ( added ) ) ;
134+ expect ( new Set ( parsed . files . map ( buildFileDiffIdentityKey ) ) . size ) . toBe ( parsed . files . length ) ;
135+ } ) ;
136+
110137 it ( "keeps identities stable and versions local to the changed file" , ( ) => {
111138 const patch = ( secondLine : string ) =>
112139 [
Original file line number Diff line number Diff line change @@ -163,8 +163,13 @@ export function resolveFileDiffPreviousPath(fileDiff: FileDiffMetadata): string
163163 return raw ;
164164}
165165
166+ /**
167+ * Stable across re-renders of the same file, distinct for every block in a
168+ * patch. A type change (regular file to symlink) arrives as a deletion and an
169+ * addition of the same path, so the change type is part of the identity.
170+ */
166171export function buildFileDiffIdentityKey ( fileDiff : FileDiffMetadata ) : string {
167- return `${ resolveFileDiffPreviousPath ( fileDiff ) } \u0000${ resolveFileDiffPath ( fileDiff ) } ` ;
172+ return `${ resolveFileDiffPreviousPath ( fileDiff ) } \u0000${ resolveFileDiffPath ( fileDiff ) } \u0000 ${ fileDiff . type } ` ;
168173}
169174
170175export function buildFileDiffRenderKey ( fileDiff : FileDiffMetadata ) : string {
You can’t perform that action at this time.
0 commit comments