All files / src min-server-version.ts

100% Statements 10/10
100% Branches 6/6
100% Functions 2/2
100% Lines 9/9

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 52 53 54 55 56                                647x 211x         105x       51x     51x           51x             51x           51x     51x        
import { compare, valid } from "@renovatebot/pep440";
 
/**
 * The plugin's minimum lilbee server version. The release workflow reads the
 * same floor from min-server-version.json; a test asserts the two agree.
 */
 
/**
 * True when `current` orders strictly before `latest` under PEP 440 ordering
 * (`.devN` < `aN` < `bN` < `rcN` < a final release < `.postN`), which is the
 * scheme lilbee's own version strings follow. Release segments compare
 * numerically, zero-padded to the longer length, so `0.6.90` equals `0.6.90.0`.
 * A version PEP 440 cannot parse fails open: never "older", so an unknown or
 * unparseable version never blocks a feature.
 */
export function isVersionOlder(current: string, latest: string): boolean {
    if (!valid(current) || !valid(latest)) return false;
    return compare(current, latest) < 0;
}
 
/** Whichever of the two versions orders later; ties keep `a`. */
export function higherVersion(a: string, b: string): string {
    return isVersionOlder(a, b) ? b : a;
}
 
/** Oldest server with the /api/sessions routes; the 0.6.66 stable line predates them. */
export const SESSIONS_MIN_SERVER_VERSION = "0.6.90b420";
 
/** Oldest server with the /api/placement routes; also new in the 0.6.90 line. */
export const PLACEMENT_MIN_SERVER_VERSION = "0.6.90b420";
 
/**
 * Oldest server with the /api/sessions/{id}/fork route: release 0.6.90b446, which ships
 * lilbee #890. The plugin checks it against the running server, which can be older than MIN_SERVER_VERSION.
 */
export const SESSION_FORK_MIN_SERVER_VERSION = "0.6.90b446";
 
/**
 * Oldest server whose /api/sessions/{id}/markdown route names the file in a Content-Disposition
 * header: release 0.6.90b447, which ships lilbee #902. The plugin checks it against the running
 * server, which can be older than MIN_SERVER_VERSION.
 */
export const SESSION_EXPORT_MIN_SERVER_VERSION = "0.6.90b447";
 
/**
 * Oldest server that sends each source's `label` and `citation_number` and a saved turn's
 * `source_refs`. Below it a restored answer's content still holds the markdown Sources list.
 */
export const SOURCE_REFS_MIN_SERVER_VERSION = "0.6.90b692";
 
/** The plugin's real floor: the latest of the sessions, placement and source-refs minimums. */
export const MIN_SERVER_VERSION = [PLACEMENT_MIN_SERVER_VERSION, SOURCE_REFS_MIN_SERVER_VERSION].reduce(
    higherVersion,
    SESSIONS_MIN_SERVER_VERSION,
);