File size: 1,724 Bytes
11330a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import assert from 'node:assert/strict';
import { nextAttempt, notePilotTarget, retryAlreadyCommitted, summariseRun } from './mic_loop_support.mjs';
assert.equal(notePilotTarget([{type:'page',url:'http://127.0.0.1:8001/other'},
  {type:'page',url:'http://localhost:8000/test/score',id:'correct'}]).id, 'correct');
let result = nextAttempt(1, 1, 6, 6);
assert.equal(result.index, 2);
assert.equal(result.gaveUp, true);
result = nextAttempt(result.index, 1, result.attempt, 6);
assert.equal(result.index, 2, 'a lagging follower must not rewind us to the event we gave up');
assert.equal(result.attempt, 1);
assert.equal(nextAttempt(2, 4, 1, 6).index, 4);
assert.equal(retryAlreadyCommitted(0, 0), false);
assert.equal(retryAlreadyCommitted(0, 1), true, 'a late commit cancels the queued retry');
const resultSummary = summariseRun({events:[
  {type:'input.testEvent',index:0,pitches:[39,53],attempt:0,t:100},
  {type:'follow.advance',toIndex:0,t:300,accepted:true},
  {type:'input.testEvent',index:1,pitches:[55],attempt:0,t:1000},
  {type:'input.testEvent',index:1,pitches:[55],attempt:1,t:1500},
  {type:'follow.advance',toIndex:1,t:1750,accepted:true},
  {type:'follow.advance',toIndex:2,t:1900,accepted:true},
  {type:'input.testEvent',index:2,pitches:[56],attempt:0,t:2000},
]});
assert.equal(resultSummary.attemptedEvents, 3);
assert.equal(resultSummary.detectedWithin450ms, 2, 'one committed chord is one hit');
assert.equal(resultSummary.retries, 1);
assert.equal(resultSummary.commitsWithoutPriorAttempt.length, 1, 'future attempts cannot justify an early advance');
assert.deepEqual(resultSummary.undetected, [2]);
console.log('PASS: target selection, bounded retries, chord/event scoring and early-advance audit');