test(dsh): pin the plugin lifetime that stops install jobs

dispose() on the manager stops running installs, but nothing tied that to
the plugin's own lifetime: a change to the registration could have left
pip running after the plugin unloads. Mount the plugin, replace the
provided manager's dispose with a counter, run the envLifetime cleanup and
assert it is called once.
This commit is contained in:
LiangshouX 2026-10-28 19:25:49 +08:00
parent 64d4bbd2c6
commit 559efcee28

View file

@ -261,3 +261,56 @@ function applyPlugin(t, ctx, input) {
});
return apply(ctx, { ...input, autoMemoryQueueDir: directory });
}
test("disposes the environment manager when the plugin unloads", async (t) => {
const effects = [];
const provided = {};
const directory = mkdtempSync(join(tmpdir(), "reme-dsh-dispose-"));
t.after(async () => {
// Stop the runtime before removing the queue directory it reads on shutdown.
await provided.remeMemory?.disposeAll();
rmSync(directory, { recursive: true, force: true });
});
const ctx = {
fiber: { state: 0 },
logger: { debug() {}, warn() {}, log() {} },
provide(name, value) {
provided[name] = value;
},
plugin() {
return Promise.resolve();
},
inject() {},
effect(execute, label) {
effects.push({ label, cleanup: execute() });
return () => {};
},
tools: {
register() {
return () => {};
},
},
on() {},
};
apply(ctx, {
autoMemoryEnabled: false,
autoDreamEnabled: false,
autoMemoryQueueDir: directory,
});
const manager = provided.remeEnv;
assert.ok(manager, "the environment manager is provided to the context");
let disposed = 0;
manager.dispose = () => {
disposed += 1;
};
// The plugin owns the lifetime of the installs it started, so unloading it
// must reach the manager rather than leaving pip running.
const lifetime = effects.find(
(entry) => entry.label === "remeMemory.envLifetime()",
);
assert.ok(lifetime?.cleanup, "the env lifetime effect registers a cleanup");
lifetime.cleanup();
assert.equal(disposed, 1);
});