-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add comprehensive test coverage and edge case tests #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hawkeyexl
wants to merge
10
commits into
main
Choose a base branch
from
coverage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d18c31b
Remove llama.cpp link
hawkeyexl 934cdba
test: add comprehensive test coverage infrastructure and tests
hawkeyexl 556ff9d
test: add fetchFile and replaceEnvs edge case tests
hawkeyexl 47f3b09
test: add comprehensive heretto.js tests for 94% coverage
hawkeyexl 60ba96d
test: enhance coverage and add edge case tests
hawkeyexl 7bc3cf3
test: update coverage thresholds and enhance validation checks
hawkeyexl 3ff2b32
test: disable coverage check for integration tests
hawkeyexl 3cfec9a
test: improve stderr capture in spawnCommand tests
hawkeyexl 0d1fe45
chore: normalize line endings to LF and add .gitattributes
hawkeyexl cccf78f
refactor: update workflowToTest function and improve success criteria…
hawkeyexl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "all": true, | ||
| "include": ["src/**/*.js"], | ||
| "exclude": ["src/**/*.test.js", "src/**/*.integration.test.js"], | ||
| "reporter": ["text", "lcov", "json", "json-summary"], | ||
| "report-dir": "coverage", | ||
| "check-coverage": true, | ||
| "lines": 50, | ||
| "branches": 45, | ||
| "functions": 50, | ||
| "statements": 50 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| # TDD and Coverage Skill | ||
|
|
||
| **Type:** Rigid (follow exactly) | ||
|
|
||
| ## When to Use | ||
|
|
||
| Use this skill when: | ||
| - Creating new functionality | ||
| - Modifying existing code | ||
| - Fixing bugs | ||
| - Refactoring | ||
|
|
||
| ## Mandatory Process | ||
|
|
||
| ### 1. Test First (TDD) | ||
|
|
||
| Before writing or modifying any implementation code: | ||
|
|
||
| 1. **Write the test(s)** that describe the expected behavior | ||
| 2. **Run the test** - it should FAIL (red) | ||
| 3. **Write the implementation** to make the test pass | ||
| 4. **Run the test** - it should PASS (green) | ||
| 5. **Refactor** if needed, keeping tests passing | ||
|
|
||
| ### 2. Coverage Verification | ||
|
|
||
| After any code change: | ||
|
|
||
| ```bash | ||
| # Run tests with coverage | ||
| npm run test:coverage | ||
|
|
||
| # Verify coverage hasn't decreased | ||
| npm run coverage:ratchet | ||
| ``` | ||
|
|
||
| **Coverage must not decrease.** If ratchet check fails: | ||
| 1. Add tests for uncovered code | ||
| 2. Re-run coverage until ratchet passes | ||
|
|
||
| ### 3. Coverage Thresholds | ||
|
|
||
| Current thresholds are in `coverage-thresholds.json`. These values must only increase: | ||
|
|
||
| | Metric | Current Threshold | | ||
| |--------|-------------------| | ||
| | Lines | 75% | | ||
| | Statements | 75% | | ||
| | Functions | 86% | | ||
| | Branches | 82% | | ||
|
|
||
| ### 4. Test Location | ||
|
|
||
| Tests are co-located with source files in `src/`: | ||
|
|
||
| | Code | Test File | | ||
| |------|-----------| | ||
| | `src/openapi.js` | `src/openapi.test.js` | | ||
| | `src/arazzo.js` | `src/arazzo.test.js` | | ||
| | `src/utils.js` | `src/utils.test.js` | | ||
| | `src/resolve.js` | `src/resolve.test.js` | | ||
| | `src/sanitize.js` | `src/sanitize.test.js` | | ||
| | `src/telem.js` | `src/telem.test.js` | | ||
| | `src/config.js` | `src/config.test.js` | | ||
| | `src/heretto.js` | `src/heretto.test.js` | | ||
| | `src/index.js` | `src/index.test.js` | | ||
|
|
||
| ### 5. Test Structure Pattern | ||
|
|
||
| ```javascript | ||
| const { expect } = require("chai"); | ||
| const sinon = require("sinon"); | ||
| const { functionUnderTest } = require("./module"); | ||
|
|
||
| describe("Module Name", function () { | ||
| let consoleLogStub; | ||
|
|
||
| beforeEach(function () { | ||
| consoleLogStub = sinon.stub(console, "log"); | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| consoleLogStub.restore(); | ||
| }); | ||
|
|
||
| describe("functionUnderTest", function () { | ||
| describe("input validation", function () { | ||
| it("should throw error when required param missing", function () { | ||
| expect(() => functionUnderTest()).to.throw(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("happy path", function () { | ||
| it("should return expected result for valid input", function () { | ||
| const result = functionUnderTest({ validInput: true }); | ||
| expect(result).to.deep.equal(expectedOutput); | ||
| }); | ||
| }); | ||
|
|
||
| describe("edge cases", function () { | ||
| it("should handle boundary condition", function () { | ||
| // test edge case | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| ### 6. Checklist | ||
|
|
||
| Before completing any code change: | ||
|
|
||
| - [ ] Tests written BEFORE implementation (or for existing code: tests added) | ||
| - [ ] All tests pass (`npm test`) | ||
| - [ ] Coverage hasn't decreased (`npm run coverage:ratchet`) | ||
| - [ ] New code has corresponding test coverage | ||
| - [ ] Error paths are tested (not just happy paths) | ||
|
|
||
| ## Commands Reference | ||
|
|
||
| ```bash | ||
| # Run all tests | ||
| npm test | ||
|
|
||
| # Run tests with coverage report | ||
| npm run test:coverage | ||
|
|
||
| # Run coverage ratchet check (prevents coverage decrease) | ||
| npm run coverage:ratchet | ||
|
|
||
| # Check coverage thresholds | ||
| npm run coverage:check | ||
|
|
||
| # Run integration tests with coverage | ||
| npm run test:integration:coverage | ||
|
|
||
| # Run all tests with coverage | ||
| npm run test:all:coverage | ||
| ``` | ||
|
|
||
| ## Common Patterns | ||
|
|
||
| ### Testing async functions | ||
|
|
||
| ```javascript | ||
| it("should handle async operation", async function () { | ||
| const result = await asyncFunction(); | ||
| expect(result).to.exist; | ||
| }); | ||
| ``` | ||
|
|
||
| ### Mocking with Sinon | ||
|
|
||
| ```javascript | ||
| const stub = sinon.stub(fs, "readFileSync").returns("mock content"); | ||
| try { | ||
| const result = functionUnderTest(); | ||
| expect(result).to.equal("expected"); | ||
| } finally { | ||
| stub.restore(); | ||
| } | ||
| ``` | ||
|
|
||
| ### Stubbing console.log (for log() function tests) | ||
|
|
||
| ```javascript | ||
| let consoleLogStub; | ||
|
|
||
| beforeEach(function () { | ||
| consoleLogStub = sinon.stub(console, "log"); | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| consoleLogStub.restore(); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Testing error handling | ||
|
|
||
| ```javascript | ||
| it("should throw on invalid input", function () { | ||
| expect(() => functionUnderTest(null)).to.throw(/error message/); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Testing with temporary files | ||
|
|
||
| ```javascript | ||
| const os = require("os"); | ||
| const path = require("path"); | ||
| const fs = require("fs"); | ||
|
|
||
| let tempDir; | ||
| let tempFile; | ||
|
|
||
| beforeEach(function () { | ||
| tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "test-")); | ||
| tempFile = path.join(tempDir, "test-file.txt"); | ||
| fs.writeFileSync(tempFile, "test content"); | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| if (fs.existsSync(tempFile)) fs.unlinkSync(tempFile); | ||
| if (fs.existsSync(tempDir)) fs.rmdirSync(tempDir); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Testing OpenAPI operations | ||
|
|
||
| ```javascript | ||
| it("should parse OpenAPI spec", async function () { | ||
| const spec = { | ||
| openapi: "3.0.0", | ||
| info: { title: "Test API", version: "1.0.0" }, | ||
| paths: { | ||
| "/test": { | ||
| get: { operationId: "testOp", responses: { 200: { description: "OK" } } } | ||
| } | ||
| } | ||
| }; | ||
| const result = await loadDescription(JSON.stringify(spec)); | ||
| expect(result.info.title).to.equal("Test API"); | ||
| }); | ||
| ``` | ||
|
|
||
| ## Project-Specific Notes | ||
|
|
||
| - Use `config.logLevel = "error"` in tests to suppress log output | ||
| - The `log()` function from `utils.js` checks config.logLevel before logging | ||
| - OpenAPI specs can be loaded from files or URLs using `loadDescription()` | ||
| - The Arazzo workflow format is supported via `workflowToTest()` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.