2121 validate_order_intent ,
2222)
2323from tradingcodex_service .mcp_runtime import static_mcp_tools
24+ from tradingcodex_service .version import TRADINGCODEX_VERSION
2425
2526
2627ROOT = Path (__file__ ).resolve ().parents [1 ]
@@ -72,6 +73,7 @@ def test_template_copy_skips_python_bytecode_cache(tmp_path: Path) -> None:
7273def test_python_generator_creates_workspace_contract (tmp_path : Path ) -> None :
7374 workspace = make_workspace (tmp_path )
7475 assert (workspace / "pyproject.toml" ).exists ()
76+ assert f'version = "{ TRADINGCODEX_VERSION } "' in (workspace / "pyproject.toml" ).read_text (encoding = "utf-8" )
7577 assert not (workspace / "package.json" ).exists ()
7678 assert (workspace / "tcx" ).exists ()
7779 assert not (workspace / "tradingcodex" ).exists ()
@@ -101,13 +103,32 @@ def test_python_generator_creates_workspace_contract(tmp_path: Path) -> None:
101103 assert "head-manager MCP execution submit excluded" in doctor
102104 assert "execution-operator MCP execution allowlist configured" in doctor
103105 assert "risk-manager MCP approval allowlist configured" in doctor
106+ hooks = json .loads ((workspace / ".codex" / "hooks.json" ).read_text (encoding = "utf-8" ))["hooks" ]
107+ expected_hook_events = {
108+ "SessionStart" ,
109+ "PreToolUse" ,
110+ "PermissionRequest" ,
111+ "PostToolUse" ,
112+ "UserPromptSubmit" ,
113+ "SubagentStart" ,
114+ "SubagentStop" ,
115+ "Stop" ,
116+ }
117+ assert set (hooks ) == expected_hook_events
118+ assert "matcher" not in hooks ["UserPromptSubmit" ][0 ]
119+ assert "matcher" not in hooks ["Stop" ][0 ]
120+ assert hooks ["PreToolUse" ][0 ]["matcher" ] == "Bash|mcp__.*"
121+ assert hooks ["SubagentStart" ][0 ]["matcher" ]
104122 service_usage = run (["./tcx" , "service" , "nope" ], workspace , expect_ok = False )
105123 assert "Usage: tcx service runserver [addrport] [django runserver args]" in service_usage .stderr
106124 agent_files = sorted ((workspace / ".codex" / "agents" ).glob ("*.toml" ))
107125 assert len (agent_files ) == 9
108126 actual_mcp_tools = {tool ["name" ] for tool in static_mcp_tools ()}
109127 stale_mcp_tool_names = {"evaluate_policy" , "get_positions_snapshot" , "write_audit_event" }
110128 root_config = tomllib .loads ((workspace / ".codex" / "config.toml" ).read_text (encoding = "utf-8" ))
129+ assert root_config ["default_permissions" ] == "tradingcodex"
130+ assert root_config ["permissions" ]["tradingcodex" ]["extends" ] == ":workspace"
131+ assert root_config ["permissions" ]["tradingcodex" ]["network" ]["enabled" ] is False
111132 root_mcp = root_config ["mcp_servers" ]["tradingcodex" ]
112133 assert root_mcp ["command" ] == "uvx"
113134 assert root_mcp ["args" ] == ["--python" , "3.14" , "--from" , "tradingcodex" , "tcx" , "mcp" , "stdio" ]
@@ -124,9 +145,12 @@ def test_python_generator_creates_workspace_contract(tmp_path: Path) -> None:
124145 assert "cancel_approved_order" not in root_mcp ["enabled_tools" ]
125146 for agent_file in agent_files :
126147 agent_config = agent_file .read_text (encoding = "utf-8" )
148+ agent_toml = tomllib .loads (agent_config )
149+ assert agent_toml ["name" ] == agent_file .stem
150+ assert agent_toml ["description" ]
151+ assert agent_toml ["developer_instructions" ]
127152 assert 'model = "gpt-5.5"' in agent_config
128153 assert 'model_reasoning_effort = "high"' in agent_config
129- agent_toml = tomllib .loads (agent_config )
130154 agent_mcp = agent_toml ["mcp_servers" ]["tradingcodex" ]
131155 assert agent_mcp ["command" ] == "uvx"
132156 assert agent_mcp ["args" ] == ["--python" , "3.14" , "--from" , "tradingcodex" , "tcx" , "mcp" , "stdio" ]
@@ -189,7 +213,7 @@ def test_init_current_directory_and_overwrite_language(tmp_path: Path) -> None:
189213
190214 assert f"TradingCodex workspace created: { workspace .resolve ()} " in result .stdout
191215 assert (workspace / "tcx" ).exists ()
192- assert json .loads ((workspace / ".tradingcodex" / "generated" / "module-lock.json" ).read_text (encoding = "utf-8" ))["tradingcodex_version" ] == "0.1.0a4"
216+ assert json .loads ((workspace / ".tradingcodex" / "generated" / "module-lock.json" ).read_text (encoding = "utf-8" ))["tradingcodex_version" ] == TRADINGCODEX_VERSION
193217
194218 repeated = run ([sys .executable , "-m" , "tradingcodex_cli" , "init" , "." ], workspace , expect_ok = False , env_extra = env_extra )
195219 assert "--overwrite" in repeated .stderr
0 commit comments