Files
iptvnator/apps/electron-backend-e2e/src/performance/xtream-main-lifecycle.spec.ts
T
4gray a2fafcfc08 test(performance): add end-to-end Xtream benchmark harness (#1300)
* docs(performance): plan Xtream benchmark

* feat(xtream-mock-server): add deterministic 100k fixture

* style(xtream-mock-server): apply repository formatting

* fix(xtream-mock-server): harden performance fixture data

* feat(xtream-mock-server): add performance control plane

* docs(performance): correct Xtream capture plan

* fix(xtream-mock-server): harden performance controls

* fix(xtream-mock-server): harden control lifecycle

* feat(performance): add Xtream preload markers

* feat(performance): trace Xtream main phases

* feat(performance): mark Xtream store publications

* feat(performance): trace Xtream database phases

* feat(performance): trace Xtream delete cancellation

* feat(performance): capture Xtream phase attribution

* feat(performance): mark Sources Xtream refresh

* test(performance): define Xtream benchmark evidence contracts

* test(performance): add Xtream benchmark runner

* test(performance): surface failure evidence writes

* test(performance): align database read clock

* test(performance): preserve capture failure contracts
2026-07-28 08:08:07 +02:00

95 lines
2.9 KiB
TypeScript

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { createXtreamMainLifecycleValidator } from './xtream-main-lifecycle';
describe('Xtream request-scoped main lifecycle validator', () => {
it('reconstructs without module closures and accepts legal producer paths', () => {
const restore = <T>(source: string): T =>
new Function(`"use strict"; return (${source});`)() as T;
const factory = restore<typeof createXtreamMainLifecycleValidator>(
createXtreamMainLifecycleValidator.toString()
);
const validate = factory().validate;
const network = phase('xtream.network.total', 100, 120);
const json = phase('xtream.json.transform', 105, 110);
const response = phase('xtream.response.ready', 121, 122);
assert.equal(
validate({
method: 'xtreamRequest',
outcome: 'success',
phases: [network, json, response],
}),
null
);
assert.equal(
validate({
method: 'xtreamRequest',
outcome: 'error',
phases: [network],
}),
null
);
assert.equal(
validate({
method: 'xtreamRequest',
outcome: 'error',
phases: [network, json],
}),
null
);
assert.equal(
validate({
method: 'xtreamCancelSession',
outcome: 'success',
phases: [phase('xtream.cancel-session', 100, 101)],
}),
null
);
});
it('rejects incomplete and impossible request lifecycles', () => {
const validate = createXtreamMainLifecycleValidator().validate;
const network = phase('xtream.network.total', 100, 120);
const json = phase('xtream.json.transform', 105, 110);
assert.equal(
validate({
method: 'xtreamRequest',
outcome: 'success',
phases: [network, json],
}),
'main-phase-inventory-incomplete'
);
assert.equal(
validate({
method: 'xtreamRequest',
outcome: 'success',
phases: [
network,
json,
phase('xtream.response.ready', 119, 121),
],
}),
'main-phase-topology-invalid'
);
assert.equal(
validate({
method: 'xtreamRequest',
outcome: 'error',
phases: [network, phase('xtream.response.ready', 121, 122)],
}),
'main-phase-topology-invalid'
);
});
});
function phase(phaseName: string, startEpochMs: number, endEpochMs: number) {
return {
endEpochMs,
phase: phaseName,
startEpochMs,
};
}