Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 31, 2025

This PR implements a comprehensive AST-based validation suite that discovers and validates actual architectural patterns in the codebase, replacing hardcoded assumptions with adaptive pattern recognition.

🔄 Major Overhaul: Dynamic Pattern Discovery

The validation system now discovers actual patterns used in the codebase instead of enforcing rigid, hardcoded rules that don't match the current architecture.

Key Innovation: Context-Aware Validation

Before (Hardcoded):

// Always required dispose(), even when cleanup() was used
if (!hasDisposeMethod) {
  ERRORS.push({
    message: `Manager class "${className}" missing dispose() method`
  });
}

After (Dynamic Discovery):

// Discovers what patterns are actually used
const workspaceManagers = managers.filter(m => m.className.includes('workspace'));
const primaryCleanupPattern = discoverMostCommonPattern(workspaceManagers);

// Validates consistency within discovered patterns
if (manager.pattern !== primaryCleanupPattern) {
  WARNINGS.push({
    message: `Uses ${manager.pattern} but workspace managers typically use ${primaryCleanupPattern}`
  });
}

🎯 Real-World Impact

Validation Results Comparison

Before: 6 false positive errors

❌ WorkspaceDevlogManager missing dispose() method
   (Actually has cleanup() method - legitimate pattern!)
❌ ConfigurationManager missing dispose() method  
❌ GitHubLabelManager missing dispose() method

After: 2 legitimate issues + useful insights

🎯 Discovered patterns:
   - Workspace managers: dispose() (2 classes)
   - Devlog managers: cleanup() (1 class)

❌ FileWorkspaceManager missing initialize() method (REAL ISSUE)
⚠️  WorkspaceDevlogManager uses cleanup() but other workspace managers use dispose()
   (USEFUL INCONSISTENCY DETECTION)

🔍 Validation Suite Components

  1. Dynamic Architecture Patterns (validate-architecture-patterns-ast.js) - COMPLETELY REWRITTEN

    • Discovers actual manager lifecycle patterns (initialize/cleanup/dispose)
    • Categorizes by component type (Workspace, Storage, Service, Provider)
    • Validates consistency within each category
    • Adapts to architectural evolution
  2. TypeScript Best Practices (validate-typescript-best-practices-ast.js)

    • Type safety enforcement (any usage, unsafe assertions)
    • Async/await patterns and error handling
    • JSDoc documentation requirements
  3. Testing Standards (validate-testing-standards-ast.js)

    • Test isolation and cleanup patterns
    • Mock usage and assertion patterns
    • Async test handling
  4. Security & Performance (validate-security-performance-ast.js)

    • Security vulnerability detection
    • Performance anti-pattern identification
    • Resource management validation
  5. Import Patterns (validate-imports.js)

    • ESM compliance with .js extensions
    • Cross-package dependency validation

🚀 Usage

# Run comprehensive validation
npm run validate

# Target specific areas
npm run validate:architecture  # Now uses dynamic discovery
npm run validate:typescript
npm run validate:security

# Development mode
npm run validate:quick

📊 Benefits for AI Development

  • Accurate Feedback: No false positives from outdated assumptions
  • Architectural Awareness: Understands actual codebase patterns
  • Adaptive Learning: Evolves with the architecture
  • Consistency Detection: Identifies legitimate inconsistencies worth reviewing
  • Context Sensitivity: Different rules for different component types

The validation suite now works with your architecture instead of against it, providing meaningful guidance that helps maintain code quality while respecting legitimate architectural choices.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link

vercel bot commented Jul 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
devlog-web ❌ Failed (Inspect) Jul 31, 2025 3:56am

@tikazyq
Copy link
Collaborator

tikazyq commented Jul 31, 2025

@copilot let's work on develop branch instead of the main.

Copy link
Contributor Author

Copilot AI commented Jul 31, 2025

@copilot let's work on develop branch instead of the main.

Switched to develop branch! I've created a new branch copilot/fix-23-develop based on the develop branch and will continue the AST validation script work from there. The existing scripts provide a good foundation - I'll extend them to cover all packages with additional AST-based checks for code quality standards.

Co-authored-by: tikazyq <3393101+tikazyq@users.noreply.github.com>
Co-authored-by: tikazyq <3393101+tikazyq@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement AST-based validation check scripts for standardization for all packages Implement comprehensive AST-based validation suite for code standardization across all packages Jul 31, 2025
@tikazyq
Copy link
Collaborator

tikazyq commented Jul 31, 2025

@copilot we don't have manager classes anymore. Also, we should not hardcode the class names. Let's do an overhaul to address this.

…amic discovery

- Replace hardcoded manager class validation with dynamic pattern discovery
- Categorize managers by type (Workspace, Storage, Other) for context-aware validation
- Discover actual patterns used (cleanup vs dispose) instead of enforcing rigid rules
- Reduce false positives from 6 errors to 2 legitimate issues
- Add comprehensive documentation of the overhaul approach
- Validation now adapts to actual codebase architecture instead of enforcing outdated assumptions

Co-authored-by: tikazyq <3393101+tikazyq@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 31, 2025

@copilot we don't have manager classes anymore. Also, we should not hardcode the class names. Let's do an overhaul to address this.

Addressed the hardcoded manager class assumptions with a comprehensive overhaul (commit 03d176a).

Key changes:

  • Replaced hardcoded patterns with dynamic discovery that detects actual architectural patterns used in the codebase
  • Categorized managers by type (Workspace, Storage, Other) for context-aware validation
  • Reduced false positives from 6 errors to 2 legitimate issues
  • Adaptive validation that works with current architecture (cleanup vs dispose methods) instead of enforcing outdated assumptions

