{{ message }}
Repository navigation
fix: align MCP gateway schema and reference examples #70865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+295
−25
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
docs/adr/70865-compile-reference-doc-examples-as-regression-tests.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # ADR-70865: Expose sandbox.mcp.trusted-bots in the Schema and Compile Reference Doc Examples as Regression Tests | ||
|
|
||
| **Date**: 2026-10-21 | ||
| **Status**: Draft | ||
| **Deciders**: Not recorded; acceptance remains pending maintainer review. | ||
|
|
||
| --- | ||
|
|
||
| ### Context | ||
|
|
||
| The [MCP gateway reference](../src/content/docs/reference/mcp-gateway.md) and the workflow validation contract had diverged. The compiler already extracts `sandbox.mcp.trusted-bots` and emits `trustedBots` into the gateway configuration, but the closed `sandbox.mcp` object in the [canonical workflow schema](../../pkg/parser/schemas/main_workflow_schema.json) did not expose that property. The OIDC example also needed root-level `mcp-servers`, `id-token: write`, and an explicit network allowlist. These examples need to exercise the same validation and compilation path as workflow files, rather than remain unchecked YAML fragments. | ||
|
|
||
| Exposing the trusted-bot field also requires a bounded input contract. The generated configuration passes through a shell heredoc; JSON string encoding alone does not prevent shell expansion. Accepting arbitrary nonempty strings would therefore be insufficient. This ADR records the proposed contract and test strategy for [PR #70865](https://github.com/github/gh-aw/pull/70865), not maintainer approval or evidence of successful execution. | ||
|
|
||
| ### Decision | ||
|
|
||
| Expose `sandbox.mcp.trusted-bots` as an optional, nonempty array of validated literal GitHub-style identities, such as `github-actions[bot]`. Require ASCII letters, digits, hyphens, or underscores, optionally followed by `[bot]`, in both schema validation and the renderer. Reject malformed identities, whitespace-only entries, shell substitutions, and template expressions rather than trimming or evaluating them. Remove the unreachable camelCase extraction alias: frontmatter accepts only `trusted-bots`, while generated gateway JSON uses `trustedBots`. These additional identities are merged by the gateway with its built-in list; they neither remove nor override built-in identities. | ||
|
|
||
| Keep the two frontmatter examples as complete, titled `aw` blocks in the reference page. The [reference regression test](../../pkg/workflow/mcp_gateway_reference_test.go) extracts those exact blocks, compiles them with the real compiler, and checks generated lock-file substrings for trusted-bot configuration and OIDC configuration, permission, and environment forwarding. [Schema regression tests](../../pkg/parser/schema_trusted_bots_test.go) cover the input contract separately. This keeps published examples, schema validation, and compiler output connected without introducing a general documentation-test framework. | ||
|
|
||
| ### Alternatives Considered | ||
|
|
||
| #### Alternative 1: Fix only the documentation text and schema, without tests | ||
|
|
||
| This has the lowest immediate maintenance cost, but leaves no direct regression guard connecting the published examples to compiler behavior. | ||
|
|
||
| #### Alternative 2: Keep duplicate copies of the examples as fixture files under `pkg/` | ||
|
|
||
| Separate fixtures avoid parsing Markdown, but duplicate the examples and can pass while the published version breaks. Extracting the published blocks avoids that duplication. | ||
|
|
||
| #### Alternative 3: Remove `trusted-bots` from the docs instead of allowing it in the schema | ||
|
|
||
| Removal avoids expanding the schema but hides an existing compiler capability. A constrained schema entry makes the supported input explicit instead. | ||
|
|
||
| #### Alternative 4: Accept arbitrary nonempty identity strings | ||
|
|
||
| This matches the initial draft's broad string contract but permits values unsafe for the generated shell context. Strict literal identity validation is preferable to exposing arbitrary strings or treating JSON escaping as shell protection. | ||
|
|
||
| ### Consequences | ||
|
|
||
| #### Positive | ||
| - Valid literal bot identities have an explicit schema contract; invalid shapes and unsafe identity values are intended to fail before configuration generation. | ||
| - Compiling the published blocks provides a focused regression signal for schema or compiler changes affecting these examples. | ||
| - Complete workflow structure makes the examples less ambiguous. The OIDC server URL and audience remain placeholders requiring a real server and its trust configuration. | ||
|
|
||
| #### Negative | ||
| - The test depends on the exact fence string (`` ```aw wrap title=".github/workflows/<name>.md" ``) and the docs file path. Editing the docs layout or fence attributes can break the test even when behavior is unchanged. | ||
| - Unit tests now read docs content, which mixes documentation and Go test concerns. Other contributors may not expect this coupling. | ||
| - Strict validation intentionally rejects arbitrary strings previously accepted by extraction code, including values that are not literal bot identities. | ||
|
|
||
| #### Neutral | ||
| - The test asserts on substrings of the generated lock file, so changes to lock file formatting may require updating the expected strings. | ||
| - Coverage is limited to these two examples. Compilation does not verify live OIDC authentication, remote-server authorization, gateway identity merging at runtime, or other snippets. | ||
| - Test definitions and automated completion notices are not evidence that checks passed or changes were published. Validation results must be reported separately for the final revision. | ||
| - This decision does not add `tools.github.refusal-labels` or change concurrency behavior. | ||
|
|
||
| --- | ||
|
|
||
| *Draft retained pending maintainer acceptance; no decider or approval is inferred from automation.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| //go:build !integration | ||
|
|
||
| package parser | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSandboxMCPTrustedBotsSchema(t *testing.T) { | ||
| for _, test := range []struct { | ||
| name string | ||
| value any | ||
| wantErr bool | ||
| }{ | ||
| {"one bot", []any{"github-actions[bot]"}, false}, | ||
| {"multiple bots", []any{"github-actions[bot]", "copilot-swe-agent[bot]"}, false}, | ||
| {"login without suffix", []any{"My-Bot_123"}, false}, | ||
| {"empty list", []any{}, true}, | ||
| {"empty identity", []any{""}, true}, | ||
| {"command substitution", []any{"$(id)"}, true}, | ||
| {"backtick substitution", []any{"`id`"}, true}, | ||
| {"variable expansion", []any{"${HOME}"}, true}, | ||
| {"workflow expression", []any{"${{ github.actor }}"}, true}, | ||
| {"whitespace", []any{"my bot"}, true}, | ||
| {"trailing newline", []any{"github-actions[bot]\n"}, true}, | ||
| {"quote", []any{`my"bot`}, true}, | ||
| {"backslash", []any{`my\bot`}, true}, | ||
| {"non-ASCII identity", []any{"böt"}, true}, | ||
| {"invalid suffix", []any{"my-bot[other]"}, true}, | ||
| {"mixed types", []any{"github-actions[bot]", 42}, true}, | ||
| {"scalar", "github-actions[bot]", true}, | ||
| {"null", nil, true}, | ||
| } { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| err := ValidateMainWorkflowFrontmatterWithSchemaAndLocation(map[string]any{ | ||
| "on": "workflow_dispatch", | ||
| "sandbox": map[string]any{ | ||
| "mcp": map[string]any{"trusted-bots": test.value}, | ||
| }, | ||
| }, "trusted-bots.md") | ||
| if test.wantErr { | ||
| require.Error(t, err) | ||
| } else { | ||
| require.NoError(t, err) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| t.Run("gateway JSON key is not a frontmatter alias", func(t *testing.T) { | ||
| err := ValidateMainWorkflowFrontmatterWithSchemaAndLocation(map[string]any{ | ||
| "on": "workflow_dispatch", | ||
| "sandbox": map[string]any{ | ||
| "mcp": map[string]any{"trustedBots": []any{"github-actions[bot]"}}, | ||
| }, | ||
| }, "trusted-bots.md") | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "trustedBots") | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //go:build !integration | ||
|
|
||
| package workflow | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestMCPGatewayReferenceExamplesCompile(t *testing.T) { | ||
| pagePath := filepath.Join("..", "..", "docs", "src", "content", "docs", "reference", "mcp-gateway.md") | ||
| page, err := os.ReadFile(pagePath) | ||
| require.NoError(t, err) | ||
|
|
||
| for _, test := range []struct { | ||
| name string | ||
| want []string | ||
| }{ | ||
| { | ||
| name: "trusted-bots", | ||
| want: []string{`"trustedBots": ["github-actions[bot]", "copilot-swe-agent[bot]"]`}, | ||
| }, | ||
| { | ||
| name: "oidc-mcp", | ||
| want: []string{ | ||
| `"url": "https://my-server.example.com/mcp"`, | ||
| `"type": "github-oidc"`, | ||
| `"audience": "https://my-server.example.com"`, | ||
| "id-token: write", | ||
| "-e ACTIONS_ID_TOKEN_REQUEST_URL", | ||
| "-e ACTIONS_ID_TOKEN_REQUEST_TOKEN", | ||
| }, | ||
| }, | ||
| } { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| fence := "```aw wrap title=\".github/workflows/" + test.name + ".md\"\n" | ||
| require.Equal(t, 1, strings.Count(string(page), fence)) | ||
| _, rest, found := strings.Cut(string(page), fence) | ||
| require.True(t, found) | ||
| example, _, found := strings.Cut(rest, "\n```") | ||
| require.True(t, found, "reference example must have a closing fence") | ||
|
|
||
| dir := t.TempDir() | ||
| path := filepath.Join(dir, test.name+".md") | ||
| require.NoError(t, os.WriteFile(path, []byte(example+"\n"), 0o600)) | ||
| compiler := NewCompiler() | ||
| require.NoError(t, compiler.CompileWorkflow(path)) | ||
|
|
||
| lock, err := os.ReadFile(filepath.Join(dir, test.name+".lock.yml")) | ||
| require.NoError(t, err) | ||
| for _, want := range test.want { | ||
| require.Contains(t, string(lock), want) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.

Uh oh!
There was an error while loading. Please reload this page.