Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions application/tests/harvester_test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
tests for Module A configuration layer (empty for now)
"""
122 changes: 122 additions & 0 deletions application/tests/harvester_test/config_loader_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from pathlib import Path
import unittest

from application.utils.harvester.config_loader import (
ConfigLoaderError,
ConfigFileNotFoundError,
load_repo_config,
)

FIXTURES_DIR = Path(__file__).parent / "fixtures"


class ConfigLoaderTests(unittest.TestCase):
def test_load_valid_config(self):
config_path = FIXTURES_DIR / "valid_repos.yaml"

config = load_repo_config(config_path)

self.assertEqual(len(config.repositories), 1)

repo = config.repositories[0]

self.assertEqual(repo.id, "owasp-asvs")
self.assertEqual(repo.owner, "OWASP")
self.assertEqual(repo.repo, "ASVS")

def test_missing_repository_id(self):
config_path = FIXTURES_DIR / "invalid_missing_id.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

def test_invalid_chunk_size(self):
config_path = FIXTURES_DIR / "invalid_chunk_size.yaml"

with self.assertRaisesRegex(ConfigLoaderError, "max_tokens"):
load_repo_config(config_path)

def test_invalid_yaml_syntax(self):
config_path = FIXTURES_DIR / "invalid_yaml.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

def test_missing_config_file(self):
with self.assertRaises(ConfigFileNotFoundError):
load_repo_config("does_not_exist.yaml")

def test_invalid_polling_interval(self):
config_path = FIXTURES_DIR / "invalid_polling_interval.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

def test_empty_include_paths(self):
config_path = FIXTURES_DIR / "empty_include_paths.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please extend this test class to exercise the validation paths represented by the existing but unused empty_owner.yaml, invalid_chunking_strategy.yaml, and invalid_polling_mode.yaml fixtures; each should call load_repo_config() and assert ConfigLoaderError. Also add cases for whitespace-only repository fields and overlap_tokens >= max_tokens, plus a success test loading the real packaged repos.yaml. In repos_validator_test.py, add case-only duplicate IDs/repositories so the intended casefold() behavior is locked down.


def test_whitespace_only_repository_id(self):
config_path = FIXTURES_DIR / "whitespace_id.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

def test_whitespace_only_owner(self):
config_path = FIXTURES_DIR / "whitespace_owner.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

def test_whitespace_only_repo(self):
config_path = FIXTURES_DIR / "whitespace_repo.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

def test_whitespace_only_branch(self):
config_path = FIXTURES_DIR / "whitespace_branch.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

def test_overlap_tokens_must_be_less_than_max_tokens(self):
config_path = FIXTURES_DIR / "invalid_overlap_tokens.yaml"

with self.assertRaisesRegex(ConfigLoaderError, "overlap_tokens"):
load_repo_config(config_path)

def test_load_packaged_repos_yaml(self):
config_path = (
Path(__file__).resolve().parents[2] / "utils" / "harvester" / "repos.yaml"
)

config = load_repo_config(config_path)

self.assertEqual(len(config.repositories), 2)
self.assertEqual(config.repositories[0].id, "owasp-asvs")
self.assertEqual(config.repositories[1].id, "owasp-cheatsheets")

def test_empty_owner(self):
config_path = FIXTURES_DIR / "empty_owner.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

def test_invalid_chunking_strategy(self):
config_path = FIXTURES_DIR / "invalid_chunking_strategy.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)

def test_invalid_polling_mode(self):
config_path = FIXTURES_DIR / "invalid_polling_mode.yaml"

with self.assertRaises(ConfigLoaderError):
load_repo_config(config_path)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repositories:
- id: duplicate-includes
type: github
enabled: true

owner: OWASP
repo: ASVS
branch: master

paths:
include:
- "docs/**/*.md"
- "docs/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200
overlap_tokens: 100

polling:
mode: incremental
interval_minutes: 60
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repositories:
- id: asvs
type: github
owner: OWASP
repo: ASVS

paths:
include:
- "4.0/en/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60

- id: asvs
type: github
owner: OWASP
repo: CheatSheetSeries

paths:
include:
- "cheatsheets/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repositories:
- id: asvs
type: github
owner: OWASP
repo: ASVS

paths:
include:
- "4.0/en/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60

- id: ASVS
type: github
owner: OWASP
repo: CheatSheetSeries

paths:
include:
- "cheatsheets/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repositories:
- id: asvs-1
type: github
owner: OWASP
repo: ASVS

paths:
include:
- "4.0/en/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60

- id: asvs-2
type: github
owner: OWASP
repo: ASVS

paths:
include:
- "4.0/en/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repositories:
- id: asvs-1
type: github
owner: OWASP
repo: ASVS

paths:
include:
- "4.0/en/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60

- id: asvs-2
type: github
owner: owasp
repo: asvs

paths:
include:
- "4.0/en/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repositories:
- id: asvs
type: github
owner: OWASP
repo: ASVS

paths:
include: []

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60
21 changes: 21 additions & 0 deletions application/tests/harvester_test/fixtures/empty_owner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repositories:
- id: empty-owner
type: github
enabled: true

owner: ""
repo: ASVS
branch: master

paths:
include:
- "docs/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200
overlap_tokens: 100

polling:
mode: incremental
interval_minutes: 60
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repositories:
- id: owasp-asvs

type: github
owner: OWASP
repo: ASVS

paths:
include:
- "4.0/en/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 0

polling:
mode: incremental
interval_minutes: 60
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repositories:
- id: invalid-strategy
type: github
enabled: true

owner: OWASP
repo: ASVS
branch: master

paths:
include:
- "docs/**/*.md"

chunking:
strategy: invalid_strategy
max_tokens: 1200
overlap_tokens: 100

polling:
mode: incremental
interval_minutes: 60
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repositories:
- type: github

owner: OWASP
repo: ASVS

paths:
include:
- "4.0/en/**/*.md"

chunking:
strategy: markdown_heading
max_tokens: 1200

polling:
mode: incremental
interval_minutes: 60
Loading
Loading