Files
orca/src/shared/quick-open-listing-limits.ts
T
Neil 70475e0228 test: stop testing private internals through exports no caller needs (#23829)
Third audit wave. The detector looked for production modules exporting three
or more symbols that no production file imports — only tests do. That shape is
the authoring gate's fourth question failing: a test needing a production seam
no caller needs belongs at the real boundary instead.

Most hits were detector false positives and were left alone; the scanner misses
re-export barrels and dynamic imports, so every module was re-verified with rg
before any edit. Where a private predicate's behavior was already covered
through the module's real entry point, the duplicate cases are gone and the
symbol is module-private again. Where it was NOT covered anywhere else, the test
stays — this audit removes tests, it does not author replacements.

Production code deleted where tests were its only callers: the superseded
`filesystem-directory-listing-limit` module, the unused
`format{Hourly,Daily,Adhoc}Version` helpers and their orphaned prerelease
identifiers, the dead `filterByAutomationListSearch*` family superseded by
`matchAutomationListSearchRowKeys`, and the dead
`getAiVaultResumeWorktreeTargetStatus` copy of the live workspace branch.

Also drops two call-shape source greps in `relay-sweep-schedule.test.ts` that
asserted `index.ts` spells `jitteredSweepIntervalMs(30_000)`; the jitter math
has a behavioral owner at the top of the same file. The structural census that
counts role-gated vs total `setInterval(` calls stays — an ungated sweep runs in
every cell, and nothing else can catch that.
2026-09-29 15:53:18 -07:00

80 lines
2.5 KiB
TypeScript

import { GrowingByteBuffer } from './growing-byte-buffer'
export const QUICK_OPEN_LISTING_MAX_RESULTS = 20_001
const QUICK_OPEN_LISTING_MAX_PATH_BYTES = 64 * 1024
export function resolveQuickOpenResultLimit(requested?: number): number {
if (requested === undefined || requested === Number.POSITIVE_INFINITY) {
return QUICK_OPEN_LISTING_MAX_RESULTS
}
if (!Number.isFinite(requested)) {
return 0
}
return Math.min(Math.max(Math.trunc(requested), 0), QUICK_OPEN_LISTING_MAX_RESULTS)
}
export type QuickOpenPathAccumulatorResult = 'continue' | 'stopped' | 'path-too-large'
export class QuickOpenSubprocessPathAccumulator {
private readonly field = new GrowingByteBuffer()
constructor(
private readonly delimiter: number,
private readonly maxPathBytes = QUICK_OPEN_LISTING_MAX_PATH_BYTES
) {
if (!Number.isInteger(delimiter) || delimiter < 0 || delimiter > 0xff) {
throw new RangeError('Quick Open path delimiter must be one byte')
}
if (!Number.isSafeInteger(maxPathBytes) || maxPathBytes < 0) {
throw new RangeError('Quick Open path limit must be a non-negative safe integer')
}
}
push(
rawChunk: Buffer | string,
onPath: (path: string) => boolean
): QuickOpenPathAccumulatorResult {
const chunk = Buffer.isBuffer(rawChunk) ? rawChunk : Buffer.from(rawChunk, 'utf8')
let cursor = 0
while (cursor < chunk.length) {
const delimiter = chunk.indexOf(this.delimiter, cursor)
const end = delimiter === -1 ? chunk.length : delimiter
const segmentBytes = end - cursor
if (this.field.byteLength + segmentBytes > this.maxPathBytes) {
this.clear()
return 'path-too-large'
}
if (delimiter !== -1 && this.field.byteLength === 0) {
if (!onPath(chunk.toString('utf8', cursor, end))) {
return 'stopped'
}
} else if (segmentBytes > 0) {
// Why: copying prevents a short residual path from retaining the whole read buffer.
this.field.append(chunk.subarray(cursor, end))
if (delimiter !== -1 && !onPath(this.take())) {
return 'stopped'
}
} else if (delimiter !== -1 && !onPath(this.take())) {
return 'stopped'
}
if (delimiter === -1) {
return 'continue'
}
cursor = delimiter + 1
}
return 'continue'
}
finish(): string | null {
return this.field.byteLength > 0 ? this.take() : null
}
clear(): void {
this.field.clear()
}
private take(): string {
return this.field.takeString()
}
}