mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +03:00
Validado numa worktree combinada com as 16 PRs desta leva sobre `release/v3.8.51`: typecheck:core limpo, check-file-size e check-changelog-integrity OK, complexity 2788/3218 e cognitive 1261/1437, ESLint 0 erros nos 152 arquivos alterados, e a suíte vitest:ui completa (2149) verde. Sobre esta PR especificamente: rodei os **23 arquivos de teste** que ela toca sobre o tip final, depois do merge da base — **392/392**. A migration `174_server_tool_executions.sql` não colide (o tip está em 173, e você já a renumerou em `c35f0fd7`). O dono foi consultado antes do merge, porque o loop está atrás da flag `SERVER_OWNED_TOOL_LOOP_ENABLED` mas o primeiro send não-streaming mudou de dono sem flag, e a verificação manual em combo com Memory continuava desmarcada. A condição dele foi: entra se os testes focados passarem aqui. Passaram. O lock de passthrough (`fetchCalls.length === 1`) é a parte que mais me convenceu — o double-dispatch que um `if (stream)` em volta do send existente causaria é exatamente o tipo de regressão que não aparece em teste de comportamento, só em contagem de chamada. **Três ajustes meus na sua branch:** 1. `tests/unit/chatcore-stream-error-result.test.ts` procurava `"const legResult = await runNonStreamingProviderLeg"`, mas o seu commit final `6077b9dd` passou a reatribuir `legResult` e trocou para `let`. O guard falhava na sua própria branch (confirmei que o arquivo e o `chatCore.ts` eram byte-idênticos ao head da PR, então não era efeito da leva). Passou a aceitar `const|let` — a intenção do guard é o try/catch em volta da chamada, não a palavra-chave. 2. `tests/integration/skills-pipeline.test.ts` foi de 1156 para 1338 linhas e estourou o `testCap` de 1200. Segui o mesmo caminho que você já tinha tomado em `a1d2d20d` para os testes unitários: extraí os três casos do server-owned tool loop para `tests/integration/server-owned-tool-loop-pipeline.test.ts` (259 linhas), com instância própria do harness. O glob `tests/integration/*.test.ts` pega o arquivo novo sem registro adicional. 3/3 verdes isolados. 3. O arquivo novo herdou cinco `any` do original — que só passavam por estarem congelados no `eslint-suppressions.json` sob o nome antigo. Tipei como `Record<string, unknown>`. E `tests/unit/non-streaming-finalization.test.ts` tinha dois argumentos não usados em `trackPendingRequest`, agora prefixados com `_`. Nada disso toca produção nem enfraquece asserção.
141 lines
5.2 KiB
TypeScript
141 lines
5.2 KiB
TypeScript
import { describe, it, before, after, beforeEach } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import fs from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-test-flag-loop-"));
|
|
process.env.DATA_DIR = tmpDir;
|
|
|
|
const { FEATURE_FLAG_DEFINITIONS } =
|
|
await import("../../src/shared/constants/featureFlagDefinitions.ts");
|
|
const { setFeatureFlagOverride, clearAllFeatureFlagOverrides } =
|
|
await import("../../src/lib/db/featureFlags.ts");
|
|
const { isServerOwnedToolLoopEnabled } = await import("../../src/shared/utils/featureFlags.ts");
|
|
|
|
describe("SERVER_OWNED_TOOL_LOOP_ENABLED flag definition", () => {
|
|
it("exists in FEATURE_FLAG_DEFINITIONS", () => {
|
|
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "SERVER_OWNED_TOOL_LOOP_ENABLED");
|
|
assert.ok(def, "SERVER_OWNED_TOOL_LOOP_ENABLED should exist");
|
|
assert.equal(def.category, "runtime");
|
|
assert.equal(def.defaultValue, "false");
|
|
assert.equal(def.requiresRestart, false);
|
|
assert.equal(def.descriptionI18nKey, "featureFlagServerOwnedToolLoopDescription");
|
|
});
|
|
});
|
|
|
|
describe("isServerOwnedToolLoopEnabled wrapper", () => {
|
|
beforeEach(() => {
|
|
clearAllFeatureFlagOverrides();
|
|
});
|
|
|
|
it("returns false when no override is set (default)", () => {
|
|
assert.equal(isServerOwnedToolLoopEnabled(), false);
|
|
});
|
|
|
|
it("returns true when DB override is set to true", () => {
|
|
setFeatureFlagOverride("SERVER_OWNED_TOOL_LOOP_ENABLED", "true");
|
|
assert.equal(isServerOwnedToolLoopEnabled(), true);
|
|
});
|
|
|
|
it("returns false and logs when injected reader throws", () => {
|
|
const logs: unknown[] = [];
|
|
const origError = console.error;
|
|
console.error = (...args: unknown[]) => {
|
|
logs.push(args);
|
|
};
|
|
try {
|
|
const throwingReader = () => {
|
|
throw new Error("flag read failed");
|
|
};
|
|
const result = isServerOwnedToolLoopEnabled(throwingReader);
|
|
assert.equal(result, false);
|
|
assert.ok(logs.length >= 1, "console.error should be called at least once");
|
|
assert.ok(
|
|
logs.some((args) =>
|
|
String(args).includes("Failed to resolve SERVER_OWNED_TOOL_LOOP_ENABLED")
|
|
),
|
|
"error log should mention the flag key"
|
|
);
|
|
} finally {
|
|
console.error = origError;
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("feature-flags-settings count update", () => {
|
|
it("flag count matches updated expected value", () => {
|
|
assert.equal(FEATURE_FLAG_DEFINITIONS.length, 55);
|
|
});
|
|
});
|
|
|
|
describe("i18n key parity for SERVER_OWNED_TOOL_LOOP_ENABLED", () => {
|
|
let enMessages: Record<string, unknown>;
|
|
let ptBrMessages: Record<string, unknown>;
|
|
|
|
before(async () => {
|
|
const enRaw = fs.readFileSync(
|
|
path.resolve(__dirname, "../../src/i18n/messages/en.json"),
|
|
"utf8"
|
|
);
|
|
enMessages = JSON.parse(enRaw);
|
|
const ptBrRaw = fs.readFileSync(
|
|
path.resolve(__dirname, "../../src/i18n/messages/pt-BR.json"),
|
|
"utf8"
|
|
);
|
|
ptBrMessages = JSON.parse(ptBrRaw);
|
|
});
|
|
|
|
it("en.json has nested featureFlags.definitions.SERVER_OWNED_TOOL_LOOP_ENABLED.label", () => {
|
|
const defs = enMessages.featureFlags as Record<string, unknown> | undefined;
|
|
assert.ok(defs, "en.json should have featureFlags section");
|
|
const definitions = (defs as Record<string, unknown>).definitions as
|
|
Record<string, unknown> | undefined;
|
|
assert.ok(definitions, "en.json featureFlags should have definitions");
|
|
const flagDef = definitions.SERVER_OWNED_TOOL_LOOP_ENABLED as
|
|
Record<string, unknown> | undefined;
|
|
assert.ok(flagDef, "definitions should contain SERVER_OWNED_TOOL_LOOP_ENABLED");
|
|
assert.equal(flagDef.label, "Server-Owned Tool Loop");
|
|
assert.equal(
|
|
flagDef.description,
|
|
"Continue non-streaming server-owned tool calls until the model returns a client-usable response."
|
|
);
|
|
});
|
|
|
|
it("pt-BR.json has nested featureFlags.definitions.SERVER_OWNED_TOOL_LOOP_ENABLED.label", () => {
|
|
const defs = ptBrMessages.featureFlags as Record<string, unknown> | undefined;
|
|
assert.ok(defs, "pt-BR.json should have featureFlags section");
|
|
const definitions = (defs as Record<string, unknown>).definitions as
|
|
Record<string, unknown> | undefined;
|
|
assert.ok(definitions, "pt-BR.json featureFlags should have definitions");
|
|
const flagDef = definitions.SERVER_OWNED_TOOL_LOOP_ENABLED as
|
|
Record<string, unknown> | undefined;
|
|
assert.ok(flagDef, "definitions should contain SERVER_OWNED_TOOL_LOOP_ENABLED");
|
|
assert.equal(flagDef.label, "Server-Owned Tool Loop");
|
|
assert.equal(typeof flagDef.description, "string");
|
|
assert.ok(
|
|
((flagDef.description as string) || "").length > 0,
|
|
"description should be non-empty"
|
|
);
|
|
});
|
|
|
|
it("en.json does NOT have stale top-level featureFlagServerOwnedToolLoopDescription", () => {
|
|
assert.equal(
|
|
(enMessages as Record<string, unknown>).featureFlagServerOwnedToolLoopDescription,
|
|
undefined,
|
|
"top-level key should be removed"
|
|
);
|
|
});
|
|
});
|
|
|
|
after(() => {
|
|
try {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
} catch {
|
|
// ignore
|
|
}
|
|
});
|