Skip to content

Remove dead template stubs#271

Merged
wanghailei merged 1 commit intomainfrom
remove-dead-template-stubs
Mar 12, 2026
Merged

Remove dead template stubs#271
wanghailei merged 1 commit intomainfrom
remove-dead-template-stubs

Conversation

@wanghailei
Copy link
Owner

No description provided.

Drop 5 built-in .github/ template files (carson.md, AGENTS.md, CLAUDE.md,
copilot-instructions.md, pull_request_template.md) that are now superseded
by lint.canonical distribution. Default template.managed_files to empty.

Add removed files to SUPERSEDED so template_apply! cleans them from governed
repos. Fix stale-only propagation bug in refresh! where SUPERSEDED removals
were not counted in drift totals, causing template_propagate! to skip when
only stale files needed remote cleanup.

Use fetch_optional_string_array for managed_files to allow empty defaults.
@wanghailei wanghailei merged commit 7b8f185 into main Mar 12, 2026
0 of 2 checks passed
@wanghailei wanghailei deleted the remove-dead-template-stubs branch March 12, 2026 11:24
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request streamlines Carson's template management by removing all hardcoded, built-in .github/*.md template files. Instead of maintaining a separate set of "governance files," Carson now exclusively uses the lint.canonical configuration to synchronize all GitHub and lint-policy files. This change simplifies the system, reduces internal complexity, and provides users with a single, consistent mechanism for managing their repository templates, ensuring greater flexibility and control over their project's governance.

