#!/usr/bin/env bash
set -euo pipefail

export CARBON_ANALYTICS=off

PLUGIN_ROOT="$(cd "$(dirname "$0")/.." && pwd)"

test -f "$PLUGIN_ROOT/.codex-plugin/plugin.json"
test -f "$PLUGIN_ROOT/.claude-plugin/plugin.json"
test -f "$PLUGIN_ROOT/.cursor-plugin/plugin.json"
test -f "$PLUGIN_ROOT/plugin.json"
test -f "$PLUGIN_ROOT/mcp.json"
test -f "$PLUGIN_ROOT/.mcp.json"
test ! -e "$PLUGIN_ROOT/.mcp.claude.json"
test -f "$PLUGIN_ROOT/package.json"
test -f "$PLUGIN_ROOT/MCP_SERVER.md"
test -f "$PLUGIN_ROOT/bin/carbon-mcp.mjs"
test -f "$PLUGIN_ROOT/mcp-configs/mcp.json"
test -f "$PLUGIN_ROOT/mcp-configs/codex.toml"
test -f "$PLUGIN_ROOT/server/index.js"
test -f "$PLUGIN_ROOT/ui/settings.html"
test -f "$PLUGIN_ROOT/ui/tests.html"
test -f "$PLUGIN_ROOT/ui/human.html"
test -f "$PLUGIN_ROOT/ui/feedback.html"
test -f "$PLUGIN_ROOT/ui/execution-plan.html"
test -f "$PLUGIN_ROOT/assets/icon.png"
test -f "$PLUGIN_ROOT/skills/carbon/assets/carbon-mark.svg"
test -f "$PLUGIN_ROOT/skills/carbon/assets/carbon-logo.svg"
cmp -s "$PLUGIN_ROOT/skills/carbon/assets/carbon-mark.svg" "$PLUGIN_ROOT/skills/carbon/assets/carbon-logo.svg"
rg -q '<rect width="256" height="256" fill="#000000"/>' "$PLUGIN_ROOT/skills/carbon/assets/carbon-mark.svg"
rg -q 'fill="#ffffff"' "$PLUGIN_ROOT/skills/carbon/assets/carbon-mark.svg"
if rg -q '#F59E0B|testers\.ai|>6<' "$PLUGIN_ROOT/skills/carbon/assets/carbon-mark.svg"; then
  echo "FAIL: CARBON icon contains deprecated branding details" >&2
  exit 1
