perf(executors): lazy-load the executor registry — defer class imports + construction to first use (#11220) (#11421)

Validated in a combined 3-PR batch worktree off release/v3.8.51 tip (a sibling PR from the same author, #11495, was held out — a typecheck error in zai-web.ts only reproduced with this PR + #11495 boarded together, and cleared without #11495; isolated this PR alone confirmed clean on its own too, so the interaction belonged to #11495's side — see its comment).
- Golden lock: executor-map-golden.test.ts — passes byte-identical (same keys, classes, provider identities, dispatch guards)
- Focused tests part of batch's 94/94 node:test run
- typecheck:core, file-size, changelog-integrity, complexity, cognitive-complexity — all OK
- Full-repo lint: 228 pre-existing dashboard react-hooks/* findings, unrelated to this diff

Thanks for the measured, careful methodology here — the golden-lock contract plus the isolated DATA_DIR benchmarking make this an easy PR to trust despite the wide surface (72 files).
This commit is contained in:
Paijo
2026-08-26 04:22:46 +07:00
committed by GitHub
parent 026d26edb7
commit 7cfabfc5c9
72 changed files with 562 additions and 590 deletions

View File

@@ -91,15 +91,15 @@ test("Command Code provider catalog has pinned models and alias lookup", () => {
assert.equal(getRegistryEntry("cmd"), entry);
});
test("getExecutor returns the specialized Command Code executor", () => {
test("getExecutor returns the specialized Command Code executor", async () => {
assert.equal(hasSpecializedExecutor("command-code"), true);
assert.ok(getExecutor("command-code") instanceof CommandCodeExecutor);
assert.ok(getExecutor("cmd") instanceof CommandCodeExecutor);
assert.ok((await getExecutor("command-code")) instanceof CommandCodeExecutor);
assert.ok((await getExecutor("cmd")) instanceof CommandCodeExecutor);
});
test("Command Code executor posts a flat OpenAI body + standard headers to /provider/v1/chat/completions (#10265)", async () => {
const calls = captureFetch({});
const executor = getExecutor("command-code");
const executor = await getExecutor("command-code");
const { response, url, headers } = await executor.execute({
model: "gpt-5.4-mini",
stream: false,
@@ -143,7 +143,7 @@ test("Command Code executor posts a flat OpenAI body + standard headers to /prov
test("Command Code executor passes reasoning/thinking fields through at the top level of the OpenAI body", async () => {
const calls = captureFetch({});
await getExecutor("command-code").execute({
(await getExecutor("command-code")).execute({
model: "deepseek/deepseek-v4-pro",
stream: false,
credentials: { apiKey: "cc_test_key" },
@@ -166,7 +166,7 @@ test("Command Code executor passes reasoning/thinking fields through at the top
test("Command Code executor honors body.model rewrite from payload rules", async () => {
const calls = captureFetch({});
await getExecutor("command-code").execute({
(await getExecutor("command-code")).execute({
model: "deepseek-v4-pro-max",
stream: false,
credentials: { apiKey: "cc_test_key" },
@@ -187,7 +187,7 @@ test("Command Code executor maps unsupported minimal reasoning_effort to low (up
const calls = captureFetch({});
// `minimal` (a Muse Spark catalog tier) must be downgraded to `low` before
// the wire body is built, on BOTH the combo and single-model paths.
await getExecutor("command-code").execute({
(await getExecutor("command-code")).execute({
model: "poolside/laguna-s-2.1-free",
stream: false,
credentials: { apiKey: "cc_test_key" },
@@ -232,7 +232,7 @@ test("Command Code executor passes the upstream OpenAI SSE stream through untouc
});
};
const { response } = await getExecutor("command-code").execute({
const { response } = (await getExecutor("command-code")).execute({
model: "gpt-5.4",
stream: true,
credentials: { apiKey: "cc_test_key" },
@@ -266,7 +266,7 @@ test("Command Code executor passes the upstream OpenAI JSON through untouched (n
});
};
const { response } = await getExecutor("command-code").execute({
const { response } = (await getExecutor("command-code")).execute({
model: "gpt-5.4-mini",
stream: false,
credentials: { apiKey: "cc_test_key" },
@@ -279,7 +279,7 @@ test("Command Code executor passes the upstream OpenAI JSON through untouched (n
test("Command Code executor surfaces upstream errors", async () => {
globalThis.fetch = async () => new Response("bad key", { status: 401, statusText: "Unauthorized" });
const upstreamFailure = await getExecutor("command-code").execute({
const upstreamFailure = (await getExecutor("command-code")).execute({
model: "gpt-5.4-mini",
stream: false,
credentials: { apiKey: "cc_test_key" },
@@ -291,7 +291,7 @@ test("Command Code executor surfaces upstream errors", async () => {
test("Command Code executor omits max_tokens when the client does not supply one", async () => {
const calls = captureFetch({});
await getExecutor("command-code").execute({
(await getExecutor("command-code")).execute({
model: "zai-org/GLM-5.1",
stream: false,
credentials: { apiKey: "cc_test_key" },
@@ -305,7 +305,7 @@ test("Command Code executor omits max_tokens when the client does not supply one
test("Command Code executor clamps an oversized client-supplied max_tokens to the endpoint ceiling", async () => {
const calls = captureFetch({});
// A client asking for more than the 200000 endpoint ceiling is clamped down.
await getExecutor("command-code").execute({
(await getExecutor("command-code")).execute({
model: "deepseek/deepseek-v4-pro",
stream: false,
credentials: { apiKey: "cc_test_key" },
@@ -316,7 +316,7 @@ test("Command Code executor clamps an oversized client-supplied max_tokens to th
test("Command Code executor honors a smaller client-provided max_tokens", async () => {
const calls = captureFetch({});
await getExecutor("command-code").execute({
(await getExecutor("command-code")).execute({
model: "zai-org/GLM-5.1",
stream: false,
credentials: { apiKey: "cc_test_key" },
@@ -350,7 +350,7 @@ test("Command Code stream preserves the upstream OpenAI usage chunk (passthrough
globalThis.fetch = async () =>
new Response(sse, { status: 200, headers: { "Content-Type": "text/event-stream" } });
const { response } = await getExecutor("command-code").execute({
const { response } = (await getExecutor("command-code")).execute({
model: "gpt-5.4-mini",
stream: true,
credentials: { apiKey: "cc_test_key" },