mirror of
https://github.com/affaan-m/ECC.git
synced 2026-08-17 21:15:40 +02:00
* fix(hooks,lib): fix hook detection and parsing edge cases
- auto-tmux-dev: dev\b -> dev(?![\w-]) so one-shot dev-build/dev-docs scripts
are not detached into tmux; align command shapes (yarn run dev, bun dev) with
pre-bash-dev-server-block.js DEV_PATTERN.
- pre-bash-commit-quality: skip obvious non-secret placeholders (env refs,
${...}, <...>, whitelisted tokens) in the api-key rule without suppressing
real high-entropy secrets; make -m message extraction quote- and
escaped-quote-aware so `-m "fix: \"x\""` / apostrophes are not truncated.
- pre-compact: annotate the CURRENT worktree's session (match **Worktree:** /
legacy **Project:**) instead of the newest *-session.tmp across all projects,
layered onto the LLM-summary flow from #2388; a present-but-blank Worktree
header is treated as non-legacy (no foreign project fallback).
- shell-substitution: stop double-appending a trailing backslash in an
unterminated backtick span.
- utils readStdinJson: on overflow, settle and resolve {} immediately (clear
timer + listeners) instead of waiting for end/timeout and parsing a partial
prefix; surface the overflow on stderr.
Regression tests added/extended (new tests/hooks/pre-compact.test.js).
Addresses review feedback on #2405. The earlier block-no-verify change was
dropped: its message-value skip on merge/cherry-pick/am/rebase would let
`git rebase -m --no-verify` bypass the hook (rebase's -m is the boolean
--merge), a false-negative worse than the contrived false-positive it fixed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(ci): align hook fixtures and drain oversized stdin
---------
Co-authored-by: djpjronline-netizen <276112803+djpjronline-netizen@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: haelyra <49814733+haelyra@users.noreply.github.com>
154 lines
5.2 KiB
JavaScript
154 lines
5.2 KiB
JavaScript
/**
|
|
* Tests for scripts/hooks/auto-tmux-dev.js
|
|
*
|
|
* Tests dev server command transformation for tmux wrapping.
|
|
*
|
|
* Run with: node tests/hooks/auto-tmux-dev.test.js
|
|
*/
|
|
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const { spawnSync } = require('child_process');
|
|
|
|
const script = path.join(__dirname, '..', '..', 'scripts', 'hooks', 'auto-tmux-dev.js');
|
|
|
|
function test(name, fn) {
|
|
try {
|
|
fn();
|
|
console.log(` \u2713 ${name}`);
|
|
return true;
|
|
} catch (err) {
|
|
console.log(` \u2717 ${name}`);
|
|
console.log(` Error: ${err.message}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function runScript(input) {
|
|
const result = spawnSync('node', [script], {
|
|
encoding: 'utf8',
|
|
input: typeof input === 'string' ? input : JSON.stringify(input),
|
|
timeout: 10000,
|
|
});
|
|
return {
|
|
code: result.status || 0,
|
|
stdout: result.stdout || '',
|
|
stderr: result.stderr || '',
|
|
};
|
|
}
|
|
|
|
function runTests() {
|
|
console.log('\n=== Testing auto-tmux-dev.js ===\n');
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
// Check if tmux is available for conditional tests
|
|
const tmuxAvailable = spawnSync('which', ['tmux'], { encoding: 'utf8' }).status === 0;
|
|
|
|
console.log('Dev server detection:');
|
|
|
|
if (test('transforms npm run dev command', () => {
|
|
const result = runScript({ tool_input: { command: 'npm run dev' } });
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
if (process.platform !== 'win32' && tmuxAvailable) {
|
|
assert.ok(output.tool_input.command.includes('tmux'), 'Should contain tmux');
|
|
assert.ok(output.tool_input.command.includes('npm run dev'), 'Should contain original command');
|
|
}
|
|
})) passed++; else failed++;
|
|
|
|
if (test('transforms pnpm dev command', () => {
|
|
const result = runScript({ tool_input: { command: 'pnpm dev' } });
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
if (process.platform !== 'win32' && tmuxAvailable) {
|
|
assert.ok(output.tool_input.command.includes('tmux'));
|
|
}
|
|
})) passed++; else failed++;
|
|
|
|
if (test('transforms yarn dev command', () => {
|
|
const result = runScript({ tool_input: { command: 'yarn dev' } });
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
if (process.platform !== 'win32' && tmuxAvailable) {
|
|
assert.ok(output.tool_input.command.includes('tmux'));
|
|
}
|
|
})) passed++; else failed++;
|
|
|
|
if (test('transforms bun run dev command', () => {
|
|
const result = runScript({ tool_input: { command: 'bun run dev' } });
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
if (process.platform !== 'win32' && tmuxAvailable) {
|
|
assert.ok(output.tool_input.command.includes('tmux'));
|
|
}
|
|
})) passed++; else failed++;
|
|
|
|
console.log('\nNon-dev commands (pass-through):');
|
|
|
|
if (test('does not transform npm install', () => {
|
|
const input = { tool_input: { command: 'npm install' } };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
assert.strictEqual(output.tool_input.command, 'npm install');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('does not transform npm test', () => {
|
|
const input = { tool_input: { command: 'npm test' } };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
assert.strictEqual(output.tool_input.command, 'npm test');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('does not transform npm run build', () => {
|
|
const input = { tool_input: { command: 'npm run build' } };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
assert.strictEqual(output.tool_input.command, 'npm run build');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('does not transform npm run develop (partial match)', () => {
|
|
const input = { tool_input: { command: 'npm run develop' } };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
assert.strictEqual(output.tool_input.command, 'npm run develop');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('does not transform npm run dev-build (hyphenated script)', () => {
|
|
const input = { tool_input: { command: 'npm run dev-build' } };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
assert.strictEqual(output.tool_input.command, 'npm run dev-build');
|
|
})) passed++; else failed++;
|
|
|
|
console.log('\nEdge cases:');
|
|
|
|
if (test('handles empty input gracefully', () => {
|
|
const result = runScript('{}');
|
|
assert.strictEqual(result.code, 0);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('handles invalid JSON gracefully', () => {
|
|
const result = runScript('not json');
|
|
assert.strictEqual(result.code, 0);
|
|
assert.strictEqual(result.stdout, 'not json');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('passes through missing command field', () => {
|
|
const input = { tool_input: {} };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
})) passed++; else failed++;
|
|
|
|
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
|
process.exit(failed > 0 ? 1 : 0);
|
|
}
|
|
|
|
runTests();
|