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
2 changes: 2 additions & 0 deletions pkgs/mcpx/internal/e2e/effect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var implementedEffectProbes = map[string]string{
"plugin.toolTiming": "TestPluginToolTimingRecordsToolCallsFromTheEnvironment",
"plugin.remember": "TestPluginRememberScopePersistsTheDaemonChoiceFromTheEnvironment",
"plugin.headless": "TestPluginHeadlessSuppressesToastsFromTheEnvironment",
"plugin.instructions": "TestPluginInstructionsAppendsTheContextParagraphFromTheEnvironment",
"paths.state": "TestStateDirectoryIsReachableAsASetting",
"paths.configFile": "TestPathsConfigFileChangesWhichConfigLoads",
"paths.scripts": "TestPathsScriptsFindsRecipesThatLiveOnlyThere",
Expand Down Expand Up @@ -308,6 +309,7 @@ var effectProbeFuncs = map[string]func(*testing.T){
"TestPluginToolTimingRecordsToolCallsFromTheEnvironment": TestPluginToolTimingRecordsToolCallsFromTheEnvironment,
"TestPluginRememberScopePersistsTheDaemonChoiceFromTheEnvironment": TestPluginRememberScopePersistsTheDaemonChoiceFromTheEnvironment,
"TestPluginHeadlessSuppressesToastsFromTheEnvironment": TestPluginHeadlessSuppressesToastsFromTheEnvironment,
"TestPluginInstructionsAppendsTheContextParagraphFromTheEnvironment": TestPluginInstructionsAppendsTheContextParagraphFromTheEnvironment,
"TestPoolDefaultsAreReachableFromTheEnvironment": TestPoolDefaultsAreReachableFromTheEnvironment,
"TestRegistryLimitReachesTheCLI": TestRegistryLimitReachesTheCLI,
"TestRegistryPageSizeChangesWhatTheCLIAsksFor": TestRegistryPageSizeChangesWhatTheCLIAsksFor,
Expand Down
1 change: 0 additions & 1 deletion pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ setting daemon.tsnetUpTimeout no integration-test exercise yet; burn-down #8468
setting http.streamBufferInit allocation-capacity hint only; output and line ceiling are unchanged, so allocation size has no stable e2e behavior oracle
setting protoTasks.cancelGrace no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test
setting plugin.disabledTools no integration-test exercise yet; burn-down #8472 (settings plugin family); needs an EffectProbes entry + e2e test
setting plugin.instructions no integration-test exercise yet; burn-down #8472 (settings plugin family); needs an EffectProbes entry + e2e test
setting embeddings.wasmPath embeddings backend: needs a compiled wasm model fixture the harness does not provide; no embed-exporting model ships with the repo
39 changes: 39 additions & 0 deletions pkgs/mcpx/internal/e2e/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,42 @@ func TestPluginHeadlessSuppressesToastsFromTheEnvironment(t *testing.T) {
t.Fatalf("the plugin.headless probe did not report a clean run:\n%s", out)
}
}

// TestPluginInstructionsAppendsTheContextParagraphFromTheEnvironment
// is the effect probe for plugin.instructions (#8472; the effect
// guard is #1971).
//
// The setting's whole effect lives in the opencode plugin host: it
// is the opt-in that adds mcpx's session-context paragraph to the
// model's system prompt — the v2 setup's session "context" hook
// calls appendContextOnce only when the resolved option is on
// (plugin/opencode/v2/index.ts), and the paragraph is paid help, so
// it stays off unless asked for. No Go caller produces the system
// prompt, so the probe drives the host the way the plugin suite
// does — bun, the real setupMcpxV2 with a stub context — and the
// bun cases in plugin/opencode/v2/instructions.test.ts assert the
// observable with/without difference: unset and explicit false
// append nothing; true appends the paragraph, once per system
// array; another truthy spelling appends it too; and the host
// option beats the environment in both directions. The cases set
// the setting the way a user would — MCPX_PLUGIN_INSTRUCTIONS
// through resolveOptions, or the host option. A run that skipped
// the cases is a run that did not check what this probe exists to
// check, so skips fail it, as in
// TestPluginHeadlessSuppressesToastsFromTheEnvironment.
func TestPluginInstructionsAppendsTheContextParagraphFromTheEnvironment(t *testing.T) {
bun := testsupport.RequireBinary(t, "bun")
recordSettingProbes(t)
cmd := exec.Command(bun, "test", "plugin/opencode/v2/instructions.test.ts")
cmd.Dir = repoRoot(t)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("bun test plugin/opencode/v2/instructions.test.ts: %v\n%s", err, out)
}
if strings.Contains(string(out), " skip") && !strings.Contains(string(out), " 0 skip") {
t.Fatalf("the plugin.instructions probe cases were skipped:\n%s", out)
}
if !strings.Contains(string(out), " 0 fail") {
t.Fatalf("the plugin.instructions probe did not report a clean run:\n%s", out)
}
}
4 changes: 2 additions & 2 deletions pkgs/mcpx/internal/settings/effect.go

Large diffs are not rendered by default.

