Skip to content

The agent that grows with you

test: move two existing tests into topical siblings to keep files under their size cap

kshitijk4poor06559414d3bd
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
index c0b26b1d08a..7d54519d34c 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
@@ -38,7 +38,7 @@ import { clearSingleFlightSessionResumeState } from './single-flight-resume'
import { SESSION_COMPRESS_TIMEOUT_MS } from './slash'
import type { SubmitTextOptions } from './utils'
-import { uploadComposerAttachment, usePromptActions } from '.'
+import { usePromptActions } from '.'
// Suites in this file reuse the same stored-id constants. The module-level
// single-flight resume map (and drift-recovery cache) would otherwise leak a
@@ -3396,46 +3396,6 @@ describe('usePromptActions file attachment sync', () => {
})
})
- it('uses image.attach_bytes for a Windows image when the local backend cwd is POSIX', async () => {
- const readFileDataUrl = vi.fn(async () => 'data:image/jpeg;base64,aGVsbG8=')
- Object.defineProperty(window, 'hermesDesktop', {
- configurable: true,
- value: { readFileDataUrl }
- })
-
- const requestGateway = vi.fn(async (method: string) => {
- if (method === 'image.attach_bytes') {
- return { attached: true, path: '/root/tmp/photo.jpg' } as never
- }
-
- return {} as never
- })
-
- const uploaded = await uploadComposerAttachment(
- {
- id: 'image:photo.jpg',
- kind: 'image',
- label: 'photo.jpg',
- path: 'C:\\Users\\alice\\Pictures\\photo.jpg'
- },
- {
- backendCwd: '/root',
- remote: false,
- requestGateway,
- sessionId: RUNTIME_SESSION_ID
- }
- )
-
- expect(readFileDataUrl).toHaveBeenCalledWith('C:\\Users\\alice\\Pictures\\photo.jpg')
- expect(requestGateway).toHaveBeenCalledWith('image.attach_bytes', {
- content_base64: 'aGVsbG8=',
- filename: 'photo.jpg',
- session_id: RUNTIME_SESSION_ID
- })
- expect(requestGateway).not.toHaveBeenCalledWith('image.attach', expect.anything())
- expect(uploaded.path).toBe('/root/tmp/photo.jpg')
- })
-
it('merges image staging into the current occurrence without dropping its thumbnail', async () => {
$connection.set({ mode: 'local' } as never)
$currentCwd.set('/root')
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/upload-composer-attachment.test.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/upload-composer-attachment.test.ts
index 23c7e9a8417..6998acdfee1 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/upload-composer-attachment.test.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/upload-composer-attachment.test.ts
@@ -98,3 +98,49 @@ describe('uploadComposerAttachment image cache contract', () => {
expect(uploaded.path).toBe('/gw/images/shot.png')
})
})
+
+describe('uploadComposerAttachment local cross-platform staging', () => {
+ afterEach(() => {
+ vi.restoreAllMocks()
+ })
+
+ it('uses image.attach_bytes for a Windows image when the local backend cwd is POSIX', async () => {
+ const readFileDataUrl = vi.fn(async () => 'data:image/jpeg;base64,aGVsbG8=')
+ Object.defineProperty(window, 'hermesDesktop', {
+ configurable: true,
+ value: { readFileDataUrl }
+ })
+
+ const requestGateway = vi.fn(async (method: string) => {
+ if (method === 'image.attach_bytes') {
+ return { attached: true, path: '/root/tmp/photo.jpg' } as never
+ }
+
+ return {} as never
+ })
+
+ const uploaded = await uploadComposerAttachment(
+ {
+ id: 'image:photo.jpg',
+ kind: 'image',
+ label: 'photo.jpg',
+ path: 'C:\\Users\\alice\\Pictures\\photo.jpg'
+ },
+ {
+ backendCwd: '/root',
+ remote: false,
+ requestGateway,
+ sessionId: RUNTIME_SESSION_ID
+ }
+ )
+
+ expect(readFileDataUrl).toHaveBeenCalledWith('C:\\Users\\alice\\Pictures\\photo.jpg')
+ expect(requestGateway).toHaveBeenCalledWith('image.attach_bytes', {
+ content_base64: 'aGVsbG8=',
+ filename: 'photo.jpg',
+ session_id: RUNTIME_SESSION_ID
+ })
+ expect(requestGateway).not.toHaveBeenCalledWith('image.attach', expect.anything())
+ expect(uploaded.path).toBe('/root/tmp/photo.jpg')
+ })
+})
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.py
index 956acad7eb1..a4bf9574b2c 100644
--- a/tests/tui_gateway/test_tui_gateway_server.py
+++ b/tests/tui_gateway/test_tui_gateway_server.py
@@ -7481,89 +7481,6 @@ def test_prompt_submit_refuses_empty_truncation_without_confirm(monkeypatch):
server._sessions.pop("empty-trunc-sid", None)
-def test_prompt_submit_empty_truncation_allowed_with_confirm(monkeypatch):
- """Intentional restore/regenerate of the first user turn may wipe history."""
-
- seen = {}
- replaced = []
-
- class _Agent:
- def run_conversation(
- self, prompt, conversation_history=None, stream_callback=None, **_kwargs
- ):
- seen["prompt"] = prompt
- seen["history"] = conversation_history
- return {
- "final_response": "regenerated",
- "messages": [
- *(conversation_history or []),
- {"role": "user", "content": prompt},
- {"role": "assistant", "content": "regenerated"},
- ],
- }
-
- class _ImmediateThread:
- def __init__(self, target=None, daemon=None, **_thread_options):
- self._target = target
-
- def start(self):
- self._target()
-
- class _FakeDB:
- def replace_messages(
- self,
- key,
- messages,
- active_only=False,
- archive_dropped=False,
- reject_active_turn_lease=False,
- ):
- replaced.append((key, list(messages)))
-
- history = [
- {"_row_id": 101, "role": "user", "content": "first"},
- {"_row_id": 102, "role": "assistant", "content": "ok"},
- {"_row_id": 103, "role": "user", "content": "second"},
- {"_row_id": 104, "role": "assistant", "content": "done"},
- ]
- server._sessions["confirm-empty-sid"] = _session(
- agent=_Agent(), history=list(history)
- )
-
- try:
- monkeypatch.setattr(server.threading, "Thread", _ImmediateThread)
- monkeypatch.setattr(server, "_get_usage", lambda _a: {})
- monkeypatch.setattr(server, "render_message", lambda _t, _c: "")
- monkeypatch.setattr(server, "_emit", lambda *a: None)
- monkeypatch.setattr(server, "_get_db", lambda: _FakeDB())
-
- resp = server.handle_request(
- {
- "id": "1",
- "method": "prompt.submit",
- "params": {
- "session_id": "confirm-empty-sid",
- "text": "first",
- "truncate_before_row_id": 101,
- "truncate_before_user_ordinal": 0,
- "confirm_truncate": True,
- "confirm_empty_truncate": True,
- "confirm_deep_truncate": True, # drops both user turns (#133716)
- },
- }
- )
- assert resp.get("result"), f"got error: {resp.get('error')}"
- assert seen["prompt"] == "first"
- assert seen["history"] == []
- assert replaced == [("session-key", [])]
- assert server._sessions["confirm-empty-sid"]["history"] == [
- {"role": "user", "content": "first"},
- {"role": "assistant", "content": "regenerated"},
- ]
- finally:
- server._sessions.pop("confirm-empty-sid", None)
-
-
class _StopAfterOneNotificationPoll:
def __init__(self):
self._checks = 0
diff --git a/tests/tui_gateway/test_tui_gateway_server_deep_truncate.py b/tests/tui_gateway/test_tui_gateway_server_deep_truncate.py
index a793420f1d9..c3cf9ce4f7b 100644
--- a/tests/tui_gateway/test_tui_gateway_server_deep_truncate.py
+++ b/tests/tui_gateway/test_tui_gateway_server_deep_truncate.py
@@ -1,5 +1,6 @@
-"""prompt.submit depth gate (#133716): a cut that archives more than one user turn needs
-``confirm_deep_truncate`` — a valid anchor can still name the wrong (stale) row."""
+"""prompt.submit history-cut opt-ins: ``confirm_empty_truncate`` (wipe) and
+``confirm_deep_truncate`` (#133716: a cut that archives more than one user turn — a valid
+anchor can still name the wrong, stale row)."""
import threading
import types
@@ -7,6 +8,16 @@ import types
from tui_gateway import server
+def _session(agent=None, **extra):
+ return {
+ "agent": agent if agent is not None else types.SimpleNamespace(),
+ "session_key": "session-key", "history": [], "history_lock": threading.Lock(),
+ "history_version": 0, "running": False, "attached_images": [], "image_counter": 0,
+ "cols": 80, "slash_worker": None, "show_reasoning": False, "tool_progress_mode": "all",
+ **extra,
+ }
+
+
def test_prompt_submit_refuses_deep_truncation_without_confirm(monkeypatch):
replaced = []
@@ -20,12 +31,7 @@ def test_prompt_submit_refuses_deep_truncation_without_confirm(monkeypatch):
{"_row_id": 100 + 2 * turn, "role": "user", "content": f"u{turn}"},
{"_row_id": 101 + 2 * turn, "role": "assistant", "content": f"a{turn}"},
]
- sess = {
- "agent": types.SimpleNamespace(), "session_key": "session-key", "history": list(history),
- "history_lock": threading.Lock(), "history_version": 0, "running": False,
- "attached_images": [], "image_counter": 0, "cols": 80, "slash_worker": None,
- "show_reasoning": False, "tool_progress_mode": "all",
- }
+ sess = _session(history=list(history))
server._sessions["deep-trunc-sid"] = sess
monkeypatch.setattr(server, "_get_db", lambda: _FakeDB())
monkeypatch.setattr(server, "_start_agent_build", lambda *a, **k: None)
@@ -47,3 +53,86 @@ def test_prompt_submit_refuses_deep_truncation_without_confirm(monkeypatch):
assert replaced == [history[:2]]
finally:
server._sessions.pop("deep-trunc-sid", None)
+
+
+def test_prompt_submit_empty_truncation_allowed_with_confirm(monkeypatch):
+ """Intentional restore/regenerate of the first user turn may wipe history."""
+
+ seen = {}
+ replaced = []
+
+ class _Agent:
+ def run_conversation(
+ self, prompt, conversation_history=None, stream_callback=None, **_kwargs
+ ):
+ seen["prompt"] = prompt
+ seen["history"] = conversation_history
+ return {
+ "final_response": "regenerated",
+ "messages": [
+ *(conversation_history or []),
+ {"role": "user", "content": prompt},
+ {"role": "assistant", "content": "regenerated"},
+ ],
+ }
+
+ class _ImmediateThread:
+ def __init__(self, target=None, daemon=None, **_thread_options):
+ self._target = target
+
+ def start(self):
+ self._target()
+
+ class _FakeDB:
+ def replace_messages(
+ self,
+ key,
+ messages,
+ active_only=False,
+ archive_dropped=False,
+ reject_active_turn_lease=False,
+ ):
+ replaced.append((key, list(messages)))
+
+ history = [
+ {"_row_id": 101, "role": "user", "content": "first"},
+ {"_row_id": 102, "role": "assistant", "content": "ok"},
+ {"_row_id": 103, "role": "user", "content": "second"},
+ {"_row_id": 104, "role": "assistant", "content": "done"},
+ ]
+ server._sessions["confirm-empty-sid"] = _session(
+ agent=_Agent(), history=list(history)
+ )
+
+ try:
+ monkeypatch.setattr(server.threading, "Thread", _ImmediateThread)
+ monkeypatch.setattr(server, "_get_usage", lambda _a: {})
+ monkeypatch.setattr(server, "render_message", lambda _t, _c: "")
+ monkeypatch.setattr(server, "_emit", lambda *a: None)
+ monkeypatch.setattr(server, "_get_db", lambda: _FakeDB())
+
+ resp = server.handle_request(
+ {
+ "id": "1",
+ "method": "prompt.submit",
+ "params": {
+ "session_id": "confirm-empty-sid",
+ "text": "first",
+ "truncate_before_row_id": 101,
+ "truncate_before_user_ordinal": 0,
+ "confirm_truncate": True,
+ "confirm_empty_truncate": True,
+ "confirm_deep_truncate": True, # drops both user turns (#133716)
+ },
+ }
+ )
+ assert resp.get("result"), f"got error: {resp.get('error')}"
+ assert seen["prompt"] == "first"
+ assert seen["history"] == []
+ assert replaced == [("session-key", [])]
+ assert server._sessions["confirm-empty-sid"]["history"] == [
+ {"role": "user", "content": "first"},
+ {"role": "assistant", "content": "regenerated"},
+ ]
+ finally:
+ server._sessions.pop("confirm-empty-sid", None)