mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
95 lines
4.5 KiB
Python
95 lines
4.5 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import click
|
|
from insightscli_commands.change_detection import changed_files, matches_globs
|
|
|
|
|
|
def _completed(stdout: str = "", returncode: int = 0, stderr: str = "") -> MagicMock:
|
|
return MagicMock(stdout=stdout, stderr=stderr, returncode=returncode)
|
|
|
|
|
|
class TestChangedFiles:
|
|
@patch("insightscli_commands.change_detection.subprocess.run")
|
|
def test_combines_branch_diff_and_working_tree(self, mock_run: MagicMock) -> None:
|
|
mock_run.side_effect = [
|
|
_completed(stdout="file_branch.py\0"),
|
|
_completed(stdout=" M file_modified.py\0A file_staged.py\0?? file_untracked.py\0"),
|
|
]
|
|
assert changed_files() == ["file_branch.py", "file_modified.py", "file_staged.py", "file_untracked.py"]
|
|
|
|
@patch("insightscli_commands.change_detection.subprocess.run")
|
|
def test_deduplicates_across_diff_and_working_tree(self, mock_run: MagicMock) -> None:
|
|
mock_run.side_effect = [_completed(stdout="same_file.py\0"), _completed(stdout="M same_file.py\0")]
|
|
assert changed_files() == ["same_file.py"]
|
|
|
|
@patch("insightscli_commands.change_detection.subprocess.run")
|
|
def test_paths_with_spaces_stay_unquoted(self, mock_run: MagicMock) -> None:
|
|
mock_run.side_effect = [
|
|
_completed(stdout="insights/migrations/0067_table copy.py\0"),
|
|
_completed(stdout=" M docs/a b.md\0"),
|
|
]
|
|
assert changed_files() == ["docs/a b.md", "insights/migrations/0067_table copy.py"]
|
|
|
|
@patch("insightscli_commands.change_detection.subprocess.run")
|
|
def test_default_base_falls_back_to_local_master(self, mock_run: MagicMock) -> None:
|
|
mock_run.side_effect = [
|
|
_completed(returncode=128, stderr="fatal: bad revision 'origin/master...HEAD'"),
|
|
_completed(stdout="file_branch.py\0"),
|
|
_completed(stdout=""),
|
|
]
|
|
assert changed_files() == ["file_branch.py"]
|
|
|
|
@patch("insightscli_commands.change_detection.subprocess.run")
|
|
def test_no_base_ref_degrades_to_working_tree_only(self, mock_run: MagicMock) -> None:
|
|
mock_run.side_effect = [
|
|
_completed(returncode=128, stderr="fatal: bad revision"),
|
|
_completed(returncode=128, stderr="fatal: bad revision"),
|
|
_completed(stdout="?? sandbox_edit.py\0"),
|
|
]
|
|
assert changed_files() == ["sandbox_edit.py"]
|
|
|
|
@patch("insightscli_commands.change_detection.subprocess.run")
|
|
def test_explicit_bad_ref_raises_instead_of_reporting_clean(self, mock_run: MagicMock) -> None:
|
|
mock_run.return_value = _completed(returncode=128, stderr="fatal: bad revision 'orgin/master'")
|
|
with pytest.raises(click.UsageError):
|
|
changed_files("orgin/master")
|
|
|
|
@patch("insightscli_commands.change_detection.subprocess.run")
|
|
def test_exclude_worktree_returns_committed_diff_only(self, mock_run: MagicMock) -> None:
|
|
# Pre-push scope: only the committed branch diff is pushed, so untracked/uncommitted
|
|
# work must not leak in. git status is never consulted (a single subprocess call).
|
|
mock_run.side_effect = [_completed(stdout="file_branch.py\0")]
|
|
assert changed_files(include_worktree=False) == ["file_branch.py"]
|
|
assert mock_run.call_count == 1
|
|
|
|
@patch("insightscli_commands.change_detection.subprocess.run")
|
|
def test_status_failure_raises_instead_of_dropping_uncommitted_work(self, mock_run: MagicMock) -> None:
|
|
mock_run.side_effect = [
|
|
_completed(stdout="file_branch.py\0"),
|
|
_completed(returncode=128, stderr="fatal: Unable to create index.lock"),
|
|
]
|
|
with pytest.raises(click.UsageError):
|
|
changed_files()
|
|
|
|
|
|
class TestMatchesGlobs:
|
|
@pytest.mark.parametrize(
|
|
"path,globs,expected",
|
|
[
|
|
("insights/api/insight.py", ["insights/api/*"], True),
|
|
("insights/api/dashboards/dashboard.py", ["insights/api/*"], True),
|
|
("insights/models/team.py", ["insights/api/*"], False),
|
|
("tools/a/b.py", ["*.py"], True),
|
|
("notes.md", ["*.py"], False),
|
|
("insights/migrations/0001_x.py", ["*/migrations/*.py"], True),
|
|
("pnpm-workspace.yaml", ["pnpm-workspace.yaml"], True),
|
|
("patches/[email protected]", ["patches/*"], True),
|
|
("x.py", [], False),
|
|
],
|
|
)
|
|
def test_matches(self, path: str, globs: list[str], expected: bool) -> None:
|
|
assert matches_globs(path, globs) is expected
|