Skip to content

[jsweep] Clean convert_gateway_config_gemini.cjs#29878

Merged
pelikhan merged 2 commits intomainfrom
jsweep/convert-gateway-config-gemini-4355bdd9433ec27c
May 3, 2026
Merged

[jsweep] Clean convert_gateway_config_gemini.cjs#29878
pelikhan merged 2 commits intomainfrom
jsweep/convert-gateway-config-gemini-4355bdd9433ec27c

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 3, 2026

Summary

Adds comprehensive tests for convert_gateway_config_gemini.cjs, the oldest untested file in actions/setup/js/.

Context

Execution context: Node.js (runs outside github-script, uses shim.cjs for core globals)

Changes

convert_gateway_config_gemini.test.cjs (new file)

The source file was already clean (@ts-check, modern JS, well-documented), but lacked any dedicated tests. The transformGeminiEntry function was only partially covered by convert_gateway_config_adapters.test.cjs. Added 16 tests across two suites:

transformGeminiEntry (8 tests):

  • Removes type field (Gemini transport auto-detection)
  • Rewrites URLs to use configured urlPrefix
  • Preserves all other fields (headers, tools, etc.)
  • Does not mutate the original entry (immutability)
  • Handles entries without a url field
  • Handles non-string url values unchanged
  • Works with different urlPrefix values
  • Handles empty entry

main (8 tests):

  • Writes settings.json to .gemini/ directory in workspace
  • Rewrites server URLs to use MCP_GATEWAY_HOST_DOMAIN
  • Removes type field from all server entries
  • Includes /tmp/ in context.includeDirectories
  • Filters out CLI-mounted servers (GH_AW_MCP_CLI_SERVERS)
  • Writes output with 0o600 permissions (bearer token protection)
  • Uses localhost as default when MCP_GATEWAY_HOST_DOMAIN is unset
  • Handles empty mcpServers gracefully

Validation

  • ✅ Formatting: npm run format:cjs — no changes needed
  • ✅ Linting: npm run lint:cjs — all files pass
  • ✅ Type checking: npm run typecheck — no new errors (pre-existing errors in other files unrelated to this change)
  • ✅ Tests: 16/16 pass in convert_gateway_config_gemini.test.cjs

Generated by jsweep - JavaScript Unbloater · ● 2.6M ·

  • expires on May 5, 2026, 5:01 AM UTC

…ni.cjs

Add 16 tests covering:
- transformGeminiEntry: type removal, URL rewriting, field preservation, immutability,
  missing url, non-string url, empty entry
- main: settings.json output path, URL rewriting, type removal, /tmp/ include dir,
  CLI server filtering, file permissions (0o600), localhost default, empty servers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review May 3, 2026 08:09
Copilot AI review requested due to automatic review settings May 3, 2026 08:09
@github-actions github-actions Bot mentioned this pull request May 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 3, 2026

🧪 Test Quality Sentinel Report

Test Quality Score: 85/100

Excellent test quality

Metric Value
New/modified tests analyzed 16
✅ Design tests (behavioral contracts) 16 (100%)
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases 8 (50%)
Duplicate test clusters 0
Test inflation detected N/A (tests added for pre-existing file)
🚨 Coding-guideline violations None

Test Classification Details

View all 16 test classifications
Test File Classification Notes
removes the type field from the entry convert_gateway_config_gemini.test.cjs ✅ Design Behavioral contract: type removal
rewrites the url to use the configured domain and port convert_gateway_config_gemini.test.cjs ✅ Design Behavioral contract: URL rewriting
preserves all other fields from the entry convert_gateway_config_gemini.test.cjs ✅ Design Behavioral contract: field passthrough
does not mutate the original entry convert_gateway_config_gemini.test.cjs ✅ Design Immutability invariant
handles entries without a url field gracefully convert_gateway_config_gemini.test.cjs ✅ Design Edge case: missing url
handles entries with non-string url values unchanged convert_gateway_config_gemini.test.cjs ✅ Design Edge case: non-string url
works with a different urlPrefix convert_gateway_config_gemini.test.cjs ✅ Design Behavioral contract: prefix parameterization
handles entries with empty object convert_gateway_config_gemini.test.cjs ✅ Design Edge case: empty input
writes settings.json to .gemini directory in workspace convert_gateway_config_gemini.test.cjs ✅ Design Behavioral contract: file output path
rewrites server URLs to use MCP_GATEWAY_HOST_DOMAIN convert_gateway_config_gemini.test.cjs ✅ Design Behavioral contract: domain rewriting
removes type field from all server entries convert_gateway_config_gemini.test.cjs ✅ Design Behavioral contract: multi-server type removal
includes /tmp/ in context.includeDirectories convert_gateway_config_gemini.test.cjs ✅ Design Behavioral contract: context config
filters out CLI-mounted servers convert_gateway_config_gemini.test.cjs ✅ Design Behavioral contract: CLI server exclusion
writes settings.json with 0o600 file permissions convert_gateway_config_gemini.test.cjs ✅ Design Security invariant: file permissions
uses localhost as default when MCP_GATEWAY_HOST_DOMAIN is not set convert_gateway_config_gemini.test.cjs ✅ Design Edge case: default env var behavior
handles empty mcpServers gracefully convert_gateway_config_gemini.test.cjs ✅ Design Edge case: empty server map

