Skip to content

Fixdecision insertion inside html comment#17

Closed
doguhanniltextra wants to merge 2 commits intoActiveMemory:mainfrom
doguhanniltextra:fix/decision-insertion-inside-html-comment
Closed

Fixdecision insertion inside html comment#17
doguhanniltextra wants to merge 2 commits intoActiveMemory:mainfrom
doguhanniltextra:fix/decision-insertion-inside-html-comment

Conversation

@doguhanniltextra
Copy link
Contributor

Problem

On a fresh DECISIONS.md scaffolded by ctx init, running ctx add decision inserts the new entry inside the <!-- DECISION FORMATS ... --> comment block, making it invisible when rendered in any Markdown viewer.

Issue

#10

The INDEX table at the top updates correctly, but the decision body is hidden — users don't notice until they view the rendered page.

Root cause

Two bugs in internal/cli/add/insert.go:

  1. insertDecision used strings.Index(content, "## [") which matched the ## [YYYY-MM-DD] Decision Title template example that lives inside the <!-- DECISION FORMATS ... --> comment block.

  2. insertAfterHeader (the fallback path when no real entries exist yet) only skipped <!-- ctx:context --> and <!-- ctx:end --> markers. It stopped at <!-- INDEX:START --> and inserted before the index table and format-guide comment.

Fix

  • isInsideHTMLComment(content, idx) — new helper that checks whether a byte position falls between a <!-- and its closing -->.
  • insertDecision / insertLearning — rewritten to walk all ## [ occurrences in a loop, skipping any that isInsideHTMLComment identifies as being inside a comment block.
  • insertAfterHeader — updated to skip any <!-- ... --> block (not just ctx-specific markers), so the fallback path clears the INDEX markers and the DECISION FORMATS guide before placing the insertion point.

Tests

  • TestInsertDecisionNotInsideComment — regression test using the exact fresh-file structure from the bug report, with two sub-tests:
    • first decision lands after the comment block
    • second decision prepends correctly before the first (order preserved)
  • TestIsInsideHTMLComment — 8 table-driven unit tests for the new helper, covering: before/inside/after a comment, inline single-line comment, multi-line comment with heading inside vs after close, unclosed comment, and no-comment content.

All existing tests in internal/cli/add continue to pass.

Checklist

  • go fmt ./internal/cli/add/... — clean
  • go vet ./internal/cli/add/... — clean
  • go test ./internal/cli/add/... -count=1 — all pass
  • Regression test added (TestInsertDecisionNotInsideComment)
  • Unit test added for new helper (TestIsInsideHTMLComment)
  • DCO sign-off on all commits

On a fresh DECISIONS.md the template contains a multi-line
<!-- DECISION FORMATS ... --> comment that includes an example
heading '## [YYYY-MM-DD] Decision Title'. Two bugs caused new
decisions to land inside that comment block, making them invisible
when rendered:

1. insertDecision used strings.Index to find the first '## ['
   occurrence, which matched the template example inside the comment.

2. insertAfterHeader (the fallback path) only skipped ctx-specific
   markers (<!-- ctx:context -->, <!-- ctx:end -->), so it stopped
   at <!-- INDEX:START --> and inserted before the index table and
   format-guide comment.

Fix:
- Add isInsideHTMLComment(content, idx) helper that checks whether
  a byte position falls between a <!-- and its closing -->.
- Rewrite insertDecision and insertLearning to walk all '## ['
  occurrences in a loop, skipping any that isInsideHTMLComment
  identifies as being inside a comment block.
- Update insertAfterHeader to skip any <!-- ... --> block (not just
  ctx-specific markers), so the fallback path clears the INDEX
  markers and the DECISION FORMATS guide before placing the entry.

Add TestInsertDecisionNotInsideComment regression test that
reproduces the exact fresh-file structure from the bug report and
asserts the new entry appears after the closing --> of the
DECISION FORMATS block.

Signed-off-by: doguhanniltextra <doguhangithub@gmail.com>
- Split TestInsertDecisionNotInsideComment into sub-tests:
  * first decision lands after comment block
  * second decision prepends before first (verifies prepend order
    still works correctly after the fix)

- Add TestIsInsideHTMLComment with 8 table-driven cases covering:
  * position before, inside, and after a comment
  * inline single-line comment (<!-- INDEX:START -->)
  * multi-line comment with heading inside vs after close
  * unclosed comment (treated as inside)
  * content with no comment at all

Signed-off-by: doguhanniltextra <doguhangithub@gmail.com>
@doguhanniltextra doguhanniltextra self-assigned this Feb 18, 2026
@doguhanniltextra doguhanniltextra deleted the fix/decision-insertion-inside-html-comment branch February 18, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments