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
4 changes: 3 additions & 1 deletion docs/system-specs/modules/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,9 @@ One flag is a MODE rather than a check and short-circuits before the list above

`kirocrew update` pulls the latest source and rebuilds:

1. `git fetch`, then `git reset --hard <oid>` from `KIROCREW_PROJECT_DIR`, where
1. `git fetch`, then `git reset --hard <oid>` from `KIROCREW_PROJECT_DIR`, or, when
it is unset (run outside the clone with no saved project dir), from the checkout
the running package loads from (`_bootstrap._source_checkout_root()`), where
`<oid>` is `origin/<branch>` resolved ONCE right after the fetch (`git
rev-parse --verify origin/<branch>^{commit}`). Every later judgment — "already
up to date", the divergence counts, the interpreter floor below — and the
Expand Down
1 change: 1 addition & 0 deletions src/kiro_crew/cli_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ def _tail_log_file(path: Path, lines: int, follow: bool) -> None:
__all__ = sorted(n for n in set(globals()) | set(_EXPORTS) if not n.startswith("_"))
if TYPE_CHECKING: # every owner-defined name in _EXPORTS, for type checkers and IDEs
from kiro_crew import update_next_start # noqa: F401
from kiro_crew._bootstrap import _source_checkout_root # noqa: F401
from kiro_crew.cli_server_peer import ( # noqa: F401
_CLI_LOOPBACK,
_PEER_RESOLVE_RETRY_INTERVAL,
Expand Down
9 changes: 6 additions & 3 deletions src/kiro_crew/cli_server_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pathlib import Path

from kiro_crew import dep_sync, platform_compat
from kiro_crew._bootstrap import _source_checkout_root
from kiro_crew.beacon import distribution
from kiro_crew.cli_server_peer import (
_CLI_LOOPBACK,
Expand Down Expand Up @@ -250,7 +251,9 @@ def _update(force: bool = False) -> None:
sys.exit(1)
return

proj = os.environ.get("KIROCREW_PROJECT_DIR", "")
# Run outside the clone with no saved project dir, a source install has no
# KIROCREW_PROJECT_DIR; the checkout its code loads from is still the one to update.
proj = os.environ.get("KIROCREW_PROJECT_DIR", "") or str(_source_checkout_root() or "")
# Dispatch on the shared derivation, not on the git probe alone. The probe
# answers "is this a working tree", which is NOT the same question as "who
# owns updating this install": a container or a desktop bundle pointed at a
Expand Down Expand Up @@ -836,8 +839,8 @@ def _refresh_agent_config(proj: str) -> None:
def _update_wheel(layout) -> None:
"""Update a wheel/cli.sh install by checking the release feed and re-running the installer.

This is the path taken when KIROCREW_PROJECT_DIR is unset or has no .git —
the standard state for ``curl | sh`` installs where the venv at
This is the path taken when ``derive_capability`` hands the update to Kiro Crew's
own installer — the standard state for ``curl | sh`` installs where the venv at
``~/.kiro/crew-venv`` has no source tree.
"""

Expand Down
3 changes: 3 additions & 0 deletions test/test_cli_server_more_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,8 @@ class TestUpdateWheelDispatch:

def test_layout_is_built_from_the_distribution(self, monkeypatch, capsys) -> None:
monkeypatch.delenv("KIROCREW_PROJECT_DIR", raising=False)
# The suite runs from a checkout, which `_update` would update by git.
monkeypatch.setattr(cli_server, "_source_checkout_root", lambda: None)
# Both bindings: the capability derives WHO owns the update from the
# stamp, and cli_server names the layout kind from its own import.
monkeypatch.setattr("kiro_crew.platform.update_capability.distribution", lambda: "wheel")
Expand All @@ -915,6 +917,7 @@ def test_layout_is_built_from_the_distribution(self, monkeypatch, capsys) -> Non

def test_unknown_distribution_defaults_to_wheel(self, monkeypatch) -> None:
monkeypatch.delenv("KIROCREW_PROJECT_DIR", raising=False)
monkeypatch.setattr(cli_server, "_source_checkout_root", lambda: None)
monkeypatch.setattr("kiro_crew.platform.update_capability.distribution", lambda: "")
monkeypatch.setattr("kiro_crew.cli_server.distribution", lambda: "")
seen: list[InstallLayout] = []
Expand Down
49 changes: 49 additions & 0 deletions test/test_update_wheel_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,55 @@ def fake_run(args, **kwargs):
git_calls = [c for c in calls if c[0] == "git"]
assert any("rev-parse" in c for c in git_calls)

def test_a_source_checkout_with_no_project_dir_takes_the_git_path(
self, monkeypatch, tmp_path
) -> None:
"""Run outside its clone with no saved project dir, a checkout still updates by git.

With KIROCREW_PROJECT_DIR unset, the checkout the package loads from is the
install root, so the update fetches there instead of checking the release feed.
"""
proj = tmp_path / "project"
proj.mkdir()
_init_repo(proj)
monkeypatch.delenv("KIROCREW_PROJECT_DIR", raising=False)

import kiro_crew.cli_server as cs

# raising=False: without the fallback the test still reaches its assertion.
monkeypatch.setattr(cs, "_source_checkout_root", lambda: proj, raising=False)
monkeypatch.setattr(
"kiro_crew.platform.update_capability.running_from_checkout",
lambda root, **kw: root == str(proj),
)

def _no_wheel(_layout): # pragma: no cover - must not be called
raise AssertionError("a source checkout must not take the release-feed path")

monkeypatch.setattr(cs, "_update_wheel", _no_wheel)
calls: list[tuple[list[str], object]] = []

def fake_run(args, **kwargs):
calls.append((args, kwargs.get("cwd")))
result = MagicMock()
result.returncode = 0
result.stdout = f"{proj}\n" if "--show-toplevel" in args else "main\n"
return result

monkeypatch.setattr("subprocess.run", fake_run)
monkeypatch.setattr(
"kiro_crew.platform.update_governance.resolve_remote_url", lambda *a, **k: ""
)
monkeypatch.setattr(
"kiro_crew.platform.update_governance.update_blocked_reason", lambda *a: ""
)
monkeypatch.setattr(
"kiro_crew.platform.update_governance.repo_exec_config_reason", lambda proj, **_k: ""
)

cs._update()
assert any(args[:2] == ["git", "fetch"] and cwd == str(proj) for args, cwd in calls)


class TestUpdateDivergenceGuard:
"""The git update path refuses a hard reset on a DIVERGED checkout.
Expand Down
Loading