Skip to content

Comments

feat: enhance response of querying convention #58

Merged
sehwan505 merged 3 commits intomainfrom
feature/enhance-query-convention
Dec 14, 2025
Merged

feat: enhance response of querying convention #58
sehwan505 merged 3 commits intomainfrom
feature/enhance-query-convention

Conversation

@sehwan505
Copy link
Contributor

  • convention 반환할 때 명령 추가해서 반환
  • category input 여러개 입력 가능

Copy link

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

This PR enhances the convention querying functionality by allowing multiple category filters and improving the response format. The changes make the API more flexible by accepting an array of categories instead of a single category string, and restructure the output to be more suitable for AI coding assistants.

Key Changes:

  • Parameter renamed from singular category to plural categories, now accepting an array of strings
  • Response format enhanced with a structured, prompt-style output that groups conventions by category and includes clear instructions
  • New helper functions normalizeCategories() and matchesCategories() implement the multi-category filtering logic

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/mcp/server.go Implements multiple category filtering with new helper functions, updates struct definitions, and adds buildConventionPrompt() for enhanced response formatting
internal/mcp/server_test.go Updates all test cases to use categories array parameter instead of singular category string
Comments suppressed due to low confidence (1)

internal/mcp/server_test.go:219

  • The test suite doesn't include a test case for querying multiple categories simultaneously (e.g., categories: ["security", "documentation"]). While single category queries are tested, the new capability to filter by multiple categories at once should have test coverage to ensure the OR logic works correctly.
	t.Run("query all categories for javascript", func(t *testing.T) {
		params := map[string]interface{}{
			"categories": []interface{}{"all"},
			"languages":  []interface{}{"javascript"},
		}

		result, rpcErr := server.handleListConvention(params)
		require.Nil(t, rpcErr)
		require.NotNil(t, result)

		resultMap := result.(map[string]interface{})
		content := resultMap["content"].([]map[string]interface{})
		text := content[0]["text"].(string)

		t.Logf("Result: %s", text)

		// Should find conventions
		assert.NotContains(t, text, "No conventions found")
		assert.Contains(t, text, "DOC-001")
		assert.Contains(t, text, "SEC-001")
		assert.Contains(t, text, "STYLE-001")
	})

	t.Run("query documentation category for javascript", func(t *testing.T) {
		params := map[string]interface{}{
			"categories": []interface{}{"documentation"},
			"languages":  []interface{}{"javascript"},
		}

		result, rpcErr := server.handleListConvention(params)
		require.Nil(t, rpcErr)
		require.NotNil(t, result)

		resultMap := result.(map[string]interface{})
		content := resultMap["content"].([]map[string]interface{})
		text := content[0]["text"].(string)

		t.Logf("Result: %s", text)

		// Should find only documentation conventions
		assert.Contains(t, text, "DOC-001")
		assert.NotContains(t, text, "SEC-001")
		assert.NotContains(t, text, "STYLE-001")
	})

	t.Run("query security category for typescript", func(t *testing.T) {
		params := map[string]interface{}{
			"categories": []interface{}{"security"},
			"languages":  []interface{}{"typescript"},
		}

		result, rpcErr := server.handleListConvention(params)
		require.Nil(t, rpcErr)
		require.NotNil(t, result)

		resultMap := result.(map[string]interface{})
		content := resultMap["content"].([]map[string]interface{})
		text := content[0]["text"].(string)

		t.Logf("Result: %s", text)

		// Should find SEC-001 (supports typescript)
		assert.Contains(t, text, "SEC-001")
		assert.NotContains(t, text, "DOC-001") // javascript only
	})

	t.Run("query with unsupported language", func(t *testing.T) {
		params := map[string]interface{}{
			"categories": []interface{}{"all"},
			"languages":  []interface{}{"python"},
		}

		result, rpcErr := server.handleListConvention(params)
		require.Nil(t, rpcErr)
		require.NotNil(t, result)

		resultMap := result.(map[string]interface{})
		content := resultMap["content"].([]map[string]interface{})
		text := content[0]["text"].(string)

		t.Logf("Result: %s", text)

		// Should return no conventions
		assert.Contains(t, text, "No conventions found")
	})

	t.Run("rule without severity uses defaults", func(t *testing.T) {
		params := map[string]interface{}{
			"categories": []interface{}{"style"},
			"languages":  []interface{}{"javascript"},
		}

		result, rpcErr := server.handleListConvention(params)
		require.Nil(t, rpcErr)
		require.NotNil(t, result)

		resultMap := result.(map[string]interface{})
		content := resultMap["content"].([]map[string]interface{})
		text := content[0]["text"].(string)

		t.Logf("Result: %s", text)

		// STYLE-001 doesn't have explicit severity, should use default "error"
		assert.Contains(t, text, "STYLE-001")
		assert.Contains(t, text, "[error]") // Should use default from policy
	})

	t.Run("empty parameters returns all conventions", func(t *testing.T) {
		params := map[string]interface{}{}

		result, rpcErr := server.handleListConvention(params)
		require.Nil(t, rpcErr)
		require.NotNil(t, result)

		resultMap := result.(map[string]interface{})
		content := resultMap["content"].([]map[string]interface{})
		text := content[0]["text"].(string)

		t.Logf("Result: %s", text)

		// Should return all conventions when no filters specified
		assert.Contains(t, text, "DOC-001")
		assert.Contains(t, text, "SEC-001")
		assert.Contains(t, text, "STYLE-001")
	})

	t.Run("only category specified", func(t *testing.T) {
		params := map[string]interface{}{
			"categories": []interface{}{"security"},
		}

		result, rpcErr := server.handleListConvention(params)
		require.Nil(t, rpcErr)
		require.NotNil(t, result)

		resultMap := result.(map[string]interface{})
		content := resultMap["content"].([]map[string]interface{})
		text := content[0]["text"].(string)

		t.Logf("Result: %s", text)

		// Should return only security conventions
		assert.Contains(t, text, "SEC-001")
		assert.NotContains(t, text, "DOC-001")
	})
}

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

// Instructions section
sb.WriteString("---\n\n")
sb.WriteString("## Instructions\n\n")
sb.WriteString("1. Apply all conventions above when writing code(without configuration files)\n")
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

Missing space before the opening parenthesis in "code(without configuration files)". Should be "code (without configuration files)".

Suggested change
sb.WriteString("1. Apply all conventions above when writing code(without configuration files)\n")
sb.WriteString("1. Apply all conventions above when writing code (without configuration files)\n")

Copilot uses AI. Check for mistakes.
@sehwan505 sehwan505 merged commit 31ea416 into main Dec 14, 2025
8 checks passed
@sehwan505 sehwan505 deleted the feature/enhance-query-convention branch December 14, 2025 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant