fix(hooks): avoid escaped quotes in plugin bootstrap

Generate the inline hook root resolver with single-quoted JavaScript literals so Windows Git Bash does not choke on nested escaped double quotes before Node starts. Refresh hooks.json and add regression coverage for parsed hook commands and installed hook manifests.
This commit is contained in:
Affaan Mustafa
2026-05-19 05:05:26 -04:00
committed by Affaan Mustafa
parent f93e8f6869
commit 6cb194a3c6
6 changed files with 74 additions and 24 deletions

View File

@@ -2513,6 +2513,29 @@ async function runTests() {
passed++;
else failed++;
if (
test('inline hook bootstraps avoid escaped double quotes for Git Bash', () => {
const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8'));
for (const [eventName, hookArray] of Object.entries(hooks.hooks)) {
for (const entry of hookArray) {
for (const hook of entry.hooks) {
const commandText = Array.isArray(hook.command) ? hook.command.join(' ') : hook.command;
if (typeof commandText === 'string' && commandText.startsWith('node -e ')) {
assert.ok(
!commandText.includes('\\"'),
`${eventName}/${entry.id || entry.matcher || 'hook'} should not ship escaped double quotes in node -e payload`,
);
}
}
}
}
})
)
passed++;
else failed++;
if (
test('all hook commands use node or approved shell wrappers', () => {
const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');

View File

@@ -997,6 +997,13 @@ async function runTests() {
(Array.isArray(command) && typeof command[0] === 'string' && command[0].endsWith('.sh')) ||
commandText.endsWith('.sh');
if (isInline) {
assert.ok(
!commandText.includes('\\"'),
`Hook command in ${hookType} should not include escaped double quotes in node -e payload: ${commandText.substring(0, 80)}`
);
}
assert.ok(
isInline || isFilePath || isNpx || isShellWrapper || isShellScriptPath,
`Hook command in ${hookType} should be node -e, node script, npx, or shell wrapper/script, got: ${commandText.substring(0, 80)}`

View File

@@ -38,8 +38,9 @@ test('skill-health command uses shared inline resolver in all shell snippets', (
});
test('inline resolver covers current and legacy marketplace plugin roots', () => {
assert.ok(INLINE_RESOLVE.includes('"marketplaces","ecc"'));
assert.ok(INLINE_RESOLVE.includes('"marketplaces","everything-claude-code"'));
assert.ok(INLINE_RESOLVE.includes("'marketplaces','ecc'"));
assert.ok(INLINE_RESOLVE.includes("'marketplaces','everything-claude-code'"));
assert.ok(!INLINE_RESOLVE.includes('\\"'), 'Inline resolver should not require escaped double quotes');
});
console.log(`Passed: ${passed}`);

View File

@@ -531,6 +531,10 @@ function runTests() {
installedBashDispatcherEntry.hooks[0].command.includes('pre-bash-dispatcher.js'),
'hooks/hooks.json should point the Bash preflight contract at the consolidated dispatcher'
);
assert.ok(
!installedBashDispatcherEntry.hooks[0].command.includes('\\"'),
'hooks/hooks.json should avoid escaped double quotes that break Windows Git Bash parsing'
);
assert.ok(
!installedBashDispatcherEntry.hooks[0].command.includes('${CLAUDE_PLUGIN_ROOT}'),
'hooks/hooks.json should not retain raw CLAUDE_PLUGIN_ROOT shell placeholders after install'