supercode-harness 0.4.21

The optional native Supercode agent and tool harness
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
//! ORCH-19 dev/01 — the controlled tier over `harness.v1.sessions.*`,
//! exercised against FAKE harness doors.
//!
//! Each door is stood up as the harness itself would present it, so what is
//! under test is exactly supercode's half of the contract:
//!
//! * a fake `codex` CLI records its argv and moves/removes the rollout the way
//!   the real one does (`archive` → `archived_sessions/`, verified live on an
//!   isolated `CODEX_HOME` 2026-09-03),
//! * a mock OpenCode HTTP server records its request lines and answers the
//!   re-read, so a `DELETE` that leaves the session behind and an archive the
//!   server never stamped both FAIL,
//! * a mock ACP agent records the prompts it receives, proving `/new` reaches
//!   Hermes through the same `send_input` path a human's message takes,
//! * every harness with no door for a verb refuses with `unsupported_action`
//!   and says why.
//!
//! No real harness, no gateway, no model spend.

use std::io::{BufRead, BufReader, Read, Write};
use std::net::TcpListener;
use std::path::{Path, PathBuf};

use serde_json::{json, Value};
use supercode_harness::harness_service::HARNESS_SERVICE_METHODS;
use supercode_harness::sessions_control::CODEX_BIN_ENV;
use supercode_harness::{HarnessSessionService, SdkOperation};

/// `SUPERCODE_*_BIN` is process-global, so the tests that set it run one at a
/// time even though cargo runs the file's tests in threads.
static BIN_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());

fn bin_lock() -> std::sync::MutexGuard<'static, ()> {
    BIN_LOCK.lock().unwrap_or_else(|error| error.into_inner())
}

fn scratch(tag: &str) -> PathBuf {
    let root = std::env::temp_dir().join(format!(
        "supercode-orch19-{tag}-{}-{}",
        std::process::id(),
        std::time::SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .unwrap()
            .as_nanos()
    ));
    std::fs::create_dir_all(&root).unwrap();
    root
}

fn request(method: &str, params: Value) -> Value {
    json!({"jsonrpc": "2.0", "id": 1, "method": method, "params": params})
}

async fn call(service: &mut HarnessSessionService, method: &str, params: Value) -> Value {
    let response = service.handle_async(request(method, params)).await;
    assert!(response.get("error").is_none(), "{method}: {response}");
    response["result"].clone()
}

async fn call_err(service: &mut HarnessSessionService, method: &str, params: Value) -> Value {
    let response = service.handle_async(request(method, params)).await;
    assert!(response.get("result").is_none(), "{method}: {response}");
    response["error"].clone()
}

/// The narration with the (temp-path) program stripped, so an assertion can
/// name the verb the harness ran.
fn ran_arguments(result: &Value) -> String {
    let ran = result["ran"]
        .as_str()
        .expect("every outcome narrates `ran`");
    ran.split_once(' ')
        .map(|(_, rest)| rest.to_string())
        .unwrap_or_default()
}

// ---------------------------------------------------------------------------
// Codex — a fake CLI that behaves the way the real one was measured to behave
// ---------------------------------------------------------------------------

/// One codex rollout in `$CODEX_HOME/sessions`, in the shape the loader reads.
fn write_rollout(codex_home: &Path, id: &str, cwd: &Path) {
    let dir = codex_home.join("sessions/2026/09/03");
    std::fs::create_dir_all(&dir).unwrap();
    std::fs::write(
        dir.join(format!("rollout-2026-09-03T00-00-00-{id}.jsonl")),
        format!(
            "{{\"timestamp\":\"2026-09-03T00:00:00.000Z\",\"type\":\"session_meta\",\
             \"payload\":{{\"id\":\"{id}\",\"cwd\":{}}}}}\n\
             {{\"timestamp\":\"2026-09-03T00:00:02.000Z\",\"type\":\"response_item\",\
             \"payload\":{{\"type\":\"message\",\"role\":\"user\",\
             \"content\":[{{\"type\":\"input_text\",\"text\":\"orch19\"}}]}}}}\n",
            serde_json::to_string(&cwd.to_string_lossy()).unwrap()
        ),
    )
    .unwrap();
}

