fix(core,cli): enable recursive directory access for (#17094)

This commit is contained in:
Gal Zahavi
2026-01-21 09:58:23 -08:00
committed by GitHub
parent acbef4cd31
commit 45d554ae2f
17 changed files with 410 additions and 135 deletions

View File

@@ -9,6 +9,9 @@ import { HookSystem } from './hookSystem.js';
import { Config } from '../config/config.js';
import { HookType } from './types.js';
import { spawn } from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
import type { Readable, Writable } from 'node:stream';
@@ -58,13 +61,16 @@ describe('HookSystem Integration', () => {
beforeEach(() => {
vi.resetAllMocks();
const testDir = path.join(os.tmpdir(), 'test-hooks');
fs.mkdirSync(testDir, { recursive: true });
// Create a real config with simple command hook configurations for testing
config = new Config({
model: 'gemini-1.5-flash',
targetDir: '/tmp/test-hooks',
targetDir: testDir,
sessionId: 'test-session',
debugMode: false,
cwd: '/tmp/test-hooks',
cwd: testDir,
hooks: {
BeforeTool: [
{
@@ -141,13 +147,16 @@ describe('HookSystem Integration', () => {
});
it('should handle initialization errors gracefully', async () => {
const invalidDir = path.join(os.tmpdir(), 'test-hooks-invalid');
fs.mkdirSync(invalidDir, { recursive: true });
// Create a config with invalid hooks to trigger initialization errors
const invalidConfig = new Config({
model: 'gemini-1.5-flash',
targetDir: '/tmp/test-hooks-invalid',
targetDir: invalidDir,
sessionId: 'test-session-invalid',
debugMode: false,
cwd: '/tmp/test-hooks-invalid',
cwd: invalidDir,
hooks: {
BeforeTool: [
{
@@ -254,13 +263,16 @@ describe('HookSystem Integration', () => {
describe('hook disabling via settings', () => {
it('should not execute disabled hooks from settings', async () => {
const disabledDir = path.join(os.tmpdir(), 'test-hooks-disabled');
fs.mkdirSync(disabledDir, { recursive: true });
// Create config with two hooks, one enabled and one disabled via settings
const configWithDisabled = new Config({
model: 'gemini-1.5-flash',
targetDir: '/tmp/test-hooks-disabled',
targetDir: disabledDir,
sessionId: 'test-session-disabled',
debugMode: false,
cwd: '/tmp/test-hooks-disabled',
cwd: disabledDir,
hooks: {
BeforeTool: [
{
@@ -322,13 +334,16 @@ describe('HookSystem Integration', () => {
describe('hook disabling via command', () => {
it('should disable hook when setHookEnabled is called', async () => {
const setEnabledDir = path.join(os.tmpdir(), 'test-hooks-setEnabled');
fs.mkdirSync(setEnabledDir, { recursive: true });
// Create config with a hook
const configForDisabling = new Config({
model: 'gemini-1.5-flash',
targetDir: '/tmp/test-hooks-setEnabled',
targetDir: setEnabledDir,
sessionId: 'test-session-setEnabled',
debugMode: false,
cwd: '/tmp/test-hooks-setEnabled',
cwd: setEnabledDir,
hooks: {
BeforeTool: [
{