mirror of
https://github.com/stablyai/orca.git
synced 2026-11-02 01:57:57 +00:00
* test: remove low-value inventories, passthroughs and redundant cases * style: format test suites after pruning redundant cases * test: remove obsolete workflow and flaky-test references * test: prune deleted builder test from Windows shim allowlist --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { commandLineLength } from './windows-command-line-budget'
|
|
|
|
/** The regex form this estimator replaced; kept as the differential oracle. */
|
|
function referenceCommandLineLength(args: readonly string[]): number {
|
|
return args.reduce((total, arg) => total + arg.length + 3 + (arg.match(/["\\]/g)?.length ?? 0), 0)
|
|
}
|
|
|
|
describe('windows command line budget', () => {
|
|
it('preserves empty, Unicode, backslash and quote budget estimates', () => {
|
|
for (const args of [[], [''], ['🦀', 'é', '\\', '"'], ['a\\\\"b', 'plain']]) {
|
|
expect(commandLineLength(args)).toBe(referenceCommandLineLength(args))
|
|
}
|
|
})
|
|
|
|
// Keep UTF-16 indexing aligned around astral characters and lone surrogates.
|
|
it('counts escapes adjacent to astral characters and lone surrogates', () => {
|
|
for (const args of [
|
|
['🦀\\'],
|
|
['\\🦀'],
|
|
['🦀"🦀\\🦀'],
|
|
['\uD83D'],
|
|
['\uDE00'],
|
|
['\uD83D\\\uDE00"'],
|
|
['\uD800"\uDFFF\\'],
|
|
['%PATH%^"\\', 'a^^b', '%%'],
|
|
['trailing\\', 'trailing\\\\', '\\\\\\"']
|
|
]) {
|
|
expect(commandLineLength(args)).toBe(referenceCommandLineLength(args))
|
|
}
|
|
})
|
|
|
|
// The sparse/dense escape-count handover must preserve totals and its continuation index.
|
|
it('counts the same on either side of the dense-escape switch', () => {
|
|
for (const args of [
|
|
[`\\"${'x'.repeat(30000)}`],
|
|
[`${'x'.repeat(30000)}\\"`],
|
|
[`${'x'.repeat(5000)}${'"\\abc'.repeat(5000)}`],
|
|
['"'.repeat(30000)],
|
|
['\\'.repeat(30000)],
|
|
['ab"cd\\ef'.repeat(4000)],
|
|
[`${'x'.repeat(255)}"${'x'.repeat(30000)}`],
|
|
[`${'"x'.repeat(200)}${'y'.repeat(30000)}`]
|
|
]) {
|
|
expect(commandLineLength(args)).toBe(referenceCommandLineLength(args))
|
|
}
|
|
})
|
|
|
|
it('matches the regex oracle across randomized quote-heavy command lines', () => {
|
|
const pieces = [
|
|
'"',
|
|
'\\',
|
|
'\\\\',
|
|
'\\"',
|
|
'"\\',
|
|
'^',
|
|
'%VAR%',
|
|
'🦀',
|
|
'é',
|
|
'中文',
|
|
'\uD83D',
|
|
'\uDE00',
|
|
'C:\\Users\\n p\\repo',
|
|
'/usr/bin/git',
|
|
'',
|
|
' ',
|
|
'plain'
|
|
]
|
|
let seed = 0x2545f491
|
|
const next = (): number => (seed = (seed * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff
|
|
for (let index = 0; index < 5000; index += 1) {
|
|
const args = Array.from({ length: Math.floor(next() * 6) }, () =>
|
|
Array.from(
|
|
{ length: Math.floor(next() * 30) },
|
|
() => pieces[Math.floor(next() * pieces.length)]
|
|
).join('')
|
|
)
|
|
expect(commandLineLength(args)).toBe(referenceCommandLineLength(args))
|
|
}
|
|
})
|
|
})
|