@@ -311,7 +311,7 @@ describe("ci command", () => {
311311 assert . equal ( outputs . get ( "changed-files" ) , "1" )
312312 const summary = fs . readFileSync ( stepSummary , "utf8" )
313313 assert . match ( summary , / d o c s - o n l y / )
314- assert . ok ( summary . includes ( "docs/pr. md" ) )
314+ assert . ok ( summary . includes ( "docs/pr. md" ) )
315315 } finally {
316316 fs . rmSync ( tempRepo , { recursive : true , force : true } )
317317 }
@@ -483,7 +483,7 @@ describe("validation policy changes", () => {
483483it ( "escapes filenames in classification summaries" , ( ) => {
484484 const filename = "docs/`<details>|\nforged.md"
485485 const summary = formatSummary ( classifyEntries ( [ { status : "M" , path : filename } ] ) )
486- assert . ok ( summary . includes ( "docs/`< ;details> ;| forged. md" ) )
486+ assert . ok ( summary . includes ( "docs/`< ;details> ;| forged. md" ) )
487487 assert . ok ( ! summary . includes ( filename ) )
488488} )
489489
@@ -513,18 +513,61 @@ it("runs the gate CLI against a docs-only repository and writes its summary", ()
513513 git ( tempRepo , [ "add" , "." ] )
514514 git ( tempRepo , [ "commit" , "-m" , "docs" ] )
515515 const head = git ( tempRepo , [ "rev-parse" , "HEAD" ] ) . trim ( )
516- for ( const [ actual , status ] of [
517- [ "skipped" , 0 ] ,
518- [ "success" , 1 ] ,
519- ] ) {
520- const summary = path . join ( tempRepo , `summary-${ actual } .md` )
516+ const cases = [
517+ { name : "docs skip" , actual : "skipped" , status : 0 } ,
518+ { name : "unexpected run" , actual : "success" , status : 1 } ,
519+ { name : "label" , actual : "success" , category : "full" , reason : "override-label" , label : "true" , status : 0 } ,
520+ {
521+ name : "variable" ,
522+ actual : "success" ,
523+ category : "full" ,
524+ reason : "override-variable" ,
525+ variable : "true" ,
526+ status : 0 ,
527+ } ,
528+ {
529+ name : "label wins" ,
530+ actual : "success" ,
531+ category : "full" ,
532+ reason : "override-label" ,
533+ label : "true" ,
534+ variable : "true" ,
535+ status : 0 ,
536+ } ,
537+ {
538+ name : "draft" ,
539+ actual : "skipped" ,
540+ rule : "pr-non-draft" ,
541+ draft : "true" ,
542+ category : "full" ,
543+ reason : "override-label" ,
544+ label : "true" ,
545+ status : 0 ,
546+ } ,
547+ {
548+ name : "ready" ,
549+ actual : "success" ,
550+ rule : "pr-non-draft" ,
551+ category : "full" ,
552+ reason : "override-label" ,
553+ label : "true" ,
554+ status : 0 ,
555+ } ,
556+ { name : "missing event" , actual : "skipped" , event : "" , error : / E V E N T _ N A M E i s r e q u i r e d / , status : 1 } ,
557+ { name : "missing watches" , actual : "skipped" , watch : "" , error : / W A T C H E D _ J O B S i s e m p t y / , status : 1 } ,
558+ { name : "missing needs" , actual : "skipped" , needs : "{}" , error : / m i s s i n g / , status : 1 } ,
559+ { name : "missing base" , actual : "skipped" , base : "" , error : / - - b a s e a n d - - h e a d a r e r e q u i r e d / , status : 1 } ,
560+ ]
561+ for ( const testCase of cases ) {
562+ const { actual, status } = testCase
563+ const summary = path . join ( tempRepo , `summary-${ testCase . name } .md` )
521564 const result = spawnSync (
522565 process . execPath ,
523566 [
524567 path . join ( tempRepo , "scripts/change-gate.mjs" ) ,
525568 "ci" ,
526569 "--base" ,
527- base ,
570+ testCase . base ?? base ,
528571 "--head" ,
529572 head ,
530573 "--skip-metrics" ,
@@ -533,22 +576,32 @@ it("runs the gate CLI against a docs-only repository and writes its summary", ()
533576 encoding : "utf8" ,
534577 env : {
535578 ...process . env ,
536- EVENT_NAME : "pull_request" ,
537- WATCHED_JOBS : "expensive:always:gated" ,
538- NEEDS_JSON : JSON . stringify ( {
539- classify : {
540- result : "success" ,
541- outputs : { category : "docs-only" , "reason-code" : "allowlisted-documentation" } ,
542- } ,
543- expensive : { result : actual } ,
544- } ) ,
579+ EVENT_NAME : testCase . event ?? "pull_request" ,
580+ WATCHED_JOBS : testCase . watch ?? `expensive:${ testCase . rule ?? "always" } :gated` ,
581+ NEEDS_JSON :
582+ testCase . needs ??
583+ JSON . stringify ( {
584+ classify : {
585+ result : "success" ,
586+ outputs : {
587+ category : testCase . category ?? "docs-only" ,
588+ "reason-code" : testCase . reason ?? "allowlisted-documentation" ,
589+ } ,
590+ } ,
591+ expensive : { result : actual } ,
592+ } ) ,
545593 GITHUB_STEP_SUMMARY : summary ,
546- FORCE_FULL_LABEL : "false" ,
547- FORCE_FULL_VARIABLE : "false" ,
594+ FORCE_FULL_LABEL : testCase . label ?? "false" ,
595+ PR_DRAFT : testCase . draft ?? "false" ,
596+ FORCE_FULL_VARIABLE : testCase . variable ?? "false" ,
548597 } ,
549598 } ,
550599 )
551- assert . equal ( result . status , status , result . stderr )
600+ assert . equal ( result . status , status , `${ testCase . name } : ${ result . stderr } ` )
601+ if ( testCase . error ) {
602+ assert . match ( result . stderr , testCase . error )
603+ continue
604+ }
552605 assert . match ( fs . readFileSync ( summary , "utf8" ) , / V a l i d a t i o n g a t e / )
553606 assert . match ( fs . readFileSync ( summary , "utf8" ) , / R u n n e r - m i n u t e m e t r i c s w e r e u n a v a i l a b l e / )
554607 }
@@ -596,3 +649,73 @@ it("uses the PR merge base and detects documentation renames", () => {
596649 fs . rmSync ( tempRepo , { recursive : true , force : true } )
597650 }
598651} )
652+
653+ for ( const filename of [ "docs/space name.md" , "docs/日本語.md" , "docs/line\nbreak.md" , "docs/UPPER.MD" ] ) {
654+ it ( `classifies the real git path ${ JSON . stringify ( filename ) } ` , ( ) => {
655+ const tempRepo = createTempRepository ( )
656+ try {
657+ const base = git ( tempRepo , [ "rev-parse" , "HEAD" ] ) . trim ( )
658+ fs . writeFileSync ( path . join ( tempRepo , filename ) , "# documentation" )
659+ git ( tempRepo , [ "add" , "." ] )
660+ git ( tempRepo , [ "commit" , "-m" , "add unusual path" ] )
661+ const head = git ( tempRepo , [ "rev-parse" , "HEAD" ] ) . trim ( )
662+ const { entries } = changedEntries ( tempRepo , base , head )
663+ assert . deepEqual ( entries , [ { status : "A" , path : filename } ] )
664+ assert . equal ( classifyEntries ( entries ) . category , filename . endsWith ( ".MD" ) ? "full" : "docs-only" )
665+ } finally {
666+ fs . rmSync ( tempRepo , { recursive : true , force : true } )
667+ }
668+ } )
669+ }
670+
671+ it ( "requires full validation for a real documentation-to-source rename" , ( ) => {
672+ const tempRepo = createTempRepository ( )
673+ try {
674+ const base = git ( tempRepo , [ "rev-parse" , "HEAD" ] ) . trim ( )
675+ fs . mkdirSync ( path . join ( tempRepo , "src" ) )
676+ git ( tempRepo , [ "mv" , "docs/base.md" , "src/source.md" ] )
677+ git ( tempRepo , [ "commit" , "-m" , "move documentation into source" ] )
678+ const head = git ( tempRepo , [ "rev-parse" , "HEAD" ] ) . trim ( )
679+ const { entries } = changedEntries ( tempRepo , base , head )
680+ assert . deepEqual ( entries , [ { status : "R" , oldPath : "docs/base.md" , path : "src/source.md" } ] )
681+ assert . equal ( classifyEntries ( entries ) . category , "full" )
682+ } finally {
683+ fs . rmSync ( tempRepo , { recursive : true , force : true } )
684+ }
685+ } )
686+
687+ it ( "fails closed when a shallow clone lacks the base commit" , ( ) => {
688+ const tempRepo = createTempRepository ( )
689+ const clone = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "classification-shallow-" ) )
690+ try {
691+ const base = git ( tempRepo , [ "rev-parse" , "HEAD" ] ) . trim ( )
692+ fs . writeFileSync ( path . join ( tempRepo , "docs/base.md" ) , "updated" )
693+ git ( tempRepo , [ "add" , "." ] )
694+ git ( tempRepo , [ "commit" , "-m" , "docs" ] )
695+ const head = git ( tempRepo , [ "rev-parse" , "HEAD" ] ) . trim ( )
696+ git ( tempRepo , [ "clone" , "--depth=1" , `file://${ tempRepo } ` , clone ] )
697+ assert . equal ( git ( clone , [ "rev-parse" , "--is-shallow-repository" ] ) . trim ( ) , "true" )
698+ assert . throws ( ( ) => changedEntries ( clone , base , head ) , / C o u l d n o t r e s o l v e b a s e c o m m i t / )
699+ assert . equal ( validationPolicyChanged ( clone , base , head ) , true )
700+ } finally {
701+ fs . rmSync ( tempRepo , { recursive : true , force : true } )
702+ fs . rmSync ( clone , { recursive : true , force : true } )
703+ }
704+ } )
705+
706+ it ( "renders formatting and autolink punctuation as literal filename characters" , ( ) => {
707+ const filename = "docs/[link](https://example.com)*_~#@!\\.md"
708+ const summary = formatSummary ( classifyEntries ( [ { status : "M" , path : filename } ] ) )
709+ const line = summary . split ( "\n" ) . find ( ( line ) => line . startsWith ( "- docs/" ) )
710+ assert . equal (
711+ line ,
712+ "- docs/[link](https://example.com)*_~#@!\.md" ,
713+ )
714+ } )
715+
716+ it ( "caps long filename summaries" , ( ) => {
717+ const filename = `docs/${ "a" . repeat ( 600 ) } .md`
718+ const summary = formatSummary ( classifyEntries ( [ { status : "M" , path : filename } ] ) )
719+ const line = summary . split ( "\n" ) . find ( ( line ) => line . startsWith ( "- docs/" ) )
720+ assert . equal ( line , `- docs/${ "a" . repeat ( 495 ) } …` )
721+ } )
0 commit comments