Files
kilocode/packages/kilo-vscode/tests/unit/memory-command.test.ts
T
rakshith1928 2246ef70b5 fix(webview): preserve existing text when selecting slash command at start (#11728)
* fix(webview): preserve existing text when selecting slash command at input start

* remove unwanted check not related to pr

* fix(webview): update test mocks for new select() cursor usage and add trailing text tests

* chore: add changeset for slash command trailing text fix

* fix(webview): add slashEnd signal to fix cursor-corruption bug when selecting slash commands

* chore(test): fix redundant double type assertion in use-slash-command.test.ts

* address the pr review comments

* fix(test): use full text length as onInput cursor in review slash test

* fix: preserve trailing text on no-argument /memory commands

* refactor: drop review commit and review pr slash suggestions

* fix(webview): place caret at start when preserving trailing text for action commands

* fix(kilo-memory): preserve trailing text for /memory show like other no-arg commands

* fix(kilo-vscode): update mirrored /memory show fixture for rest field

* fix(kilo-vscode): format prompt-input-utils.ts to satisfy prettier

* fix(kilo-vscode): place caret at start for preserved /memory text
2026-08-14 15:07:53 +02:00

70 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "bun:test"
import { parseMemoryCommand, type ParsedMemoryCommand } from "../../webview-ui/src/utils/memory-command"
type MemoryOperation =
| "enable"
| "status"
| "inspect"
| "disable"
| "rebuild"
| "remember"
| "correct"
| "forget"
| "purge"
| "auto"
type Case = {
name: string
input: string
result: "none" | "help" | "show" | "operation" | "usage"
operation?: MemoryOperation
mode?: "status" | "on" | "off"
confirm?: boolean
text?: string
query?: string
reason?: string
rest?: string
}
const cases = (await Bun.file(
new URL("../../../kilo-memory/test/command-cases.json", import.meta.url),
).json()) as Case[]
function expected(item: Case): ParsedMemoryCommand | undefined {
if (item.result === "none") return
if (item.result === "help") return { kind: "help" }
if (item.result === "show") return { kind: "show", rest: item.rest ?? "" }
if (item.result === "usage") return { kind: "usage", reason: item.reason ?? "" }
if (!item.operation) throw new Error(`Missing operation for fixture: ${item.name}`)
if (item.operation === "remember" || item.operation === "correct") {
if (!item.text) throw new Error(`Missing text for fixture: ${item.name}`)
return { kind: "operation", operation: item.operation, text: item.text }
}
if (item.operation === "forget") {
if (!item.query) throw new Error(`Missing query for fixture: ${item.name}`)
return { kind: "operation", operation: item.operation, query: item.query }
}
if (item.operation === "auto") {
if (!item.mode) throw new Error(`Missing mode for fixture: ${item.name}`)
return { kind: "operation", operation: item.operation, mode: item.mode }
}
if (item.operation === "purge") {
if (item.confirm !== true) throw new Error(`Missing confirmation for fixture: ${item.name}`)
return { kind: "operation", operation: item.operation, confirm: true }
}
return { kind: "operation", operation: item.operation, rest: item.rest ?? "" }
}
describe("parseMemoryCommand", () => {
it("matches shared command fixtures", () => {
for (const item of cases) {
const parsed = parseMemoryCommand(item.input)
if (item.result === "usage") {
expect(parsed?.kind, item.name).toBe("usage")
expect(parsed && "reason" in parsed ? parsed.reason : "", item.name).toContain(item.reason ?? "")
continue
}
expect(parsed, item.name).toEqual(expected(item))
}
})
})