test(forge): update specs for inline forge refs

Problem: existing tests asserted that `parse.body()` stripped forge
tokens from the description and populated `meta.forge_ref`. The
`conceal_patterns` test referenced a removed function.

Solution: update `parse.body` integration tests to assert tokens stay
in the description. Add `find_refs()` tests covering single/multiple
refs, URLs, byte offsets, and empty cases. Remove `conceal_patterns`
test. Update diff tests to assert description includes the token.
This commit is contained in:
Barrett Ruth 2026-03-10 18:58:49 -04:00
parent dee79320c8
commit ff280a9c2a

View file

@ -143,6 +143,49 @@ describe('forge', function()
end)
end)
describe('find_refs', function()
it('finds a single shorthand ref', function()
local refs = forge.find_refs('Fix bug gh:user/repo#42')
assert.equals(1, #refs)
assert.equals('github', refs[1].ref.forge)
assert.equals(42, refs[1].ref.number)
assert.equals('gh:user/repo#42', refs[1].raw)
assert.equals(8, refs[1].start_byte)
assert.equals(23, refs[1].end_byte)
end)
it('finds multiple refs', function()
local refs = forge.find_refs('Fix gh:a/b#1 gh:c/d#2')
assert.equals(2, #refs)
assert.equals('a', refs[1].ref.owner)
assert.equals('c', refs[2].ref.owner)
end)
it('finds full URL refs', function()
local refs = forge.find_refs('Fix https://github.com/user/repo/issues/10')
assert.equals(1, #refs)
assert.equals('github', refs[1].ref.forge)
assert.equals(10, refs[1].ref.number)
end)
it('returns empty for no refs', function()
local refs = forge.find_refs('Fix the bug')
assert.equals(0, #refs)
end)
it('skips invalid forge-like tokens', function()
local refs = forge.find_refs('Fix the gh: prefix handling')
assert.equals(0, #refs)
end)
it('records correct byte offsets', function()
local refs = forge.find_refs('gh:a/b#1')
assert.equals(1, #refs)
assert.equals(0, refs[1].start_byte)
assert.equals(8, refs[1].end_byte)
end)
end)
describe('_api_url', function()
it('builds GitHub API URL', function()
local url = forge._api_url({
@ -231,52 +274,38 @@ describe('forge', function()
assert.equals('PendingForgeClosed', hl)
end)
end)
describe('conceal_patterns', function()
it('returns base patterns', function()
local patterns = forge.conceal_patterns()
assert.is_true(#patterns >= 6)
end)
end)
end)
describe('forge parse.body integration', function()
local parse = require('pending.parse')
it('extracts gh: shorthand from task text', function()
it('keeps gh: shorthand in description', function()
local desc, meta = parse.body('Fix login bug gh:user/repo#42')
assert.equals('Fix login bug', desc)
assert.is_not_nil(meta.forge_ref)
assert.equals('github', meta.forge_ref.forge)
assert.equals(42, meta.forge_ref.number)
assert.equals('Fix login bug gh:user/repo#42', desc)
assert.is_nil(meta.forge_ref)
end)
it('extracts gl: shorthand', function()
it('keeps gl: shorthand in description', function()
local desc, meta = parse.body('Update docs gl:group/project#15')
assert.equals('Update docs', desc)
assert.is_not_nil(meta.forge_ref)
assert.equals('gitlab', meta.forge_ref.forge)
assert.equals('Update docs gl:group/project#15', desc)
assert.is_nil(meta.forge_ref)
end)
it('extracts GitHub URL', function()
it('keeps GitHub URL in description', function()
local desc, meta = parse.body('Fix bug https://github.com/user/repo/issues/10')
assert.equals('Fix bug', desc)
assert.is_not_nil(meta.forge_ref)
assert.equals('github', meta.forge_ref.forge)
assert.equals(10, meta.forge_ref.number)
assert.equals('Fix bug https://github.com/user/repo/issues/10', desc)
assert.is_nil(meta.forge_ref)
end)
it('combines forge ref with due date', function()
it('extracts due date but keeps forge ref in description', function()
local desc, meta = parse.body('Fix bug gh:user/repo#42 due:tomorrow')
assert.equals('Fix bug', desc)
assert.is_not_nil(meta.forge_ref)
assert.equals('Fix bug gh:user/repo#42', desc)
assert.is_not_nil(meta.due)
end)
it('combines forge ref with category', function()
it('extracts category but keeps forge ref in description', function()
local desc, meta = parse.body('Fix bug gh:user/repo#42 cat:Work')
assert.equals('Fix bug', desc)
assert.is_not_nil(meta.forge_ref)
assert.equals('Fix bug gh:user/repo#42', desc)
assert.equals('Work', meta.cat)
end)
@ -285,14 +314,6 @@ describe('forge parse.body integration', function()
assert.equals('Fix the gh: prefix handling', desc)
assert.is_nil(meta.forge_ref)
end)
it('only takes one forge ref', function()
local desc, meta = parse.body('Fix gh:a/b#1 gh:c/d#2')
assert.equals('Fix gh:a/b#1', desc)
assert.is_not_nil(meta.forge_ref)
assert.equals('c', meta.forge_ref.owner)
assert.equals('d', meta.forge_ref.repo)
end)
end)
describe('forge diff integration', function()
@ -306,6 +327,7 @@ describe('forge diff integration', function()
diff.apply({ '- [ ] Fix bug gh:user/repo#42' }, s)
local tasks = s:active_tasks()
assert.equals(1, #tasks)
assert.equals('Fix bug gh:user/repo#42', tasks[1].description)
assert.is_not_nil(tasks[1]._extra)
assert.is_not_nil(tasks[1]._extra._forge_ref)
assert.equals('github', tasks[1]._extra._forge_ref.forge)
@ -321,6 +343,7 @@ describe('forge diff integration', function()
s:save()
diff.apply({ '/' .. task.id .. '/- [ ] Fix bug gh:user/repo#10' }, s)
local updated = s:get(task.id)
assert.equals('Fix bug gh:user/repo#10', updated.description)
assert.is_not_nil(updated._extra)
assert.is_not_nil(updated._extra._forge_ref)
assert.equals(10, updated._extra._forge_ref.number)