Repository navigation
test: time linear-time checks on the calling thread's CPU only - #1126
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
Thank you for following the naming conventions! 🙏 |
Risk score: Low (1/4)Assessed at 00543c8 from the changed files and the title, by
|
@evlog/cli
evlog
@evlog/nuxthub
@evlog/signals
@evlog/telemetry
commit: |
expectLinearTimenow times each run withprocess.threadCpuUsage()instead ofprocess.cpuUsage(). Process CPU time also counts V8's background threads (concurrent GC marking, JIT compilation). When that work lands on the long run alone, a linear input fails the 24x ratio. That is how "masks tokens in linear time on long attacker-controlled input" failed on #1121's Test (24) job and then passed on rerun.Before and after
The CI failure on
e5a2b385(job). The short run measured close to local speed, and the long run about 4x slower:The same input measured in this orb is linear: 40.2 µs at 8,163 characters and 302.7 µs at 65,038, a ratio of 7.5.
To reproduce it, a scratch test, not committed, runs
expectLinearTimeon a plain character scan, with three worker threads spinning only while the long input is timed:v3(process.cpuUsage())linear (0.7ms / 0.0ms): expected 52.22989076464701 to be less than 24,linear (0.8ms / 0.0ms): expected 69.21068249258211 to be less than 24(2 of 3 runs failed)process.threadCpuUsage())Neither external CPU load (6 busy processes on 4 cores, 480 checks) nor a 442 MB heap failed the check on
v3. Only CPU from threads inside the test process did.New test in
test/helpers/timers.test.ts, "ignores CPU time other threads use while the long input runs". It reports 4x process CPU during the long call. Onv3's helper:With this branch:
Tests 9 passed (9).Fallback for Node before 22.19
Added in 00543c8.
enginesallows Node 22.0, which has noprocess.threadCpuUsage(). There,cpuMs()uses process CPU time, as before this PR, instead of throwing:"times on process CPU time where Node has no threadCpuUsage" deletes
process.threadCpuUsageand expects quadratic work timed on a mockedcpuUsageto be rejected. Without the fallback it fails with"process.threadCpuUsage is not a function". The 4 test files that useexpectLinearTimepass with it (Tests 112 passed (112)), and lint is clean. The same change is in #1127 formain.Validation
pnpm --filter evlog exec vitest run: 2674 passedpnpm --filter evlog run lintandtypecheck: passprocess.threadCpuUsage()exists on both CI versions (checked on Node 22.23.5 and 24.22.2). It was added in Node 22.19, so below that the helper falls back toprocess.cpuUsage()(see below).Test-only, so no changeset.
ELI5
A test checks that hiding secrets in a long string doesn't get disproportionately slow. It timed the whole program, so when Node's background helpers happened to work during the long measurement, the long string looked slower than it was. The test now times only the thread doing the work.