feat: add fake send connector contract

This commit is contained in:
zhaoyilun
2026-07-10 20:22:02 +08:00
parent 9eb7f382cc
commit dadf42817c
6 changed files with 343 additions and 18 deletions

View File

@@ -90,7 +90,7 @@ git push gitea main
- Produces: `type SendMessageConnectorResult struct { Accepted bool; Status string; AckRef string; ErrorCode string; ErrorMessage string; ConnectorMode string }`
- Produces: `RegisterISphereSendMessageToolWithStateAndConnector(server, auditStore, idempotencyStore, connector)` for tests only.
- [ ] **Step 1: Write failing fake-accepted test**
- [x] **Step 1: Write failing fake-accepted test**
Add `TestISphereSendMessageFakeConnectorAcceptedAudit` to `internal/tools/isphere_send_message_test.go`:
@@ -118,19 +118,19 @@ go test ./internal/tools -run TestISphereSendMessageFakeConnectorAcceptedAudit -
Expected before implementation: FAIL because `RegisterISphereSendMessageToolWithStateAndConnector` and connector types do not exist.
- [ ] **Step 2: Write failing fake-failed test**
- [x] **Step 2: Write failing fake-failed test**
Add `TestISphereSendMessageFakeConnectorFailureAudit` asserting `ok=false`, `send_status="failed"`, `error_code="fake_rejected"`, and `side_effect_flags.real_send_attempted=false`.
Add `TestISphereSendMessageFakeConnectorFailureAudit` asserting `ok=false`, `send_status="failed"`, `error_code="fake_rejected"`, and no real side-effect flags such as `sent_message` or `typed_text`.
- [ ] **Step 3: Implement connector contract**
- [x] **Step 3: Implement connector contract**
Create `internal/tools/send_message_connector.go` with the interface, request/result structs, and result normalization. Keep the fake connector in the test file.
- [ ] **Step 4: Wire injected connector only for tests**
- [x] **Step 4: Wire injected connector only for tests**
Modify `internal/tools/isphere_send_message.go` so default `RegisterISphereSendMessageTool` still blocks production, while `RegisterISphereSendMessageToolWithStateAndConnector` can execute a fake connector in tests.
- [ ] **Step 5: Verify and commit**
- [x] **Step 5: Verify and commit**
```powershell
git diff --check
@@ -145,6 +145,14 @@ git push gitea main
**Acceptance gate:** Default MCP still reports `production_send_enabled=false`; fake connector is reachable only through test injection.
**R6f Result:**
- Added `internal/tools/send_message_connector.go` with `SendMessageConnector`, `SendMessageConnectorRequest`, `SendMessageConnectorResult`, and result normalization.
- Added `RegisterISphereSendMessageToolWithStateAndConnector` for injected test-only connector execution.
- Added fake connector accepted/failed tests proving accepted/failed connector outcomes map into structured response and redacted audit metadata.
- Default server registration still uses no connector; `execution_mode="production"` remains blocked with `production_send_enabled=false`.
- No helper send operation, UI click/type, network replay, hook, upload, or real production send was introduced.
---
### R6g: Send audit and idempotency replay diagnostics