mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-05-13 16:13:03 +08:00
docs: salvage focused stale PR contributions
- add Vite and Redis pattern skills from closed stale PRs - add frontend-slides support assets - port skill-comply runner fixes and LLM prompt/provider regressions - harden agent frontmatter validation and sync catalog counts
This commit is contained in:
committed by
Affaan Mustafa
parent
d8f879e671
commit
b39d2244cf
@@ -2002,6 +2002,28 @@ function runTests() {
|
||||
cleanupTestDir(testDir);
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('rejects agent with duplicate top-level frontmatter keys', () => {
|
||||
const testDir = createTestDir();
|
||||
fs.writeFileSync(path.join(testDir, 'dup-model.md'),
|
||||
'---\nname: dup\nmodel: sonnet\ntools: Read, Write\ndescription: test\nmodel: opus\n---\n# Agent');
|
||||
|
||||
const result = runValidatorWithDir('validate-agents', 'AGENTS_DIR', testDir);
|
||||
assert.strictEqual(result.code, 1, 'Should reject duplicate top-level YAML keys');
|
||||
assert.ok(result.stderr.includes('Duplicate frontmatter keys'), 'Should report duplicate keys');
|
||||
assert.ok(result.stderr.includes('model'), 'Should name the duplicated key');
|
||||
cleanupTestDir(testDir);
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('allows duplicate-looking nested frontmatter keys', () => {
|
||||
const testDir = createTestDir();
|
||||
fs.writeFileSync(path.join(testDir, 'nested.md'),
|
||||
'---\nmodel: sonnet\ntools: Read\nmetadata:\n model: display-only\n---\n# Agent');
|
||||
|
||||
const result = runValidatorWithDir('validate-agents', 'AGENTS_DIR', testDir);
|
||||
assert.strictEqual(result.code, 0, 'Indented nested keys should not count as top-level duplicates');
|
||||
cleanupTestDir(testDir);
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 32: empty frontmatter & edge cases ──
|
||||
console.log('\nRound 32: validate-agents (empty frontmatter):');
|
||||
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
||||
|
||||
|
||||
def pytest_configure(config: pytest.Config) -> None:
|
||||
config.addinivalue_line("markers", "unit: marks fast unit tests")
|
||||
|
||||
@@ -24,22 +24,37 @@ class TestPromptBuilder:
|
||||
assert len(result) == 2
|
||||
assert result[0].role == Role.SYSTEM
|
||||
|
||||
def test_build_adds_system_from_config(self):
|
||||
messages = [Message(role=Role.USER, content="Hello")]
|
||||
builder = PromptBuilder(system_template="You are a pirate.")
|
||||
result = builder.build(messages)
|
||||
|
||||
assert len(result) == 2
|
||||
assert "pirate" in result[0].content
|
||||
|
||||
def test_build_adds_system_from_config(self):
|
||||
messages = [Message(role=Role.USER, content="Hello")]
|
||||
builder = PromptBuilder(config=PromptConfig(system_template="You are a pirate."))
|
||||
result = builder.build(messages)
|
||||
|
||||
assert len(result) == 2
|
||||
assert "pirate" in result[0].content
|
||||
def test_build_with_tools(self):
|
||||
def test_build_adds_system_from_keyword_options(self):
|
||||
messages = [Message(role=Role.USER, content="Hello")]
|
||||
builder = PromptBuilder(system_template="You are a pirate.")
|
||||
result = builder.build(messages)
|
||||
|
||||
assert len(result) == 2
|
||||
assert "pirate" in result[0].content
|
||||
|
||||
def test_build_adds_system_from_prompt_config(self):
|
||||
messages = [Message(role=Role.USER, content="Hello")]
|
||||
builder = PromptBuilder(config=PromptConfig(system_template="You are a pirate."))
|
||||
result = builder.build(messages)
|
||||
|
||||
assert len(result) == 2
|
||||
assert "pirate" in result[0].content
|
||||
|
||||
def test_rejects_config_with_keyword_options(self):
|
||||
with pytest.raises(ValueError, match="Pass either config or PromptBuilder keyword options"):
|
||||
PromptBuilder(
|
||||
config=PromptConfig(system_template="Configured."),
|
||||
system_template="Keyword override.",
|
||||
)
|
||||
|
||||
def test_empty_system_template_does_not_add_blank_system_message(self):
|
||||
messages = [Message(role=Role.USER, content="Hello")]
|
||||
builder = PromptBuilder(system_template="")
|
||||
result = builder.build(messages)
|
||||
|
||||
assert result == messages
|
||||
|
||||
def test_build_with_tools(self):
|
||||
messages = [Message(role=Role.USER, content="Search for something")]
|
||||
tools = [
|
||||
ToolDefinition(name="search", description="Search the web", parameters={}),
|
||||
|
||||
111
tests/test_claude_provider.py
Normal file
111
tests/test_claude_provider.py
Normal file
@@ -0,0 +1,111 @@
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from llm.core.types import LLMInput, Message, Role
|
||||
from llm.providers.claude import ClaudeProvider
|
||||
|
||||
|
||||
class FakeMessages:
|
||||
def __init__(self, response: SimpleNamespace) -> None:
|
||||
self.response = response
|
||||
|
||||
def create(self, **_params: object) -> SimpleNamespace:
|
||||
return self.response
|
||||
|
||||
|
||||
class FakeClient:
|
||||
def __init__(self, response: SimpleNamespace) -> None:
|
||||
self.messages = FakeMessages(response)
|
||||
self.api_key = "test-key"
|
||||
|
||||
|
||||
def make_provider(response: SimpleNamespace) -> ClaudeProvider:
|
||||
provider = ClaudeProvider(api_key="test-key")
|
||||
provider.client = FakeClient(response)
|
||||
return provider
|
||||
|
||||
|
||||
def make_response(content: list[SimpleNamespace], stop_reason: str = "tool_use") -> SimpleNamespace:
|
||||
return SimpleNamespace(
|
||||
content=content,
|
||||
model="claude-test",
|
||||
usage=SimpleNamespace(input_tokens=3, output_tokens=5),
|
||||
stop_reason=stop_reason,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_generate_collects_text_and_tool_use_blocks() -> None:
|
||||
provider = make_provider(
|
||||
make_response(
|
||||
[
|
||||
SimpleNamespace(type="text", text="I will search. "),
|
||||
SimpleNamespace(type="tool_use", id="toolu_1", name="search", input={"query": "claude"}),
|
||||
SimpleNamespace(type="text", text="Done."),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
output = provider.generate(LLMInput(messages=[Message(role=Role.USER, content="Search")]))
|
||||
|
||||
assert output.content == "I will search. Done."
|
||||
assert output.tool_calls is not None
|
||||
assert len(output.tool_calls) == 1
|
||||
assert output.tool_calls[0].id == "toolu_1"
|
||||
assert output.tool_calls[0].name == "search"
|
||||
assert output.tool_calls[0].arguments == {"query": "claude"}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_generate_collects_multiple_tool_use_blocks() -> None:
|
||||
provider = make_provider(
|
||||
make_response(
|
||||
[
|
||||
SimpleNamespace(type="tool_use", id="toolu_1", name="search", input={"query": "claude"}),
|
||||
SimpleNamespace(
|
||||
type="tool_use",
|
||||
id="toolu_2",
|
||||
name="read",
|
||||
input=SimpleNamespace(path="README.md"),
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
output = provider.generate(LLMInput(messages=[Message(role=Role.USER, content="Use tools")]))
|
||||
|
||||
assert output.content == ""
|
||||
assert [call.id for call in output.tool_calls or []] == ["toolu_1", "toolu_2"]
|
||||
assert (output.tool_calls or [])[1].arguments == {"path": "README.md"}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_generate_copies_tool_use_dict_arguments() -> None:
|
||||
raw_arguments: dict[str, Any] = {"query": "claude"}
|
||||
provider = make_provider(
|
||||
make_response(
|
||||
[SimpleNamespace(type="tool_use", id="toolu_1", name="search", input=raw_arguments)]
|
||||
)
|
||||
)
|
||||
|
||||
output = provider.generate(LLMInput(messages=[Message(role=Role.USER, content="Use tools")]))
|
||||
raw_arguments["query"] = "mutated"
|
||||
|
||||
assert (output.tool_calls or [])[0].arguments == {"query": "claude"}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_generate_text_only_has_no_tool_calls() -> None:
|
||||
provider = make_provider(
|
||||
make_response(
|
||||
[SimpleNamespace(type="text", text="Hello.")],
|
||||
stop_reason="end_turn",
|
||||
)
|
||||
)
|
||||
|
||||
output = provider.generate(LLMInput(messages=[Message(role=Role.USER, content="Hi")]))
|
||||
|
||||
assert output.content == "Hello."
|
||||
assert output.tool_calls is None
|
||||
71
tests/test_templates.py
Normal file
71
tests/test_templates.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import pytest
|
||||
|
||||
from llm.prompt import (
|
||||
TEMPLATES,
|
||||
clear_templates,
|
||||
deregister_template,
|
||||
get_template,
|
||||
get_template_or_default,
|
||||
register_template,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def restore_template_registry():
|
||||
snapshot = dict(TEMPLATES)
|
||||
clear_templates()
|
||||
yield
|
||||
try:
|
||||
clear_templates()
|
||||
finally:
|
||||
TEMPLATES.update(snapshot)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_register_template_exposes_public_template_mapping():
|
||||
register_template("system", "You are helpful.")
|
||||
|
||||
assert get_template("system") == "You are helpful."
|
||||
assert get_template_or_default("missing", "fallback") == "fallback"
|
||||
assert TEMPLATES["system"] == "You are helpful."
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_templates_mapping_remains_mutable_for_existing_callers():
|
||||
TEMPLATES["legacy"] = "Use the existing public mapping."
|
||||
|
||||
assert get_template("legacy") == "Use the existing public mapping."
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_deregister_template_removes_named_template():
|
||||
register_template("system", "You are helpful.")
|
||||
|
||||
deregister_template("system")
|
||||
|
||||
assert get_template("system") is None
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_clear_templates_removes_all_registered_templates():
|
||||
register_template("system", "You are helpful.")
|
||||
register_template("user", "Answer clearly.")
|
||||
|
||||
clear_templates()
|
||||
|
||||
assert TEMPLATES == {}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.parametrize(
|
||||
("name", "template", "error_match"),
|
||||
[
|
||||
("", "content", "Template name must be a non-empty string"),
|
||||
(" ", "content", "Template name must be a non-empty string"),
|
||||
("system", "", "Template content must be a non-empty string"),
|
||||
("system", " ", "Template content must be a non-empty string"),
|
||||
],
|
||||
)
|
||||
def test_register_template_rejects_empty_inputs(name, template, error_match):
|
||||
with pytest.raises(ValueError, match=error_match):
|
||||
register_template(name, template)
|
||||
Reference in New Issue
Block a user