mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
Heap snapshots fail on large heaps, so GET /api/experimental/debug/runtime?heap=true returns the 25 most common object types from bun:jsc heapStats(). It counts without serializing, about 10 ns per object; the default response skips it and stays cheap. Gauges now register with a RuntimeStats service provided by a global layer node instead of a module-level map, so servers in one process keep separate registries.
51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { expect } from "bun:test"
|
|
import { DebugRuntime } from "@opencode/protocol/groups/debug-runtime"
|
|
import { Effect, Schema } from "effect"
|
|
import { tmpdir } from "../../core/test/fixture/tmpdir"
|
|
import { it } from "../../core/test/lib/effect"
|
|
import { ServerFetch } from "../src/fetch"
|
|
|
|
const decode = Schema.decodeUnknownSync(DebugRuntime)
|
|
|
|
it.live("reports runtime memory and long-lived structure sizes", () =>
|
|
Effect.gen(function* () {
|
|
const config = yield* Effect.acquireDisposable(Effect.promise(() => tmpdir("opencode-debug-runtime-")))
|
|
const handler = yield* ServerFetch.make({
|
|
app: { version: "test-version" },
|
|
database: { path: ":memory:" },
|
|
config: { project: false, directory: config.path },
|
|
models: { fetch: false },
|
|
fs: { filewatcher: false },
|
|
})
|
|
const get = (query = "") =>
|
|
Effect.promise(() =>
|
|
handler(new Request(`http://opencode.local/api/experimental/debug/runtime${query}`)).then(async (response) => {
|
|
expect(response.status).toBe(200)
|
|
return decode(await response.json())
|
|
}),
|
|
)
|
|
const read = get()
|
|
|
|
const before = yield* read
|
|
expect(before.pid).toBe(process.pid)
|
|
expect(before.memory.rss).toBeGreaterThan(0)
|
|
expect(before.objectTypes).toBeUndefined()
|
|
expect((yield* get("?heap=true")).objectTypes?.["Object"]).toBeGreaterThan(0)
|
|
expect(before.locations).toBe(0)
|
|
expect(before.gauges["bus.live.backlog"]).toBe(0)
|
|
expect(before.gauges["job"]).toBe(0)
|
|
|
|
// Booting a Location registers its plugin registry.
|
|
const location = yield* Effect.promise(() =>
|
|
handler(
|
|
new Request("http://opencode.local/api/location", {
|
|
headers: { "x-opencode-directory": encodeURIComponent(config.path) },
|
|
}),
|
|
),
|
|
)
|
|
expect(location.status).toBe(200)
|
|
const after = yield* read
|
|
expect(after.locations).toBe(1)
|
|
expect(after.gauges["plugin.active"]).toBeGreaterThanOrEqual(0)
|
|
}),
|
|
)
|