Skip to content

test: add TypeScript plugin and teacher contract test coverage#495

Draft
madara88645 wants to merge 1 commit into
mainfrom
tests/add-typescript-contract-tests-20260703
Draft

test: add TypeScript plugin and teacher contract test coverage#495
madara88645 wants to merge 1 commit into
mainfrom
tests/add-typescript-contract-tests-20260703

Conversation

@madara88645

Copy link
Copy Markdown
Owner

Summary

Closes two test gaps found in a prior audit — both files were pure logic with no dedicated test coverage:

  • analyst/languages/typescript.py (TypeScriptAnalyzer, tree-sitter-based TS/TSX parsing) had no test file, even though its siblings analyst/languages/javascript.py and analyst/languages/python.py are both covered by tests/languages/test_javascript.py and tests/languages/test_python.py.
  • teacher/contract.py (~383 lines of prompt/response normalization helpers: clip_text, _normalize_contract_sections, normalize_chat_text, normalize_explain_payload, normalize_ghost_payload, normalize_learning_steps, extract_node_ids_from_summary, build_*_prompt) had no tests/test_contract.py — it was only reachable indirectly through mocked tests of teacher/openrouter_teacher.py.

Changes

  • tests/languages/test_typescript.py (new, 10 tests in TestTypeScriptAnalyzer, mirrors the test_python.py tempdir-fixture convention):

    • test_function_and_class_declarations, test_arrow_function_export, test_interface_and_type_alias_do_not_create_nodes — basic TS parsing
    • test_tsx_jsx_syntax_parses — TSX/JSX support
    • test_nestjs_route_decorators_mark_api_boundary, test_non_route_decorator_does_not_mark_api_boundary — decorator-based api_boundary detection
    • test_import_type_only_is_stripped — TS-specific import type stripping
    • test_empty_file_returns_valid_analysis, test_malformed_syntax_does_not_crash, test_unreadable_file_returns_none — edge cases

    Bug found while writing tests (not fixed here, documented in the test with a detailed comment): _TypeScriptWalker._collect_decorators in typescript.py finds a node's siblings via child is node (identity comparison). tree-sitter's Python bindings return a new Node wrapper object on every .children/.parent access, so this identity check never matches in practice — decorators are never collected, and api_boundary is never True for NestJS/Angular-decorated methods today, despite the module docstring's stated intent. test_nestjs_route_decorators_mark_api_boundary asserts the actual (currently-false) behavior and explains the root cause inline; a follow-up fix would likely switch the comparison to child.id == node.id.

  • tests/test_contract.py (new, 54 tests, pytest-class style matching tests/test_openrouter_teacher.py's conventions):

    • TestClipText — truncation at/under/over the limit, empty/whitespace fallback, custom fallback
    • TestNormalizeContractSections — well-formed input, missing sections key, wrong-typed sections/unknowns, non-string values rendered as markdown, References fallback
    • TestRenderContractText, TestNormalizeChatText — JSON vs. text-extraction paths (including the same-line-header-content-is-dropped nuance)
    • TestNormalizeExplainPayload, TestNormalizeGhostPayload — valid/missing/wrong-typed payload keys, importance allow-list normalization
    • TestNormalizeLearningSteps — valid payload, wrong types, missing/duplicate node ids, allowed-list filtering, step renumbering
    • TestExtractNodeIdsFromSummary — ids present/absent/mixed
    • TestTeacherReferencesRender, TestBudgetsAreDefinedForEverySection — supporting dataclass/constants

Testing

  • Existing tests pass (python -m pytest tests/ -v) — 420 passed (356 baseline + 64 new)
  • New tests added: python -m pytest tests/languages/test_typescript.py tests/test_contract.py -v — 64 passed

Checklist

  • Code passes lint (ruff check . --select E,F --ignore E501,E402)
  • No secrets or credentials committed
  • Code passes type check — not run (test-only change, no source edits)

Only the two new test files are touched; no source, config, CI, or lockfile changes.


Generated by Claude Code

…t normalization

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vibegraph Ready Ready Preview, Comment Jul 3, 2026 4:18am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant