context-engine: make factory ctx parameter required

This commit is contained in:
Jari Mustonen
2026-04-15 09:42:58 +03:00
committed by Josh Lehman
parent 6ceb1b5981
commit c88f7fe452
2 changed files with 8 additions and 7 deletions

View File

@@ -360,7 +360,7 @@ describe("Engine contract tests", () => {
const resolved = getContextEngineFactory("mock");
expect(resolved).toBe(factory);
const engine = await resolved!();
const engine = await resolved!({});
expect(engine).toBeInstanceOf(MockContextEngine);
expect(engine.info.id).toBe("mock");
});
@@ -706,7 +706,7 @@ describe("Factory context passing", () => {
const engineId = `factory-ctx-${Date.now().toString(36)}`;
let receivedCtx: ContextEngineFactoryContext | undefined;
const factory: ContextEngineFactory = (ctx?: ContextEngineFactoryContext) => {
const factory: ContextEngineFactory = (ctx: ContextEngineFactoryContext) => {
receivedCtx = ctx;
return {
info: { id: engineId, name: "Ctx Engine" },
@@ -771,7 +771,7 @@ describe("Factory context passing", () => {
// Override the default "legacy" engine to intercept the no-config path
registerContextEngineForOwner(
"legacy",
(ctx?: ContextEngineFactoryContext) => {
(ctx: ContextEngineFactoryContext) => {
receivedCtx = ctx;
return {
info: { id: "legacy", name: "NoConfig Engine", version: "1" },

View File

@@ -19,12 +19,13 @@ export type ContextEngineFactoryContext = {
* A factory that creates a ContextEngine instance.
* Supports async creation for engines that need DB connections etc.
*
* Factories may accept an optional {@link ContextEngineFactoryContext} parameter
* for runtime context. No-arg factories remain supported for backward compatibility
* since the parameter is optional.
* The factory receives a {@link ContextEngineFactoryContext} with runtime
* environment context (config, paths). Existing no-arg factories remain
* backward compatible because TypeScript permits assigning functions with
* fewer parameters to wider signatures.
*/
export type ContextEngineFactory = (
ctx?: ContextEngineFactoryContext,
ctx: ContextEngineFactoryContext,
) => ContextEngine | Promise<ContextEngine>;
export type ContextEngineRegistrationResult = { ok: true } | { ok: false; existingOwner: string };