fix: support conversational mode draft updates

This commit is contained in:
vee
2026-09-07 23:59:42 +08:00
parent 6b2b644ee6
commit f0a248ede3
19 changed files with 2326 additions and 109 deletions
+54 -5
View File
@@ -13,15 +13,15 @@ def test_console_contains_ai_assistant_surface():
assert 'aria-label="AI助手对话"' in html
assert 'placeholder="向 AI助手提问或交代工作"' in html
assert 'aria-label="发送消息"' in html
assert 'href="/assistant-chat.css?v=codex-assistant-22"' in html
assert 'src="/assistant-chat.js?v=codex-assistant-22"' in html
assert 'href="/assistant-chat.css?v=codex-assistant-23"' in html
assert 'src="/assistant-chat.js?v=codex-assistant-23"' in html
def test_codex_assistant_assets_are_versioned_together_in_the_service_worker():
service_worker = (ROOT / "apps/web-console/service-worker.js").read_text(encoding="utf-8")
assert 'const CACHE_VERSION = "cognitive-agent-pad-v271"' in service_worker
assert '"/assistant-chat.css?v=codex-assistant-22"' in service_worker
assert '"/assistant-chat.js?v=codex-assistant-22"' in service_worker
assert 'const CACHE_VERSION = "cognitive-agent-pad-v272"' in service_worker
assert '"/assistant-chat.css?v=codex-assistant-23"' in service_worker
assert '"/assistant-chat.js?v=codex-assistant-23"' in service_worker
def test_codex_frontend_uses_one_streaming_endpoint_and_agent_work_events():
@@ -157,6 +157,55 @@ def test_assistant_mode_creation_previews_then_saves_to_the_compact_mode_strip()
assert ".assistant-mode-created" in css
def test_assistant_carries_only_the_active_mode_draft_reference_to_follow_up_turns():
assistant = (ROOT / "apps/web-console/assistant-chat.js").read_text(encoding="utf-8")
request_body = assistant.split("function requestBody(message)", 1)[1].split(
"async function readErrorResponse", 1
)[0]
context_flow = assistant.split("function sanitizeModeDraftContext", 1)[1].split(
"function loadStoredMessages", 1
)[0]
assert (
'const ACTIVE_MODE_DRAFT_STORAGE_KEY = "cognitive-agent.active-mode-draft"'
in assistant
)
assert "mode_profile_draft_context: modeProfileDraftContext" in request_body
assert "requestModeDraftContext(message)" in request_body
assert "name: context.name" in context_flow
assert "source_request_id: context.source_request_id" in context_flow
assert "vehicle_id: context.vehicle_id" in context_flow
assert "actions" not in context_flow
assert "rememberModeDraftContext(draft)" in assistant
assert "activeModeDraftContext = loadActiveModeDraftContext()" in assistant
assert "function isModeDraftUpdateRequest(message, context)" in assistant
assert "normalizeModeName(matched[1]) === normalizeModeName(context.name)" in assistant
def test_latest_same_name_mode_draft_retires_stale_card_and_lifecycle_clears_context():
assistant = (ROOT / "apps/web-console/assistant-chat.js").read_text(encoding="utf-8")
css = (ROOT / "apps/web-console/assistant-chat.css").read_text(encoding="utf-8")
replace_flow = assistant.split("function supersedeModeDraftCards", 1)[1].split(
"function appendModeDraftState", 1
)[0]
save_flow = assistant.split("async function saveModeProfileDraft", 1)[1].split(
"async function tryModeProfileDraft", 1
)[0]
new_conversation_flow = assistant.split(
'if (!target?.closest("#newConversation")) return;', 1
)[1].split("}, true);", 1)[0]
assert "card.dataset.assistantModeName !== nextName" in replace_flow
assert "card.dataset.assistantModeDraft === nextRequestId" in replace_flow
assert 'card.classList.add("is-superseded")' in replace_flow
assert "button.disabled = true" in replace_flow
assert "已由下方最新草稿替换" in replace_flow
assert "clearActiveModeDraftContext(draft.source_request_id)" in save_flow
assert "clearActiveModeDraftContext()" in new_conversation_flow
assert ".assistant-mode-draft.is-superseded" in css
assert ".assistant-mode-draft-status.superseded" in css
def test_assistant_composer_grows_to_a_cap_then_scrolls_its_own_content():
assistant = (ROOT / "apps/web-console/assistant-chat.js").read_text(encoding="utf-8")
css = (ROOT / "apps/web-console/assistant-chat.css").read_text(encoding="utf-8")