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

"""Billing attribution requires observed movement, not a model-name guess."""

import copy
import sys
import unittest
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from foreman.billing import billing_window, effective_multiplier, tier_billing


def measured_tier():
    return {
        "model": "gpt-5.3-codex-spark", "effort": "low", "multiplier": 0.5,
        "billing_evidence": {
            "schema_version": 1, "isolated": True, "model": "gpt-5.3-codex-spark",
            "effort": "low", "cli_version": "fixture-cli-1", "prompt_hash": "a" * 64,
            "measured_at": "2026-01-02T03:00:00Z",
            "before": {
                "spark": {"remaining_pct": 90, "reset_at": "2026-01-03T00:00:00Z"},
                "weekly": {"remaining_pct": 80, "reset_at": "2026-01-08T00:00:00Z"},
            },
            "after": {
                "spark": {"remaining_pct": 89, "reset_at": "2026-01-03T00:00:00Z"},
                "weekly": {"remaining_pct": 80, "reset_at": "2026-01-08T00:00:00Z"},
            },
        },
    }


class BillingTest(unittest.TestCase):
    def test_spark_is_unknown_without_measurement(self):
        tier = {"model": "gpt-5.3-codex-spark", "effort": "low", "multiplier": 0.1}
        self.assertEqual(billing_window(tier), "unknown")
        self.assertEqual(effective_multiplier(tier), 1.0)
        self.assertEqual(tier_billing({"mechanical": tier})["mechanical"]["window"], "unknown")

    def test_isolated_spark_movement_names_the_window(self):
        tier = measured_tier()
        self.assertEqual(billing_window(tier), "spark")
        self.assertEqual(effective_multiplier(tier), 0.5)

    def test_claude_movement_is_in_the_shared_weekly(self):
        tier = measured_tier()
        tier["model"] = tier["billing_evidence"]["model"] = "sonnet-5"
        evidence = tier["billing_evidence"]
        evidence["after"]["spark"]["remaining_pct"] = 90
        evidence["after"]["weekly"]["remaining_pct"] = 79
        self.assertEqual(billing_window(tier), "weekly")

    def test_ambiguous_reset_incomplete_or_unbound_evidence_is_unknown(self):
        original = measured_tier()
        variants = []
        for key, value in (("isolated", False), ("model", "different"), ("effort", "high"),
                           ("cli_version", ""), ("schema_version", 2)):
            variant = copy.deepcopy(original)
            variant["billing_evidence"][key] = value
            variants.append(variant)
        for value in (90, 91, True, float("nan"), -1):
            variant = copy.deepcopy(original)
            variant["billing_evidence"]["after"]["spark"]["remaining_pct"] = value
            variants.append(variant)
        variant = copy.deepcopy(original)
        variant["billing_evidence"]["after"]["weekly"]["remaining_pct"] = 79
        variants.append(variant)
        variant = copy.deepcopy(original)
        variant["billing_evidence"]["after"]["spark"]["reset_at"] = "changed"
        variants.append(variant)
        variant = copy.deepcopy(original)
        del variant["billing_evidence"]["after"]["weekly"]
        variants.append(variant)
        for variant in variants:
            with self.subTest(variant=variant):
                self.assertEqual(billing_window(variant), "unknown")


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