test(hooks): remove unsafe test assertions
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -41,6 +41,10 @@ function truncateQuestionLabels(args: AskUserQuestionArgs): AskUserQuestionArgs
|
||||
};
|
||||
}
|
||||
|
||||
function hasQuestions(args: Record<string, unknown>): args is Record<string, unknown> & AskUserQuestionArgs {
|
||||
return Array.isArray(args.questions);
|
||||
}
|
||||
|
||||
export function createQuestionLabelTruncatorHook() {
|
||||
return {
|
||||
"tool.execute.before": async (
|
||||
@@ -50,10 +54,8 @@ export function createQuestionLabelTruncatorHook() {
|
||||
const toolName = input.tool?.toLowerCase();
|
||||
|
||||
if (toolName === "askuserquestion" || toolName === "ask_user_question") {
|
||||
const args = output.args as unknown as AskUserQuestionArgs | undefined;
|
||||
|
||||
if (args?.questions) {
|
||||
const truncatedArgs = truncateQuestionLabels(args);
|
||||
if (hasQuestions(output.args)) {
|
||||
const truncatedArgs = truncateQuestionLabels(output.args);
|
||||
Object.assign(output.args, truncatedArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
};
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(input as any, output as any);
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
|
||||
// then
|
||||
const truncatedLabel = (output.args as any).questions[0].options[0].label;
|
||||
const truncatedLabel = (testCoerce(output.args)).questions[0].options[0].label;
|
||||
expect(truncatedLabel.length).toBeLessThanOrEqual(30);
|
||||
expect(truncatedLabel).toBe("This is a very long label t...");
|
||||
expect(truncatedLabel.endsWith("...")).toBe(true);
|
||||
@@ -50,10 +50,10 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
};
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(input as any, output as any);
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
|
||||
// then
|
||||
const resultLabel = (output.args as any).questions[0].options[0].label;
|
||||
const resultLabel = (testCoerce(output.args)).questions[0].options[0].label;
|
||||
expect(resultLabel).toBe(shortLabel);
|
||||
});
|
||||
|
||||
@@ -74,10 +74,10 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
};
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(input as any, output as any);
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
|
||||
// then
|
||||
const resultLabel = (output.args as any).questions[0].options[0].label;
|
||||
const resultLabel = (testCoerce(output.args)).questions[0].options[0].label;
|
||||
expect(resultLabel).toBe(exactLabel);
|
||||
});
|
||||
|
||||
@@ -90,7 +90,7 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
const originalArgs = { ...output.args };
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(input as any, output as any);
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
|
||||
// then
|
||||
expect(output.args).toEqual(originalArgs);
|
||||
@@ -120,11 +120,11 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
};
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(input as any, output as any);
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
|
||||
// then
|
||||
const q1opts = (output.args as any).questions[0].options;
|
||||
const q2opts = (output.args as any).questions[1].options;
|
||||
const q1opts = (testCoerce(output.args)).questions[0].options;
|
||||
const q2opts = (testCoerce(output.args)).questions[1].options;
|
||||
|
||||
expect(q1opts[0].label).toBe("Very long label number one ...");
|
||||
expect(q1opts[0].label.length).toBeLessThanOrEqual(30);
|
||||
|
||||
Reference in New Issue
Block a user