Files
iptvnator/apps/electron-backend-e2e/src/performance/xtream-worker-request-snapshot.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

93 lines
3.1 KiB
TypeScript

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import {
createXtreamIterationDefinitions,
XTREAM_SCENARIO_ID,
} from './xtream-benchmark-contract';
import { iteration } from './xtream-benchmark-report.fixtures';
import type { XtreamWorkerRequestAccounting } from './xtream-summary-contract';
import { validXtreamWorkerRequestAccounting } from './xtream-worker-request-evidence';
describe('Xtream worker request canonical snapshot', () => {
it('rejects an accessor-backed request record without invoking it', () => {
const requests = deleteAccounting();
const target = required(requests.evidence, 0);
const forged = { ...target };
const invoked: string[] = [];
Object.defineProperty(forged, 'operation', {
enumerable: true,
get() {
invoked.push('request.operation');
return target.operation;
},
});
assert.equal(
validXtreamWorkerRequestAccounting(
withRequest(requests, target, forged),
XTREAM_SCENARIO_ID.DELETE_LARGE
),
false
);
assert.deepEqual(invoked, []);
});
it('rejects caller-owned nested phase array methods without invoking them', () => {
const requests = deleteAccounting();
const target = required(requests.evidence, 0);
const phaseEvents = [...target.phaseEvents];
const invoked: string[] = [];
for (const method of ['filter', 'flatMap', 'map', 'some'] as const) {
Object.defineProperty(phaseEvents, method, {
configurable: true,
value(...args: unknown[]) {
invoked.push(method);
return Reflect.apply(
Array.prototype[method],
target.phaseEvents,
args
);
},
});
}
const forged = { ...target, phaseEvents };
assert.equal(
validXtreamWorkerRequestAccounting(
withRequest(requests, target, forged),
XTREAM_SCENARIO_ID.DELETE_LARGE
),
false
);
assert.deepEqual(invoked, []);
});
});
function deleteAccounting(): XtreamWorkerRequestAccounting {
const definition = createXtreamIterationDefinitions(false).find(
({ scenarioId }) => scenarioId === XTREAM_SCENARIO_ID.DELETE_LARGE
);
assert.ok(definition);
return iteration(definition, 1).databaseWorker.requests;
}
function withRequest(
accounting: XtreamWorkerRequestAccounting,
target: XtreamWorkerRequestAccounting['evidence'][number],
replacement: XtreamWorkerRequestAccounting['evidence'][number]
): XtreamWorkerRequestAccounting {
return {
...accounting,
evidence: accounting.evidence.map((request) =>
request === target ? replacement : request
),
};
}
function required<T>(values: readonly T[], index: number): T {
const value = values[index];
assert.ok(value);
return value;
}