mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
fix: resolve mypy and ty type errors in test file
- Fix invalid FunctionToOptimize constructor args (qualified_name, line_number don't exist) - Fix import to use aiservice.models.functions_to_optimize instead of core.shared.testgen_models - Cast messages[1]["content"] to str to satisfy type checker - Simplify effective_module_system assignment in testgen.py to fix mypy error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
da778302b3
commit
e018c40bb5
2 changed files with 8 additions and 27 deletions
|
|
@ -301,10 +301,7 @@ def build_javascript_prompt(
|
|||
# For TypeScript test files, always use ESM import syntax regardless of project module system.
|
||||
# Test runners like @swc/jest and ts-jest expect ESM imports in TypeScript files.
|
||||
# See Issue #12: https://github.com/codeflash-ai/codeflash-internal/pull/2552
|
||||
if language == "typescript":
|
||||
effective_module_system = "esm"
|
||||
else:
|
||||
effective_module_system = module_system
|
||||
effective_module_system: str | None = "esm" if language == "typescript" else module_system
|
||||
|
||||
system_message: ChatCompletionMessageParam = {
|
||||
"role": "system",
|
||||
|
|
|
|||
|
|
@ -8,10 +8,8 @@ because test runners (@swc/jest, ts-jest) expect it, regardless of the project's
|
|||
module system.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from aiservice.models.functions_to_optimize import FunctionToOptimize
|
||||
from core.languages.js_ts.testgen import build_javascript_prompt
|
||||
from core.shared.testgen_models import FunctionToOptimize
|
||||
|
||||
|
||||
class TestTypeScriptCommonJSImport:
|
||||
|
|
@ -32,13 +30,8 @@ class TestTypeScriptCommonJSImport:
|
|||
- This is because @swc/jest and ts-jest expect ESM syntax in TypeScript tests
|
||||
"""
|
||||
# Setup: TypeScript function in CommonJS package
|
||||
function_to_optimize = FunctionToOptimize(
|
||||
function_name="prefixed",
|
||||
qualified_name="prefixed",
|
||||
file_path="packages/types/src/documents/document.ts",
|
||||
line_number=4,
|
||||
is_async=False,
|
||||
parents=[],
|
||||
_ = FunctionToOptimize(
|
||||
function_name="prefixed", file_path="packages/types/src/documents/document.ts", is_async=False, parents=[]
|
||||
)
|
||||
|
||||
function_code = """export const prefixed = (type: DocumentType) => `${type}${SEPARATOR}`"""
|
||||
|
|
@ -61,12 +54,10 @@ class TestTypeScriptCommonJSImport:
|
|||
)
|
||||
|
||||
# Assert: User message should contain ESM import, not require()
|
||||
user_message = messages[1]["content"]
|
||||
user_message = str(messages[1]["content"])
|
||||
|
||||
# Should use import syntax
|
||||
assert "import" in user_message, (
|
||||
"TypeScript test should use 'import' syntax even in CommonJS packages"
|
||||
)
|
||||
assert "import" in user_message, "TypeScript test should use 'import' syntax even in CommonJS packages"
|
||||
assert "import { prefixed }" in user_message or "import prefixed" in user_message, (
|
||||
"Should have proper import statement for the function"
|
||||
)
|
||||
|
|
@ -83,14 +74,7 @@ class TestTypeScriptCommonJSImport:
|
|||
This test ensures we don't break JavaScript test generation.
|
||||
JavaScript tests (.test.js) in CommonJS packages should still use require().
|
||||
"""
|
||||
function_to_optimize = FunctionToOptimize(
|
||||
function_name="add",
|
||||
qualified_name="add",
|
||||
file_path="src/calculator.js",
|
||||
line_number=1,
|
||||
is_async=False,
|
||||
parents=[],
|
||||
)
|
||||
_ = FunctionToOptimize(function_name="add", file_path="src/calculator.js", is_async=False, parents=[])
|
||||
|
||||
function_code = """export function add(a, b) { return a + b; }"""
|
||||
module_path = "src/calculator"
|
||||
|
|
@ -111,7 +95,7 @@ class TestTypeScriptCommonJSImport:
|
|||
)
|
||||
|
||||
# Assert: For JavaScript in CommonJS, require() is still valid
|
||||
user_message = messages[1]["content"]
|
||||
user_message = str(messages[1]["content"])
|
||||
|
||||
# JavaScript tests in CommonJS can use either import or require
|
||||
# Both are valid since Jest transforms them
|
||||
|
|
|
|||
Loading…
Reference in a new issue