fi
test -f "$PLUGIN_ROOT/TESTING_GUIDE.md"
test -f "$PLUGIN_ROOT/COMMANDS.md"
test -f "$PLUGIN_ROOT/references/testing-ai-methods.md"
test -f "$PLUGIN_ROOT/scripts/persona-roster-contract-test.mjs"
test -f "$PLUGIN_ROOT/scripts/specialist-domain-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/fathom-analytics-contract-test.mjs"
test -f "$PLUGIN_ROOT/scripts/confidence-smoke-test.cjs"
test -f "$PLUGIN_ROOT/scripts/carbon-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/framework-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/harness-positioning-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/intent-library-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/evidence-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/persona-exploration-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/runtime-architecture-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/install-claude-aliases.py"
test -f "$PLUGIN_ROOT/scripts/claude-alias-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/configure-claude-plugin-skills.py"
test -f "$PLUGIN_ROOT/scripts/claude-package-command-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/plugin-standard-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/package-standard-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/advisor-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/workspace-onboarding-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/import-bake-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/execution-context-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/settings-ui-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/integration-contract-test.mjs"
test -f "$PLUGIN_ROOT/scripts/promotion-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/execution-plan-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/quality-confidence-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/intelligence-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/stats-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/report-brand-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/historical-report-migration-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/browser-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/vibium-compat-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/schema-governance-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/mobile-html-contract-test.py"
test -f "$PLUGIN_ROOT/bin/carbon-confidence-init"
test -f "$PLUGIN_ROOT/skills/carbon-confidence/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-help/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-help/agents/openai.yaml"
test -f "$PLUGIN_ROOT/skills/carbon-demo/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-stats/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-stats/agents/openai.yaml"
test -f "$PLUGIN_ROOT/skills/carbon-generate/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-generate/agents/openai.yaml"
test -f "$PLUGIN_ROOT/skills/carbon-tests/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-tests/agents/openai.yaml"
test -f "$PLUGIN_ROOT/runtime/carbon/references/intent-test-contract.md"
test -f "$PLUGIN_ROOT/skills/carbon-settings/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-settings/agents/openai.yaml"
test -f "$PLUGIN_ROOT/skills/carbon-release/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-browser/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-browser/agents/openai.yaml"
test -f "$PLUGIN_ROOT/skills/carbon-test/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-accessibility/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-privacy/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-security/SKILL.md"
test -f "$PLUGIN_ROOT/runtime/carbon/references/classic-browser-capabilities.md"
test -f "$PLUGIN_ROOT/skills/carbon-human/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-human/agents/openai.yaml"
test -f "$PLUGIN_ROOT/skills/carbon-feedback/SKILL.md"
test -f "$PLUGIN_ROOT/skills/carbon-feedback/agents/openai.yaml"
test -x "$PLUGIN_ROOT/bin/carbon-runtime"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_run.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_plan_view.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_learn.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_record.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_auto.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_framework.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_intent.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_evidence.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_advisor.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_workspace.py"
test -f "$PLUGIN_ROOT/runtime/carbon/references/workspace-onboarding.md"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_bake.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_context.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_quality_confidence.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_intelligence.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_stats.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_human.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_feedback.py"
test -f "$PLUGIN_ROOT/runtime/carbon/references/human-decision-context.md"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_demo.py"
test -f "$PLUGIN_ROOT/runtime/carbon/demo-fixtures/manifest.json"
test -f "$PLUGIN_ROOT/runtime/carbon/references/intelligence-layer.md"
test -f "$PLUGIN_ROOT/runtime/carbon/references/specialists.json"
test -f "$PLUGIN_ROOT/runtime/carbon/references/testing-domains.json"
test -f "$PLUGIN_ROOT/runtime/carbon/references/wcag22-criteria.json"
test -f "$PLUGIN_ROOT/runtime/carbon/references/acr-reporting.json"
test -f "$PLUGIN_ROOT/assets/specialists/pete-gray.jpg"
test -f "$PLUGIN_ROOT/assets/specialists/alejandro-gray.jpg"
test -f "$PLUGIN_ROOT/assets/specialists/hiroshi-gray.jpg"
test -f "$PLUGIN_ROOT/runtime/carbon/benchmarks/seeded-defects/manifest.json"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_browser.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_vibium.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_command_report.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_report_visuals.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_command_progress.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_promotions.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_chatbot.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_ai_upgrade.py"
test -f "$PLUGIN_ROOT/runtime/carbon/scripts/carbon_failure.py"
test -f "$PLUGIN_ROOT/runtime/carbon/templates/carbon_ai_visual_check.py"
test -f "$PLUGIN_ROOT/runtime/carbon/references/ai-upgrade-visual-checks.md"
test -f "$PLUGIN_ROOT/skills/chatbot/SKILL.md"
test -f "$PLUGIN_ROOT/runtime/carbon/references/chatbot-testing.md"
test -f "$PLUGIN_ROOT/scripts/chatbot-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/ai-upgrade-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/failure-contract-test.py"
test -f "$PLUGIN_ROOT/runtime/carbon/references/command-result-reporting.md"
test -f "$PLUGIN_ROOT/scripts/command-report-contract-test.py"
test -f "$PLUGIN_ROOT/runtime/carbon/references/command-start-preview.md"
test -f "$PLUGIN_ROOT/scripts/command-start-preview-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/command-progress-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/command-progress-demo-contract-test.py"
test -f "$PLUGIN_ROOT/scripts/run-command-progress-demo.py"
test -f "$PLUGIN_ROOT/ui/command-progress.html"
test -f "$PLUGIN_ROOT/runtime/carbon/references/browser/carbon-browser-v1.json"
test -f "$PLUGIN_ROOT/runtime/carbon/references/browser/carbon-browser-v1.md"
test -f "$PLUGIN_ROOT/runtime/carbon/references/execution/global-context.md"
test -f "$PLUGIN_ROOT/runtime/carbon/references/automatic-framework.md"
test -f "$PLUGIN_ROOT/runtime/carbon/references/api-first-testing.md"

skill_count="$(find "$PLUGIN_ROOT/skills" -mindepth 2 -maxdepth 2 -name SKILL.md | wc -l | tr -d ' ')"
test "$skill_count" = "44"

if rg -n '\[TODO:' "$PLUGIN_ROOT" --glob '!**/verify-install.sh'; then
  echo "FAIL: unfinished placeholders remain" >&2
  exit 1
fi

