principles-disciple 1.61.0 → 1.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,632 +0,0 @@
1
- /**
2
- * P-03 Edit Verification - P1 Improvements Tests
3
- *
4
- * Testing P1 improvements to edit verification:
5
- * - Configuration system (PROFILE.json integration)
6
- * - File size check (>10MB threshold)
7
- * - Permission error handling
8
- * - File not found error handling
9
- * - Encoding error handling
10
- * - Configurable fuzzy match threshold
11
- * - Configurable skip_large_file_action
12
- */
13
-
14
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
15
- import { handleBeforeToolCall } from '../../src/hooks/gate.js';
16
- import * as fs from 'fs';
17
- import * as path from 'path';
18
- import { WorkspaceContext } from '../../src/core/workspace-context.js';
19
-
20
- vi.mock('fs');
21
- vi.mock('../../src/core/workspace-context.js');
22
-
23
- describe('P-03 Edit Verification - P1 Improvements', () => {
24
- const workspaceDir = '/mock/workspace';
25
-
26
- const mockEvent = {
27
- toolName: 'edit',
28
- params: {
29
- file_path: 'src/example.ts',
30
- oldText: 'const x = 1;',
31
- newText: 'const x = 2;',
32
- },
33
- };
34
-
35
- const mockWctx = {
36
- workspaceDir,
37
- resolve: vi.fn().mockImplementation((p) => {
38
- if (p === 'src/example.ts') return path.join(workspaceDir, 'src/example.ts');
39
- if (p === 'large-file.ts') return path.join(workspaceDir, 'large-file.ts');
40
- if (p === 'PROFILE') return path.join(workspaceDir, 'PROFILE.json');
41
- return p;
42
- }),
43
- trust: {
44
- getScore: vi.fn().mockReturnValue(75),
45
- getStage: vi.fn().mockReturnValue(3),
46
- },
47
- config: {
48
- get: vi.fn().mockReturnValue({
49
- limits: { stage_2_max_lines: 50, stage_3_max_lines: 300 }
50
- }),
51
- },
52
- };
53
-
54
- // Console spies
55
- let consoleInfoSpy: any;
56
- let consoleWarnSpy: any;
57
- let consoleErrorSpy: any;
58
-
59
- const mockCtx = {
60
- workspaceDir,
61
- logger: console,
62
- };
63
-
64
- beforeEach(() => {
65
- vi.clearAllMocks();
66
- vi.mocked(WorkspaceContext.fromHookContext).mockReturnValue(mockWctx as any);
67
-
68
- // Setup console spies
69
- consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
70
- consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
71
- consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
72
-
73
- vi.mocked(fs.existsSync).mockImplementation((p: any) => {
74
- if (typeof p === 'string' && p.includes('PROFILE.json')) {
75
- return true;
76
- }
77
- if (typeof p === 'string' && p.endsWith('.ts')) {
78
- return true;
79
- }
80
- return false;
81
- });
82
- // Default: return empty profile (enables edit verification)
83
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
84
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
85
- return JSON.stringify({
86
- progressive_gate: { enabled: false },
87
- });
88
- }
89
- return 'mock content';
90
- });
91
- });
92
-
93
- afterEach(() => {
94
- vi.restoreAllMocks();
95
- consoleInfoSpy?.mockRestore();
96
- consoleWarnSpy?.mockRestore();
97
- consoleErrorSpy?.mockRestore();
98
- });
99
-
100
- describe('Configuration System - PROFILE.json', () => {
101
- it('should use default config when edit_verification not specified', () => {
102
- const fileContent = 'const x = 1;';
103
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
104
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
105
- return JSON.stringify({
106
- progressive_gate: { enabled: false },
107
- });
108
- }
109
- return fileContent;
110
- });
111
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
112
-
113
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
114
-
115
- expect(result).toBeUndefined(); // Should allow edit with default config
116
- });
117
-
118
- it('should disable verification when edit_verification.enabled = false', () => {
119
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
120
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
121
- return JSON.stringify({
122
- progressive_gate: { enabled: false },
123
- edit_verification: { enabled: false },
124
- });
125
- }
126
- return 'any content'; // Content doesn't match, but verification is disabled
127
- });
128
-
129
- const event = {
130
- ...mockEvent,
131
- params: {
132
- ...mockEvent.params,
133
- oldText: 'this does not match', // Mismatched text
134
- },
135
- };
136
-
137
- const result = handleBeforeToolCall(event as any, { ...mockCtx, ...mockWctx } as any);
138
-
139
- expect(result).toBeUndefined(); // Should allow edit even with mismatch (verification disabled)
140
- });
141
-
142
- it('should use custom max_file_size_bytes from config', () => {
143
- const customMaxSize = 5 * 1024 * 1024; // 5MB
144
- const fileSize = 6 * 1024 * 1024; // 6MB (over custom limit)
145
-
146
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
147
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
148
- return JSON.stringify({
149
- progressive_gate: { enabled: false },
150
- edit_verification: {
151
- enabled: true,
152
- max_file_size_bytes: customMaxSize,
153
- skip_large_file_action: 'warn',
154
- },
155
- });
156
- }
157
- return 'const x = 1;';
158
- });
159
-
160
- vi.mocked(fs.statSync).mockReturnValue({ size: fileSize } as fs.Stats);
161
-
162
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
163
-
164
- expect(result).toBeUndefined(); // Should skip but not block
165
- });
166
-
167
- it('should use custom fuzzy_match_threshold from config', () => {
168
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
169
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
170
- return JSON.stringify({
171
- progressive_gate: { enabled: false },
172
- edit_verification: {
173
- enabled: true,
174
- fuzzy_match_enabled: true,
175
- fuzzy_match_threshold: 0.9, // Higher threshold (90%)
176
- },
177
- });
178
- }
179
- // File has "const x = 1;" (extra spaces) - needs >90% match
180
- return 'const x = 1;';
181
- });
182
-
183
- const event = {
184
- ...mockEvent,
185
- params: {
186
- ...mockEvent.params,
187
- oldText: 'const x = 1;',
188
- },
189
- };
190
-
191
- const result = handleBeforeToolCall(event as any, { ...mockCtx, ...mockWctx } as any);
192
-
193
- // With 90% threshold, single line with different spacing should still match (1/1 = 100%)
194
- // Fuzzy match should succeed and return corrected params
195
- expect(result).toBeDefined();
196
- expect(result?.params?.oldText).toBe('const x = 1;');
197
- });
198
-
199
- it('should respect skip_large_file_action = block', () => {
200
- const largeFileSize = 11 * 1024 * 1024; // 11MB
201
-
202
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
203
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
204
- return JSON.stringify({
205
- progressive_gate: { enabled: false },
206
- edit_verification: {
207
- enabled: true,
208
- max_file_size_bytes: 10 * 1024 * 1024,
209
- skip_large_file_action: 'block',
210
- },
211
- });
212
- }
213
- return 'const x = 1;';
214
- });
215
-
216
- vi.mocked(fs.statSync).mockReturnValue({ size: largeFileSize } as fs.Stats);
217
-
218
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
219
-
220
- expect(result?.block).toBe(true);
221
- expect(result?.blockReason).toContain('File is too large');
222
- });
223
-
224
- it('should respect skip_large_file_action = warn', () => {
225
- const largeFileSize = 11 * 1024 * 1024; // 11MB
226
-
227
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
228
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
229
- return JSON.stringify({
230
- progressive_gate: { enabled: false },
231
- edit_verification: {
232
- enabled: true,
233
- max_file_size_bytes: 10 * 1024 * 1024,
234
- skip_large_file_action: 'warn',
235
- },
236
- });
237
- }
238
- return 'const x = 1;';
239
- });
240
-
241
- vi.mocked(fs.statSync).mockReturnValue({ size: largeFileSize } as fs.Stats);
242
-
243
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
244
-
245
- expect(result).toBeUndefined(); // Should allow with warning
246
- expect(consoleWarnSpy).toHaveBeenCalledWith(
247
- expect.stringContaining('SKIPPING verification')
248
- );
249
- });
250
- });
251
-
252
- describe('File Size Check', () => {
253
- it('should pass verification for small files (<10MB)', () => {
254
- const smallFileSize = 1024; // 1KB
255
- const fileContent = 'const x = 1;';
256
-
257
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
258
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
259
- return JSON.stringify({ progressive_gate: { enabled: false } });
260
- }
261
- return fileContent;
262
- });
263
- vi.mocked(fs.statSync).mockReturnValue({ size: smallFileSize } as fs.Stats);
264
-
265
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
266
-
267
- expect(result).toBeUndefined();
268
- expect(consoleInfoSpy).toHaveBeenCalledWith(
269
- expect.stringContaining('File size check passed')
270
- );
271
- });
272
-
273
- it('should pass verification for files exactly at 10MB threshold', () => {
274
- const exactThreshold = 10 * 1024 * 1024; // Exactly 10MB
275
- const fileContent = 'const x = 1;';
276
-
277
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
278
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
279
- return JSON.stringify({ progressive_gate: { enabled: false } });
280
- }
281
- return fileContent;
282
- });
283
- vi.mocked(fs.statSync).mockReturnValue({ size: exactThreshold } as fs.Stats);
284
-
285
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
286
-
287
- expect(result).toBeUndefined();
288
- });
289
-
290
- it('should skip verification (warn) for files >10MB with default config', () => {
291
- const largeFileSize = 11 * 1024 * 1024; // 11MB
292
- const fileContent = 'const x = 1;';
293
-
294
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
295
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
296
- return JSON.stringify({ progressive_gate: { enabled: false } });
297
- }
298
- return fileContent;
299
- });
300
- vi.mocked(fs.statSync).mockReturnValue({ size: largeFileSize } as fs.Stats);
301
-
302
- const event = {
303
- ...mockEvent,
304
- params: {
305
- ...mockEvent.params,
306
- oldText: 'this does not match', // Mismatched text
307
- },
308
- };
309
-
310
- const result = handleBeforeToolCall(event as any, { ...mockCtx, ...mockWctx } as any);
311
-
312
- expect(result).toBeUndefined(); // Should allow (skip verification)
313
- expect(consoleWarnSpy).toHaveBeenCalledWith(
314
- expect.stringContaining('SKIPPING verification')
315
- );
316
- });
317
-
318
- it('should block for files >10MB when skip_large_file_action = block', () => {
319
- const largeFileSize = 11 * 1024 * 1024; // 11MB
320
- const fileContent = 'const x = 1;';
321
-
322
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
323
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
324
- return JSON.stringify({
325
- progressive_gate: { enabled: false },
326
- edit_verification: {
327
- skip_large_file_action: 'block',
328
- },
329
- });
330
- }
331
- return fileContent;
332
- });
333
- vi.mocked(fs.statSync).mockReturnValue({ size: largeFileSize } as fs.Stats);
334
-
335
- const event = {
336
- ...mockEvent,
337
- params: {
338
- ...mockEvent.params,
339
- oldText: 'this does not match',
340
- },
341
- };
342
-
343
- const result = handleBeforeToolCall(event as any, { ...mockCtx, ...mockWctx } as any);
344
-
345
- expect(result?.block).toBe(true);
346
- expect(result?.blockReason).toContain('File is too large');
347
- expect(result?.blockReason).toContain('11.00MB');
348
- });
349
- });
350
-
351
- describe('Permission Error Handling', () => {
352
- it('should block with helpful message when stat() fails with EACCES', () => {
353
- vi.mocked(fs.statSync).mockImplementation(() => {
354
- const error = new Error('Permission denied') as any;
355
- error.code = 'EACCES';
356
- throw error;
357
- });
358
-
359
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
360
-
361
- expect(result?.block).toBe(true);
362
- expect(result?.blockReason).toContain('Permission denied');
363
- expect(result?.blockReason).toContain('Check file permissions');
364
- });
365
-
366
- it('should block with helpful message when stat() fails with EPERM', () => {
367
- vi.mocked(fs.statSync).mockImplementation(() => {
368
- const error = new Error('Operation not permitted') as any;
369
- error.code = 'EPERM';
370
- throw error;
371
- });
372
-
373
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
374
-
375
- expect(result?.block).toBe(true);
376
- expect(result?.blockReason).toContain('Permission denied');
377
- });
378
-
379
- it('should block with helpful message when readFileSync() fails with EACCES', () => {
380
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
381
- vi.mocked(fs.readFileSync).mockImplementation(() => {
382
- const error = new Error('Permission denied') as any;
383
- error.code = 'EACCES';
384
- throw error;
385
- });
386
-
387
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
388
-
389
- expect(result?.block).toBe(true);
390
- expect(result?.blockReason).toContain('Permission denied');
391
- expect(result?.blockReason).toContain('Cannot read file');
392
- });
393
-
394
- it('should block with helpful message when readFileSync() fails with EPERM', () => {
395
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
396
- vi.mocked(fs.readFileSync).mockImplementation(() => {
397
- const error = new Error('Operation not permitted') as any;
398
- error.code = 'EPERM';
399
- throw error;
400
- });
401
-
402
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
403
-
404
- expect(result?.block).toBe(true);
405
- expect(result?.blockReason).toContain('Permission denied');
406
- });
407
- });
408
-
409
- describe('File Not Found Error Handling', () => {
410
- it('should allow edit when file does not exist (stat ENOENT)', () => {
411
- vi.mocked(fs.statSync).mockImplementation(() => {
412
- const error = new Error('No such file') as any;
413
- error.code = 'ENOENT';
414
- throw error;
415
- });
416
-
417
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
418
-
419
- expect(result).toBeUndefined(); // Allow edit (file will be created)
420
- });
421
-
422
- it('should allow edit when file does not exist (read ENOENT)', () => {
423
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
424
- vi.mocked(fs.readFileSync).mockImplementation(() => {
425
- const error = new Error('No such file') as any;
426
- error.code = 'ENOENT';
427
- throw error;
428
- });
429
-
430
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
431
-
432
- expect(result).toBeUndefined(); // Allow edit (file will be created)
433
- });
434
-
435
- it('should log warning when file not found', () => {
436
- vi.mocked(fs.statSync).mockImplementation(() => {
437
- const error = new Error('No such file') as any;
438
- error.code = 'ENOENT';
439
- throw error;
440
- });
441
-
442
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
443
-
444
- expect(result).toBeUndefined();
445
- expect(consoleWarnSpy).toHaveBeenCalledWith(
446
- expect.stringContaining('File not found')
447
- );
448
- });
449
- });
450
-
451
- describe('Encoding Error Handling', () => {
452
- it('should block with helpful message for encoding errors', () => {
453
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
454
- vi.mocked(fs.readFileSync).mockImplementation(() => {
455
- const error = new Error('Invalid UTF-8 sequence') as any;
456
- error.code = 'ERR_ENCODING';
457
- throw error;
458
- });
459
-
460
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
461
-
462
- expect(result?.block).toBe(true);
463
- expect(result?.blockReason).toContain('Encoding error');
464
- expect(result?.blockReason).toContain('UTF-8');
465
- });
466
-
467
- it('should provide actionable solution for encoding errors', () => {
468
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
469
- vi.mocked(fs.readFileSync).mockImplementation(() => {
470
- const error = new Error('UTF-8 decode error') as any;
471
- error.code = 'ERR_UTF8_DECODE';
472
- throw error;
473
- });
474
-
475
- const result = handleBeforeToolCall(mockEvent as any, { ...mockCtx, ...mockWctx } as any);
476
-
477
- expect(result?.block).toBe(true);
478
- expect(result?.blockReason).toContain('Solution:');
479
- expect(result?.blockReason).toContain('UTF-8 encoded');
480
- });
481
- });
482
-
483
- describe('Fuzzy Match Threshold Configuration', () => {
484
- it('should use 0.8 threshold by default', () => {
485
- // File has different whitespace than oldText - need fuzzy match
486
- // oldText has 2 lines, file has "line one" with extra space (2/2 = 100% fuzzy match)
487
- // Since 100% > 80%, fuzzy match should succeed
488
- const fileContent = 'line one\nline two\n'; // Extra space - no exact match
489
- const event = {
490
- ...mockEvent,
491
- params: {
492
- ...mockEvent.params,
493
- oldText: 'line one\nline two\n', // Different whitespace
494
- },
495
- };
496
-
497
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
498
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
499
- return JSON.stringify({ progressive_gate: { enabled: false } });
500
- }
501
- return fileContent;
502
- });
503
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
504
-
505
- const result = handleBeforeToolCall(event as any, { ...mockCtx, ...mockWctx } as any);
506
-
507
- // With 80% threshold and 100% match (2/2 lines), should auto-correct
508
- expect(result?.block).toBeUndefined();
509
- expect(result?.params?.oldText).toBeTruthy();
510
- });
511
-
512
- it('should use custom threshold from config', () => {
513
- // oldText doesn't match exactly, fuzzy match needed
514
- const fileContent = 'line a\nline b\nline c\n';
515
- const event = {
516
- ...mockEvent,
517
- params: {
518
- ...mockEvent.params,
519
- oldText: 'line a\nline b\n', // Won't match exactly
520
- },
521
- };
522
-
523
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
524
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
525
- return JSON.stringify({
526
- progressive_gate: { enabled: false },
527
- edit_verification: {
528
- fuzzy_match_threshold: 0.6, // Lower threshold (60%)
529
- },
530
- });
531
- }
532
- return fileContent;
533
- });
534
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
535
-
536
- const result = handleBeforeToolCall(event as any, { ...mockCtx, ...mockWctx } as any);
537
-
538
- // 2/3 = 66.7% > 60%, should pass with fuzzy match
539
- expect(result?.block).toBeUndefined();
540
- });
541
-
542
- it('should disable fuzzy match when fuzzy_match_enabled = false', () => {
543
- const fileContent = 'const x = 1;'; // Extra spaces
544
- const event = {
545
- ...mockEvent,
546
- params: {
547
- ...mockEvent.params,
548
- oldText: 'const x = 1;',
549
- },
550
- };
551
-
552
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
553
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
554
- return JSON.stringify({
555
- progressive_gate: { enabled: false },
556
- edit_verification: {
557
- fuzzy_match_enabled: false,
558
- },
559
- });
560
- }
561
- return fileContent;
562
- });
563
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
564
-
565
- const result = handleBeforeToolCall(event as any, { ...mockCtx, ...mockWctx } as any);
566
-
567
- // Fuzzy match disabled, should block with detailed error
568
- expect(result?.block).toBe(true);
569
- expect(result?.blockReason).toContain('[P-03 Violation]');
570
- expect(result?.blockReason).toContain('Whitespace characters');
571
- });
572
- });
573
-
574
- describe('Integration Tests', () => {
575
- it('should handle all checks together: size, permissions, fuzzy match', () => {
576
- const fileContent = 'function hello() {\n const x = 1;\n}\n';
577
-
578
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
579
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
580
- return JSON.stringify({
581
- progressive_gate: { enabled: false },
582
- edit_verification: {
583
- max_file_size_bytes: 10 * 1024 * 1024,
584
- fuzzy_match_threshold: 0.8,
585
- fuzzy_match_enabled: true,
586
- },
587
- });
588
- }
589
- return fileContent;
590
- });
591
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
592
-
593
- const event = {
594
- ...mockEvent,
595
- params: {
596
- ...mockEvent.params,
597
- oldText: 'function hello() {\n const x = 1;\n}',
598
- },
599
- };
600
-
601
- const result = handleBeforeToolCall(event as any, { ...mockCtx, ...mockWctx } as any);
602
-
603
- expect(result).toBeUndefined(); // All checks pass
604
- });
605
-
606
- it('should provide complete error stack for failed edit', () => {
607
- const fileContent = 'function hello() {\n const x = 1;\n}\n';
608
- const event = {
609
- ...mockEvent,
610
- params: {
611
- ...mockEvent.params,
612
- oldText: 'completely wrong text',
613
- },
614
- };
615
-
616
- vi.mocked(fs.readFileSync).mockImplementation((filePath: any) => {
617
- if (typeof filePath === 'string' && filePath.includes('PROFILE.json')) {
618
- return JSON.stringify({ progressive_gate: { enabled: false } });
619
- }
620
- return fileContent;
621
- });
622
- vi.mocked(fs.statSync).mockReturnValue({ size: 1024 } as fs.Stats);
623
-
624
- const result = handleBeforeToolCall(event as any, { ...mockCtx, ...mockWctx } as any);
625
-
626
- expect(result?.block).toBe(true);
627
- expect(result?.blockReason).toContain('Expected to find:');
628
- expect(result?.blockReason).toContain('Actual file contains:');
629
- expect(result?.blockReason).toContain('Solution:');
630
- });
631
- });
632
- });