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,92 @@
|
|
|
1
|
+
"""actor_failed 执行失败信号测试(2026-09-07 B5:失败语义归还引擎)。
|
|
2
|
+
|
|
3
|
+
锁定契约:
|
|
4
|
+
- _invoke_ai_llm 宿主分支:wait_key 信箱收到失败信封
|
|
5
|
+
{'__actor_failed__': True, kind, detail} → raise FEMOActorExecutionError(kind/detail 透传);
|
|
6
|
+
- _exec_ai 裁决:执行体失败 → notify_author{severity:'agent_giveup', message 含
|
|
7
|
+
'执行体失败'} + node_settled{outcome:'failed'} + ai_done 空台词 + flow_done
|
|
8
|
+
(剧本继续——沉默收场,不 node_retry 打回已死的执行者、不 3600s 挂等)。
|
|
9
|
+
"""
|
|
10
|
+
import asyncio
|
|
11
|
+
|
|
12
|
+
from femoCompiler.FEMO_errors import FEMOActorExecutionError
|
|
13
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
14
|
+
from femoCompiler.FEMO_runtime import FEMORunner
|
|
15
|
+
|
|
16
|
+
ACTOR_FAILED_FEMO = """meta:
|
|
17
|
+
name = actor-failed-test
|
|
18
|
+
session = new
|
|
19
|
+
actors:
|
|
20
|
+
ai @a = soul:the1stlittlesoul
|
|
21
|
+
action act @ai(@a):
|
|
22
|
+
prompt: 输出赋值
|
|
23
|
+
mainflow:
|
|
24
|
+
[START] -> act -> [END]
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
FAILURE_ENVELOPE = {'__actor_failed__': True, 'kind': 'executor_error', 'detail': '子代理死亡'}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def build_runner(events):
|
|
31
|
+
script = parse_script(ACTOR_FAILED_FEMO, base_dir=".")
|
|
32
|
+
return FEMORunner(script, base_dir=".", verbose=False,
|
|
33
|
+
event_callback=lambda t, d: events.append({"event": t, "data": d or {}}))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def ev(events, name):
|
|
37
|
+
return [e["data"] for e in events if e["event"] == name]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class TestInvokeAiLlmFailureEnvelope:
|
|
41
|
+
|
|
42
|
+
def test_failure_envelope_raises(self):
|
|
43
|
+
"""失败信封 → FEMOActorExecutionError(kind/detail 透传)。"""
|
|
44
|
+
events = []
|
|
45
|
+
runner = build_runner(events)
|
|
46
|
+
runner._host_ai_backend = True
|
|
47
|
+
|
|
48
|
+
async def _fake_wait(key, timeout=None):
|
|
49
|
+
return dict(FAILURE_ENVELOPE)
|
|
50
|
+
|
|
51
|
+
runner.engine.human_input.wait_for_input = _fake_wait
|
|
52
|
+
raised = None
|
|
53
|
+
try:
|
|
54
|
+
asyncio.run(runner._invoke_ai_llm({}, None, '@a', {}, [], 'act',
|
|
55
|
+
ai_name='@a', wait_key='wk1', emit_request=False))
|
|
56
|
+
except FEMOActorExecutionError as e:
|
|
57
|
+
raised = e
|
|
58
|
+
assert raised is not None
|
|
59
|
+
assert raised.kind == 'executor_error'
|
|
60
|
+
assert raised.detail == '子代理死亡'
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class TestExecAiActorFailedAdjudication:
|
|
64
|
+
|
|
65
|
+
def test_node_settles_failed_and_suspends_resumable(self):
|
|
66
|
+
"""执行体失败 → 通知作者(agent_giveup)+ outcome='failed' + 挂起存档可续跑
|
|
67
|
+
(走 runtime 既有暂停分支:checkpoint 落盘 + flow_paused,绝不 node_retry
|
|
68
|
+
打回已死执行者)。"""
|
|
69
|
+
events = []
|
|
70
|
+
runner = build_runner(events)
|
|
71
|
+
runner._host_ai_backend = True
|
|
72
|
+
|
|
73
|
+
async def _fake_wait(key, timeout=None):
|
|
74
|
+
return dict(FAILURE_ENVELOPE)
|
|
75
|
+
|
|
76
|
+
runner.engine.human_input.wait_for_input = _fake_wait
|
|
77
|
+
asyncio.run(runner.run_async())
|
|
78
|
+
|
|
79
|
+
notifies = ev(events, 'notify_author')
|
|
80
|
+
assert any(n.get('severity') == 'agent_giveup' and '执行体失败' in str(n.get('message', ''))
|
|
81
|
+
for n in notifies), f'notify_author 缺失: {notifies}'
|
|
82
|
+
|
|
83
|
+
settled = ev(events, 'node_settled')
|
|
84
|
+
assert settled and settled[0].get('outcome') == 'failed', f'node_settled: {settled}'
|
|
85
|
+
|
|
86
|
+
dones = ev(events, 'ai_done')
|
|
87
|
+
assert dones and dones[0].get('output') == ''
|
|
88
|
+
|
|
89
|
+
# 挂起存档(可续跑)= checkpoint 落盘 + flow_paused;断点续跑=换新执行体重演
|
|
90
|
+
assert ev(events, 'checkpoint'), '断点未落盘(无 checkpoint)'
|
|
91
|
+
assert ev(events, 'flow_paused'), '未挂起(无 flow_paused)'
|
|
92
|
+
assert not ev(events, 'node_retry'), '不应向已死执行者发 node_retry'
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""编译期 warning 桶测试(2026-09-07 warning 桶落地)。
|
|
2
|
+
|
|
3
|
+
契约:
|
|
4
|
+
- validate_flow_reentry 的「分支数爆炸回流」模式不再阻断(原 raise 已退役),
|
|
5
|
+
编译放行,提示收集进 script.warnings({'where', 'message'}),随
|
|
6
|
+
check/job_start 回执上浮宿主;
|
|
7
|
+
- 干净剧本 warnings 为空——warning 收集纯增量,不影响既有编译产物。
|
|
8
|
+
"""
|
|
9
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
10
|
+
|
|
11
|
+
# 回流模式:[a] 有两条无条件出边([a]->[b] / [a]->[c]),且流程内部有边
|
|
12
|
+
# 回到 [a]([b]->[a])——原 raise 场景,现应产生 warning 而编译放行。
|
|
13
|
+
REENTRY_FEMO = """meta:
|
|
14
|
+
name = warn-reentry
|
|
15
|
+
session = new
|
|
16
|
+
|
|
17
|
+
vars:
|
|
18
|
+
count = 0
|
|
19
|
+
|
|
20
|
+
action noop @assign:
|
|
21
|
+
out:
|
|
22
|
+
count += 1
|
|
23
|
+
|
|
24
|
+
mainflow:
|
|
25
|
+
[a]: noop
|
|
26
|
+
[b]: noop
|
|
27
|
+
[c]: noop
|
|
28
|
+
[START] -> [a]
|
|
29
|
+
[a] -> [b]
|
|
30
|
+
[a] -> [c]
|
|
31
|
+
[b] -> [a]
|
|
32
|
+
[c] -> [END]
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
CLEAN_FEMO = """meta:
|
|
36
|
+
name = warn-clean
|
|
37
|
+
session = new
|
|
38
|
+
|
|
39
|
+
vars:
|
|
40
|
+
count = 0
|
|
41
|
+
|
|
42
|
+
action noop @assign:
|
|
43
|
+
out:
|
|
44
|
+
count += 1
|
|
45
|
+
|
|
46
|
+
mainflow:
|
|
47
|
+
[a]: noop
|
|
48
|
+
[START] -> [a]
|
|
49
|
+
[a] -> [END]
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_flow_reentry_compiles_and_warns():
|
|
54
|
+
script = parse_script(REENTRY_FEMO, base_dir='.')
|
|
55
|
+
assert script.flow is not None and script.flow.nodes, "编译必须放行(不阻断)"
|
|
56
|
+
assert len(script.warnings) == 1
|
|
57
|
+
w = script.warnings[0]
|
|
58
|
+
assert w['where'] == 'mainflow'
|
|
59
|
+
assert '[a]' in w['message']
|
|
60
|
+
assert '分支数会爆炸' in w['message']
|
|
61
|
+
assert '加空节点' in w['message']
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_clean_script_has_no_warnings():
|
|
65
|
+
script = parse_script(CLEAN_FEMO, base_dir='.')
|
|
66
|
+
assert script.warnings == []
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# @assign 空 out(2026-09-07 用户拍板):赋值节点什么都不赋值 = 惰性死配置,
|
|
70
|
+
# 编译放行但应产生 warning(不 raise——运行时空过无害,多半不是本意而已)。
|
|
71
|
+
ASSIGN_EMPTY_OUT_FEMO = """meta:
|
|
72
|
+
name = warn-assign-empty
|
|
73
|
+
session = new
|
|
74
|
+
|
|
75
|
+
vars:
|
|
76
|
+
count = 0
|
|
77
|
+
|
|
78
|
+
action do_nothing @assign:
|
|
79
|
+
|
|
80
|
+
mainflow:
|
|
81
|
+
[a]: do_nothing
|
|
82
|
+
[START] -> [a]
|
|
83
|
+
[a] -> [END]
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_assign_empty_out_warns():
|
|
88
|
+
script = parse_script(ASSIGN_EMPTY_OUT_FEMO, base_dir='.')
|
|
89
|
+
hits = [w for w in script.warnings if 'out: 为空' in w['message']]
|
|
90
|
+
assert len(hits) == 1, f"应恰有 1 条 @assign 空 out 警告,实际 {script.warnings}"
|
|
91
|
+
assert hits[0]['where'] == 'action "do_nothing"'
|
|
92
|
+
assert 'do_nothing' in hits[0]['message']
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_assign_with_out_no_warning():
|
|
96
|
+
# 有 out 的 @assign 不应触发该警告(CLEAN_FEMO 的 noop 带out,零警告)。
|
|
97
|
+
script = parse_script(CLEAN_FEMO, base_dir='.')
|
|
98
|
+
assert not [w for w in script.warnings if 'out: 为空' in w['message']]
|
|
99
|
+
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""DebugLogBus 实时调试日志契约测试(2026-09-08 调试日志接口)。
|
|
2
|
+
|
|
3
|
+
消费方接口锁定(FakeHost 干跑,零 LLM / 零网络):
|
|
4
|
+
- 订阅者抛异常不影响其他订阅者(响亮拦截,铁律:不静默)
|
|
5
|
+
- unsubscribe 之后不再收到事件;snapshot 与事件序一致
|
|
6
|
+
- @func 输出(入参/结果)与 @assign/@func 的 out 声明都要上总线
|
|
7
|
+
|
|
8
|
+
(2026-09-13:run_start/run_end 序、跨 run assign 归属两条用例随夹具剧本
|
|
9
|
+
femoExamples/debug-selftest.femo 退役——夹具在工作区清理中删除,用例原文
|
|
10
|
+
移入 dsh/mytrashbin/femo-plugin-retired-debugger-tests-20260913/。)
|
|
11
|
+
"""
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
|
|
17
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
18
|
+
|
|
19
|
+
import femo_debugger as fd
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_subscriber_exception_does_not_poison_bus():
|
|
23
|
+
bus = fd.DebugLogBus()
|
|
24
|
+
got = []
|
|
25
|
+
|
|
26
|
+
def boom(rec):
|
|
27
|
+
raise RuntimeError('订阅者炸了')
|
|
28
|
+
|
|
29
|
+
bus.subscribe(boom)
|
|
30
|
+
bus.subscribe(got.append)
|
|
31
|
+
rec = bus.emit('node_start', node='x', node_type='ai')
|
|
32
|
+
assert len(got) == 1 and got[0] is rec # 炸的订阅者不影响其他订阅者
|
|
33
|
+
assert bus.snapshot()[-1]['kind'] == 'node_start' # 缓冲照常追加
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_unsubscribe_and_snapshot():
|
|
37
|
+
bus = fd.DebugLogBus()
|
|
38
|
+
seen = []
|
|
39
|
+
sub = bus.subscribe(seen.append)
|
|
40
|
+
bus.emit('edge', src='a', tgt='b')
|
|
41
|
+
bus.unsubscribe(sub)
|
|
42
|
+
bus.emit('edge', src='b', tgt='c')
|
|
43
|
+
assert len(seen) == 1
|
|
44
|
+
assert len(bus.snapshot()) == 2
|
|
45
|
+
assert bus.snapshot()[0]['src'] == 'a'
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
FUNC_SCRIPT = """meta:
|
|
49
|
+
name = func-dbg
|
|
50
|
+
session = new
|
|
51
|
+
|
|
52
|
+
vars:
|
|
53
|
+
label = ""
|
|
54
|
+
n = 0
|
|
55
|
+
|
|
56
|
+
code:
|
|
57
|
+
helpers = file:"helpers.py"
|
|
58
|
+
|
|
59
|
+
action mk @func(helpers.make_label):
|
|
60
|
+
in: base = label
|
|
61
|
+
out: label
|
|
62
|
+
|
|
63
|
+
action bump @assign:
|
|
64
|
+
out: n += 1
|
|
65
|
+
|
|
66
|
+
mainflow:
|
|
67
|
+
[mk]: mk
|
|
68
|
+
[bump]: bump
|
|
69
|
+
[START] -> [mk]
|
|
70
|
+
[mk] -> [bump]
|
|
71
|
+
[bump] -> [END]
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_func_result_and_action_outs(tmp_path):
|
|
76
|
+
"""@func 输出(入参/结果)与 @assign/@func 的 out 声明都要上总线。"""
|
|
77
|
+
(tmp_path / 'helpers.py').write_text(
|
|
78
|
+
'def make_label(base):\n'
|
|
79
|
+
' return (base or "empty") + "!"\n',
|
|
80
|
+
encoding='utf-8')
|
|
81
|
+
(tmp_path / 's.femo').write_text(FUNC_SCRIPT, encoding='utf-8')
|
|
82
|
+
|
|
83
|
+
bus = fd.DebugLogBus()
|
|
84
|
+
seen = []
|
|
85
|
+
bus.subscribe(seen.append)
|
|
86
|
+
with fd.DBSandbox(verbose=False):
|
|
87
|
+
script = fd.load_script(str(tmp_path / 's.femo'))
|
|
88
|
+
result = fd.run_once(script, seed=1, overrides={}, assign_prob=1.0,
|
|
89
|
+
max_steps=20, quiet=True, bus=bus, run_index=1)
|
|
90
|
+
|
|
91
|
+
assert result['outcome'] == 'completed'
|
|
92
|
+
kinds = [r['kind'] for r in seen]
|
|
93
|
+
# @func:out 声明 + 函数结果(引擎 func_result 事件接线)
|
|
94
|
+
ao_func = next(r for r in seen if r['kind'] == 'action_outs'
|
|
95
|
+
and r.get('node_type') == 'func')
|
|
96
|
+
assert ao_func['exprs'] == ['label']
|
|
97
|
+
fr = next(r for r in seen if r['kind'] == 'func_result')
|
|
98
|
+
assert fr['node'] and 'output' in fr and 'func_input' in fr
|
|
99
|
+
# @assign:out 声明(赋值表达式)+ 实际落值 diff
|
|
100
|
+
ao_assign = next(r for r in seen if r['kind'] == 'action_outs'
|
|
101
|
+
and r.get('node_type') == 'assign')
|
|
102
|
+
assert ao_assign['exprs'] == ['n += 1']
|
|
103
|
+
a = next(r for r in seen if r['kind'] == 'assign' and r['var'] == 'n')
|
|
104
|
+
assert a['old'] == '0' and a['new'] == '1'
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if __name__ == '__main__':
|
|
108
|
+
sys.exit(pytest.main([__file__, '-v']))
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""femo_debugger 模块单测(--module / wrap_module_test)契约测试。
|
|
2
|
+
|
|
3
|
+
锁定(2026-09-12 模块调试三坑修复):
|
|
4
|
+
- resolve_module_def / wrap_module_test 支持嵌套模块点路径('Outer.Inner'),
|
|
5
|
+
未知模块响亮 ValueError(列出顶层可用名),容忍 '&' 前缀
|
|
6
|
+
- 引擎 _run_module 顶层点路径 fallback:嵌套模块经合成 wrapper 真实跑通
|
|
7
|
+
(回归锁定:原实现顶层只查顶层名,点路径 print+return 静默假跑——流程
|
|
8
|
+
报 completed,模块一个节点都没执行)
|
|
9
|
+
- module 模式终报口径:未达节点按被测模块自己的 flow 算(原实现固定看被
|
|
10
|
+
wrapper 换掉的 script.flow——全是结构节点,模块死分支永远报不出来)
|
|
11
|
+
- max_steps 结局语义:跑满步数预算未停 =「可能是无限循环」,退出码 0 非
|
|
12
|
+
错误(cli_exit_code 与 max_steps 消息口径);无 [OUT]/[BREAK] 出口的
|
|
13
|
+
持续循环型模块被静态识别(module_has_out=False)
|
|
14
|
+
|
|
15
|
+
(2026-09-13:依赖 femoExamples/group-chat.femo 的两条用例
|
|
16
|
+
test_module_has_out_static / test_cli_groupchat_module_max_steps_exit_zero
|
|
17
|
+
随夹具退役——夹具在工作区清理中删除,用例原文移入
|
|
18
|
+
dsh/mytrashbin/femo-plugin-retired-debugger-tests-20260913/。)
|
|
19
|
+
"""
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
|
|
23
|
+
import pytest
|
|
24
|
+
|
|
25
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
26
|
+
sys.path.insert(0, os.path.join(
|
|
27
|
+
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'femo2host', 'femoToolcall'))
|
|
28
|
+
|
|
29
|
+
import femo_debugger as fd
|
|
30
|
+
|
|
31
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
32
|
+
|
|
33
|
+
# 嵌套模块内联剧本:外层含 vars/assign action + 嵌套内层;内层含 AI 节点
|
|
34
|
+
# (FakeHost 替答,零 LLM)+ 模块 local out。外层 flow 不被执行(wrapper
|
|
35
|
+
# 直进内层),只作嵌套定义的载体。
|
|
36
|
+
NESTED_SCRIPT = '''meta:
|
|
37
|
+
name = 嵌套模块调试单测
|
|
38
|
+
session = new
|
|
39
|
+
|
|
40
|
+
vars:
|
|
41
|
+
hits = 0
|
|
42
|
+
|
|
43
|
+
actors:
|
|
44
|
+
ai @bot = soul:AI助手
|
|
45
|
+
|
|
46
|
+
module 外层:
|
|
47
|
+
vars:
|
|
48
|
+
outer_mark = ""
|
|
49
|
+
action outer_assign @assign:
|
|
50
|
+
out: outer_mark = "hit"
|
|
51
|
+
module 内层:
|
|
52
|
+
vars:
|
|
53
|
+
inner_mark = ""
|
|
54
|
+
action 内层发言 @ai(@bot):
|
|
55
|
+
prompt: "嵌套模块自测发言。"
|
|
56
|
+
out: inner_mark(string, "标记")
|
|
57
|
+
flow:
|
|
58
|
+
[IN] -> 内层发言 -> [OUT]
|
|
59
|
+
flow:
|
|
60
|
+
[IN] -> outer_assign -> [OUT]
|
|
61
|
+
|
|
62
|
+
mainflow:
|
|
63
|
+
[START] -> [END]
|
|
64
|
+
'''
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _write_nested(tmp_path):
|
|
68
|
+
p = tmp_path / 'nested-selftest.femo'
|
|
69
|
+
p.write_text(NESTED_SCRIPT, encoding='utf-8')
|
|
70
|
+
return str(p)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _load(tmp_path, path=None):
|
|
74
|
+
with fd.DBSandbox(verbose=False):
|
|
75
|
+
return fd.load_script(path or _write_nested(tmp_path))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# ── 坑1a:点路径解析(调试器侧) ──
|
|
79
|
+
|
|
80
|
+
def test_resolve_module_def_dotted_and_amp(tmp_path):
|
|
81
|
+
script = _load(tmp_path)
|
|
82
|
+
assert fd.resolve_module_def(script, '外层.内层').name == '内层'
|
|
83
|
+
assert fd.resolve_module_def(script, '&外层').name == '外层'
|
|
84
|
+
assert fd.resolve_module_def(script, '外层').name == '外层'
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_resolve_module_def_unknown_loud(tmp_path):
|
|
88
|
+
script = _load(tmp_path)
|
|
89
|
+
with pytest.raises(ValueError, match='未定义'):
|
|
90
|
+
fd.resolve_module_def(script, '外层.不存在')
|
|
91
|
+
with pytest.raises(ValueError, match='未定义'):
|
|
92
|
+
fd.resolve_module_def(script, '根本没这模块')
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_wrap_module_test_accepts_dotted(tmp_path):
|
|
96
|
+
script = _load(tmp_path)
|
|
97
|
+
fd.wrap_module_test(script, '&外层.内层')
|
|
98
|
+
mod_node = script.flow.nodes.get('[MT_MOD]')
|
|
99
|
+
assert mod_node is not None and mod_node.module_ref == '外层.内层'
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# ── 坑1b:引擎 _run_module 顶层点路径 fallback(端到端,FakeHost 干跑) ──
|
|
103
|
+
|
|
104
|
+
def test_nested_module_e2e_run(tmp_path):
|
|
105
|
+
p = _write_nested(tmp_path)
|
|
106
|
+
bus = fd.DebugLogBus()
|
|
107
|
+
with fd.DBSandbox(verbose=False):
|
|
108
|
+
script = fd.load_script(p)
|
|
109
|
+
fd.wrap_module_test(script, '外层.内层')
|
|
110
|
+
result = fd.run_once(script, seed=7, overrides={}, assign_prob=1.0,
|
|
111
|
+
max_steps=50, quiet=True, bus=bus)
|
|
112
|
+
assert result['outcome'] == 'completed', result.get('error')
|
|
113
|
+
recs = bus.snapshot()
|
|
114
|
+
node_starts = [r.get('node') for r in recs if r.get('kind') == 'node_start']
|
|
115
|
+
assert '[内层发言]' in node_starts # 模块自己的 flow 真跑了(节点 id 带方括号)
|
|
116
|
+
assigns = [r.get('var') for r in recs if r.get('kind') == 'assign']
|
|
117
|
+
assert 'inner_mark' in assigns # 模块 local 帧真实落值
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# ── 坑2:module 模式终报口径(未达节点按被测模块自己的 flow) ──
|
|
121
|
+
|
|
122
|
+
def test_unreached_nodes_module_mode_scope(tmp_path):
|
|
123
|
+
script = _load(tmp_path)
|
|
124
|
+
fd.wrap_module_test(script, '外层.内层')
|
|
125
|
+
tracker = fd.CoverageTracker() # 零访问:全部作者节点未达
|
|
126
|
+
# 旧行为对照:mainflow 口径(被 wrapper 换掉,全是结构节点)→ 永远空
|
|
127
|
+
assert fd._unreached_nodes(tracker, script) == []
|
|
128
|
+
# 新口径:module 模式按被测模块自己的 flow 算([IN]/[OUT] 结构节点除外;
|
|
129
|
+
# 裸 action 名的节点 id 带方括号)
|
|
130
|
+
assert fd._unreached_nodes(tracker, script, '外层.内层') == ['[内层发言]']
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
# ── 坑3:max_steps 语义 + 持续循环型静态识别 ──
|
|
134
|
+
|
|
135
|
+
def test_cli_exit_code_max_steps_is_zero():
|
|
136
|
+
R = lambda o: {'outcome': o}
|
|
137
|
+
assert fd.cli_exit_code([R('max_steps')]) == 0
|
|
138
|
+
assert fd.cli_exit_code([R('completed'), R('max_steps')]) == 0
|
|
139
|
+
assert fd.cli_exit_code([R('completed'), R('error')]) == 2
|
|
140
|
+
assert fd.cli_exit_code([R('exception')]) == 1
|
|
141
|
+
assert fd.cli_exit_code([R('completed')]) == 0
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""错误三桶分类测试(2026-08-18 模块化)。
|
|
2
|
+
|
|
3
|
+
- classify_error:FEMOTransientError → AGENT;其余(FEMOConfigError/编译类/未知)→ FATAL
|
|
4
|
+
- handle_error:FATAL → emit flow_error;AGENT/TOLERANT 不 emit
|
|
5
|
+
- bridge check 命令:编译成功 ok / 失败带错误细节
|
|
6
|
+
"""
|
|
7
|
+
import json
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import threading
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from femoCompiler.FEMO_errors import (
|
|
15
|
+
ErrorCategory,
|
|
16
|
+
FEMOConfigError,
|
|
17
|
+
FEMOTransientError,
|
|
18
|
+
classify_error,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TestClassifyError:
|
|
23
|
+
def test_transient_is_agent(self):
|
|
24
|
+
assert classify_error(FEMOTransientError("限流")) == ErrorCategory.AGENT
|
|
25
|
+
|
|
26
|
+
def test_config_is_fatal(self):
|
|
27
|
+
assert classify_error(FEMOConfigError("无 key")) == ErrorCategory.FATAL
|
|
28
|
+
|
|
29
|
+
def test_compile_error_is_fatal(self):
|
|
30
|
+
assert classify_error(SyntaxError("bad syntax")) == ErrorCategory.FATAL
|
|
31
|
+
assert classify_error(ValueError("变量未声明")) == ErrorCategory.FATAL
|
|
32
|
+
|
|
33
|
+
def test_unknown_is_fatal(self):
|
|
34
|
+
assert classify_error(RuntimeError("未知")) == ErrorCategory.FATAL
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
GOOD_FEMO = """meta:
|
|
38
|
+
name = check-ok
|
|
39
|
+
session = new
|
|
40
|
+
actors:
|
|
41
|
+
ai @a = soul:the1stlittlesoul
|
|
42
|
+
action act @ai(@a):
|
|
43
|
+
prompt: hi
|
|
44
|
+
mainflow:
|
|
45
|
+
[START] -> act -> [END]
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
BAD_FEMO = """meta:
|
|
49
|
+
name = check-bad
|
|
50
|
+
session = new
|
|
51
|
+
actors:
|
|
52
|
+
ai @a = soul:the1stlittlesoul
|
|
53
|
+
action act @ai(@a):
|
|
54
|
+
prompt: hi
|
|
55
|
+
mainflow:
|
|
56
|
+
[START] -> par @a:
|
|
57
|
+
-> act ->
|
|
58
|
+
-> [END]
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def bridge_check(femo_text):
|
|
63
|
+
"""起 bridge 进程发 check 命令,返回 (ok, result_or_error)。"""
|
|
64
|
+
import os
|
|
65
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
66
|
+
p = subprocess.Popen(
|
|
67
|
+
[sys.executable, os.path.join(ROOT, "hostAdapter", "dshAdapter", "python", "femo_bridge.py"), "--fe4m", ROOT],
|
|
68
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
69
|
+
text=True, encoding="utf-8", errors="replace", bufsize=1,
|
|
70
|
+
)
|
|
71
|
+
response = {}
|
|
72
|
+
stop = threading.Event()
|
|
73
|
+
|
|
74
|
+
def drain():
|
|
75
|
+
try:
|
|
76
|
+
for line in p.stdout:
|
|
77
|
+
line = line.strip()
|
|
78
|
+
if not line:
|
|
79
|
+
continue
|
|
80
|
+
try:
|
|
81
|
+
obj = json.loads(line)
|
|
82
|
+
except json.JSONDecodeError:
|
|
83
|
+
continue
|
|
84
|
+
if obj.get("type") == "response" and obj.get("id") == 1:
|
|
85
|
+
response["value"] = obj
|
|
86
|
+
stop.set()
|
|
87
|
+
finally:
|
|
88
|
+
stop.set()
|
|
89
|
+
|
|
90
|
+
t = threading.Thread(target=drain, daemon=True)
|
|
91
|
+
t.start()
|
|
92
|
+
p.stdin.write(json.dumps({"id": 1, "cmd": "check", "args": {"femo": femo_text}}) + "\n")
|
|
93
|
+
p.stdin.flush()
|
|
94
|
+
stop.wait(20)
|
|
95
|
+
p.stdin.write(json.dumps({"id": 2, "cmd": "shutdown", "args": {}}) + "\n")
|
|
96
|
+
p.stdin.flush()
|
|
97
|
+
import time
|
|
98
|
+
time.sleep(0.3)
|
|
99
|
+
p.stdin.close()
|
|
100
|
+
try:
|
|
101
|
+
p.wait(timeout=10)
|
|
102
|
+
except subprocess.TimeoutExpired:
|
|
103
|
+
p.kill()
|
|
104
|
+
return response.get("value", {})
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class TestBridgeCheck:
|
|
108
|
+
def test_check_ok(self):
|
|
109
|
+
resp = bridge_check(GOOD_FEMO)
|
|
110
|
+
assert resp.get("ok") is True
|
|
111
|
+
assert resp.get("result", {}).get("actions") == 1
|
|
112
|
+
|
|
113
|
+
def test_check_compile_error(self):
|
|
114
|
+
resp = bridge_check(BAD_FEMO)
|
|
115
|
+
assert resp.get("ok") is False
|
|
116
|
+
err = resp.get("error", "")
|
|
117
|
+
assert "语法错误" in err, f"错误应含细节: {err}"
|