refactor: cache provider tool runtimes

This commit is contained in:
Peter Steinberger
2026-04-18 18:57:29 +01:00
parent c39314c14a
commit a7e029fde9
12 changed files with 179 additions and 18 deletions

View File

@@ -54,4 +54,39 @@ describe("check-dynamic-import-warts", () => {
`;
expect(findDynamicImportAdvisories(source)).toEqual([]);
});
it("flags direct dynamic imports inside execute paths", () => {
const source = `
export function createTool() {
return {
execute: async () => {
return await import("./runtime.js");
},
};
}
`;
expect(findDynamicImportAdvisories(source)).toEqual([
{
line: 5,
reason:
'direct dynamic import of "./runtime.js" inside execute path; move it behind a cached loader',
},
]);
});
it("allows execute paths that call cached loaders", () => {
const source = `
let runtimePromise: Promise<typeof import("./runtime.js")> | undefined;
function loadRuntime() {
runtimePromise ??= import("./runtime.js");
return runtimePromise;
}
export function createTool() {
return {
execute: async () => await loadRuntime(),
};
}
`;
expect(findDynamicImportAdvisories(source)).toEqual([]);
});
});