fix(dev-host): reload manifest.json instead of failing the identity check

The dev host read manifest.json once at startup and froze that copy in
the Sidecar, while the backend watcher happily rebuilt the binary on any
source edit. Editing the manifest while the host ran — a routine version
bump during a release, for example — then made every restart compare the
fresh binary against the stale in-memory manifest and fail with "Sidecar
identity or protocol does not match manifest" until the whole dev host
was restarted.

Two layers of fixing: the project root now watches manifest.json and hot
swaps the in-memory copy (plus secret-key collection), and the sidecar
handshake re-reads the manifest from disk before declaring a mismatch, so
the check can no longer race the watcher. A genuinely disagreeing
manifest still fails the handshake.
This commit is contained in:
t8y2 committed 2026-09-16 15:10:06 +08:00
1 parent 048b9ed291
commit 2c4f2091a6
4 files changed
+102 -11

No files matched your search

@@ -3,6 +3,9 @@ import assert from "node:assert/strict";
import { fileURLToPath } from "node:url";
import { once } from "node:events";
import { setTimeout as delay } from "node:timers/promises";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { FrameDecoder, JsonLineDecoder, frame, binaryPayload, Sidecar, JSON_LIMIT } from "../sidecar.mjs";
const config = { executable: process.execPath, args: [fileURLToPath(new URL("./echo-sidecar.mjs", import.meta.url))], transport: "stdio-framed", manifest: { id: "example.echo", version: "1.0.0" } };
@@ -88,6 +91,28 @@ test("handshake rejects wrong identity and missing executables terminate promptl
await missing.stop();
});
test("handshake adopts a manifest.json rewritten on disk when the in-memory copy is stale", async (t) => {
const project = await mkdtemp(join(tmpdir(), "dbx-sidecar-manifest-"));
t.after(() => rm(project, { recursive: true, force: true }));
// Simulates a version bump made while the dev host was already running:
// the sidecar binary reports 1.0.0, the in-memory manifest is behind.
await writeFile(join(project, "manifest.json"), JSON.stringify({ id: "example.echo", version: "1.0.0" }));
const sidecar = new Sidecar({ ...config, cwd: project, manifest: { id: "example.echo", version: "0.9.0" } });
t.after(() => sidecar.stop());
const info = await sidecar.start();
assert.equal(sidecar.state, "ready");
assert.equal(sidecar.manifest.version, "1.0.0");
assert.equal(info.plugin.version, "1.0.0");
});
test("handshake still rejects when the on-disk manifest also disagrees with the sidecar", async (t) => {
const project = await mkdtemp(join(tmpdir(), "dbx-sidecar-manifest-"));
t.after(() => rm(project, { recursive: true, force: true }));
await writeFile(join(project, "manifest.json"), JSON.stringify({ id: "example.echo", version: "0.9.0" }));
const sidecar = new Sidecar({ ...config, cwd: project, manifest: { id: "example.echo", version: "0.9.0" } });
await assert.rejects(sidecar.start(), /identity/);
});
test("JSONL supports split lines, concurrent RPC, events and rejects binary channels", async (t) => {
const packets = [],
decoder = new JsonLineDecoder((packet) => packets.push(packet));