Results:

  • WorkspaceDevlogManager no longer flagged for "missing dispose()" - correctly detects it uses cleanup()
  • ✅ Discovered actual patterns: workspace managers use dispose() while devlog managers use cleanup()
  • ⚠️ Provides useful inconsistency warning: WorkspaceDevlogManager uses different cleanup pattern than other workspace managers

The validation now discovers and adapts to your actual architecture instead of enforcing rigid, outdated rules.

Copilot AI changed the title Implement comprehensive AST-based validation suite for code standardization across all packages Implement dynamic AST validation suite with adaptive pattern discovery for code standardization Jul 31, 2025
Copy link
Collaborator

@tikazyq tikazyq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot We are using pnpm instead of npm. Please update

Copy link
Contributor Author

Copilot AI commented Jul 31, 2025

@copilot We are using pnpm instead of npm. Please update

Updated all documentation to use pnpm instead of npm commands (commit 5b8d7c2). Changed references in:

  • docs/AST_VALIDATION_GUIDE.md
  • packages/mcp/README.md
  • .github/guides/error-checking.md

All validation commands now consistently show pnpm run validate instead of npm run validate.

Copilot AI requested a review from tikazyq July 31, 2025 03:56
@tikazyq tikazyq marked this pull request as ready for review July 31, 2025 03:59
Copilot AI review requested due to automatic review settings July 31, 2025 03:59
@tikazyq tikazyq merged commit 5be090c into develop Jul 31, 2025
1 of 3 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive AST-based validation suite that discovers and validates actual architectural patterns in the codebase, replacing hardcoded assumptions with adaptive pattern recognition. The system now dynamically analyzes the codebase to understand existing patterns and validates consistency rather than enforcing rigid rules.

Key changes:

  • Dynamic Pattern Discovery: Replaced hardcoded validation rules with pattern discovery that learns from the actual codebase
  • Context-Aware Validation: Different validation rules for different component types (workspace, storage, service managers)
  • Comprehensive AST Analysis: New validation scripts for TypeScript best practices, testing standards, and security/performance patterns

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
scripts/validate-typescript-best-practices-ast.js New AST-based TypeScript validation checking type safety, async patterns, and documentation
scripts/validate-testing-standards-ast.js New test validation script enforcing test structure, isolation, and assertion patterns
scripts/validate-security-performance-ast.js New security and performance validation detecting vulnerabilities and anti-patterns
scripts/validate-architecture-patterns-ast.js Completely rewritten architecture validation with dynamic pattern discovery
scripts/validate-all-ast.js New orchestrator script coordinating all validation scripts with CLI options
package.json Updated scripts to use new AST-based validation suite
docs/DYNAMIC_VALIDATION_OVERHAUL.md Documentation explaining the overhaul from hardcoded to dynamic validation
docs/AST_VALIDATION_GUIDE.md Comprehensive guide for using the new AST validation suite

const lineNum = getLineNumber(sourceFile, node);

// Check for 'any' type usage - use safer checking
if (isTypeReferenceSafe(node) && isAnyType(node)) {
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for detecting 'any' type usage is incorrect. isTypeReferenceSafe checks if a node is a TypeReferenceNode, but isAnyType checks for AnyKeyword. These are mutually exclusive - an AnyKeyword is not a TypeReferenceNode.

Suggested change
if (isTypeReferenceSafe(node) && isAnyType(node)) {
if (isAnyType(node)) {

Copilot uses AI. Check for mistakes.
const lineNum = getLineNumber(sourceFile, node);

// Check type parameters for proper constraints
if (ts.isTypeParameterDeclaration && ts.isTypeParameterDeclaration(node)) {
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition 'ts.isTypeParameterDeclaration && ts.isTypeParameterDeclaration(node)' is redundant. The first part checks if the function exists, but since TypeScript compiler API is being used, this check is unnecessary and the second condition is sufficient.

Suggested change
if (ts.isTypeParameterDeclaration && ts.isTypeParameterDeclaration(node)) {
if (ts.isTypeParameterDeclaration(node)) {

Copilot uses AI. Check for mistakes.
});
}

if ((hasFileSystemOperations || hasProcessCwdUsage || hasEnvVarChanges) && !hasProperCleanup) {
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hasProperCleanup variable only checks for afterEach calls but doesn't verify if they actually contain cleanup code. This could lead to false negatives where afterEach exists but doesn't perform the necessary cleanup.

Copilot uses AI. Check for mistakes.
Comment on lines +348 to +349
const parent = node.parent;
while (parent) {
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This while loop traverses up the parent chain without a termination condition other than reaching null. This could potentially cause an infinite loop if there's a circular reference in the AST (though unlikely with TypeScript AST).

Suggested change
const parent = node.parent;
while (parent) {
const parent = node.parent;
const visitedNodes = new Set();
while (parent) {
if (visitedNodes.has(parent)) {
break; // Break the loop if a circular reference is detected
}
visitedNodes.add(parent);

Copilot uses AI. Check for mistakes.
});
break;
}
parent = parent.parent;
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parent traversal should have a safety check to prevent potential infinite loops. While TypeScript AST shouldn't have circular references, it's a defensive programming practice.

Copilot uses AI. Check for mistakes.
"tsx": "^4.0.0"
},
"packageManager": "pnpm@10.13.1+sha512.37ebf1a5c7a30d5fabe0c5df44ee8da4c965ca0c5af3dbab28c3a1681b70a256218d05c81c9c0dcf767ef6b8551eb5b960042b9ed4300c59242336377e01cfad"
}
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The packageManager field was removed from package.json, which could cause issues with package manager version consistency across different environments.

Suggested change
}
},
"packageManager": "pnpm@8.6.0"

Copilot uses AI. Check for mistakes.
@tikazyq tikazyq deleted the copilot/fix-23 branch July 31, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement AST-based validation check scripts for standardization for all packages

2 participants