Skip to content

fix(sync): clean up stale context.expanded.md when markers removed#21

Merged
jung-thomas merged 1 commit into
mainfrom
fix/stale-expanded-md
May 26, 2026
Merged

fix(sync): clean up stale context.expanded.md when markers removed#21
jung-thomas merged 1 commit into
mainfrom
fix/stale-expanded-md

Conversation

@jung-thomas
Copy link
Copy Markdown
Contributor

Summary

  • When a pack's context.md loses all its <!-- sync:fetch ... --> markers, the previously-written context.expanded.md was never deleted. Because the loader prefers context.expanded.md over context.md, sync + inject kept serving stale fetched content indefinitely.
  • runMarkerExpansion now deletes the orphaned context.expanded.md for any pack that no longer has markers, so the loader falls back to the fresh context.md.
  • Added a small removeStaleExpansion helper plus three unit tests covering: file is deleted, no-file-is-not-an-error, sibling context.md is left untouched.
  • Documented the cleanup contract in CLAUDE.md and docs/content-authoring.md so pack authors can rely on it.

Repro (before the fix)

  1. Add a <!-- sync:fetch ... --> marker to a pack's context.md and run sap-devs sync.
  2. Remove the marker from context.md and run sap-devs sync again.
  3. sap-devs inject still includes the fetched content because context.expanded.md is preferred and was never cleaned up.

Test plan

  • go build ./...
  • go vet ./...
  • go test -c ./cmd/ (compiles; execution blocked locally by Windows Defender per the documented gotcha — CI runs them)
  • CI green on ubuntu-latest
  • Manually verified: deleted local stale context.expanded.md; next inject uses fresh context.md

When a pack's context.md loses all its <!-- sync:fetch --> markers,
runMarkerExpansion previously returned early without touching the
existing context.expanded.md. Because the loader prefers
context.expanded.md over context.md, sync+inject would keep serving
the stale fetched content indefinitely.

The fix deletes the previously-written context.expanded.md for any
pack that no longer has markers, so the loader falls back to the
fresh context.md.
@jung-thomas jung-thomas merged commit 12542d3 into main May 26, 2026
3 checks passed
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