Skip to content

Refactor parse_hook_folder() to be more robust and testable - #4744

Draft
flatcap with Copilot wants to merge 5 commits into
mainfrom
copilot/refactor-parse-hook-folder
Draft

flatcap with Copilot wants to merge 5 commits into
mainfrom
copilot/refactor-parse-hook-folder

Conversation

Copilot AI commented Dec 30, 2025

Copy link
Copy Markdown
  • Create struct FolderHookData to hold parsed folder-hook data
  • Create folder_hook_data_free() helper function
  • Refactor parse_folder_hook_line() to return parsed data (not a Hook)
  • Refactor parse_hook_folder() to use parse_folder_hook_line()
  • Update unit tests for new API
  • Tests pass
Original prompt

Refactor parse_hook_folder() to be more robust and testable

Introduction

Config Commands are defined by struct Command and registered with commands_register().
When NeoMutt reads a config file, it calls parse_rc_line() for each line.
parse_rc_line() matches the text to Command.name, then calls Command.parse() to do the actual parsing and storage.

The prototype for the folder-hook Command is:

  • folder-hook [ -noregex ] <regex> <command>

Sample valid Commands:

folder-hook "." "set collapse_unread"
folder-hook "=trash" "macro index d <delete-message>"

Problem

parse_hook_folder() parses the folder-hook Command.
It stores the result in the global Hooks, which makes it hard to unit test the function.

Task

Split out the parsing from parse_hook_folder() into a new function that can be tested thoroughly.

Goals

  • Simple parsing function for folder-hook
  • On success: return a struct Hook
  • On error:
    • Return a clear error message
    • Return the location of the error in the string
    • Error return mechanism should be reusable for other Command parsing functions
  • Testing:
    • Valid config returns a struct Hook with the correct contents
    • Invalid config returns an error message and the location of the error
    • The tests provide 100% code coverage of the parsing function

Testing

Build:

  • ./configure --testing --coverage
  • make to build NeoMutt
  • make test to build and run the unit tests
  • make coverage to perform code coverage tests
    (Results are saved in the coverage directory)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Refactor parse_hook_folder for improved testability Refactor parse_hook_folder() to be more robust and testable Dec 30, 2025
Copilot AI requested a review from flatcap December 30, 2025 12:52
Comment thread hooks/parse.c Fixed
@flatcap

flatcap commented Dec 30, 2025

Copy link
Copy Markdown
Member

@copilot change parse_hook_folder() to actually use parse_folder_hook_line()

Copilot AI commented Dec 30, 2025

Copy link
Copy Markdown
Author

@copilot change parse_hook_folder() to actually use parse_folder_hook_line()

Done in 0fc13b1. Now parse_hook_folder() uses parse_folder_hook_line() to do the basic parsing, then handles path expansion, sanitization, duplicate detection, regex compilation, and storage in the global Hooks list.

@flatcap
flatcap force-pushed the copilot/refactor-parse-hook-folder branch from 0fc13b1 to 2033987 Compare January 4, 2026 23:52
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