-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver-version.integration.test.mjs
More file actions
40 lines (37 loc) · 1.37 KB
/
Copy pathserver-version.integration.test.mjs
File metadata and controls
40 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import assert from 'node:assert/strict'
import { spawn } from 'node:child_process'
import { once } from 'node:events'
import { mkdtemp, readFile, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import test from 'node:test'
test('health reports the package version', async t => {
const root = await mkdtemp(join(tmpdir(), 'mneme-version-'))
const port = 19000 + Math.floor(Math.random() * 1000)
const child = spawn(process.execPath, ['mcp-server.mjs', '--transport=http', `--port=${port}`], {
cwd: import.meta.dirname,
env: { ...process.env, TOKENMEM_DB_PATH: join(root, 'test.db') },
stdio: 'ignore',
})
t.after(async () => {
if (child.exitCode === null) {
child.kill()
await once(child, 'exit')
}
await rm(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 })
})
let health
for (let attempt = 0; attempt < 40; attempt++) {
try {
const response = await fetch(`http://127.0.0.1:${port}/health`)
if (response.ok) {
health = await response.json()
break
}
} catch {}
await new Promise(resolve => setTimeout(resolve, 100))
}
assert.ok(health, 'test server did not become healthy')
const packageJson = JSON.parse(await readFile(new URL('./package.json', import.meta.url), 'utf8'))
assert.equal(health.version, packageJson.version)
})