okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
f57c0adcb
main
1'use strict' ; 2const test = require ( 'node:test' ); 3const assert = require ( 'node:assert' ); 4const c = require ( './item-check' ); 5const bot = require ( './reset-bot' ); 6 7const bugForm = ( over = {}) => { 8const f = { 9'Area' :'[Engine] (speed, kernels, models, the server and API)' , 10'Desktop app, Terminal or source?' :'Terminal (the `strata` command)' , 11'What happened' :'Decode stops after two minutes with "CUDA error 700". I expected it to continue.' , 12'Smallest steps or command that reproduce it' :'_No response_' , 13'Reproduction status' :'Reproduced locally' , 14'Strata version' :'Strata 0.2.0-beta · engine 0.1.45.3' , 15'Graphics card, memory and system' :'RTX 5070 12 GB · 64 GB RAM · Windows 11' , 16 ...over , 17}; 18return Object . entries ( f ). map (([ k , v ]) => `### ${ k } \n\n ${ v } ` ). join ( '\n\n' ); 19}; 20 21test ( 'title prefix' , () => { 22assert . ok ( c . hasAreaPrefix ( '[Engine] fix decode' )); 23assert . ok ( c . hasAreaPrefix ( '[Docs] x' )); 24assert . ok ( ! c . hasAreaPrefix ( 'Engine fix' )); 25assert . ok ( ! c . hasAreaPrefix ( '[engine] fix' )); 26assert . ok ( ! c . hasAreaPrefix ( '[Engine]' )); 27assert . ok ( ! c . hasAreaPrefix ( '[Engine] ' )); 28assert . ok ( ! c . hasAreaPrefix ( '[Area] foo' )); 29assert . ok ( ! c . hasAreaPrefix ( '' )); 30assert . ok ( ! c . hasAreaPrefix ( undefined )); 31}); 32 33test ( 'filled bug form passes in both modes' , () => { 34for ( const mode of [ 'intake' , 'reopen' ]) { 35const r = c . checkIssue ({ title :'[Engine] decode stops' , body :bugForm (), labels :[ 'bug' ], mode}); 36assert . deepStrictEqual ( r . missing , []); 37assert . strictEqual ( r . kind , 'bug' ); 38} 39}); 40 41test ( 'bug form: missing parts are named' , () => { 42const r = c . checkIssue ({ title :'decode stops' , body :bugForm ({ 'Strata version' :'_No response_' , 'What happened' :'bad' }) }); 43assert . ok ( ! r . ok ); 44assert . ok ( r . missing . some (( m ) => / title / i . test ( m ))); 45assert . ok ( r . missing . some (( m ) => m . includes ( 'What happened' ))); 46assert . ok ( r . missing . some (( m ) => m . includes ( 'Strata version' ))); 47}); 48 49test ( 'reopen needs a 0.2 version, intake does not' , () => { 50const body = bugForm ({ 'Strata version' :'Strata 0.1.44' }); 51assert . ok ( c . checkIssue ({ title :'[Engine] x y' , body, mode :'intake' }). ok ); 52const r = c . checkIssue ({ title :'[Engine] x y' , body, mode :'reopen' }); 53assert . ok ( ! r . ok ); 54assert . ok ( r . missing . some (( m ) => m . includes ( '0.2.0-beta' ))); 55}); 56 57test ( 'html comments and placeholders do not count' , () => { 58const r = c . checkIssue ({ title :'[Engine] x y' , body :bugForm ({ 'What happened' :'<!-- describe -->' }) }); 59assert . ok ( r . missing . some (( m ) => m . includes ( 'What happened' ))); 60}); 61 62test ( 'feature and question forms' , () => { 63const f = '### Area\n\n[GUI] (the desktop app)\n\n### What do you want to do?\n\nLet me pin a model to the top of the list in the app.' ; 64assert . ok ( c . checkIssue ({ title :'[GUI] pin models' , body :f , mode :'reopen' }). ok ); 65assert . ok ( ! c . checkIssue ({ title :'[GUI] pin models' , body :'### Area\n\n[GUI]\n\n### What do you want to do?\n\n_No response_' }). ok ); 66const q = '### Area\n\n[Other]\n\n### Your question\n\nHow do I move the model folder to another drive?' ; 67assert . ok ( c . checkIssue ({ title :'[Other] model folder' , body :q }). ok ); 68}); 69 70test ( 'free-form issue' , () => { 71const good = 'Strata 0.2.0-beta on an RTX 3060 12 GB with 32 GB RAM on Linux: the server hangs when I send two requests at once. Expected both to finish.' ; 72assert . ok ( c . checkIssue ({ title :'[Engine] hang on two requests' , body :good , mode :'reopen' }). ok ); 73assert . ok ( ! c . checkIssue ({ title :'[Engine] hang' , body :'it crashes' , mode :'intake' }). ok ); 74const old = good . replace ( '0.2.0-beta' , '0.1.40' ); 75assert . ok ( c . checkIssue ({ title :'[Engine] hang' , body :old , mode :'intake' }). ok ); 76assert . ok ( ! c . checkIssue ({ title :'[Engine] hang' , body :old , mode :'reopen' }). ok ); 77assert . ok ( c . checkIssue ({ title :'[Other] idea' , body :'It would help if the app remembered my last model between runs, today I pick it again.' , labels :[ 'enhancement' ], mode :'reopen' }). ok ); 78}); 79 80const prBody = ( over = {}) => { 81const p = { 82problem :'Decode stopped on prompts above 8k because the stop check read the wrong length. Now it continues.' , 83validation :'**Passed:** `ctest -R decode`, commit abcdef1, RTX 3060, 12 of 12.\n\n**Failed:** none observed\n\n**Not run:** HIP build' , 84 ...over , 85}; 86return `## Problem and result\n<!-- hint -->\n ${ p . problem } \n\n## Related discussion\nnone\n\n## Approach\nFix the length.\n\n## Validation\n ${ p . validation } \n\n## Limits\nnone` ; 87}; 88 89test ( 'filled PR passes' , () => { 90assert . deepStrictEqual ( c . checkPull ({ title :'[Engine] fix stop' , body :prBody (), mode :'reopen' }). missing , []); 91}); 92 93test ( 'untouched PR template fails' , () => { 94const tpl = '## Problem and result\n<!-- What triggered -->\n\n## Validation\n<!-- cmds -->\n\n**Passed:**\n<!-- x -->\n\n**Failed:**\n\n**Not run:**\n' ; 95const r = c . checkPull ({ title :'[Engine] fix stop' , body :tpl }); 96assert . ok ( ! r . ok ); 97assert . ok ( r . missing . some (( m ) => m . includes ( 'Problem and result' ))); 98assert . ok ( r . missing . some (( m ) => m . includes ( 'Validation' ))); 99}); 100 101test ( 'PR: empty body and bad title' , () => { 102const r = c . checkPull ({ title :'fix' , body :null }); 103assert . ok ( ! r . ok ); 104assert . ok ( r . missing . length >= 2 ); 105}); 106 107test ( 'PR reopen needs a revision' , () => { 108const body = prBody ({ validation :'**Passed:** I tried it and it worked for me on my machine, looked fine.' }); 109assert . ok ( c . checkPull ({ title :'[Engine] x y' , body, mode :'intake' }). ok ); 110assert . ok ( ! c . checkPull ({ title :'[Engine] x y' , body, mode :'reopen' }). ok ); 111}); 112 113test ( 'free-form PR' , () => { 114const body = 'This fixes a crash when the context is above 8k, because the length was read from the wrong field. Before it aborted, after it continues. I built it on CUDA and ran the decode test, passed.' ; 115assert . ok ( c . checkPull ({ title :'[Engine] fix crash' , body}). ok ); 116assert . ok ( ! c . checkPull ({ title :'[Engine] fix crash' , body :'fixes stuff' }). ok ); 117}); 118 119test ( 'messages' , () => { 120const m = c . intakeComment ( false , [ 'a' , 'b' ]); 121assert . ok ( m . includes ( '- [ ] a' ) && m . includes ( '/reopen' ) && m . includes ( 'CONTRIBUTING.md' )); 122assert . ok ( c . staleComment ( true ). includes ( '/reopen' )); 123}); 124 125// handlers with a fake GitHub client 126function fake ( calls , extra = {}) { 127const rest = { 128issues :{ 129getLabel :async () => ({}), 130createLabel :async ( a ) => calls . push ([ 'createLabel' , a . name ]), 131addLabels :async ( a ) => calls . push ([ 'addLabels' , a . labels ]), 132removeLabel :async ( a ) => calls . push ([ 'removeLabel' , a . name ]), 133createComment :async ( a ) => calls . push ([ 'comment' , a . body ]), 134update :async ( a ) => calls . push ([ 'update' , a . state ]), 135get :async () => ({ data :extra . live }), 136listEvents :async () => {}, 137listForRepo :async () => {}, 138}, 139pulls :{ get :async () => ({ data :{ mergeable_state :'clean' } }) }, 140}; 141return { rest, paginate :async ( fn ) => ( fn === rest . issues . listEvents ?( extra . events || []) :( extra . items || [])) }; 142} 143const core = { info () {} }; 144const repo = { owner :'o' , repo :'r' }; 145 146test ( 'intake labels and comments once' , async () => { 147const calls = []; 148const item = { number :1 , title :'bad' , body :'' , labels :[], user :{ type :'User' }, author_association :'NONE' }; 149await bot . intake ({ github :fake ( calls ), context :{ repo, payload :{ action :'opened' , issue :item } }, core}); 150assert . deepStrictEqual ( calls . map (( c ) => c [ 0 ]), [ 'addLabels' , 'comment' ]); 151calls . length = 0 ; 152item . labels = [{ name :'needs-format' }]; 153await bot . intake ({ github :fake ( calls ), context :{ repo, payload :{ action :'edited' , issue :item } }, core}); 154assert . deepStrictEqual ( calls , []); 155}); 156 157test ( 'intake clears the label when edited into shape' , async () => { 158const calls = []; 159const item = { number :1 , title :'[Engine] x y' , body :bugForm (), labels :[{ name :'needs-format' }], user :{ type :'User' } }; 160await bot . intake ({ github :fake ( calls ), context :{ repo, payload :{ action :'edited' , issue :item } }, core}); 161assert . deepStrictEqual ( calls . map (( c ) => c [ 0 ]), [ 'removeLabel' , 'comment' ]); 162}); 163 164test ( 'reopen: ignores strangers, reopens the author when it passes' , async () => { 165const issue = { number :5 , state :'closed' , user :{ login :'amy' }, labels :[] }; 166let calls = []; 167const comment = { body :'/reopen' , user :{ login :'bob' , type :'User' }, author_association :'NONE' }; 168await bot . reopen ({ github :fake ( calls ), context :{ repo, payload :{ issue, comment} }, core}); 169assert . deepStrictEqual ( calls , []); 170 171const live = { number :5 , title :'[Engine] x y' , body :bugForm (), labels :[] }; 172comment . user . login = 'amy' ; 173await bot . reopen ({ github :fake ( calls , { live}), context :{ repo, payload :{ issue, comment} }, core}); 174assert . deepStrictEqual ( calls . map (( c ) => c [ 0 ]), [ 'update' , 'removeLabel' , 'comment' ]); 175assert . strictEqual ( calls [ 0 ][ 1 ], 'open' ); 176 177calls = []; 178live . title = 'no prefix' ; 179await bot . reopen ({ github :fake ( calls , { live}), context :{ repo, payload :{ issue, comment} }, core}); 180assert . deepStrictEqual ( calls . map (( c ) => c [ 0 ]), [ 'comment' ]); 181assert . ok ( calls [ 0 ][ 1 ]. includes ( 'Not reopened' )); 182}); 183 184test ( 'sweep closes only old flagged items' , async () => { 185const calls = []; 186const old = new Date ( Date . now () - 6 * 86400000 ). toISOString (); 187const fresh = new Date ( Date . now () - 1 * 86400000 ). toISOString (); 188const mk = ( n , created ) => ({ number :n , title :'bad' , body :'' , labels :[{ name :'needs-format' }], created_at :created }); 189const gh = fake ( calls , { items :[ mk ( 1 , old ), mk ( 2 , fresh )] }); 190await bot . sweep ({ github :gh , context :{ repo}, core}); 191assert . deepStrictEqual ( calls . map (( c ) => c [ 0 ]), [ 'comment' , 'update' ]); 192});