Skip to content
Open
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
282 changes: 282 additions & 0 deletions .continue/checks/tests/test_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
"""
Tests for .continue/checks agent instruction files.

Covers the PR changes:
- agentsmd-updater.md: newly added agent check file
- lighthouse-best-practice-analyzer.md: deleted file (must not exist)
"""

import os
import re

import pytest
import yaml

CHECKS_DIR = os.path.join(os.path.dirname(__file__), "..")
AGENTSMD_UPDATER_PATH = os.path.join(CHECKS_DIR, "agentsmd-updater.md")
LIGHTHOUSE_ANALYZER_PATH = os.path.join(
CHECKS_DIR, "lighthouse-best-practice-analyzer.md"
)


def parse_frontmatter(filepath):
"""Parse YAML frontmatter and body from a markdown file.

Returns (frontmatter_dict, body_str) or raises ValueError if frontmatter
is missing or malformed.
"""
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()

if not content.startswith("---"):
raise ValueError(f"File {filepath} does not start with YAML frontmatter '---'")

# Match the opening and closing --- delimiters
match = re.match(r"^---\n(.*?)\n---\n?(.*)", content, re.DOTALL)
if not match:
raise ValueError(f"File {filepath} has malformed YAML frontmatter")

frontmatter_str, body = match.group(1), match.group(2)
frontmatter = yaml.safe_load(frontmatter_str)
return frontmatter, body


# ---------------------------------------------------------------------------
# agentsmd-updater.md – file existence
# ---------------------------------------------------------------------------


class TestAgentsmdUpdaterExists:
def test_file_exists(self):
"""agentsmd-updater.md must be present after the PR."""
assert os.path.isfile(AGENTSMD_UPDATER_PATH), (

Check warning on line 52 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L52

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 HIGH RISK

This file triggers 30 instances of Bandit B101 due to the use of 'assert'. While these are false positives in a unit test context, they are blocking the PR's quality gate. Suppress these warnings using '# nosec' or configure your linter to ignore the tests directory to resolve the 'Not Up to Standards' status.

See Issue in Codacy

f"Expected {AGENTSMD_UPDATER_PATH} to exist"
)

def test_file_is_not_empty(self):
"""agentsmd-updater.md must contain content."""
assert os.path.getsize(AGENTSMD_UPDATER_PATH) > 0, (

Check warning on line 58 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L58

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"agentsmd-updater.md must not be empty"
)


# ---------------------------------------------------------------------------
# agentsmd-updater.md – YAML frontmatter structure
# ---------------------------------------------------------------------------


class TestAgentsmdUpdaterFrontmatter:
def setup_method(self):
self.frontmatter, self.body = parse_frontmatter(AGENTSMD_UPDATER_PATH)

def test_frontmatter_is_parseable(self):
"""File must have valid YAML frontmatter delimited by ---."""
assert self.frontmatter is not None

Check warning on line 74 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L74

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

def test_frontmatter_has_name_field(self):
"""Frontmatter must contain a 'name' key."""
assert "name" in self.frontmatter, (

Check warning on line 78 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L78

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"agentsmd-updater.md frontmatter must contain a 'name' field"
)

def test_name_field_value(self):
"""'name' field must be 'agentsmd-updater'."""
assert self.frontmatter["name"] == "agentsmd-updater", (

Check warning on line 84 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L84

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
f"Expected name='agentsmd-updater', got '{self.frontmatter['name']}'"
)

def test_frontmatter_has_no_extra_required_fields(self):
"""Frontmatter should only contain the 'name' field (minimal definition)."""
# The agentsmd-updater check deliberately uses a minimal frontmatter.
# If new mandatory fields are added this test should be updated.
assert set(self.frontmatter.keys()) == {"name"}, (

Check warning on line 92 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L92

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ LOW RISK

This assertion restricts the YAML frontmatter to only the 'name' key. This will break if optional fields like 'description' or 'version' are added later. Suggest removing the 'test_frontmatter_has_no_extra_required_fields' check.

f"Unexpected frontmatter fields: {set(self.frontmatter.keys()) - {'name'}}"
)

