Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/entire/cli/agent/opencode/entire_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export const EntirePlugin: Plugin = async ({ directory }) => {
seenUserMessages.clear()
messageStore.clear()
currentModel = null
await callHook("session-start", {
session_id: session.id,
})
}
currentSessionID = session.id
await callHook("session-start", {
session_id: session.id,
})
break
}

Expand Down
40 changes: 40 additions & 0 deletions cmd/entire/cli/agent/opencode/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -101,6 +102,45 @@ func TestInstallHooks_LocalDev(t *testing.T) {
}
}

func TestInstallHooks_SessionStartIsGuardedBySessionSwitch(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
ag := &OpenCodeAgent{}

if _, err := ag.InstallHooks(context.Background(), false, false); err != nil {
t.Fatalf("install failed: %v", err)
}

pluginPath := filepath.Join(dir, ".opencode", "plugins", "entire.ts")
data, err := os.ReadFile(pluginPath)
if err != nil {
t.Fatalf("plugin file not created: %v", err)
}

content := string(data)
guard := "if (currentSessionID !== session.id) {"
hook := `await callHook("session-start", {`
currentSessionAssignment := "currentSessionID = session.id"

guardIdx := strings.Index(content, guard)
hookIdx := strings.Index(content, hook)
assignIdx := strings.Index(content, currentSessionAssignment)

if guardIdx == -1 {
t.Fatalf("plugin file missing guard %q", guard)
}
if hookIdx == -1 {
t.Fatalf("plugin file missing session-start hook call %q", hook)
}
if assignIdx == -1 {
t.Fatalf("plugin file missing current session assignment %q", currentSessionAssignment)
}
if !(guardIdx < hookIdx && hookIdx < assignIdx) {
t.Fatalf("expected guarded session-start call before session assignment, got guard=%s hook=%s assignment=%s",
strconv.Itoa(guardIdx), strconv.Itoa(hookIdx), strconv.Itoa(assignIdx))
}
}

func TestInstallHooks_ForceReinstall(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
Expand Down