mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 03:32:43 +00:00
test(agents): dedupe embedded runner and sessions lifecycle fixtures
This commit is contained in:
@@ -64,6 +64,30 @@ describe("resolveExtraParams", () => {
|
||||
});
|
||||
|
||||
describe("applyExtraParamsToAgent", () => {
|
||||
function createOptionsCaptureAgent() {
|
||||
const calls: Array<SimpleStreamOptions | undefined> = [];
|
||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||
calls.push(options);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
return {
|
||||
calls,
|
||||
agent: { streamFn: baseStreamFn },
|
||||
};
|
||||
}
|
||||
|
||||
function buildAnthropicModelConfig(modelKey: string, params: Record<string, unknown>) {
|
||||
return {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
[modelKey]: { params },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function runStoreMutationCase(params: {
|
||||
applyProvider: string;
|
||||
applyModelId: string;
|
||||
@@ -86,12 +110,7 @@ describe("applyExtraParamsToAgent", () => {
|
||||
}
|
||||
|
||||
it("adds OpenRouter attribution headers to stream options", () => {
|
||||
const calls: Array<SimpleStreamOptions | undefined> = [];
|
||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||
calls.push(options);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
const { calls, agent } = createOptionsCaptureAgent();
|
||||
|
||||
applyExtraParamsToAgent(agent, undefined, "openrouter", "openrouter/auto");
|
||||
|
||||
@@ -113,25 +132,8 @@ describe("applyExtraParamsToAgent", () => {
|
||||
});
|
||||
|
||||
it("adds Anthropic 1M beta header when context1m is enabled for Opus/Sonnet", () => {
|
||||
const calls: Array<SimpleStreamOptions | undefined> = [];
|
||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||
calls.push(options);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
"anthropic/claude-opus-4-6": {
|
||||
params: {
|
||||
context1m: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const { calls, agent } = createOptionsCaptureAgent();
|
||||
const cfg = buildAnthropicModelConfig("anthropic/claude-opus-4-6", { context1m: true });
|
||||
|
||||
applyExtraParamsToAgent(agent, cfg, "anthropic", "claude-opus-4-6");
|
||||
|
||||
@@ -152,26 +154,11 @@ describe("applyExtraParamsToAgent", () => {
|
||||
});
|
||||
|
||||
it("merges existing anthropic-beta headers with configured betas", () => {
|
||||
const calls: Array<SimpleStreamOptions | undefined> = [];
|
||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||
calls.push(options);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
"anthropic/claude-sonnet-4-5": {
|
||||
params: {
|
||||
context1m: true,
|
||||
anthropicBeta: ["files-api-2025-04-14"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const { calls, agent } = createOptionsCaptureAgent();
|
||||
const cfg = buildAnthropicModelConfig("anthropic/claude-sonnet-4-5", {
|
||||
context1m: true,
|
||||
anthropicBeta: ["files-api-2025-04-14"],
|
||||
});
|
||||
|
||||
applyExtraParamsToAgent(agent, cfg, "anthropic", "claude-sonnet-4-5");
|
||||
|
||||
@@ -193,25 +180,8 @@ describe("applyExtraParamsToAgent", () => {
|
||||
});
|
||||
|
||||
it("ignores context1m for non-Opus/Sonnet Anthropic models", () => {
|
||||
const calls: Array<SimpleStreamOptions | undefined> = [];
|
||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||
calls.push(options);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
"anthropic/claude-haiku-3-5": {
|
||||
params: {
|
||||
context1m: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const { calls, agent } = createOptionsCaptureAgent();
|
||||
const cfg = buildAnthropicModelConfig("anthropic/claude-haiku-3-5", { context1m: true });
|
||||
|
||||
applyExtraParamsToAgent(agent, cfg, "anthropic", "claude-haiku-3-5");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user