CtrlK
BlogDocsLog inGet started
Tessl Logo

jbaruch/coding-policy

General-purpose coding policy for Baruch's AI agents

74

Quality

93%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Medium

Suggest reviewing before use

Overview
Quality
Evals
Security
Files

test_resolve_policy_paths.pyskills/herdr-foreman/tests/

"""Public resolver outcomes for installed policy artifacts; no user HOME edits."""

import json
import os
from pathlib import Path
import subprocess
import tempfile
import unittest


SCRIPT = Path(__file__).resolve().parents[1] / "resolve-policy-paths.sh"
RELEASE = Path("plugins/jbaruch/coding-policy/skills/release/SKILL.md")
TEAM = Path("plugins/jbaruch/coding-policy/skills/herdr-foreman/references/team-operation.md")


class ResolvePolicyPaths(unittest.TestCase):
    def setUp(self):
        self.temp = tempfile.TemporaryDirectory()
        self.addCleanup(self.temp.cleanup)
        self.root = Path(self.temp.name).resolve()
        self.project = self.root / "project with spaces"
        self.project.mkdir()
        self.local = self.project / ".tessl"
        self.global_root = self.root / "global with spaces"

    def artifact(self, root, relative, content="policy fixture\n"):
        path = root / relative
        path.parent.mkdir(parents=True, exist_ok=True)
        path.write_text(content)
        return str(path)

    def invoke(self, *args, env=None):
        return subprocess.run(
            ["/bin/bash", str(SCRIPT), *(args or (str(self.project), str(self.global_root)))],
            text=True, capture_output=True, check=False, env=env,
        )

    def test_local_precedes_global_and_spaces_survive(self):
        expected = {"POLICY_INDEX": self.artifact(self.local, Path("RULES.md")),
                    "RELEASE_SKILL": self.artifact(self.local, RELEASE),
                    "TEAM_OPERATION": self.artifact(self.local, TEAM)}
        self.artifact(self.global_root, Path("RULES.md"))
        self.artifact(self.global_root, RELEASE)
        self.artifact(self.global_root, TEAM)
        result = self.invoke()
        self.assertEqual(result.returncode, 0, result.stderr)
        self.assertEqual(json.loads(result.stdout), expected)

    def test_global_only_install(self):
        expected = {"POLICY_INDEX": self.artifact(self.global_root, Path("RULES.md")),
                    "RELEASE_SKILL": self.artifact(self.global_root, RELEASE),
                    "TEAM_OPERATION": self.artifact(self.global_root, TEAM)}
        result = self.invoke()
        self.assertEqual(result.returncode, 0, result.stderr)
        self.assertEqual(json.loads(result.stdout), expected)

    def test_each_artifact_selects_its_own_available_root(self):
        expected = {"POLICY_INDEX": self.artifact(self.local, Path("RULES.md")),
                    "RELEASE_SKILL": self.artifact(self.global_root, RELEASE),
                    "TEAM_OPERATION": self.artifact(self.local, TEAM)}
        result = self.invoke()
        self.assertEqual(result.returncode, 0, result.stderr)
        self.assertEqual(json.loads(result.stdout), expected)

    def test_missing_release_emits_no_partial_result(self):
        self.artifact(self.local, Path("RULES.md"))
        result = self.invoke()
        self.assertEqual(result.returncode, 2)
        self.assertEqual(result.stdout, "")
        self.assertIn("install or repair", result.stderr)
        self.assertIn(str(RELEASE), result.stderr)

    def test_missing_team_operation_emits_no_partial_result(self):
        self.artifact(self.local, Path("RULES.md"))
        self.artifact(self.global_root, RELEASE)
        result = self.invoke()
        self.assertEqual(result.returncode, 2)
        self.assertEqual(result.stdout, "")
        self.assertIn(str(TEAM), result.stderr)

    def test_empty_or_directory_artifacts_cannot_supply_policy(self):
        self.artifact(self.local, Path("RULES.md"), "")
        (self.local / RELEASE).mkdir(parents=True)
        result = self.invoke()
        self.assertEqual(result.returncode, 2)
        self.assertEqual(result.stdout, "")

    def test_invalid_roots_are_actionable(self):
        for args in [("relative", str(self.global_root)),
                     (str(self.project), "relative"),
                     (str(self.root / "absent"), str(self.global_root)),
                     (str(self.project), str(self.global_root) + "\n")]:
            with self.subTest(args=args):
                result = self.invoke(*args)
                self.assertEqual(result.returncode, 1)
                self.assertEqual(result.stdout, "")
                self.assertIn("absolute", result.stderr)

    def test_missing_jq_is_a_precondition_failure(self):
        empty_bin = self.root / "empty-bin"
        empty_bin.mkdir()
        result = self.invoke(env={**os.environ, "PATH": str(empty_bin)})
        self.assertEqual(result.returncode, 1)
        self.assertEqual(result.stdout, "")
        self.assertIn("install jq", result.stderr)


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_lifecycle.py

test_load_set.py

test_measure.py

test_members.py

test_memory.py

test_minimum_adequate.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_reset_input_hook.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_successors.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