Highlights

  • Removed Built-in Templates: Eliminated several hardcoded .github/*.md template files (e.g., carson.md, pull_request_template.md, AI agent discovery files) from the templates directory and the gem specification.
  • Centralized Template Management: Shifted Carson's template management strategy to exclusively rely on the lint.canonical configuration for all GitHub and lint-policy files, removing the concept of Carson-managed "governance files."
  • Updated Documentation: Modified API.md and MANUAL.md to reflect the removal of built-in templates and clarify the new, unified approach to canonical file synchronization.
  • Refined Configuration: Updated lib/carson/config.rb to remove the default list of managed template files and adjusted how template files are fetched, making the managed_files list empty by default.
  • Improved Template Drift Detection: Enhanced the onboard process in lib/carson/runtime/local/onboard.rb to correctly account for both drifted and newly "stale" (removed) template files during synchronization.
Changelog
  • API.md
    • Removed references to specific Carson-managed .github files.
    • Clarified the description of lint.canonical to reflect its role in syncing all canonical GitHub and lint-policy files.
  • MANUAL.md
    • Updated the description of template synchronization to refer to "canonical .github/* template synchronisation" instead of "managed templates."
    • Revised the "Commit generated files" section to be more general.
    • Rewrote the "Canonical Templates" section to state that Carson has no built-in templates and relies solely on lint.canonical.
    • Adjusted the description of how Carson discovers and syncs files to remove mention of its "own governance files."
    • Updated the "Template propagation" strategy to refer only to "canonical policy files."
    • Removed the "Agent Discovery" section, which described the now-removed AI agent discovery files.
  • carson.gemspec
    • Removed .github/copilot-instructions.md and .github/pull_request_template.md from the list of files included in the gem.
  • lib/carson/config.rb
    • Emptied the default template.managed_files array.
    • Changed the method for fetching template_managed_files from fetch_string_array to fetch_optional_string_array.
  • lib/carson/runtime/local/onboard.rb
    • Modified refresh! and onboard_apply! methods to include stale_count in the drift_count for template propagation.
    • Updated output messages to reflect the removal of stale templates.
    • Revised the post-onboard message to remove references to specific built-in templates.
  • lib/carson/runtime/local/template.rb
    • Added .github/carson.md, .github/copilot-instructions.md, .github/CLAUDE.md, .github/AGENTS.md, and .github/pull_request_template.md to the SUPERSEDED list.
  • templates/.github/AGENTS.md
    • Removed the file.
  • templates/.github/CLAUDE.md
    • Removed the file.
  • templates/.github/carson.md
    • Removed the file.
  • templates/.github/copilot-instructions.md
    • Removed the file.
  • templates/.github/pull_request_template.md
    • Removed the file.
  • test/config_canonical_test.rb
    • Renamed test_canonical_does_not_duplicate_existing_managed_files to test_canonical_does_not_duplicate_managed_files.
    • Updated comments and assertions to reflect that template_managed_files is now empty by default.
    • Added the newly superseded .github/*.md files to the SUPERSEDED assertion list.
  • test/gemspec_test.rb
    • Removed .github/copilot-instructions.md and .github/pull_request_template.md from the approved list in test_gemspec_only_includes_approved_dot_github_files.
  • test/runtime_canonical_template_test.rb
    • Renamed test_canonical_file_overrides_carson_built_in to test_canonical_github_root_file_is_deployed.
    • Updated comments to reflect the deployment of canonical GitHub root files.
  • test/runtime_template_propagate_test.rb
    • Modified test_branch_workflow_creates_pr, test_trunk_workflow_pushes_to_main, test_worktree_cleanup_on_error, and test_no_op_when_content_matches_remote to set up a lint.canonical configuration.
    • Updated pre_populate_templates! to accept config_path and use template_source_for.
    • Added template_source_for helper method to find source files for managed templates.
    • Updated assertions to check for canonical files (e.g., rubocop.yml) instead of previously built-in carson.md.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively removes the built-in template files, shifting the responsibility to user-provided canonical files via lint.canonical. The changes are consistent across documentation, application logic, and tests. The old template files are now correctly marked as superseded to ensure they are cleaned up from existing installations. I have one suggestion to improve maintainability in the test suite by ensuring test logic directly reflects application behavior, thereby preventing unintended divergence.

Comment on lines +287 to 302
def pre_populate_templates!( repo_root:, tool_root:, config_path: nil )
env = config_path ? { "CARSON_CONFIG_FILE" => config_path } : {}
cfg = with_env( env ) { Carson::Config.load( repo_root: repo_root ) }
cfg.template_managed_files.each do |managed_file|
relative_within_github = managed_file.delete_prefix( ".github/" )
template_path = File.join( templates_dir, relative_within_github )
template_path = File.join( templates_dir, File.basename( managed_file ) ) unless File.file?( template_path )
next unless File.file?( template_path )
source = template_source_for( managed_file: managed_file, tool_root: tool_root, config: cfg )
next unless source

target_path = File.join( repo_root, managed_file )
FileUtils.mkdir_p( File.dirname( target_path ) )
content = File.read( template_path ).gsub( "\r\n", "\n" ).rstrip + "\n"
content = File.read( source ).gsub( "\r\n", "\n" ).rstrip + "\n"
File.write( target_path, content )
end
system( "git", "-C", repo_root, "add", "--all", out: File::NULL, err: File::NULL )
system( "git", "-C", repo_root, "commit", "-m", "add templates", out: File::NULL, err: File::NULL )
system( "git", "-C", repo_root, "push", "origin", "main", out: File::NULL, err: File::NULL )
end
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and reduce code duplication, this test helper should be refactored. The template_source_for method (lines 304-320) duplicates the logic for resolving template source paths, which is already implemented in Carson::Runtime::Local#template_source_path. Relying on a separate implementation in the tests can lead to them becoming out of sync with the application code if the source path logic changes in the future.

I suggest modifying pre_populate_templates! to use the private template_source_path method from a Carson::Runtime instance via send. This will ensure your test setup always uses the same logic as the application. After applying this suggestion, the template_source_for helper method can be removed.

	def pre_populate_templates!( repo_root:, tool_root:, config_path: nil )
		env = config_path ? { "CARSON_CONFIG_FILE" => config_path } : {}
		runtime = with_env( env ) do
			# We need a runtime instance to access the real template_source_path logic.
			Carson::Runtime.new( repo_root: repo_root, tool_root: tool_root, output: StringIO.new, error: StringIO.new )
		end

		runtime.config.template_managed_files.each do |managed_file|
			source = runtime.send( :template_source_path, managed_file: managed_file )
			next unless source && File.file?( source )

			target_path = File.join( repo_root, managed_file )
			FileUtils.mkdir_p( File.dirname( target_path ) )
			content = File.read( source ).gsub( "\r\n", "\n" ).rstrip + "\n"
			File.write( target_path, content )
		end
		system( "git", "-C", repo_root, "add", "--all", out: File::NULL, err: File::NULL )
		system( "git", "-C", repo_root, "commit", "-m", "add templates", out: File::NULL, err: File::NULL )
		system( "git", "-C", repo_root, "push", "origin", "main", out: File::NULL, err: File::NULL )
	end
References
  1. While the rule advises against premature abstraction if duplicated code is expected to diverge, in this specific scenario, the test's template source path resolution logic must accurately reflect the application's logic. Relying on the application's existing method directly ensures consistency and prevents unintended divergence, which would lead to incorrect test behavior. This approach aligns with avoiding incorrect abstractions by ensuring the test accurately models the system under test.

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