femo-plugin 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FEMO_logo.svg +55 -0
- package/FEMO_logo_slogan.svg +29 -0
- package/README.md +10 -2
- package/_tmp/fallback/driver2.py +176 -0
- package/_tmp/fallback/events.jsonl +108 -0
- package/_tmp/fallback/gateway_ui.py +325 -0
- package/_tmp/fallback/outbox/j1553_human_[/347/234/213/347/211/214]_1.done +1 -0
- package/_tmp/fallback/outbox/r1.done +1 -0
- package/_tmp/fallback/outbox/r2.done +1 -0
- package/_tmp/fallback/outbox/r3.done +1 -0
- package/_tmp/fallback/outbox/r4.done +1 -0
- package/_tmp/fallback/outbox/r5.done +1 -0
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225.femo +3 -2
- package/hostAdapter/dshAdapter/client/client-ui/composer.tsx +112 -9
- package/hostAdapter/dshAdapter/client/client-ui/styles.ts +17 -0
- package/hostAdapter/dshAdapter/client/fa-icons.tsx +3 -0
- package/hostAdapter/dshAdapter/host/engine-events.ts +4 -1
- package/hostAdapter/dshAdapter/host/index.ts +5 -0
- package/hostAdapter/dshAdapter/host/preset-install.ts +59 -0
- package/hostAdapter/dshAdapter/host/projection-input.ts +14 -6
- package/hostAdapter/dshAdapter/lib/client.js +124 -5
- package/hostAdapter/dshAdapter/lib/client.js.map +3 -3
- package/hostAdapter/dshAdapter/lib/index.js +58 -18
- package/hostAdapter/dshAdapter/lib/index.js.map +4 -4
- package/hostAdapter/dshAdapter/package.json +1 -5
- package/hostAdapter/dshAdapter/preset/agent.cordis.yml +220 -0
- package/hostAdapter/dshAdapter/preset/preset.yml +3 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/gateway.port +1 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-a-_40_52a9_624b.jsonl +3 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-a-_40_6211.jsonl +10 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-god.jsonl +11 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-stage.jsonl +11 -0
- package/hostAdapter/zcodeAdapter/.zcode-plugin/plugin.json +23 -0
- package/hostAdapter/zcodeAdapter/README.md +61 -0
- package/hostAdapter/zcodeAdapter/commands/femo.md +9 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/.zcode-plugin/plugin.json +23 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/LICENSE +201 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/README.md +635 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/commands/femo.md +9 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/__init__.py +4 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/chronica.py +156 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/femo-chat.mjs +69 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/femo_debugger.py +1515 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femo_api.py +437 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femo_gen_api.jsx +77 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/ContextExample.py +555 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/MemoryExample.py +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/__init__.py +1 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/getDir/get_dir.py +56 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/getDir//344/275/240/345/217/257/344/273/245/350/256/276/345/256/232/344/273/273/346/204/217/346/226/207/344/273/266/345/244/271/344/270/272/347/224/250/346/210/267/346/225/260/346/215/256/346/226/207/344/273/266/345/244/271.txt +10 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/llmBridge.py +247 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/llmProviders.py +308 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_CLIrenderer.py +198 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_config.py +35 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_errors.py +278 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_interpreter.py +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_normalizer.py +396 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_parser.py +2468 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_runtime.py +3630 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_scope_resolver.py +209 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/__init__.py +1 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/actor_resolver.py +86 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/block_collector.py +441 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/db_utils.py +485 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/femoAsync.py +401 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/host_manifest.py +68 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/job_manager.py +767 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/protocol.py +126 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/save_dialog.py +402 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/task_world.py +544 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/__init__.py +19 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/checkpoint.py +113 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/env.py +686 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/evaluator.py +567 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/join.py +303 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/merge.py +157 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/model.py +245 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/345/211/252/350/247/206/351/242/221/AI/345/211/252/350/247/206/351/242/221.femo +192 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/350/201/212/345/244/251/345/256/244/group-chat.femo +42 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +10 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/LuxFiat/luxfiat.femo +38 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/LuxFiat/wait.py +29 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +222 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/discussion.femo +70 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/goal-mode.femo +23 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//345/270/270/347/224/250/345/267/245/345/205/267python/wait.py +29 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils.py +205 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils2.py +324 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200-/350/255/246/351/225/277/347/211/210.femo +544 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +331 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225/undercover_utils.py +683 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225-/350/217/234/345/270/202/345/234/272/345/261/200.femo +348 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225.femo +393 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/after-tool.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/hooks.json +16 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/lib.mjs +59 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/prompt-state.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/session-start.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/stop-intent.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hostAdapter/dshAdapter/python/dev-bridge-test.py +43 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hostAdapter/dshAdapter/python/femo_bridge.py +533 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/bridge-manager.mjs +192 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/event-router.mjs +258 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/femo-server.mjs +429 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/gateway.mjs +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/projection-writer.mjs +294 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/skills/femo/SKILL.md +93 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/bridge-smoke.mjs +26 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/event-router.test.mjs +157 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/gateway-smoke.mjs +107 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/integration-human.mjs +111 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/main-actor.mjs +107 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/mcp-smoke.mjs +130 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/projection-writer.test.mjs +144 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/zcode.host.manifest.json +5 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist//346/212/225/345/275/261/347/252/227/351/207/215/350/256/276/350/256/241-/350/256/250/350/256/272/347/250/277.md +113 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist//350/257/255/346/263/225/346/226/207/346/241/243.md +1136 -0
- package/hostAdapter/zcodeAdapter/hooks/after-tool.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/hooks.json +16 -0
- package/hostAdapter/zcodeAdapter/hooks/lib.mjs +59 -0
- package/hostAdapter/zcodeAdapter/hooks/prompt-state.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/session-start.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/stop-intent.mjs +3 -0
- package/hostAdapter/zcodeAdapter/mcp/bridge-manager.mjs +192 -0
- package/hostAdapter/zcodeAdapter/mcp/event-router.mjs +258 -0
- package/hostAdapter/zcodeAdapter/mcp/femo-server.mjs +429 -0
- package/hostAdapter/zcodeAdapter/mcp/gateway.mjs +163 -0
- package/hostAdapter/zcodeAdapter/mcp/projection-writer.mjs +294 -0
- package/hostAdapter/zcodeAdapter/skills/femo/SKILL.md +93 -0
- package/hostAdapter/zcodeAdapter/tests/bridge-smoke.mjs +26 -0
- package/hostAdapter/zcodeAdapter/tests/event-router.test.mjs +157 -0
- package/hostAdapter/zcodeAdapter/tests/gateway-smoke.mjs +107 -0
- package/hostAdapter/zcodeAdapter/tests/integration-human.mjs +111 -0
- package/hostAdapter/zcodeAdapter/tests/main-actor.mjs +107 -0
- package/hostAdapter/zcodeAdapter/tests/mcp-smoke.mjs +130 -0
- package/hostAdapter/zcodeAdapter/tests/projection-writer.test.mjs +144 -0
- package/hostAdapter/zcodeAdapter/zcode.host.manifest.json +5 -0
- package/hostAdapter/zcodeAdapter//346/212/225/345/275/261/347/252/227/351/207/215/350/256/276/350/256/241-/350/256/250/350/256/272/347/250/277.md +113 -0
- package/package.json +1 -1
- package/scripts/diag-find-redblue.mjs +38 -0
- package/scripts/diag-god-log.mjs +31 -0
- package/scripts/diag-god-log2.mjs +39 -0
- package/scripts/diag-god-log3.mjs +35 -0
- package/scripts/diag-god-log4.mjs +59 -0
- package/scripts/diag-god-log4b.mjs +39 -0
- package/scripts/diag-redblue-god.mjs +39 -0
- package/scripts/diag-redblue-log.mjs +37 -0
- package/scripts/diag-redblue-span.mjs +41 -0
- package/scripts/diag-stage-1017.mjs +63 -0
- package/scripts/dump_session.py +36 -0
- package/scripts/link-workspace.ps1 +51 -0
- package/scripts/list_souls.py +18 -0
- package/scripts/probe-composer-refresh.mjs +197 -0
- package/scripts/seed_story_souls.py +86 -0
- package/scripts/sync-zcode-dist.ps1 +55 -0
- package/scripts/theme-tokenize/color-extract.txt +288 -0
- package/scripts/theme-tokenize/round1-quoted.ps1 +149 -0
- package/scripts/theme-tokenize/round2-bare.ps1 +138 -0
- package/scripts/theme-tokenize/round3-shape.ps1 +110 -0
- package/tests/_diag_r4_join.femo +32 -0
- package/tests/conftest.py +95 -0
- package/tests/diag-subagent-dir-3081.mjs +101 -0
- package/tests/femoGenerator.test.mjs +3909 -0
- package/tests/femoParser.test.mjs +4813 -0
- package/tests/femogen_notice.test.mjs +109 -0
- package/tests/femoparser_validation.test.mjs +84 -0
- package/tests/main-delivery-queue.test.mjs +329 -0
- package/tests/pre-step-gate.test.mjs +282 -0
- package/tests/read-subagent-model.mjs +24 -0
- package/tests/run-script-tests.py +97 -0
- package/tests/safe-steer.test.mjs +59 -0
- package/tests/strip_comments.test.mjs +164 -0
- package/tests/test_actor_failed.py +92 -0
- package/tests/test_compile_warnings.py +99 -0
- package/tests/test_debug_log_bus.py +108 -0
- package/tests/test_debugger_module_mode.py +141 -0
- package/tests/test_error_buckets.py +117 -0
- package/tests/test_error_dispatcher.py +261 -0
- package/tests/test_exec_ai_retry.py +155 -0
- package/tests/test_exec_human_retry.py +159 -0
- package/tests/test_file_resolve.py +104 -0
- package/tests/test_flow_events.py +311 -0
- package/tests/test_flow_ref_validation.py +92 -0
- package/tests/test_func_dict_fallback.py +39 -0
- package/tests/test_job_lifecycle.py +236 -0
- package/tests/test_job_manager.py +424 -0
- package/tests/test_mind.py +99 -0
- package/tests/test_module_call_args.py +258 -0
- package/tests/test_module_visibility.py +238 -0
- package/tests/test_notice.py +143 -0
- package/tests/test_out_whitelist.py +83 -0
- package/tests/test_par_if_dispatch.py +64 -0
- package/tests/test_par_nested_for.py +78 -0
- package/tests/test_parser.py +494 -0
- package/tests/test_pause.py +102 -0
- package/tests/test_pause_contract.py +135 -0
- package/tests/test_protocol_transcript.py +158 -0
- package/tests/test_scope_self.py +202 -0
- package/tests/test_source_validate.py +113 -0
- package/tests/test_task_world.py +447 -0
- package/tests/test_town_structure.py +70 -0
- package/tests/test_v2_checkpoint.py +115 -0
- package/tests/test_v2_env.py +383 -0
- package/tests/test_v2_evaluator.py +227 -0
- package/tests/test_v2_join.py +315 -0
- package/tests/test_v2_join_wiring.py +429 -0
- package/tests/test_v2_merge.py +167 -0
- package/tests/test_v2_model.py +143 -0
- package/tests/test_v2_resume_e2e.py +472 -0
- package/tests/test_var_decls.py +271 -0
- package/tests/verify-model-functions.mjs +90 -0
- package/tests/verify-subagent-model-3081.mjs +153 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225/node-notice-/346/226/275/345/267/245/346/270/205/345/215/225.md +395 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//344/270/244/344/270/252/345/276/205/350/247/243/345/206/263/347/232/204/351/227/256/351/242/230.MD +66 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//345/201/234/346/255/242/351/223/276/344/277/256/345/244/215-/346/226/275/345/267/245/346/270/205/345/215/225.md +475 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//345/217/230/351/207/217/344/270/216task/347/263/273/347/273/237/351/207/215/346/236/204-/346/226/275/345/267/245/346/270/205/345/215/225-v2.md +847 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//350/277/220/350/241/214/347/212/266/346/200/201/351/223/276/350/267/257/351/207/215/346/236/204-/346/226/275/345/267/245/346/270/205/345/215/225v4.md +654 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//351/224/231/350/257/257/346/263/250/345/205/245/347/273/255/350/201/212-/346/226/275/345/267/245/346/270/205/345/215/225.md +471 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"""剧本级事件流断言:起 bridge 进程跑剧本,校验事件序列与变量结果。
|
|
2
|
+
|
|
3
|
+
全部零 LLM(@assign 逻辑),不烧 token。
|
|
4
|
+
"""
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from conftest import read_script
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def event_types(events):
|
|
13
|
+
return [e["event"] for e in events]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def node_starts(events, name):
|
|
17
|
+
return [e for e in events if e["event"] == "node_start" and e["data"].get("node_name") == name]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestSyntaxScripts:
|
|
21
|
+
"""现有三个语法测试剧本:必须 flow_done 且无 flow_error。"""
|
|
22
|
+
|
|
23
|
+
@pytest.mark.parametrize("fname", [
|
|
24
|
+
"test-if-fork-join.femo",
|
|
25
|
+
"test-for-if.femo",
|
|
26
|
+
"test-par.femo",
|
|
27
|
+
])
|
|
28
|
+
def test_script_runs_clean(self, run_events, fname):
|
|
29
|
+
events = run_events(read_script(fname))
|
|
30
|
+
types = event_types(events)
|
|
31
|
+
assert "flow_error" not in types, \
|
|
32
|
+
f"{fname} 报错: {[e['data'] for e in events if e['event'] == 'flow_error']}"
|
|
33
|
+
assert "flow_done" in types, f"{fname} 未见 flow_done: {types}"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class TestGoblinMini:
|
|
37
|
+
"""goblin-mini:fork + 空 module + for 循环全结构(零 token 复刻)。"""
|
|
38
|
+
|
|
39
|
+
def test_for_loop_executes_all_iterations(self, run_events):
|
|
40
|
+
events = run_events(read_script("goblin-mini.femo"))
|
|
41
|
+
types = event_types(events)
|
|
42
|
+
assert "flow_error" not in types, \
|
|
43
|
+
[e["data"] for e in events if e["event"] == "flow_error"]
|
|
44
|
+
assert "flow_done" in types
|
|
45
|
+
|
|
46
|
+
# for 循环:@hero 展开 4 次(3 ai + 1 human),各自正确走 [L]/[LP]
|
|
47
|
+
l_count = len(node_starts(events, "[L]"))
|
|
48
|
+
lp_count = len(node_starts(events, "[LP]"))
|
|
49
|
+
assert l_count == 3, f"[L] 应执行 3 次(knight/mage/rogue),实际 {l_count}"
|
|
50
|
+
assert lp_count == 1, f"[LP] 应执行 1 次(player),实际 {lp_count}"
|
|
51
|
+
|
|
52
|
+
# count 最终值 = 8(opening/ASK/GO 3 + L 3 + LP 1 + FAREWELL 1)
|
|
53
|
+
assigns = [e["data"]["output"] for e in events if e["event"] == "assign_result"]
|
|
54
|
+
assert assigns[-1]["count"] == 8, f"count 最终值应为 8,实际 {assigns[-1]}"
|
|
55
|
+
|
|
56
|
+
# 流程完整性:fork 分支 [GO] 与 module 都执行过
|
|
57
|
+
assert any(e["event"] == "module_enter" for e in events)
|
|
58
|
+
assert node_starts(events, "[GO]")
|
|
59
|
+
assert node_starts(events, "[FAREWELL]")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class TestForkErrorReporting:
|
|
63
|
+
"""错误必须上报(编译器原则:不静默)。
|
|
64
|
+
|
|
65
|
+
【协议语义迁移(§12.1)】goblin-mini-bad 的错误=编译期(for 循环变量
|
|
66
|
+
@hero 未声明,SyntaxError)。旧协议经 worker except 变 flow_error 事件;
|
|
67
|
+
Job 模型协议下编译错误在 job_start 同步拒绝(compile_error,Job 文件都
|
|
68
|
+
不产生,§7.2)——上报面从事件流迁移到 response,断言面随之迁移,
|
|
69
|
+
"错误必须上报且提到 @hero"的本意不变。"""
|
|
70
|
+
|
|
71
|
+
def test_fork_branch_error_becomes_flow_error(self):
|
|
72
|
+
from test_v2_resume_e2e import BridgeSession
|
|
73
|
+
with BridgeSession() as bs:
|
|
74
|
+
resp = bs.rpc("job_start", {
|
|
75
|
+
"femo": read_script("goblin-mini-bad.femo"),
|
|
76
|
+
"base_dir": os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "femoExamples"),
|
|
77
|
+
"host_ref": "pytest", "script_name": "goblin-mini-bad",
|
|
78
|
+
})
|
|
79
|
+
assert resp.get("ok") is not True, f"编译错误应拒绝 job_start: {resp}"
|
|
80
|
+
text = f"{resp.get('error', '')} {resp.get('detail', '')}"
|
|
81
|
+
assert "@hero" in text, f"错误应提到 @hero: {resp}"
|
|
82
|
+
# 脏 Job 号零残留:编译失败的剧本不产生 Job 档案
|
|
83
|
+
jobs = bs.rpc("list_jobs").get("result", {}).get("jobs", [])
|
|
84
|
+
assert all(j["script_name"] != "goblin-mini-bad" for j in jobs), jobs
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class TestMultiOutEdges:
|
|
88
|
+
"""普通节点多条出边 = fork 并发语义(文档:不写 fork 直接 mermaid 也并行)。"""
|
|
89
|
+
|
|
90
|
+
def test_all_branches_execute(self, run_events):
|
|
91
|
+
script = """meta:
|
|
92
|
+
session = new
|
|
93
|
+
vars:
|
|
94
|
+
count = 0
|
|
95
|
+
action mark_a @assign:
|
|
96
|
+
out: count += 1
|
|
97
|
+
action mark_b @assign:
|
|
98
|
+
out: count += 10
|
|
99
|
+
action mark_c @assign:
|
|
100
|
+
out: count += 100
|
|
101
|
+
mainflow:
|
|
102
|
+
[A]: mark_a
|
|
103
|
+
[B]: mark_b
|
|
104
|
+
[C]: mark_c
|
|
105
|
+
[START] -> [A]
|
|
106
|
+
[A] -> [B]
|
|
107
|
+
[A] -> [C]
|
|
108
|
+
[B] -> [END]
|
|
109
|
+
[C] -> [END]
|
|
110
|
+
"""
|
|
111
|
+
events = run_events(script)
|
|
112
|
+
types = event_types(events)
|
|
113
|
+
assert "flow_error" not in types, [e["data"] for e in events if e["event"] == "flow_error"]
|
|
114
|
+
b_ran = any(e["event"] == "node_start" and e["data"].get("node_name") == "[B]" for e in events)
|
|
115
|
+
c_ran = any(e["event"] == "node_start" and e["data"].get("node_name") == "[C]" for e in events)
|
|
116
|
+
assert b_ran and c_ran, f"两条出边都应执行: B={b_ran} C={c_ran}"
|
|
117
|
+
assigns = [e["data"]["output"] for e in events if e["event"] == "assign_result"]
|
|
118
|
+
# R2 后竞态结构性消失(apply_intent 全程无 await,协作式调度下不可分割;
|
|
119
|
+
# 旧"VarManager 竞态已知限制"注释删除)——断言保持宽松以兼容旧档。
|
|
120
|
+
assert assigns[-1]["count"] in (11, 101), f"并发最终值应为 11 或 101: {assigns}"
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class TestPauseDuringLoop:
|
|
124
|
+
"""pause 在深层 fork 循环嵌套任务链中必须正常工作(Task.cancel 递归栈溢出回归)。"""
|
|
125
|
+
|
|
126
|
+
def test_pause_on_nested_fork_loop(self):
|
|
127
|
+
import subprocess, threading, json, time, os as _os, sys as _sys
|
|
128
|
+
ROOT = _os.path.dirname(_os.path.dirname(_os.path.abspath(__file__)))
|
|
129
|
+
script = """meta:
|
|
130
|
+
session = new
|
|
131
|
+
vars:
|
|
132
|
+
count = 0
|
|
133
|
+
module M:
|
|
134
|
+
action up @assign:
|
|
135
|
+
out: count += 1
|
|
136
|
+
flow:
|
|
137
|
+
[IN] -> [UP]:up -> fork:
|
|
138
|
+
-> if (count < 100000) -> [IN]
|
|
139
|
+
-> if (count >= 100000) -> [OUT]
|
|
140
|
+
mainflow:
|
|
141
|
+
[START] -> [M]:&M -> [END]
|
|
142
|
+
"""
|
|
143
|
+
p = subprocess.Popen(
|
|
144
|
+
[_sys.executable, _os.path.join(ROOT, "hostAdapter", "dshAdapter", "python", "femo_bridge.py"), "--fe4m", ROOT],
|
|
145
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
146
|
+
text=True, encoding="utf-8", errors="replace", bufsize=1,
|
|
147
|
+
)
|
|
148
|
+
events = []
|
|
149
|
+
responses = []
|
|
150
|
+
def drain():
|
|
151
|
+
for line in p.stdout:
|
|
152
|
+
line = line.strip()
|
|
153
|
+
if not line:
|
|
154
|
+
continue
|
|
155
|
+
try:
|
|
156
|
+
obj = json.loads(line)
|
|
157
|
+
except json.JSONDecodeError:
|
|
158
|
+
continue
|
|
159
|
+
if obj.get("type") == "event":
|
|
160
|
+
events.append(obj)
|
|
161
|
+
elif obj.get("type") == "response":
|
|
162
|
+
responses.append(obj)
|
|
163
|
+
t = threading.Thread(target=drain, daemon=True)
|
|
164
|
+
t.start()
|
|
165
|
+
def send(obj):
|
|
166
|
+
p.stdin.write(json.dumps(obj, ensure_ascii=False) + "\n")
|
|
167
|
+
p.stdin.flush()
|
|
168
|
+
send({"id": 1, "cmd": "job_start",
|
|
169
|
+
"args": {"femo": script, "base_dir": _os.path.join(ROOT, "femoExamples"),
|
|
170
|
+
"host_ref": "pytest", "script_name": "pause-deep-nest"}})
|
|
171
|
+
# 等回执到达(同步 parse 需要时间),再取 job_id
|
|
172
|
+
deadline = time.time() + 30
|
|
173
|
+
while time.time() < deadline:
|
|
174
|
+
if any(r.get("id") == 1 for r in responses):
|
|
175
|
+
break
|
|
176
|
+
time.sleep(0.1)
|
|
177
|
+
start_resp = next((r for r in responses if r.get("id") == 1), None)
|
|
178
|
+
job_id = ((start_resp or {}).get("result") or {}).get("job_id")
|
|
179
|
+
assert isinstance(job_id, int), f"job_start 回执缺 job_id: {start_resp}"
|
|
180
|
+
time.sleep(3) # 让循环嵌套跑起来
|
|
181
|
+
send({"id": 2, "cmd": "job_pause", "args": {"job_id": job_id}})
|
|
182
|
+
deadline = time.time() + 15
|
|
183
|
+
while time.time() < deadline:
|
|
184
|
+
if any(r.get("id") == 2 for r in responses):
|
|
185
|
+
break
|
|
186
|
+
time.sleep(0.1)
|
|
187
|
+
pause_resp = next((r for r in responses if r.get("id") == 2), None)
|
|
188
|
+
assert pause_resp is not None, "pause 无响应(Task.cancel 递归栈溢出)"
|
|
189
|
+
assert pause_resp.get("ok") is True, f"pause 失败: {pause_resp}"
|
|
190
|
+
# flow_paused 事件应发出
|
|
191
|
+
assert any(e["event"] == "flow_paused" for e in events), "应收到 flow_paused 事件"
|
|
192
|
+
send({"id": 3, "cmd": "shutdown", "args": {}})
|
|
193
|
+
time.sleep(0.3)
|
|
194
|
+
p.stdin.close()
|
|
195
|
+
try:
|
|
196
|
+
p.wait(timeout=10)
|
|
197
|
+
except subprocess.TimeoutExpired:
|
|
198
|
+
p.kill()
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
class TestHumanInputRetry:
|
|
202
|
+
"""人类输入容错(2026-09-05 迁移,v4 §11):赋值失败 → node_retry(target='human')
|
|
203
|
+
事件 → 重试成功,流程不中断。(human_input_error 已退役——裁决⑥)"""
|
|
204
|
+
|
|
205
|
+
def test_bad_input_then_retry(self):
|
|
206
|
+
import subprocess, threading, json, time, os, sys as _sys
|
|
207
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
208
|
+
script_text = """meta:
|
|
209
|
+
session = new
|
|
210
|
+
vars:
|
|
211
|
+
player_choice = ""
|
|
212
|
+
count = 0
|
|
213
|
+
action accept @human(@player):
|
|
214
|
+
prompt: "选一个"
|
|
215
|
+
scope: [@player]
|
|
216
|
+
out:
|
|
217
|
+
player_choice(dropdown, choices={["A", "B"]}, label="选择")
|
|
218
|
+
action after @assign:
|
|
219
|
+
out: count += 1
|
|
220
|
+
actors:
|
|
221
|
+
human @player = soul:human, source:0
|
|
222
|
+
mainflow:
|
|
223
|
+
[START] -> [ASK] -> [AFTER] -> [END]
|
|
224
|
+
[ASK]: accept
|
|
225
|
+
[AFTER]: after
|
|
226
|
+
"""
|
|
227
|
+
p = subprocess.Popen(
|
|
228
|
+
[_sys.executable, os.path.join(ROOT, "hostAdapter", "dshAdapter", "python", "femo_bridge.py"), "--fe4m", ROOT],
|
|
229
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
230
|
+
text=True, encoding="utf-8", errors="replace", bufsize=1,
|
|
231
|
+
)
|
|
232
|
+
events = []
|
|
233
|
+
responses = []
|
|
234
|
+
def drain():
|
|
235
|
+
for line in p.stdout:
|
|
236
|
+
line = line.strip()
|
|
237
|
+
if not line:
|
|
238
|
+
continue
|
|
239
|
+
try:
|
|
240
|
+
obj = json.loads(line)
|
|
241
|
+
except json.JSONDecodeError:
|
|
242
|
+
continue
|
|
243
|
+
if obj.get("type") == "event":
|
|
244
|
+
events.append(obj)
|
|
245
|
+
elif obj.get("type") == "response":
|
|
246
|
+
responses.append(obj)
|
|
247
|
+
t = threading.Thread(target=drain, daemon=True)
|
|
248
|
+
t.start()
|
|
249
|
+
def send(obj):
|
|
250
|
+
p.stdin.write(json.dumps(obj, ensure_ascii=False) + "\n")
|
|
251
|
+
p.stdin.flush()
|
|
252
|
+
send({"id": 1, "cmd": "job_start",
|
|
253
|
+
"args": {"femo": script_text, "base_dir": os.path.join(ROOT, "femoExamples"),
|
|
254
|
+
"host_ref": "pytest", "script_name": "human-retry"}})
|
|
255
|
+
deadline = time.time() + 15
|
|
256
|
+
while time.time() < deadline:
|
|
257
|
+
if any(r.get("id") == 1 for r in responses):
|
|
258
|
+
break
|
|
259
|
+
time.sleep(0.1)
|
|
260
|
+
start_resp = next((r for r in responses if r.get("id") == 1), None)
|
|
261
|
+
job_id = ((start_resp or {}).get("result") or {}).get("job_id")
|
|
262
|
+
assert isinstance(job_id, int), f"job_start 回执缺 job_id: {start_resp}"
|
|
263
|
+
# 等 human_wait
|
|
264
|
+
deadline = time.time() + 15
|
|
265
|
+
wait = None
|
|
266
|
+
while time.time() < deadline:
|
|
267
|
+
waits = [e["data"] for e in events if e["event"] == "human_wait"]
|
|
268
|
+
if waits:
|
|
269
|
+
wait = waits[0]
|
|
270
|
+
break
|
|
271
|
+
time.sleep(0.1)
|
|
272
|
+
assert wait is not None, f"未见 human_wait: {[e['event'] for e in events]}"
|
|
273
|
+
# 第一次:提交未声明变量 → 应被拒绝
|
|
274
|
+
send({"id": 2, "cmd": "human_input", "args": {
|
|
275
|
+
"job_id": job_id,
|
|
276
|
+
"wait_key": wait["wait_key"],
|
|
277
|
+
"body": {"chat_text": "A", "variables": {"nope_undeclared": "x"}},
|
|
278
|
+
}})
|
|
279
|
+
deadline = time.time() + 10
|
|
280
|
+
while time.time() < deadline:
|
|
281
|
+
if any(e["event"] == "node_retry" for e in events):
|
|
282
|
+
break
|
|
283
|
+
time.sleep(0.1)
|
|
284
|
+
errs = [e["data"] for e in events if e["event"] == "node_retry"]
|
|
285
|
+
assert len(errs) == 1, f"应收到 node_retry(target='human'): {errs}"
|
|
286
|
+
assert errs[0].get("target") == "human", f"human 节点的重试信号 target 应为 human: {errs[0]}"
|
|
287
|
+
assert errs[0].get("wait_key") == wait["wait_key"], f"wait_key 应与 human_wait 一致: {errs[0]}"
|
|
288
|
+
first_error = (errs[0].get("error") or [""])[0]
|
|
289
|
+
assert "未声明" in first_error, f"错误应提到未声明: {errs[0]}"
|
|
290
|
+
# 第二次:正确输入 → human_done → 流程继续到 flow_done
|
|
291
|
+
send({"id": 3, "cmd": "human_input", "args": {
|
|
292
|
+
"job_id": job_id,
|
|
293
|
+
"wait_key": wait["wait_key"],
|
|
294
|
+
"body": {"chat_text": "A", "variables": {"player_choice": "A"}},
|
|
295
|
+
}})
|
|
296
|
+
deadline = time.time() + 15
|
|
297
|
+
while time.time() < deadline:
|
|
298
|
+
if any(e["event"] in ("flow_done", "flow_error") for e in events):
|
|
299
|
+
break
|
|
300
|
+
time.sleep(0.1)
|
|
301
|
+
types = event_types(events)
|
|
302
|
+
assert "flow_error" not in types, [e["data"] for e in events if e["event"] == "flow_error"]
|
|
303
|
+
assert "flow_done" in types, f"重试后应正常跑完: {types}"
|
|
304
|
+
assert "human_done" in types, "human_done 应出现"
|
|
305
|
+
send({"id": 4, "cmd": "shutdown", "args": {}})
|
|
306
|
+
time.sleep(0.3)
|
|
307
|
+
p.stdin.close()
|
|
308
|
+
try:
|
|
309
|
+
p.wait(timeout=10)
|
|
310
|
+
except subprocess.TimeoutExpired:
|
|
311
|
+
p.kill()
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""flow 引用校验测试(2026-08-18)。
|
|
2
|
+
|
|
3
|
+
用户指出:`已知action -> 不认识`(裸名引用未声明 action)应编译报错;
|
|
4
|
+
`已知action -> [不认识]`(方括号空节点)合法。
|
|
5
|
+
根因:标准化器把任意裸 token 无条件替换成 [节点] 绑定(不校验声明),
|
|
6
|
+
解析器原先的裸名报错永远没机会触发——本测试覆盖解析器兜底校验。
|
|
7
|
+
"""
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
BASE = """meta:
|
|
14
|
+
name = ref-check
|
|
15
|
+
session = new
|
|
16
|
+
actors:
|
|
17
|
+
ai @a = soul:1
|
|
18
|
+
action act @ai(@a):
|
|
19
|
+
prompt: hi
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class TestFlowRefValidation:
|
|
24
|
+
def test_bare_unknown_action_rejected(self):
|
|
25
|
+
"""裸名引用未声明 action → 编译报错(带节点名与提示)。"""
|
|
26
|
+
femo = BASE + """mainflow:
|
|
27
|
+
[START] -> act -> no_such_action -> [END]
|
|
28
|
+
"""
|
|
29
|
+
with pytest.raises(SyntaxError) as ei:
|
|
30
|
+
parse_script(femo, base_dir=".")
|
|
31
|
+
assert "no_such_action" in str(ei.value)
|
|
32
|
+
assert "未声明的动作" in str(ei.value)
|
|
33
|
+
|
|
34
|
+
def test_bracket_empty_node_allowed(self):
|
|
35
|
+
"""方括号空节点([不认识])合法——不绑定动作。"""
|
|
36
|
+
femo = BASE + """mainflow:
|
|
37
|
+
[START] -> act -> [不认识] -> [END]
|
|
38
|
+
"""
|
|
39
|
+
script = parse_script(femo, base_dir=".")
|
|
40
|
+
assert "act" in script.actions
|
|
41
|
+
|
|
42
|
+
def test_bare_known_action_ok(self):
|
|
43
|
+
"""裸名引用已声明 action → 正常。"""
|
|
44
|
+
femo = BASE + """mainflow:
|
|
45
|
+
[START] -> act -> [END]
|
|
46
|
+
"""
|
|
47
|
+
script = parse_script(femo, base_dir=".")
|
|
48
|
+
assert "act" in script.actions
|
|
49
|
+
|
|
50
|
+
def test_unknown_module_ref_rejected(self):
|
|
51
|
+
"""裸名引用未声明 module → 编译报错。"""
|
|
52
|
+
femo = BASE + """mainflow:
|
|
53
|
+
[START] -> &no_such_module -> [END]
|
|
54
|
+
"""
|
|
55
|
+
with pytest.raises(SyntaxError) as ei:
|
|
56
|
+
parse_script(femo, base_dir=".")
|
|
57
|
+
assert "no_such_module" in str(ei.value)
|
|
58
|
+
|
|
59
|
+
def test_module_flow_unknown_action_rejected(self):
|
|
60
|
+
"""模块 flow 内裸名引用未声明 action → 编译报错(尾部统一校验)。"""
|
|
61
|
+
femo = BASE + """module M:
|
|
62
|
+
action inner @ai(@a):
|
|
63
|
+
prompt: hi
|
|
64
|
+
flow:
|
|
65
|
+
[IN] -> inner -> ghost_action -> [OUT]
|
|
66
|
+
|
|
67
|
+
mainflow:
|
|
68
|
+
[START] -> &M -> [END]
|
|
69
|
+
"""
|
|
70
|
+
with pytest.raises(SyntaxError) as ei:
|
|
71
|
+
parse_script(femo, base_dir=".")
|
|
72
|
+
assert "ghost_action" in str(ei.value)
|
|
73
|
+
|
|
74
|
+
def test_module_flow_valid_ok(self):
|
|
75
|
+
"""模块 flow 引用模块内 action + 嵌套 module → 正常。"""
|
|
76
|
+
femo = BASE + """module Sub:
|
|
77
|
+
action sub_act @ai(@a):
|
|
78
|
+
prompt: hi
|
|
79
|
+
flow:
|
|
80
|
+
[IN] -> sub_act -> [OUT]
|
|
81
|
+
|
|
82
|
+
module M:
|
|
83
|
+
action inner @ai(@a):
|
|
84
|
+
prompt: hi
|
|
85
|
+
flow:
|
|
86
|
+
[IN] -> inner -> &Sub -> [OUT]
|
|
87
|
+
|
|
88
|
+
mainflow:
|
|
89
|
+
[START] -> &M -> [END]
|
|
90
|
+
"""
|
|
91
|
+
script = parse_script(femo, base_dir=".")
|
|
92
|
+
assert "M" in script.modules and "Sub" in script.modules
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""本地零 token 验证 @func 字典宽容回退(battle.enemy_phase 返回 hp 字典给 out: hp)。"""
|
|
3
|
+
import sys, os
|
|
4
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
5
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
6
|
+
sys.path.insert(0, os.path.join(ROOT, "tests"))
|
|
7
|
+
from conftest import run_script
|
|
8
|
+
|
|
9
|
+
script = """meta:
|
|
10
|
+
session = new
|
|
11
|
+
vars:
|
|
12
|
+
alive_party = [@knight, @mage, @player]
|
|
13
|
+
hp = {@knight: 100, @mage: 80, @player: 100}
|
|
14
|
+
enemy_hp = 150
|
|
15
|
+
battle_round = 1
|
|
16
|
+
damage_report = {}
|
|
17
|
+
code:
|
|
18
|
+
battle = file:"utils/battle.py"
|
|
19
|
+
actors:
|
|
20
|
+
ai @knight = soul:littlecat
|
|
21
|
+
ai @mage = soul:AI助手
|
|
22
|
+
human @player = soul:human, source:0
|
|
23
|
+
action ep @func(battle.enemy_phase):
|
|
24
|
+
in: hp, alive_party, battle_round
|
|
25
|
+
out: hp
|
|
26
|
+
action sd @func(battle.sum_damage):
|
|
27
|
+
in: damage_report, enemy_hp
|
|
28
|
+
out: enemy_hp
|
|
29
|
+
mainflow:
|
|
30
|
+
[START] -> [EP]:ep -> [SD]:sd -> [END]
|
|
31
|
+
"""
|
|
32
|
+
events = run_script(script)
|
|
33
|
+
types = [e["event"] for e in events]
|
|
34
|
+
print("事件:", " -> ".join(types))
|
|
35
|
+
for e in events:
|
|
36
|
+
if e["event"] in ("func_result", "assign_result", "flow_error"):
|
|
37
|
+
print(" ", e["event"], str(e.get("data", {}))[:200])
|
|
38
|
+
errs = [e for e in events if e["event"] == "flow_error"]
|
|
39
|
+
print("PASS" if not errs and "flow_done" in types else "FAIL")
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""Job 生命周期引擎级测试(运行状态链路重构施工清单 v3 §12.3:孤儿信/C3/取消路径落库)。
|
|
2
|
+
|
|
3
|
+
锁定三条生命周期语义(全部走真 bridge 子进程 + Job 模型协议):
|
|
4
|
+
|
|
5
|
+
1. test_orphan_mail_and_run_tag —— 孤儿信与世代前缀(§12.3.3):
|
|
6
|
+
stop 后向旧 wait_key 投递 → `{delivered:false}`(B6 投递侧防线:不盲投
|
|
7
|
+
信箱);新 Job 的 human wait_key 带 `j<N>:` 世代前缀(§5.6 机制性免疫:
|
|
8
|
+
旧 run 的滞留信永远 pop 不进新 run 的信箱)。
|
|
9
|
+
2. test_c3_direct_ai_pause —— C3 直连 AI 失败挂起(§12.3.4):
|
|
10
|
+
直连模式 AI 调用失败(请求层失败 → FEMOTransientError 重试用尽 →
|
|
11
|
+
llm_output=None)→ flow_paused(reason=node_pause) + 档案
|
|
12
|
+
suspended(node_pause) + 断点非空 + job_resume 可续——旧世界
|
|
13
|
+
`await event.wait()` 无超时无人 set 的挂死协程(C3)根除锁定。
|
|
14
|
+
3. test_cancel_path_flushes_dialog —— 取消路径落库(§12.3.6):
|
|
15
|
+
human 输入已消费后 stop → 取消路径 wait_empty 兜底(D2 真超时)→
|
|
16
|
+
发言落库不丢(批次 1 丢台词实锤的回归锁定)。
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import sqlite3
|
|
22
|
+
import subprocess
|
|
23
|
+
import sys
|
|
24
|
+
import threading
|
|
25
|
+
import time
|
|
26
|
+
|
|
27
|
+
import pytest
|
|
28
|
+
|
|
29
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
30
|
+
if ROOT not in sys.path:
|
|
31
|
+
sys.path.insert(0, ROOT)
|
|
32
|
+
|
|
33
|
+
from test_v2_resume_e2e import BridgeSession # 复用 NDJSON 会话壳(协议 §12.1 同源)
|
|
34
|
+
|
|
35
|
+
STOP_FEMO = """meta:
|
|
36
|
+
name = lifecycle-probe
|
|
37
|
+
session = new
|
|
38
|
+
|
|
39
|
+
vars:
|
|
40
|
+
counter = 0
|
|
41
|
+
|
|
42
|
+
actors:
|
|
43
|
+
human player = soul:human, source:0
|
|
44
|
+
|
|
45
|
+
action bump @assign:
|
|
46
|
+
out: counter += 1
|
|
47
|
+
|
|
48
|
+
action wait_player @human(@player):
|
|
49
|
+
prompt: "暂停点:请回复继续"
|
|
50
|
+
|
|
51
|
+
mainflow:
|
|
52
|
+
[START] -> [B1]:bump -> [W1]:wait_player -> [B2]:bump -> [W2]:wait_player -> [END]
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
# C3 直连 AI 剧本:soul 用预置 Eve(ensure_default_data 种子)。直连 llmBridge
|
|
56
|
+
# 依赖可选的 requests 库(测试环境不保证有)——本用例按清单 §12.3 原文
|
|
57
|
+
# 「mock llmBridge 返回 None」在测试进程内打桩(见用例体),不经 bridge 子进程。
|
|
58
|
+
DIRECT_AI_FEMO = """meta:
|
|
59
|
+
name = c3-node-pause-probe
|
|
60
|
+
session = new
|
|
61
|
+
|
|
62
|
+
actors:
|
|
63
|
+
ai @Eve = soul:the1stlittlesoul
|
|
64
|
+
|
|
65
|
+
action speak @ai(@Eve):
|
|
66
|
+
prompt: "说一句简短的中文问候,不超过20字。"
|
|
67
|
+
scope: [@Eve]
|
|
68
|
+
|
|
69
|
+
mainflow:
|
|
70
|
+
[START] -> [S]:speak -> [END]
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.fixture
|
|
75
|
+
def bridge():
|
|
76
|
+
bs = BridgeSession()
|
|
77
|
+
try:
|
|
78
|
+
yield bs
|
|
79
|
+
finally:
|
|
80
|
+
bs.close()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_orphan_mail_and_run_tag(bridge):
|
|
84
|
+
"""孤儿信投递侧防线 + run_tag 世代前缀(B6/§5.6)。"""
|
|
85
|
+
jid1 = bridge.start(STOP_FEMO)
|
|
86
|
+
ev = bridge.wait_event(lambda e: e["event"] == "human_wait", timeout=30)
|
|
87
|
+
old_wait_key = (ev.get("data") or {}).get("wait_key", "")
|
|
88
|
+
assert old_wait_key, f"human_wait 缺 wait_key: {ev}"
|
|
89
|
+
bridge.pause()
|
|
90
|
+
bridge.wait_event(lambda e: e["event"] == "bridge_run_ended", timeout=30)
|
|
91
|
+
|
|
92
|
+
# ① 暂停后向旧 wait_key 投递:不盲投(不假成功——B5 死于结构)
|
|
93
|
+
resp = bridge.human_input(old_wait_key, {"chat_text": "孤儿信", "variables": {}})
|
|
94
|
+
body = resp.get("result") or {}
|
|
95
|
+
assert resp.get("ok") and body.get("delivered") is False, \
|
|
96
|
+
f"暂停后投递旧 wait_key 应 delivered=False(不盲投): {resp}"
|
|
97
|
+
assert body.get("error") in ("job_not_active", "no_such_job"), \
|
|
98
|
+
f"投递拒绝应带结构化 error code: {resp}"
|
|
99
|
+
|
|
100
|
+
# ② 新 Job 的 wait_key 带 j<N>: 世代前缀——旧滞留信机制性免疫
|
|
101
|
+
# (走 start():BridgeSession.job_id 随回执更新,后续 stop 才停对本 Job)
|
|
102
|
+
jid2 = bridge.start(STOP_FEMO)
|
|
103
|
+
ev2 = bridge.wait_event(lambda e: e["event"] == "human_wait"
|
|
104
|
+
and (e.get("data") or {}).get("job_id") == jid2, timeout=30)
|
|
105
|
+
new_wait_key = (ev2.get("data") or {}).get("wait_key", "")
|
|
106
|
+
assert new_wait_key.startswith(f"j{jid2}:"), \
|
|
107
|
+
f"新 Job wait_key 应带 j{jid2}: 世代前缀,实际 {new_wait_key!r}"
|
|
108
|
+
# 新 Job 正常收尾(幂等 stop),不留 running 僵尸档案
|
|
109
|
+
bridge.pause()
|
|
110
|
+
bridge.wait_event(lambda e: e["event"] == "bridge_run_ended"
|
|
111
|
+
and (e.get("data") or {}).get("job_id") == jid2, timeout=30)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_c3_direct_ai_pause():
|
|
115
|
+
"""C3:直连 AI 失败 → 挂起(可续),不再挂死(进程内 mock 形态)。
|
|
116
|
+
|
|
117
|
+
mock llmBridge.call_ai_with_blocks(清单 §12.3 原文):前 3 次调用抛
|
|
118
|
+
FEMOTransientError(直连临时失败的唯一真实形态——llmBridge 请求层失败
|
|
119
|
+
不返回 None 而是抛它)→ _exec_ai 重试用尽(默认 max_retries=2 → 3 轮)
|
|
120
|
+
→ llm_output=None → FEMORunPaused 分支 → run_async 以 suspended(node_pause)
|
|
121
|
+
收场且**不发 flow_done**;job_resume 六关全过 → 第 4 次调用返回正常回复
|
|
122
|
+
→ 续跑跑完 flow_done → 档案 finished。完整闭环全部在本进程内锁定
|
|
123
|
+
(bridge 层只做翻译,状态机在 JobManager)。"""
|
|
124
|
+
import types
|
|
125
|
+
import asyncio
|
|
126
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
127
|
+
from femoCompiler.FEMO_errors import FEMOTransientError
|
|
128
|
+
from femoCompiler.FEMO_runtime import FEMORunner
|
|
129
|
+
from femoCompiler.job_manager import JobManager, fingerprint_script
|
|
130
|
+
|
|
131
|
+
calls = {'n': 0}
|
|
132
|
+
|
|
133
|
+
def _fake_call(*args, **kwargs):
|
|
134
|
+
calls['n'] += 1
|
|
135
|
+
if calls['n'] <= 3: # 第一次 run 的 3 轮重试全失败(对齐真实失败链)
|
|
136
|
+
raise FEMOTransientError('模拟直连 AI 临时失败(限流/超时/网络)')
|
|
137
|
+
return '恢复后的正常回复'
|
|
138
|
+
|
|
139
|
+
fake_mod = types.ModuleType('femoBridges.llmBridge')
|
|
140
|
+
fake_mod.call_ai_with_blocks = _fake_call
|
|
141
|
+
saved_mod = sys.modules.get('femoBridges.llmBridge')
|
|
142
|
+
sys.modules['femoBridges.llmBridge'] = fake_mod
|
|
143
|
+
|
|
144
|
+
jm = JobManager()
|
|
145
|
+
rec = jm.create_job(fingerprint_script(DIRECT_AI_FEMO), host_ref='pytest',
|
|
146
|
+
script_name='c3-inproc')
|
|
147
|
+
jid = rec.job_id
|
|
148
|
+
script = parse_script(DIRECT_AI_FEMO, base_dir=ROOT) # bridge run_compile 同款
|
|
149
|
+
events = []
|
|
150
|
+
|
|
151
|
+
def cb(event_type, data):
|
|
152
|
+
payload = {**(data if isinstance(data, dict) else {}), 'job_id': jid}
|
|
153
|
+
jm.observe_event(jid, event_type, payload) # bridge per-job 包装同款(§7.3)
|
|
154
|
+
events.append((event_type, payload))
|
|
155
|
+
|
|
156
|
+
rc = {
|
|
157
|
+
'on_flow_start': lambda p: jm.mark_session(jid, p.get('session_id')),
|
|
158
|
+
'on_checkpoint': lambda p: jm.merge_checkpoint(jid, p),
|
|
159
|
+
'on_state_change': lambda st, reason: jm.suspend(jid, reason),
|
|
160
|
+
'on_run_end': lambda fs: jm.finalize(jid, 'finished'),
|
|
161
|
+
}
|
|
162
|
+
try:
|
|
163
|
+
# ── 第一次 run:AI 失败 → node_pause 挂起 ──
|
|
164
|
+
runner = FEMORunner(script, base_dir=ROOT, verbose=False,
|
|
165
|
+
event_callback=cb, runtime_callbacks=rc,
|
|
166
|
+
run_tag=f'j{jid}:')
|
|
167
|
+
jm.attach(jid, runner)
|
|
168
|
+
runner.run() # FEMORunPaused 被 run_async 吞掉,run 正常返回(不挂死)
|
|
169
|
+
|
|
170
|
+
stops = [d for t, d in events if t == 'flow_paused']
|
|
171
|
+
assert len(stops) == 1 and stops[0].get('reason') == 'node_pause', \
|
|
172
|
+
f"应恰一次 flow_paused(reason=node_pause): {stops}"
|
|
173
|
+
assert not [t for t, _ in events if t == 'flow_done'], \
|
|
174
|
+
"FEMORunPaused 挂起路径不许发 flow_done(假跑完同罪)"
|
|
175
|
+
state = jm.get_job_state(jid)
|
|
176
|
+
assert state.get('state') == 'suspended' and state.get('reason') == 'node_pause', \
|
|
177
|
+
f"档案应为 suspended(node_pause): {state}"
|
|
178
|
+
assert state.get('checkpoints'), f"node_pause 断点必须非空: {state.get('checkpoints')}"
|
|
179
|
+
|
|
180
|
+
# ── job_resume 六关裁决 → 续跑跑完 ──
|
|
181
|
+
rec2 = jm.resume_job(jid, fingerprint_script(DIRECT_AI_FEMO), host_ref='pytest')
|
|
182
|
+
resume_state = jm.build_resume_state(rec2)
|
|
183
|
+
jm.mark_running(jid)
|
|
184
|
+
runner2 = FEMORunner(script, base_dir=ROOT, verbose=False,
|
|
185
|
+
event_callback=cb, resume_state=resume_state,
|
|
186
|
+
runtime_callbacks=rc, run_tag=f'j{jid}:')
|
|
187
|
+
jm.attach(jid, runner2)
|
|
188
|
+
runner2.run()
|
|
189
|
+
assert [t for t, _ in events if t == 'flow_done'], \
|
|
190
|
+
"恢复后 AI 正常应跑完发 flow_done"
|
|
191
|
+
final = jm.get_job_state(jid)
|
|
192
|
+
assert final.get('state') == 'finished', f"恢复跑完应收口 finished: {final}"
|
|
193
|
+
assert calls['n'] >= 4, f"mock 直连应被调用至少 4 次(3 败 + 1 成): {calls}"
|
|
194
|
+
retries = [d for t, d in events if t == 'ai_retry']
|
|
195
|
+
assert len(retries) == 2, f"3 轮重试应发恰 2 条 ai_retry: {len(retries)}"
|
|
196
|
+
finally:
|
|
197
|
+
if saved_mod is None:
|
|
198
|
+
sys.modules.pop('femoBridges.llmBridge', None)
|
|
199
|
+
else:
|
|
200
|
+
sys.modules['femoBridges.llmBridge'] = saved_mod
|
|
201
|
+
jm.detach(jid)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def test_cancel_path_flushes_dialog(bridge):
|
|
205
|
+
"""取消路径落库:输入已消费后 stop → wait_empty 兜底 → 发言落库不丢。"""
|
|
206
|
+
marker = f"暂停落库探针-{int(time.time())}"
|
|
207
|
+
jid = bridge.start(STOP_FEMO)
|
|
208
|
+
ev = bridge.wait_event(lambda e: e["event"] == "human_wait", timeout=30)
|
|
209
|
+
wait_key = (ev.get("data") or {}).get("wait_key", "")
|
|
210
|
+
resp = bridge.human_input(wait_key, {"chat_text": marker, "variables": {}})
|
|
211
|
+
assert (resp.get("result") or {}).get("delivered") is True, f"投递失败: {resp}"
|
|
212
|
+
# human_done 在 save_human_finish 落库 event.wait 之后发出——到达即已入队
|
|
213
|
+
bridge.wait_event(lambda e: e["event"] == "human_done"
|
|
214
|
+
and (e.get("data") or {}).get("job_id") == jid, timeout=30)
|
|
215
|
+
bridge.pause()
|
|
216
|
+
bridge.wait_event(lambda e: e["event"] == "bridge_run_ended", timeout=30)
|
|
217
|
+
time.sleep(0.5)
|
|
218
|
+
|
|
219
|
+
# 档案诚实挂起(不伪 finished)
|
|
220
|
+
state = bridge.rpc("get_job_state", {"job_id": jid})
|
|
221
|
+
rec = state.get("result") or {}
|
|
222
|
+
assert rec.get("state") == "suspended" and rec.get("reason") == "user_pause", rec
|
|
223
|
+
|
|
224
|
+
# 发言落库不丢(dialog 表按场次+标记文本查;get_db_path 与 bridge 同源——
|
|
225
|
+
# get_user_dir 解析一致,test_v2_resume_e2e 场景4 已实证同源)
|
|
226
|
+
from femoCompiler.FEMO_config import get_db_path
|
|
227
|
+
session_id = rec.get("femo_session_id")
|
|
228
|
+
assert isinstance(session_id, int) and session_id > 0, f"档案缺 femo_session_id: {rec}"
|
|
229
|
+
conn = sqlite3.connect(get_db_path())
|
|
230
|
+
try:
|
|
231
|
+
rows = conn.execute(
|
|
232
|
+
"SELECT user_prompt FROM dialog WHERE session_id = ? AND user_prompt LIKE ?",
|
|
233
|
+
(session_id, f"%{marker}%")).fetchall()
|
|
234
|
+
finally:
|
|
235
|
+
conn.close()
|
|
236
|
+
assert rows, f"暂停后玩家发言应落库不丢: session={session_id} marker={marker!r}"
|