hephaestus/heph.nvim/tests/e2e/promote_spec.lua
Erich Blume 0e9cfc1fd7
Some checks failed
Build / validate (pull_request) Failing after 5m1s
feat(nvim): frontmatter edit surface — diff block into RPCs on save (§8.3)
Node buffers now open with the editable YAML frontmatter block on top
(node.get {frontmatter: true}); on :w, `frontmatter.lua` parses the
block, diffs it against what was rendered, and routes each changed field
to the right RPC:
- title → node.update rename
- attention → task.set_attention
- do_date/late_on/recurrence → task.set_schedule (YYYY-MM-DD → local-ms;
  a removed line clears via null)
- project → task.set_project (resolved by name)
- tags → tag.add / tag.remove
A mistyped state surfaces the daemon's validation error; a buffer with no
block edits no metadata (deleting the block can't wipe tags). Body rides
node.update as before (the store strips any echoed frontmatter).

Body-position features are content-relative, so the prepended block
doesn't disturb them; e2e specs that targeted absolute line 1 now locate
body lines by content via a new `h.find` helper. New frontmatter_spec
covers render + the full diff→RPC round-trip. 21 nvim e2e specs green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 11:44:39 -07:00

47 lines
1.7 KiB
Lua

-- Workflow (f): promote a context-item line to a committed task. The daemon
-- mints the task and rewrites the source line into a [[link]] to it.
local h = require("e2e.helpers")
describe("promote context item", function()
local ctx
before_each(function()
ctx = h.start()
end)
after_each(function()
h.stop(ctx)
end)
it("mints a task, links the source line, and surfaces it in next", function()
local container = h.create_doc("Errands", "- [ ] call plumber")
local buf = h.open(container.id)
local lnum = h.find(buf, "call plumber") -- the context-item line, below frontmatter
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
local task = require("heph.task").promote_under_cursor({ attention = "orange" })
assert.is_truthy(task.node_id)
-- The promoted task appears in the Tactical ranking.
local found = false
for _, t in ipairs(ctx.q:call("next", { limit = 10 })) do
if t.node_id == task.node_id then
found = true
end
end
assert.is_true(found, "promoted task missing from next")
-- The source line became a wiki-link to the task (persisted + in-buffer).
assert.are.equal("- [[call plumber]]", ctx.q:call("node.get", { id = container.id }).body)
local reloaded = vim.api.nvim_get_current_buf()
assert.is_truthy(h.find(reloaded, "%- %[%[call plumber%]%]"), "rewritten link line missing from buffer")
-- ...and the container backlinks the task.
local linked = false
for _, l in ipairs(ctx.q:call("links.backlinks", { id = task.node_id })) do
if l.src_id == container.id and l.link_type == "wiki" then
linked = true
end
end
assert.is_true(linked, "expected a wiki backlink from the container to the task")
end)
end)