-
Notifications
You must be signed in to change notification settings - Fork 528
Document panic() contract for embed-guarded lazy-load panic sites #54599
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2febcbe
Initial plan
Copilot 35ba1f4
Document panic() contract for embed-guarded lazy-load panic sites
Copilot 012d726
Merge branch 'main' into copilot/document-panic-contract
github-actions[bot] 0617d89
Add executable guardrail tests for documented panic invariants and fi…
Copilot 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
There are no files selected for viewing
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
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,85 @@ | ||
| //go:build !integration | ||
|
|
||
| package workflow | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // The tests in this file are executable guardrails for the "build-time invariant" | ||
| // panic sites documented in this package. Each test exercises the real code path | ||
| // that precedes a panic() so that a refactor which makes the panic reachable fails | ||
| // the test suite instead of only surfacing at runtime. | ||
|
|
||
| // TestEmbeddedModelAliasesAreLoadable guards the panics in getBuiltinOnlyAliasMap | ||
| // and BuiltinModelAliases, which fire only when the embedded model_aliases.json | ||
| // cannot be unmarshaled. | ||
| func TestEmbeddedModelAliasesAreLoadable(t *testing.T) { | ||
| aliases, err := loadBuiltinModelAliases() | ||
| require.NoError(t, err, "embedded model_aliases.json must unmarshal at build time") | ||
| assert.NotEmpty(t, aliases) | ||
|
|
||
| assert.NotEmpty(t, getBuiltinOnlyAliasMap()) | ||
| assert.NotEmpty(t, BuiltinModelAliases()) | ||
| } | ||
|
|
||
| // TestEmbeddedToolsetPermissionsAreLoadable guards the panic in | ||
| // getToolsetPermissionsMap, which fires only when the embedded GitHub toolsets | ||
| // JSON cannot be unmarshaled. | ||
| func TestEmbeddedToolsetPermissionsAreLoadable(t *testing.T) { | ||
| assert.NotEmpty(t, getToolsetPermissionsMap()) | ||
| } | ||
|
|
||
| // TestBuiltinEnginesRegisterWithoutError guards the panic in NewEngineRegistry. | ||
| // Register only rejects a negative dedicatedLLMGatewayPort, so re-registering every | ||
| // built-in engine asserts exactly the failure mode the panic guards against. | ||
| func TestBuiltinEnginesRegisterWithoutError(t *testing.T) { | ||
| registry := NewEngineRegistry() | ||
|
|
||
| for _, id := range registry.GetSupportedEngines() { | ||
| engine, err := registry.GetEngine(id) | ||
| require.NoError(t, err) | ||
| assert.NoError(t, NewEngineRegistry().Register(engine), "built-in engine %q must register without error", id) | ||
| } | ||
| } | ||
|
|
||
| // TestBuildPiModelsJSONMarshalsRuntimeValues guards the panic in buildPiModelsJSON. | ||
| // The payload mixes literals with runtime arguments, so this asserts that those | ||
| // argument types always serialise. | ||
| func TestBuildPiModelsJSONMarshalsRuntimeValues(t *testing.T) { | ||
| out := buildPiModelsJSON(4141, "COPILOT_GITHUB_TOKEN", "claude-sonnet-4-20250514") | ||
|
|
||
| var decoded map[string]any | ||
| require.NoError(t, json.Unmarshal([]byte(out), &decoded)) | ||
| assert.Contains(t, decoded, "providers") | ||
| } | ||
|
|
||
| // TestMCPGatewayCustomEnvNamesMarshal guards the panic in | ||
| // writeMCPGatewayStepEnvWithCustomGatewayEnvNames, which fires only if the | ||
| // []string of env var names fails to marshal. | ||
| func TestMCPGatewayCustomEnvNamesMarshal(t *testing.T) { | ||
| var stepEnv strings.Builder | ||
| gatewayEnv := map[string]string{"CUSTOM_ONE": "value-one", "CUSTOM_TWO": "value-two"} | ||
| writeMCPGatewayStepEnvForTest(&stepEnv, nil, nil, gatewayEnv) | ||
|
|
||
| assert.Contains(t, stepEnv.String(), mcpGatewayCustomEnvNamesVar) | ||
| assert.Contains(t, stepEnv.String(), `[\"CUSTOM_ONE\",\"CUSTOM_TWO\"]`) | ||
| } | ||
|
|
||
| // TestFileRenderConfigMarshals guards the panic in generateSafeOutputsSetup, which | ||
| // fires only if the fixed fileRenderConfig struct fails to marshal. | ||
| func TestFileRenderConfigMarshals(t *testing.T) { | ||
| out, err := json.Marshal(fileRenderConfig{ | ||
| Files: []fileRenderItem{{ | ||
| Path: "safeoutputs/config.json", | ||
| ContentEnv: "GH_AW_SAFE_OUTPUTS_CONFIG", | ||
| }}, | ||
| }) | ||
| require.NoError(t, err) | ||
| assert.JSONEq(t, `{"files":[{"path":"safeoutputs/config.json","content_env":"GH_AW_SAFE_OUTPUTS_CONFIG"}]}`, string(out)) | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/grill-with-docs] The cross-reference
// Build-time invariant: see comment in getBuiltinOnlyAliasMap above.leavesBuiltinModelAliases(a public function) dependent on navigating to another function to understand the invariant. Readers encountering this in search results or generated docs won't have that context.💡 Suggested inline wording
Mirrors the comment in
getBuiltinOnlyAliasMapdirectly, making each site self-contained.@copilot please address this.