-
Notifications
You must be signed in to change notification settings - Fork 2
test: add comprehensive branch name validation tests #2551
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
Changes from all commits
2928921
03903c1
bdc5058
68399dd
9071932
b7ceb64
f8d2586
2ede9ca
1439c78
9d6505a
1a0ab44
2612b57
8ea33e3
6861f5b
bbd488a
96e58b4
ce5e1b6
ee681f1
8450c74
23e8fc8
e345267
11da54a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,8 @@ For all repos (client, product, infra, etc.), use: | |
| - `ux/` — user experience | ||
| - `i18n/` — internationalization | ||
| - `ops/` — operations | ||
| - `audit/` — governance audits and compliance reviews | ||
| - `codex/` — codex, knowledge base, or reference documentation | ||
|
|
||
| ### 3.2 Product-specific Prefixes (optional) | ||
|
|
||
|
|
@@ -123,10 +125,43 @@ hotfix/ga4-purchase-duplicate | |
|
|
||
| Use a single regex in a workflow to enforce naming discipline: | ||
|
|
||
| **Non-release branches:** | ||
|
|
||
| ```regex | ||
| ^(feat|fix|hotfix|refactor|chore|docs|test|perf|ci|build|deps|security|revert|research|design|a11y|ux|i18n|ops|proto|ds|api|schema|telemetry|content|seo|config|migrate|qa|uat|audit|codex)/[a-z0-9]+(?:-[a-z0-9]+)*-[a-z0-9]+(?:-[a-z0-9]+)*$ | ||
| ``` | ||
|
|
||
| **Release branches (semantic versioning):** | ||
|
|
||
| ```regex | ||
| ^release/v?\d+\.\d+\.\d+(-[a-z0-9]+)*$ | ||
| ``` | ||
|
|
||
| **Release branches (standard format):** | ||
|
|
||
| ```regex | ||
| ^(feat|fix|hotfix|release|refactor|chore|docs|test|perf|ci|build|deps|security|revert|research|design|a11y|ux|i18n|ops|proto|ds|api|schema|telemetry|content|seo|config|migrate|qa|uat)/[a-z0-9._-]+$ | ||
| ^release/[a-z0-9]+(?:-[a-z0-9]+)*-[a-z0-9]+(?:-[a-z0-9]+)*$ | ||
| ``` | ||
|
|
||
| **For exact patterns, see the authoritative validator:** `scripts/validation/validate-branch-name.cjs` (lines 66-78) | ||
|
|
||
| ### 4.1 Forbidden Prefixes (AI Agent Governance) | ||
|
|
||
| The following prefixes are **strictly forbidden** for all branches to enforce proper governance of AI-assisted development: | ||
|
|
||
| - `claude/` — Reserved for governance audits only; blocks automated routing | ||
| - `copilot/` — GitHub Copilot-specific branches not permitted | ||
| - `openai/` — OpenAI-related work must use appropriate type prefixes | ||
|
|
||
| **Rationale:** Forbidden prefixes act as circuit-breakers for AI agents (Claude Code, GitHub Copilot). When detected, they trigger fallback routing to default PR templates and prevent type-based automation. This ensures: | ||
|
|
||
| - AI agents cannot bypass branch naming governance | ||
| - Explicit type prefixes drive proper automation routing | ||
| - Governance audits are tracked and auditable | ||
| - No silent acceptance of non-conforming branch names | ||
|
|
||
| **Enforcement:** CI will reject any branch matching `claude/`, `copilot/`, or `openai/` prefixes, even if followed by valid scope-title patterns. | ||
|
|
||
| Example workflow (`.github/workflows/validate-branch-name.yml`): | ||
|
|
||
| ```yaml | ||
|
|
@@ -143,8 +178,12 @@ jobs: | |
| BRANCH="${{ github.head_ref }}" | ||
| # Allow dependabot/renovate | ||
| if [[ "$BRANCH" =~ ^(dependabot|renovate)/ ]]; then exit 0; fi | ||
| if [[ ! "$BRANCH" =~ ^(feat|fix|hotfix|release|refactor|chore|docs|test|perf|ci|build|deps|security|revert|research|design|a11y|ux|i18n|ops|proto|ds|api|schema|telemetry|content|seo|config|migrate|qa|uat)/[a-z0-9._-]+$ ]]; then | ||
| echo "❌ Branch '$BRANCH' must match the required pattern." | ||
| # Allow release branches with semantic versioning | ||
| if [[ "$BRANCH" =~ ^release/v?[0-9]+\.[0-9]+\.[0-9]+ ]]; then exit 0; fi | ||
| # Standard pattern: {type}/{scope}-{title} | ||
| if [[ ! "$BRANCH" =~ ^(feat|fix|hotfix|release|refactor|chore|docs|test|perf|ci|build|deps|security|revert|research|design|a11y|ux|i18n|ops|proto|ds|api|schema|telemetry|content|seo|config|migrate|qa|uat|audit|codex)/[a-z0-9]+(-[a-z0-9]+)*-[a-z0-9]+(-[a-z0-9]+)*$ ]]; then | ||
| echo "❌ Branch '$BRANCH' must match the pattern: {type}/{scope}-{title}" | ||
| echo "Example: feat/user-auth-login" | ||
| exit 1 | ||
| fi | ||
| ``` | ||
|
|
@@ -154,6 +193,33 @@ jobs: | |
| - For monorepos, ensure branch naming applies to each package/subproject, or use a consistent prefix (e.g. `feat/frontend-...`, `fix/api-...`). | ||
| - For forked repos, always clean up branches after merging upstream PRs, and avoid duplicating branch names across forks to prevent confusion. | ||
|
|
||
| ### 4.3 PR Template Routing & Fallback Behavior | ||
|
|
||
| PR template selection is automatically routed based on branch type prefix: | ||
|
|
||
| | Branch Type | PR Template | | ||
| |---|---| | ||
| | `feat/` | `pr_feature.md` | | ||
| | `fix/` | `pr_bug.md` | | ||
| | `hotfix/` | `pr_hotfix.md` | | ||
| | `release/` | `pr_release.md` | | ||
| | `refactor/` | `pr_refactor.md` | | ||
| | `chore/` | `pr_chore.md` | | ||
| | `docs/` | `pr_docs.md` | | ||
| | `ci/` | `pr_ci.md` | | ||
| | `deps/` | `pr_dep_update.md` | | ||
| | `audit/` | `pr_chore.md` (governance review) | | ||
| | `codex/` | `pr_docs.md` (knowledge base) | | ||
| | Other types | `pr_chore.md` (default) | | ||
| | Forbidden prefixes | `pr_chore.md` (fallback) | | ||
|
|
||
| **Fallback Logic:** If a branch uses a forbidden prefix (e.g., `claude/governance-audit-implementation`), the PR template resolver detects the violation and routes to the default `pr_chore.md` template. This ensures: | ||
|
|
||
| - No PR is left without template guidance | ||
| - Forbidden prefixes trigger visible fallback routing (auditable) | ||
| - Authors are prompted to re-open PR with proper branch naming | ||
| - Type detection hierarchy: branch type → linked issue type → default | ||
|
Comment on lines
+216
to
+221
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 8 'pr-template-resolver|claude/|copilot/|openai/|pr_chore\.md|linked issue type|routes:' .github scripts agentsRepository: lightspeedwp/.github Length of output: 50379 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- repository guidance ---'
find /tmp/coderabbit-repo-knowledge/lightspeedwp-github-64c92c82 -maxdepth 2 -type f -name '*.md' -print \
| sort \
| while read -r f; do
case "$f" in
*/learnings/*|*/architecture/*|*/repository-conventions/*|*/conventions/*) printf '%s\n' "$f";;
esac
done
for f in /tmp/coderabbit-repo-knowledge/lightspeedwp-github-64c92c82/*/*.md; do
[ -f "$f" ] || continue
printf '\n--- %s ---\n' "$f"
head -80 "$f"
done
printf '%s\n' '--- resolver workflow ---'
sed -n '1,190p' .github/workflows/pr-template-resolver.yml
printf '%s\n' '--- template config ---'
sed -n '1,120p' .github/PULL_REQUEST_TEMPLATE/config.yml
printf '%s\n' '--- documented section ---'
sed -n '170,215p' docs/BRANCHING_STRATEGY.md
printf '%s\n' '--- branch validator contract ---'
sed -n '1,180p' scripts/validation/validate-branch-name.cjsRepository: lightspeedwp/.github Length of output: 50376 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- resolver workflow: mapping and resolution ---'
sed -n '1,125p' .github/workflows/pr-template-resolver.yml
printf '%s\n' '--- resolver workflow: outputs and fallback use ---'
sed -n '125,180p' .github/workflows/pr-template-resolver.yml
printf '%s\n' '--- template config: relevant entries ---'
nl -ba .github/PULL_REQUEST_TEMPLATE/config.yml | sed -n '55,90p'
printf '%s\n' '--- documented fallback section ---'
nl -ba docs/BRANCHING_STRATEGY.md | sed -n '185,205p'
printf '%s\n' '--- relevant repository conventions ---'
for f in \
/tmp/coderabbit-repo-knowledge/lightspeedwp-github-64c92c82/conventions/repo-wide.md \
/tmp/coderabbit-repo-knowledge/lightspeedwp-github-64c92c82/conventions/github-pull-request-template.md \
/tmp/coderabbit-repo-knowledge/lightspeedwp-github-64c92c82/learnings/repo-wide.md
do
printf '\n--- %s ---\n' "$f"
cat "$f"
doneRepository: lightspeedwp/.github Length of output: 7405 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- template config ---'
sed -n '1,110p' .github/PULL_REQUEST_TEMPLATE/config.yml
printf '%s\n' '--- documented fallback section ---'
sed -n '185,205p' docs/BRANCHING_STRATEGY.md
printf '%s\n' '--- branch validator ---'
sed -n '1,180p' scripts/validation/validate-branch-name.cjs
printf '%s\n' '--- resolver/config references only ---'
rg -n -C 3 'claude/|copilot/|openai/|defaultTemplate|typeToTemplate|branchName|config\.yml' \
.github/workflows/pr-template-resolver.yml \
.github/PULL_REQUEST_TEMPLATE/config.yml \
docs/BRANCHING_STRATEGY.md \
scripts/validation/validate-branch-name.cjsRepository: lightspeedwp/.github Length of output: 24878 Align the documented fallback with the resolver workflow. The resolver does not check the branch prefix and does not read 🤖 Prompt for AI Agents |
||
|
|
||
| --- | ||
|
|
||
| ## 5. Prefixes Drive Automation | ||
|
|
@@ -197,6 +263,8 @@ Ensure `.github/labeler.yml` seeds new PRs with `status:needs-review` when appro | |
| "^migrate/.*", | ||
| "^qa/.*", | ||
| "^uat/.*", | ||
| "^audit/.*", | ||
| "^codex/.*", | ||
| ] | ||
| ``` | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| --- | ||
| file_type: "documentation" | ||
| name: "Frontmatter Validation" | ||
| description: "Comprehensive frontmatter validation scripts for LightSpeedWP .github repository ensuring schema compliance and consistency" | ||
| version: "1.0.0" | ||
| last_updated: "2025-12-04" | ||
| name: "Validation Scripts & Tests" | ||
| description: "Comprehensive validation scripts and tests for frontmatter, JSON, YAML, and branch naming in LightSpeedWP .github repository ensuring schema compliance and governance" | ||
| version: "1.1.0" | ||
| last_updated: "2026-08-30" | ||
| owners: | ||
| - "LightSpeedWP Team" | ||
| tags: | ||
|
|
@@ -12,10 +12,12 @@ tags: | |
| - "schema" | ||
| - "testing" | ||
| - "automation" | ||
| - "branch-governance" | ||
| apply_to: | ||
| - "repository maintenance" | ||
| - "documentation standards" | ||
| - "quality assurance" | ||
| - "branch naming governance" | ||
| --- | ||
|
|
||
|
|
||
|
|
@@ -34,9 +36,15 @@ The validation system provides automated checking of: | |
| All schema files are stored in `../../.schemas/`. | ||
|
|
||
| ```mermaid | ||
| --- | ||
| config: | ||
| theme: default | ||
| look: handDrawn | ||
| layout: elk | ||
| accTitle: Validation System Flow | ||
| accDescr: Flowchart showing file discovery through log output with configuration, schema, and pattern inputs | ||
| --- | ||
|
Comment on lines
+39
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: printf '%s\n' '--- repository conventions ---'
find /tmp/coderabbit-repo-knowledge/lightspeedwp-github-64c92c82 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- README excerpt ---'
sed -n '1,110p' scripts/validation/README.md
printf '%s\n' '--- Mermaid/package references ---'
rg -n -i 'mermaid|`@mermaid`|accTitle|accDescr|validation/README' package.json package-lock.json yarn.lock pnpm-lock.yaml scripts/validation .github 2>/dev/null | head -160Repository: lightspeedwp/.github Length of output: 26500 🏁 Script executed: printf '%s\n' '--- Mermaid repository contract ---'
sed -n '30,75p' .github/instructions/mermaid.instructions.md
printf '%s\n' '--- accessibility validator contract ---'
sed -n '85,135p' scripts/validation/validate-mermaid-accessibility.js
printf '%s\n' '--- syntax validator handling ---'
sed -n '65,90p' scripts/validation/validate-mermaid-syntax.jsRepository: lightspeedwp/.github Length of output: 4291 Move 🤖 Prompt for AI AgentsSource: MCP tools |
||
| graph TD | ||
| accTitle: Frontmatter validation pipeline | ||
| accDescr: Top-down graph showing the frontmatter validation pipeline from discovery through report generation | ||
| A[File Discovery] --> B[Frontmatter Extraction] | ||
| B --> C[Schema Validation] | ||
| C --> D[LightSpeed Rules Check] | ||
|
|
@@ -63,6 +71,7 @@ graph TD | |
| ## Test Files | ||
|
|
||
| - **`__tests__/validate-frontmatter.test.js`** — Test suite for frontmatter validation | ||
| - **`__tests__/validate-branch-names.test.js`** — Jest test suite for branch name validation (34 allowed types, forbidden prefix rejection, format validation) | ||
| - **`validate-coderabbit-yml.test.js`** — Jest test suite for the CodeRabbit YAML validator | ||
|
|
||
| ## Features | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.