mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Measure session object identity and listener counts across engine switches
window.__gevSession names each session object by a stable instance id and counts applications, attachments and detaches. scripts/qa-app-once.mjs (report-only with --report for now) runs three round trips and a parked-renderer rollback on a keyless preview with paid map, model and voice endpoints blocked.
This commit is contained in:
1 parent
5564156c09
commit
b2cc00833d
5 files changed
+716
No files matched your search
@@ -0,0 +1,66 @@
|
||||
// Identity and attachment counters for the page session, read by the switch
|
||||
// acceptance scripts (scripts/qa-app-once.mjs, qa-voice-engine-switch.mjs):
|
||||
// an engine switch keeps every session object and only re-attaches the parts
|
||||
// bound to an engine, so each id below stays the same across switches.
|
||||
|
||||
const ids = new WeakMap();
|
||||
let nextId = 0;
|
||||
|
||||
/**
|
||||
* A small number naming one object for this page: the same object always
|
||||
* reads the same id, a different object a different one. Null for values
|
||||
* that are not objects.
|
||||
* @param {unknown} value
|
||||
* @returns {number|null}
|
||||
*/
|
||||
export function instanceId(value) {
|
||||
if (
|
||||
value === null ||
|
||||
(typeof value !== 'object' && typeof value !== 'function')
|
||||
)
|
||||
return null;
|
||||
let id = ids.get(value);
|
||||
if (id === undefined) {
|
||||
id = ++nextId;
|
||||
ids.set(value, id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The page's diagnostic handle (`window.__gevSession`).
|
||||
* `read()` returns the session objects by name; `ids` maps each name to its
|
||||
* {@link instanceId}. `count(name)` bumps a counter such as `attachments`.
|
||||
* @param {() => Record<string, unknown>} read
|
||||
*/
|
||||
export function createSessionDiagnostics(read) {
|
||||
const counters = {
|
||||
applications: 0,
|
||||
attachments: 0,
|
||||
detaches: 0,
|
||||
rollbacks: 0,
|
||||
};
|
||||
return Object.freeze({
|
||||
get ids() {
|
||||
return Object.fromEntries(
|
||||
Object.entries(read() ?? {}).map(([name, value]) => [
|
||||
name,
|
||||
instanceId(value),
|
||||
]),
|
||||
);
|
||||
},
|
||||
get counters() {
|
||||
return { ...counters };
|
||||
},
|
||||
get attachments() {
|
||||
return counters.attachments;
|
||||
},
|
||||
get detaches() {
|
||||
return counters.detaches;
|
||||
},
|
||||
count(name) {
|
||||
counters[name] = (counters[name] ?? 0) + 1;
|
||||
return counters[name];
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user