-
Notifications
You must be signed in to change notification settings - Fork 7.2k
feat: add --dev flag to extension update command #2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4024,6 +4024,7 @@ def _print_extension_info(ext_info: dict, manager): | |||||||||||||||||||||||||||||||
| @extension_app.command("update") | ||||||||||||||||||||||||||||||||
| def extension_update( | ||||||||||||||||||||||||||||||||
| extension: str = typer.Argument(None, help="Extension ID or name to update (or all)"), | ||||||||||||||||||||||||||||||||
| dev: bool = typer.Option(False, "--dev", help="Update from local directory (re-copies source, preserves config)"), | ||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||
| """Update extension(s) to latest version.""" | ||||||||||||||||||||||||||||||||
| from .extensions import ( | ||||||||||||||||||||||||||||||||
|
|
@@ -4048,9 +4049,113 @@ def extension_update( | |||||||||||||||||||||||||||||||
| raise typer.Exit(1) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| manager = ExtensionManager(project_root) | ||||||||||||||||||||||||||||||||
| catalog = ExtensionCatalog(project_root) | ||||||||||||||||||||||||||||||||
| speckit_version = get_speckit_version() | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # ── Dev mode: update from local directory ────────────────────────── | ||||||||||||||||||||||||||||||||
| if dev: | ||||||||||||||||||||||||||||||||
| if not extension: | ||||||||||||||||||||||||||||||||
| console.print("[red]Error:[/red] --dev requires extension path argument") | ||||||||||||||||||||||||||||||||
| console.print("Usage: specify extension update --dev /path/to/extension") | ||||||||||||||||||||||||||||||||
| raise typer.Exit(1) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| source_path = Path(extension).expanduser().resolve() | ||||||||||||||||||||||||||||||||
| if not source_path.exists(): | ||||||||||||||||||||||||||||||||
| console.print(f"[red]Error:[/red] Directory not found: {source_path}") | ||||||||||||||||||||||||||||||||
| raise typer.Exit(1) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| raise typer.Exit(1) | |
| raise typer.Exit(1) | |
| elif not source_path.is_dir(): | |
| console.print(f"[red]Error:[/red] --dev path must be a directory: {source_path}") | |
| raise typer.Exit(1) |
Copilot
AI
Mar 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading/parsing extension.yml here is outside the surrounding try/except and can raise (YAML syntax error, permission error, etc.), resulting in an uncaught exception/traceback. Consider using the existing ExtensionManifest loader/validator (from specify_cli.extensions) or wrapping the file read + yaml.safe_load in error handling and returning a clean Typer error message.
| import yaml | |
| with open(manifest_path) as f: | |
| manifest_data = yaml.safe_load(f) or {} | |
| try: | |
| with open(manifest_path) as f: | |
| manifest_data = yaml.safe_load(f) or {} | |
| except (OSError, yaml.YAMLError) as e: | |
| console.print(f"[red]Error:[/red] Failed to read or parse {manifest_path}: {e}") | |
| raise typer.Exit(1) |
Copilot
AI
Mar 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installed detection uses manager.list_installed() to build installed_ids. list_installed() is based on registry.list() which filters out corrupted/non-dict entries, so an extension can still be “installed” per registry.is_installed() yet be missing from installed_ids—leading --dev to attempt a fresh install and fail with “already installed”. Consider checking installation via manager.registry.is_installed(extension_id) (or manager.registry.keys()) instead of relying on list_installed().
| # Check if installed | |
| installed = manager.list_installed() | |
| installed_ids = {ext["id"] for ext in installed} | |
| if extension_id not in installed_ids: | |
| # Check if installed using registry to handle corrupted entries gracefully | |
| try: | |
| is_installed = manager.registry.is_installed(extension_id) | |
| except AttributeError: | |
| # Fallback for environments without registry.is_installed | |
| installed = manager.list_installed() | |
| installed_ids = {ext["id"] for ext in installed} | |
| is_installed = extension_id in installed_ids | |
| if not is_installed: |
Copilot
AI
Mar 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the extension was disabled before the update, this code restores enabled=False in the registry, but it doesn’t re-disable hooks in .specify/extensions.yml. The catalog update path explicitly disables those hooks to keep behavior consistent. Consider mirroring that logic here so disabled extensions don’t end up executing hooks after a dev update.
Copilot
AI
Mar 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failure handling here can cause irreversible loss: after remove() succeeds, if install_from_directory() or config restore fails, the old extension is gone and the config backup is deleted in finally. Consider implementing rollback (similar to the existing catalog update path) or, at minimum, only deleting the backup directory after a successful update and leaving it in place on failure. Also consider guarding shutil.rmtree in the cleanup path so a cleanup error doesn’t mask the original update failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are CLI integration tests for
specify extension updatealready (seeTestExtensionUpdateCLI), but this new--devcode path is untested. Adding tests for--devupdate (installed and not-installed cases, config preservation, and disabled extension hook behavior) would help prevent regressions.