chore: update how txt pasting ux feels

This commit is contained in:
Brooklyn Nicholson 2026-04-13 14:49:10 -05:00
parent 9db94e8521
commit 77b97b810a
8 changed files with 239 additions and 83 deletions

View file

@ -1,6 +1,15 @@
import { describe, expect, it } from 'vitest'
import { estimateRows, fmtK, isToolTrailResultLine, lastCotTrailIndex, sameToolTrailGroup } from '../lib/text.js'
import {
edgePreview,
estimateRows,
estimateTokensRough,
fmtK,
isToolTrailResultLine,
lastCotTrailIndex,
pasteTokenLabel,
sameToolTrailGroup
} from '../lib/text.js'
describe('isToolTrailResultLine', () => {
it('detects completion markers', () => {
@ -50,6 +59,46 @@ describe('fmtK', () => {
})
})
describe('estimateTokensRough', () => {
it('uses 4 chars per token rounding up', () => {
expect(estimateTokensRough('')).toBe(0)
expect(estimateTokensRough('a')).toBe(1)
expect(estimateTokensRough('abcd')).toBe(1)
expect(estimateTokensRough('abcde')).toBe(2)
})
})
describe('edgePreview', () => {
it('keeps both ends for long text', () => {
expect(edgePreview('Vampire Bondage ropes slipped from her neck, still stained with blood', 8, 18)).toBe(
'Vampire.. stained with blood'
)
})
})
describe('pasteTokenLabel', () => {
it('builds readable long-paste labels with counts', () => {
expect(
pasteTokenLabel({
charCount: 1000,
id: 7,
lineCount: 250,
text: 'Vampire Bondage ropes slipped from her neck, still stained with blood',
tokenCount: 250
})
).toContain('[[paste:7 ')
expect(
pasteTokenLabel({
charCount: 1000,
id: 7,
lineCount: 250,
text: 'Vampire Bondage ropes slipped from her neck, still stained with blood',
tokenCount: 250
})
).toContain('[250 lines · 250 tok · 1K chars]')
})
})
describe('estimateRows', () => {
it('handles tilde code fences', () => {
const md = ['~~~markdown', '# heading', '~~~'].join('\n')