All files / js stub_tracker.js

0% Statements 0/50
0% Branches 0/1
0% Functions 0/1
0% Lines 0/50

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                                                                                     
// stub_tracker.js — Permanent stub-hit tracking for Rule 2 compliance.
//
// Every stub/TODO function should call stub_hit('funcname') when reached.
// At session end, getStubReport() returns a sorted summary of which stubs
// fired and how often, enabling prioritized porting decisions.
//
// Usage in game code:
//   import { stub_hit } from './stub_tracker.js';
//   function poly_obj(obj, id) {
//       stub_hit('poly_obj');
//       return obj; // stub
//   }
//
// Usage in test harness:
//   import { getStubReport, resetStubCounts } from './stub_tracker.js';
//   resetStubCounts();
//   // ... run session ...
//   const report = getStubReport();
//   // report = [{ name: 'poly_obj', count: 12 }, ...]

const counts = new Map();

// Record that a stub was reached. Cheap — just a map increment.
export function stub_hit(name) {
    counts.set(name, (counts.get(name) || 0) + 1);
}

// Get sorted report: highest-hit stubs first.
export function getStubReport() {
    return [...counts.entries()]
        .map(([name, count]) => ({ name, count }))
        .sort((a, b) => b.count - a.count);
}

// Total number of stub hits across all stubs.
export function getStubHitTotal() {
    let total = 0;
    for (const c of counts.values()) total += c;
    return total;
}

// Number of distinct stubs that fired at least once.
export function getStubHitCount() {
    return counts.size;
}

// Reset for a new session run.
export function resetStubCounts() {
    counts.clear();
}