mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
* test: strengthen launch, subject identity, and release witnesses * test: strengthen approval paths and prompt answer boundaries * test: strengthen conversation names and mobile log persistence * refactor: group background task stop contract with stop operations * test: strengthen question, title, and release validation * test: distinguish row text and generated dispatch titles * test: verify mobile revival events and retry exclusivity * test: reject incomplete child row output assertions * test: verify copied modules and option selection contracts * test: verify mobile host state and status retry boundaries * test: observe connector refusals and real diagnostic delivery * test: consolidate platform memory coverage and verify bounded work * test: allow cached legacy failure reads within work bounds * test: verify packaging boundaries with independent fixtures --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
71 lines
2.6 KiB
JavaScript
71 lines
2.6 KiB
JavaScript
import path from 'node:path'
|
|
import { beforeAll, describe, expect, it } from 'vitest'
|
|
import { runOxlintPluginOnSources } from './oxlint-plugin-test-runner.mjs'
|
|
|
|
function lintSources(sources) {
|
|
return runOxlintPluginOnSources({
|
|
pluginName: 'sort-comparator-performance',
|
|
pluginPath: path.resolve('config/oxlint-plugins/sort-comparator-performance.mjs'),
|
|
rules: { 'sort-comparator-performance/no-repeated-collator': 'warn' },
|
|
sources
|
|
})
|
|
}
|
|
|
|
const sources = {
|
|
repeatedCollation: `
|
|
rows.sort((a, b) => a.name.localeCompare(b.name, locale, { sensitivity: 'base' }))
|
|
rows.toSorted(function (a, b) { return new Intl.Collator('sv').compare(a, b) })
|
|
rows['sort']((a, b) => Intl.Collator('en', { numeric: true }).compare(a, b))
|
|
rows.sort((a, b) => a['localeCompare'](b, undefined, options))
|
|
`,
|
|
acceptedComparisons: `
|
|
const collator = new Intl.Collator(locale, options)
|
|
rows.sort((a, b) => collator.compare(a.name, b.name) || a.id.localeCompare(b.id))
|
|
rows.toSorted(collator.compare)
|
|
const equal = a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0
|
|
rows.map(a => new Intl.Collator(a.locale))
|
|
rows.sort((a, b) => {
|
|
function deferred() { return new Intl.Collator(locale) }
|
|
return a - b
|
|
})
|
|
`
|
|
}
|
|
|
|
const diagnosticsBySource = new Map()
|
|
beforeAll(() => {
|
|
const fixtures = Object.values(sources)
|
|
lintSources(fixtures).forEach((diagnostics, index) => {
|
|
diagnosticsBySource.set(fixtures[index], diagnostics)
|
|
})
|
|
})
|
|
|
|
describe('sort comparator performance', () => {
|
|
it('reports repeated collation setup in inline sort and toSorted callbacks', () => {
|
|
const findings = diagnosticsBySource.get(sources.repeatedCollation)
|
|
expect(findings).toHaveLength(4)
|
|
expect(
|
|
findings.every(
|
|
(finding) => finding.code === 'sort-comparator-performance(no-repeated-collator)'
|
|
)
|
|
).toBe(true)
|
|
const reportedSources = findings.map(({ labels }) => {
|
|
const { offset, length } = labels[0].span
|
|
return Buffer.from(sources.repeatedCollation)
|
|
.subarray(offset, offset + length)
|
|
.toString('utf8')
|
|
})
|
|
expect(reportedSources.sort()).toEqual(
|
|
[
|
|
"a.name.localeCompare(b.name, locale, { sensitivity: 'base' })",
|
|
"new Intl.Collator('sv')",
|
|
"Intl.Collator('en', { numeric: true })",
|
|
"a['localeCompare'](b, undefined, options)"
|
|
].sort()
|
|
)
|
|
})
|
|
|
|
it('allows one collator per sort, bare comparisons, and unrelated callbacks', () => {
|
|
expect(diagnosticsBySource.get(sources.acceptedComparisons)).toEqual([])
|
|
})
|
|
})
|