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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ GitHub Actions workflows (via [`tesslio/setup-tessl`](https://github.com/tesslio

Evals are run locally via `make eval` or `tessl eval run .` during development.

The spec validation scripts have a local regression suite that needs Python 3
and Bash, with no Tessl credentials required:

```bash
python3 -m unittest discover -s tests -v
```

## The Spec Format

Specs are markdown files (`.spec.md`) with YAML frontmatter:
Expand Down
25 changes: 20 additions & 5 deletions scripts/check-spec-links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ check_links() {
local in_frontmatter=false
local in_targets=false

while IFS= read -r line; do
while IFS= read -r line || [[ -n "$line" ]]; do
line="${line%$'\r'}"
if [[ "$line" == "---" ]]; then
if $in_frontmatter; then
break # End of frontmatter
Expand All @@ -41,14 +42,27 @@ check_links() {
continue
fi
if $in_targets; then
if [[ "$line" =~ ^[[:space:]]+-[[:space:]]+(.*) ]]; then
if [[ "$line" =~ ^[[:space:]]*-[[:space:]]+(.*) ]]; then
local target="${BASH_REMATCH[1]}"
# YAML permits quoted scalar paths; the quotes are not part of the path.
if [[ "$target" == \"*\" || "$target" == \'*\' ]]; then
target="${target:1:${#target}-2}"
fi
local resolved="$file_dir/$target"

# Check if it's a glob pattern
if [[ "$target" == *"*"* ]]; then
if [[ "$target" == *[\*\?\[]* ]]; then
local matches
matches=$(compgen -G "$resolved" 2>/dev/null | head -1 || true)
# Expand ** across zero or more directories. An empty IFS keeps
# paths containing spaces intact during pathname expansion.
matches=$(
shopt -s globstar nullglob
IFS=
paths=( $resolved )
if [ ${#paths[@]} -gt 0 ]; then
printf '%s\n' "${paths[0]}"
fi
)
if [ -z "$matches" ]; then
errors+=("target glob matches no files: $target")
fi
Expand All @@ -65,7 +79,8 @@ check_links() {
done < "$file"

# Check [@test] links in body
while IFS= read -r line; do
while IFS= read -r line || [[ -n "$line" ]]; do
line="${line%$'\r'}"
if [[ "$line" =~ \[@test\][[:space:]]*(.*) ]]; then
local test_path="${BASH_REMATCH[1]}"
# Strip trailing backtick if present
Expand Down
7 changes: 5 additions & 2 deletions scripts/validate-specs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ check_spec() {
# Check for frontmatter delimiters
local first_line
first_line=$(head -1 "$file")
first_line="${first_line%$'\r'}"
if [[ "$first_line" != "---" ]]; then
errors+=("Missing YAML frontmatter (no opening ---)")
for err in "${errors[@]}"; do
Expand All @@ -42,7 +43,9 @@ check_spec() {

# Extract frontmatter (between first and second ---)
local frontmatter
frontmatter=$(awk 'NR==1{next} /^---$/{exit} {print}' "$file")
if ! frontmatter=$(awk '{sub(/\r$/, "")} NR==1{next} /^---$/{closed=1; exit} {print} END{if (!closed) exit 1}' "$file"); then
errors+=("Missing closing YAML frontmatter delimiter (---)")
fi

if [ -z "$frontmatter" ]; then
errors+=("Empty or missing YAML frontmatter")
Expand All @@ -59,7 +62,7 @@ check_spec() {
else
# Check that targets has at least one entry
local target_count
target_count=$(echo "$frontmatter" | awk '/^targets:/{found=1; next} found && /^ - /{count++} found && /^[^ ]/{exit} END{print count+0}')
target_count=$(echo "$frontmatter" | awk '/^targets:/{found=1; next} found && /^[[:space:]]*-[[:space:]]+/{count++; next} found && /^[^[:space:]]/{exit} END{print count+0}')
if [ "$target_count" -eq 0 ]; then
errors+=("targets list is empty (at least one target required)")
fi
Expand Down
92 changes: 92 additions & 0 deletions tests/test_spec_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import os
import pathlib
import subprocess
import tempfile
import unittest


ROOT = pathlib.Path(__file__).resolve().parents[1]
BASH = os.environ.get('BASH', 'bash')


class SpecScriptsTest(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = pathlib.Path(self.temp.name)
self.specs = self.root / 'specs'
self.specs.mkdir()
(self.root / 'src').mkdir()
(self.root / 'src' / 'app.py').touch()
(self.root / 'test.py').touch()

def write_spec(self, targets='../src/app.py', body='', closing=True, newline='\n'):
text = '---\nname: Example\ndescription: Example behavior\ntargets:\n - ' + targets + '\n'
if closing:
text += '---\n'
text += body
(self.specs / 'example.spec.md').write_bytes(text.replace('\n', newline).encode())

def run_script(self, name, expected=0):
result = subprocess.run(
[BASH, (ROOT / 'scripts' / name).as_posix(), self.specs.as_posix()],
text=True, capture_output=True,
)
self.assertEqual(result.returncode, expected, result.stdout + result.stderr)
return result.stdout

def test_valid_spec(self):
self.write_spec(body='[@test] ../test.py\n')
self.run_script('validate-specs.sh')
self.run_script('check-spec-links.sh')

def test_target_sequences_accept_other_yaml_indentation(self):
for indentation in ['', ' ', ' ', ' ']:
with self.subTest(indentation=repr(indentation)):
self.write_spec()
spec = self.specs / 'example.spec.md'
spec.write_text(spec.read_text().replace(' - ', indentation + '- '))
self.run_script('validate-specs.sh')
self.run_script('check-spec-links.sh')

def test_requires_closing_frontmatter(self):
self.write_spec(closing=False)
self.run_script('validate-specs.sh', 1)

def test_crlf_frontmatter_and_links(self):
self.write_spec(body='[@test] ../test.py\n', newline='\r\n')
self.run_script('validate-specs.sh')
self.run_script('check-spec-links.sh')

def test_quoted_target_paths(self):
for quote in ['"', "'"]:
with self.subTest(quote=quote):
self.write_spec(targets=quote + '../src/app.py' + quote)
self.run_script('check-spec-links.sh')

def test_recursive_glob_includes_direct_and_deep_children(self):
self.write_spec(targets='../src/**/*.py')
self.run_script('check-spec-links.sh')
(self.root / 'src' / 'app.py').unlink()
deep = self.root / 'src' / 'one' / 'two'
deep.mkdir(parents=True)
(deep / 'app.py').touch()
self.run_script('check-spec-links.sh')

def test_question_mark_and_character_class_globs(self):
for target in ['../src/ap?.py', '../src/[a-z]pp.py']:
with self.subTest(target=target):
self.write_spec(targets=target)
self.run_script('check-spec-links.sh')

def test_missing_test_link_without_final_newline(self):
self.write_spec(body='[@test] ../missing.py')
self.run_script('check-spec-links.sh', 1)

def test_missing_targets_and_test_links_still_fail(self):
self.write_spec(targets='../missing/*.py', body='[@test] ../missing.py\n')
self.run_script('check-spec-links.sh', 1)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tile.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tessl-labs/spec-driven-development",
"version": "2.0.1",
"version": "2.0.2",
"summary": "Spec-driven workflow covering requirement gathering, spec authoring, implementation review, and verification — with skills, rules, and evaluation scenarios.",
"private": false,
"docs": "docs/index.md",
Expand Down