Skip to content

Commit f44551c

Browse files
author
SqlRush
committed
Accept string task expectations
1 parent cacabcb commit f44551c

4 files changed

Lines changed: 61 additions & 26 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ M7 补充:prompt history `LogEntry` 读取现在接受 `sessionID`/`session`/`
606606

607607
本轮补充:interaction script 的 direct expectation count alias 字段现在也递归解包 wrapper;`expectEventCount``expectTotalEventCount``expectDialogResultCount``expectTotalDialogResultCount` 可从 wrapped `value`/`count`/`total` 恢复计数断言,避免 direct expectation fixture 在 int decode 阶段失败。
608608

609-
本轮补充:interaction script 的 UpperCamel step 字段现在也复用 raw/wrapper 解析;`UpsertTask``CancelAllTasks``OpenTasksDialog``ExpectEvent(s)``ExpectDialog``ExpectDialogResult(s)``ExpectPrompt``ExpectVim``ExpectScreen``ExpectViewport``ExpectReverseSearch``ExpectTasks` 等 Go 默认字段名可直接接受 JSON:API/GraphQL-style wrapper,task status/expectation 的 ID/title/state/detail/progress、event expectation 的 Type/Value/DialogID、dialog expectation 的 Active/ActionCount/FocusedIndex、dialog-result expectation 的 ID/Found/Stale、prompt expectation 的 Cursor/PastedContentCount/NextPastedID/Empty、pasted-content expectation 的 ID/MediaType/Filename/ContentContains、vim expectation 的 Enabled/Mode/Register/RegisterLinewise、screen expectation 的 Width/Height、viewport expectation 的 Offset/VisibleLineCount 和 reverse-search expectation 的 Cursor/ResultCount/NoResults 改为 raw-first 解码并继续接受数字字符串/非严格 bool。
609+
本轮补充:interaction script 的 UpperCamel step 字段现在也复用 raw/wrapper 解析;`UpsertTask`、`CancelAllTasks`、`OpenTasksDialog`、`ExpectEvent(s)`、`ExpectDialog`、`ExpectDialogResult(s)`、`ExpectPrompt`、`ExpectVim`、`ExpectScreen`、`ExpectViewport`、`ExpectReverseSearch`、`ExpectTasks` 等 Go 默认字段名可直接接受 JSON:API/GraphQL-style wrapper,task status/expectation 的 ID/title/state/detail/progress、tasks expectation 的 Count/StateCounts、event expectation 的 Type/Value/DialogID、dialog expectation 的 Active/ActionCount/FocusedIndex、dialog-result expectation 的 ID/Found/Stale、prompt expectation 的 Cursor/PastedContentCount/NextPastedID/Empty、pasted-content expectation 的 ID/MediaType/Filename/ContentContains、vim expectation 的 Enabled/Mode/Register/RegisterLinewise、screen expectation 的 Width/Height、viewport expectation 的 Offset/VisibleLineCount 和 reverse-search expectation 的 Cursor/ResultCount/NoResults 改为 raw-first 解码并继续接受数字字符串/非严格 bool。
610610

611611
本轮补充:interaction script 的 direct expectation string-list alias 字段现在也递归解包 wrapper;`expectStatusContains`/`NotContains``expectSnapshotContains`/`NotContains` 可从 wrapped `value`/`values`/`contains`/`items` 恢复断言列表,避免 direct expectation fixture 在 list decode 阶段失败。
612612

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ test/parity/ # golden tests against TS/official behavior
333333
- 本轮补充:interaction script 的 direct dialog 字段现在改为 raw payload 解析;`dialog`/`Dialog` 可递归解包 `resource.attributes``edge.node.attrs` 和单元素数组,`showDialog` action payload 也复用同一解析路径,避免 wrapper-only dialog 被解码成空弹窗。
334334
- 本轮补充:interaction script 的 direct image 字段现在改为 raw payload 解析;`image`/`Image` 可复用 pasteImage action 的 wrapper 解析,递归解包 `resource.attributes``edge.node.attrs` 和单元素数组,保留 filename/media/content/source-path 后再生成 prompt pasted-image。
335335
- 本轮补充:interaction script 的 direct keybinding mutation 字段现在改为 raw-only 解析;`keybindings`/`key_bindings`/`keyBindings`/`keybindingSpecs`/`Keybindings` 不再先走 `[]BindingSpec` 基础解码,统一复用 keybinding loader 的 object-map、resource wrapper 和 edge/node collection parser。
336-
- 本轮补充:interaction script 的 UpperCamel step 字段现在也进入 raw/wrapper 解析路径;`UpsertTask`、`CancelAllTasks`、`OpenTasksDialog`、`ExpectEvent(s)`、`ExpectDialog`、`ExpectDialogResult(s)`、`ExpectPrompt`、`ExpectVim`、`ExpectScreen`、`ExpectViewport`、`ExpectReverseSearch`、`ExpectTasks` 等 Go 默认字段名可直接接受 JSON:API/GraphQL-style wrapper,task status/expectation 的 ID/title/state/detail/progress、event expectation 的 Type/Value/DialogID、dialog expectation 的 Active/ActionCount/FocusedIndex、dialog-result expectation 的 ID/Found/Stale、prompt expectation 的 Cursor/PastedContentCount/NextPastedID/Empty、pasted-content expectation 的 ID/MediaType/Filename/ContentContains、vim expectation 的 Enabled/Mode/Register/RegisterLinewise、screen expectation 的 Width/Height、viewport expectation 的 Offset/VisibleLineCount 和 reverse-search expectation 的 Cursor/ResultCount/NoResults 改为 raw-first 解码并继续接受数字字符串/非严格 bool。
336+
- 本轮补充:interaction script 的 UpperCamel step 字段现在也进入 raw/wrapper 解析路径;`UpsertTask`、`CancelAllTasks`、`OpenTasksDialog`、`ExpectEvent(s)`、`ExpectDialog`、`ExpectDialogResult(s)`、`ExpectPrompt`、`ExpectVim`、`ExpectScreen`、`ExpectViewport`、`ExpectReverseSearch`、`ExpectTasks` 等 Go 默认字段名可直接接受 JSON:API/GraphQL-style wrapper,task status/expectation 的 ID/title/state/detail/progress、tasks expectation 的 Count/StateCounts、event expectation 的 Type/Value/DialogID、dialog expectation 的 Active/ActionCount/FocusedIndex、dialog-result expectation 的 ID/Found/Stale、prompt expectation 的 Cursor/PastedContentCount/NextPastedID/Empty、pasted-content expectation 的 ID/MediaType/Filename/ContentContains、vim expectation 的 Enabled/Mode/Register/RegisterLinewise、screen expectation 的 Width/Height、viewport expectation 的 Offset/VisibleLineCount 和 reverse-search expectation 的 Cursor/ResultCount/NoResults 改为 raw-first 解码并继续接受数字字符串/非严格 bool。
337337
- 本轮补充:terminal CSI-u/kitty keyboard parser 接受 `codepoint:alternate``modifier:event-type` 冒号字段,按主 codepoint/modifier 解析 ctrl/alt/shift/rune 键,覆盖 kitty progressive keyboard protocol 的常见变体。
338338
- 本轮补充:terminal CSI-u/kitty keyboard parser 接受无 modifier 字段或 modifier `1` 的 base key 序列,覆盖 printable rune、Enter、Tab、Esc 和 Backspace,避免 extended-key 模式下普通键序列被解析成 unknown。
339339
- 本轮补充:terminal input parser 接受 xterm modified arrow 序列(如 `CSI 1;2D``CSI 1;6C``CSI 1;7D`),把 shift-arrow 降级为方向键、alt-arrow 映射到 word-motion key、ctrl/ctrl+alt-arrow 映射到 ctrl word-motion key,避免 extended navigation 序列落入 unknown。

internal/tui/script_aliases.go

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4312,6 +4312,28 @@ func intMapJSONField(fields map[string]json.RawMessage, names ...string) map[str
43124312
if err := json.Unmarshal(raw, &value); err == nil {
43134313
return value
43144314
}
4315+
var rawValues map[string]json.RawMessage
4316+
if err := json.Unmarshal(raw, &rawValues); err != nil {
4317+
continue
4318+
}
4319+
value = make(map[string]int, len(rawValues))
4320+
for key, rawValue := range rawValues {
4321+
var intValue int
4322+
if err := json.Unmarshal(rawValue, &intValue); err == nil {
4323+
value[key] = intValue
4324+
continue
4325+
}
4326+
var stringValue string
4327+
if err := json.Unmarshal(rawValue, &stringValue); err != nil {
4328+
return nil
4329+
}
4330+
parsed, err := strconv.Atoi(strings.TrimSpace(stringValue))
4331+
if err != nil {
4332+
return nil
4333+
}
4334+
value[key] = parsed
4335+
}
4336+
return value
43154337
}
43164338
return nil
43174339
}
@@ -4752,36 +4774,49 @@ func (expect *VimExpectation) UnmarshalJSON(data []byte) error {
47524774
}
47534775

47544776
func (expect *TasksExpectation) UnmarshalJSON(data []byte) error {
4755-
data = normalizeObjectFieldsToArray(data, "contains")
4777+
data = normalizeObjectFieldsToArray(data, "Contains", "contains")
47564778
type alias TasksExpectation
47574779
var raw alias
4758-
if err := json.Unmarshal(data, &raw); err != nil {
4780+
if err := json.Unmarshal(stripJSONAliasFields(data,
4781+
"Count",
4782+
"count",
4783+
"TaskCount",
4784+
"task_count",
4785+
"taskCount",
4786+
"Total",
4787+
"total",
4788+
"Size",
4789+
"size",
4790+
"Length",
4791+
"length",
4792+
"StateCounts",
4793+
"state_counts",
4794+
"stateCounts",
4795+
"StatusCounts",
4796+
"status_counts",
4797+
"statusCounts",
4798+
"Counts",
4799+
"counts",
4800+
"CountsByState",
4801+
"counts_by_state",
4802+
"countsByState",
4803+
"ByState",
4804+
"by_state",
4805+
"byState",
4806+
), &raw); err != nil {
47594807
return err
47604808
}
47614809
*expect = TasksExpectation(raw)
47624810

4763-
var fields struct {
4764-
StateCounts map[string]int `json:"state_counts"`
4765-
StateCountsCamel map[string]int `json:"stateCounts"`
4766-
}
4767-
if err := json.Unmarshal(data, &fields); err != nil {
4768-
return err
4769-
}
47704811
fieldMap := map[string]json.RawMessage{}
47714812
if err := json.Unmarshal(data, &fieldMap); err != nil {
47724813
return err
47734814
}
47744815
if expect.Count == nil {
4775-
expect.Count = intPtrJSONField(fieldMap, "task_count", "taskCount", "total", "size", "length")
4776-
}
4777-
if fields.StateCounts != nil {
4778-
expect.StateCounts = fields.StateCounts
4779-
}
4780-
if fields.StateCountsCamel != nil {
4781-
expect.StateCounts = fields.StateCountsCamel
4816+
expect.Count = intPtrJSONField(fieldMap, "Count", "count", "TaskCount", "task_count", "taskCount", "Total", "total", "Size", "size", "Length", "length")
47824817
}
47834818
if len(expect.StateCounts) == 0 {
4784-
expect.StateCounts = intMapJSONField(fieldMap, "status_counts", "statusCounts", "counts", "counts_by_state", "countsByState", "by_state", "byState")
4819+
expect.StateCounts = intMapJSONField(fieldMap, "StateCounts", "state_counts", "stateCounts", "StatusCounts", "status_counts", "statusCounts", "Counts", "counts", "CountsByState", "counts_by_state", "countsByState", "ByState", "by_state", "byState")
47854820
}
47864821
return nil
47874822
}

internal/tui/tui_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7157,9 +7157,9 @@ func TestRunDialogRuntimeScriptAcceptsWrappedTaskExpectationAliasFields(t *testi
71577157
"expectTasks": {
71587158
"resource": {
71597159
"attributes": {
7160-
"taskCount": 1,
7161-
"statusCounts": {"running": 1},
7162-
"contains": {"taskId": "task_1", "taskTitle": "Build", "status": "running", "statusText": "go test", "progressPercent": 40}
7160+
"Count": "1",
7161+
"StateCounts": {"running": "1"},
7162+
"Contains": {"ID": "task_1", "Title": "Build", "State": "running", "Detail": "go test", "Progress": "40"}
71637163
}
71647164
}
71657165
}
@@ -7171,9 +7171,9 @@ func TestRunDialogRuntimeScriptAcceptsWrappedTaskExpectationAliasFields(t *testi
71717171
"edge": {
71727172
"node": {
71737173
"attrs": {
7174-
"total": 1,
7175-
"countsByState": {"cancelled": 1},
7176-
"contains": {"id": "task_1", "state": "cancelled", "detail": "stopped"}
7174+
"Count": "1",
7175+
"StateCounts": {"cancelled": "1"},
7176+
"Contains": {"ID": "task_1", "State": "cancelled", "Detail": "stopped"}
71777177
}
71787178
}
71797179
}
@@ -7184,7 +7184,7 @@ func TestRunDialogRuntimeScriptAcceptsWrappedTaskExpectationAliasFields(t *testi
71847184
"expectTasks": {
71857185
"resource": {
71867186
"attributes": {
7187-
"taskCount": 0
7187+
"Count": "0"
71887188
}
71897189
}
71907190
}

0 commit comments

Comments
 (0)