Flagged Tests — Requires Review

No tests flagged. All tests are behavioral contract tests with no coding-guideline violations.


Language Support

Tests analyzed:

  • 🟨 JavaScript (*.test.cjs): 16 tests (vitest)

Verdict

Check passed. 0% of new tests are implementation tests (threshold: 30%). This PR adds a dedicated test file for the pre-existing convert_gateway_config_gemini.cjs module with excellent behavioral coverage. Highlights include an immutability invariant test, a file permission security invariant (0o600), and thorough edge cases for missing/invalid fields and environment variable defaults.


📖 Understanding Test Classifications

Design Tests (High Value) verify what the system does:

  • Assert on observable outputs, return values, or state changes
  • Cover error paths and boundary conditions
  • Would catch a behavioral regression if deleted
  • Remain valid even after internal refactoring

Implementation Tests (Low Value) verify how the system does it:

  • Assert on internal function calls (mocking internals)
  • Only test the happy path with typical inputs
  • Break during legitimate refactoring even when behavior is correct

Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.

🧪 Test quality analysis by Test Quality Sentinel · ● 426K ·

Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Test Quality Sentinel: 85/100. Test quality is excellent — 0% of new tests are implementation tests (threshold: 30%). All 16 tests verify behavioral contracts with no coding-guideline violations.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a dedicated Vitest suite for convert_gateway_config_gemini.cjs to cover both entry transformation and end-to-end config generation for Gemini CLI.

Changes:

  • Adds focused unit tests for transformGeminiEntry, including URL rewriting, type removal, immutability, and edge cases.
  • Adds integration-style tests for main() covering workspace output, CLI-server filtering, /tmp/ inclusion, permissions, and host-domain behavior.
  • Uses temporary directories and environment setup/teardown to exercise the converter in a realistic Node.js execution context.
Show a summary per file
File Description
actions/setup/js/convert_gateway_config_gemini.test.cjs New dedicated test coverage for Gemini gateway-config conversion behavior and output generation.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment on lines +40 to +41
const entry = { type: "http", url: "http://old/mcp/github" };
const original = { ...entry };
Comment on lines +199 to +203
it("handles empty mcpServers gracefully", () => {
writeGatewayOutput({});

main();

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented May 3, 2026

@copilot review all comments

…payload tests

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/e438bc8e-a350-41cc-9c4f-2430c3fac903

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 3, 2026

@copilot review all comments

Addressed both optional suggestions in 484687c:

  1. Immutability test (lines 39-44): fixture now includes nested headers and tools fields, and the snapshot uses JSON.parse(JSON.stringify(entry)) (deep clone) instead of a shallow spread — so mutation of nested objects would be caught.

  2. Malformed gateway payloads: added a writeRawGatewayOutput helper and three new main() tests covering the loadGatewayContext() normalisation paths: missing mcpServers key, null value, and an array value — all should normalise to {}. 19/19 tests pass.

Copilot AI requested a review from pelikhan May 3, 2026 13:22
@pelikhan pelikhan merged commit 8ccd88e into main May 3, 2026
@pelikhan pelikhan deleted the jsweep/convert-gateway-config-gemini-4355bdd9433ec27c branch May 3, 2026 14:49
Copilot AI pushed a commit that referenced this pull request May 3, 2026
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants