Skip to content

Conversation

@dpaluy
Copy link
Owner

@dpaluy dpaluy commented Jan 7, 2026

Summary

Implements T7 (#44): Config DSL methods for enabling pattern-based PII redaction.

New Config API

TraceBook.configure do |config|
  config.redact :email, :phone, :credit_card    # Enable specific patterns
  config.redact_group :api_keys                  # Enable pattern group
  config.redact_pattern(/secret=\w+/, "[SECRET]") # Custom pattern
end

Included Changes

  • T2: Validators module with Luhn algorithm and SSN range validation
  • T3: PATTERNS hash with 16 built-in patterns:
    • PII: email, phone, ssn
    • Financial: credit_card (with Luhn validation)
    • API Keys: openai_key, anthropic_key, aws_key, stripe_key, github_token, github_pat
    • Auth: bearer_token, basic_auth, jwt
    • Network: ipv4, ipv6
    • Crypto: private_key
  • T7: Config DSL methods (redact, redact_group, redact_pattern)
  • Pattern groups for batch enabling (pii, financial, api_keys, auth, network, crypto)

Validation

  • Invalid pattern names raise ConfigurationError at config time
  • Invalid group names raise ConfigurationError at config time

Test Plan

  • 14 new config DSL tests added
  • All 160 tests pass

dpaluy added 4 commits January 6, 2026 23:00
…ased refactor

Remove dual-layer PII redaction system (database rules + class-based redactors) to prepare for new unified pattern-based architecture.

Deleted:
- RedactionRule model and migration (database-backed rules)
- Base, Email, Phone, CardPAN redactor classes
- Related tests for legacy system

Modified:
- RedactionPipeline: removed apply_database_rules! method
- Config: default_redactors now returns [] with TODO comment
- Tests: updated to use custom_redactors instead of built-in ones

Breaking change: No redactors active until new Pattern system is implemented (T1-T3).
Tests pass: 123 runs, 368 assertions, 0 failures

Related: #38-#54 (PII Redaction Architecture Refactor)
Implements immutable value object for tracking PII redaction operations,
supporting GDPR/CCPA compliance requirements (Spec Gap 9).

Key features:
- Immutable instances with builder pattern methods
- Tracks redaction metadata: timestamp, redactors applied, fields, counts
- LLM redaction status tracking (success, failed, skipped)
- Methods: record_redaction, record_llm_failure, record_llm_success, to_h
- Deduplicates and sorts redactor names
- Compact JSON serialization via to_h

Comprehensive test suite (22 tests):
- Default initialization and timestamp handling
- Redaction recording and deduplication
- Immutability verification
- LLM status transitions
- Hash serialization with nil filtering
- Complex nested scenarios and chaining

Next: Integrate with RedactionPipeline and NormalizedInteraction
Add public method to convert ActiveRecord actors to job-safe serialized
format for background job enqueueing. Supports GlobalID extraction with
fallback to type/id tuple for objects without GlobalID support.

Closes #42
Add pattern-based redaction DSL to Config class:
- config.redact :email, :phone - enables individual patterns
- config.redact_group :api_keys - enables pattern groups
- config.redact_pattern(/regex/, "[REPLACEMENT]") - custom patterns
- config.active_patterns - returns all enabled Pattern objects

Also includes:
- T2: Validators module with Luhn and SSN range validation
- T3: PATTERNS hash with 16 built-in patterns (email, phone, credit_card,
  ssn, openai_key, anthropic_key, aws_key, stripe_key, github_token,
  github_pat, bearer_token, basic_auth, private_key, ipv4, ipv6, jwt)
- PATTERN_GROUPS for convenient batch enabling (pii, financial, api_keys,
  auth, network, crypto)

Invalid pattern names raise ConfigurationError at config time for
early validation.
@dpaluy dpaluy added the enhancement New feature or request label Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants