Problem
generate.NewGenerator() reads ANTHROPIC_API_KEY, OPENAI_API_KEY, and GEMINI_API_KEY from the environment at construction time in BuildRootCommand(). This means:
- Every
toolwright invocation stores API keys in memory even when generate manifest is never called.
- Tests that call
BuildRootCommand() and set env vars mid-test won't see the updated values.
Context
Raised in PR #14 review (comment). Deferred because it changes the NewGenerator constructor and provider wiring.
Suggested fix
Read keys lazily inside Generate() instead of at construction:
func NewGenerator() *Generator {
return &Generator{
providers: map[string]providerFactory{
"anthropic": func() LLMProvider { return NewAnthropicProvider(os.Getenv("ANTHROPIC_API_KEY"), nil) },
// ...
},
}
}
Or use a NewGeneratorFromEnv() that defers reads to first Generate() call.
Problem
generate.NewGenerator()readsANTHROPIC_API_KEY,OPENAI_API_KEY, andGEMINI_API_KEYfrom the environment at construction time inBuildRootCommand(). This means:toolwrightinvocation stores API keys in memory even whengenerate manifestis never called.BuildRootCommand()and set env vars mid-test won't see the updated values.Context
Raised in PR #14 review (comment). Deferred because it changes the
NewGeneratorconstructor and provider wiring.Suggested fix
Read keys lazily inside
Generate()instead of at construction:Or use a
NewGeneratorFromEnv()that defers reads to firstGenerate()call.