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

"""Specialist plans retain their original report-recovery fingerprint."""

import copy
import json
from pathlib import Path
import sys
import unittest

ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
    sys.path.insert(0, str(ROOT))

from foreman import recovery, report_delivery, supervision
from foreman.assign import assignment_text
from foreman.errors import UsageError
from tests import test_stale_grok_delivery as fixture
from tests.test_report_delivery import AT, SESSION, encode


class SpecialistDeliveryTests(unittest.TestCase):
    def setUp(self):
        self.case = fixture.StaleGrokDeliveryTests()
        self.case.setUp()
        self.addCleanup(self.case.doCleanups)

    def prepare(self, role, requirements):
        case = self.case
        for row in (case.assignment, case.dispatch, case.dispatch['result']):
            row['role'] = role
            if requirements is not None:
                row['requirements'] = requirements
            if role == 'reviewer':
                row['reviewer_scope'] = 'verification'
        case.dispatch['schema_version'] = case.dispatch['result']['schema_version'] = 2
        case.prompt = assignment_text(role, case.dispatch['common'], case.dispatch['brief'])
        case.rows[2]['params']['update']['content']['text'] = case.prompt
        Path(case.data['source']).write_text(encode(case.rows))
        plan = {'schema_version': 5, 'assignments': {role: 'worker'}}
        options = {'task': case.dispatch['task'], 'fix_round': None, 'plan': None,
                   'work': None, 'rounds': {}, 'retain_context': False, 'no_clear': False}
        if requirements is not None:
            plan['requirements'] = {role: requirements}
            options['requirements'] = plan['requirements']
        Path(case.data['plan']).write_text(json.dumps(plan))
        _, fingerprint = recovery.dispatch_identity(
            case.dispatch['task'], role, 'worker', None,
            {'common': case.dispatch['common'], role: case.dispatch['brief']}, options=options)
        case.dispatch['fingerprint'] = supervision.report_bound_fingerprint(fingerprint, case.data['report'])
        return plan

    def test_bound_consultation_recovers_without_changing_contribution_or_continuity(self):
        requirement = {'specialty': 'ux-product', 'required_capabilities': ['ux'],
                       'independent': False, 'engagement': 'onboarding-ux'}
        self.prepare('advisor', requirement)
        before = copy.deepcopy(self.case.document)
        result = self.case.recover()
        self.assertEqual(result['source_session']['value'], SESSION)
        self.assertFalse(result['grants_review_approval'])
        self.assertIsNone(result['native_session_proof'])
        self.assertEqual(self.case.document['assignments'], before['assignments'])
        self.assertEqual(self.case.dispatch, before['recovery']['dispatches'][0])
        recovery.validate_store(self.case.document['recovery'], self.case.document['assignments'])
        self.assertEqual(self.case.recover(), result)

    def test_changed_requirement_or_missing_plan_requirement_cannot_recover(self):
        requirement = {'specialty': 'security', 'required_capabilities': ['security'],
                       'independent': True, 'engagement': 'token-review'}
        original = self.prepare('reviewer', requirement)
        for field, value in (('engagement', 'another-review'), ('independent', False),
                             ('required_capabilities', ['ux']), ('specialty', 'ux')):
            plan = copy.deepcopy(original)
            plan['requirements']['reviewer'][field] = value
            Path(self.case.data['plan']).write_text(json.dumps(plan))
            before = copy.deepcopy(self.case.document)
            with self.subTest(field=field), self.assertRaises(UsageError):
                self.case.recover()
            self.assertEqual(self.case.document, before)
        original.pop('requirements')
        Path(self.case.data['plan']).write_text(json.dumps(original))
        with self.assertRaisesRegex(UsageError, 'grok_dispatch_unbound'):
            self.case.recover()

    def test_scope_only_reviewer_keeps_legacy_fingerprint_inputs(self):
        self.prepare('reviewer', None)
        result = self.case.recover()
        self.assertEqual(result['at'], AT)
        self.assertEqual(self.case.dispatch['reviewer_scope'], 'verification')
        self.assertNotIn('requirements', self.case.dispatch)
        recovery.validate_store(self.case.document['recovery'], self.case.document['assignments'])


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