@@ -45,24 +45,88 @@ func TestLoad_NewStructure(t *testing.T) {
4545lockVersion: "2.0.0"
4646id: "test-uuid"
4747management: {}
48+ persistentEdits:
49+ generation_id: "uuid-550e"
50+ pristine_commit_hash: "a1b2c3"
51+ pristine_tree_hash: "tree-e5f6"
52+ trackedFiles:
53+ "pkg/models/user.go":
54+ id: "uuid-breadcrumb-123"
55+ last_write_checksum: "sha1:file-hash-789"
56+ pristine_git_object: "blob-123"
57+ ` )
58+
59+ lf , err := lockfile .Load (newYAML )
60+ require .NoError (t , err )
61+
62+ // Verify persistentEdits
63+ require .NotNil (t , lf .PersistentEdits )
64+ assert .Equal (t , "uuid-550e" , lf .PersistentEdits .GenerationID )
65+ assert .Equal (t , "a1b2c3" , lf .PersistentEdits .PristineCommitHash )
66+ assert .Equal (t , "tree-e5f6" , lf .PersistentEdits .PristineTreeHash )
67+
68+ // Verify tracked file
69+ tf , ok := lf .TrackedFiles .Get ("pkg/models/user.go" )
70+ require .True (t , ok )
71+
72+ assert .Equal (t , "uuid-breadcrumb-123" , tf .ID )
73+ assert .Equal (t , "sha1:file-hash-789" , tf .LastWriteChecksum )
74+ assert .Equal (t , "blob-123" , tf .PristineGitObject )
75+ }
76+
77+ func TestLoad_MigratesPristineBlobHashToGitObject (t * testing.T ) {
78+ // Legacy lockfile YAML with 'pristine_blob_hash' field
79+ legacyYAML := []byte (`
80+ lockVersion: "2.0.0"
81+ id: "test-uuid"
82+ management: {}
4883trackedFiles:
4984 "src/model.go":
5085 id: "file-uuid-123"
5186 pristine_blob_hash: "git-hash-456"
5287 last_write_checksum: "sha1:file-hash-789"
5388` )
5489
55- lf , err := lockfile .Load (newYAML )
90+ lf , err := lockfile .Load (legacyYAML )
5691 require .NoError (t , err )
92+ require .NotNil (t , lf )
5793
94+ // Verify the file exists in tracked files
5895 tf , ok := lf .TrackedFiles .Get ("src/model.go" )
5996 require .True (t , ok )
6097
98+ // Verify migration
99+ assert .Equal (t , "git-hash-456" , tf .PristineGitObject , "Should migrate pristine_blob_hash to pristine_git_object" )
100+
101+ // Verify cleanup
102+ _ , exists := tf .AdditionalProperties ["pristine_blob_hash" ]
103+ assert .False (t , exists , "Should remove pristine_blob_hash from AdditionalProperties" )
104+
105+ // Verify other properties preserved
61106 assert .Equal (t , "file-uuid-123" , tf .ID )
62- assert .Equal (t , "git-hash-456" , tf .PristineBlobHash )
63107 assert .Equal (t , "sha1:file-hash-789" , tf .LastWriteChecksum )
64108}
65109
110+ func TestLoad_OmitsEmptyPersistentEdits (t * testing.T ) {
111+ // Lockfile YAML without persistentEdits section
112+ yamlWithoutPE := []byte (`
113+ lockVersion: "2.0.0"
114+ id: "test-uuid"
115+ management: {}
116+ trackedFiles:
117+ "src/file.go":
118+ id: "file-uuid"
119+ last_write_checksum: "sha1:hash"
120+ ` )
121+
122+ lf , err := lockfile .Load (yamlWithoutPE )
123+ require .NoError (t , err )
124+ require .NotNil (t , lf )
125+
126+ // Verify persistentEdits is nil when not present
127+ assert .Nil (t , lf .PersistentEdits , "PersistentEdits should be nil when not in YAML" )
128+ }
129+
66130func TestNew_CreatesValidLockFile (t * testing.T ) {
67131 lf := lockfile .New ()
68132 require .NotNil (t , lf )
@@ -71,4 +135,5 @@ func TestNew_CreatesValidLockFile(t *testing.T) {
71135 assert .NotEmpty (t , lf .ID )
72136 assert .NotNil (t , lf .TrackedFiles )
73137 assert .Equal (t , 0 , lf .TrackedFiles .Len ())
138+ assert .Nil (t , lf .PersistentEdits , "PersistentEdits should be nil in new lockfile" )
74139}
0 commit comments