/// A fake `codex`: logs its argv, then does what the real CLI was OBSERVED to
/// do on an isolated `CODEX_HOME` — `archive` moves the rollout into
/// `archived_sessions/`, `delete` removes it, and an unknown id fails with
/// codex's own message on stderr.
fn fake_codex(root: &Path) -> PathBuf {
    let path = root.join("fake-codex");
    std::fs::write(
        &path,
        "#!/bin/sh\n\
         dir=$(dirname \"$0\")\n\
         for a in \"$@\"; do printf '%s\\n' \"$a\" >> \"$dir/codex.argv\"; done\n\
         printf '%s\\n' \"$CODEX_HOME\" > \"$dir/codex.home\"\n\
         verb=$1\n\
         id=$2\n\
         found=$(find \"$CODEX_HOME/sessions\" -name \"*$id*\" 2>/dev/null | head -1)\n\
         if [ -z \"$found\" ]; then\n\
         printf 'Error: no saved session with id %s\\n' \"$id\" >&2\n\
         exit 1\n\
         fi\n\
         case \"$verb\" in\n\
         archive) mkdir -p \"$CODEX_HOME/archived_sessions\"; mv \"$found\" \"$CODEX_HOME/archived_sessions/\"; printf 'Archived session %s.\\n' \"$id\" ;;\n\
         delete) rm -f \"$found\"; printf 'Deleted session %s.\\n' \"$id\" ;;\n\
         *) printf 'unknown verb %s\\n' \"$verb\" >&2; exit 2 ;;\n\
         esac\n",
    )
    .unwrap();
    #[cfg(unix)]
    {
        use std::os::unix::fs::PermissionsExt;
        std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();
    }
    path
}

fn codex_params(codex_home: &Path, session: &str) -> Value {
    json!({
        "harness": "codex",
        "session": session,
        "homes": {"codex": codex_home.join("sessions")},
    })
}

#[tokio::test]
async fn codex_archive_runs_the_harnesss_own_verb_and_reports_its_store() {
    let _guard = bin_lock();
    let root = scratch("codex-archive");
    let home = root.join("codex_home");
    let workspace = root.join("ws");
    std::fs::create_dir_all(&workspace).unwrap();
    write_rollout(&home, "cx-1", &workspace);
    std::env::set_var(CODEX_BIN_ENV, fake_codex(&root));

    let mut service = HarnessSessionService::new();
    let result = call(
        &mut service,
        "harness.v1.sessions.archive",
        codex_params(&home, "cx-1"),
    )
    .await;

    assert_eq!(ran_arguments(&result), "archive cx-1");
    assert_eq!(result["archived"], json!(true));
    assert_eq!(result["session"], json!("cx-1"));
    // The harness's own home reached the verb, not the ambient one.
    assert_eq!(
        std::fs::read_to_string(root.join("codex.home"))
            .unwrap()
            .trim(),
        home.to_string_lossy()
    );
    // codex moved the rollout; the active listing no longer holds it.
    assert!(home
        .join("archived_sessions")
        .read_dir()
        .unwrap()
        .next()
        .is_some());
    assert!(result.get("row").is_none() || result["row"].is_null());
    std::env::remove_var(CODEX_BIN_ENV);
}

