Skip to content

feat: auto-update last_modified in dev server and add freshness test#3011

Open
bartlomieju wants to merge 1 commit into
mainfrom
auto-update-last-modified
Open

feat: auto-update last_modified in dev server and add freshness test#3011
bartlomieju wants to merge 1 commit into
mainfrom
auto-update-last-modified

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Adds a beforeUpdate event listener in the dev server that automatically updates the last_modified frontmatter field to today's date whenever a markdown page is edited during deno task dev
  • Adds a new test that validates all last_modified dates are valid YYYY-MM-DD, not in the future, and match the last content-change date in git history (using git log -G to skip metadata-only commits)

Test plan

  • Run deno test -A frontmatter_test.ts — all 512 steps should pass
  • Run deno task dev, edit a markdown file, and verify the last_modified field is updated to today's date
  • Verify no infinite loop: the second watcher trigger should be a no-op since the date already matches

🤖 Generated with Claude Code

The dev server now automatically updates the `last_modified` frontmatter
field to today's date when a markdown page is edited, keeping timestamps
in sync without manual effort. Also adds a test that validates all
`last_modified` dates are well-formed and match git history.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@fibibot fibibot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beforeUpdate handler in _config.ts looks fine. The freshness test in frontmatter_test.ts is broken though.

git log -G "^(?!last_modified:)" uses PCRE negative lookahead, but git's -G is POSIX ERE — on git 2.43 it exits 128 with fatal: invalid regex: Invalid preceding regular expression (also fails with --perl-regexp, which doesn't apply to -G). The Deno.Command call doesn't check result.success or stderr, so stdout is empty, gitDates is empty, and the if (gitDate) guard makes assertEquals(dateStr, gitDate, …) a no-op for every file. The 220 steps that pass only assert format / parseability / not-in-the-future — the headline "matches last content change" check never runs, and the PR's own "Test plan" 512-step claim doesn't reproduce.

Two things needed:

  1. assert(result.success, ...) after outputSync() so this fails loud if git rejects the regex (otherwise this will silently rot again).
  2. Replace the lookahead. e.g. run git log --name-only --pretty=... over all commits and filter out last_modified:-only commits in-process; or use --invert-grep --grep on commit messages if you adopt a marker; the current approach can't be expressed in POSIX ERE.

Holding approval.

Copy link
Copy Markdown
Contributor

@lunadogbot lunadogbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One blocker: the new freshness check can pass without checking any git dates.

  1. "^(?!last_modified:)" is passed to git log -G, but -G uses POSIX extended regex and rejects that lookahead with fatal: invalid regex: Invalid preceding regular expression on git 2.43. Because result.success/stderr are ignored, gitDates stays empty and the if (gitDate) guard skips every assertEquals; deno test --allow-read --allow-run frontmatter_test.ts still reports 512 passing steps. Please assert the git command succeeded and replace the lookahead with in-process filtering or another git query that ERE can express.

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.

3 participants