runtime-storage-write-paths.test.ts
1 import assert from 'node:assert/strict' 2 import fs from 'node:fs' 3 import path from 'node:path' 4 import test from 'node:test' 5 6 const repoRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname), '../../../..') 7 8 function readRepoSource(relativePath: string): string { 9 return fs.readFileSync(path.join(repoRoot, relativePath), 'utf-8') 10 } 11 12 test('runtime hot paths use row-level task, schedule, and wallet writes', () => { 13 const expectations = [ 14 { 15 file: 'src/lib/server/runtime/scheduler.ts', 16 required: ['upsertTask(', 'upsertSchedule(', 'upsertSchedules('], 17 forbidden: ['saveTasks(', 'saveSchedules('], 18 }, 19 { 20 file: 'src/lib/server/schedules/schedule-route-service.ts', 21 required: ['saveTask(', 'upsertSchedule('], 22 forbidden: ['saveTasks(', 'saveSchedules('], 23 }, 24 { 25 file: 'src/lib/server/wallets/wallet-service.ts', 26 required: ['saveWallet(', 'deleteWallet('], 27 forbidden: ['saveWallets('], 28 }, 29 ] as const 30 31 for (const expectation of expectations) { 32 const src = readRepoSource(expectation.file) 33 for (const token of expectation.required) { 34 assert.equal(src.includes(token), true, `${expectation.file} should use ${token}`) 35 } 36 for (const token of expectation.forbidden) { 37 assert.equal(src.includes(token), false, `${expectation.file} should not use ${token}`) 38 } 39 } 40 })