Skip to content

Commit b53e70a

Browse files
author
SqlRush
committed
Accept wrapped string action payloads
1 parent 0c6b799 commit b53e70a

5 files changed

Lines changed: 82 additions & 4 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ M7 补充:prompt history `LogEntry` 读取现在接受 `sessionID`/`session`/`
588588

589589
本轮补充:interaction script action/type/kind/name/operation 动作判别字段现在接受 compact/camel fixture aliases,例如 `typeText``inputText``insertText``keyPress``pressKey``keySequence``pasteText``pastedText``clipboardText``setStatus``statusLine``terminalSize``screenSize`
590590

591+
本轮补充:interaction script 的 typeText/pasteText/setStatus/snapshot 字符串 action payload 现在递归解包 JSON:API/GraphQL-style wrapper,wrapped prompt text、paste text、status text 和 snapshot name 可直接驱动对应脚本步骤。
592+
591593
本轮补充:interaction script 的 resize/terminalSize/screenSize action payload 现在递归解包 `value`/`payload`/`data`/`resource`/`attributes`/`properties`/`attrs`/`edge.node` 等 wrapper,JSON:API/GraphQL fixture 中的 columns/rows 可直接驱动 screen resize。
592594

593595
本轮补充:interaction script action/type/kind/name/operation 动作判别字段现在也接受 compact/camel event/media aliases,包括 `focusIn``focusOut``mouseEvent``pasteImage``imagePaste`

docs/claude-code-go-rewrite-plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ test/parity/ # golden tests against TS/official behavior
305305
- 本轮补充:interaction script 的 `keys` 字段支持 printable text chunk 和空格分隔 named-key sequence,例如 `ctrl-x ctrl-k`,减少官方脚本把连续输入拆成数组的改写成本。
306306
- 本轮补充:interaction script key input 接受 press-style aliases,包括 `press``keyPress``keypress``shortcutKey``presses``keyPresses``shortcuts`
307307
- 本轮补充:interaction script action/type/kind/name/operation 动作判别字段接受 compact/camel fixture aliases,包括 `typeText``inputText``insertText``keyPress``pressKey``keySequence``pasteText``pastedText``clipboardText``setStatus``statusLine``terminalSize``screenSize`
308+
- 本轮补充:interaction script 的 typeText/pasteText/setStatus/snapshot 字符串 action payload 现在递归解包 JSON:API/GraphQL-style wrapper,`payload.resource.attributes.text``edge.node.attrs.content``resource.attributes.message` 和 wrapped snapshot `name` 可直接驱动 prompt、paste、status 与 snapshot capture。
308309
- 本轮补充:interaction script resize/terminalSize/screenSize action payload 现在递归解包 `value`/`payload`/`data`/`resource`/`attributes`/`properties`/`attrs`/`edge.node` 等 wrapper,官方/API fixture 可把 columns/rows 放在 JSON:API 或 GraphQL envelope 内。
309310
- 本轮补充:interaction script action/type/kind/name/operation 动作判别字段继续接受 compact/camel event/media aliases,包括 `focusIn``focusOut``mouseEvent``pasteImage``imagePaste`
310311
- 本轮补充:interaction script mouseEvent/pasteImage action payload 现在递归解包 JSON:API/GraphQL-style `resource`/`attributes`/`properties`/`attrs`/`edge.node` wrapper,wrapped mouse 坐标/按钮和 image filename/media/content 可直接驱动 dialog click 与 image paste。

docs/first-second-parity-audit.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ M7 progress now includes:
359359
- `internal/contracts`/`internal/session`: content block decoding now accepts text aliases such as `body`/`message`/`value`/`output`/`contentText`/`content_text` and string `content` for `text`/`thinking` blocks, so transcript resume preserves these nested block variants.
360360
- `internal/tui`: interaction script steps now accept `action`/`type`/`kind`/`name`/`operation` discriminator aliases for common actions such as key press, key sequences, text input, paste, status updates, resize, mouse/image, and focus/blur.
361361
- `internal/tui`: interaction script action discriminators now accept compact/camel fixture names such as `typeText`, `inputText`, `insertText`, `keyPress`, `pressKey`, `keySequence`, `pasteText`, `pastedText`, `clipboardText`, `setStatus`, `statusLine`, `terminalSize`, and `screenSize`.
362+
- `internal/tui`: string action payloads for type, paste, status, and snapshot capture now recursively unwrap JSON:API/GraphQL-style wrappers, preserving wrapped prompt text, paste text, status text, and snapshot names from API-shaped interaction fixtures.
362363
- `internal/tui`: resize, terminal-size, and screen-size action payloads now recursively unwrap JSON:API/GraphQL-style wrappers such as `resource.attributes` and `edge.node.attrs`, preserving columns/rows from API-shaped interaction fixtures.
363364
- `internal/tui`: interaction script action discriminators now also accept compact event/media fixture names such as `focusIn`, `focusOut`, `mouseEvent`, `pasteImage`, and `imagePaste`.
364365
- `internal/tui`: mouse and image action payloads now recursively unwrap JSON:API/GraphQL-style wrappers, preserving wrapped mouse button/coordinate fields and image filename/media/content fields for scripted dialog clicks and paste-image prompts.

internal/tui/script_aliases.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,19 +1303,19 @@ func applyScriptStepActionAlias(step *ScriptStep, fields map[string]json.RawMess
13031303
}
13041304
case "text", "type", "typetext", "type-text", "input", "inputtext", "textinput", "insert", "inserttext", "write", "writetext":
13051305
if step.Text == "" {
1306-
step.Text = stringJSONField(fields, "value", "text", "input", "content", "body", "message", "data", "payload")
1306+
step.Text = scriptActionStringField(fields, "text", "input", "content", "body", "message", "data", "payload", "value")
13071307
}
13081308
case "paste", "pastetext", "pastedtext", "clipboard", "clipboardtext":
13091309
if step.Paste == "" {
1310-
step.Paste = stringJSONField(fields, "value", "paste", "clipboard", "text", "content", "data", "payload")
1310+
step.Paste = scriptActionStringField(fields, "paste", "clipboard", "text", "content", "body", "message", "data", "payload", "value")
13111311
}
13121312
case "status", "setstatus", "set-status", "statusline", "status-line":
13131313
if step.Status == "" {
1314-
step.Status = stringJSONField(fields, "value", "status", "text", "content", "message", "data", "payload")
1314+
step.Status = scriptActionStringField(fields, "status", "text", "content", "body", "message", "data", "payload", "value")
13151315
}
13161316
case "snapshot", "capture", "capture-snapshot":
13171317
if step.SnapshotName == "" {
1318-
step.SnapshotName = stringJSONField(fields, "value", "snapshot", "name", "label", "id", "data", "payload")
1318+
step.SnapshotName = scriptActionStringField(fields, "snapshot", "name", "label", "id", "data", "payload", "value")
13191319
}
13201320
case "resize", "terminalsize", "terminal-size", "screensize", "screen-size":
13211321
if step.ResizeWidth <= 0 || step.ResizeHeight <= 0 {

internal/tui/tui_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5535,6 +5535,80 @@ func TestRunInteractionScriptAcceptsWrappedResizeActionPayloads(t *testing.T) {
55355535
}
55365536
}
55375537

5538+
func TestRunInteractionScriptAcceptsWrappedStringActionPayloads(t *testing.T) {
5539+
steps, err := ParseInteractionScript([]byte(`[
5540+
{
5541+
"action": "typeText",
5542+
"payload": {
5543+
"resource": {
5544+
"attributes": {
5545+
"text": "hi"
5546+
}
5547+
}
5548+
},
5549+
"expectPrompt": {"text": "hi"}
5550+
},
5551+
{
5552+
"type": "keyPress",
5553+
"payload": "enter",
5554+
"expectEvent": {"type": "prompt_submitted", "value": "hi"},
5555+
"expectPrompt": {"empty": true}
5556+
},
5557+
{
5558+
"name": "pasteText",
5559+
"payload": {
5560+
"edge": {
5561+
"node": {
5562+
"attrs": {
5563+
"content": "clip"
5564+
}
5565+
}
5566+
}
5567+
},
5568+
"expectPrompt": {"text": "[Pasted text #1]", "expandedText": "clip", "pastedContentCount": 1}
5569+
},
5570+
{
5571+
"operation": "setStatus",
5572+
"payload": {
5573+
"resource": {
5574+
"attributes": {
5575+
"message": "wrapped status"
5576+
}
5577+
}
5578+
},
5579+
"expectStatusContains": "wrapped status"
5580+
},
5581+
{"message": {"role": "assistant", "text": "ready"}},
5582+
{
5583+
"action": "snapshot",
5584+
"payload": {
5585+
"edge": {
5586+
"node": {
5587+
"attrs": {
5588+
"name": "wrapped-snapshot"
5589+
}
5590+
}
5591+
}
5592+
},
5593+
"expectSnapshotContains": "assistant: ready"
5594+
}
5595+
]`))
5596+
if err != nil {
5597+
t.Fatal(err)
5598+
}
5599+
screen := NewREPLScreen(40, 8, nil)
5600+
result, err := RunInteractionScriptChecked(&screen, steps)
5601+
if err != nil {
5602+
t.Fatal(err)
5603+
}
5604+
if len(result.Events) != 1 || result.Events[0].Type != ScreenEventPromptSubmitted || result.Events[0].Value != "hi" {
5605+
t.Fatalf("events = %#v", result.Events)
5606+
}
5607+
if len(result.Snapshots) != 1 || result.Snapshots[0].Name != "wrapped-snapshot" {
5608+
t.Fatalf("snapshots = %#v", result.Snapshots)
5609+
}
5610+
}
5611+
55385612
func TestRunInteractionScriptAcceptsCompactEventActionAliases(t *testing.T) {
55395613
steps, err := ParseInteractionScript([]byte(`[
55405614
{"action":"focusOut","expectEvent":{"type":"focus_out"},"expectFocused":false},

0 commit comments

Comments
 (0)