sus-fixtures-agent-context 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c9d4dad22be9729608f3805460e81bdc828f8d3f96b4152d681b83266e71abf5
4
+ data.tar.gz: 29d3f5f5d024240d95629f4bf29904905c1ee31cffc32d3eb693902d204a13f4
5
+ SHA512:
6
+ metadata.gz: 533ff26c37f929daad81155ce92ca7054008a1e1012537b79a82a047ade05d63989a63bd3279cb1acb50c26ad451bca83e7f40016d51da204dee85e119bf860d
7
+ data.tar.gz: a486b1e28a8833b8dd7df9af87c81238ee0d3072bb1ece0e9a604d50cd9c6f9fe63f00ff7ab0b081fab83fd571a7f35ad2e1007cf98ce06022a95480e1774242
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ u.byg��?+)�M�G��/��Lb��X'?U� e����7���O������{�01Wh[�b1���f=�yE��1�EV�bq
2
+ b��@k�V��Q�to�������
data/agent.md ADDED
@@ -0,0 +1,51 @@
1
+ # Agent
2
+
3
+ ## Context
4
+
5
+ This section provides links to documentation from installed packages. It is automatically generated and may be updated by running `bake agent:context:install`.
6
+
7
+ **Important:** Before performing any code, documentation, or analysis tasks, always read and apply the full content of any relevant documentation referenced in the following sections. These context files contain authoritative standards and best practices for documentation, code style, and project-specific workflows. **Do not proceed with any actions until you have read and incorporated the guidance from relevant context files.**
8
+
9
+ ### agent-context
10
+
11
+ Install and manage context files from Ruby gems.
12
+
13
+ #### [Usage Guide](.context/agent-context/usage.md)
14
+
15
+ `agent-context` is a tool that helps you discover and install contextual information from Ruby gems for AI agents. Gems can provide additional documentation, examples, and guidance in a `context/` ...
16
+
17
+ ### decode
18
+
19
+ Code analysis for documentation generation.
20
+
21
+ #### [Getting Started with Decode](.context/decode/getting-started.md)
22
+
23
+ The Decode gem provides programmatic access to Ruby code structure and metadata. It can parse Ruby files and extract definitions, comments, and documentation pragmas, enabling code analysis, docume...
24
+
25
+ #### [Documentation Coverage](.context/decode/coverage.md)
26
+
27
+ This guide explains how to test and monitor documentation coverage in your Ruby projects using the Decode gem's built-in bake tasks.
28
+
29
+ #### [Ruby Documentation](.context/decode/ruby-documentation.md)
30
+
31
+ This guide covers documentation practices and pragmas supported by the Decode gem for documenting Ruby code. These pragmas provide structured documentation that can be parsed and used to generate A...
32
+
33
+ #### [Setting Up RBS Types and Steep Type Checking for Ruby Gems](.context/decode/types.md)
34
+
35
+ This guide covers the process for establishing robust type checking in Ruby gems using RBS and Steep, focusing on automated generation from source documentation and proper validation.
36
+
37
+ ### sus
38
+
39
+ A fast and scalable test runner.
40
+
41
+ #### [Using Sus Testing Framework](.context/sus/usage.md)
42
+
43
+ Sus is a modern Ruby testing framework that provides a clean, BDD-style syntax for writing tests. It's designed to be fast, simple, and expressive.
44
+
45
+ #### [Mocking](.context/sus/mocking.md)
46
+
47
+ There are two types of mocking in sus: `receive` and `mock`. The `receive` matcher is a subset of full mocking and is used to set expectations on method calls, while `mock` can be used to replace m...
48
+
49
+ #### [Shared Test Behaviors and Fixtures](.context/sus/shared.md)
50
+
51
+ Sus provides shared test contexts which can be used to define common behaviours or tests that can be reused across one or more test files.
@@ -0,0 +1,31 @@
1
+ # Getting Started
2
+
3
+ This guide explains how to use the `sus-fixtures-agent-context` gem to test agent contexts.
4
+
5
+ ## Installation
6
+
7
+ Add the gem to your project:
8
+
9
+ ```bash
10
+ bundle add sus-fixtures-agent-context
11
+ ```
12
+
13
+ You will need a locally accessible Ollama server to use this gem, as it relies on the `Async::Ollama` client to interact with agents. Make sure you have Ollama installed and running.
14
+
15
+ ## Testing Agent Contexts
16
+
17
+ This gem provides a convenient way to test whether a given context is sufficient for an agent to perform a task. It uses the `Async::Ollama` client to interact with agents. So you will need to have an Ollama server running and accessible.
18
+
19
+ ```ruby
20
+ include Sus::Fixtures::Agent::Context
21
+
22
+ it "can use the with_agent_context fixture" do
23
+ # The path is relative to the working directory by default.
24
+ with_agent_context("context/getting-started.md") do |session|
25
+ response = session.call("Write an expectation that checks if an `array` contains an `item`.")
26
+ expect(response).to be ==~ /expect\(array\).to be(:include?, item\)/
27
+ end
28
+ end
29
+ ```
30
+
31
+ It is recommended that you put these tests in `test/.agent/context` directory, and they must be run explicitly with `sus test/.agent/context`. By default, `sus` will not recurse into directories starting with a dot, so this is an acceptable way to organize your tests.
@@ -0,0 +1,59 @@
1
+ # GitHub Actions
2
+
3
+ This guide explains how to integrate the `sus-fixtures-agent-context` gem with GitHub Actions for testing agent contexts.
4
+
5
+ ## Workflow
6
+
7
+ In order to use this gem in GitHub Actions, you can set up a workflow that includes the Ollama server. Here is an example of how to configure your `.github/workflows/test.yml`:
8
+
9
+ ```yaml
10
+ name: Test Agent Context
11
+
12
+ on: [push, pull_request]
13
+
14
+ permissions:
15
+ contents: read
16
+
17
+ jobs:
18
+ test:
19
+ name: Agent Context
20
+ runs-on: ${{matrix.os}}-latest
21
+ continue-on-error: ${{matrix.experimental}}
22
+
23
+ services:
24
+ ollama:
25
+ image: ollama/ollama
26
+ ports:
27
+ - 11434:11434
28
+
29
+ strategy:
30
+ matrix:
31
+ os:
32
+ - ubuntu
33
+
34
+ ruby:
35
+ - "3.4"
36
+
37
+ experimental: [false]
38
+
39
+ include:
40
+ - os: ubuntu
41
+ ruby: head
42
+ experimental: true
43
+
44
+ steps:
45
+ - uses: actions/checkout@v4
46
+ - uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: ${{matrix.ruby}}
49
+ bundler-cache: true
50
+
51
+ - name: Pull Model
52
+ run: bundle exec bake async:ollama:pull
53
+
54
+ - name: Run tests
55
+ timeout-minutes: 30
56
+ run: bundle exec sus test/.agent/context
57
+ ```
58
+
59
+ Note that the timeout is set to 30 mintues to allow sufficient time for the Ollama server to start and for the tests to run.
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2025, by Samuel Williams.
5
+
6
+ require "async/ollama"
7
+ require "async/ollama/conversation"
8
+
9
+ module Sus
10
+ module Fixtures
11
+ module Agent
12
+ module Context
13
+ # Manages a conversation session with an agent, loading context and handling prompts.
14
+ class Session
15
+ # @constant [String] The system prompt used to instruct the agent on how to use the provided context.
16
+ CONTEXT_PROMPT = <<~PROMPT
17
+ You are a documentation-aware assistant tasked with answering questions strictly based on the provided context.
18
+
19
+ The context you are given is the sole source of truth. It defines how the system behaves, what features exist, and how they are used.
20
+
21
+ - Do not rely on your prior training or general knowledge.
22
+ - If the answer cannot be inferred from the context, say: “The context does not contain enough information to answer this.”
23
+ - Do not speculate, assume, or generalize beyond what is written in the context.
24
+
25
+ Your responses should be clear, concise, and strictly grounded in the information provided. Prioritize accuracy over completeness or fluency.
26
+ PROMPT
27
+
28
+ # Initializes a new session for agent context interaction.
29
+ # @option :temperatuire [Float] The temperature for the agent's responses (default is 0.0 for deterministic responses).
30
+ # @option :model [String] The model to use for the agent (default is "llama3.1").
31
+ def initialize(**options)
32
+ # Remove as much non-determinism as possible:
33
+ options[:temperature] = 0.0
34
+
35
+ @client = ::Async::Ollama::Client.open
36
+ @conversation = ::Async::Ollama::Conversation.new(@client, **options)
37
+ end
38
+
39
+ # @attribute [::Async::Ollama::Conversation] The conversation object for this session.
40
+ attr :conversation
41
+
42
+ # Sends a prompt to the agent and returns the response.
43
+ # @parameter prompt [String] The prompt to send to the agent.
44
+ # @returns [String] The agent's response.
45
+ def call(prompt)
46
+ chat = @conversation.call(prompt)
47
+
48
+ return chat.response
49
+ end
50
+
51
+ # Loads a context file and appends it to the conversation as a system message.
52
+ # @parameter path [String] The path to the context file.
53
+ def load_context_path(path)
54
+ ::File.read(path).tap do |content|
55
+ @conversation.messages << {
56
+ role: "system",
57
+ content: CONTEXT_PROMPT + "\n\n--- The context follows:\n\n" + content
58
+ }
59
+ end
60
+ end
61
+
62
+ # Closes the underlying client connection.
63
+ def close
64
+ @client.close if @client
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2025, by Samuel Williams.
5
+
6
+ module Sus
7
+ module Fixtures
8
+ module Agent
9
+ module Context
10
+ VERSION = "0.1.0"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2025, by Samuel Williams.
5
+
6
+ require_relative "context/session"
7
+
8
+ # @namespace
9
+ module Sus
10
+ # @namespace
11
+ module Fixtures
12
+ # @namespace
13
+ module Agent
14
+ # @namespace
15
+ module Context
16
+ include Sus::Fixtures::Async::SchedulerContext
17
+
18
+ # @constant [String] The default path to the agent context file.
19
+ AGENT_PATH = "agent.md"
20
+
21
+ # @returns [Integer] the default timeout for agent-based tests, in seconds.
22
+ def timeout
23
+ # 10 minutes - we don't expect tests to actually take this long, but sometimes Ollama has to load models which can take an exceptionally long time depending on the model size and hardware.
24
+ 60*10
25
+ end
26
+
27
+ # Yields a session with the agent context loaded from the given path or the default {AGENT_PATH}.
28
+ # Ensures the session is closed after the block.
29
+ # @parameter path [String | nil] The path to the context file to load.
30
+ # @parameter options [Hash] Additional options for the session.
31
+ # @yields {|session| ...} Yields the session with the loaded context.
32
+ # @parameter session [Session] The session with the loaded context.
33
+ def with_agent_context(path = nil, **options, &block)
34
+ session = Session.new(**options)
35
+
36
+ if path
37
+ session.load_context_path(path)
38
+ end
39
+
40
+ yield session
41
+ ensure
42
+ session&.close
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
data/license.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright, 2025, by Samuel Williams.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,37 @@
1
+ # Sus::Fixtures::Agent::Context
2
+
3
+ Provides convenient fixtures for testing whether a given context is sufficient for an agent to performn a task.
4
+
5
+ [![Development Status](https://github.com/socketry/sus-fixtures-agent-context/workflows/Test/badge.svg)](https://github.com/socketry/sus-fixtures-agent-context/actions?workflow=Test)
6
+
7
+ ## Usage
8
+
9
+ Please see the [project documentation](https://socketry.github.io/sus-fixtures-async/) for more details.
10
+
11
+ - [Getting Started](https://socketry.github.io/sus-fixtures-async/guides/getting-started/index) - This guide explains how to use the `sus-fixtures-agent-context` gem to test agent contexts.
12
+
13
+ - [GitHub Actions](https://socketry.github.io/sus-fixtures-async/guides/github-actions/index) - This guide explains how to integrate the `sus-fixtures-agent-context` gem with GitHub Actions for testing agent contexts.
14
+
15
+ ## Releases
16
+
17
+ Please see the [project releases](https://socketry.github.io/sus-fixtures-async/releases/index) for all releases.
18
+
19
+ ### v0.1.0
20
+
21
+ ## Contributing
22
+
23
+ We welcome contributions to this project.
24
+
25
+ 1. Fork it.
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
28
+ 4. Push to the branch (`git push origin my-new-feature`).
29
+ 5. Create new Pull Request.
30
+
31
+ ### Developer Certificate of Origin
32
+
33
+ In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
34
+
35
+ ### Community Guidelines
36
+
37
+ This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
data/releases.md ADDED
@@ -0,0 +1,3 @@
1
+ # Releases
2
+
3
+ ## v0.1.0
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sus-fixtures-agent-context
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ bindir: bin
9
+ cert_chain:
10
+ - |
11
+ -----BEGIN CERTIFICATE-----
12
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
13
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
14
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
15
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
16
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
17
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
18
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
19
+ 9qZdoq9xt7H+RPbwL28LDpDNfl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qEUe+yo6DKIT3MtGE2+CP
35
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
36
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
37
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
38
+ -----END CERTIFICATE-----
39
+ date: 1980-01-02 00:00:00.000000000 Z
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: async-ollama
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ executables: []
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - agent.md
74
+ - context/getting-started.md
75
+ - context/github-actions.md
76
+ - lib/sus/fixtures/agent/context.rb
77
+ - lib/sus/fixtures/agent/context/session.rb
78
+ - lib/sus/fixtures/agent/context/version.rb
79
+ - license.md
80
+ - readme.md
81
+ - releases.md
82
+ homepage: https://github.com/socketry/sus-fixtures-async
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ documentation_uri: https://socketry.github.io/sus-fixtures-async/
87
+ funding_uri: https://github.com/sponsors/ioquatix/
88
+ source_code_uri: https://github.com/socketry/sus-fixtures-async.git
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '3.2'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.6.7
104
+ specification_version: 4
105
+ summary: Test fixtures for running in Async.
106
+ test_files: []
metadata.gz.sig ADDED
Binary file