fix(agent): list all compose profiles and fail closed on unknown services (#7)

This commit is contained in:
2026-10-12 19:38:07 +02:00
parent 27c4200dda
commit c5dba96cf8
6 changed files with 85 additions and 15 deletions
+19 -3
View File
@@ -124,7 +124,20 @@ func TestComposeExecutor(t *testing.T) {
_, err := setup(fakeCompose{rw, []container.Summary{ct}}, &fakeDist{digest: d}, rec).Execute(context.Background(), job, io.Discard)
require.NoError(t, err)
require.Len(t, outr.cmds, 1)
assert.Equal(t, ranCmd{stack, []string{"compose", "-p", "slusk", "--project-directory", stack, "-f", filepath.Join(stack, "compose.yaml"), "config", "--format", "json"}}, outr.cmds[0])
assert.Equal(t, ranCmd{stack, []string{"compose", "-p", "slusk", "--project-directory", stack, "-f", filepath.Join(stack, "compose.yaml"), "--profile", "*", "config", "--format", "json"}}, outr.cmds[0])
})
t.Run("service missing from the config is refused", func(t *testing.T) {
t.Cleanup(cleanOverride)
rec := &recorder{}
e := setup(fakeCompose{rw, []container.Summary{ct}}, &fakeDist{digest: d}, rec)
outr.json = `{"services":{"db":{"image":"y"}}}`
dist := &fakeDist{digest: d}
e.resolve = NewResolver(dist, nil)
_, err := e.Execute(context.Background(), job, io.Discard)
assert.EqualError(t, err, "service web not found in compose config")
assert.Empty(t, rec.cmds)
assert.Empty(t, dist.refs, "nothing resolved")
assert.NoFileExists(t, overridePath)
})
t.Run("build check failure stops the job", func(t *testing.T) {
t.Cleanup(cleanOverride)
@@ -140,13 +153,16 @@ func TestComposeExecutor(t *testing.T) {
t.Cleanup(cleanOverride)
envFile := filepath.Join(stack, ".env.prod")
require.NoError(t, os.WriteFile(envFile, []byte("A=1\n"), 0o644))
t.Cleanup(func() { os.Remove(envFile); os.Remove(filepath.Join(stack, ".env.local")) })
envFile2 := filepath.Join(stack, ".env.local")
require.NoError(t, os.WriteFile(envFile2, []byte("B=2\n"), 0o644))
withEnv := container.Summary{Labels: map[string]string{
labelWorkingDir: stack, labelConfigFiles: filepath.Join(stack, "compose.yaml"), labelEnvFile: envFile,
labelWorkingDir: stack, labelConfigFiles: filepath.Join(stack, "compose.yaml"), labelEnvFile: envFile + "," + envFile2,
}}
rec := &recorder{}
_, err := setup(fakeCompose{rw, []container.Summary{withEnv}}, &fakeDist{digest: d}, rec).Execute(context.Background(), job, io.Discard)
require.NoError(t, err)
prefix := []string{"compose", "-p", "slusk", "--project-directory", stack, "--env-file", envFile}
prefix := []string{"compose", "-p", "slusk", "--project-directory", stack, "--env-file", envFile, "--env-file", envFile2}
require.Len(t, outr.cmds, 1)
assert.Equal(t, prefix, outr.cmds[0].args[:len(prefix)])
require.Len(t, rec.cmds, 2)