33export function validateCommitOrder ( positions :string [ ] ) :boolean {
44// loop over positions
55const errors :number [ ] = [ ] ;
6- let previous = { level :0 , step :0 } ;
7- let current = { level :0 , step :0 } ;
6+ let previous = { level :0 , step :0 , type : "" } ;
7+ let current = { level :0 , step :0 , type : "" } ;
88positions . forEach ( ( position :string , index :number ) => {
99if ( position === "INIT" ) {
1010if ( previous . level !== 0 && previous . step !== 0 ) {
1111errors . push ( index ) ;
1212}
13- current = { level :0 , step :0 } ;
13+ current = { level :0 , step :0 , type : "" } ;
1414return ;
1515} else {
1616//@deprecate - remove L|Q
1717const levelMatch = position . match ( / ^ (?< level > [ 0 - 9 ] + ) $ / ) ;
1818//@deprecate - remove S|Q|A
1919const stepMatch = position . match (
20- / ^ (?< level > [ 0 - 9 ] + ) \. (?< step > [ 0 - 9 ] + ) : [ T | S ] $ /
20+ / ^ (?< level > [ 0 - 9 ] + ) \. (?< step > [ 0 - 9 ] + ) : (?< stepType > [ T | S ] ) $ /
2121) ;
2222if ( levelMatch ) {
2323// allows next level or step
@@ -27,7 +27,7 @@ export function validateCommitOrder(positions: string[]): boolean {
2727return ;
2828}
2929const level = Number ( levelString ) ;
30- current = { level, step :0 } ;
30+ current = { level, step :0 , type : "" } ;
3131} else if ( stepMatch ) {
3232// allows next level or step
3333if ( ! stepMatch ?. groups ?. level || ! stepMatch ?. groups . step ) {
@@ -38,13 +38,26 @@ export function validateCommitOrder(positions: string[]): boolean {
3838
3939const level = Number ( levelString ) ;
4040const step = Number ( stepString ) ;
41- current = { level, step} ;
41+ const type = stepMatch ?. groups . stepType ;
42+
43+ const sameStep = previous . level === level && previous . step === step ;
44+
45+ if (
46+ // tests should come before the solution
47+ ( sameStep && type === "T" && previous . type === "S" ) ||
48+ // step should have tests
49+ ( ! sameStep && type === "S" )
50+ ) {
51+ errors . push ( index ) ;
52+ }
53+ current = { level, step, type} ;
4254} else {
4355// error
4456console . warn ( `Invalid commit position:${ position } ` ) ;
4557return ;
4658}
4759if (
60+ // levels or steps are out of order
4861current . level < previous . level ||
4962( current . level === previous . level && current . step < previous . step )
5063) {