femo-plugin 1.0.1 → 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/_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,494 @@
|
|
|
1
|
+
"""解析器单元测试:FEMO_parser 直接 import,零进程、零 token。"""
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
8
|
+
|
|
9
|
+
from femoCompiler.FEMO_parser import parse_script, _parse_out_multi, OutType
|
|
10
|
+
from femoCompiler.FEMO_parser import OutDef
|
|
11
|
+
|
|
12
|
+
PY = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "femoExamples")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def load(name):
|
|
16
|
+
with open(os.path.join(PY, name), encoding="utf-8") as f:
|
|
17
|
+
return parse_script(f.read(), base_dir=PY)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# ── out 语法解析 ───────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
class TestParseOutMulti:
|
|
23
|
+
def test_dropdown_form(self):
|
|
24
|
+
outs = _parse_out_multi(
|
|
25
|
+
'player_choice(dropdown, choices={["接受", "拒绝"]}, label="是否接受委托")'
|
|
26
|
+
)
|
|
27
|
+
assert len(outs) == 1
|
|
28
|
+
od = outs[0]
|
|
29
|
+
assert od.var_name == "player_choice"
|
|
30
|
+
assert od.out_type == OutType.DROPDOWN
|
|
31
|
+
assert od.choices is not None and "接受" in od.choices
|
|
32
|
+
assert od.label == "是否接受委托"
|
|
33
|
+
|
|
34
|
+
def test_assign_form(self):
|
|
35
|
+
outs = _parse_out_multi("refuse_count += 1")
|
|
36
|
+
assert len(outs) == 1
|
|
37
|
+
assert outs[0].out_type == OutType.ASSIGN
|
|
38
|
+
assert outs[0].var_name == "refuse_count += 1"
|
|
39
|
+
|
|
40
|
+
def test_plain_var(self):
|
|
41
|
+
outs = _parse_out_multi("reply")
|
|
42
|
+
assert len(outs) == 1
|
|
43
|
+
assert outs[0].var_name == "reply"
|
|
44
|
+
assert outs[0].out_type == OutType.STRING
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# ── vars 解析:循环变量保留 @ 前缀 ──────────────────────────
|
|
48
|
+
|
|
49
|
+
class TestParseVars:
|
|
50
|
+
def test_at_prefixed_loop_var_kept(self):
|
|
51
|
+
script = load("for-repro-declare.femo")
|
|
52
|
+
assert "@hero" in script.vars
|
|
53
|
+
|
|
54
|
+
def test_plain_vars(self):
|
|
55
|
+
script = load("goblin-mini.femo")
|
|
56
|
+
assert script.vars["player_choice"] == "接受"
|
|
57
|
+
assert "alive_party" in script.vars
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# ── goblin 图结构 ──────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
class TestGoblinStructure:
|
|
63
|
+
@pytest.fixture(scope="class")
|
|
64
|
+
def goblin(self):
|
|
65
|
+
return load("goblin-demo.femo")
|
|
66
|
+
|
|
67
|
+
def test_nodes(self, goblin):
|
|
68
|
+
ids = set(goblin.flow.nodes)
|
|
69
|
+
for nid in ("[START]", "[opening]", "[ASK]", "[B1]", "[GO]", "[WIN]",
|
|
70
|
+
"[FAREWELL]", "[END]", "[L]", "[LP]", "[NO]", "[NO2]"):
|
|
71
|
+
assert nid in ids, f"缺少节点 {nid}"
|
|
72
|
+
|
|
73
|
+
def test_fork_gateway(self, goblin):
|
|
74
|
+
fork = goblin.flow.nodes["__fork_1__"]
|
|
75
|
+
assert fork.type == "gateway"
|
|
76
|
+
assert fork.meta.get("gw_kind") == "fork"
|
|
77
|
+
|
|
78
|
+
def test_fork_conditional_edges(self, goblin):
|
|
79
|
+
edges = {(e.source, e.target): e.condition
|
|
80
|
+
for e in goblin.flow.edges if e.source == "__fork_1__"}
|
|
81
|
+
assert edges["__fork_1__", "[GO]"] == 'player_choice == "接受"'
|
|
82
|
+
assert "refuse_count < 2" in edges["__fork_1__", "[NO]"]
|
|
83
|
+
assert "refuse_count >= 2" in edges["__fork_1__", "[NO2]"]
|
|
84
|
+
|
|
85
|
+
def test_for_gateway_meta(self, goblin):
|
|
86
|
+
for_gw = goblin.flow.nodes["__for_2__"]
|
|
87
|
+
assert for_gw.type == "gateway"
|
|
88
|
+
assert for_gw.meta["gw_kind"] == "for"
|
|
89
|
+
assert for_gw.meta["var_name"] == "@hero"
|
|
90
|
+
assert for_gw.meta["iterable"] == "alive_party"
|
|
91
|
+
|
|
92
|
+
def test_for_back_edges_and_exit(self, goblin):
|
|
93
|
+
back = {(e.source, e.target) for e in goblin.flow.edges
|
|
94
|
+
if e.target == "__for_2__"}
|
|
95
|
+
assert ("[L]", "__for_2__") in back
|
|
96
|
+
assert ("[LP]", "__for_2__") in back
|
|
97
|
+
# 出口:无条件边到 [FAREWELL]
|
|
98
|
+
exit_edges = [e for e in goblin.flow.edges
|
|
99
|
+
if e.source == "__for_2__" and not e.condition]
|
|
100
|
+
assert [e.target for e in exit_edges] == ["[FAREWELL]"]
|
|
101
|
+
|
|
102
|
+
def test_module_empty_flow_ok(self, goblin):
|
|
103
|
+
mod = goblin.modules["BattleRound"]
|
|
104
|
+
assert mod.flow is not None
|
|
105
|
+
assert len(mod.flow.nodes) == 0 # 空 module 不崩
|
|
106
|
+
|
|
107
|
+
def test_actions(self, goblin):
|
|
108
|
+
assert goblin.actions["accept_quest"].outs[0].var_name == "player_choice"
|
|
109
|
+
# loot_share 是 @ai(@hero):执行器参数为循环变量 @hero
|
|
110
|
+
assert goblin.actions["loot_share"].executor_param == "@hero"
|
|
111
|
+
assert goblin.actions["count_refuse"].outs[0].out_type == OutType.ASSIGN
|
|
112
|
+
|
|
113
|
+
def test_out_continuation_lines(self):
|
|
114
|
+
"""单行 out 后的缩进续行必须合并(out: x += 1 后接 y = {} 两行都生效)。"""
|
|
115
|
+
script = load("goblin-v2.femo")
|
|
116
|
+
ru = script.modules["BattleRound"].actions["round_up"]
|
|
117
|
+
assert len(ru.outs) == 2, f"round_up 应有 2 个 out(含续行),实际 {len(ru.outs)}"
|
|
118
|
+
names = [o.var_name for o in ru.outs]
|
|
119
|
+
assert any("battle_round" in n for n in names), f"缺少 battle_round: {names}"
|
|
120
|
+
assert any("damage_report" in n for n in names), f"续行 damage_report 未合并: {names}"
|
|
121
|
+
|
|
122
|
+
def test_join_to_chain(self):
|
|
123
|
+
"""join 的 to [X]:ref -> [Y] 链:绑定保留 + 尾边存在。"""
|
|
124
|
+
script = load("test-if-fork-join.femo")
|
|
125
|
+
done = script.flow.nodes.get("[DONE]")
|
|
126
|
+
assert done is not None
|
|
127
|
+
assert done.action_name == "finish", f"[DONE] 绑定应保留 finish: {getattr(done, 'action_name', None)}"
|
|
128
|
+
assert any(e.source == "[DONE]" and e.target == "[END]" for e in script.flow.edges), \
|
|
129
|
+
"[DONE] -> [END] 边应存在"
|
|
130
|
+
|
|
131
|
+
def test_prompt_comment_exempt(self):
|
|
132
|
+
"""prompt 多行块内 # 和 // 是内容,注释剥离必须豁免。"""
|
|
133
|
+
script = load("goblin-v2.femo")
|
|
134
|
+
p = script.actions["opening"].prompt
|
|
135
|
+
assert "哥布林" in p # 正常内容
|
|
136
|
+
# 构造一个 prompt 内含 # // 的剧本验证豁免
|
|
137
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
138
|
+
text = """meta:
|
|
139
|
+
session = new
|
|
140
|
+
vars:
|
|
141
|
+
reply = ""
|
|
142
|
+
action talk @assign:
|
|
143
|
+
out: reply = "x"
|
|
144
|
+
action speak @ai(@e):
|
|
145
|
+
prompt: |
|
|
146
|
+
这是 # 内容
|
|
147
|
+
斜杠 // 也是内容
|
|
148
|
+
scope: [@e]
|
|
149
|
+
actors:
|
|
150
|
+
ai @e = soul:1
|
|
151
|
+
mainflow:
|
|
152
|
+
[START] -> [T] -> [END]
|
|
153
|
+
[T]: speak
|
|
154
|
+
"""
|
|
155
|
+
s = parse_script(text, base_dir=PY)
|
|
156
|
+
p2 = s.actions["speak"].prompt
|
|
157
|
+
assert "#" in p2 and "//" in p2, f"prompt 内注释被剥离: {p2!r}"
|
|
158
|
+
|
|
159
|
+
def test_double_dash_only_in_flow(self):
|
|
160
|
+
"""-- 只在 flow/mainflow 区等价 ->;vars 字符串值里必须保留。"""
|
|
161
|
+
script = load("for-repro-declare.femo") if False else None
|
|
162
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
163
|
+
text = """meta:
|
|
164
|
+
session = new
|
|
165
|
+
vars:
|
|
166
|
+
note = "a--b"
|
|
167
|
+
mainflow:
|
|
168
|
+
[START] -- [END]
|
|
169
|
+
"""
|
|
170
|
+
s = parse_script(text, base_dir=PY)
|
|
171
|
+
assert s.vars["note"] == "a--b", f"-- 被替换: {s.vars['note']!r}"
|
|
172
|
+
# flow 区 -- 应等价 ->([START] -> [END] 连通)
|
|
173
|
+
assert any(e.source == "[START]" and e.target == "[END]" for e in s.flow.edges)
|
|
174
|
+
|
|
175
|
+
def test_goblin_v2_engine_parse(self):
|
|
176
|
+
"""goblin-v2(4 空格缩进 + 裸 &module + for 出口链)引擎解析完整性。
|
|
177
|
+
回归保护:normalizer min_indent 初始值 bug(4 空格缩进剧本流程行全丢)
|
|
178
|
+
与 &module 裸引用 bug(\b 边界不覆盖 &)。"""
|
|
179
|
+
script = load("goblin-v2.femo")
|
|
180
|
+
# 主流程完整
|
|
181
|
+
assert "[START]" in script.flow.nodes, "[START] 丢失(min_indent bug)"
|
|
182
|
+
assert "[END]" in script.flow.nodes
|
|
183
|
+
fw = script.flow.nodes.get("[FAREWELL]")
|
|
184
|
+
assert fw is not None and fw.action_name == "farewell"
|
|
185
|
+
assert any(e.source == "[FAREWELL]" and e.target == "[END]" for e in script.flow.edges), \
|
|
186
|
+
"for 出口链 [FAREWELL] -> [END] 边丢失"
|
|
187
|
+
# 裸 &module 引用
|
|
188
|
+
br = script.flow.nodes.get("[BattleRound]")
|
|
189
|
+
assert br is not None and br.module_ref == "BattleRound", \
|
|
190
|
+
f"&BattleRound 引用错误: {getattr(br, 'module_ref', None)}"
|
|
191
|
+
# module flow 完整
|
|
192
|
+
mod = script.modules.get("BattleRound")
|
|
193
|
+
assert mod is not None and mod.flow is not None
|
|
194
|
+
assert len(mod.flow.nodes) >= 10, f"module flow 节点缺失: {len(mod.flow.nodes)}"
|
|
195
|
+
# 模块内 par + fork 网关
|
|
196
|
+
gw = [n for n in mod.flow.nodes.values() if n.type == "gateway"]
|
|
197
|
+
assert any(n.meta.get("is_par_fork") for n in gw), "module 内 par 网关缺失"
|
|
198
|
+
assert any(n.meta.get("gw_kind") == "fork" and not n.meta.get("is_par_fork") for n in gw), \
|
|
199
|
+
"module 内 fork 网关缺失"
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# ── 语法测试剧本(引擎真实语法)──────────────────────────────
|
|
203
|
+
|
|
204
|
+
class TestSyntaxScripts:
|
|
205
|
+
def test_if_fork_join(self):
|
|
206
|
+
script = load("test-if-fork-join.femo")
|
|
207
|
+
# join 网关存在
|
|
208
|
+
join_nodes = [n for n in script.flow.nodes.values()
|
|
209
|
+
if n.type == "gateway" and n.meta.get("gw_kind") == "join"]
|
|
210
|
+
assert len(join_nodes) >= 1
|
|
211
|
+
|
|
212
|
+
def test_for_if(self):
|
|
213
|
+
script = load("test-for-if.femo")
|
|
214
|
+
for_gws = [n for n in script.flow.nodes.values()
|
|
215
|
+
if n.type == "gateway" and n.meta.get("gw_kind") == "for"]
|
|
216
|
+
assert len(for_gws) == 1
|
|
217
|
+
assert for_gws[0].meta["var_name"] == "@m"
|
|
218
|
+
|
|
219
|
+
def test_par(self):
|
|
220
|
+
script = load("test-par.femo")
|
|
221
|
+
# par 展开为 par_fork 网关(gw_kind=fork + is_par_fork + par_var)
|
|
222
|
+
par_forks = [n for n in script.flow.nodes.values()
|
|
223
|
+
if n.type == "gateway" and n.meta.get("is_par_fork")]
|
|
224
|
+
assert len(par_forks) == 1
|
|
225
|
+
assert par_forks[0].meta["par_var"] == "@w"
|
|
226
|
+
assert par_forks[0].meta["par_iterable"] == "workers"
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
# ── meta.owner 默认值(dsh 插件唯一用户 u001)──────────────────
|
|
230
|
+
|
|
231
|
+
class TestOwnerDefault:
|
|
232
|
+
SCRIPT = """\
|
|
233
|
+
meta:
|
|
234
|
+
name = owner 测试
|
|
235
|
+
|
|
236
|
+
actors:
|
|
237
|
+
ai @host = soul:1
|
|
238
|
+
|
|
239
|
+
mainflow:
|
|
240
|
+
[START] -> [END]
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
def test_owner_missing_defaults_u001(self):
|
|
244
|
+
s = parse_script(self.SCRIPT)
|
|
245
|
+
assert s.meta.get('owner') == ['u001']
|
|
246
|
+
|
|
247
|
+
def test_owner_empty_list_defaults_u001(self):
|
|
248
|
+
s = parse_script("""\
|
|
249
|
+
meta:
|
|
250
|
+
name = t
|
|
251
|
+
owner = []
|
|
252
|
+
|
|
253
|
+
actors:
|
|
254
|
+
ai @host = soul:1
|
|
255
|
+
|
|
256
|
+
mainflow:
|
|
257
|
+
[START] -> [END]
|
|
258
|
+
""")
|
|
259
|
+
assert s.meta.get('owner') == ['u001']
|
|
260
|
+
|
|
261
|
+
def test_owner_explicit_kept(self):
|
|
262
|
+
s = parse_script("""\
|
|
263
|
+
meta:
|
|
264
|
+
name = t
|
|
265
|
+
owner = [1]
|
|
266
|
+
|
|
267
|
+
actors:
|
|
268
|
+
ai @host = soul:1
|
|
269
|
+
|
|
270
|
+
mainflow:
|
|
271
|
+
[START] -> [END]
|
|
272
|
+
""")
|
|
273
|
+
assert s.meta.get('owner') == ['1']
|
|
274
|
+
|
|
275
|
+
def test_owner_scalar_string_kept(self):
|
|
276
|
+
s = parse_script("""\
|
|
277
|
+
meta:
|
|
278
|
+
name = t
|
|
279
|
+
owner = abc
|
|
280
|
+
|
|
281
|
+
actors:
|
|
282
|
+
ai @host = soul:1
|
|
283
|
+
|
|
284
|
+
mainflow:
|
|
285
|
+
[START] -> [END]
|
|
286
|
+
""")
|
|
287
|
+
assert s.meta.get('owner') == ['abc']
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
# ── @notice 解析与分级校验(2026-09-07)────────────────────
|
|
291
|
+
|
|
292
|
+
from femoCompiler.FEMO_parser import ExecutorType
|
|
293
|
+
|
|
294
|
+
NOTICE_OK = """\
|
|
295
|
+
meta:
|
|
296
|
+
name = notice-ok
|
|
297
|
+
owner = [u001]
|
|
298
|
+
actors:
|
|
299
|
+
ai @eve = soul:the1stlittlesoul
|
|
300
|
+
action announce @notice:
|
|
301
|
+
prompt: 今夜暴雨,公园玩家回家
|
|
302
|
+
scope: [@eve]
|
|
303
|
+
mainflow:
|
|
304
|
+
[START] -> announce -> [END]
|
|
305
|
+
"""
|
|
306
|
+
|
|
307
|
+
NOTICE_NO_PROMPT = """\
|
|
308
|
+
meta:
|
|
309
|
+
name = notice-noprompt
|
|
310
|
+
actors:
|
|
311
|
+
ai @eve = soul:the1stlittlesoul
|
|
312
|
+
action announce @notice:
|
|
313
|
+
scope: [@eve]
|
|
314
|
+
mainflow:
|
|
315
|
+
[START] -> announce -> [END]
|
|
316
|
+
"""
|
|
317
|
+
|
|
318
|
+
NOTICE_WITH_OUT = """\
|
|
319
|
+
meta:
|
|
320
|
+
name = notice-out
|
|
321
|
+
actors:
|
|
322
|
+
ai @eve = soul:the1stlittlesoul
|
|
323
|
+
vars:
|
|
324
|
+
x = 0
|
|
325
|
+
action announce @notice:
|
|
326
|
+
prompt: 公告
|
|
327
|
+
out: x = 1
|
|
328
|
+
mainflow:
|
|
329
|
+
[START] -> announce -> [END]
|
|
330
|
+
"""
|
|
331
|
+
|
|
332
|
+
NOTICE_WITH_RESOLVE = """\
|
|
333
|
+
meta:
|
|
334
|
+
name = notice-resolve
|
|
335
|
+
actors:
|
|
336
|
+
ai @eve = soul:the1stlittlesoul
|
|
337
|
+
code:
|
|
338
|
+
m = file:"nonexist_notice_mod.py"
|
|
339
|
+
action announce @notice:
|
|
340
|
+
prompt: 公告
|
|
341
|
+
resolve: m.f
|
|
342
|
+
mainflow:
|
|
343
|
+
[START] -> announce -> [END]
|
|
344
|
+
"""
|
|
345
|
+
|
|
346
|
+
NOTICE_INERT = """\
|
|
347
|
+
meta:
|
|
348
|
+
name = notice-inert
|
|
349
|
+
owner = [u001]
|
|
350
|
+
actors:
|
|
351
|
+
ai @eve = soul:the1stlittlesoul
|
|
352
|
+
action announce @notice(@eve):
|
|
353
|
+
prompt: 公告
|
|
354
|
+
showprompt: 提醒
|
|
355
|
+
memory: rag
|
|
356
|
+
context: ctx
|
|
357
|
+
max_retries: 3
|
|
358
|
+
fallback: other
|
|
359
|
+
scope: self
|
|
360
|
+
mainflow:
|
|
361
|
+
[START] -> announce -> [END]
|
|
362
|
+
"""
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
class TestNoticeParse:
|
|
366
|
+
def test_notice_parses_to_notice_executor(self):
|
|
367
|
+
script = parse_script(NOTICE_OK, base_dir=".")
|
|
368
|
+
action = script.actions["announce"]
|
|
369
|
+
assert action.executor_type == ExecutorType.NOTICE
|
|
370
|
+
assert action.executor_param == ""
|
|
371
|
+
assert action.prompt == "今夜暴雨,公园玩家回家" # 全角逗号被符号规范化为半角
|
|
372
|
+
assert action.scope == "[@eve]"
|
|
373
|
+
|
|
374
|
+
def test_notice_empty_prompt_rejected(self):
|
|
375
|
+
with pytest.raises(SyntaxError, match="prompt 为空"):
|
|
376
|
+
parse_script(NOTICE_NO_PROMPT, base_dir=".")
|
|
377
|
+
|
|
378
|
+
def test_notice_out_rejected(self):
|
|
379
|
+
with pytest.raises(SyntaxError, match="不支持 out"):
|
|
380
|
+
parse_script(NOTICE_WITH_OUT, base_dir=".")
|
|
381
|
+
|
|
382
|
+
def test_notice_resolve_rejected(self):
|
|
383
|
+
with pytest.raises(SyntaxError, match="不支持 resolve"):
|
|
384
|
+
parse_script(NOTICE_WITH_RESOLVE, base_dir=".")
|
|
385
|
+
|
|
386
|
+
def test_notice_inert_fields_warn_not_raise(self):
|
|
387
|
+
"""惰性死配置(memory/context/showprompt/max_retries/fallback/scope:self/
|
|
388
|
+
误填执行者)→ 编译放行,warning 桶逐条知情。"""
|
|
389
|
+
script = parse_script(NOTICE_INERT, base_dir=".")
|
|
390
|
+
msgs = " ".join(w["message"] for w in script.warnings)
|
|
391
|
+
for frag in ("memory:", "context:", "showprompt:", "max_retries:",
|
|
392
|
+
"fallback:", "self", "@notice(@eve)"):
|
|
393
|
+
assert frag in msgs, f"warning 桶缺 {frag}: {script.warnings}"
|
|
394
|
+
|
|
395
|
+
def test_notice_no_false_warnings_on_clean_script(self):
|
|
396
|
+
script = parse_script(NOTICE_OK, base_dir=".")
|
|
397
|
+
assert script.warnings == []
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
class TestFlowEdgeDedupe:
|
|
401
|
+
"""for/par 出口行接控制块且链上 ≥2 节点时,出口链曾被「出口行预解析 +
|
|
402
|
+
主循环 pre_tail」解析两遍,中间边注册两次——重复边被 _execute_flow 的
|
|
403
|
+
多出边 fork 语义扇出成两个分支、下游节点双跑(2026-09-12 实锤:模块内
|
|
404
|
+
投票 6 票跑成 10 票)。add_edge 现已对同 (src, tgt, condition) 去重。"""
|
|
405
|
+
|
|
406
|
+
def test_for_exit_chain_into_control_block_no_dup_edges(self):
|
|
407
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
408
|
+
text = """meta:
|
|
409
|
+
session = new
|
|
410
|
+
vars:
|
|
411
|
+
$alive = []
|
|
412
|
+
$voters = []
|
|
413
|
+
@speaker = ""
|
|
414
|
+
actors:
|
|
415
|
+
ai @a = soul:1
|
|
416
|
+
module 一轮:
|
|
417
|
+
action 公告 @notice:
|
|
418
|
+
prompt: "r"
|
|
419
|
+
action 陈述 @mind(@speaker):
|
|
420
|
+
prompt: "s"
|
|
421
|
+
scope: all
|
|
422
|
+
action 预处理 @assign:
|
|
423
|
+
out: $voters = $alive
|
|
424
|
+
action 投票 @mind(@speaker):
|
|
425
|
+
prompt: "v"
|
|
426
|
+
scope: self
|
|
427
|
+
action 收票 @assign:
|
|
428
|
+
out: $voters = remove(@speaker)
|
|
429
|
+
flow:
|
|
430
|
+
[公告]: 公告
|
|
431
|
+
[陈述]: 陈述
|
|
432
|
+
[预处理]: 预处理
|
|
433
|
+
[投票]: 投票
|
|
434
|
+
[收票]: 收票
|
|
435
|
+
[IN] -> [公告] -> for @speaker in $alive:
|
|
436
|
+
-> [陈述] ->
|
|
437
|
+
-> [预处理] -> [投票] -> par @speaker in $voters:
|
|
438
|
+
-> [收票] ->
|
|
439
|
+
-> [OUT]
|
|
440
|
+
mainflow:
|
|
441
|
+
[START] -> [一轮] -> [END]
|
|
442
|
+
"""
|
|
443
|
+
s = parse_script(text, base_dir=".")
|
|
444
|
+
flow = s.modules["一轮"].flow
|
|
445
|
+
ec = {}
|
|
446
|
+
for e in flow.edges:
|
|
447
|
+
k = (e.source, e.target, e.condition)
|
|
448
|
+
ec[k] = ec.get(k, 0) + 1
|
|
449
|
+
dups = {k: v for k, v in ec.items() if v > 1}
|
|
450
|
+
assert not dups, f"flow 中仍有重复边: {dups}"
|
|
451
|
+
expected = {
|
|
452
|
+
("[IN]", "[公告]", ""),
|
|
453
|
+
("[公告]", "__for_1__", ""),
|
|
454
|
+
("__for_1__", "[陈述]", ""),
|
|
455
|
+
("[陈述]", "__for_1__", ""), # 循环回边
|
|
456
|
+
("__for_1__", "[预处理]", ""), # for 出口边(连链首)
|
|
457
|
+
("[预处理]", "[投票]", ""), # 出口链中间边——回归点,曾被注册两次
|
|
458
|
+
("[投票]", "__par_fork_3__", ""),
|
|
459
|
+
("__par_fork_3__", "[收票]", ""),
|
|
460
|
+
("[收票]", "__par_join_2__", ""),
|
|
461
|
+
("__par_join_2__", "[OUT]", ""),
|
|
462
|
+
}
|
|
463
|
+
assert set(ec) == expected, f"边集不符: 多 {set(ec) - expected} 少 {expected - set(ec)}"
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
class TestActorToolsSemantics:
|
|
467
|
+
"""tools 字段五态语义(2026-09-12 修正:显式空列表 [] ≡ 明确禁用,
|
|
468
|
+
与「不写 tools」= 宿主默认全开严格区分——否则 ai_request 载荷
|
|
469
|
+
(tools_enabled=None/False) 无法区分两者。"""
|
|
470
|
+
|
|
471
|
+
def test_tools_five_states(self):
|
|
472
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
473
|
+
text = """meta:
|
|
474
|
+
session = new
|
|
475
|
+
actors:
|
|
476
|
+
ai @未声明 = soul:1
|
|
477
|
+
ai @显式关 = soul:1, tools: false
|
|
478
|
+
ai @显式开 = soul:1, tools: true
|
|
479
|
+
ai @空白名单 = soul:1, tools: []
|
|
480
|
+
ai @白名单 = soul:1, tools = [web_search, deep_think]
|
|
481
|
+
mainflow:
|
|
482
|
+
[START] -> [END]
|
|
483
|
+
"""
|
|
484
|
+
s = parse_script(text, base_dir=".")
|
|
485
|
+
a = s.actors["@未声明"]
|
|
486
|
+
assert a.tools_enabled is None and a.tools == [], "不写 = None(宿主默认全开)"
|
|
487
|
+
b = s.actors["@显式关"]
|
|
488
|
+
assert b.tools_enabled is False and b.tools == [], "false = 明确禁用"
|
|
489
|
+
c = s.actors["@显式开"]
|
|
490
|
+
assert c.tools_enabled is True, "true = 显式全开"
|
|
491
|
+
d = s.actors["@空白名单"]
|
|
492
|
+
assert d.tools_enabled is False and d.tools == [], "显式空列表 [] = 明确禁用(≠ 不写)"
|
|
493
|
+
e = s.actors["@白名单"]
|
|
494
|
+
assert e.tools_enabled is None and e.tools == ["web_search", "deep_think"], "列表 = 白名单"
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""pause 修复回归测试:fork 分支协程里的节点在 pause 后必须真正暂停。
|
|
2
|
+
|
|
3
|
+
修复前 pause 只取消 _main_task(asyncio cancel 不级联),fork 分支任务
|
|
4
|
+
注册在 engine._active_tasks 但没被取消——狼人杀场景表现为"暂停失败、
|
|
5
|
+
狼人节点疯狂重复"。本测试:fork 分支进入 human_wait 后 pause,
|
|
6
|
+
断言 flow_paused 且之后无新事件。
|
|
7
|
+
"""
|
|
8
|
+
import json
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import threading
|
|
12
|
+
import time
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
from conftest import ROOT, BRIDGE
|
|
17
|
+
|
|
18
|
+
PAUSE_FEMO = """meta:
|
|
19
|
+
name = pause-probe
|
|
20
|
+
session = new
|
|
21
|
+
actors:
|
|
22
|
+
human @p = soul:human, source:0
|
|
23
|
+
action ask @human(@p):
|
|
24
|
+
prompt: 请说话
|
|
25
|
+
mainflow:
|
|
26
|
+
[START] -> fork:
|
|
27
|
+
-> [H]:ask
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def run_and_pause(femo_text, wait_for="human_wait", settle=2.0):
|
|
32
|
+
p = subprocess.Popen(
|
|
33
|
+
[sys.executable, BRIDGE, "--fe4m", ROOT],
|
|
34
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
35
|
+
text=True, encoding="utf-8", errors="replace", bufsize=1,
|
|
36
|
+
)
|
|
37
|
+
events = []
|
|
38
|
+
responses = {}
|
|
39
|
+
done = threading.Event()
|
|
40
|
+
|
|
41
|
+
def drain():
|
|
42
|
+
try:
|
|
43
|
+
for line in p.stdout:
|
|
44
|
+
line = line.strip()
|
|
45
|
+
if not line:
|
|
46
|
+
continue
|
|
47
|
+
try:
|
|
48
|
+
obj = json.loads(line)
|
|
49
|
+
except json.JSONDecodeError:
|
|
50
|
+
continue
|
|
51
|
+
if obj.get("type") == "event":
|
|
52
|
+
events.append(obj)
|
|
53
|
+
elif obj.get("type") == "response":
|
|
54
|
+
responses[obj.get("id")] = obj
|
|
55
|
+
finally:
|
|
56
|
+
done.set()
|
|
57
|
+
|
|
58
|
+
t = threading.Thread(target=drain, daemon=True)
|
|
59
|
+
t.start()
|
|
60
|
+
|
|
61
|
+
def send(obj):
|
|
62
|
+
p.stdin.write(json.dumps(obj, ensure_ascii=False) + "\n")
|
|
63
|
+
p.stdin.flush()
|
|
64
|
+
|
|
65
|
+
# Job 模型协议(§12.1):run → job_start;pause → job_pause(带 job_id)
|
|
66
|
+
send({"id": 1, "cmd": "job_start",
|
|
67
|
+
"args": {"femo": femo_text, "base_dir": ROOT + r"\python",
|
|
68
|
+
"host_ref": "pytest", "script_name": "pause-probe"}})
|
|
69
|
+
deadline = time.time() + 10
|
|
70
|
+
while time.time() < deadline:
|
|
71
|
+
if any(e["event"] == wait_for for e in events):
|
|
72
|
+
break
|
|
73
|
+
time.sleep(0.1)
|
|
74
|
+
start_resp = responses.get(1) or {}
|
|
75
|
+
job_id = (start_resp.get("result") or {}).get("job_id")
|
|
76
|
+
assert isinstance(job_id, int), f"job_start 回执缺 job_id: {start_resp}"
|
|
77
|
+
send({"id": 2, "cmd": "job_pause", "args": {"job_id": job_id}})
|
|
78
|
+
time.sleep(settle)
|
|
79
|
+
send({"id": 9, "cmd": "shutdown", "args": {}})
|
|
80
|
+
time.sleep(0.3)
|
|
81
|
+
p.stdin.close()
|
|
82
|
+
try:
|
|
83
|
+
p.wait(timeout=10)
|
|
84
|
+
except subprocess.TimeoutExpired:
|
|
85
|
+
p.kill()
|
|
86
|
+
return events
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class TestPause:
|
|
90
|
+
def test_pause_cancels_fork_branch(self):
|
|
91
|
+
events = run_and_pause(PAUSE_FEMO)
|
|
92
|
+
types = [e["event"] for e in events]
|
|
93
|
+
assert "human_wait" in types, f"未进入 human_wait: {types}"
|
|
94
|
+
assert "flow_paused" in types, f"未收到 flow_paused: {types}"
|
|
95
|
+
# pause 之后不应再有业务事件(分支协程必须被取消);
|
|
96
|
+
# bridge_run_ended 是 worker 收尾,允许出现。
|
|
97
|
+
# 【A1 负断言(§12.1 升级)】取消路径不发 flow_done——旧世界取消后照发
|
|
98
|
+
# flow_done(假跑完)正是本次重构要根除的 bug,此处锁定修复。
|
|
99
|
+
idx = types.index("flow_paused")
|
|
100
|
+
tail = types[idx + 1:]
|
|
101
|
+
business = [e for e in tail if e != "bridge_run_ended"]
|
|
102
|
+
assert business == [], f"pause 后仍有业务事件(分支未停或假跑完): {business}"
|