Files
orca/config/scripts/vitest-node-runtime-boundary.test.ts
T
Neil d8c871a1f0 Speed up unit tests with cross-runtime duration scheduling (#25967)
* Schedule unit tests across runtimes by measured duration

* Keep new SQLite fixture suites on Node after updating main

* Inject scheduling timings instead of mocking the module

* Keep agent-session database lifecycle contracts on Node
2026-10-06 15:33:40 -07:00

61 lines
2.0 KiB
TypeScript

import { globSync, readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import ts from 'typescript-api'
import { expect, it } from 'vitest'
import { discoverUnitFiles } from './ci-unit-files.mjs'
import { NODE_RUNTIME_INCLUDE } from './vitest-node-runtime-files.mjs'
it('runs Node runtime contracts in Node even when the coordinator uses Bun', () => {
expect(process.versions.bun).toBeUndefined()
expect(process.release.name).toBe('node')
expect(Number(process.versions.node.split('.')[0])).toBeGreaterThanOrEqual(24)
})
function isGlobalThis(expression: ts.Expression): boolean {
if (
ts.isParenthesizedExpression(expression) ||
ts.isAsExpression(expression) ||
ts.isSatisfiesExpression(expression) ||
ts.isNonNullExpression(expression)
) {
return isGlobalThis(expression.expression)
}
return ts.isIdentifier(expression) && expression.text === 'globalThis'
}
it('keeps exposed-GC heap measurements in the Node runtime project', () => {
const root = process.cwd()
const nodeFiles = new Set(globSync(NODE_RUNTIME_INCLUDE).map((file) => resolve(root, file)))
const missing: string[] = []
for (const file of discoverUnitFiles(root)) {
if (nodeFiles.has(resolve(root, file))) {
continue
}
const source = readFileSync(resolve(root, file), 'utf8')
if (!source.includes('heapUsed') || !source.includes('gc')) {
continue
}
const module = ts.createSourceFile(file, source, ts.ScriptTarget.Latest)
let usesGlobalGc = false
const visit = (node: ts.Node): void => {
if (
(ts.isPropertyAccessExpression(node) &&
node.name.text === 'gc' &&
isGlobalThis(node.expression)) ||
(ts.isElementAccessExpression(node) &&
ts.isStringLiteral(node.argumentExpression) &&
node.argumentExpression.text === 'gc' &&
isGlobalThis(node.expression))
) {
usesGlobalGc = true
}
ts.forEachChild(node, visit)
}
visit(module)
if (usesGlobalGc) {
missing.push(file)
}
}
expect(missing).toEqual([])
})