Implement the following plan: Plan: Add Factory AI Droid Integration Tests Context The…
Jump to turn (6)
- User
Implement the following plan:
The integration test folder (cmd/entire/cli/integration_test/) has comprehensive tests for Claude Code and Gemini CLI agents — detection, hook installation, session operations, strategy composition, and enable command smoke tests. Factory AI Droid has zero integration tests despite implementing HookSupport, HookHandler, TranscriptAnalyzer, and SubagentAwareExtractor. This is a coverage gap for the real CLI binary execution path.
| File | Action | Purpose |
|---|---|---|
integration_test/hooks.go | Modify | Add FactoryDroidHookRunner, FactoryDroidSession, CreateDroidTranscript |
integration_test/agent_test.go | Modify | Add detection, hook install, helper, and session stub tests |
integration_test/setup_factoryai_hooks_test.go | Create | Smoke tests for entire enable --agent factoryai-droid |
integration_test/agent_strategy_test.go | Modify | Add agent+strategy composition tests |
hooks.goAdd FactoryDroidHookRunner mirroring GeminiHookRunner (line 501).
Key details:
exec.Command(getTestBinary(), "hooks", "factoryai-droid", hookName)GetSessionDir is a stub)os.Environ() and cmd.Dir = r.RepoDirSimulation methods:
SimulateUserPromptSubmit(sessionID) — input: {session_id, transcript_path, prompt}SimulateStop(sessionID, transcriptPath) — input: {session_id, transcript_path}SimulateSessionStart(sessionID) — input: {session_id, transcript_path}SimulateSessionEnd(sessionID, transcriptPath) — input: {session_id, transcript_path}SimulatePreTask(sessionID, transcriptPath, toolUseID) — input with tool_inputSimulatePostTask(input PostTaskInput) — input with tool_response.agentIdSimulateUserPromptSubmitWithOutput, SimulateSessionStartWithOutput — return HookOutputFactoryDroidSession struct + NewFactoryDroidSession() on TestEnv:
"droid-session-N".entire/tmp/<id>.jsonlCreateDroidTranscript(prompt, changes) — must generate Droid envelope JSONL, not Claude formatDroid transcript format (critical — ParseDroidTranscript requires type:"message" outer wrapper):
{"type":"message","id":"m1","message":{"role":"user","content":[{"type":"text","text":"Fix the bug"}]}}
{"type":"message","id":"m2","message":{"role":"assistant","content":[{"type":"text","text":"I'll fix it"},{"type":"tool_use","id":"toolu_1","name":"Write","input":{"file_path":"main.go","content":"..."}}]}}
{"type":"message","id":"m3","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_1","content":"Success"}]}}
Convenience methods on TestEnv:
SimulateFactoryDroid{UserPromptSubmit,Stop,SessionStart,SessionEnd,PreTask,PostTask}SimulateFactoryDroid{UserPromptSubmit,SessionStart}WithOutputagent_test.goAdd 4 test functions at the end. Import factoryaidroid package.
TestFactoryAIDroidAgentDetection (not parallel — os.Chdir)agent.List() contains "factoryai-droid" (parallel).factory dir, os.Chdir, DetectPresence() → trueTestFactoryAIDroidHookInstallation (not parallel — os.Chdir)InstallHooks(false, false) returns 7; AreHooksInstalled() true; settings.json contains SessionStart, SessionEnd, Stop, UserPromptSubmit, PreToolUse, PostToolUse, PreCompact; permissions.deny has Read(./.entire/metadata/**)"go run" and "${FACTORY_PROJECT_DIR}""entire hooks factoryai-droid"TestFactoryAIDroidHelperMethods (parallel)FormatResumeCommand("abc123") == "droid --session-id abc123"TestFactoryAIDroidSessionStubs (parallel)setup_factoryai_hooks_test.goMirror setup_gemini_hooks_test.go. Build tag: //go:build integration.
TestSetupFactoryAIHooks_AddsAllRequiredHooksNewTestEnv, InitRepo, InitEntire("manual-commit"), initial commitRunCLIWithError("enable", "--agent", "factoryai-droid").factory/settings.json → verify all 7 hook types presentpermissions.deny contains metadata deny ruleTestSetupFactoryAIHooks_PreservesExistingSettings.factory/settings.json with customSetting and user Stop hookenable --agent factoryai-droidcustomSetting preserved, user Stop hook preserved, our hooks addedHelper: readFactorySettingsFile(t, env) FactorySettings
agent_strategy_test.goTestFactoryAIDroidAgentStrategyCompositionAllStrategies() manually (can't use RunForAllStrategies — it defaults agent to claude-code)NewTestEnv → InitRepo → InitEntireWithAgent(strat, "factoryai-droid") → initial commit → feature branchFactoryDroidSession with Droid-envelope transcriptUserPromptSubmit → StopGetRewindPoints() has >= 1 pointTestFactoryAIDroidSessionIDTransformationRewind(points[0].ID) succeedsNote: Since ReadSession is a stub, these tests only verify the hook-based flow (lifecycle dispatcher reads transcript via TranscriptAnalyzer interface). No transcript restoration test (that requires ReadSession/WriteSession).
mise run fmt && mise run lint && mise run test:ci
Integration tests specifically:
mise run test:integration
If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /Users/alisha/.REDACTED.jsonl
★ Insight ─────────────────────────────────────
This plan adds integration tests for Factory AI Droid, the third agent in the CLI. Integration tests here exercise the real compiled binary (not unit test mocks), validating hook installation, session lifecycle, and strategy composition through the actual CLI execution path. This is important because it catches issues that unit tests miss — like incorrect command routing, missing registrations, or broken JSONL parsing in the full binary context.
─────────────────────────────────────────────────
Let me start by reading the key files I'll need to modify and reference.
Now let me read the remaining reference files I need.
Now let me read the remaining files I need for context.
Now let me check how the Gemini hook runner interacts with hook lifecycle and what InitEntireWithAgent uses for the agent name.
Now I have a thorough understanding of the codebase. Let me create tasks to track progress and start implementing.
★ Insight ─────────────────────────────────────
The integration tests use a compiled test binary pattern: TestMain builds the CLI once, then all tests invoke it as a subprocess. This means hook runners don't call Go functions directly — they shell out to getTestBinary() hooks <agent> <hook-name> with JSON on stdin. This is what makes these "integration" tests rather than unit tests — they exercise the full binary path including command routing and agent dispatch.
─────────────────────────────────────────────────
Let me start with Step 1 — adding the FactoryDroidHookRunner and related helpers to hooks.go.
Now Step 2 — add Factory AI Droid tests to agent_test.go.
★ Insight ─────────────────────────────────────
The detection tests (TestFactoryAIDroidAgentDetection) can't use t.Parallel() at the top level because DetectPresence() internally calls paths.RepoRoot() which depends on the working directory. The test needs os.Chdir() which is process-global state. However, the "agent is registered" subtest doesn't use os.Chdir, so it CAN be parallel. This selective parallelism is a deliberate pattern seen in the existing Claude and Gemini tests.
─────────────────────────────────────────────────
Now add the four test functions at the end of agent_test.go. Let me read the end of the file to find the right insertion point.
Now Step 3 — create setup_factoryai_hooks_test.go.
★ Insight ─────────────────────────────────────
The setup_*_hooks_test.go files are "smoke tests" that exercise the full CLI binary path: they run entire enable --agent factoryai-droid as a subprocess, then verify the settings file was written correctly. This is different from the TestFactoryAIDroidHookInstallation tests above which call InstallHooks() directly on the Go struct. The smoke tests catch issues like missing cobra command registration, incorrect agent flag routing, or broken serialization.
─────────────────────────────────────────────────
Actually, let me simplify that — I should just use strings.Contains instead of writing custom helpers.
Now Step 4 — add strategy composition tests to agent_strategy_test.go.
★ Insight ─────────────────────────────────────
The strategy composition tests can't use RunForAllStrategies because that helper hardcodes the Claude Code agent (it uses NewFeatureBranchEnv which defaults to claude-code). Instead, we iterate AllStrategies() manually and use InitEntireWithAgent(strat, "factoryai-droid") to set up the Droid agent. This is important because the lifecycle dispatcher (which reads transcripts and creates checkpoints) uses the agent from .entire/settings.json to determine which TranscriptAnalyzer to use for parsing.
─────────────────────────────────────────────────
Now add the strategy composition tests at the end of the file.
Now let me run the checks. First, let me check if the unused import of factoryaidroid in agent_test.go is actually needed — I imported it but I need to verify it's used (the tests reference factoryaidroid.FactorySettingsFileName).
Looking at the code again, agent_test.go uses factoryaidroid.FactorySettingsFileName in the hook installation tests. Good.
Let me also verify that the _ "factoryaidroid" blank import in agent_strategy_test.go is needed. Since agent.Get("factoryai-droid") requires the agent to be registered via its init() function, the blank import ensures the agent is available. But let me check if it's already imported transitively.
Good. Now let me check if the TestMain already imports the factoryaidroid package via the setup binary.
Good — the test builds the full CLI binary which will include the factoryaidroid agent via its init() registration. The blank import in agent_strategy_test.go is needed because the agent registration happens in the test process for agent.Get() calls, but the binary has its own registration. Let me check if the existing test files have similar blank imports for Gemini.
Now let me run format and lint to check for issues.
Format and lint pass cleanly. Now let me run the full test suite.
The tests are failing because the rewind --list command outputs a log line before the JSON when it encounters the "agent" field in settings. Let me investigate the settings loading.
I see — the EntireSettings struct doesn't have an "agent" field, so DisallowUnknownFields() rejects it. Let me find where the agent setting is actually read/stored.
Let me check how the enable command stores the agent preference — the "agent" key in settings.json might not be in the EntireSettings struct.
The issue is that InitEntireWithAgent writes "agent": "factoryai-droid" to .entire/settings.json, but EntireSettings doesn't have that field. The settings loader uses DisallowUnknownFields() and rejects it. Let me check how the lifecycle dispatcher determines the agent.
Now I see the issue. GetStrategy() (line 70) is called by the rewind command. It loads settings, and when settings parsing fails due to the unknown "agent" field, it logs a warning and falls back to the default strategy (manual-commit). The log line gets mixed with the JSON output.
The fix: don't write "agent" to .entire/settings.json in the test helper since the EntireSettings struct doesn't recognize it. The agent is determined by the hook command routing (entire hooks factoryai-droid ...), not by settings. I should just use InitEntire(strat) without agent, since the hooks are called through the FactoryDroidHookRunner which already routes to entire hooks factoryai-droid.
Now the blank import of factoryaidroid isn't needed since we're not using any symbols from it. Let me also remove it since the agent is already registered via the import in agent_test.go (same package).
Now let me run the integration tests specifically to verify the fix, rather than the full suite (which has an unrelated timeout).
All integration tests pass. Now let me also run the unit tests to make sure we haven't broken anything.
[Request interrupted by user for tool use]
[Request interrupted by user]
/exit exit
No response requested.
commit-commands:commit /commit-commands:commit
Untracked files: (use "git add ..." to include in what will be committed) .claude/worktrees/ implement-agent-guide.md test-files/
Preview (first 2KB): diff --git a/cmd/entire/cli/agent/factoryaidroid/factoryaidroid_test.go b/cmd/entire/cli/agent/factoryaidroid/factoryaidroid_test.go new file mode 100644 index 00000000..539f605a --- /dev/null +++ b/cmd/entire/cli/agent/factoryaidroid/factoryaidroid_test.go @@ -0,0 +1,342 @@ +package factoryaidroid + +import (
+func TestNewFactoryAIDroidAgent(t *testing.T) {
t.Fatal("NewFactoryAIDroidAgent() returned nil")
t.Fatal("NewFactoryAIDroidAgent() didn't return *FactoryAIDroidAgent")
+func TestName(t *testing.T) {
t.Errorf("Name() = %q, want %q", name, agent.AgentNameFactoryAIDroid)
+func TestType(t *testing.T) {
t.Errorf("Type() = %q, want %q", tp, agent.AgentTypeFactoryAIDroid)
Commit created successfully: c83248a7 — "Add Factory AI Droid integration tests"
5 files changed, 1319 insertions across:
factoryaidroid packageentire enable --agent factoryai-droidhooks.goNot yet included in a published release.
+func TestDescription(t *testing.T) {
t.Error("Description() returned empty string")
+func TestProtectedDirs(t *testing.T) {
t.Errorf("ProtectedDirs() = %v, want [.factory]", dirs)
+func TestGetHookConfigPath(t *testing.T) {
t.Errorf("GetHookConfigPath() = %q, want .factory/settings.json", path)
+func TestSupportsHooks(t *testing.T) {
t.Error("SupportsHooks() = false, want true")
Based on the above changes, create a single git commit.
You have the capability to call multiple tools in a single response. Stage and create the commit using a single message. Do not use any other tools or do anything else. Do not send any other text or messages besides these tool calls.