#[tokio::test]
async fn codex_delete_is_verified_against_the_store_and_a_failure_carries_stderr() {
    let _guard = bin_lock();
    let root = scratch("codex-delete");
    let home = root.join("codex_home");
    let workspace = root.join("ws");
    std::fs::create_dir_all(&workspace).unwrap();
    write_rollout(&home, "cx-2", &workspace);
    std::env::set_var(CODEX_BIN_ENV, fake_codex(&root));

    let mut service = HarnessSessionService::new();
    let result = call(
        &mut service,
        "harness.v1.sessions.delete",
        codex_params(&home, "cx-2"),
    )
    .await;
    assert_eq!(ran_arguments(&result), "delete cx-2 --force");
    assert_eq!(result["deleted"], json!(true));
    assert!(result.get("row").is_none());

    // A verb that fails surfaces the HARNESS'S own message, never a success.
    let error = call_err(
        &mut service,
        "harness.v1.sessions.delete",
        codex_params(&home, "cx-nope"),
    )
    .await;
    assert_eq!(error["code"], json!(-32000));
    let message = error["message"].as_str().unwrap();
    assert!(
        message.contains("no saved session with id cx-nope"),
        "the harness's own stderr must come through: {message}"
    );
    std::env::remove_var(CODEX_BIN_ENV);
}

// ---------------------------------------------------------------------------
// OpenCode — a mock server standing in for its own session API
// ---------------------------------------------------------------------------

/// A single-threaded mock OpenCode server.
///
/// `archived` decides whether the PATCH is HONORED: with `false` the server
/// accepts the request and stamps nothing, which is precisely the "a payload
/// the server ignored" case the re-read has to catch.
struct MockOpenCode {
    base_url: String,
    requests: std::sync::Arc<std::sync::Mutex<Vec<String>>>,
    _thread: std::thread::JoinHandle<()>,
}

fn mock_opencode(honor_patch: bool, bearer: Option<&'static str>) -> MockOpenCode {
    let listener = TcpListener::bind("127.0.0.1:0").unwrap();
    let base_url = format!("http://{}", listener.local_addr().unwrap());
    let requests = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));
    let log = std::sync::Arc::clone(&requests);
    let thread = std::thread::spawn(move || {
        let mut deleted = false;
        let mut archived_at: Option<u64> = None;
        for stream in listener.incoming() {
            let Ok(mut stream) = stream else { break };
            let mut reader = BufReader::new(stream.try_clone().unwrap());
            let mut line = String::new();
            if reader.read_line(&mut line).is_err() || line.trim().is_empty() {
                continue;
            }
            let request_line = line.trim().to_string();
            let mut length = 0usize;
            let mut authorization = String::new();
            loop {
                let mut header = String::new();
                if reader.read_line(&mut header).is_err() || header.trim().is_empty() {
                    break;
                }
                let lower = header.to_ascii_lowercase();
                if let Some(value) = lower.strip_prefix("content-length:") {
                    length = value.trim().parse().unwrap_or(0);
                }
                if lower.starts_with("authorization:") {
                    authorization = header.trim().to_string();
                }
            }
            let mut body = vec![0u8; length];
            if length > 0 {
                let _ = reader.read_exact(&mut body);
            }
            log.lock().unwrap().push(format!(
                "{request_line} | {authorization} | {}",
                String::from_utf8_lossy(&body)
            ));
            let method = request_line.split_whitespace().next().unwrap_or("");
            let (status, payload) = match method {
                "DELETE" => {
                    deleted = true;
                    ("200 OK", json!({"ok": true}))
                }
                "PATCH" => {
                    if honor_patch {
                        archived_at =
                            serde_json::from_slice::<Value>(&body)
                                .ok()
                                .and_then(|value| {
                                    value.pointer("/time/archived").and_then(Value::as_u64)
                                });
                    }
                    ("200 OK", json!({"ok": true}))
                }
                _ if deleted => ("404 Not Found", json!({"error": "not found"})),
                _ => (
                    "200 OK",
                    json!({
                        "id": "ses_1",
                        "title": "orch19 conversation",
                        "time": {"created": 1, "updated": 2, "archived": archived_at},
                    }),
                ),
            };
            let _ = bearer; // asserted by the caller against `requests`
            let body = serde_json::to_string(&payload).unwrap();
            let _ = write!(
                stream,
                "HTTP/1.1 {status}\r\ncontent-type: application/json\r\ncontent-length: {}\r\nconnection: close\r\n\r\n{body}",
                body.len()
            );
            let _ = stream.flush();
        }
    });
    MockOpenCode {
        base_url,
        requests,
        _thread: thread,
    }
}

