Skip to content

Commit e2f6f0a

Browse files
authored
Merge pull request #2870 from fullsend-ai/fix-2869-validation-schema-env
fix(#2869): inject FULLSEND_OUTPUT_SCHEMA into validation script env
2 parents d0771f7 + 1c2514e commit e2f6f0a

2 files changed

Lines changed: 56 additions & 6 deletions

File tree

internal/cli/run.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,12 +1106,7 @@ func runAgent(ctx context.Context, agentName, fullsendDir, outputBase, targetRep
11061106
printer.StepStart("Running validation: " + h.ValidationLoop.Script)
11071107
valCmd := exec.Command(h.ValidationLoop.Script)
11081108
valCmd.Dir = iterDir
1109-
valCmd.Env = append(os.Environ(),
1110-
append(envToList(h.RunnerEnv),
1111-
fmt.Sprintf("TARGET_REPO_DIR=%s", hostRepositoryDir),
1112-
fmt.Sprintf("FULLSEND_RUN_DIR=%s", runDir),
1113-
)...,
1114-
)
1109+
valCmd.Env = append(os.Environ(), validationEnv(h, hostRepositoryDir, runDir)...)
11151110
valOut, valErr := valCmd.CombinedOutput()
11161111

11171112
if valErr == nil {
@@ -1698,6 +1693,21 @@ func childScriptEnv(runnerEnv map[string]string, traceparent string) []string {
16981693
return env
16991694
}
17001695

1696+
// validationEnv builds the extra environment entries for the validation
1697+
// script. It includes RunnerEnv, TARGET_REPO_DIR, FULLSEND_RUN_DIR, and —
1698+
// when the harness specifies a validation_loop.schema — FULLSEND_OUTPUT_SCHEMA
1699+
// pointing to the host-side cached schema path.
1700+
func validationEnv(h *harness.Harness, hostRepoDir, runDir string) []string {
1701+
env := append(envToList(h.RunnerEnv),
1702+
fmt.Sprintf("TARGET_REPO_DIR=%s", hostRepoDir),
1703+
fmt.Sprintf("FULLSEND_RUN_DIR=%s", runDir),
1704+
)
1705+
if h.ValidationLoop != nil && h.ValidationLoop.Schema != "" {
1706+
env = append(env, fmt.Sprintf("FULLSEND_OUTPUT_SCHEMA=%s", h.ValidationLoop.Schema))
1707+
}
1708+
return env
1709+
}
1710+
17011711
func envToList(env map[string]string) []string {
17021712
keys := make([]string, 0, len(env))
17031713
for k := range env {

internal/cli/run_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,46 @@ func TestValidationFailMessage_TrimsOutput(t *testing.T) {
13931393
assert.Equal(t, "some output", msg)
13941394
}
13951395

1396+
func TestValidationEnv_IncludesSchemaWhenSet(t *testing.T) {
1397+
h := &harness.Harness{
1398+
RunnerEnv: map[string]string{"FOO": "bar"},
1399+
ValidationLoop: &harness.ValidationLoop{
1400+
Script: "scripts/validate.sh",
1401+
Schema: "/tmp/test-schema.json",
1402+
},
1403+
}
1404+
env := validationEnv(h, "/repo", "/run")
1405+
assert.Contains(t, env, "FULLSEND_OUTPUT_SCHEMA=/tmp/test-schema.json")
1406+
assert.Contains(t, env, "TARGET_REPO_DIR=/repo")
1407+
assert.Contains(t, env, "FULLSEND_RUN_DIR=/run")
1408+
assert.Contains(t, env, "FOO=bar")
1409+
}
1410+
1411+
func TestValidationEnv_OmitsSchemaWhenEmpty(t *testing.T) {
1412+
h := &harness.Harness{
1413+
RunnerEnv: map[string]string{"FOO": "bar"},
1414+
ValidationLoop: &harness.ValidationLoop{
1415+
Script: "scripts/validate.sh",
1416+
},
1417+
}
1418+
env := validationEnv(h, "/repo", "/run")
1419+
for _, e := range env {
1420+
assert.False(t, strings.HasPrefix(e, "FULLSEND_OUTPUT_SCHEMA="),
1421+
"FULLSEND_OUTPUT_SCHEMA should not be set when Schema is empty")
1422+
}
1423+
}
1424+
1425+
func TestValidationEnv_OmitsSchemaWhenNoValidationLoop(t *testing.T) {
1426+
h := &harness.Harness{
1427+
RunnerEnv: map[string]string{"FOO": "bar"},
1428+
}
1429+
env := validationEnv(h, "/repo", "/run")
1430+
for _, e := range env {
1431+
assert.False(t, strings.HasPrefix(e, "FULLSEND_OUTPUT_SCHEMA="),
1432+
"FULLSEND_OUTPUT_SCHEMA should not be set when ValidationLoop is nil")
1433+
}
1434+
}
1435+
13961436
func TestOpenTeeReader_EmptyPath(t *testing.T) {
13971437
src := strings.NewReader("hello")
13981438
printer := ui.New(io.Discard)

0 commit comments

Comments
 (0)