Skip to content

Commit b8a4a36

Browse files
delphinusclaude
andauthored
fix(test): stub supports_kitty in autolink media-routing tests (#17)
image_placements are only registered when image.supports_kitty() returns true, which requires a Kitty graphics-capable terminal (WezTerm/kitty/ghostty). CI runners report false, so the standalone autolink tests added in #13 failed there even though the routing logic itself is correct. Stub image.supports_kitty for the duration of these tests with a restore-on-error wrapper. The negative test is also stubbed so it exercises the URL filter rather than passing for the wrong reason (no placement because no kitty support). Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 99689f7 commit b8a4a36

1 file changed

Lines changed: 38 additions & 22 deletions

File tree

tests/link_types_test.lua

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -144,34 +144,50 @@ end)
144144
-- Standalone <URL> on a line that points at GitHub's user-attachments CDN
145145
-- routes through image_placements so the existing download + magic-byte
146146
-- detection can render it as image/video (mirrors github.com behavior).
147+
--
148+
-- image_placements are only added when the terminal supports the Kitty
149+
-- graphics protocol; CI runners do not, so stub `supports_kitty` for the
150+
-- duration of these tests. The stub is restored even if the test errors.
151+
local function with_kitty_stubbed(fn)
152+
local image = require "md-render.image"
153+
local original = image.supports_kitty
154+
image.supports_kitty = function() return true end
155+
local ok, err = pcall(fn)
156+
image.supports_kitty = original
157+
if not ok then error(err) end
158+
end
147159

148160
test("standalone autolink to user-attachments registers image placement", function()
149-
local ContentBuilder = require("md-render.content_builder").ContentBuilder
150-
local b = ContentBuilder.new()
151-
local url = "https://github.com/user-attachments/assets/4c042f5c-fb7f-4a1e-a3d9-e2ab43ae215a"
152-
b:render_document({ "<" .. url .. ">" }, { max_width = 80, indent = " " })
153-
local result = b:result()
154-
local found
155-
for _, p in ipairs(result.image_placements or {}) do
156-
if p.src_url == url then found = p; break end
157-
end
158-
assert_eq(found ~= nil, true, "user-attachments autolink: image placement registered")
159-
assert_eq(found and found.src_url, url, "user-attachments autolink: src_url preserved")
161+
with_kitty_stubbed(function()
162+
local ContentBuilder = require("md-render.content_builder").ContentBuilder
163+
local b = ContentBuilder.new()
164+
local url = "https://github.com/user-attachments/assets/4c042f5c-fb7f-4a1e-a3d9-e2ab43ae215a"
165+
b:render_document({ "<" .. url .. ">" }, { max_width = 80, indent = " " })
166+
local result = b:result()
167+
local found
168+
for _, p in ipairs(result.image_placements or {}) do
169+
if p.src_url == url then found = p; break end
170+
end
171+
assert_eq(found ~= nil, true, "user-attachments autolink: image placement registered")
172+
assert_eq(found and found.src_url, url, "user-attachments autolink: src_url preserved")
173+
end)
160174
end)
161175

162176
test("standalone autolink to non-attachments URL does NOT become a placement", function()
163-
local ContentBuilder = require("md-render.content_builder").ContentBuilder
164-
local b = ContentBuilder.new()
165-
b:render_document({ "<https://example.com/page>" }, { max_width = 80, indent = " " })
166-
local result = b:result()
167-
for _, p in ipairs(result.image_placements or {}) do
168-
if p.src_url == "https://example.com/page" then
169-
fail_count = fail_count + 1
170-
print("FAIL: non-attachments autolink should not become an image placement")
171-
return
177+
with_kitty_stubbed(function()
178+
local ContentBuilder = require("md-render.content_builder").ContentBuilder
179+
local b = ContentBuilder.new()
180+
b:render_document({ "<https://example.com/page>" }, { max_width = 80, indent = " " })
181+
local result = b:result()
182+
for _, p in ipairs(result.image_placements or {}) do
183+
if p.src_url == "https://example.com/page" then
184+
fail_count = fail_count + 1
185+
print("FAIL: non-attachments autolink should not become an image placement")
186+
return
187+
end
172188
end
173-
end
174-
pass_count = pass_count + 1
189+
pass_count = pass_count + 1
190+
end)
175191
end)
176192

177193
-- Highlight tests for wikilinks

0 commit comments

Comments
 (0)