From f5a083365dbda8b32b297ab13e8c4b0d813bd612 Mon Sep 17 00:00:00 2001 From: Vinsy Moyya <186405436+vinsymoyya@users.noreply.github.com> Date: Sat, 14 Nov 2026 14:55:23 +0530 Subject: [PATCH 1/2] fix: validate spec delimiters and supported link paths --- README.md | 7 ++++ scripts/check-spec-links.sh | 23 ++++++++-- scripts/validate-specs.sh | 5 ++- tests/test_spec_scripts.py | 83 +++++++++++++++++++++++++++++++++++++ tile.json | 2 +- 5 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 tests/test_spec_scripts.py diff --git a/README.md b/README.md index 942ac4e..ac67be2 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/scripts/check-spec-links.sh b/scripts/check-spec-links.sh index a71cd23..f85f781 100755 --- a/scripts/check-spec-links.sh +++ b/scripts/check-spec-links.sh @@ -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 @@ -43,12 +44,25 @@ check_links() { if $in_targets; 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 @@ -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 diff --git a/scripts/validate-specs.sh b/scripts/validate-specs.sh index 46ceac0..e0f166b 100755 --- a/scripts/validate-specs.sh +++ b/scripts/validate-specs.sh @@ -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 @@ -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") diff --git a/tests/test_spec_scripts.py b/tests/test_spec_scripts.py new file mode 100644 index 0000000..a0a3c4c --- /dev/null +++ b/tests/test_spec_scripts.py @@ -0,0 +1,83 @@ +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_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() diff --git a/tile.json b/tile.json index 12b873f..27fecd2 100644 --- a/tile.json +++ b/tile.json @@ -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", From 0bb3631a73205616494fa6f0a1f1e03660aba5ca Mon Sep 17 00:00:00 2001 From: Vinsy Moyya <186405436+vinsymoyya@users.noreply.github.com> Date: Sat, 14 Nov 2026 16:45:42 +0530 Subject: [PATCH 2/2] fix: accept valid YAML target sequence indentation --- scripts/check-spec-links.sh | 2 +- scripts/validate-specs.sh | 2 +- tests/test_spec_scripts.py | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/check-spec-links.sh b/scripts/check-spec-links.sh index f85f781..fb460fa 100755 --- a/scripts/check-spec-links.sh +++ b/scripts/check-spec-links.sh @@ -42,7 +42,7 @@ 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 diff --git a/scripts/validate-specs.sh b/scripts/validate-specs.sh index e0f166b..5ec2186 100755 --- a/scripts/validate-specs.sh +++ b/scripts/validate-specs.sh @@ -62,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 diff --git a/tests/test_spec_scripts.py b/tests/test_spec_scripts.py index a0a3c4c..839e58d 100644 --- a/tests/test_spec_scripts.py +++ b/tests/test_spec_scripts.py @@ -40,6 +40,15 @@ def test_valid_spec(self): 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)