agentsclimarketplace

Legacy safety rails

Skill ForeverSc/ai-handrail/skills/legacy-safety-rails

Making Legacy Projects Safer for Vibe Coding. AI适老化改造,让老项目更适合 Vibe Coding。

Install
npx -y skills add ForeverSc/ai-handrail --skill legacy-safety-rails

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when a legacy project needs test coverage, observability, feature flags, or rollback mechanisms before refactoring. Triggers when user says "add tests to this old code", "make this safe to refactor", "add guardrails", "protect this before changing it", or after legacy-doc-bootstrap has created docs.

SKILL.md

10.9 KB, as published. Nobody here has run it

Legacy Safety Rails

Build the protective infrastructure that makes legacy refactoring safe: tests, observability, feature flags, and rollback plans.

Goal

Create a multi-layer safety net so that any future code change can be verified, monitored, and reversed.

When to Use

  • After documentation exists (via legacy-doc-bootstrap)
  • Before any refactoring or modernization work begins
  • When the user wants to "make this safe to change"
  • When critical paths lack test coverage

The Five Guardrail Layers

Layer 1: Behavior Baseline

Capture current behavior as the source of truth.

  • API responses: Record request/response pairs for key endpoints
  • UI state: Screenshots or snapshots of critical pages/states
  • Data contracts: Current schemas, field types, required fields
  • Performance baseline: Response times, throughput for P0 paths
  • Side effects: What external calls happen (emails, webhooks, analytics events)
  • Runtime behavior: Actual call chains, feature flag states, real data shapes (see docs/methodology.md → Runtime Behavior Capture)

Layer 2: Test Guardrails

Priority order (NOT "write all unit tests first"):

  1. Characterization tests — capture actual behavior as golden files/snapshots, including bug behavior that downstream may depend on. See docs/methodology.md → Characterization Testing.
  2. P0 path integration tests — end-to-end for critical user journeys
  3. Business rule module tests — isolated tests for core business logic
  4. Contract tests — API schemas, database schemas, message formats (see Contract-First below)
  5. Smoke tests — basic "does it start and respond" health checks

Characterization test rules:

  • Capture reality, not intent. Do not "fix" tests to match expectations.
  • Include edge cases: empty input, null values, boundary conditions, error responses.
  • Tools: snapshot testing (Jest snapshots, approval tests), API recording (VCR/Nock/Polly.js).
  • After refactoring, these tests catch unintended behavior changes — even "bug fixes" that break downstream.

Layer 3: Compatibility Guardrails

Protect interfaces and contracts using a contract-first approach (see docs/methodology.md → Contract-First Boundary Definition):

  • API contracts: OpenAPI spec / JSON Schema for HTTP interfaces
  • Data contracts: TypeScript interfaces or JSON Schema for data structures
  • Event contracts: Schema for events/messages between modules
  • Database contracts: Migration-versioned schema expectations
  • Error codes and error message formats
  • Default values and fallback behaviors

Key rule: Contracts must be tested (Layer 2 contract tests). Untested contracts are just documentation.

Layer 4: Release Guardrails

Mechanisms for safe deployment:

  • Feature flags for new code paths
  • Gradual rollout / canary deployment strategy
  • Shadow mode (new code runs but old code serves)
  • Rollback procedure (documented, tested)

Layer 5: Change Guardrails

Per-change safety checklist:

  • Impact scope documented
  • Verification method defined
  • Rollback method defined
  • Human approval obtained for flagged changes

Mandatory Workflow

Step 1: Assess Existing Safety Infrastructure

  1. What test framework is in use? What version?
  2. What tests exist? What do they cover?
  3. Is there CI/CD? What checks run on commit/deploy?
  4. Are there feature flags, monitoring, or alerting?
  5. What's the current deployment/rollback process?
  6. Check project type from discovery outputs. Load the corresponding profile from skills/legacy-discovery/profiles/ to understand stack-specific testing tools and guardrail priorities.

Step 2: Prioritize by Risk

Using discovery risk labels:

