@@ -96,7 +96,10 @@ def _create_catalog_zip(
9696 zf .writestr (extra_manifest_path , manifest_text )
9797
9898 @pytest .mark .parametrize ("native_hooks" , [False , True ])
99- def test_update_legacy_event_follows_opt_in_mode (self , tmp_path , native_hooks ):
99+ @pytest .mark .parametrize ("event" , ["custom:after" , "before_my-extension_assess" ])
100+ def test_update_legacy_event_follows_opt_in_mode (self , tmp_path , native_hooks , event ):
101+ from specify_cli .extensions ._command_update_artifacts import _archive_extension_directory
102+
100103 project = tmp_path / "project"
101104 project .mkdir ()
102105 (project / ".specify" ).mkdir ()
@@ -108,43 +111,56 @@ def test_update_legacy_event_follows_opt_in_mode(self, tmp_path, native_hooks):
108111 manager .install_from_directory (
109112 original_source , "0.1.0" , catalog_name = "original-catalog"
110113 )
111- original_entry = manager .registry .get ("test-ext" )
112- original_config = yaml .safe_load ((project / ".specify/extensions.yml" ).read_text ())
114+ executor = HookExecutor (project )
115+ config = executor .load_project_config_for_update ()
116+ config ["hooks" ]["after_tasks" ].append ({
117+ "extension" : "other-ext" , "command" : "speckit.other-ext.run" ,
118+ })
119+ executor .save_project_config (config )
120+ executor .config_file .write_bytes (
121+ b"# Preserve hook order and formatting\r \n "
122+ + executor .config_file .read_bytes ().replace (b"\n " , b"\r \n " )
123+ )
124+ executor .migrate_project_config ()
125+ original_files = {
126+ path .relative_to (project ): path .read_bytes ()
127+ for path in project .rglob ("*" ) if path .is_file ()
128+ }
113129 updated_source = self ._create_extension_source (tmp_path , "2.0.0" )
114130 manifest_path = updated_source / "extension.yml"
115131 manifest = yaml .safe_load (manifest_path .read_text ())
116- manifest ["hooks" ] = {"custom:after" : {"command" : "speckit.test-ext.hello" }}
132+ manifest ["hooks" ] = {event : {"command" : "speckit.test-ext.hello" }}
117133 manifest_path .write_text (yaml .safe_dump (manifest ))
118- zip_path = tmp_path / "test-ext-update.zip"
119- self ._create_catalog_zip (zip_path , "2.0.0" )
120-
121- def install_invalid_update (self_obj , _zip_path , version , * , catalog_name = None ):
122- return self_obj .install_from_directory (
123- updated_source , version , catalog_name = catalog_name
124- )
134+ zip_path = _archive_extension_directory (updated_source )
125135
126136 with patch .object (Path , "cwd" , return_value = project ), \
127137 patch .object (ExtensionCatalog , "get_extension_info" , return_value = {
128138 "id" : "test-ext" , "name" : "Test Extension" , "version" : "2.0.0" ,
129139 "_install_allowed" : True ,
130140 }), \
131141 patch .object (ExtensionCatalog , "download_extension" , return_value = zip_path ), \
132- patch .object (ExtensionManager , "install_from_zip" , install_invalid_update ):
142+ patch .object (
143+ ExtensionManager , "remove" , autospec = True ,
144+ side_effect = ExtensionManager .remove ,
145+ ) as remove :
133146 result = CliRunner ().invoke (
134147 app , ["extension" , "update" , "test-ext" ], input = "y\n "
135148 )
149+ assert not zip_path .exists ()
136150 if native_hooks :
137151 assert result .exit_code == 1 , result .output
138152 assert "Rename legacy events" in result .output
139- assert ExtensionManager (project ).registry .get ("test-ext" ) == original_entry
140- assert yaml .safe_load (
141- (project / ".specify/extensions.yml" ).read_text ()
142- ) == original_config
143- assert (project / ".specify/hook-dispatch" ).exists ()
153+ remove .assert_not_called ()
154+ assert "Rolling back" not in result .output
155+ assert {
156+ path .relative_to (project ): path .read_bytes ()
157+ for path in project .rglob ("*" ) if path .is_file ()
158+ } == original_files
144159 else :
145160 assert result .exit_code == 0 , result .output
161+ remove .assert_called_once ()
146162 assert ExtensionManager (project ).registry .get ("test-ext" )["version" ] == "2.0.0"
147- assert "custom:after" in yaml .safe_load (
163+ assert event in yaml .safe_load (
148164 (project / ".specify/extensions.yml" ).read_text ()
149165 )["hooks" ]
150166 assert not (project / ".specify/hook-dispatch" ).exists ()
0 commit comments