CtrlK
BlogDocsLog inGet started
Tessl Logo

jbaruch/coding-policy

General-purpose coding policy for Baruch's AI agents

73

Quality

91%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Low

Low-risk findings worth noting

Overview
Quality
Evals
Security
Files

test_prune_result.pyskills/herdr-foreman/tests/

"""Shape checks shared by every reader of the two prune scripts' results."""
import sys
import unittest
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from foreman.prune_result import prune_schema_error, remote_schema_error


def prune_doc(**over):
    doc = {"worktrees_removed": [], "worktrees_kept": [], "branches_deleted": [], "branches_kept": [], "failed": []}
    doc.update(over)
    return doc


def remote_doc(**over):
    doc = {"deleted": [], "questionable": [], "kept": [], "failed": [], "could_not_check": None, "default_branch": "main"}
    doc.update(over)
    return doc


class PruneResultTest(unittest.TestCase):
    def test_whole_prune_result_passes(self):
        kept = [{"path": "/w/a", "reason": "dirty", "age_hours": 30, "dirty_files": 2, "command": "git -C /w/a status"},
                {"path": "/w/b", "reason": "locked"}]
        branches = [{"branch": "feat/x", "reason": "unpushed", "unpushed_commits": 1, "age_hours": 40, "command": "git push"}]
        self.assertIsNone(prune_schema_error(prune_doc(worktrees_kept=kept, branches_kept=branches,
                                                       failed=[{"target": "/w/c", "error": "busy"}])))

    def test_malformed_prune_results_are_named(self):
        cases = {
            "not a JSON object": [],
            "no failed list": prune_doc(failed=None),
            "a malformed worktrees_removed entry": prune_doc(worktrees_removed=[None]),
            "a malformed branches_deleted entry": prune_doc(branches_deleted=[{}]),
            "a malformed worktrees_kept entry": prune_doc(worktrees_kept=[None]),
            "a malformed dirty worktree entry": prune_doc(worktrees_kept=[{"path": "/w/a", "reason": "dirty"}]),
            "a malformed branches_kept entry": prune_doc(branches_kept=[{"reason": "unpushed"}]),
            "a malformed unpushed branch entry": prune_doc(branches_kept=[{"branch": "b", "reason": "unpushed"}]),
            "a malformed failed entry": prune_doc(failed=[{"target": "/w/a"}]),
        }
        for why, doc in cases.items():
            with self.subTest(why=why):
                self.assertEqual(prune_schema_error(doc), why)

    def test_remote_result(self):
        self.assertIsNone(remote_schema_error(remote_doc()))
        self.assertEqual(remote_schema_error(remote_doc(default_branch=None)), "no default_branch")
        self.assertEqual(remote_schema_error(remote_doc(questionable=[{"branch": "b"}])), "a malformed questionable entry")
        self.assertEqual(remote_schema_error(remote_doc(failed=[None])), "a malformed failed entry")
        self.assertEqual(remote_schema_error(remote_doc(deleted=[None])), "a malformed deleted entry")
        self.assertEqual(remote_schema_error(remote_doc(kept=[{}])), "a malformed kept entry")
        self.assertEqual(remote_schema_error({"deleted": []}), "no questionable list")


if __name__ == "__main__":
    unittest.main()

skills

herdr-foreman

tests

__init__.py

fakes.py

test_assign.py

test_attention.py

test_billing.py

test_bounded_run.sh

test_capabilities.py

test_capability_routing.py

test_chronology.py

test_churn.py

test_classify.sh

test_claude_native.py

test_cli.py

test_compose_briefs.sh

test_composer.py

test_composition.py

test_config.py

test_continuity_cli.py

test_cost_report.py

test_diagnostics.py

test_engagement.py

test_entrypoints.py

test_foreman_launcher.sh

test_foreman_queue.py

test_foreman_reset.py

test_foreman_seat.py

test_foreman_tier_check.py

test_freeze.py

test_herdr.py

test_historical.py

test_home.py

test_label_workspaces.sh

test_launch.py

test_legacy_recovery.py

test_load_set.py

test_measure.py

test_members.py

test_memory.py

test_oracle.py

test_parsers.py

test_partition.py

test_planner.py

test_probe.py

test_provision_worktree.sh

test_prune_remote_branches.sh

test_prune_report_caches.py

test_prune_result.py

test_prune_worktrees.sh

test_recovery_cli.py

test_recovery.py

test_renderable.py

test_report_contract.py

test_report_delivery.py

test_report_gates.py

test_report_verdict.py

test_resolve_gates.sh

test_resolve_policy_paths.py

test_restoration.py

test_retrospective_runtime.py

test_retrospective.py

test_review_package.py

test_role_clear.py

test_roster.sh

test_round_preflight.sh

test_runnable.py

test_scoring.py

test_script_dir_newline.sh

test_seat_holds.py

test_selection.py

test_skill_invocations.sh

test_slice_scope_parity.py

test_specialist_cli.py

test_specialist_delivery.py

test_specialist_recovery.py

test_specialist_retention.py

test_stale_grok_delivery.py

test_start_judge_worker.py

test_state.py

test_supervision_cli.py

test_supervision_diagnostics.py

test_supervision_gate.py

test_supervision_replay.py

test_supervision.py

test_sweep_worktrees.sh

test_tier_integration.py

test_tiers.py

test_triggers.py

test_typesafe_client.py

test_verdict_gates.py

test_verify_authority.sh

test_wait_report.sh

tier_fixture.py

bounded-run.sh

compose-briefs.sh

config.example.json

foreman-tier-check.py

foreman.sh

label-workspaces.sh

provision-worktree.sh

prune-remote-branches.sh

prune-report-caches.py

prune-worktrees.sh

resolve-gates.sh

resolve-policy-paths.sh

review-package.sh

roster.sh

round-preflight.sh

SKILL.md

start-judge-worker.sh

state-schema.md

sweep-worktrees.sh

verify-authority.sh

wait-report.sh

README.md

tile.json