fn opencode_params(server: &MockOpenCode, extra: Value) -> Value {
    let mut params = json!({
        "harness": "opencode",
        "session": "ses_1",
        "base_url": server.base_url,
    });
    for (key, value) in extra.as_object().unwrap() {
        params[key] = value.clone();
    }
    params
}

#[tokio::test]
async fn opencode_delete_goes_through_its_own_api_and_is_verified_by_the_re_read() {
    let server = mock_opencode(true, None);
    let mut service = HarnessSessionService::new();
    let result = call(
        &mut service,
        "harness.v1.sessions.delete",
        opencode_params(&server, json!({"bearer": "connect-secret"})),
    )
    .await;

    assert_eq!(result["deleted"], json!(true));
    assert!(result.get("row").is_none());
    let ran = result["ran"].as_str().unwrap();
    assert!(ran.starts_with("DELETE http://"), "{ran}");
    assert!(
        !ran.contains("connect-secret"),
        "a credential must never reach the narration: {ran}"
    );
    let requests = server.requests.lock().unwrap().clone();
    assert!(
        requests[0].starts_with("DELETE /session/ses_1"),
        "{requests:?}"
    );
    assert!(
        requests[0]
            .to_ascii_lowercase()
            .contains("bearer connect-secret"),
        "the credential must reach the SERVER: {requests:?}"
    );
    // The verification read is the server's own, not a file scan.
    assert!(
        requests[1].starts_with("GET /session/ses_1"),
        "{requests:?}"
    );
}

#[tokio::test]
async fn opencode_archive_fails_when_the_server_never_stamped_it() {
    // A server that accepts the PATCH and records nothing is the "supercode
    // guessed the payload wrong" case: it must be a loud failure, never a
    // reported success.
    let ignoring = mock_opencode(false, None);
    let mut service = HarnessSessionService::new();
    let error = call_err(
        &mut service,
        "harness.v1.sessions.archive",
        opencode_params(&ignoring, json!({})),
    )
    .await;
    assert_eq!(error["code"], json!(-32000));
    assert!(error["message"]
        .as_str()
        .unwrap()
        .contains("still lists `ses_1` as an active conversation"));

    let honoring = mock_opencode(true, None);
    let result = call(
        &mut service,
        "harness.v1.sessions.archive",
        opencode_params(&honoring, json!({})),
    )
    .await;
    assert_eq!(result["archived"], json!(true));
    assert!(result["row"]["time"]["archived"].as_u64().is_some());
}

// ---------------------------------------------------------------------------
// Hermes / OpenClaw — `/new` typed into a live driven session
// ---------------------------------------------------------------------------

/// A mock ACP agent that completes the handshake, opens a session, and appends
/// every prompt it receives to `prompts.log`.
fn mock_acp_agent(root: &Path) -> PathBuf {
    let path = root.join("mock-acp");
    let log = root.join("prompts.log");
    std::fs::write(
        &path,
        format!(
            "#!/bin/sh\n\
             while IFS= read -r line; do\n\
             id=$(printf '%s' \"$line\" | sed -n 's/.*\"id\":\\([0-9]*\\).*/\\1/p')\n\
             case \"$line\" in\n\
             *'\"method\":\"initialize\"'*)\n\
             printf '{{\"jsonrpc\":\"2.0\",\"id\":%s,\"result\":{{\"protocolVersion\":1,\"agentCapabilities\":{{\"loadSession\":false,\"promptCapabilities\":{{}}}},\"authMethods\":[]}}}}\\n' \"$id\" ;;\n\
             *'\"method\":\"session/new\"'*)\n\
             printf '{{\"jsonrpc\":\"2.0\",\"id\":%s,\"result\":{{\"sessionId\":\"hermes-live-1\"}}}}\\n' \"$id\" ;;\n\
             *'\"method\":\"session/prompt\"'*)\n\
             printf '%s\\n' \"$line\" >> '{log}'\n\
             printf '{{\"jsonrpc\":\"2.0\",\"id\":%s,\"result\":{{\"stopReason\":\"end_turn\"}}}}\\n' \"$id\" ;;\n\
             *'\"id\"'*)\n\
             printf '{{\"jsonrpc\":\"2.0\",\"id\":%s,\"result\":{{}}}}\\n' \"$id\" ;;\n\
             esac\n\
             done\n",
            log = log.display()
        ),
    )
    .unwrap();
    #[cfg(unix)]
    {
        use std::os::unix::fs::PermissionsExt;
        std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();
    }
    path
}

