CI guide
This guide explains AlignTrue’s multi-layered validation approach to catch errors early and provides quick fixes for common CI failures.
Overview
AlignTrue uses a multi-layered validation approach:
- Pre-refactor validation - Run before large changes to ensure clean baseline
- Pre-commit hook - Incremental checks on every commit (fast, focused)
- CI validation - Full workspace validation on push (comprehensive)
Pre-commit hook (automatic)
Runs automatically on every git commit. Optimized for speed with incremental checks.
Flow:
- Warn if 50+ files are staged (commit may be slow; consider splitting).
- Block temp artifacts: fails if any staged path starts with
temp-. - Auto-regenerate protected docs (
README.md,CONTRIBUTING.md,DEVELOPMENT.md) when their sources change and stage the outputs. - Validate workspace protocol on staged
package.jsonfiles (pnpm validate:workspace). - Format and lint staged files via
lint-staged(Prettier + ESLint, zero warnings). - If staged files include TypeScript, build affected packages (
pnpm build:packages) to catch resolution/type errors. - Validate Next.js
transpilePackagesconfiguration. - Validate documentation accuracy when docs or related code change (docs content,
package.json, CLI command registry, exporters, performance thresholds).
Total time: ~45-90s for typical commits (faster with small staged sets)
Protected repository files
The following files are auto-generated from documentation source and cannot be directly edited:
README.md(generated fromapps/docs/content/index.mdx)CONTRIBUTING.md(generated fromapps/docs/content/07-contributing/creating-aligns.md)DEVELOPMENT.md(generated fromapps/docs/content/06-development/*)
Why: AlignTrue practices what it preaches - documentation is the IR (Intermediate Representation), and generated files are the exports. This enforces the docs-first architecture.
Correct workflow:
- Edit the canonical source in
apps/docs/content/ - Run
pnpm generate:repo-filesto regenerate root files (the pre-commit hook will also do this automatically when docs sources change) - Commit both the doc changes AND the regenerated files
If you accidentally try to directly edit a protected file:
❌ Protected files were directly edited
📝 These files are generated from docs content:
README.md
CONTRIBUTING.md
DEVELOPMENT.md
🔄 Correct workflow:
1. Edit source files in apps/docs/content/
2. Run: pnpm generate:repo-files
3. Commit both docs changes AND generated filesTo fix: Follow the workflow above and retry your commit.
Bypassing the hook
Only use --no-verify when absolutely necessary (e.g., emergency hotfix, known CI issue):
git commit --no-verify -m "fix: Emergency hotfix"CI validation (automatic)
Runs on every push to main or develop. Comprehensive validation of entire workspace.
What CI checks:
- Workspace protocol validation (
pnpm validate:workspace) - Workspace link verification (
pnpm verify:workspace-links) - Build all packages (
pnpm build:packages) - Full validation suite (
pnpm validate:all) - Docs build (
pnpm --filter @aligntrue/docs build) - Full typecheck (
pnpm typecheck) - Tests with coverage (
pnpm test -- --coverage) - Conformance testkit (
pnpm verify) - Golden repository validation (
examples/golden-repo/test-golden-repo.sh)
Time: 3-5 minutes per platform
Platform coverage
CI runs on multiple platforms to catch platform-specific issues:
- Ubuntu (Linux) - Node 20 and Node 22
- macOS - Node 22
- Windows - Node 22 (limited coverage, see below)
Windows test limitations
Current status: 13 integration test suites skip on Windows due to persistent EBUSY file locking issues.
Affected tests:
init-command.test.tssync-command.test.tscheck-command.test.tsoverlays.test.tsscopes-monorepo.test.tsplugs-resolution.test.tscustomization-combined.test.tsalign-sources.test.tsoverride-add-command.test.tsoverride-remove-command.test.tsoverride-status-command.test.ts- Plus 1 unit test in
core/tests/overlays/patch-writer.test.ts
Root cause: Windows file system locks files more aggressively than Unix-like systems, causing EBUSY errors when tests try to clean up temporary directories. The cleanup helper in packages/cli/tests/helpers/fs-cleanup.ts includes retry logic (6 retries on Windows vs 1 on Unix), but CI environment still experiences intermittent failures.
Impact:
- Core CLI commands (init, sync, check) are not integration tested on Windows in CI
- Unit tests and smoke tests still run on Windows
- Path normalization and cross-platform compatibility are validated via unit tests
- Windows support is “best effort” - basic functionality works but edge cases may slip through
Workaround for local Windows testing:
- Run tests locally with longer timeouts
- Use WSL2 for full test suite coverage
- Report Windows-specific issues as bugs with reproduction steps
Future work:
- Investigate more robust cleanup strategies (rimraf, graceful-fs)
- Add Windows-specific smoke tests that DO run in CI
- Consider marking Windows as “community supported” if issues persist
Troubleshooting quick fixes
Workspace protocol validation failed
Symptom
Workspace protocol validation failed: @aligntrue/core version is "^0.2.0".Fix
- Run
pnpm validate:workspacelocally. - Update the dependency to
workspace:*in the referencedpackage.json. - Re-run
pnpm install && pnpm build:packages.
Workspace link verification failed
Symptom
Workspace link verification failed: @aligntrue/cli → /node_modules/.pnpm/...Fix
- Ensure you ran
pnpm installafter switching branches. - If links still resolve to
.pnpm, runpnpm clean && pnpm install. - Re-run
pnpm verify:workspace-links.
Version mismatch during prepublish
Symptom
Versions must match across all workspace packages.Fix
- Run
pnpm prepublish:checklocally; it prints every mismatched package. - Bump all packages to the same version (for example, 0.2.0) before releasing.
Type mismatch after renaming formats
Symptom
TS2322: Type '"agents-md"' is not assignable to type '"agents"'.Fix
- Ensure packages were rebuilt:
pnpm build:packages. - Run
pnpm validate:workspaceandpnpm verify:workspace-links. - If CI still fails, run
pnpm clean && pnpm installto refresh workspace links.
Common type error patterns
1. Import path errors
Problem: Wrong import path or missing type export
// ❌ Wrong
import { DriftDetectionResult } from "@aligntrue/core/team/drift.js";
// ✅ Correct
import { DriftResult } from "@aligntrue/core/team/drift.js";Fix: Check the actual exports in the source file
2. Duplicate imports
Problem: Same type imported from multiple locations
// ❌ Wrong
import { AlignRule } from "@aligntrue/core";
import { AlignRule } from "@aligntrue/schema";
// ✅ Correct
import { AlignRule } from "@aligntrue/schema";Fix: Import types from their canonical source (usually @aligntrue/schema)
3. Type narrowing issues
Problem: TypeScript can’t infer type after conditional
// ❌ Wrong
if (!acc[item.category]) acc[item.category] = [];
acc[item.category].push(item); // Error: possibly undefined
// ✅ Correct
if (!acc[item.category]) acc[item.category] = [];
acc[item.category]!.push(item); // Non-null assertionFix: Use non-null assertion (!) or type guards
4. exactOptionalPropertyTypes issues
Problem: Optional property can’t be explicitly set to undefined
// ❌ Wrong
type Result = {
summary?: string;
};
// ✅ Correct
type Result = {
summary?: string | undefined;
};Fix: Explicitly allow undefined in optional properties
Import path reference
Common type locations:
- Schema types:
@aligntrue/schemaAlignRule,Align,validateAlignSchema,validateRuleId
- Core types:
@aligntrue/coreAlignTrueConfig,SyncEngine,BackupManager
- Team types:
@aligntrue/core/team/drift.jsDriftResult,DriftFinding,DriftCategory
- Exporter types:
@aligntrue/exportersExporterRegistry,ExportResult
- Source types:
@aligntrue/sourcesGitSourceConfig,CatalogSourceConfig
Common issues and fixes
Next.js dev server fails with “Cannot find module” errors
Symptom: Dev server crashes with errors like:
Error: Cannot find module './vendor-chunks/nextra@4.6.0...'
Cannot find module '@aligntrue/ui'Cause: Next.js doesn’t transpile workspace packages by default. The @aligntrue/ui package exports TypeScript source directly (no build step), so Next.js needs to be configured to transpile it.
Fix:
See Setup - Next.js dev server fails for detailed troubleshooting steps.
Pre-commit hook is slow
Cause: Checking too many packages or full workspace
Fix: The optimized hook only checks changed packages. If still slow:
- Check if you have uncommitted changes in many packages
- Commit packages separately if working on multiple
Type errors only appear in CI
Cause: Local build is stale or using cached types
Fix:
# Clean and rebuild
pnpm clean
pnpm build
# Then run typecheck
pnpm typecheckPre-commit hook fails but types seem fine
Cause: Hook uses stricter checks than your IDE
Fix:
- Run
pnpm typechecklocally to see all errors - Check that your IDE is using workspace TypeScript version
- Ensure
tsconfig.jsonhasstrict: true
Best practices
- Commit frequently - Smaller commits = faster pre-commit checks
- Fix type errors immediately - Don’t let them accumulate
- Use the right import paths - Check source files for canonical exports
- Test locally before pushing - Run
pnpm typecheck && pnpm test
Next steps
- Review setup guide
- Learn test maintenance for handling test failures