def test_name_is_string(self):
"""'name' value must be a non-empty string."""
assert isinstance(self.frontmatter["name"], str)

Check warning on line 98 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L98

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert len(self.frontmatter["name"]) > 0

Check warning on line 99 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L99

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


# ---------------------------------------------------------------------------
# agentsmd-updater.md – instruction body content
# ---------------------------------------------------------------------------


class TestAgentsmdUpdaterBody:
def setup_method(self):
_, self.body = parse_frontmatter(AGENTSMD_UPDATER_PATH)

def test_body_is_not_empty(self):
"""Instruction body must not be empty."""
assert self.body.strip(), "Instruction body must contain text"

Check warning on line 113 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L113

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

def test_body_references_agents_md(self):
"""Instructions must mention the AGENTS.md target file."""
assert "AGENTS.md" in self.body, (

Check warning on line 117 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L117

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must reference the AGENTS.md file"
)

def test_body_mentions_pull_request(self):
"""Instructions must reference pull request context."""
assert "pull request" in self.body.lower(), (

Check warning on line 123 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L123

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must mention 'pull request'"
)

def test_body_mentions_build_steps(self):
"""Instructions must tell the agent to look for build steps."""
assert "build steps" in self.body.lower(), (

Check warning on line 129 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L129

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must mention 'build steps'"
)

def test_body_mentions_dependencies(self):
"""Instructions must tell the agent to look for dependency changes."""
assert "dependencies" in self.body.lower(), (

Check warning on line 135 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L135

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must mention 'dependencies'"
)

def test_body_mentions_environment_variables(self):
"""Instructions must tell the agent to look for environment variables."""
assert "environment variables" in self.body.lower(), (

Check warning on line 141 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L141

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must mention 'environment variables'"
)

def test_body_restricts_modifications_to_agents_md_only(self):
"""Instructions must explicitly forbid modifying other files."""
assert "do not modify any other file" in self.body.lower(), (

Check warning on line 147 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L147

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must contain 'Do not modify any other file'"
)

def test_body_mentions_repo_root(self):
"""Instructions must reference placing AGENTS.md in the root directory."""
assert "root" in self.body.lower(), (

Check warning on line 153 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L153

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must reference the repository root directory"
)

def test_body_mentions_missing_file_creation(self):
"""Instructions must describe behaviour when AGENTS.md is absent."""
assert "missing" in self.body.lower() or "create" in self.body.lower(), (

Check warning on line 159 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L159

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must handle the case where AGENTS.md does not yet exist"
)

def test_body_mentions_scripts(self):
"""Instructions must tell the agent to look for script changes."""
assert "scripts" in self.body.lower(), (

Check warning on line 165 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L165

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must mention 'scripts'"
)

def test_body_mentions_workflows(self):
"""Instructions must tell the agent to look for workflow changes."""
assert "workflows" in self.body.lower(), (

Check warning on line 171 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L171

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must mention 'workflows'"
)

def test_body_mentions_preserving_existing_info(self):
"""Instructions must tell the agent to preserve existing relevant content."""
# The instruction says "Preserve all existing relevant information"
assert "preserve" in self.body.lower() or "existing" in self.body.lower(), (

Check warning on line 178 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L178

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must tell the agent to preserve existing information"
)

