Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
93 changes: 93 additions & 0 deletions pkgs/mcpx/internal/e2e/effect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ var implementedEffectProbes = map[string]string{
"protoTasks.maxPerRequestor": "TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment",
"protoTasks.perMinute": "TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment",
"events.history": "TestEventsHistoryBoundsTheReplay",
"prompt.autonomy": "TestPromptAutonomyRunsTheMatchedRecipeFromTheEnvironment",
"hooks.autonomy": "TestHooksAutonomySkipsAConfiguredHookFromTheEnvironment",
"repair.autonomy": "TestRepairAutonomyOffDropsTheDiagnosticsFromTheEnvironment",
"policy.write": "TestPolicyWriteDeniesAnUnannotatedCallFromTheEnvironment",
"elicit.confirmDestructive": "TestElicitConfirmDestructiveGatesADestructiveCallFromTheEnvironment",
"autonomy.max": "TestAutonomyMaxClampsARecipeRunFromTheEnvironment",
Expand Down Expand Up @@ -259,6 +262,9 @@ var effectProbeFuncs = map[string]func(*testing.T){
"TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment": TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment,
"TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment": TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment,
"TestEventsHistoryBoundsTheReplay": TestEventsHistoryBoundsTheReplay,
"TestPromptAutonomyRunsTheMatchedRecipeFromTheEnvironment": TestPromptAutonomyRunsTheMatchedRecipeFromTheEnvironment,
"TestHooksAutonomySkipsAConfiguredHookFromTheEnvironment": TestHooksAutonomySkipsAConfiguredHookFromTheEnvironment,
"TestRepairAutonomyOffDropsTheDiagnosticsFromTheEnvironment": TestRepairAutonomyOffDropsTheDiagnosticsFromTheEnvironment,
"TestPolicyWriteDeniesAnUnannotatedCallFromTheEnvironment": TestPolicyWriteDeniesAnUnannotatedCallFromTheEnvironment,
"TestElicitConfirmDestructiveGatesADestructiveCallFromTheEnvironment": TestElicitConfirmDestructiveGatesADestructiveCallFromTheEnvironment,
"TestAutonomyMaxClampsARecipeRunFromTheEnvironment": TestAutonomyMaxClampsARecipeRunFromTheEnvironment,
Expand Down Expand Up @@ -3097,6 +3103,93 @@ func TestAutonomyMaxClampsARecipeRunFromTheEnvironment(t *testing.T) {
}
}

// TestPromptAutonomyRunsTheMatchedRecipeFromTheEnvironment is the effect
// probe for prompt.autonomy. A prompt that matches a recipe leaving a
// file behind proposes the script by default (propose): the source comes
// back and nothing runs. With prompt.autonomy=run the same prompt runs
// the recipe and the file appears.
func TestPromptAutonomyRunsTheMatchedRecipeFromTheEnvironment(t *testing.T) {
prompt := func(extra ...string) (string, bool) {
e := newEnv(t, oneServer)
writeRecipe(t, e, "mark", markRecipe)
e.setenv(extra...)
mark := filepath.Join(e.dir, "mark.out")
out := e.run("prompt", "--set", "path="+mark, "leave a mark on the filesystem")
_, err := os.Stat(mark)
return out, err == nil
}
out, marked := prompt()
if marked || !strings.Contains(out, "writeFileSync") {
t.Fatalf("oracle: by default the prompt should propose the recipe's source without running it (marked %v):\n%s", marked, out)
}
if out, marked := prompt("MCPX_PROMPT_AUTONOMY=run"); !marked || !strings.Contains(out, "marked") {
t.Fatalf("with prompt.autonomy=run the recipe should run and leave its mark (marked %v):\n%s", marked, out)
}
}

// TestHooksAutonomySkipsAConfiguredHookFromTheEnvironment is the effect
// probe for hooks.autonomy. A hook from the environment is code the
// command did not send. At the default (run) it runs after the body;
// with hooks.autonomy=propose it is skipped and stderr says so.
func TestHooksAutonomySkipsAConfiguredHookFromTheEnvironment(t *testing.T) {
hook := `MCPX_SCRIPT_ON_SUCCESS=console.log("configured-hook")`
def := newEnv(t, oneServer)
def.setenv(hook)
if out := def.run("exec", `console.log("body")`); !strings.Contains(out, "configured-hook") {
t.Fatalf("oracle: at the default hooks.autonomy the configured hook should run:\n%s", out)
}
e := newEnv(t, oneServer)
e.setenv(hook, "MCPX_HOOKS_AUTONOMY=propose")
out, errOut, err := e.split("exec", `console.log("body")`)
if err != nil {
t.Fatalf("%v\n%s\n%s", err, out, errOut)
}
if strings.Contains(out, "configured-hook") || !strings.Contains(out, "body") {
t.Fatalf("with hooks.autonomy=propose the body should run and the hook should not:\n%s", out)
}
if !strings.Contains(errOut, "hooks.autonomy is propose; not running the configured onSuccess hook") {
t.Fatalf("stderr should say the hook was skipped:\n%s", errOut)
}
}

// TestRepairAutonomyOffDropsTheDiagnosticsFromTheEnvironment is the
// effect probe for repair.autonomy. A server's schema gains a required
// argument, and a call made to the old shape is refused. At the default
// (advise) the refusal carries a diagnostic naming the missing argument;
// with repair.autonomy=off only the validator's own error comes back.
func TestRepairAutonomyOffDropsTheDiagnosticsFromTheEnvironment(t *testing.T) {
refused := func(extra ...string) callErrorDoc {
schema := filepath.Join(t.TempDir(), "schema")
mustWrite(t, schema, "v1")
e := newEnv(t, strings.ReplaceAll(schemaServer, "VERSIONFILE", schema))
e.setenv(extra...)
e.run("refresh")
mustWrite(t, schema, "v2")
e.run("refresh")
resp, err := e.socketClient(t).Post("http://mcpx/v1/call", "application/json",
strings.NewReader(`{"server":"demo","tool":"create_issue","args":{"title":"x"}}`))
if err != nil {
t.Fatal(err)
}
b, _ := io.ReadAll(resp.Body)
_ = resp.Body.Close()
var got callErrorDoc
if err := json.Unmarshal(b, &got); err != nil || resp.StatusCode != http.StatusBadGateway {
t.Fatalf("the old-shape call should be refused with 502: status %d: %v\n%s", resp.StatusCode, err, b)
}
if !strings.HasPrefix(got.Error, "Invalid params") {
t.Fatalf("the refusal's own error should come back:\n%s", b)
}
return got
}
if got := refused(); len(got.Diagnostics) == 0 {
t.Fatalf("oracle: at the default repair.autonomy the refusal should carry diagnostics: %+v", got)
}
if got := refused("MCPX_REPAIR_AUTONOMY=off"); len(got.Diagnostics) != 0 {
t.Fatalf("with repair.autonomy=off no diagnostics should be attached: %+v", got)
}
}

// TestDaemonAddressIsReachableFromTheEnvironment is the effect probe
// for daemon.address (#8468 chain 1). The exemption it replaced said
// a bind address is a network identity the harness cannot vary
Expand Down
3 changes: 0 additions & 3 deletions pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ setting model.profiles no integration-test exercise yet; burn-down #8471 (settin
setting model.provider no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting model.providers no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting model.timeout no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting prompt.autonomy no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting prompt.catalogBudget no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting prompt.maxTokens no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting prompt.runTimeout no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
Expand All @@ -98,8 +97,6 @@ setting autostart.idleExit no integration-test exercise yet; burn-down #8470 (se
setting autostart.pollInterval no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test
setting deps.autoInstall no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test
setting events.reconnect no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test
setting hooks.autonomy no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test
setting repair.autonomy no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test
setting retention.stickyWindow no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test
setting sampling.answerLocally no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test
setting search.semantic no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test
Expand Down
Loading