ci / build (push) Canceled after 0s
- stage-d: next-line / block-close / multi-line fixes, symbols format 2, TS errors in the header. Held-out: 0.426 exact / 0.700 edit sim (stage-c 0.405 / 0.689); block close 0.27 -> 0.79. - stage-e: next-edit (80% exact region rewrites, abstains on 100% of no-edit samples). - Manifest: nextEditModel (companion) and nextEditFormat (older extensions ignore it, so they never use next-edit with the empty-output deletion bug). - Daemon: next-edit served by the companion model in a second llama-server, started after the main model loads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J39imRDT8L7xYbWzsVWd8A
86 lines
5.5 KiB
JavaScript
86 lines
5.5 KiB
JavaScript
// End-to-end test of managed mode without VS Code: local "git server" (with Range support),
|
|
// resumable + verified downloads, llama.cpp fetch/unpack, daemon start/reuse/replace.
|
|
// node test/managed.e2e.mjs <release-out-dir> <scratch-dir>
|
|
import http from 'node:http'
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import assert from 'node:assert/strict'
|
|
import { createRequire } from 'node:module'
|
|
const core = createRequire(import.meta.url)('../dist/managed-core.js')
|
|
|
|
const [releaseDir, scratch] = process.argv.slice(2)
|
|
const storage = path.join(scratch, 'storage')
|
|
const daemonDir = path.resolve('dist/daemon')
|
|
fs.rmSync(storage, { recursive: true, force: true })
|
|
|
|
let rangeRequests = 0
|
|
const server = http.createServer((req, res) => {
|
|
const file = path.join(releaseDir, decodeURIComponent(new URL(req.url, 'http://x').pathname))
|
|
if (!fs.existsSync(file)) { res.writeHead(404); return res.end() }
|
|
const size = fs.statSync(file).size
|
|
const m = /bytes=(\d+)-/.exec(req.headers.range ?? '')
|
|
if (m) {
|
|
rangeRequests++
|
|
const start = Number(m[1])
|
|
res.writeHead(206, { 'content-length': size - start, 'content-range': `bytes ${start}-${size - 1}/${size}` })
|
|
return fs.createReadStream(file, { start }).pipe(res)
|
|
}
|
|
res.writeHead(200, { 'content-length': size })
|
|
fs.createReadStream(file).pipe(res)
|
|
}).listen(7120)
|
|
const manifestUrl = 'http://127.0.0.1:7120/manifest.json'
|
|
const settings = { port: 7111, manifestUrl, model: '', modelPath: '', modelProfile: { order: 'spm', modes: ['simple'], defaultMode: 'simple' }, llamaServerPath: '', llamaServerArgs: [], recordingDir: '', idleShutdownMinutes: 30 }
|
|
const log = []
|
|
const progress = msg => { if (!log.includes(msg.replace(/\d+ \/ /, 'N / '))) log.push(msg.replace(/\d+ \/ /, 'N / ')) }
|
|
const step = (name, fn) => fn().then(r => { console.log(`PASS ${name}`); return r }, e => { console.log(`FAIL ${name}: ${e.message}`); process.exitCode = 1; throw e })
|
|
|
|
// 1. Simulate an interrupted model download: first 100 MB already on disk.
|
|
fs.mkdirSync(path.join(storage, 'models'), { recursive: true })
|
|
const modelSrc = path.join(releaseDir, 'stage-d-q8_0.gguf')
|
|
const fd = fs.openSync(modelSrc, 'r'); const buf = Buffer.alloc(100e6); fs.readSync(fd, buf, 0, buf.length, 0); fs.closeSync(fd)
|
|
fs.writeFileSync(path.join(storage, 'models', 'stage-d-q8_0.gguf.part'), buf)
|
|
|
|
let t0 = Date.now()
|
|
const prepared = await step('first run: manifest, resumed + verified model download, llama.cpp download + unpack', () => core.prepare(storage, daemonDir, '0.4.0-test', settings, progress))
|
|
console.log(` ${((Date.now() - t0) / 1000).toFixed(1)} s; range requests: ${rangeRequests}; model verified: ${fs.existsSync(path.join(storage, 'models', 'stage-d-q8_0.gguf.verified'))}`)
|
|
assert.ok(rangeRequests >= 1, 'download should have resumed with a Range request')
|
|
const cfg = JSON.parse(fs.readFileSync(prepared.configPath, 'utf8'))
|
|
assert.ok(fs.existsSync(cfg.llamaServer.binary), 'llama-server unpacked')
|
|
await step('next-edit companion downloaded and wired (stage-d → stage-e)', async () => {
|
|
assert.equal(cfg.defaultModel, 'stage-d')
|
|
assert.equal(cfg.models['stage-d'].nextEditModel, 'stage-e')
|
|
assert.equal(cfg.models['stage-e'].nextEdit, true)
|
|
assert.ok(fs.existsSync(path.join(storage, 'models', 'stage-e-q8_0.gguf.verified')))
|
|
})
|
|
|
|
await step('daemon starts on the editor runtime', async () => assert.equal(await core.ensureRunning(storage, daemonDir, prepared, settings.port, progress), 'started'))
|
|
const fim = await (await fetch('http://127.0.0.1:7111/v1/fim', { method: 'POST', body: JSON.stringify({ repo: 'e2e', path: 'src/a.ts', prefix: "import { z } from 'zod'\nexport const s = z.object({ a: z.string() })\nexport type S = ", suffix: '\n' }) })).json()
|
|
await step(`completion through the managed daemon (${JSON.stringify(fim.text)})`, async () => assert.match(fim.text, /z\.infer<typeof s>/))
|
|
const neText = "export function f(s: string) {\n const t = s.trim()\n return parse(t))\n}\n"
|
|
const ne = await (await fetch('http://127.0.0.1:7111/v1/next-edit', { method: 'POST', body: JSON.stringify({ repo: 'e2e', path: 'src/f.ts', text: neText, cursor: neText.indexOf('(t)') + 1 }) })).json()
|
|
await step(`next-edit through the companion model (${JSON.stringify(ne.newText ?? ne.error ?? ne)})`, async () => assert.ok(ne.newText?.includes('return parse(t)\n')))
|
|
|
|
t0 = Date.now()
|
|
const again = await step('second window: no re-download, daemon reused', async () => {
|
|
const p = await core.prepare(storage, daemonDir, '0.4.0-test', settings, () => {})
|
|
assert.equal(await core.ensureRunning(storage, daemonDir, p, settings.port, () => {}), 'reused')
|
|
return p
|
|
})
|
|
console.log(` ${((Date.now() - t0) / 1000).toFixed(2)} s`)
|
|
|
|
await step('changed settings replace the managed daemon', async () => {
|
|
const p = await core.prepare(storage, daemonDir, '0.4.0-test', { ...settings, idleShutdownMinutes: 31 }, () => {})
|
|
assert.notEqual(p.instanceTag, again.instanceTag)
|
|
assert.equal(await core.ensureRunning(storage, daemonDir, p, settings.port, () => {}), 'started')
|
|
})
|
|
|
|
await step('checksum mismatch is rejected and the partial file removed', async () => {
|
|
const bad = path.join(storage, 'bad.bin')
|
|
await assert.rejects(core.ensureFile('http://127.0.0.1:7120/NOTICE', bad, '0'.repeat(64), 'NOTICE', () => {}), /checksum mismatch/)
|
|
assert.ok(!fs.existsSync(bad) && !fs.existsSync(`${bad}.part`))
|
|
})
|
|
|
|
console.log('progress messages:', log.filter(l => !l.startsWith('downloading')).join(' | '))
|
|
await fetch('http://127.0.0.1:7111/v1/shutdown', { method: 'POST' }).catch(() => {})
|
|
server.close()
|