Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/install/air-gapped.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ specify init my-project --integration copilot
> (`powershell.exe`), which is included with Windows. PowerShell 7 (`pwsh`) is
> not required for offline scaffolding. Pass `--script ps` to select the
> PowerShell scripts explicitly; non-interactive initialization on Windows
> selects them by default.
> selects them by default. Windows PowerShell 5.1 remains supported for now,
> but its support will be deprecated in the next point release.
>
> To prepare offline, download a PowerShell 7 installer or ZIP on a connected
> machine using [Microsoft's installation guide](https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows),
> then transfer it to the target. Install it or extract the ZIP and add its
> directory to `PATH`. See the [migration guidance](../installation.md#preparing-for-powershell-7).

## Component catalogs and sources

Expand Down
16 changes: 16 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ specify init <project_name> --script ps
specify init <project_name> --script py
```

#### Preparing for PowerShell 7

Windows PowerShell 5.1 remains supported for now. Its support will be deprecated
in the next point release; PowerShell 7 is not required yet. To prepare, install
[PowerShell 7 or later](https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows)
if `pwsh` is not available. On Windows, one option is:

```powershell
winget install --id Microsoft.PowerShell --source winget
```

Open a new shell and run `pwsh --version` to confirm the installation. Use
`pwsh` to run Spec Kit's PowerShell scripts, and update project or CI commands
that invoke them with `powershell.exe`. PowerShell 7 installs alongside Windows
PowerShell 5.1.

### CI and AI Agent Harnesses

For environments without a keyboard, or a PTY that cannot send arrow keys, pass
Expand Down
16 changes: 16 additions & 0 deletions src/specify_cli/_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@
# never contaminate stdout (which carries machine-readable ``--json`` payloads).
err_console = Console(stderr=True, highlight=False)


def show_powershell_support_notice() -> None:
err_console.print()
err_console.print(
Panel(
"Spec Kit's Windows PowerShell 5.1 support will be deprecated "
"in the next point release. PowerShell 5.1 remains supported "
"for now.\n\n"
"Migration guidance: https://github.github.io/spec-kit/installation.html",
title="[yellow]PowerShell Support Notice[/yellow]",
border_style="yellow",
padding=(1, 2),
)
)


class StepTracker:
"""Track and render hierarchical steps without emojis, similar to Claude Code tree output.
Supports live auto-refresh via an attached refresh callback.
Expand Down
10 changes: 9 additions & 1 deletion src/specify_cli/command_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
_locate_bundled_workflow,
get_speckit_version,
)
from ._console import StepTracker, console, select_with_arrows, show_banner
from ._console import (
StepTracker,
console,
select_with_arrows,
show_banner,
show_powershell_support_notice,
)
from ._utils import check_tool


Expand Down Expand Up @@ -1102,6 +1108,8 @@ def init(
console.print(tracker.render())
lifecycle_success("\n[bold green]Project ready.[/bold green]")

show_powershell_support_notice()

agent_config = AGENT_CONFIG.get(selected_ai)
if agent_config:
agent_folder = agent_config["folder"] or integration_parsed_options.get(
Expand Down
5 changes: 5 additions & 0 deletions src/specify_cli/workflows/step/init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def execute(self, config: dict[str, Any], context: StepContext) -> StepResult:
or f"specify init exited with code {exit_code}."
),
)

from specify_cli._console import show_powershell_support_notice

show_powershell_support_notice()

return StepResult(status=StepStatus.COMPLETED, output=output)

@staticmethod
Expand Down
13 changes: 13 additions & 0 deletions tests/specify_cli/bundles/test_command_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
REPO_ROOT = Path(__file__).parents[3]


def test_bundle_init_surfaces_powershell_notice(tmp_path, monkeypatch):
from specify_cli.bundles import command_init

monkeypatch.setattr(command_init, "_default_script_type", lambda: "ps")
monkeypatch.chdir(tmp_path)

result = runner.invoke(app, ["bundle", "init", "--integration", "none", "--offline"])

assert result.exit_code == 0, result.output
assert (tmp_path / ".specify" / "scripts" / "powershell" / "common.ps1").is_file()
assert result.stderr.count("PowerShell Support Notice") == 1


def test_bundle_init_uses_declared_integration_in_new_project(tmp_path, monkeypatch):
bundle = write_manifest(
tmp_path / "claude-bundle",
Expand Down
82 changes: 71 additions & 11 deletions tests/specify_cli/test_command_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,88 @@ def _strip(text: str) -> str:
return _ANSI.sub("", text or "")


def _init(tmp_path: Path, name: str):
def _init(
tmp_path: Path, name: str, script: str | None = None, extension: str | None = None
):
"""Run a fully offline, non-interactive `specify init <name>`."""
previous = os.getcwd()
os.chdir(tmp_path)
try:
args = [
"init",
name,
"--integration",
"generic",
"--integration-options",
"--commands-dir .agent/commands",
"--ignore-agent-tools",
"--offline",
]
if script:
args.extend(["--script", script])
if extension:
args.extend(["--extension", extension])
return CliRunner().invoke(
app,
[
"init",
name,
"--integration",
"generic",
"--integration-options",
"--commands-dir .agent/commands",
"--ignore-agent-tools",
"--offline",
],
args,
catch_exceptions=True,
)
finally:
os.chdir(previous)


def test_powershell_deprecation_notice_for_powershell_scaffold(tmp_path: Path):
ps_result = _init(tmp_path, "powershell-project", script="ps")
assert ps_result.exit_code == 0, _strip(ps_result.output)
ps_scripts = tmp_path / "powershell-project" / ".specify" / "scripts" / "powershell"
assert (ps_scripts / "common.ps1").is_file()
ps_output = " ".join(_strip(ps_result.output).replace("│", " ").replace("|", " ").split())
assert (
"Windows PowerShell 5.1 support will be deprecated in the next point release"
in ps_output
)
assert "PowerShell 5.1 remains supported for now" in ps_output
assert ps_result.stderr.count("PowerShell Support Notice") == 1

sh_result = _init(tmp_path, "shell-project", script="sh")
assert sh_result.exit_code == 0, _strip(sh_result.output)
assert sh_result.stderr.count("PowerShell Support Notice") == 1


def test_powershell_notice_for_shell_scaffold_with_git_extension(tmp_path: Path):
result = _init(tmp_path, "shell-git-project", script="sh", extension="git")

assert result.exit_code == 0, result.output
ps_script = (
tmp_path
/ "shell-git-project"
/ ".specify"
/ "extensions"
/ "git"
/ "scripts"
/ "powershell"
/ "initialize-repo.ps1"
)
assert ps_script.is_file()
assert result.stderr.count("PowerShell Support Notice") == 1


def test_python_init_warns_when_powershell_fallback_is_installed(tmp_path, monkeypatch):
from specify_cli import shared_infra

original_variants = shared_infra.script_variant_dirs

def windows_variants(script):
return ("python", "powershell") if script == "py" else original_variants(script)

monkeypatch.setattr(shared_infra, "script_variant_dirs", windows_variants)
result = _init(tmp_path, "python-project", script="py")

assert result.exit_code == 0, result.output
assert (tmp_path / "python-project" / ".specify" / "scripts" / "powershell").is_dir()
assert "PowerShell Support Notice" in result.output


@pytest.mark.parametrize("numbering", ["timestamp", "sequential", None])
def test_reinit_preserves_feature_numbering(tmp_path: Path, monkeypatch, numbering):
result = _init(tmp_path, "proj")
Expand Down Expand Up @@ -255,6 +314,7 @@ def test_invalid_integration_value_is_rendered_literally(tmp_path: Path):

assert result.exit_code != 0
assert "nope[/red]" in _strip(result.stdout)
assert "PowerShell Support Notice" not in result.stderr


def _fail_shared_infra(monkeypatch, unowned: str | None = None, probe=None):
Expand Down
77 changes: 77 additions & 0 deletions tests/specify_cli/workflows/test_command_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,83 @@
from tests.specify_cli.workflows.helpers import force_gate_stdin as _force_gate_stdin


@pytest.mark.parametrize("json_output", [False, True])
@pytest.mark.parametrize(
("script", "variants", "integration", "exit_code", "notice_expected"),
[
("ps", None, "none", 0, True),
("sh", None, "none", 0, True),
("py", ("python", "powershell"), "none", 0, True),
("py", ("python", "bash"), "none", 0, True),
(None, None, "none", 0, True),
("ps", None, "no-such-agent", 1, False),
],
)
def test_init_step_powershell_notice(
tmp_path, monkeypatch, json_output, script, variants, integration, exit_code, notice_expected
):
from typer.testing import CliRunner

from specify_cli import app

if variants is not None:
from specify_cli import shared_infra

original_variants = shared_infra.script_variant_dirs

def selected_variants(value):
return variants if value == "py" else original_variants(value)

monkeypatch.setattr(shared_infra, "script_variant_dirs", selected_variants)

home = tmp_path / "home"
home.mkdir()
monkeypatch.setenv("HOME", str(home))
monkeypatch.setenv("USERPROFILE", str(home))
monkeypatch.setenv("XDG_CACHE_HOME", str(home / ".cache"))
monkeypatch.setenv("XDG_CONFIG_HOME", str(home / ".config"))
monkeypatch.setenv("XDG_DATA_HOME", str(home / ".local" / "share"))
project = tmp_path / "project"
project.mkdir()
workflow = tmp_path / "workflow.yml"
workflow.write_text(
yaml.safe_dump(
{
"schema_version": "1.0",
"workflow": {"id": "init-notice", "name": "Init notice", "version": "1.0.0"},
"steps": [
{
"id": "bootstrap",
"type": "init",
"project": "demo",
"integration": integration,
"script": script,
}
],
}
),
encoding="utf-8",
)
monkeypatch.chdir(project)

result = CliRunner().invoke(
app,
["workflow", "run", str(workflow), *(["--json"] if json_output else [])],
catch_exceptions=False,
)

assert result.exit_code == exit_code, result.output
assert (project / "demo" / ".specify").is_dir() is (exit_code == 0)
if json_output:
assert json.loads(result.stdout)["status"] == ("completed" if exit_code == 0 else "failed")
assert "PowerShell Support Notice" not in result.stdout
assert result.stderr.count("PowerShell Support Notice") == int(notice_expected)
if notice_expected:
notice = " ".join(result.stderr.replace("│", " ").replace("|", " ").split())
assert "Windows PowerShell 5.1 support will be deprecated in the next point release" in notice
assert "PowerShell 5.1 remains supported for now" in notice


class TestWorkflowStartupArtifacts:
@pytest.fixture(params=["missing", "numeric", "enum"])
def invalid_input(self, request):
Expand Down
Loading