from __future__ import annotations import json from agents.crypto_venture import CryptoVentureService from control_plane.ventures.models import CompanyProposalStatus, CryptoJurisdictionPolicy, TokenNecessityClassification, TokenRedTeamFlag, VentureCohortMember, VentureTrack from graph.bootstrap import champion_crypto_venture_cohort_graph_v1 from graph.crypto_venture_cohort import crypto_venture_cohort_registry from graph.langgraph_runtime import LangGraphRuntime from graph.models import GraphRun, GraphRunStatus from model_router.router import ModelProvider, ModelRequestContract, ModelResponseContract, ModelRouter class SolCryptoReviewProvider(ModelProvider): provider_name = "sol-test" def complete(self, request: ModelRequestContract) -> ModelResponseContract: prompt = request.prompt if "Counterfactual token necessity" in prompt: payload = {"classification": "TOKEN_STRONGLY_JUSTIFIED", "score": 78, "rationale": "Provider staking and slashing materially degrade with database credits.", "fiat_or_database_substitution": "Stablecoin can pay fees but cannot replace bonded slashing and public reputation."} elif "Independent Token Red Team" in prompt: payload = {"flags": ["BOOTSTRAP_PROBLEM"], "severity": "MEDIUM", "critique": "Provider supply bootstrap remains the main risk."} elif "Final Crypto IC" in prompt: payload = {"score_adjustment": 3, "decision": "PROTOCOL_VALIDATE", "rationale": "Token loop is plausible but needs testnet evidence."} else: payload = {} return ModelResponseContract("sol", json.dumps(payload), {}) def health(self) -> str: return "AVAILABLE" def service(router: ModelRouter | None = None) -> CryptoVentureService: return CryptoVentureService(router, web_research_available=False, generation_model_hint="qwen", research_model_hint="qwen", final_ic_model_hint="sol") def test_crypto_track_and_token_gate_remove_weak_then_regenerate() -> None: svc = service() cohort = svc.prepare_cohort(size=2, concurrency=1) weak = svc._create_proposal( cohort.mandate, {"name": "Community Points SaaS", "product_thesis": "A normal SaaS dashboard.", "protocol_thesis": "A private database tracks points.", "token_thesis": "Community marketing token.", "token_utility": ["community"], "token_demand_loop": ["more users equals more token demand"]}, "test", "OPEN_CRYPTO_CATEGORY", ) VentureCohortMember.objects.create(cohort=cohort, proposal=weak) svc.token_necessity_gate(cohort) svc.regenerate_rejected_slots(cohort) weak.refresh_from_db() assert weak.status == CompanyProposalStatus.REJECTED assert weak.metadata["routed_to_saas"] is True assert cohort.members.count() == 2 assert all(member.proposal.token_utility_assessment.classification in {TokenNecessityClassification.TOKEN_ESSENTIAL, TokenNecessityClassification.TOKEN_STRONGLY_JUSTIFIED} for member in cohort.members.select_related("proposal")) def test_sol_counterfactual_red_team_and_final_ic_are_used() -> None: svc = service(ModelRouter({"sol": SolCryptoReviewProvider()})) cohort = svc.prepare_cohort(size=1, concurrency=1) proposal = svc._create_proposal(cohort.mandate, svc._fallback_payload(0, "PROOF_ATTESTATION_MARKETS"), "test", "PROOF_ATTESTATION_MARKETS") VentureCohortMember.objects.create(cohort=cohort, proposal=proposal) token = svc.assess_token_necessity(proposal) red = svc.red_team_proposal(proposal) svc.tokenomics_simulation(cohort) review = svc.portfolio_crypto_ic(cohort) assert token.classification == TokenNecessityClassification.TOKEN_STRONGLY_JUSTIFIED assert token.metadata["sol_counterfactual_review"] assert TokenRedTeamFlag.BOOTSTRAP_PROBLEM in red.flags assert review.rankings[0]["sol_final_ic_review"]["score_adjustment"] == 3 def test_regulatory_negation_does_not_treat_disabled_sale_as_issuance_risk() -> None: svc = service() cohort = svc.prepare_cohort(size=1, concurrency=1) proposal = svc._create_proposal(cohort.mandate, svc._fallback_payload(0, "AGENT_TO_AGENT_PAYMENTS"), "test", "AGENT_TO_AGENT_PAYMENTS") policy = svc.regulatory_policy(proposal) assert policy.regulatory_manageability_score == 72 assert policy.metadata["TOKEN_SALE_DISABLED"] is True assert CryptoJurisdictionPolicy.objects.get(proposal=proposal).legal_review_required is True def test_tokenomics_simulation_is_proposal_specific() -> None: svc = service() cohort = svc.prepare_cohort(size=1, concurrency=1) low = svc._create_proposal(cohort.mandate, {**svc._fallback_payload(0, "AGENT_TO_AGENT_PAYMENTS"), "confidence": 0.35}, "test", "AGENT_TO_AGENT_PAYMENTS") high = svc._create_proposal(cohort.mandate, {**svc._fallback_payload(1, "DECENTRALIZED_AI_COMPUTE"), "confidence": 0.9}, "test", "DECENTRALIZED_AI_COMPUTE") low_sim = svc.simulate_tokenomics(low) high_sim = svc.simulate_tokenomics(high) assert low_sim.scenarios["EXPECTED"]["users"] != high_sim.scenarios["EXPECTED"]["users"] assert low_sim.scenarios["EXPECTED"]["token_demand"] != high_sim.scenarios["EXPECTED"]["token_demand"] def test_crypto_cohort_graph_real_gates_and_report() -> None: svc = service() version = champion_crypto_venture_cohort_graph_v1() graph_run = GraphRun.objects.create(execution_graph_version=version, current_node=version.graph_spec["entry"]) LangGraphRuntime(crypto_venture_cohort_registry(svc, cohort_size=3, concurrency=1)).run_until_terminal_or_paused(graph_run) graph_run.refresh_from_db() cohort = graph_run.venture_cohorts.get() report = cohort.mandate.artifacts.get(artifact_type="CRYPTO_VENTURE_COHORT_REPORT") assert graph_run.status == GraphRunStatus.COMPLETE assert cohort.metadata["venture_track"] == VentureTrack.CRYPTO_PROTOCOL assert cohort.members.count() == 3 assert cohort.metrics["protocol_security_gate_passed"] >= 1 assert len(report.content["ranking"]) == 3 assert len(report.content["top_3"]) <= 3