Files
autocomplete-model/extensions/vscode/test/logic.test.mjs
T
HarvmasterandClaude Opus 5.5 fa8f775779 Restructure into a monorepo: models, VS Code extension, daemon, shared
- models/: GGUFs (Git LFS), manifest.json, model card, Apache-2.0 LICENSE + NOTICE
- extensions/vscode/: the Local Autocomplete extension (v0.5.0, publisher harvmaster)
- daemon/: acd completion daemon (bundled into the extension; also runs standalone)
- shared/: prompt layout + symbol extraction shared with the training pipeline
- scripts/: make-model-release.mjs, publish-extension-release.mjs (Gitea releases)
- README with quick start, settings, architecture, build and release instructions;
  MIT license for code; CHANGELOG

The default model manifest URL moves to models/manifest.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 15:37:19 +00:00

39 lines
1.7 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { sliceDocument, applySelectedSuggestion, repoAndPath, statusText } from '../dist/logic.js'
test('slices at the cursor', () => {
const s = sliceDocument('abc\ndef', 5, 1000, 1000)
assert.deepEqual(s, { prefix: 'abc\nd', suffix: 'ef', prefixLineOffset: 0 })
})
test('large prefixes are cut at a stable line chunk', () => {
const doc = Array.from({ length: 2000 }, (_, i) => `line ${i}`).join('\n')
const a = sliceDocument(doc, doc.length - 5, 5000, 100, 256)
const b = sliceDocument(doc, doc.length - 2, 5000, 100, 256) // typed 3 more chars
assert.equal(a.prefixLineOffset % 256, 0)
assert.equal(a.prefixLineOffset, b.prefixLineOffset)
assert.ok(a.prefix.startsWith(`line ${a.prefixLineOffset}\n`))
assert.ok(a.prefix.length <= 5000 + 20 * 256)
})
test('suffix is cut at a line boundary', () => {
const s = sliceDocument('x' + '\nabcdef'.repeat(10), 1, 1000, 15)
assert.ok(s.suffix.endsWith('\n'))
})
test('selected IntelliSense item is treated as typed', () => {
const r = applySelectedSuggestion('this.conn', 5, 9, 'connections')
assert.deepEqual(r, { text: 'this.connections', cursorOffset: 16 })
})
test('repo/path normalisation', () => {
assert.deepEqual(repoAndPath('wrapped.cash', 'src\\a\\b.ts', '/x/src/a/b.ts'), { repo: 'wrapped.cash', path: 'src/a/b.ts' })
assert.deepEqual(repoAndPath(undefined, '', '/tmp/scratch.ts'), { repo: 'untitled', path: 'scratch.ts' })
})
test('status text', () => {
assert.match(statusText({ enabled: true, mode: 'symbols', effectiveMode: 'simple', model: 'stage-c' }, 41.6), /symbols→simple · 42 ms/)
assert.match(statusText(null, null), /no daemon/)
})