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_chronology.pyskills/herdr-foreman/tests/

"""Event ordering preserves audit identity and refuses uncertain chronology."""

import os
import sys

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if ROOT not in sys.path:
    sys.path.insert(0, ROOT)

import copy
import unittest

from foreman.chronology import assignment_after, latest_assignment
from foreman.errors import UsageError


class ChronologyTests(unittest.TestCase):
    def row(self, at, **extra):
        return {"at": at, "agent": "worker", "task": "task", "role": "developer", "status": "applied", **extra}

    def test_event_time_and_timezone_choose_original_row_without_mutation(self):
        history = [self.row("2026-02-03T10:00:00Z"), self.row("2026-02-03T10:30:00+01:00")]
        original = copy.deepcopy(history)
        latest = latest_assignment(history, agent="worker")
        self.assertIsNotNone(latest)
        assert latest is not None
        self.assertEqual(latest[0], 0)
        self.assertIs(latest[1], history[0])
        self.assertEqual(history, original)
        self.assertTrue(assignment_after(history, 0, 1))
        self.assertFalse(assignment_after(history, 1, 0))

    def test_filters_exclude_unrelated_unknown_chronology(self):
        history = [self.row("2026-02-03T10:00:00Z"), self.row(None, task="other", agent="other")]
        self.assertEqual(latest_assignment(history, task="task", agent="worker", role="developer", status="applied"), (0, history[0]))
        self.assertIsNone(latest_assignment(history, role="judge"))
        self.assertIsNone(latest_assignment([]))

    def test_missing_invalid_naive_or_tied_latest_chronology_refuses(self):
        for at in (None, "", "invalid", "2026-02-03T10:00:00", "2026-02-03T11:00:00+01:00"):
            history = [self.row("2026-02-03T10:00:00Z"), self.row(at)]
            with self.subTest(at=at), self.assertRaises(UsageError):
                latest_assignment(history)
        with self.assertRaisesRegex(UsageError, "tied"):
            assignment_after([self.row("2026-02-03T10:00:00Z")] * 2, 1, 0)

    def test_older_ties_do_not_obscure_a_proven_latest_event(self):
        history = [self.row("2026-02-03T09:00:00Z"), self.row("2026-02-03T09:00:00Z"), self.row("2026-02-03T10:00:00Z")]
        self.assertEqual(latest_assignment(history), (2, history[2]))

    def test_before_selects_event_predecessor_including_later_append(self):
        history = [self.row("2026-02-03T10:00:00Z", role="release"), self.row("2026-02-03T09:00:00Z"), self.row("2026-02-03T11:00:00Z")]
        self.assertEqual(latest_assignment(history, role="developer", before=0), (1, history[1]))
        history.append(self.row("2026-02-03T10:00:00Z"))
        with self.assertRaisesRegex(UsageError, "tied"):
            latest_assignment(history, role="developer", before=0)


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