LabelSafety Action
P0-CRITICALLayer 1 (baseline) + Layer 2 (integration test) + Layer 4 (rollback)
HIGH-RISKLayer 2 (module tests) + Layer 3 (contracts)
TEST-MISSINGLayer 2 (appropriate test type)
LEGACY-SEALEDLayer 1 (baseline only — don't touch)
SAFE-TO-EXTRACTLayer 2 (module tests before extraction)

Step 3: Build Guardrails Incrementally

For each domain/module in scope:

  1. Capture baseline — record current behavior
  2. Write highest-priority tests — based on risk assessment
  3. Document contracts — lock down interfaces
  4. Define rollback procedure — before any refactor begins
  5. Set up feature flags — if the project's tech stack supports them

Step 4: Verify Guardrails Work

  • Run all new tests. They must pass against current code.
  • Intentionally break something small — verify tests catch it.
  • Document what each guardrail protects.

Step 5: Update Documentation

Add test baseline info to docs/legacy-modernization/domains/<domain>/test-baseline.md. Record module-to-test mapping for every guarded source file and make the edit gate explicit (ALLOW / BLOCKED-TEST-MISSING / BLOCKED-DOC-MISSING).

Required Outputs

OutputDescription
Test inventoryWhat tests were added, what they cover, what's still missing
Contract registryDocumented API/schema/event contracts
Baseline snapshotsCaptured behavior baselines with storage location
Rollback planStep-by-step rollback procedure for each area
Coverage gap reportWhat's still unprotected, prioritized by risk
Feature flag planWhat flags are needed for upcoming changes

Hard Rules

  1. Match the existing stack. Write tests using the project's existing test framework and version. Don't introduce new test frameworks without discussion.
  2. Lockfile versions apply. If the project uses Jest 27, write Jest 27-compatible tests. Don't use Jest 29 APIs.
  3. Tests must pass today. Every test you write must pass against the current codebase. Failing tests are not guardrails.
  4. Don't test implementation details. Test behavior and contracts, not internal structure.
  5. Baseline before changing. Never skip behavior capture for a P0-CRITICAL module.
  6. Rollback must be documented. Every guardrailed area needs a written rollback procedure.
  7. Don't boil the ocean. You don't need 100% coverage. You need coverage on the paths that matter.
  8. Create module-to-test mapping. The guardrail is incomplete until each protected module points to concrete tests.
  9. Block source edits when tests are missing. If a module is still TEST-MISSING, document that the edit gate remains closed.

Profile-Specific Guardrail Guidance

The project type (detected during discovery) determines which guardrails matter most. Consult the profile for stack-specific tools and approaches.

Frontend Projects (profiles/frontend.md)

LayerFocus
Behavior baselineScreenshot snapshots of key pages/states, Core Web Vitals baseline (LCP, INP, CLS)
Test guardrailsComponent tests (Testing Library), E2E tests (Playwright/Cypress), visual regression (Chromatic/Percy)
Compatibility guardrailsComponent prop interfaces, API request/response types, CSS scope boundaries
Release guardrailsFeature flags (LaunchDarkly/Unleash/custom), A/B testing hooks, bundle size gate in CI
Change guardrailsBundle size diff check, lighthouse CI, accessibility audit (axe-core)

Backend-Node Projects (profiles/backend-node.md)

LayerFocus
Behavior baselineAPI response recording (Nock/Polly.js), database state snapshots
Test guardrailsAPI integration tests (Supertest), middleware isolation tests, queue/worker tests
Compatibility guardrailsOpenAPI schema validation, database migration versioning, event schema contracts
Release guardrailsFeature flags, canary deployment, graceful shutdown verification
Change guardrailsnpm audit in CI, health check endpoint verification

Backend-Java Projects (profiles/backend-java.md)

LayerFocus
Behavior baselineAPI response recording, database state with Testcontainers
Test guardrails@SpringBootTest integration tests, MockMvc/RestAssured API tests, ArchUnit architecture tests
Compatibility guardrailsOpenAPI schema, Flyway/Liquibase migration versioning, message contract tests
Release guardrailsSpring Profiles for feature toggling, Actuator health checks, JVM metrics baseline
Change guardrailsOWASP dependency-check in CI, JaCoCo coverage gate

Backend-Python Projects (profiles/backend-python.md)

LayerFocus
Behavior baselineAPI response recording (VCR.py/responses), database state fixtures
Test guardrailspytest integration tests, DRF APIClient/FastAPI TestClient, factory_boy fixtures
Compatibility guardrailsSchema validation (Pydantic/Marshmallow), Django migration lint, event contracts
Release guardrailsFeature flags (django-waffle/Unleash), health check endpoints
Change guardrailspip-audit/safety in CI, coverage gate (pytest-cov)

Backend-Go Projects (profiles/backend-go.md)

LayerFocus
Behavior baselineAPI response recording, database state with testcontainers-go
Test guardrailshttptest API tests, table-driven tests, -race flag in CI, integration tests with build tags
Compatibility guardrailsprotobuf/OpenAPI schema validation, migration versioning (golang-migrate/goose)
Release guardrailsFeature flags, graceful shutdown (signal.NotifyContext), health/ready endpoints
Change guardrailsgovulncheck in CI, golangci-lint, benchmark regression tests

Fullstack Projects (profiles/fullstack.md)

Apply both frontend and backend layers, plus:

LayerFocus
Behavior baselineFull user journey recording spanning frontend and backend
Compatibility guardrailsFrontend-backend API contract tests (shared types or schema validation)
Release guardrailsCoordinated deploy strategy, deploy-order safety
Change guardrailsContract drift detection between frontend types and backend responses

Anti-Patterns

Don'tDo instead
Write 200 unit tests for utility functionsWrite 5 integration tests for P0 user journeys
Introduce a new test frameworkUse the existing one at its actual version
Write tests that depend on internal stateTest observable behavior and public interfaces
Assume CI will catch everythingVerify tests actually run in CI
Skip rollback planningDocument rollback for every guardrailed area
Add guardrails to sealed modulesCapture baseline only — don't modify sealed code

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.