diff --git a/test/agent/context/index.rb b/test/agent/context/index.rb index 11d54f3..cb4c5c3 100644 --- a/test/agent/context/index.rb +++ b/test/agent/context/index.rb @@ -194,6 +194,30 @@ def around expect(content).to be(:include?, "No context files found") expect(content).not.to be(:include?, "Old context content here") end + + it "only finds context sections under the Agent heading" do + existing_content = <<~MARKDOWN + # Agent + + Agent instructions. + + # Project + + ## Context + + Project context. + MARKDOWN + + File.write(agent_md_path, existing_content) + + index = Agent::Context::Index.new(context_path) + index.update_agents_md(agent_md_path) + + content = File.read(agent_md_path) + expect(content.scan("## Context").length).to be == 2 + expect(content).to be(:include?, "Project context.") + expect(content).to be(:include?, "No context files found") + end end with "title and description extraction" do diff --git a/test/agent/context/installer.rb b/test/agent/context/installer.rb index af74ee2..763032f 100644 --- a/test/agent/context/installer.rb +++ b/test/agent/context/installer.rb @@ -89,6 +89,18 @@ def around expect(content).to be_nil end + it "handles a malformed context index" do + File.write(File.join(context_path, "index.yaml"), "invalid: yaml: content: [") + + helper = subject.new(specifications: @specifications) + gem = helper.find_gem_with_context("fake-gem") + index = helper.send(:ensure_gem_index, gem, context_path) + + expect(index["description"]).to be == "A fake gem for testing" + expect(index["metadata"]).to be == {} + expect(index["files"]).to be == [] + end + with "installation" do let(:target_path) {Dir.mktmpdir} @@ -136,6 +148,20 @@ def around expect(File).to be(:exist?, File.join(target_context_path, "getting-started.md")) expect(File).to be(:exist?, File.join(target_context_path, "configuration.md")) end + + it "generates metadata for minimally structured context" do + File.write(File.join(context_path, "notes.md"), "First paragraph.\n\nSecond paragraph.") + helper = subject.new(root: @target_path, specifications: @specifications) + + expect(helper.install_gem_context("fake-gem")).to be_truthy + + index_path = File.join(@target_path, ".agents", "context", "fake-gem", "index.yaml") + index = YAML.load_file(index_path) + notes = index["files"].find{|file| file["path"] == "notes.md"} + + expect(notes["title"]).to be == "Documentation" + expect(notes["description"]).to be == "First paragraph." + end end end