Skip to content

[Feature] Add unit tests for TypeScript Stylus code validator #21

@co01y4p

Description

@co01y4p

Is this related to a problem?
The validateAndFixCode() function in apps/web/src/lib/tools/generateStylusCode.ts applies 6 phases of code fixes but has zero test coverage. This function is critical — it runs on every code generation request on the hosted service.

Describe the feature
Create a test file with cases for each of the 6 fix phases:

  1. Structural — fix #![cfg_attr] attributes, add missing extern crate alloc
  2. Imports — add missing use alloc::string::String, use alloy_sol_types::sol
  3. Storage accessors — fix .get(k).get_string(), .setter(k).set_str()
  4. API migrationmsg::sender()self.vm().msg_sender()
  5. TypesB32B256, .as_u64().to::<u64>()
  6. Output sanitizer — remove garbled LLM output, fix duplicate functions

Which module does this relate to?

  • M1: Stylus (contracts, tests, compilation)
  • Hosted Service (arbuilder.app)

Example usage

test("Fix 40: removes Debug from SolidityError derive", () => {
  const input = '#[derive(SolidityError, Debug)]';
  const result = validateAndFixCode(input);
  expect(result).toContain('#[derive(SolidityError)]');
  expect(result).not.toContain('Debug');
});

Additional context

  • Python equivalent tests are in tests/mcp_tools/test_generate_stylus_code.py
  • Check package.json for test framework (vitest or jest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions