Skip to content

Fix sample_data CLEAR=true scope, count message, and production guard - #82

Merged
kanejamison merged 1 commit into
mainfrom
claude/issue-59-sample-data-clear
Aug 28, 2026
Merged

Fix sample_data CLEAR=true scope, count message, and production guard#82
kanejamison merged 1 commit into
mainfrom
claude/issue-59-sample-data-clear

Conversation

@kanejamison

Copy link
Copy Markdown
Owner

Closes #59

Summary

Fixes three problems in lib/tasks/bunko/sample_data.rake:

  1. CLEAR=true deleted ALL posts, including hand-authored static pages. The generator itself skips the reserved "pages" post type, so clearing is now scoped the same way: Post.joins(:post_type).where.not(post_types: {name: "pages"}). Static pages survive CLEAR=true.
  2. The "Cleared" message always said 0. It printed Post.count after deletion. The count is now captured before destroying, and the task prints exactly what will be deleted (count + scope: "Deleting N post(s) from all post types except 'pages'") before doing it, then reports the actual number cleared.
  3. The production guard was bypassed in non-interactive shells. $stdin.gets returns nil immediately without a TTY (CI, cron, piped stdin), so CLEAR=true could wipe production content with no confirmation. Now: the interactive prompt is kept when a TTY is present, but if $stdin.tty? is false or gets returns nil (EOF), the task aborts unless CONFIRM_PRODUCTION=true is set explicitly. EOF is never treated as consent.

Tests

Added to test/tasks/bunko_sample_data_task_test.rb:

  • Clear message reports the actual number of posts deleted (not the post-deletion count)
  • Static pages survive CLEAR=true while non-page posts are cleared
  • Production + non-interactive stdin aborts (SystemExit, no posts created) without CONFIRM_PRODUCTION=true
  • Production + non-interactive stdin proceeds with CONFIRM_PRODUCTION=true
  • Production + TTY whose gets returns nil (EOF) aborts

Results

  • bundle exec rake (Ruby 4.0.2): 368 runs, 1343 assertions, 0 failures, 0 errors, 1 skip (pre-existing skip)
  • bundle exec standardrb: no offenses

🤖 Generated with Claude Code

https://claude.ai/code/session_01CAFZmU5SJSERBVyedpsYQW


Generated by Claude Code

- Scope CLEAR=true deletion to non-"pages" post types so hand-authored
  static pages survive, matching the generator which skips "pages"
- Print the count and scope of posts to be deleted before destroying,
  and report the actual deleted count (previously always "Cleared 0")
- Harden the production guard: keep the interactive prompt when a TTY
  is present, but abort when stdin is not a TTY or gets returns nil
  (EOF), unless CONFIRM_PRODUCTION=true is set explicitly. EOF is
  never treated as consent.
- Add tests covering the deleted-count message, static page
  preservation, and production non-interactive/EOF abort behavior

Closes #59

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CAFZmU5SJSERBVyedpsYQW
@kanejamison
kanejamison merged commit e876453 into main Aug 28, 2026
4 checks passed
@kanejamison
kanejamison deleted the claude/issue-59-sample-data-clear branch August 28, 2026 23:05
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.

sample_data CLEAR=true deletes ALL posts, reports a wrong count, and the production prompt is bypassed in non-interactive shells

2 participants