137 changes: 137 additions & 0 deletions pkgs/mcpx/plugin/opencode/v2/instructions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* plugin.instructions, observed through the real v2 setup (#8472).
*
* The instructions setting — MCPX_PLUGIN_INSTRUCTIONS, off by
* default — is the opt-in that adds mcpx's session-context
* paragraph to the model's system prompt: setup's session
* "context" hook calls appendContextOnce when the resolved option
* is on (v2/index.ts), and the paragraph rides every request once
* present, so it is paid help and stays off unless asked for.
* resolveOptions reads it host option first, then the environment
* (truthy spellings: 1 / true / yes / on), then the default false.
* The v1 system transform is covered by
* plugin/opencode/mcpx/instructions.test.ts; this suite covers the
* v2 path the same setting now drives. The setting lives entirely
* inside this plugin host, so this suite is where its effect can
* be observed: setup is the real setupMcpxV2 with the stub context
* shape tool-filter.test.ts uses (Map-backed storage, a captured
* context hook, a no-op tool domain), and the cases fire the hook
* with plain inputs and read the system array the host would send.
* The Go effect probe for the setting
* (TestPluginInstructionsAppendsTheContextParagraphFromTheEnvironment
* in internal/e2e) runs this file. The cases set the setting the
* way a user would — MCPX_PLUGIN_INSTRUCTIONS through
* resolveOptions, or the host option — and assert the observable
* with/without differences the effect guard (#1971) demands:
* unset and explicit false append nothing; true appends the
* paragraph, once per system array no matter how often the hook
* fires; another truthy spelling appends it too; and the host
* option beats the environment in both directions.
*
* bun test plugin/opencode/v2/instructions.test.ts
*/
import { afterEach, describe, expect, test } from "bun:test";
import { CONTEXT_MARKER, CONTEXT_PARAGRAPH } from "./context.ts";
import { setupMcpxV2, type McpxV2Context } from "./index.ts";
import type { Options } from "./options.ts";
import type { StorageLike } from "./remember.ts";

const ENV_KEY = "MCPX_PLUGIN_INSTRUCTIONS";
const savedEnv = process.env[ENV_KEY];
afterEach(() => {
if (savedEnv === undefined) delete process.env[ENV_KEY];
else process.env[ENV_KEY] = savedEnv;
});

const stubStorage = (): StorageLike => {
const map = new Map<string, unknown>();
return {
get: async (k) => map.get(k),
set: async (k, v) => void map.set(k, v),
remove: async (k) => void map.delete(k),
};
};

type ContextInput = {
sessionID: string;
system: unknown[];
tools: Record<string, unknown>;
};

// Setup exactly as the host performs it (v2/index.ts): the stub
// context captures the registered "context" hook so the test can
// fire it with the plain input objects the host would build.
const stubCtx = (storage: StorageLike) => {
let contextFn: ((input: never) => void) | undefined;
const ctx: McpxV2Context = {
storage,
directory: "/work",
session: {
hook: (_name, fn) => {
contextFn = fn as (input: never) => void;
},
},
tool: {
hook: () => {},
transform: async () => ({}),
},
};
const fire = (input: ContextInput): ContextInput => {
contextFn!(input as never);
return input;
};
const fireNew = (sessionID: string): ContextInput =>
fire({ sessionID, system: [], tools: {} });
return { ctx, fire, fireNew };
};

const setupWith = async (env: string | undefined, rawOptions?: Options) => {
if (env === undefined) delete process.env[ENV_KEY];
else process.env[ENV_KEY] = env;
const { ctx, fire, fireNew } = stubCtx(stubStorage());
await setupMcpxV2(ctx, rawOptions);
return { fire, fireNew };
};

const texts = (input: ContextInput): string[] =>
input.system.map((part) =>
typeof part === "string" ? part : ((part as { text?: string }).text ?? ""),
);

describe("plugin.instructions (MCPX_PLUGIN_INSTRUCTIONS)", () => {
test("unset: the context hook appends nothing", async () => {
const { fireNew } = await setupWith(undefined);
const input = fireNew("s1");
expect(input.system).toEqual([]);
});

test("true: the paragraph is appended, once per system array", async () => {
const { fire, fireNew } = await setupWith("true");
const input = fireNew("s1");
expect(texts(input)).toEqual([CONTEXT_PARAGRAPH]);
expect(texts(input)[0]).toContain(CONTEXT_MARKER);
// The hook fires per turn over the same system array; the
// marker check keeps the append to exactly one paragraph.
fire(input);
expect(texts(input)).toEqual([CONTEXT_PARAGRAPH]);
// A different session's fresh array gets its own copy.
expect(texts(fireNew("s2"))).toEqual([CONTEXT_PARAGRAPH]);
});

test("explicit false: nothing is appended, exactly like unset", async () => {
const { fireNew } = await setupWith("false");
expect(fireNew("s1").system).toEqual([]);
});

test("a different truthy value appends the paragraph — the setting alone decides", async () => {
const { fireNew } = await setupWith("1");
expect(texts(fireNew("s1"))).toEqual([CONTEXT_PARAGRAPH]);
});

test("the host option beats the environment in both directions", async () => {
const on = await setupWith(undefined, { instructions: true });
expect(texts(on.fireNew("s1"))).toEqual([CONTEXT_PARAGRAPH]);
const off = await setupWith("true", { instructions: false });
expect(off.fireNew("s1").system).toEqual([]);
});
});