test: make unsafe test coercion explicit
Move test coercion out of a hidden global and require each test to import the helper so review tools and runtime scripts can see the unsafe boundary. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
|
||||
import { describe, it, expect } from "bun:test";
|
||||
import { createQuestionLabelTruncatorHook } from "./index";
|
||||
|
||||
@@ -23,10 +24,10 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
};
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
await hook["tool.execute.before"]?.(unsafeTestValue(input), unsafeTestValue(output));
|
||||
|
||||
// then
|
||||
const truncatedLabel = (testCoerce(output.args)).questions[0].options[0].label;
|
||||
const truncatedLabel = (unsafeTestValue(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 +51,10 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
};
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
await hook["tool.execute.before"]?.(unsafeTestValue(input), unsafeTestValue(output));
|
||||
|
||||
// then
|
||||
const resultLabel = (testCoerce(output.args)).questions[0].options[0].label;
|
||||
const resultLabel = (unsafeTestValue(output.args)).questions[0].options[0].label;
|
||||
expect(resultLabel).toBe(shortLabel);
|
||||
});
|
||||
|
||||
@@ -74,10 +75,10 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
};
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
await hook["tool.execute.before"]?.(unsafeTestValue(input), unsafeTestValue(output));
|
||||
|
||||
// then
|
||||
const resultLabel = (testCoerce(output.args)).questions[0].options[0].label;
|
||||
const resultLabel = (unsafeTestValue(output.args)).questions[0].options[0].label;
|
||||
expect(resultLabel).toBe(exactLabel);
|
||||
});
|
||||
|
||||
@@ -90,7 +91,7 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
const originalArgs = { ...output.args };
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
await hook["tool.execute.before"]?.(unsafeTestValue(input), unsafeTestValue(output));
|
||||
|
||||
// then
|
||||
expect(output.args).toEqual(originalArgs);
|
||||
@@ -120,11 +121,11 @@ describe("createQuestionLabelTruncatorHook", () => {
|
||||
};
|
||||
|
||||
// when
|
||||
await hook["tool.execute.before"]?.(testCoerce(input), testCoerce(output));
|
||||
await hook["tool.execute.before"]?.(unsafeTestValue(input), unsafeTestValue(output));
|
||||
|
||||
// then
|
||||
const q1opts = (testCoerce(output.args)).questions[0].options;
|
||||
const q2opts = (testCoerce(output.args)).questions[1].options;
|
||||
const q1opts = (unsafeTestValue(output.args)).questions[0].options;
|
||||
const q2opts = (unsafeTestValue(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