Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sse/handlers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ async function handleSingleModelChat(
{
sessionId: "", // safety-net redirect doesn't have session context
forceLiveComboTest: false,
forcedConnectionId: null,
forcedConnectionId: runtimeOptions?.forcedConnectionId ?? null,
allowedConnectionIds: null,
comboStepId: null,
comboExecutionKey: null,
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/chat-safetynet-pin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";

// The safety-net redirect rebuilds the options for the inner call. The
// caller's connection pin arrives as runtimeOptions.forcedConnectionId.
// Hardcoding null there drops the pin, so a quota-weighted pool serves one
// connection no matter which one the caller named. The emergency fallback is
// a different path and still clears the pin.

const source = fs.readFileSync(new URL("../../src/sse/handlers/chat.ts", import.meta.url), "utf8");

function blockBetween(startMarker: string, endMarker: string): string {
const start = source.indexOf(startMarker);
assert.ok(start >= 0, `missing start marker ${startMarker}`);
const end = source.indexOf(endMarker, start + startMarker.length);
assert.ok(end > start, `missing end marker ${endMarker}`);
return source.slice(start, end);
}

function assignments(block: string): string[] {
return [...block.matchAll(/forcedConnectionId:\s*([^,\n]+)/g)].map((match) => match[1].trim());
}

test("safety-net combo redirect forwards the caller's connection pin", () => {
const found = assignments(
blockBetween("Safety-net combo redirect", "isModelAvailable: async () => true")
);
assert.ok(found.length > 0, "redirect block has no forcedConnectionId assignment");
for (const value of found) {
assert.notEqual(value, "null");
assert.match(value, /runtimeOptions/);
}
});

test("emergency fallback still clears the connection pin", () => {
const found = assignments(
blockBetween("EMERGENCY_FALLBACK", "no strategy for emergency fallback")
);
assert.ok(found.includes("null"), "emergency fallback no longer clears the pin");
});
Loading