Files
hapi/ios/HapiTests/PendingRequestPresentationTests.swift
T
d0b0fde6cb feat(ios): jump notifications and session rows to the pending request
Complete the pending-request center's entry points:

- Push payloads already carry the request id for permission and input
  pushes; the notification tap now passes it through AppModel into the
  home screen instead of only the session id.
- Opening a session row whose summary still has pending requests lands on
  the first wait (async questions first, since they live in the collapsible
  bottom panel; approvals scroll to their tool row).
- ChatModel queues the jump until the detail's request dictionary arrives,
  so a cold notification start does not drop the target and a blocking
  target waits for the transcript to settle before scrolling.
- A focus token lets the split detail re-fire for the session that is
  already open.

Routing and pending-target presentation tests cover the new request id.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-12-01 06:47:01 +08:00

70 lines
2.4 KiB
Swift

import XCTest
@testable import Hapi
import HapiProtocol
final class PendingRequestPresentationTests: XCTestCase {
private func request(
_ tool: String,
_ arguments: JSONValue?,
kind: PendingRequestKind = .input,
id: String = "req-1"
) -> ChatPendingRequest {
ChatPendingRequest(
id: id,
tool: tool,
toolCallId: "call-1",
arguments: arguments,
createdAt: 1,
kind: kind
)
}
func testAsyncQuestionRequiresNonBlockingRequestUserInput() {
let async = request("request_user_input", .object([
"isBlocking": .bool(false),
"questions": .array([
.object(["id": .string("q1"), "question": .string("Pick a branch")])
])
]))
XCTAssertTrue(async.isAsyncQuestion)
XCTAssertEqual(async.detailText, "Pick a branch")
let blocking = request("request_user_input", .object(["isBlocking": .bool(true)]))
XCTAssertFalse(blocking.isAsyncQuestion)
let ask = request("AskUserQuestion", .object(["isBlocking": .bool(false)]))
XCTAssertFalse(ask.isAsyncQuestion)
}
func testPermissionDetailFallsBackFromCommandToTool() {
XCTAssertEqual(
request("Bash", .object(["command": .string("rm -rf build")]), kind: .permission).detailText,
"rm -rf build"
)
XCTAssertEqual(
request("Read", .object(["file_path": .string("/tmp/a.txt")]), kind: .permission).detailText,
"/tmp/a.txt"
)
XCTAssertEqual(request("Bash", nil, kind: .permission).detailText, "Bash")
}
func testFirstFocusTargetPrefersAnAsyncQuestion() {
let permission = request("Bash", nil, kind: .permission, id: "approval")
let async = request("request_user_input", .object([
"isBlocking": .bool(false)
]), id: "question")
XCTAssertEqual([permission, async].firstFocusTarget, async)
XCTAssertEqual([permission].firstFocusTarget, permission)
XCTAssertNil([ChatPendingRequest]().firstFocusTarget)
}
func testSyntheticToolUsesTheRequestKeyAsTheReplyTarget() {
let tool = pendingRequestTool(request("request_user_input", .object([
"isBlocking": .bool(false)
])))
XCTAssertEqual(tool.id, "req-1")
XCTAssertEqual(tool.permission?.id, "req-1")
XCTAssertEqual(tool.state, .pending)
}
}