test(settings): fold local-enable tests into shared files, drop issue-numbered names · Entire

test(settings): fold local-enable tests into shared files, drop issue-numbered names

c7ff84e→main·

suhaanthayyil·3d ago·5 files·+82 added/-98 removed

Nina's review on #1713: standalone issue-numbered test files proliferate one-offs where shared setup already exists. Move TestIsSetUpAndEnabled_LocalSettingsOnly into settings_test.go (reusing its existing testutil.InitRepo pattern) and the e2e hook-flow reproduction into integration_test/setup_cmd_test.go, which already owns the enable/disable/hooks-gating test suite. Also strip the remaining "#1123" breadcrumb from the settings.go doc comment. All assertions are unchanged; only file placement and naming moved.

Changes

5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

//go:build integration

package integration

import (
    "os"
    "path/filepath"
    "testing"
)

// TestIssue1123_LocalOnlyEnable_HooksSaveCheckpoint is a full-flow reproduction
// of #1123: `entire enable --local` writes only .entire/settings.local.json, and
// the hooks (gated on settings.IsSetUpAndEnabled) silently no-op'd because that
// check only looked at settings.json — so a commit produced no checkpoint.
//
// This drives the real hook binary end-to-end: a session, a user-prompt-submit,
// a file change, a stop, and a commit — then asserts the commit actually carries
// an Entire-Checkpoint trailer (i.e. the hooks ran and a checkpoint was saved).
func TestIssue1123_LocalOnlyEnable_HooksSaveCheckpoint(t *testing.T) {
    t.Parallel()
    env := NewTestEnv(t)
    defer env.Cleanup()

env.InitRepo()
    env.WriteFile("README.md", "# Test")
    env.GitAdd("README.md")
    env.GitCommit("Initial commit")
    env.GitCheckoutNewBranch("feature/local-only")

// Simulate `entire enable --local`: only settings.local.json exists.
    entireDir := filepath.Join(env.RepoDir, ".entire")
    if err := os.MkdirAll(filepath.Join(entireDir, "tmp"), 0o755); err != nil {
        t.Fatalf("mkdir .entire/tmp: %%v", err)
    }
    localSettings := `{"enabled":true,"local_dev":true,"strategy_options":{"filtered_fetches":true}}`
    if err := os.WriteFile(filepath.Join(entireDir, "settings.local.json"), []byte(localSettings), 0o644); err != nil {
        t.Fatalf("write settings.local.json: %%v", err)
    }
    if _, err := os.Stat(filepath.Join(entireDir, "settings.json")); err == nil {
        t.Fatal("precondition: settings.json must not exist for the enable --local scenario")
    }

session := env.NewSession()
    if err := env.SimulateUserPromptSubmitWithPrompt(session.ID, "Create a hello file"); err != nil {
        t.Fatalf("user-prompt-submit: %%v", err)
    }
    env.WriteFile("hello.txt", "hello")
    session.CreateTranscript("Create a hello file", []FileChange{{Path: "hello.txt", Content: "hello"}})
    if err := env.SimulateStop(session.ID, session.TranscriptPath); err != nil {
        t.Fatalf("stop: %%v", err)
    }
    env.GitCommitWithShadowHooksAsAgent("add hello", "hello.txt")

cpID := env.GetCheckpointIDFromCommitMessage(env.GetHeadHash())
    if cpID == "" {
        t.Fatal("commit has no Entire-Checkpoint trailer — hooks silently no-op'd with only settings.local.json (#1123)")
    }
}

Dcmd/entire/cli/integration_test/issue_1123_local_enable_e2e_test.go-58

214 unmodified lines

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

214 unmodified lines

t.Errorf("Expected status to show 'manual-commit', got: %%s", stdout)
}

// TestHooksRunAfterLocalOnlyEnable is a full-flow reproduction of the
// `entire enable --local` regression: only .entire/settings.local.json
// exists, and the hooks (gated on settings.IsSetUpAndEnabled) silently
// no-op'd because that check only looked at settings.json — so a commit
// produced no checkpoint.
//
// This drives the real hook binary end-to-end: a session, a
// user-prompt-submit, a file change, a stop, and a commit — then asserts the
// commit actually carries an Entire-Checkpoint trailer (i.e. the hooks ran
// and a checkpoint was saved). Complements TestHooksSilentWhenDisabled above,
// which covers the opposite case.
func TestHooksRunAfterLocalOnlyEnable(t *testing.T) {
    t.Parallel()
    env := NewTestEnv(t)
    defer env.Cleanup()

env.InitRepo()
    env.WriteFile("README.md", "# Test")
    env.GitAdd("README.md")
    env.GitCommit("Initial commit")
    env.GitCheckoutNewBranch("feature/local-only")

cpID := env.GetCheckpointIDFromCommitMessage(env.GetHeadHash())
    if cpID == "" {
        t.Fatal("commit has no Entire-Checkpoint trailer — hooks silently no-op'd with only settings.local.json")
    }
}

Mcmd/entire/cli/integration_test/setup_cmd_test.go+52

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

package settings

import (
    "context"
    "os"
    "path/filepath"
    "testing"

"github.com/entireio/cli/cmd/entire/cli/paths"
    "github.com/entireio/cli/cmd/entire/cli/testutil"
)

// Regression for #1123: `entire enable --local` writes only
// .entire/settings.local.json, but the hook activation check
// (IsSetUpAndEnabled) only looked for .entire/settings.json, so hooks silently
// no-op'd. It must recognize a local-only setup.
func TestIsSetUpAndEnabled_LocalSettingsOnly(t *testing.T) {
    root := t.TempDir()
    testutil.InitRepo(t, root)
    entireDir := filepath.Join(root, ".entire")
    if err := os.MkdirAll(entireDir, 0o755); err != nil {
        t.Fatal(err)
    }
    // Only the local settings file exists (no settings.json), enabled.
    if err := os.WriteFile(filepath.Join(entireDir, "settings.local.json"), []byte(`{"enabled":true}`), 0o644); err != nil {
        t.Fatal(err)
    }

t.Chdir(root)
    paths.ClearWorktreeRootCache()

if IsSetUp(context.Background()) {
        t.Fatal("precondition: IsSetUp should be false with only settings.local.json")
    }
    if !IsSetUpAndEnabled(context.Background()) {
        t.Fatal("IsSetUpAndEnabled should be true when only settings.local.json exists and is enabled (#1123)")
    }
}

Dcmd/entire/cli/settings/local_enabled_test.go-38

1312 unmodified lines

1313
1314
1315
1316
1317
1316
1317
1318
1319
1320

1312 unmodified lines

// Setup is detected from either .entire/settings.json or
// .entire/settings.local.json (IsSetUpAny), because `entire enable --local`
// writes only the local file; checking settings.json alone made hooks silently
// no-op for local-only setups (#1123). Load() merges both files, so the
enabled value is correct regardless of which file is present.
// no-op for local-only setups. Load() merges both files, so the enabled value
// is correct regardless of which file is present.
// Use this for hooks that should be no-ops when Entire is not active.
func IsSetUpAndEnabled(ctx context.Context) bool {
    if !IsSetUpAny(ctx) {