Skip to content

Generate agent tests with an existing Rails superclass - #630

Open
yorzi wants to merge 1 commit into
activeagents:mainfrom
yorzi:fix/runnable-agent-tests
Open

yorzi wants to merge 1 commit into
activeagents:mainfrom
yorzi:fix/runnable-agent-tests

Conversation

@yorzi

@yorzi yorzi commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Every test that rails generate active_agent:agent writes fails while loading:

test/agents/support_agent_test.rb:3:in `<main>': uninitialized constant ActiveAgent::TestCase (NameError)

The TestUnit template inherits from ActiveAgent::TestCase, which the framework has never defined (the only other mention is a commented-out line in the Railtie). It fails even for an agent generated without actions, whose test body is all comments. The existing generator tests only matched the file's text, so they asserted the broken superclass instead of catching it.

What changes

  • lib/generators/test_unit/templates/functional_test.rb.tt: generated tests inherit from ActiveSupport::TestCase, the class the docs' own test examples already use.
  • test/generators/test_unit/agent_generator_test.rb: the text assertions expect the new superclass.
  • test/generators/active_agent/generated_agent_test.rb (new): generates an agent into a scratch Rails host (framework railties plus active_agent, no Active Record) and runs the generated test file in a subprocess. Covers a plain agent, a namespaced agent and an agent without actions, and asserts the exact run and assertion counts.

Checks

  • With the old template restored, all three new tests fail with the NameError above. With the fix, they pass.
  • bin/test: 4095 runs, 0 failures, 0 errors. bin/rubocop reports no offenses on the changed files.

🤖 Generated with Claude Code

The TestUnit template names ActiveAgent::TestCase, which the framework
does not define. Every generated test fails while loading, even when
the agent has no actions.

Use ActiveSupport::TestCase and run plain, namespaced and empty
generated tests in fresh Rails hosts to cover the installed result.
@TonsOfFun

Copy link
Copy Markdown
Contributor

Thanks @yorzi — read through this one and it looks good to me. Tight scope, the root cause is right (ActiveAgent::TestCase has never existed), and I like that generated_agent_test.rb actually runs the generated file in a subprocess instead of just matching text. CI is green across all the gemfiles.

Before I merge: do you want a proper line-by-line review on this, or are you happy for it to go in as-is? And is there anything else you have planned on this branch, or is it done?

@yorzi

yorzi commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

@TonsOfFun Thanks! I’m comfortable with this being merged as-is if you’re satisfied with the current review.

This branch is complete for the generated-test fix; I don’t have further changes planned for it.

This branch has not been deployed

No deployments
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.

2 participants