Skip to content

Commit 11d99bd

Browse files
CrazyBaranclaude
andcommitted
test(extensions): pin execute-bit restoration through the archive update route
Copilot review round 6 on #4351 reported that bundled updates lose executable permissions on POSIX because safe_extract_archive writes ZIP members without reapplying their recorded modes. The premise about the extractor is accurate, but the conclusion does not hold: every archive install funnels into install_from_directory (install_from_zip -> install_from_archive -> install_from_directory), whose trailing ensure_executable_scripts() call re-establishes execute bits on every .specify/extensions/**/*.sh shebang script - pre-existing behavior whose code comment describes exactly this stripped-mode scenario, and which covers all POSIX-invoked scripts the bundled extensions ship (.ps1 and .py files are interpreter-invoked and need no execute bit). What the report does expose is that nothing pinned this round trip: deleting the restoration call would have broken bundled updates exactly as described while CI stayed green. Add the suggested regression test - build an archive from a source with an executable script via _archive_extension_directory, install it through install_from_zip, and assert the installed script's execute bit. POSIX-only (execute bits do not exist on Windows; the helper no-ops there). Refs #4345 Assisted-by: Claude Code (model: claude-fable-5, autonomous) Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 6a7c475 commit 11d99bd

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎tests/test_extension_content_staleness.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from __future__ import annotations
1111

12+
import os
13+
1214
import pytest
1315
import yaml
1416
from pathlib import Path
@@ -196,6 +198,36 @@ def test_archive_never_follows_symlinks(self, tmp_path):
196198
finally:
197199
archive_path.unlink()
198200

201+
@pytest.mark.skipif(
202+
os.name == "nt", reason="POSIX execute bits do not exist on Windows"
203+
)
204+
def test_archive_route_restores_script_execute_bits(self, tmp_path):
205+
"""safe_extract_archive writes members without their recorded ZIP
206+
modes, so the archive install route depends on install_from_directory's
207+
trailing ensure_executable_scripts() call to keep documented
208+
`.specify/extensions/<id>/scripts/*.sh` invocations executable. Pin
209+
that round trip so removing the restoration would fail here instead
210+
of surfacing as `Permission denied` after a bundled update."""
211+
from specify_cli.extensions._commands import _archive_extension_directory
212+
213+
project_dir = _make_project(tmp_path)
214+
source = _create_extension_source(tmp_path)
215+
(source / "scripts" / "run.sh").chmod(0o755)
216+
217+
archive_path = _archive_extension_directory(source)
218+
try:
219+
ExtensionManager(project_dir).install_from_zip(archive_path, "0.1.0")
220+
finally:
221+
archive_path.unlink()
222+
223+
installed_script = (
224+
project_dir / ".specify" / "extensions" / "test-ext" / "scripts" / "run.sh"
225+
)
226+
assert installed_script.is_file()
227+
assert installed_script.stat().st_mode & 0o100, (
228+
"execute bit lost through the archive install route"
229+
)
230+
199231

200232
class TestInstallStoresContentHash:
201233
def test_registry_entry_records_source_content_hash(self, tmp_path):

0 commit comments

Comments
 (0)