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,143 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""vars/model.py — 声明模型 + 路径模型 + ScopeTable 单测(施工清单 v2 §3.1)。"""
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from femoCompiler.vars.model import (
|
|
6
|
+
Expr, FEMOVariableError, Literal, VarDecl, build_scope_table, parse_var_path,
|
|
7
|
+
split_spec_name,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TestSplitSpecName:
|
|
12
|
+
def test_plain(self):
|
|
13
|
+
assert split_spec_name('x') == ('x', False)
|
|
14
|
+
|
|
15
|
+
def test_dollar(self):
|
|
16
|
+
assert split_spec_name('$s') == ('s', True)
|
|
17
|
+
|
|
18
|
+
def test_dollar_at(self):
|
|
19
|
+
assert split_spec_name('$@选中的人') == ('@选中的人', True)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TestParseVarPath:
|
|
23
|
+
def test_plain(self):
|
|
24
|
+
p = parse_var_path('day')
|
|
25
|
+
assert p.root == 'day' and p.keys == () and p.is_plain
|
|
26
|
+
|
|
27
|
+
def test_literal_attr(self):
|
|
28
|
+
p = parse_var_path('hp.@wolfClaire')
|
|
29
|
+
assert p.root == 'hp'
|
|
30
|
+
assert p.keys == (Literal('@wolfClaire'),)
|
|
31
|
+
assert not p.is_plain
|
|
32
|
+
|
|
33
|
+
def test_nested_attrs(self):
|
|
34
|
+
p = parse_var_path('a.b.c')
|
|
35
|
+
assert p.keys == (Literal('b'), Literal('c'))
|
|
36
|
+
|
|
37
|
+
def test_int_index(self):
|
|
38
|
+
p = parse_var_path('items[0]')
|
|
39
|
+
assert p.keys == (Literal(0),)
|
|
40
|
+
|
|
41
|
+
def test_negative_int_index(self):
|
|
42
|
+
p = parse_var_path('items[-1]')
|
|
43
|
+
assert p.keys == (Literal(-1),)
|
|
44
|
+
|
|
45
|
+
def test_quoted_key(self):
|
|
46
|
+
p = parse_var_path('m["key"]')
|
|
47
|
+
assert p.keys == (Literal('key'),)
|
|
48
|
+
|
|
49
|
+
def test_dynamic_key(self):
|
|
50
|
+
p = parse_var_path('task_list[@coder]')
|
|
51
|
+
assert p.keys == (Expr('@coder'),)
|
|
52
|
+
|
|
53
|
+
def test_mixed(self):
|
|
54
|
+
p = parse_var_path('hp[@coder].x')
|
|
55
|
+
assert p.root == 'hp'
|
|
56
|
+
assert p.keys == (Expr('@coder'), Literal('x'))
|
|
57
|
+
|
|
58
|
+
def test_empty_raises(self):
|
|
59
|
+
with pytest.raises(FEMOVariableError):
|
|
60
|
+
parse_var_path(' ')
|
|
61
|
+
|
|
62
|
+
def test_unclosed_bracket_raises(self):
|
|
63
|
+
with pytest.raises(FEMOVariableError):
|
|
64
|
+
parse_var_path('a[0')
|
|
65
|
+
|
|
66
|
+
def test_empty_dot_segment_raises(self):
|
|
67
|
+
with pytest.raises(FEMOVariableError):
|
|
68
|
+
parse_var_path('a..b')
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def build_table():
|
|
72
|
+
return build_scope_table(
|
|
73
|
+
global_vars={'day': 0, 'x': 'gx', 'roles': {}, 'speaker': '', '$s': '',
|
|
74
|
+
'hp': {'@wolf': 100}},
|
|
75
|
+
module_vars={
|
|
76
|
+
'NightPhase': {'x': 0, 'dead': []},
|
|
77
|
+
'Outer': {'ox': 1},
|
|
78
|
+
'Outer.Inner': {'x': 'inner-x'},
|
|
79
|
+
'Helper': {'h': 1},
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class TestScopeTable:
|
|
84
|
+
def test_lookup_global(self):
|
|
85
|
+
assert build_table().lookup('day', ()) is not None
|
|
86
|
+
assert build_table().lookup('day', ()).initial == 0
|
|
87
|
+
|
|
88
|
+
def test_lookup_module(self):
|
|
89
|
+
t = build_table()
|
|
90
|
+
assert t.lookup('x', ('NightPhase',)).owner == 'NightPhase'
|
|
91
|
+
|
|
92
|
+
def test_lookup_nested_chain(self):
|
|
93
|
+
"""Inner 内查 x:命中 Inner 自己(shadowing);查 ox:命中 Outer。"""
|
|
94
|
+
t = build_table()
|
|
95
|
+
chain = t.module_def_chain('Outer.Inner')
|
|
96
|
+
assert chain == ('Outer', 'Inner')
|
|
97
|
+
assert t.lookup('x', chain).owner == 'Outer.Inner'
|
|
98
|
+
assert t.lookup('ox', chain).owner == 'Outer'
|
|
99
|
+
|
|
100
|
+
def test_lookup_undeclared_none(self):
|
|
101
|
+
assert build_table().lookup('nope', ()) is None
|
|
102
|
+
|
|
103
|
+
def test_word_lexical_isolation(self):
|
|
104
|
+
"""拍板 6 词法作用域:Helper(全局模块)的定义链下看不到 Outer 的 ox。"""
|
|
105
|
+
t = build_table()
|
|
106
|
+
assert t.lookup('ox', t.module_def_chain('Helper')) is None
|
|
107
|
+
# Outer 内可见
|
|
108
|
+
assert t.lookup('ox', t.module_def_chain('Outer')) is not None
|
|
109
|
+
|
|
110
|
+
def test_shared_decl(self):
|
|
111
|
+
t = build_table()
|
|
112
|
+
assert 's' in t.shared_names()
|
|
113
|
+
assert 'day' not in t.shared_names()
|
|
114
|
+
|
|
115
|
+
def test_duplicate_spec_name_raises(self):
|
|
116
|
+
# 重复声明 = 编译期语法层错误 → SyntaxError(与 parse_script
|
|
117
|
+
# 编译期校验家族一致;FEMO_parser 的旧产线同样抛 SyntaxError)
|
|
118
|
+
with pytest.raises(SyntaxError):
|
|
119
|
+
build_scope_table(global_vars={'x': 1, '$x': 2}, module_vars={})
|
|
120
|
+
|
|
121
|
+
def test_same_name_different_owner_ok(self):
|
|
122
|
+
"""不同 owner 的同名声明合法(shadowing 基础)。"""
|
|
123
|
+
t = build_table() # global x + NightPhase x + Outer.Inner x 并存
|
|
124
|
+
assert t.lookup('x', ()) .owner is None
|
|
125
|
+
assert t.lookup('x', ('NightPhase',)).owner == 'NightPhase'
|
|
126
|
+
|
|
127
|
+
def test_initials_shared_excludes_context(self):
|
|
128
|
+
t = build_table()
|
|
129
|
+
assert t.initials_shared() == {'s': ''}
|
|
130
|
+
|
|
131
|
+
def test_initials_global_excludes_shared(self):
|
|
132
|
+
t = build_table()
|
|
133
|
+
assert 's' not in t.initials_global_context()
|
|
134
|
+
assert t.initials_global_context()['day'] == 0
|
|
135
|
+
|
|
136
|
+
def test_module_initials_excludes_shared(self):
|
|
137
|
+
t = build_scope_table(global_vars={}, module_vars={'M': {'a': 1, '$b': 2}})
|
|
138
|
+
assert t.module_initials('M') == {'a': 1}
|
|
139
|
+
|
|
140
|
+
def test_var_decl_frozen(self):
|
|
141
|
+
d = VarDecl(name='x', shared=False, owner=None, initial=1)
|
|
142
|
+
with pytest.raises(Exception):
|
|
143
|
+
d.name = 'y'
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
"""R4 断点续跑端到端(bridge 子进程两级 run)——施工清单 v2 §8.2 R4 验收行。
|
|
2
|
+
|
|
3
|
+
覆盖场景:
|
|
4
|
+
1. test_resume_variables_consistent —— 暂停→恢复→变量一致:
|
|
5
|
+
run1 跑到 human 节点等待时 stop(production「暂停/暂停」同款链路:
|
|
6
|
+
stop → 协程 cancel → flow_paused;checkpoint 事件已在进入节点时上行),
|
|
7
|
+
从事件流提取最后一次 checkpoint 载荷(checkpoints/session_id/state);
|
|
8
|
+
run2 带 resume_state 直启,续跑点之后 @assign 的 assign_result 输出应
|
|
9
|
+
建立在暂停前的变量值上(counter=1 → +=1 → 2;未恢复则是 1)。
|
|
10
|
+
※ 验收行原文"AI 失败暂停"在单测环境以 human 节点暂停替代:AI 失败暂停
|
|
11
|
+
(FEMOTransient 重试用尽 → pause_manager)与 human 等待中断后恢复,走的是
|
|
12
|
+
同一条 checkpoint→宿主存档→resume_state→分支直启链路,暂停点差异不触及
|
|
13
|
+
本测试验证的变量世界恢复语义;真·AI 失败场景留给 3081 手工验收。
|
|
14
|
+
2. test_resume_join_re_sign_in —— join 签到后暂停重签到:
|
|
15
|
+
par 式 fork 两分支,A 线瞬间到 join 签到挂起、B 线停在 human。恢复后
|
|
16
|
+
A 从 join 节点直启(重签到,merge 幂等)、B 从 human 续跑后签到,凑齐
|
|
17
|
+
merge 出新 task,join 出口节点只跑一遍(assign_result 恰好一次)。
|
|
18
|
+
同时覆盖 idgen.restore_from 防撞号:merge 产物 task 号必须续自快照
|
|
19
|
+
最大号+1(不续号会与 fork 子任务 t1/t2 撞号)。
|
|
20
|
+
3. test_resume_module_fork —— 模块内 fork+human 暂停:
|
|
21
|
+
恢复直启按 mod_stack 顶进入模块 flow(_flow_for_stack),模块内 join
|
|
22
|
+
照常凑齐、模块内 action 照常执行(ijmark 的 assign_result 出现)。
|
|
23
|
+
4. test_old_snapshot_loud_invalidated —— 旧快照 VERSION 响亮作废:
|
|
24
|
+
resume_state.state 给旧格式(无 version 的平铺 dict)→ FEMORunner 构造期
|
|
25
|
+
restore_state 抛 ValueError(文案含「作废」),bridge 以 flow_error +
|
|
26
|
+
bridge_run_ended ok=false 响亮收场——绝不静默按 fresh 开演。
|
|
27
|
+
|
|
28
|
+
铁律:暂停一律用 pause 命令(job_pause;与宿主「暂停」按钮同链路),绝不 kill
|
|
29
|
+
进程伪造中断——那样事件流的最后 checkpoint 与真实宿主行为不一致。
|
|
30
|
+
|
|
31
|
+
【引擎既有缺陷留痕(2026-09-05 R4 期间实锤,非本测试引入——git stash 验证
|
|
32
|
+
挂死与 R4 改动无关)】fork 场景下 stop 后 run() 不返回:human 等待分支卡在
|
|
33
|
+
HumanInputManager.wait_for_input 的 loop.run_in_executor(None, event.wait,
|
|
34
|
+
3600)——task.cancel() 对已开始运行的 executor 任务取消失败(Task._must_cancel
|
|
35
|
+
延迟到 future 完成才注入),主协程 _run_fork 的 gather 等分支终止 → 整个
|
|
36
|
+
asyncio.run 假死至 3600s 超时。无 fork 剧本(主协程直接停在 human 等待)无此
|
|
37
|
+
问题(test 1/4 实证可退)。后果:stop 后 10s 内立刻续跑会撞 bridge 串行锁
|
|
38
|
+
拒绝(bridge 单跑守卫只宽限 10s)。场景 2/3 因此采用双进程形态(run1 shutdown
|
|
39
|
+
硬退 + run2 新进程带 resume_state 恢复——production 进程崩溃重启恢复同链路);
|
|
40
|
+
缺陷修复记档待猫猫拍板(候选方向:stop 时对 wait_for_input 的 event 全量 set,
|
|
41
|
+
或 wait_for_input 改 asyncio.Event 原生等待)。
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
import json
|
|
45
|
+
import os
|
|
46
|
+
import subprocess
|
|
47
|
+
import sys
|
|
48
|
+
import threading
|
|
49
|
+
import time
|
|
50
|
+
|
|
51
|
+
import pytest
|
|
52
|
+
|
|
53
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
54
|
+
if ROOT not in sys.path:
|
|
55
|
+
sys.path.insert(0, ROOT)
|
|
56
|
+
|
|
57
|
+
BRIDGE = os.path.join(ROOT, "hostAdapter", "dshAdapter", "python", "femo_bridge.py")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class BridgeSession:
|
|
61
|
+
"""一个 bridge 子进程会话:NDJSON 收发 + 事件累积。
|
|
62
|
+
|
|
63
|
+
与 conftest.run_script 的区别:支持多场 run(run1 暂停 → run2 续跑)、
|
|
64
|
+
human_input 投喂、stop 命令——R4 端到端需要两级 run 共享同一 DB 与进程。
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(self):
|
|
68
|
+
self.proc = subprocess.Popen(
|
|
69
|
+
[sys.executable, BRIDGE, "--fe4m", ROOT],
|
|
70
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
71
|
+
text=True, encoding="utf-8", errors="replace", bufsize=1,
|
|
72
|
+
)
|
|
73
|
+
self.events = [] # {"event": type, "data": {...}}
|
|
74
|
+
self.responses = {} # id -> response payload
|
|
75
|
+
self.job_id = None # 当前 Job(job_start 回执;stop/human_input/resume 带)
|
|
76
|
+
self._lock = threading.Lock()
|
|
77
|
+
self._next_id = 10
|
|
78
|
+
self._t = threading.Thread(target=self._drain, daemon=True)
|
|
79
|
+
self._t.start()
|
|
80
|
+
assert self.rpc("ping")["ok"], "bridge ping failed"
|
|
81
|
+
|
|
82
|
+
def _drain(self):
|
|
83
|
+
for line in self.proc.stdout:
|
|
84
|
+
line = line.strip()
|
|
85
|
+
if not line:
|
|
86
|
+
continue
|
|
87
|
+
try:
|
|
88
|
+
obj = json.loads(line)
|
|
89
|
+
except json.JSONDecodeError:
|
|
90
|
+
continue
|
|
91
|
+
with self._lock:
|
|
92
|
+
if obj.get("type") == "event":
|
|
93
|
+
self.events.append({"event": obj.get("event"), "data": obj.get("data") or {}})
|
|
94
|
+
elif obj.get("type") == "response":
|
|
95
|
+
self.responses[obj.get("id")] = obj
|
|
96
|
+
|
|
97
|
+
def rpc(self, cmd, args=None, timeout=20):
|
|
98
|
+
"""发送命令并等待 response(id 配对)。"""
|
|
99
|
+
with self._lock:
|
|
100
|
+
rid = self._next_id
|
|
101
|
+
self._next_id += 1
|
|
102
|
+
self.proc.stdin.write(json.dumps({"id": rid, "cmd": cmd, "args": args or {}},
|
|
103
|
+
ensure_ascii=False) + "\n")
|
|
104
|
+
self.proc.stdin.flush()
|
|
105
|
+
deadline = time.time() + timeout
|
|
106
|
+
while time.time() < deadline:
|
|
107
|
+
with self._lock:
|
|
108
|
+
if rid in self.responses:
|
|
109
|
+
return self.responses[rid]
|
|
110
|
+
time.sleep(0.05)
|
|
111
|
+
raise TimeoutError(f"bridge rpc '{cmd}' no response in {timeout}s")
|
|
112
|
+
|
|
113
|
+
def wait_event(self, predicate, timeout=30, collect_from=0):
|
|
114
|
+
"""等待首个满足 predicate(event) 的事件,返回它。"""
|
|
115
|
+
deadline = time.time() + timeout
|
|
116
|
+
while time.time() < deadline:
|
|
117
|
+
with self._lock:
|
|
118
|
+
for ev in self.events[collect_from:]:
|
|
119
|
+
if predicate(ev):
|
|
120
|
+
return ev
|
|
121
|
+
time.sleep(0.05)
|
|
122
|
+
raise TimeoutError(f"event not seen in {timeout}s: events={[e['event'] for e in self.events]}")
|
|
123
|
+
|
|
124
|
+
def start(self, femo_text, timeout=40):
|
|
125
|
+
"""job_start:开新 Job 并记录 job_id(Job 模型协议 §12.1)。"""
|
|
126
|
+
resp = self.rpc("job_start", {"femo": femo_text, "base_dir": ROOT,
|
|
127
|
+
"host_ref": "pytest", "script_name": "resume-e2e"},
|
|
128
|
+
timeout=timeout)
|
|
129
|
+
assert resp.get("ok"), f"job_start rejected: {resp.get('error')} {resp.get('detail', '')}"
|
|
130
|
+
self.job_id = (resp.get("result") or {}).get("job_id")
|
|
131
|
+
assert isinstance(self.job_id, int), f"job_start 回执缺 job_id: {resp}"
|
|
132
|
+
return self.job_id
|
|
133
|
+
|
|
134
|
+
def resume(self, femo_text, job_id=None, timeout=40):
|
|
135
|
+
"""job_resume:从挂起 Job 续跑——resume_state 由引擎 runs 档案提供
|
|
136
|
+
(六关裁决在 JobManager),宿主不再传 checkpoint/state。"""
|
|
137
|
+
jid = job_id if job_id is not None else self.job_id
|
|
138
|
+
resp = self.rpc("job_resume", {"job_id": jid, "femo": femo_text, "base_dir": ROOT,
|
|
139
|
+
"host_ref": "pytest"}, timeout=timeout)
|
|
140
|
+
assert resp.get("ok"), f"job_resume rejected: {resp.get('error')} {resp.get('detail', '')}"
|
|
141
|
+
self.job_id = jid
|
|
142
|
+
return resp.get("result") or {}
|
|
143
|
+
|
|
144
|
+
def human_input(self, wait_key, body):
|
|
145
|
+
return self.rpc("human_input", {"job_id": self.job_id, "wait_key": wait_key, "body": body})
|
|
146
|
+
|
|
147
|
+
def pause(self):
|
|
148
|
+
return self.rpc("job_pause", {"job_id": self.job_id})
|
|
149
|
+
|
|
150
|
+
def close(self):
|
|
151
|
+
# shutdown:bridge 侧 runner.stop() + 0.2s 后 os._exit 硬退——fork 场景
|
|
152
|
+
# 下 human 等待分支卡在 run_in_executor(cancel 无法中断已运行的
|
|
153
|
+
# executor 任务),worker 收尾会假死(引擎既有缺陷,与 R4 无关,见
|
|
154
|
+
# 测试文件头注记)。硬退即"进程死亡后从存档恢复"的真实形态。
|
|
155
|
+
try:
|
|
156
|
+
self.rpc("shutdown", timeout=10)
|
|
157
|
+
except Exception:
|
|
158
|
+
pass
|
|
159
|
+
try:
|
|
160
|
+
self.proc.wait(timeout=5)
|
|
161
|
+
except subprocess.TimeoutExpired:
|
|
162
|
+
self.proc.kill()
|
|
163
|
+
|
|
164
|
+
def __enter__(self):
|
|
165
|
+
return self
|
|
166
|
+
|
|
167
|
+
def __exit__(self, *exc):
|
|
168
|
+
self.close()
|
|
169
|
+
return False
|
|
170
|
+
|
|
171
|
+
def last_checkpoints(self):
|
|
172
|
+
"""事件流中最后一条 checkpoint 的全量位置映射(轮询等待用)。"""
|
|
173
|
+
cps = {}
|
|
174
|
+
for ev in self.events:
|
|
175
|
+
if ev["event"] == "checkpoint" and isinstance(ev["data"], dict):
|
|
176
|
+
cps = ev["data"].get("checkpoints") or cps
|
|
177
|
+
return cps
|
|
178
|
+
|
|
179
|
+
def last_checkpoint_payload(self):
|
|
180
|
+
"""事件流中最后一个携带 state 的 checkpoint 载荷
|
|
181
|
+
(R4 协议:{checkpoints, session_id, state?})→ resume_state 组装。"""
|
|
182
|
+
picked = None
|
|
183
|
+
for ev in self.events:
|
|
184
|
+
if ev["event"] == "checkpoint" and isinstance(ev["data"], dict):
|
|
185
|
+
picked = ev["data"] # 顺序覆盖 → 保留最后一条
|
|
186
|
+
assert picked is not None, "run1 未产生任何 checkpoint 事件"
|
|
187
|
+
rs = {"checkpoints": picked.get("checkpoints") or {}}
|
|
188
|
+
if picked.get("session_id") is not None:
|
|
189
|
+
rs["session_id"] = picked["session_id"]
|
|
190
|
+
if picked.get("state") is not None:
|
|
191
|
+
rs["state"] = picked["state"]
|
|
192
|
+
return rs
|
|
193
|
+
|
|
194
|
+
def assign_results(self, node_name=None):
|
|
195
|
+
out = []
|
|
196
|
+
for ev in self.events:
|
|
197
|
+
if ev["event"] == "assign_result":
|
|
198
|
+
if node_name is None or ev["data"].get("node_name") == node_name:
|
|
199
|
+
out.append(ev["data"])
|
|
200
|
+
return out
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
SCRIPT_BASIC = """meta:
|
|
204
|
+
name = resume-e2e-basic
|
|
205
|
+
session = new
|
|
206
|
+
|
|
207
|
+
vars:
|
|
208
|
+
counter = 0
|
|
209
|
+
note = ""
|
|
210
|
+
|
|
211
|
+
actors:
|
|
212
|
+
human player = soul:human, source:0
|
|
213
|
+
|
|
214
|
+
action bump @assign:
|
|
215
|
+
out: counter += 1
|
|
216
|
+
|
|
217
|
+
action mark @assign:
|
|
218
|
+
out: note = "before-pause"
|
|
219
|
+
|
|
220
|
+
action wait_player @human(@player):
|
|
221
|
+
prompt: "暂停点:请回复继续"
|
|
222
|
+
|
|
223
|
+
mainflow:
|
|
224
|
+
[START] -> [B1]:bump -> [M]:mark -> [W]:wait_player -> [B2]:bump -> [END]
|
|
225
|
+
"""
|
|
226
|
+
|
|
227
|
+
SCRIPT_JOIN = """meta:
|
|
228
|
+
name = resume-e2e-join
|
|
229
|
+
session = new
|
|
230
|
+
|
|
231
|
+
vars:
|
|
232
|
+
a_done = ""
|
|
233
|
+
b_done = ""
|
|
234
|
+
merged_log = ""
|
|
235
|
+
|
|
236
|
+
actors:
|
|
237
|
+
human player = soul:human, source:0
|
|
238
|
+
|
|
239
|
+
action markA @assign:
|
|
240
|
+
out: a_done = "yes"
|
|
241
|
+
|
|
242
|
+
action markB @assign:
|
|
243
|
+
out: b_done = "yes"
|
|
244
|
+
|
|
245
|
+
action waitB @human(@player):
|
|
246
|
+
prompt: "B 线暂停点"
|
|
247
|
+
|
|
248
|
+
action joinMark @assign:
|
|
249
|
+
out: merged_log = "merged"
|
|
250
|
+
|
|
251
|
+
mainflow:
|
|
252
|
+
[START] -> fork:
|
|
253
|
+
-> [A]:markA
|
|
254
|
+
-> [B]:waitB
|
|
255
|
+
join(all):
|
|
256
|
+
[A] ->
|
|
257
|
+
[B] ->
|
|
258
|
+
to [JOUT]:joinMark -> [END]
|
|
259
|
+
"""
|
|
260
|
+
|
|
261
|
+
SCRIPT_MODULE_FORK = """meta:
|
|
262
|
+
name = resume-e2e-module-fork
|
|
263
|
+
session = new
|
|
264
|
+
|
|
265
|
+
vars:
|
|
266
|
+
outer_seen = ""
|
|
267
|
+
|
|
268
|
+
actors:
|
|
269
|
+
human player = soul:human, source:0
|
|
270
|
+
|
|
271
|
+
module Inner:
|
|
272
|
+
vars:
|
|
273
|
+
inner_a = ""
|
|
274
|
+
inner_b = ""
|
|
275
|
+
|
|
276
|
+
action imarkA @assign:
|
|
277
|
+
out: inner_a = "A"
|
|
278
|
+
|
|
279
|
+
action iwaitB @human(@player):
|
|
280
|
+
prompt: "模块内 B 线暂停点"
|
|
281
|
+
|
|
282
|
+
action imarkB @assign:
|
|
283
|
+
out: inner_b = "B"
|
|
284
|
+
|
|
285
|
+
action ijmark @assign:
|
|
286
|
+
out: inner_b = "joined"
|
|
287
|
+
|
|
288
|
+
flow:
|
|
289
|
+
[IN] -> fork:
|
|
290
|
+
-> [IA]:imarkA
|
|
291
|
+
-> [IB]:iwaitB
|
|
292
|
+
join(all):
|
|
293
|
+
[IA] ->
|
|
294
|
+
[IB] ->
|
|
295
|
+
to [IOUT]:ijmark -> [OUT]
|
|
296
|
+
|
|
297
|
+
action itouch @assign:
|
|
298
|
+
out: outer_seen = "touched-after-module"
|
|
299
|
+
|
|
300
|
+
mainflow:
|
|
301
|
+
[START] -> [MI]:&Inner -> [OT]:itouch -> [END]
|
|
302
|
+
"""
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _wait_signed_in(bs, timeout=15):
|
|
306
|
+
"""轮询等待某个 fork 子 task 到达 join 网关签到挂起(checkpoint 位置
|
|
307
|
+
变为 __join_<n>__)——事件驱动,替代固定 sleep(模块层调度慢时 0.5s
|
|
308
|
+
不够,属测试脆弱点)。返回等待结束时的全量位置映射。"""
|
|
309
|
+
deadline = time.time() + timeout
|
|
310
|
+
while time.time() < deadline:
|
|
311
|
+
cps = bs.last_checkpoints()
|
|
312
|
+
if any(v.startswith("__join_") for v in cps.values()):
|
|
313
|
+
return cps
|
|
314
|
+
time.sleep(0.1)
|
|
315
|
+
raise TimeoutError(f"15s 内无分支到达 join 签到: {bs.last_checkpoints()}")
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def _answer_human(bs, timeout=30):
|
|
319
|
+
"""等待 human_wait 并投喂一条纯文本输入,返回该事件。"""
|
|
320
|
+
ev = bs.wait_event(lambda e: e["event"] == "human_wait", timeout=timeout)
|
|
321
|
+
wait_key = ev["data"].get("wait_key", "")
|
|
322
|
+
assert wait_key, f"human_wait without wait_key: {ev['data']}"
|
|
323
|
+
resp = bs.human_input(wait_key, {"chat_text": "继续", "variables": {}})
|
|
324
|
+
assert resp.get("ok"), resp
|
|
325
|
+
return ev
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
@pytest.fixture
|
|
329
|
+
def bridge():
|
|
330
|
+
bs = BridgeSession()
|
|
331
|
+
try:
|
|
332
|
+
yield bs
|
|
333
|
+
finally:
|
|
334
|
+
bs.close()
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def test_resume_variables_consistent(bridge):
|
|
338
|
+
"""场景 1:暂停→恢复→变量一致(counter 跨恢复累计)。"""
|
|
339
|
+
bridge.start(SCRIPT_BASIC)
|
|
340
|
+
# run1:bump(counter=1) → mark → 到 [W] human 等待
|
|
341
|
+
bridge.wait_event(lambda e: e["event"] == "human_wait", timeout=30)
|
|
342
|
+
pre = bridge.assign_results("[B1]")
|
|
343
|
+
assert pre and pre[0]["output"].get("counter") == 1, f"run1 bump 输出异常: {pre}"
|
|
344
|
+
# 暂停(production「暂停」同款:runner.stop → 协程 cancel → flow_paused)
|
|
345
|
+
bridge.pause()
|
|
346
|
+
bridge.wait_event(lambda e: e["event"] == "flow_paused", timeout=30)
|
|
347
|
+
bridge.wait_event(lambda e: e["event"] == "bridge_run_ended", timeout=30)
|
|
348
|
+
resume_state = bridge.last_checkpoint_payload()
|
|
349
|
+
# 最后位置应停在 human 节点 [W](进入节点时记录)
|
|
350
|
+
assert set(resume_state["checkpoints"].values()) == {"[W]"}, resume_state["checkpoints"]
|
|
351
|
+
assert "state" in resume_state, "checkpoint 载荷缺 state 整包(R4 协议断裂)"
|
|
352
|
+
|
|
353
|
+
n_events_run1 = len(bridge.events)
|
|
354
|
+
# run2:同一 bridge 进程 job_resume 续跑(断点归引擎 runs 档案)
|
|
355
|
+
bridge.resume(SCRIPT_BASIC)
|
|
356
|
+
ev = _answer_human(bridge, timeout=30)
|
|
357
|
+
assert ev["data"].get("prompt") and "暂停点" in str(ev["data"]["prompt"])
|
|
358
|
+
bridge.wait_event(lambda e: e["event"] == "flow_done", timeout=30,
|
|
359
|
+
collect_from=n_events_run1)
|
|
360
|
+
post = bridge.assign_results("[B2]")
|
|
361
|
+
assert post, "run2 未执行到 [B2]:bump"
|
|
362
|
+
# 变量一致的核心断言:+=1 建立在暂停前的 1 之上 → 2(未恢复则=1)
|
|
363
|
+
assert post[-1]["output"].get("counter") == 2, \
|
|
364
|
+
f"恢复后变量未接续暂停前状态(期望 2): {post[-1]['output']}"
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def test_resume_join_re_sign_in(bridge):
|
|
368
|
+
"""场景 2:join 签到后暂停重签到;出口只跑一遍;task 号防撞号。
|
|
369
|
+
|
|
370
|
+
双进程形态:run1 进程 shutdown 硬退后以新进程恢复——production 里 bridge
|
|
371
|
+
崩溃/重启后从引擎 runs 档案续跑走的就是同一条链路(档案完整自足,不依赖
|
|
372
|
+
进程内状态;job_id 跨进程传递)。"""
|
|
373
|
+
with BridgeSession() as b1:
|
|
374
|
+
b1.start(SCRIPT_JOIN)
|
|
375
|
+
# B 线停在 human 等待;轮询等 A 线到达 join 签到挂起
|
|
376
|
+
b1.wait_event(lambda e: e["event"] == "human_wait", timeout=30)
|
|
377
|
+
_wait_signed_in(b1)
|
|
378
|
+
b1.pause()
|
|
379
|
+
b1.wait_event(lambda e: e["event"] == "flow_paused", timeout=30)
|
|
380
|
+
resume_state = b1.last_checkpoint_payload()
|
|
381
|
+
cps = resume_state["checkpoints"]
|
|
382
|
+
# fork 子任务两支:一支停在 join 网关(签到后暂停→恢复重签到;网关 id
|
|
383
|
+
# 为 parser 自动生成的 __join_<n>__)、一支停在 [B]。t0 在 fork 网关的
|
|
384
|
+
# 位置记录是母 task 死亡前的正常残留——恢复侧按 ledger.alive 跳过直启,
|
|
385
|
+
# 不参与续跑。
|
|
386
|
+
child_cps = {k: v for k, v in cps.items() if k != "t0"}
|
|
387
|
+
vals = set(child_cps.values())
|
|
388
|
+
assert len(child_cps) == 2 and "[B]" in vals \
|
|
389
|
+
and any(v.startswith("__join_") for v in vals), f"分支位置异常: {cps}"
|
|
390
|
+
b1_job_id = b1.job_id
|
|
391
|
+
with BridgeSession() as b2:
|
|
392
|
+
b2.resume(SCRIPT_JOIN, job_id=b1_job_id)
|
|
393
|
+
_answer_human(b2, timeout=30)
|
|
394
|
+
b2.wait_event(lambda e: e["event"] == "flow_done", timeout=30)
|
|
395
|
+
# join 出口节点只跑一遍(重签到幂等凑齐,不重复执行出口)
|
|
396
|
+
marks = b2.assign_results("[JOUT]")
|
|
397
|
+
assert len(marks) == 1, f"join 出口应恰好执行一次,实际 {len(marks)}"
|
|
398
|
+
assert marks[0]["output"].get("merged_log") == "merged", marks[0]["output"]
|
|
399
|
+
# merge 幂等重建后无 conflict 噪音(a_done/b_done 不同键,不冲突)
|
|
400
|
+
conflicts = [e for e in b2.events if e["event"] == "merge_conflict"]
|
|
401
|
+
assert not conflicts, f"unexpected merge_conflict: {conflicts}"
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def test_resume_module_fork(bridge):
|
|
405
|
+
"""场景 3(清单验收行「含模块内 fork」):模块内暂停→按模块栈直启。
|
|
406
|
+
|
|
407
|
+
双进程形态(同场景 2 注记):run1 shutdown 硬退 → run2 新进程恢复。"""
|
|
408
|
+
with BridgeSession() as b1:
|
|
409
|
+
b1.start(SCRIPT_MODULE_FORK)
|
|
410
|
+
b1.wait_event(lambda e: e["event"] == "human_wait", timeout=30)
|
|
411
|
+
_wait_signed_in(b1) # 轮询等 A 线到模块内 join 签到挂起
|
|
412
|
+
b1.pause()
|
|
413
|
+
b1.wait_event(lambda e: e["event"] == "flow_paused", timeout=30)
|
|
414
|
+
resume_state = b1.last_checkpoint_payload()
|
|
415
|
+
cps = resume_state["checkpoints"]
|
|
416
|
+
# 模块 fork 子任务两支(t0=母 task 在模块 flow fork 网关的死亡前残留,
|
|
417
|
+
# 恢复侧按 alive 跳过):join 网关 __join_<n>__ / [IB] human 节点
|
|
418
|
+
child_cps = {k: v for k, v in cps.items() if k != "t0"}
|
|
419
|
+
vals = set(child_cps.values())
|
|
420
|
+
assert len(child_cps) == 2 and "[IB]" in vals \
|
|
421
|
+
and any(v.startswith("__join_") for v in vals), f"模块内分支位置异常: {cps}"
|
|
422
|
+
b1_job_id = b1.job_id
|
|
423
|
+
with BridgeSession() as b2:
|
|
424
|
+
b2.resume(SCRIPT_MODULE_FORK, job_id=b1_job_id)
|
|
425
|
+
_answer_human(b2, timeout=30)
|
|
426
|
+
b2.wait_event(lambda e: e["event"] == "flow_done", timeout=30)
|
|
427
|
+
# 模块 flow 恢复执行到 join 出口(直启按 mod_stack 顶进入模块 flow)
|
|
428
|
+
marks = b2.assign_results("[IOUT]")
|
|
429
|
+
assert len(marks) == 1, f"模块内 join 出口应恰好执行一次,实际 {len(marks)}"
|
|
430
|
+
# 模块出口后的主流程节点继续执行
|
|
431
|
+
touches = b2.assign_results("[OT]")
|
|
432
|
+
assert touches and touches[-1]["output"].get("outer_seen") == "touched-after-module", \
|
|
433
|
+
f"模块出口后主流程未继续: {touches}"
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def test_old_snapshot_loud_invalidated(bridge):
|
|
437
|
+
"""场景 4:档案里的旧格式快照 → restore_state VERSION 响亮作废(不静默 fresh)。
|
|
438
|
+
|
|
439
|
+
Job 模型下 resume_state 由引擎 runs 档案提供(宿主不再传)——旧格式来源
|
|
440
|
+
=档案被外部破坏/版本降级。这里手工把 suspended Job 的 vars_state 写成
|
|
441
|
+
R2 之前的合并视图平铺形态(无 version 键)模拟:job_resume 六关全过 →
|
|
442
|
+
FEMORunner 构造期 restore_state 抛 ValueError(文案含「作废」)→ worker
|
|
443
|
+
收口 flow_error + bridge_run_ended ok=false + finalize(failed)——绝不
|
|
444
|
+
静默按 fresh 开演。"""
|
|
445
|
+
bridge.start(SCRIPT_BASIC)
|
|
446
|
+
bridge.wait_event(lambda e: e["event"] == "human_wait", timeout=30)
|
|
447
|
+
bridge.pause()
|
|
448
|
+
bridge.wait_event(lambda e: e["event"] == "bridge_run_ended", timeout=30)
|
|
449
|
+
jid = bridge.job_id
|
|
450
|
+
assert isinstance(jid, int)
|
|
451
|
+
|
|
452
|
+
# 手工把档案 vars_state 改成旧格式(测试进程与 bridge 同一 runs 目录——
|
|
453
|
+
# get_user_dir() 同源)
|
|
454
|
+
from femoCompiler.job_manager import JobManager
|
|
455
|
+
jm = JobManager()
|
|
456
|
+
rec = jm._load(jid)
|
|
457
|
+
assert rec is not None and rec.state == "suspended", f"Job {jid} 应为 suspended: {rec}"
|
|
458
|
+
rec.vars_state = {"t0": {"counter": 1}, "note": "old flat view"} # 无 version 键
|
|
459
|
+
jm._save(rec)
|
|
460
|
+
|
|
461
|
+
n_events = len(bridge.events)
|
|
462
|
+
result = bridge.resume(SCRIPT_BASIC)
|
|
463
|
+
ended = bridge.wait_event(lambda e: e["event"] == "bridge_run_ended",
|
|
464
|
+
timeout=30, collect_from=n_events)
|
|
465
|
+
assert ended["data"].get("ok") is False, f"旧快照应响亮失败,实际 {ended}"
|
|
466
|
+
errors = [e["data"].get("error", "") for e in bridge.events[n_events:]
|
|
467
|
+
if e["event"] == "flow_error"]
|
|
468
|
+
assert errors and "作废" in errors[0], \
|
|
469
|
+
f"应报「旧格式快照已作废」,实际: {errors}"
|
|
470
|
+
# 构造期异常 → 收口 failed(三面收口①:不停僵尸态)
|
|
471
|
+
final = jm.get_job_state(jid)
|
|
472
|
+
assert final.get("state") == "failed", f"构造期异常应收口 failed: {final}"
|