def test_body_is_single_paragraph(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ LOW RISK

Nitpick: This test only verifies the absence of Markdown headings. To enforce a 'single paragraph' requirement as stated in the PR summary, it should also verify the absence of double newlines ('\n\n').

"""The instruction body should be a concise single paragraph (no headings)."""
# The agentsmd-updater instruction is intentionally minimal - no markdown
# headings, no bullet lists, just a plain prose instruction.
stripped = self.body.strip()
assert not re.search(r"^#{1,6}\s", stripped, re.MULTILINE), (

Check warning on line 187 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L187

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"agentsmd-updater instruction body should not contain markdown headings"
)

def test_body_does_not_start_with_whitespace_line(self):
"""Body content after frontmatter should start without a leading blank line."""
# Acceptable: body may start with a single newline coming from the ---
# separator, but should have actual content.
assert self.body.strip()

Check warning on line 195 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L195

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


# ---------------------------------------------------------------------------
# lighthouse-best-practice-analyzer.md – deletion validation
# ---------------------------------------------------------------------------


class TestLighthouseAnalyzerDeleted:
def test_file_does_not_exist(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

Verifying the absence of files and searching for naming variants depends on the developer's local filesystem state. Untracked or stale files can lead to false positives. Consider removing the 'TestLighthouseAnalyzerDeleted' class; these checks are better handled by CI linting of the repository's git diff.

"""lighthouse-best-practice-analyzer.md must have been deleted by the PR."""
assert not os.path.exists(LIGHTHOUSE_ANALYZER_PATH), (

Check warning on line 206 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L206

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
f"{LIGHTHOUSE_ANALYZER_PATH} should have been deleted but still exists"
)

def test_no_lighthouse_analyzer_variants_exist(self):
"""No variant filenames for the lighthouse analyzer should exist."""
checks_dir = CHECKS_DIR
for filename in os.listdir(checks_dir):
if not os.path.isfile(os.path.join(checks_dir, filename)):
continue
lower = filename.lower()
assert not (

Check warning on line 217 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L217

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"lighthouse" in lower and "analyzer" in lower
), (
f"Found unexpected lighthouse analyzer file: {filename}"
)


# ---------------------------------------------------------------------------
# Regression / boundary tests
# ---------------------------------------------------------------------------


class TestAgentsmdUpdaterRegression:
def test_file_uses_unix_line_endings(self):
"""File should use LF line endings (not CRLF)."""
with open(AGENTSMD_UPDATER_PATH, "rb") as f:
raw = f.read()
assert b"\r\n" not in raw, (

Check warning on line 234 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L234

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"agentsmd-updater.md must use LF (Unix) line endings, not CRLF"
)

def test_file_is_utf8_encoded(self):
"""File must be valid UTF-8."""
with open(AGENTSMD_UPDATER_PATH, "rb") as f:
raw = f.read()
try:
raw.decode("utf-8")
except UnicodeDecodeError as exc:
pytest.fail(f"agentsmd-updater.md is not valid UTF-8: {exc}")

def test_name_has_no_leading_trailing_whitespace(self):
"""'name' value must not have leading or trailing whitespace."""
frontmatter, _ = parse_frontmatter(AGENTSMD_UPDATER_PATH)
name = frontmatter.get("name", "")
assert name == name.strip(), (

Check warning on line 251 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L251

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
f"'name' value has surrounding whitespace: '{name}'"
)

def test_name_uses_kebab_case(self):
"""'name' should use kebab-case (lowercase letters and hyphens only)."""
frontmatter, _ = parse_frontmatter(AGENTSMD_UPDATER_PATH)
name = frontmatter.get("name", "")
assert re.match(r"^[a-z][a-z0-9-]*$", name), (

Check warning on line 259 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L259

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
f"'name' value '{name}' should be kebab-case"
)

def test_body_mentions_code_style(self):
"""Instructions must mention code style as a trackable concern."""
_, body = parse_frontmatter(AGENTSMD_UPDATER_PATH)
assert "code style" in body.lower(), (

Check warning on line 266 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L266

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must mention 'code style'"
)

def test_body_mentions_architectures(self):
"""Instructions must mention architecture changes."""
_, body = parse_frontmatter(AGENTSMD_UPDATER_PATH)
assert "architect" in body.lower(), (

Check warning on line 273 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L273

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must mention 'architecture' or related term"
)

def test_instruction_addresses_ai_coding_agent(self):
"""Instructions should explicitly target AI coding agents."""
_, body = parse_frontmatter(AGENTSMD_UPDATER_PATH)
assert "agent" in body.lower(), (

Check warning on line 280 in .continue/checks/tests/test_checks.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.continue/checks/tests/test_checks.py#L280

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
"Instruction must reference 'agent' (automated agent context)"
)