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.
138 lines
5.8 KiB
Python
138 lines
5.8 KiB
Python
"""Tests for the insightscli build command."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from click.testing import CliRunner
|
|
from insightscli.cli import cli
|
|
from insightscli_commands.build import TRIGGERS, _match_commands
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
class TestTriggerMatching:
|
|
@pytest.mark.parametrize(
|
|
"path,expected_command",
|
|
[
|
|
("frontend/src/queries/schema/index.ts", "build:schema"),
|
|
("frontend/src/queries/schema/schema-general.ts", "build:schema"),
|
|
("insights/schema_migrations/0001_foo.py", "build:schema"),
|
|
("insights/api/serializers.py", "build:openapi"),
|
|
("insights/api/dashboard/views.py", "build:openapi"),
|
|
("insights/scopes.py", "build:openapi"),
|
|
("ee/api/some_view.py", "build:openapi"),
|
|
("products/surveys/backend/api/serializers.py", "build:openapi"),
|
|
("products/surveys/backend/presentation/views.py", "build:openapi"),
|
|
("products/surveys/mcp/tools.yaml", "build:openapi"),
|
|
("services/mcp/definitions/core.yaml", "build:openapi"),
|
|
(".oxfmtrc.json", "build:openapi"),
|
|
(".oxlintrc.json", "build:openapi"),
|
|
("insights/insightsql/grammar/InsightsQLParser.g4", "build:grammar"),
|
|
("insights/taxonomy/taxonomy.py", "build:taxonomy-json"),
|
|
("products/surveys/frontend/src/Survey.tsx", "build:products"),
|
|
("products/insights_ai/skills/foo/SKILL.md", "build:skills"),
|
|
("services/mcp/src/handlers/foo.ts", "build:schema-mcp"),
|
|
],
|
|
)
|
|
def test_file_triggers_expected_command(self, path: str, expected_command: str) -> None:
|
|
assert expected_command in _match_commands({path})
|
|
|
|
@pytest.mark.parametrize(
|
|
"path",
|
|
[
|
|
"README.md",
|
|
"insights/models/team.py",
|
|
"frontend/src/scenes/dashboard/Dashboard.tsx",
|
|
".github/workflows/ci.yml",
|
|
"docker-compose.yml",
|
|
],
|
|
)
|
|
def test_unrelated_file_triggers_nothing(self, path: str) -> None:
|
|
assert _match_commands({path}) == []
|
|
|
|
def test_multiple_files_trigger_multiple_commands(self) -> None:
|
|
changed = {
|
|
"frontend/src/queries/schema/index.ts",
|
|
"insights/api/serializers.py",
|
|
"insights/insightsql/grammar/InsightsQLParser.g4",
|
|
}
|
|
assert set(_match_commands(changed)) == {"build:schema", "build:openapi", "build:grammar"}
|
|
|
|
def test_empty_changeset_triggers_nothing(self) -> None:
|
|
assert _match_commands(set()) == []
|
|
|
|
|
|
class TestBuildCommand:
|
|
def test_list_shows_all_commands(self) -> None:
|
|
result = runner.invoke(cli, ["build", "--list"])
|
|
assert result.exit_code == 0
|
|
for cmd in TRIGGERS:
|
|
assert cmd in result.output
|
|
|
|
@patch("insightscli_commands.build.changed_files")
|
|
def test_no_changes_exits_cleanly(self, mock_changed: MagicMock) -> None:
|
|
mock_changed.return_value = set()
|
|
result = runner.invoke(cli, ["build"])
|
|
assert result.exit_code == 0
|
|
assert "Nothing to rebuild" in result.output
|
|
|
|
@patch("insightscli_commands.build.changed_files")
|
|
def test_unrelated_changes_exits_cleanly(self, mock_changed: MagicMock) -> None:
|
|
mock_changed.return_value = {"README.md", "docs/foo.md"}
|
|
result = runner.invoke(cli, ["build"])
|
|
assert result.exit_code == 0
|
|
assert "don't match any build trigger" in result.output
|
|
|
|
@pytest.mark.parametrize(
|
|
"changed_file,expected_command",
|
|
[
|
|
("frontend/src/queries/schema/index.ts", "build:schema"),
|
|
("insights/taxonomy/foo.py", "build:taxonomy-json"),
|
|
],
|
|
)
|
|
@patch("insightscli_commands.build.subprocess.run")
|
|
@patch("insightscli_commands.build.changed_files")
|
|
def test_smart_mode_runs_single_matching_pipeline(
|
|
self, mock_changed: MagicMock, mock_run: MagicMock, changed_file: str, expected_command: str
|
|
) -> None:
|
|
mock_changed.return_value = {changed_file}
|
|
mock_run.return_value = MagicMock(returncode=0)
|
|
result = runner.invoke(cli, ["build"])
|
|
assert result.exit_code == 0
|
|
mock_run.assert_called_once()
|
|
assert expected_command in mock_run.call_args[0][0]
|
|
|
|
@patch("insightscli_commands.build.subprocess.run")
|
|
def test_force_runs_all(self, mock_run: MagicMock) -> None:
|
|
mock_run.return_value = MagicMock(returncode=0)
|
|
result = runner.invoke(cli, ["build", "--force"])
|
|
assert result.exit_code == 0
|
|
assert mock_run.call_count == len(TRIGGERS)
|
|
|
|
@patch("insightscli_commands.build.subprocess.run")
|
|
@patch("insightscli_commands.build.changed_files")
|
|
def test_dry_run_does_not_execute(self, mock_changed: MagicMock, mock_run: MagicMock) -> None:
|
|
mock_changed.return_value = {"insights/api/views.py"}
|
|
result = runner.invoke(cli, ["build", "--dry-run"])
|
|
assert result.exit_code == 0
|
|
assert "build:openapi" in result.output
|
|
mock_run.assert_not_called()
|
|
|
|
@patch("insightscli_commands.build.subprocess.run")
|
|
def test_force_dry_run_lists_all(self, mock_run: MagicMock) -> None:
|
|
result = runner.invoke(cli, ["build", "--force", "--dry-run"])
|
|
assert result.exit_code == 0
|
|
for cmd in TRIGGERS:
|
|
assert cmd in result.output
|
|
mock_run.assert_not_called()
|
|
|
|
@patch("insightscli_commands.build.subprocess.run")
|
|
def test_continues_on_failure(self, mock_run: MagicMock) -> None:
|
|
mock_run.side_effect = [MagicMock(returncode=1)] + [MagicMock(returncode=0)] * (len(TRIGGERS) - 1)
|
|
result = runner.invoke(cli, ["build", "--force"])
|
|
assert result.exit_code == 1
|
|
assert "failures" in result.output
|
|
assert mock_run.call_count == len(TRIGGERS)
|