#[tokio::test]
async fn the_live_door_types_the_harnesss_own_slash_command_into_the_session() {
    let root = scratch("live-slash");
    let workspace = root.join("ws");
    std::fs::create_dir_all(&workspace).unwrap();
    let agent = mock_acp_agent(&root);
    let start = |harness: &str| {
        json!({
            "harness": harness,
            "cwd": workspace,
            "protocol": "acp",
            "launch": {"program": agent, "arguments": [], "env": {}},
        })
    };

    let mut service = HarnessSessionService::new();
    let started = call(&mut service, "harness.v1.runtimes.start", start("hermes")).await;
    let reset = call(
        &mut service,
        "harness.v1.sessions.reset",
        json!({
            "harness": "hermes",
            "connection": started["connection"],
            "homes": {"hermes": root.join("hermes/state.db")},
        }),
    )
    .await;
    assert_eq!(reset["verb"], json!("reset"));
    assert_eq!(reset["ran"], json!("hermes live session: /reset"));
    // With no `session` named, the outcome names the conversation the runtime
    // itself reports — never one supercode invented.
    assert_eq!(reset["session"], json!("hermes-live-1"));

    // A slash command occupies a turn exactly as a typed message does, so the
    // second command goes to its own runtime rather than racing the first.
    let second = call(&mut service, "harness.v1.runtimes.start", start("openclaw")).await;
    let opened = call(
        &mut service,
        "harness.v1.sessions.new",
        json!({
            "harness": "openclaw",
            "connection": second["connection"],
            "homes": {"openclaw": root.join("openclaw")},
        }),
    )
    .await;
    assert_eq!(opened["ran"], json!("openclaw live session: /new"));

    // The agent received the harnesses' own commands, over the same prompt
    // path a human's message takes.
    let mut prompts = String::new();
    for _ in 0..100 {
        prompts = std::fs::read_to_string(root.join("prompts.log")).unwrap_or_default();
        if prompts.contains("/new") && prompts.contains("/reset") {
            break;
        }
        tokio::time::sleep(std::time::Duration::from_millis(50)).await;
    }
    assert!(
        prompts.contains("/reset"),
        "the harness must have received its own slash command: {prompts}"
    );
    assert!(prompts.contains("/new"), "{prompts}");
}

/// The refusal that exists because the DOOR does not carry the command: Hermes
/// has `/new` in chat, but its ACP adapter does not advertise it and sends any
/// unrecognized `/word` to the model as prose. Sending it would be a silent
/// no-op, so it must be refused even though an open runtime is right there.
#[tokio::test]
async fn hermes_new_is_refused_because_its_acp_door_does_not_carry_the_command() {
    let root = scratch("hermes-new-refused");
    let workspace = root.join("ws");
    std::fs::create_dir_all(&workspace).unwrap();
    let agent = mock_acp_agent(&root);

    let mut service = HarnessSessionService::new();
    let started = call(
        &mut service,
        "harness.v1.runtimes.start",
        json!({
            "harness": "hermes",
            "cwd": workspace,
            "protocol": "acp",
            "launch": {"program": agent, "arguments": [], "env": {}},
        }),
    )
    .await;
    let error = call_err(
        &mut service,
        "harness.v1.sessions.new",
        json!({"harness": "hermes", "connection": started["connection"]}),
    )
    .await;
    assert_eq!(error["code"], json!(-32020));
    let message = error["message"].as_str().unwrap();
    assert!(message.contains("GATEWAY command"), "{message}");
    assert!(message.contains("`sessions.reset`"), "{message}");
    // Nothing reached the agent: a refusal is not a turn.
    assert!(!root.join("prompts.log").exists());
}

