@@ -29,11 +29,11 @@ function runScript(input) {
2929}
3030
3131function runTests ( ) {
32- console . log ( '\n=== Testing doc-file-warning.js ===\n' ) ;
32+ console . log ( '\n=== Testing doc-file-warning.js (denylist policy) ===\n' ) ;
3333 let passed = 0 ;
3434 let failed = 0 ;
3535
36- // 1. Allowed standard doc files - no warning in stderr
36+ // 1. Standard doc filenames - never on denylist, no warning
3737 const standardFiles = [
3838 'README.md' ,
3939 'CLAUDE.md' ,
@@ -53,20 +53,26 @@ function runTests() {
5353 } ) ? passed ++ : failed ++ ) ;
5454 }
5555
56- // 2. Allowed directory paths - no warning
57- const allowedDirPaths = [
56+ // 2. Structured directory paths - no warning even for ad-hoc names
57+ const structuredDirPaths = [
5858 'docs/foo.md' ,
5959 'docs/guide/setup.md' ,
60+ 'docs/TODO.md' ,
61+ 'docs/specs/NOTES.md' ,
6062 'skills/bar.md' ,
6163 'skills/testing/tdd.md' ,
6264 '.history/session.md' ,
6365 'memory/patterns.md' ,
6466 '.claude/commands/deploy.md' ,
6567 '.claude/plans/roadmap.md' ,
6668 '.claude/projects/myproject.md' ,
69+ '.github/ISSUE_TEMPLATE/bug.md' ,
70+ 'commands/triage.md' ,
71+ 'benchmarks/test.md' ,
72+ 'templates/DRAFT.md' ,
6773 ] ;
68- for ( const file of allowedDirPaths ) {
69- ( test ( `allows directory path: ${ file } ` , ( ) => {
74+ for ( const file of structuredDirPaths ) {
75+ ( test ( `allows structured directory path: ${ file } ` , ( ) => {
7076 const { code, stderr } = runScript ( { tool_input : { file_path : file } } ) ;
7177 assert . strictEqual ( code , 0 , `expected exit code 0, got ${ code } ` ) ;
7278 assert . strictEqual ( stderr , '' , `expected no warning for ${ file } , got: ${ stderr } ` ) ;
@@ -96,18 +102,61 @@ function runTests() {
96102 } ) ? passed ++ : failed ++ ) ;
97103 }
98104
99- // 5. Non-standard doc files - warning in stderr
100- const nonStandardFiles = [ 'random-notes.md' , 'TODO.md' , 'notes.txt' , 'scratch.md' , 'ideas.txt' ] ;
101- for ( const file of nonStandardFiles ) {
102- ( test ( `warns on non-standard doc file: ${ file } ` , ( ) => {
105+ // 5. Lowercase and partial-match filenames - NOT on denylist, no warning
106+ const allowedNonDenylist = [
107+ 'random-notes.md' ,
108+ 'notes.txt' ,
109+ 'scratch.md' ,
110+ 'ideas.txt' ,
111+ 'todo-list.md' ,
112+ 'my-draft.md' ,
113+ 'meeting-notes.txt' ,
114+ ] ;
115+ for ( const file of allowedNonDenylist ) {
116+ ( test ( `allows non-denylist doc file: ${ file } ` , ( ) => {
117+ const { code, stderr } = runScript ( { tool_input : { file_path : file } } ) ;
118+ assert . strictEqual ( code , 0 ) ;
119+ assert . strictEqual ( stderr , '' , `expected no warning for ${ file } , got: ${ stderr } ` ) ;
120+ } ) ? passed ++ : failed ++ ) ;
121+ }
122+
123+ // 6. Ad-hoc denylist filenames at root/non-structured paths - SHOULD warn
124+ const deniedFiles = [
125+ 'NOTES.md' ,
126+ 'TODO.md' ,
127+ 'SCRATCH.md' ,
128+ 'TEMP.md' ,
129+ 'DRAFT.txt' ,
130+ 'BRAINSTORM.md' ,
131+ 'SPIKE.md' ,
132+ 'DEBUG.md' ,
133+ 'WIP.txt' ,
134+ 'src/NOTES.md' ,
135+ 'lib/TODO.txt' ,
136+ ] ;
137+ for ( const file of deniedFiles ) {
138+ ( test ( `warns on ad-hoc denylist file: ${ file } ` , ( ) => {
103139 const { code, stderr } = runScript ( { tool_input : { file_path : file } } ) ;
104140 assert . strictEqual ( code , 0 , 'should still exit 0 (warn only)' ) ;
105141 assert . ok ( stderr . includes ( 'WARNING' ) , `expected warning in stderr for ${ file } , got: ${ stderr } ` ) ;
106142 assert . ok ( stderr . includes ( file ) , `expected file path in stderr for ${ file } ` ) ;
107143 } ) ? passed ++ : failed ++ ) ;
108144 }
109145
110- // 6. Invalid/empty input - passes through without error
146+ // 7. Windows backslash paths - normalized correctly
147+ ( test ( 'allows ad-hoc name in structured dir with backslash path' , ( ) => {
148+ const { code, stderr } = runScript ( { tool_input : { file_path : 'docs\\specs\\NOTES.md' } } ) ;
149+ assert . strictEqual ( code , 0 ) ;
150+ assert . strictEqual ( stderr , '' , 'expected no warning for structured dir with backslash' ) ;
151+ } ) ? passed ++ : failed ++ ) ;
152+
153+ ( test ( 'warns on ad-hoc name with backslash in non-structured dir' , ( ) => {
154+ const { code, stderr } = runScript ( { tool_input : { file_path : 'src\\SCRATCH.md' } } ) ;
155+ assert . strictEqual ( code , 0 , 'should still exit 0' ) ;
156+ assert . ok ( stderr . includes ( 'WARNING' ) , 'expected warning for non-structured backslash path' ) ;
157+ } ) ? passed ++ : failed ++ ) ;
158+
159+ // 8. Invalid/empty input - passes through without error
111160 ( test ( 'handles empty object input without error' , ( ) => {
112161 const { code, stderr } = runScript ( { } ) ;
113162 assert . strictEqual ( code , 0 ) ;
@@ -126,15 +175,27 @@ function runTests() {
126175 assert . strictEqual ( stderr , '' , `expected no warning for empty file_path, got: ${ stderr } ` ) ;
127176 } ) ? passed ++ : failed ++ ) ;
128177
129- // 7. Stdout always contains the original input (pass-through)
178+ // 9. Malformed input - passes through without error
179+ ( test ( 'handles non-JSON input without error' , ( ) => {
180+ const result = spawnSync ( 'node' , [ script ] , {
181+ encoding : 'utf8' ,
182+ input : 'not-json' ,
183+ timeout : 10000 ,
184+ } ) ;
185+ assert . strictEqual ( result . status || 0 , 0 ) ;
186+ assert . strictEqual ( result . stderr || '' , '' ) ;
187+ assert . strictEqual ( result . stdout , 'not-json' ) ;
188+ } ) ? passed ++ : failed ++ ) ;
189+
190+ // 10. Stdout always contains the original input (pass-through)
130191 ( test ( 'passes through input to stdout for allowed file' , ( ) => {
131192 const input = { tool_input : { file_path : 'README.md' } } ;
132193 const { stdout } = runScript ( input ) ;
133194 assert . strictEqual ( stdout , JSON . stringify ( input ) ) ;
134195 } ) ? passed ++ : failed ++ ) ;
135196
136197 ( test ( 'passes through input to stdout for warned file' , ( ) => {
137- const input = { tool_input : { file_path : 'random-notes .md' } } ;
198+ const input = { tool_input : { file_path : 'TODO .md' } } ;
138199 const { stdout } = runScript ( input ) ;
139200 assert . strictEqual ( stdout , JSON . stringify ( input ) ) ;
140201 } ) ? passed ++ : failed ++ ) ;
0 commit comments