Merge pull request #1713 from entireio/fix/1123-local-settings-hooks · Entire
Merge pull request #1713 from entireio/fix/1123-local-settings-hooks
888c11d→main·
gtrrz-victor·2d ago·2 files·+80 added/-0 removed
fix(settings): recognize local-only setup so hooks run after enable --local
Changes
2
cmd/entire/cli
integration_test
Msetup_cmd_test.go+52
settings
Msettings_test.go+28
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")
// 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")
}
}
Mcmd/entire/cli/integration_test/setup_cmd_test.go+52
9 unmodified lines
10
11
12
13
14
15
16
1314 unmodified lines
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
9 unmodified lines
"testing"
"time"
"github.com/entireio/cli/cmd/entire/cli/paths"
"github.com/entireio/cli/cmd/entire/cli/session"
"github.com/entireio/cli/cmd/entire/cli/testutil"
)
1314 unmodified lines
t.Error("merge(nil, emptyNonNil) should return a non-nil empty map, got nil")
}
// Regression: `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")
}
}
Mcmd/entire/cli/settings/settings_test.go+28