BuilderIO / micro-agent

An AI agent that writes (actually useful) code for you
https://www.builder.io/blog/micro-agent
MIT License
2.61k stars 206 forks source link

Question about usage with existing files / tests #15

Closed RommelTJ closed 2 months ago

RommelTJ commented 3 months ago

Micro-agent works great for setting up new files, but I'm having trouble getting it to work with an existing component.

Say I have a file called ./src/HelloWorld.tsx. and a Jest file at ./src/HelloWorld.test.tsx. The test file has existing behavior that I want to keep. I want to add functionality to the HelloWorld component. But when I run micro-agent on this file, it just overwrites the existing HelloWorld.test.tsx file. Is there a way to tell micro-agent to append to the tests, or is this use case not supported?

steve8708 commented 3 months ago

hey @RommelTJ -have you tried

micro-agent ./src/HelloWorld.tsx -t "npm test"

or to specify a different test file than HelloWorld.test.tsx

micro-agent ./src/HelloWorld.tsx -t "npm test -- HelloWorld" -f ./src/path-to-test-file.ts
RommelTJ commented 3 months ago

I've tried it, but I get an error about a file not being found.

import React from 'react';

const HelloWorld: React.FC = () => {
  return (
    <div>Hello World</div>
  );
};

export default HelloWorld;

Test:

import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
import HelloWorld from './HelloWorld';

describe('HelloWorld Component', () => {
  it('should render Hello World text', () => {
    const { getByText } = render(<HelloWorld />);
    expect(getByText('Hello World')).toBeInTheDocument();
  });
});

File is at path: /Users/rommel/code/work/chatmeter/chatmeter/dashboard-ui/src/modules/snapshot/components

I cd into that path, and run: micro-agent ./HelloWorld.tsx -t "yarn test HelloWorld"

I get this output:

❯ micro-agent ./HelloWorld.tsx -t "yarn test HelloWorld"
┌  🦾 Micro Agent
│
◇  Running tests...
yarn run v1.22.19
│   $ jest HelloWorld
│   PASS src/modules/snapshot/components/HelloWorld.test.tsx
│     HelloWorld Component
│       ✓ should render Hello World text (11 ms)
│   
│   Test Suites: 1 passed, 1 total
│   Tests:       1 passed, 1 total
│   Snapshots:   0 total
│   Time:        1.258 s
│   Ran all test suites matching /HelloWorld/i.
│   Done in 5.31s.
│   
│
◇  Generating code...

✖ ENOENT: no such file or directory, open ''

    ai-shell v0.0.17

    Please open a Bug report with the information above:
    https://github.com/BuilderIO/micro-agent/issues/new
steve8708 commented 3 months ago

oh interesting, what happens if you use the -f flag explicitly?

micro-agent ./HelloWorld.tsx -t "yarn test HelloWorld" -f ./HelloWorld.test.tsx
RommelTJ commented 2 months ago

That worked! Thanks!