#[tokio::test]
async fn a_live_verb_without_an_open_runtime_says_which_door_it_needs() {
    let mut service = HarnessSessionService::new();
    let error = call_err(
        &mut service,
        "harness.v1.sessions.reset",
        json!({"harness": "openclaw", "session": "s1"}),
    )
    .await;
    assert_eq!(error["code"], json!(-32602));
    let message = error["message"].as_str().unwrap();
    assert!(message.contains("/reset"), "{message}");
    assert!(message.contains("connection"), "{message}");
}

// ---------------------------------------------------------------------------
// supercode's own store, and the refusals
// ---------------------------------------------------------------------------

#[tokio::test]
async fn supercode_archive_and_delete_act_on_its_own_store() {
    let root = scratch("own-store");
    let store = supercode_harness::SessionStore::open(&root).unwrap();
    store.save("orch19-one", "first", "").unwrap();
    store.save("orch19-two", "second", "").unwrap();

    let mut service = HarnessSessionService::new();
    let archived = call(
        &mut service,
        "harness.v1.sessions.archive",
        json!({"harness": "supercode", "session": "orch19-one", "homes": {"supercode": root}}),
    )
    .await;
    assert_eq!(archived["archived"], json!(true));
    assert_eq!(archived["row"]["archived"], json!(true));

    let deleted = call(
        &mut service,
        "harness.v1.sessions.delete",
        json!({"harness": "supercode", "session": "orch19-two", "homes": {"supercode": root}}),
    )
    .await;
    assert_eq!(deleted["deleted"], json!(true));
    assert!(!store.list().iter().any(|info| info.name == "orch19-two"));
}

#[tokio::test]
async fn every_harness_without_a_door_refuses_with_unsupported_action() {
    let mut service = HarnessSessionService::new();
    for (harness, method, needle) in [
        ("hermes", "harness.v1.sessions.archive", "BULK filter verb"),
        ("openclaw", "harness.v1.sessions.delete", "v2026.7.1-2"),
        ("openclaw", "harness.v1.sessions.archive", "v2026.7.1-2"),
        (
            "claude-code",
            "harness.v1.sessions.delete",
            "RETENTION WINDOW",
        ),
        (
            "claude-code",
            "harness.v1.sessions.new",
            "harness.v1.runtimes.start",
        ),
        ("pi", "harness.v1.sessions.archive", "publishes no door"),
    ] {
        let error = call_err(
            &mut service,
            method,
            json!({"harness": harness, "session": "whatever"}),
        )
        .await;
        assert_eq!(
            error["code"],
            json!(-32020),
            "{harness}/{method} must be unsupported_action: {error}"
        );
        let message = error["message"].as_str().unwrap();
        assert!(
            message.contains(needle),
            "{harness}/{method} must explain itself: {message}"
        );
    }
}

#[test]
fn the_four_verbs_are_published_on_every_surface() {
    for method in [
        "harness.v1.sessions.new",
        "harness.v1.sessions.reset",
        "harness.v1.sessions.archive",
        "harness.v1.sessions.delete",
    ] {
        assert!(
            HARNESS_SERVICE_METHODS.contains(&method),
            "`{method}` must be advertised by the service"
        );
        assert!(
            SdkOperation::from_method(method).is_some(),
            "`{method}` must have an SDK operation"
        );
    }
    for operation in [
        SdkOperation::SessionsNew,
        SdkOperation::SessionsReset,
        SdkOperation::SessionsArchive,
        SdkOperation::SessionsDelete,
    ] {
        assert!(SdkOperation::ALL.contains(&operation));
    }
}