Skip to content

Commit 0203bba

Browse files
Claudelpcox
andcommitted
Add missing tests and update README for payload path prefix
- Add unit test for savePayload() path remapping behavior - Add unit test for getDefaultPayloadPathPrefix() env var handling - Update README to explicitly note payloadPathPrefix not supported in JSON stdin - Update CLI help output to include --payload-path-prefix flag Addresses Copilot review comments Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
1 parent e93a262 commit 0203bba

3 files changed

Lines changed: 75 additions & 6 deletions

File tree

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ See **[Configuration Specification](https://github.com/github/gh-aw/blob/main/do
225225
- TOML config file: `payload_size_threshold = <bytes>` in `[gateway]` section
226226
- Payloads **larger** than this threshold are stored to disk and return metadata
227227
- Payloads **smaller than or equal** to this threshold are returned inline
228-
- **`payloadPathPrefix`** configures path remapping for clients/agents:
228+
- **`payloadPathPrefix`** is not supported in JSON stdin format. Use:
229229
- CLI flag: `--payload-path-prefix <path>` (default: empty - use actual filesystem path)
230230
- Environment variable: `MCP_GATEWAY_PAYLOAD_PATH_PREFIX=<path>`
231231
- TOML config file: `payload_path_prefix = "<path>"` in `[gateway]` section
@@ -304,13 +304,14 @@ Flags:
304304
-l, --listen string HTTP server listen address (default "127.0.0.1:3000")
305305
--log-dir string Directory for log files (falls back to stdout if directory cannot be created) (default "/tmp/gh-aw/mcp-logs")
306306
--payload-dir string Directory for storing large payload files (segmented by session ID) (default "/tmp/jq-payloads")
307+
--payload-path-prefix string Path prefix to use when returning payloadPath to clients (allows remapping host paths to client/agent container paths)
307308
--payload-size-threshold int Size threshold (in bytes) for storing payloads to disk. Payloads larger than this are stored, smaller ones returned inline (default 524288)
308309
--routed Run in routed mode (each backend at /mcp/<server>)
309-
--sequential-launch Launch MCP servers sequentially during startup (parallel launch is default)
310-
--unified Run in unified mode (all backends at /mcp)
311-
--validate-env Validate execution environment (Docker, env vars) before starting
312-
-v, --verbose count Increase verbosity level (use -v for info, -vv for debug, -vvv for trace)
313-
--version version for awmg
310+
--sequential-launch Launch MCP servers sequentially during startup (parallel launch is default)
311+
--unified Run in unified mode (all backends at /mcp)
312+
--validate-env Validate execution environment (Docker, env vars) before starting
313+
-v, --verbose count Increase verbosity level (use -v for info, -vv for debug, -vvv for trace)
314+
--version version for awmg
314315
315316
Use "awmg [command] --help" for more information about a command.
316317
```

internal/cmd/flags_logging_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,43 @@ func TestPayloadSizeThresholdEnvVar(t *testing.T) {
163163
result := getDefaultPayloadSizeThreshold()
164164
assert.Equal(t, 4096, result, "Environment variable should override default")
165165
}
166+
167+
func TestGetDefaultPayloadPathPrefix(t *testing.T) {
168+
tests := []struct {
169+
name string
170+
envValue string
171+
setEnv bool
172+
expected string
173+
}{
174+
{
175+
name: "no env var - returns default",
176+
setEnv: false,
177+
expected: defaultPayloadPathPrefix,
178+
},
179+
{
180+
name: "env var set - returns custom path",
181+
envValue: "/workspace/payloads",
182+
setEnv: true,
183+
expected: "/workspace/payloads",
184+
},
185+
{
186+
name: "empty env var - returns default",
187+
envValue: "",
188+
setEnv: true,
189+
expected: defaultPayloadPathPrefix,
190+
},
191+
}
192+
193+
for _, tt := range tests {
194+
t.Run(tt.name, func(t *testing.T) {
195+
if tt.setEnv {
196+
t.Setenv("MCP_GATEWAY_PAYLOAD_PATH_PREFIX", tt.envValue)
197+
} else {
198+
t.Setenv("MCP_GATEWAY_PAYLOAD_PATH_PREFIX", "")
199+
}
200+
201+
result := getDefaultPayloadPathPrefix()
202+
assert.Equal(t, tt.expected, result)
203+
})
204+
}
205+
}

internal/middleware/jqschema_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,34 @@ func TestSavePayload(t *testing.T) {
133133
assert.DirExists(t, expectedDir, "Directory should exist")
134134
}
135135

136+
func TestSavePayloadWithPathPrefix(t *testing.T) {
137+
// Create temporary directory for test
138+
baseDir := filepath.Join(os.TempDir(), "test-jq-payloads-prefix")
139+
defer os.RemoveAll(baseDir)
140+
141+
sessionID := "test-session-789"
142+
queryID := "test-query-abc"
143+
payload := []byte(`{"test": "data with prefix"}`)
144+
pathPrefix := "/workspace/payloads"
145+
146+
returnedPath, err := savePayload(baseDir, pathPrefix, sessionID, queryID, payload)
147+
require.NoError(t, err, "savePayload should not return error")
148+
149+
// Verify the actual file was written to the baseDir (filesystem path)
150+
actualFilePath := filepath.Join(baseDir, sessionID, queryID, "payload.json")
151+
assert.FileExists(t, actualFilePath, "Payload file should exist at actual filesystem path")
152+
153+
// Verify file content
154+
content, err := os.ReadFile(actualFilePath)
155+
require.NoError(t, err, "Should be able to read payload file")
156+
assert.Equal(t, payload, content, "File content should match payload")
157+
158+
// Verify the returned path uses the pathPrefix (remapped for client)
159+
expectedReturnPath := filepath.Join(pathPrefix, sessionID, queryID, "payload.json")
160+
assert.Equal(t, expectedReturnPath, returnedPath, "Returned path should use pathPrefix")
161+
assert.NotEqual(t, actualFilePath, returnedPath, "Returned path should differ from actual filesystem path")
162+
}
163+
136164
func TestWrapToolHandler(t *testing.T) {
137165
// Create temporary directory for test
138166
baseDir := filepath.Join(os.TempDir(), "test-jq-payloads")

0 commit comments

Comments
 (0)