node --check "$PLUGIN_ROOT/server/index.js"
node --check "$PLUGIN_ROOT/bin/carbon-mcp.mjs"
node --check "$PLUGIN_ROOT/scripts/persona-roster-contract-test.mjs"
node --check "$PLUGIN_ROOT/scripts/fathom-analytics-contract-test.mjs"
node --check "$PLUGIN_ROOT/scripts/mcp-smoke-test.mjs"
node --check "$PLUGIN_ROOT/scripts/integration-contract-test.mjs"
node --check "$PLUGIN_ROOT/scripts/cloud-contract-test.mjs"
node --check "$PLUGIN_ROOT/scripts/confidence-smoke-test.cjs"
node "$PLUGIN_ROOT/scripts/persona-roster-contract-test.mjs"
node "$PLUGIN_ROOT/scripts/fathom-analytics-contract-test.mjs"
node "$PLUGIN_ROOT/scripts/mcp-smoke-test.mjs"
CARBON_MCP_SERVER_PATH="$PLUGIN_ROOT/bin/carbon-mcp.mjs" node "$PLUGIN_ROOT/scripts/mcp-smoke-test.mjs"
node "$PLUGIN_ROOT/scripts/integration-contract-test.mjs"
node "$PLUGIN_ROOT/scripts/cloud-contract-test.mjs"
node "$PLUGIN_ROOT/scripts/confidence-smoke-test.cjs"
python3 "$PLUGIN_ROOT/scripts/carbon-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/demo-fixture-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/framework-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/harness-positioning-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/intent-library-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/evidence-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/persona-exploration-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/specialist-domain-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/advisor-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/workspace-onboarding-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/testing-doctrine-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/human-context-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/feedback-context-contract-test.py"
node "$PLUGIN_ROOT/scripts/feedback-private-service-contract-test.mjs"
python3 "$PLUGIN_ROOT/scripts/import-bake-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/execution-context-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/settings-ui-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/promotion-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/execution-plan-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/quality-confidence-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/intelligence-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/stats-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/report-brand-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/historical-report-migration-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/command-report-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/command-start-preview-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/command-progress-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/command-progress-demo-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/chatbot-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/ai-upgrade-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/failure-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/browser-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/vibium-compat-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/schema-governance-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/mobile-html-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/runtime-architecture-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/claude-alias-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/claude-package-command-contract-test.py"
python3 "$PLUGIN_ROOT/scripts/plugin-standard-contract-test.py"
"$PLUGIN_ROOT/bin/carbon-runtime" audit-library
"$PLUGIN_ROOT/bin/carbon-runtime" audit-flows

echo "PASS: official OpenAI ChatGPT/Codex, Agent Plugins 1.0, Cursor, Claude, and standalone MCP packaging plus 44 public workflows, 40 local MCP tools, 44 unnamespaced Claude aliases, including durable project-specific human decision context and private local feedback workspaces with optional self-hosted reviewer queues, safe bundled CARBON demo fixtures with clean-slate and existing-test profiles, universal host-requested live command pages with durable one-second progress, bounded First Look coverage with explicit business-value checks, durable deferred candidates and carbon-more continuation, privacy-safe CARBON activity statistics with exact usage attribution and honest savings scenarios, copy-only failure injection, 15 specialist-domain commands plus focused carbon-test, bundled grayscale specialist profiles, criterion-level WCAG 2.2 and VPAT 2.5Rev-aligned ACR reporting, an anonymous opinionated testing doctrine with balanced pro/con practice spices and repeatable-evidence defaults, adaptive readiness doctor, typed evidence graph and why-test lineage, failure clustering/classification/portable repros, fresh invalidatable project memory, a 15/15 seeded-defect dogfood benchmark, interactive reports, eight-dimensional confidence, secure read-first Jira/Xray/TestRail evidence and guarded synchronization, contextual versioned chatbot suites and searchable single-file reports, universal linked single-file CARBON command reports, project-first inspection, selectable focus, relocatable local state, proactive untried-workflow guidance, executable native Vibium CLI and existing-test compatibility, CARBON generation APIs, carbon-browser/v1 adapter negotiation and durable evidence ledgers, protected live pre-run plans with adaptive time estimates, evidence-qualified confidence in quality, remaining risk, missing coverage and decision-changing next evidence, secure global credentials/prompts/context documents, read-only project-aware CARBON Help, prompt-defined AI-intent tests, protected visual CRUD, local TestRail/Xray/XML/XLSX/DOCX conversion, evidence-gated full import bake, bounded definition repair and rerun, every-page artifact capture, evidence-linked persona feedback, breadth/depth exploratory charters, cross-artifact issue analysis, screenshot-rich visual reporting, automatic product/API/change mapping, evidence-backed regression lifecycle, adaptive execution, CI/reporting, durable ad preferences, local CARBON testing, testers.ai Premium Cloud commands, accessibility, 21 named specialists, and safety-gated cloud contracts verified."
