Files
alchemist-accessibility/accessibility/tests/test_history.lua
T
Accessibility ModandClaude Opus 5 fe872be683 Phase 1: console history, review keys, and wall tones
Game-file footprint unchanged: still one line in main.lua.

Console (Q4: speak everything queued, cancelled by explicit action):
- history.lua keeps our own unbounded history, since the game's console buffer
  expires entries after 3s. Mirrors the game's (xN) coalescing so what is heard
  matches what is on screen. The review cursor holds position while new lines
  arrive rather than being yanked to the tail mid-read.
- patches/console.lua wraps console.print, calling the real one first so a bug
  on our side cannot swallow a message the player would otherwise see.
- Any keypress reaching the game silences the pending speech backlog.

Hotkeys: [ and ] review, Shift+[/] jump to ends, \ repeat, Shift+\ copy.
Chosen from scancodes the game does not bind. Note keybindings.getCommand()
ignores modifiers, so Ctrl+Up would read to the game as a movement -- our keys
are consumed and never overlay a game-claimed scancode.

Wall tones (Q5: on step, 3D-positioned, radius 5):
- Direction and distance are deliberately decoupled. The listener sits at the
  camera 4 units above the plane under an inverse distance model, so placing a
  tone at the wall's real position would make distant walls quieter (the
  opposite of the request) and collapse the stereo pan. Instead the source sits
  at a fixed radius in the wall's direction at listener height, and volume is
  computed explicitly from distance.
- Step detection polls player coordinates rather than hooking movement, so it
  covers walking, pathing, portals and pushes for free.
- Respects FoV/rememberedFoV; never leaks unseen geometry.

tests/test_history.lua: 16 assertions, all passing, pure Lua.

Not yet verified in actual play -- needs a human at the keyboard.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 20:38:28 +02:00

81 lines
2.6 KiB
Lua

-- Standalone test of accessibility/history.lua coalescing + review cursor.
package.path = "./?.lua;" .. package.path
-- Stub the speech module before history requires it.
local spoken = {}
package.loaded["accessibility.speech"] = {
normalise = function(t)
if t == nil then return nil end
t = tostring(t):gsub("[\r\n]+", ". "):gsub("%s+", " "):gsub("^%s+",""):gsub("%s+$","")
if t == "" then return nil end
return t
end,
interrupt = function(t) spoken[#spoken+1] = t end,
say = function(t) spoken[#spoken+1] = t end,
}
love = { system = { setClipboardText = function() end } }
local history = require("accessibility.history")
local failures = 0
local function check(label, got, want)
if got ~= want then
failures = failures + 1
print(string.format("FAIL %-42s got=%q want=%q", label, tostring(got), tostring(want)))
else
print(string.format("ok %-42s %s", label, tostring(got)))
end
end
-- 1. plain append
check("first append", history.append("You hit the rat."), "You hit the rat.")
-- 2. coalescing matches the game's (xN) rendering
history.append("You feel cold.")
check("repeat -> x2", history.append("You feel cold."), "You feel cold. (x2)")
check("repeat -> x3", history.append("You feel cold."), "You feel cold. (x3)")
check("entry count after folds", history.count(), 2)
-- 3. a different message breaks the fold
check("new message", history.append("The rat dies."), "The rat dies.")
check("entry count", history.count(), 3)
-- 4. normalisation: newlines collapse, empties rejected
check("nil rejected", history.append(nil), nil)
check("blank rejected", history.append(" "), nil)
check("newlines collapsed", history.append("a\nb"), "a. b")
-- 5. review cursor
spoken = {}
history.reviewLast()
check("reviewLast speaks newest", spoken[#spoken], "a. b. Last message")
spoken = {}
history.reviewPrevious()
check("reviewPrevious steps back", spoken[#spoken], "The rat dies.")
spoken = {}
history.reviewFirst()
check("reviewFirst", spoken[#spoken], "You hit the rat. First message")
spoken = {}
history.reviewPrevious()
check("clamps at first", spoken[#spoken], "You hit the rat. First message")
-- 6. cursor holds still while new lines arrive (the key requirement)
history.reviewFirst()
history.append("Something new happened.")
spoken = {}
history.reviewNext()
check("cursor not yanked to tail", spoken[#spoken], "You feel cold. (x3)")
-- 7. empty history
history.clear()
spoken = {}
history.reviewNext()
check("empty history", spoken[#spoken], "No messages")
check("count after clear", history.count(), 0)
print(failures == 0 and "\nALL PASS" or ("\n" .. failures .. " FAILURE(S)"))
os.exit(failures == 0 and 0 or 1)