From bd737a70b74e2a8b9446743fd69eedc00f8fce45 Mon Sep 17 00:00:00 2001 From: John White <750350+johnhwhite@users.noreply.github.com> Date: Wed, 1 Apr 2026 11:21:52 -0400 Subject: [PATCH 1/9] feat(components/packages): add ai skills to workspace --- libs/components/packages/collection.json | 5 + libs/components/packages/migrations.json | 5 + libs/components/packages/project.json | 1 + .../update-14/add-ai-skills/add-ai-skills.ts | 3 + .../add-ai-skills.schematic.spec.ts | 94 ++++ .../add-ai-skills/add-ai-skills.schematic.ts | 21 + .../files/skills/migration-resolver/SKILL.md | 350 ++++++++++++ .../references/angular-debugging.md | 202 +++++++ .../references/condition-based-waiting.md | 171 ++++++ .../references/defense-in-depth.md | 136 +++++ .../references/root-cause-tracing.md | 180 ++++++ .../skyux-test-driven-development/SKILL.md | 434 +++++++++++++++ .../references/angular-testing-patterns.md | 285 ++++++++++ .../references/testing-antipatterns.md | 512 ++++++++++++++++++ .../SKILL.md | 157 ++++++ .../ng-generate/add-ai-skills/schema.json | 5 + .../ng-generate/add-ai-skills/tests/README.md | 69 +++ .../tests/fix-bugs/test-academic.md | 18 + .../tests/fix-bugs/test-behavioral-overlay.md | 68 +++ .../tests/fix-bugs/test-pressure-1.md | 65 +++ .../tests/fix-bugs/test-pressure-2.md | 85 +++ .../tests/fix-bugs/test-pressure-3.md | 75 +++ .../test-code-first-resistance.md | 56 ++ .../test-harness-preference.md | 64 +++ .../test-new-feature.md | 76 +++ .../test-partial-verification.md | 36 ++ .../test-premature-success.md | 57 ++ 27 files changed, 3230 insertions(+) create mode 100644 libs/components/packages/src/schematics/migrations/update-14/add-ai-skills/add-ai-skills.ts create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.ts create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/defense-in-depth.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/testing-antipatterns.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/schema.json create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-academic.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-behavioral-overlay.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-1.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-2.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-3.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-code-first-resistance.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-harness-preference.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md diff --git a/libs/components/packages/collection.json b/libs/components/packages/collection.json index aaa170e9d6..258f2e903f 100644 --- a/libs/components/packages/collection.json +++ b/libs/components/packages/collection.json @@ -36,6 +36,11 @@ "factory": "./src/schematics/ng-generate/remove-compat-stylesheets/remove-compat-stylesheets.schematic", "schema": "./src/schematics/ng-generate/remove-compat-stylesheets/schema.json" }, + "add-ai-skills": { + "description": "Add SKY UX AI skills for Claude Code to your project.", + "factory": "./src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic", + "schema": "./src/schematics/ng-generate/add-ai-skills/schema.json" + }, "standalone-migration": { "description": "Convert components to standalone using SKY UX modules.", "factory": "./src/schematics/ng-generate/standalone/standalone.schematic", diff --git a/libs/components/packages/migrations.json b/libs/components/packages/migrations.json index cbc40a197c..545de58724 100644 --- a/libs/components/packages/migrations.json +++ b/libs/components/packages/migrations.json @@ -20,6 +20,11 @@ "factory": "./src/schematics/migrations/all/workspace-check/workspace-check.schematic", "description": "Log warnings if the workspace is not configured correctly." }, + "add-ai-skills": { + "version": "0.0.0-PLACEHOLDER", + "factory": "./src/schematics/migrations/update-14/add-ai-skills/add-ai-skills", + "description": "Add AI skills to the workspace" + }, "uninstall-prettier-schematics": { "version": "0.0.0-PLACEHOLDER", "factory": "./src/schematics/migrations/update-14/uninstall-prettier-schematics/uninstall-prettier-schematics", diff --git a/libs/components/packages/project.json b/libs/components/packages/project.json index 1682b4aa4d..0673ad10e3 100644 --- a/libs/components/packages/project.json +++ b/libs/components/packages/project.json @@ -31,6 +31,7 @@ "libs/components/packages/collection.json", "libs/components/packages/migrations.json", "libs/components/packages/src/polyfills.js", + "libs/components/packages/src/schematics/**/files/**/*", "libs/components/packages/src/schematics/**/schema.json", "libs/components/packages/src/schematics/**/*.template", "libs/components/packages/*.md" diff --git a/libs/components/packages/src/schematics/migrations/update-14/add-ai-skills/add-ai-skills.ts b/libs/components/packages/src/schematics/migrations/update-14/add-ai-skills/add-ai-skills.ts new file mode 100644 index 0000000000..d89e5999aa --- /dev/null +++ b/libs/components/packages/src/schematics/migrations/update-14/add-ai-skills/add-ai-skills.ts @@ -0,0 +1,3 @@ +import { addAiSkills } from '../../../ng-generate/add-ai-skills/add-ai-skills.schematic'; + +export default addAiSkills; diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts new file mode 100644 index 0000000000..b13422b701 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts @@ -0,0 +1,94 @@ +import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; + +import { createTestApp } from '../../testing/scaffold'; + +describe('add-ai-skills', () => { + const runner = new SchematicTestRunner( + 'schematics', + require.resolve('../../../../collection.json'), + ); + + it('should copy skill files to .github/skills/', async () => { + const tree = await createTestApp(runner, { projectName: 'my-app' }); + + const resultTree = await runner.runSchematic( + 'add-ai-skills', + { project: 'my-app' }, + tree, + ); + + // Verify skill files exist at workspace root. + expect( + resultTree.exists('.github/skills/migration-resolver/SKILL.md'), + ).toBe(true); + expect( + resultTree.exists( + '.github/skills/skyux-test-driven-development/SKILL.md', + ), + ).toBe(true); + + // Verify reference files are included. + expect( + resultTree.exists( + '.github/skills/migration-resolver/references/angular-debugging.md', + ), + ).toBe(true); + expect( + resultTree.exists( + '.github/skills/skyux-test-driven-development/references/angular-testing-patterns.md', + ), + ).toBe(true); + + // Verify eval files are excluded. + expect( + resultTree.exists( + '.github/skills/migration-resolver/evals/test-academic.md', + ), + ).toBe(false); + expect( + resultTree.exists( + '.github/skills/migration-resolver/evals/test-pressure-1.md', + ), + ).toBe(false); + }); + + it('should preserve file content without template interpolation', async () => { + const tree = await createTestApp(runner, { projectName: 'my-app' }); + + const resultTree = await runner.runSchematic( + 'add-ai-skills', + { project: 'my-app' }, + tree, + ); + + const skillContent = resultTree.readContent( + '.github/skills/migration-resolver/SKILL.md', + ); + expect(skillContent).toContain( + 'ExpressionChangedAfterItHasBeenCheckedError', + ); + expect(skillContent).toContain( + '`TestbedHarnessEnvironment.documentRootLoader(fixture)`', + ); + }); + + it('should overwrite existing files on re-run', async () => { + const tree = await createTestApp(runner, { projectName: 'my-app' }); + + const firstTree = await runner.runSchematic( + 'add-ai-skills', + { project: 'my-app' }, + tree, + ); + + const secondTree = await runner.runSchematic( + 'add-ai-skills', + { project: 'my-app' }, + firstTree, + ); + + expect( + secondTree.exists('.github/skills/migration-resolver/SKILL.md'), + ).toBe(true); + }); +}); diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.ts b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.ts new file mode 100644 index 0000000000..b98f3bf6a0 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.ts @@ -0,0 +1,21 @@ +import { normalize } from '@angular-devkit/core'; +import { + MergeStrategy, + Rule, + apply, + filter, + mergeWith, + move, + url, +} from '@angular-devkit/schematics'; + +export function addAiSkills(): Rule { + return mergeWith( + apply(url('./files'), [ + filter((path) => !path.includes('/evals/')), + move(normalize('.github')), + ]), + MergeStrategy.Overwrite, + ); +} +export default addAiSkills; diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md new file mode 100644 index 0000000000..4deec612f7 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md @@ -0,0 +1,350 @@ +--- +name: migration-resolver +description: Use when encountering any bug, test failure, or unexpected behavior in Angular or SKY UX code, before proposing fixes. Covers change detection issues, DI errors, harness test failures, ExpressionChangedAfterItHasBeenCheckedError, overlay rendering problems, and flaky tests. Use this skill even if the fix seems obvious. +--- + +# SKY UX Debugging + +## Overview + +Random fixes waste time and create new bugs. Quick patches mask underlying issues. + +**Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure. + +**Violating the letter of this process is violating the spirit of debugging.** + +## The Iron Law + +``` +NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST +``` + +If you haven't completed Phase 1, you cannot propose fixes. + +## When to Use + +Use for ANY technical issue: + +- Test failures +- Bugs in production +- Unexpected behavior +- Performance problems +- Build failures +- Integration issues + +**Angular/SKY UX-specific triggers:** + +- Harness test failures +- `ExpressionChangedAfterItHasBeenCheckedError` +- Change detection not triggering (stale template bindings) +- `NullInjectorError` or circular dependency errors +- Lifecycle hook ordering issues (`ngOnInit`, `ngAfterViewInit`) +- Overlay/modal/flyout not rendering in test environment + +**Use this ESPECIALLY when:** + +- Under time pressure (emergencies make guessing tempting) +- "Just one quick fix" seems obvious +- You've already tried multiple fixes +- Previous fix didn't work +- You don't fully understand the issue + +**Don't skip when:** + +- Issue seems simple (simple bugs have root causes too) +- You're in a hurry (rushing guarantees rework) +- Manager wants it fixed NOW (systematic is faster than thrashing) + +## The Four Phases + +You MUST complete each phase before proceeding to the next. + +### Phase 1: Root Cause Investigation + +**BEFORE attempting ANY fix:** + +1. **Read Error Messages Carefully** + - Don't skip past errors or warnings + - They often contain the exact solution + - Read stack traces completely + - Note line numbers, file paths, error codes + +2. **Reproduce Consistently** + - Can you trigger it reliably? + - What are the exact steps? + - Does it happen every time? + - If not reproducible → gather more data, don't guess + +3. **Check Recent Changes** + - What changed that could cause this? + - Git diff, recent commits + - New dependencies, config changes + - Environmental differences + +4. **Gather Evidence in Multi-Component Systems** + + **WHEN system has multiple components (service → component → template, or module → provider → consumer):** + + **BEFORE proposing fixes, add diagnostic instrumentation:** + + ``` + For EACH component boundary: + - Log what data enters component + - Log what data exits component + - Verify environment/config propagation + - Check state at each layer + + Run once to gather evidence showing WHERE it breaks + THEN analyze evidence to identify failing component + THEN investigate that specific component + ``` + +5. **Trace Data Flow** + + **WHEN error is deep in call stack:** + + See `references/root-cause-tracing.md` in this directory for the complete backward tracing technique. + + **Quick version:** + - Where does bad value originate? + - What called this with bad value? + - Keep tracing up until you find the source + - Fix at source, not at symptom + +6. **Angular-Specific Investigation** + + **Change Detection:** + - Is the component using `OnPush`? Does the input change by reference or just mutation? + - Is `markForCheck()` or `detectChanges()` missing after an async operation? + - Is the component using signals? Check that computed signals depend on the right reactive sources. + + **Dependency Injection:** + - Trace the provider tree. Is the service provided at the right level (`root`, component, module)? + - Is there an unexpected singleton vs. per-component instance? + - Is a `providedIn: 'root'` service being accidentally overridden by a module provider? + + **Lifecycle Hooks:** + - `ngOnInit` fires after first `detectChanges()`. Don't access DOM here. + - `ngAfterViewInit` fires after child views initialize. `@ViewChild` is `undefined` before this. + - `ngOnChanges` fires before `ngOnInit` and on every input change. + + **Zone.js:** + - Is the code running outside NgZone (e.g., third-party callback, `requestAnimationFrame`, WebSocket)? + - Does wrapping in `NgZone.run()` fix it? + + **Harness Environment:** + - For overlay-based components (modals, flyouts, popovers), use `TestbedHarnessEnvironment.documentRootLoader(fixture)` not `.loader(fixture)`. + - Harness methods are async — are you awaiting them? + + See `references/angular-debugging.md` in this directory for detailed guidance. + +### Phase 2: Pattern Analysis + +**Find the pattern before fixing:** + +1. **Find Working Examples** + - Locate similar working code in same codebase + - In this monorepo, search `libs/components/` for a working component similar to yours + - Harness tests in `*/testing/src/` demonstrate the canonical interaction pattern + +2. **Compare Against References** + - If implementing pattern, read reference implementation COMPLETELY + - Read the corresponding harness class to understand what DOM structure the component exposes for testing + - Don't skim — read every line + - Understand the pattern fully before applying + +3. **Identify Differences** + - What's different between working and broken? + - List every difference, however small + - Pay attention to: standalone vs. non-standalone components, module imports vs. standalone imports, `data-sky-id` attribute presence + - Don't assume "that can't matter" + +4. **Understand Dependencies** + - What other components does this need? + - Check if the component requires a service, an overlay container, or specific module imports + - What settings, config, environment? + - What assumptions does it make? + +### Phase 3: Hypothesis and Testing + +**Scientific method:** + +1. **Form Single Hypothesis** + - State clearly: "I think X is the root cause because Y" + - Write it down + - Be specific, not vague + +2. **Test Minimally** + - Make the SMALLEST possible change to test hypothesis + - One variable at a time + - Don't fix multiple things at once + +3. **Angular Isolation Techniques** + - Use `TestBed.configureTestingModule()` to create a minimal reproduction with only the modules/components needed + - For change detection hypotheses: toggle between `ChangeDetectionStrategy.Default` and `OnPush` in the test component + - For DI hypotheses: provide a spy service to verify calls + - For timing hypotheses: use `fakeAsync`/`tick` to control time precisely + - For harness hypotheses: verify harness finds the element with `loader.getHarness()` before testing behavior + +4. **Verify Before Continuing** + - Did it work? Yes → Phase 4 + - Didn't work? Form NEW hypothesis + - DON'T add more fixes on top + +5. **When You Don't Know** + - Say "I don't understand X" + - Don't pretend to know + - Ask for help + - Research more + +### Phase 4: Implementation + +**Fix the root cause, not the symptom:** + +1. **Create Failing Test Case** + - Use component harnesses for the regression test: + 1. Set up `TestBed` with the component under test + 2. Create harness loader: `TestbedHarnessEnvironment.loader(fixture)` (or `documentRootLoader` for overlays) + 3. Get the harness: `const harness = await loader.getHarness(SkyXxxHarness)` + 4. Write the assertion that fails: `await expectAsync(harness.getSomething()).toBeResolvedTo(expected)` + 5. Watch the test fail + - Use the `skyux-test-driven-development` skill for writing proper failing tests + +2. **Implement Single Fix** + - Address the root cause identified + - ONE change at a time + - No "while I'm here" improvements + - No bundled refactoring + +3. **Verify Fix** + - Test passes now? + - No other tests broken? + - Issue actually resolved? + +4. **If Fix Doesn't Work** + - STOP + - Count: How many fixes have you tried? + - If < 3: Return to Phase 1, re-analyze with new information + - **If ≥ 3: STOP and question the architecture (step 5 below)** + - DON'T attempt Fix #4 without architectural discussion + +5. **If 3+ Fixes Failed: Question Architecture** + + **Pattern indicating architectural problem:** + - Each fix reveals new shared state/coupling/problem in different place + - Fixes require "massive refactoring" to implement + - Each fix creates new symptoms elsewhere + + **STOP and question fundamentals:** + - Is this pattern fundamentally sound? + - Are we "sticking with it through sheer inertia"? + - Should we refactor architecture vs. continue fixing symptoms? + + **Discuss with your human partner before attempting more fixes** + + This is NOT a failed hypothesis — this is a wrong architecture. + +## Red Flags - STOP and Follow Process + +If you catch yourself thinking: + +- "Quick fix for now, investigate later" +- "Just try changing X and see if it works" +- "Add multiple changes, run tests" +- "Skip the test, I'll manually verify" +- "It's probably X, let me fix that" +- "I don't fully understand but this might work" +- "Pattern says X but I'll adapt it differently" +- "Here are the main problems: [lists fixes without investigation]" +- Proposing solutions before tracing data flow +- **"One more fix attempt" (when already tried 2+)** +- **Each fix reveals new problem in different place** + +**ALL of these mean: STOP. Return to Phase 1.** + +**If 3+ fixes failed:** Question the architecture (see Phase 4.5) + +## Angular/SKY UX Anti-Patterns + +| Anti-Pattern | Why It Fails | What to Do Instead | +| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | +| **ng-mocks** (`MockComponent`, `MockModule`) | Hijacks Angular's test environment, masks real DI/template issues, adds a dependency this repo does not use | Use `fixture.debugElement.query(By.directive(Component))` to access child instances, simple stub components, or the real component | +| **Mocking SKY UX services with `jasmine.createSpyObj`** | Couples tests to SKY UX service internals; breaks when the service API changes | Use official testing controllers from `@skyux/*/testing` (e.g., `SkyModalTestingController`, `SkyConfirmTestingController`) | +| **Over-mocking services** | When everything is mocked, the test only tests your mocks | Mock at boundaries (HTTP, external services), use real SKY UX services and testing controllers | +| **`setTimeout`/`sleep` in tests** | Arbitrary waits are flaky; pass on fast machines, fail in CI | Use `fakeAsync`/`tick`, harness `await` patterns, or condition-based waiting | +| **Direct DOM queries on internal classes** | Internal CSS classes (`sky-modal-content`, etc.) can change across versions | Use component harnesses which provide stable APIs | +| **Skipping `detectChanges()`** | Template bindings not evaluated, harness sees stale DOM | Always call `detectChanges()` after changing inputs; harnesses handle this internally for interactions | + +## Your Human Partner's Signals You're Doing It Wrong + +**Watch for these redirections:** + +- "Is that not happening?" — You assumed without verifying +- "Will it show us...?" — You should have added evidence gathering +- "Stop guessing" — You're proposing fixes without understanding +- "Ultrathink this" — Question fundamentals, not just symptoms +- "We're stuck?" (frustrated) — Your approach isn't working + +**When you see these:** STOP. Return to Phase 1. + +## Common Rationalizations + +| Excuse | Reality | +| -------------------------------------------------------- | ----------------------------------------------------------------------------- | +| "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. | +| "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. | +| "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. | +| "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. | +| "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. | +| "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. | +| "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. | +| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. | +| "ng-mocks makes setup easier" | It replaces Angular's real behavior with stubs. You end up testing a fiction. | +| "I'll query the DOM directly, harness is too much setup" | Harnesses are the contract. Direct DOM queries break on internal refactors. | + +## Quick Reference + +| Phase | Key Activities | Success Criteria | +| --------------------- | -------------------------------------------------------------------------------------- | --------------------------- | +| **1. Root Cause** | Read errors, reproduce, check changes, gather evidence, Angular-specific investigation | Understand WHAT and WHY | +| **2. Pattern** | Find working examples in `libs/components/`, compare harness tests | Identify differences | +| **3. Hypothesis** | Form theory, test minimally, use Angular isolation techniques | Confirmed or new hypothesis | +| **4. Implementation** | Create harness-based regression test, fix, verify | Bug resolved, tests pass | + +## When Process Reveals "No Root Cause" + +If systematic investigation reveals issue is truly environmental, timing-dependent, or external: + +1. You've completed the process +2. Document what you investigated +3. Implement appropriate handling (retry, timeout, error message) +4. Add monitoring/logging for future investigation + +**But:** 95% of "no root cause" cases are incomplete investigation. + +## Supporting Techniques + +These techniques are part of systematic debugging and available in this directory: + +- **`references/root-cause-tracing.md`** — Trace bugs backward through call stack to find original trigger +- **`references/defense-in-depth.md`** — Add validation at multiple layers after finding root cause +- **`references/condition-based-waiting.md`** — Replace arbitrary timeouts with condition polling; includes Angular `fakeAsync`/`tick` patterns +- **`references/angular-debugging.md`** — Angular-specific debugging: change detection, DI, lifecycle hooks, zone.js, overlay testing + +**Related skills:** + +- **[skyux-test-driven-development](../skyux-test-driven-development/SKILL.md)** — For creating failing test case (Phase 4, Step 1) +- **[skyux-verification-before-completion](../skyux-verification-before-completion/SKILL.md)** — Verify fix worked before claiming success + +## Real-World Impact + +From debugging sessions: + +- Systematic approach: 15-30 minutes to fix +- Random fixes approach: 2-3 hours of thrashing +- First-time fix rate: 95% vs 40% +- New bugs introduced: Near zero vs common + +## Attribution + +Based on [superpowers](https://github.com/obra/superpowers) by Jesse Vincent, licensed under [MIT](https://github.com/obra/superpowers/blob/main/LICENSE). diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md new file mode 100644 index 0000000000..f6e8b5612a --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md @@ -0,0 +1,202 @@ +# Angular Debugging for SKY UX + +**Load this reference when:** debugging Angular-specific issues like change detection, dependency injection, lifecycle hooks, or overlay rendering. + +## Change Detection Issues + +### Symptoms + +- Template shows stale data +- Binding doesn't update after async operation +- Component works with `Default` strategy but breaks with `OnPush` + +### Investigation + +1. **Check the change detection strategy.** `OnPush` components only re-render when: + - An input reference changes (not just content mutation) + - An event fires from the component or a child + - `markForCheck()` or `detectChanges()` is called manually + - An `async` pipe emits a new value + +2. **Check if input objects are mutated vs. replaced:** + + ```typescript + // ❌ Mutation — OnPush won't detect this + this.items.push(newItem); + + // ✅ New reference — OnPush detects this + this.items = [...this.items, newItem]; + ``` + +3. **Check signal usage.** If using signals, verify that computed signals depend on the correct reactive sources. A computed that reads a plain property (not a signal) won't re-evaluate. + +### In Tests + +- Always call `fixture.detectChanges()` after programmatic changes +- Harness methods handle their own change detection for interactions + +## Dependency Injection Issues + +### Symptoms + +- `NullInjectorError: No provider for XxxService` +- Service has unexpected state (wrong instance) +- Circular dependency errors + +### Investigation + +1. **Trace the provider tree:** + - `providedIn: 'root'` → singleton across app + - `providers: [...]` in `@Component` → new instance per component + - `providers: [...]` in `@NgModule` → shared within module + +2. **Check for accidental overrides.** A module-level provider can shadow a `providedIn: 'root'` service, creating a second instance. + +3. **In tests:** Verify `TestBed.configureTestingModule` providers match what the component expects: + ```typescript + TestBed.configureTestingModule({ + providers: [ + // Must provide everything the component injects + { provide: SkyModalService, useValue: mockService }, + ], + }); + ``` + +## Lifecycle Hook Issues + +### Execution Order + +``` +constructor → ngOnChanges → ngOnInit → ngAfterContentInit → ngAfterViewInit → ngOnDestroy +``` + +### Common Mistakes + +- **Accessing `@ViewChild` in `ngOnInit`** — it's `undefined` until `ngAfterViewInit` +- **Heavy logic in constructor** — DI is available, but inputs are not yet set +- **Forgetting `ngOnChanges` fires before `ngOnInit`** — and fires again on every input change + +### In Tests + +- `fixture.detectChanges()` triggers `ngOnInit` on first call +- Subsequent calls trigger `ngOnChanges` if inputs changed +- Use `fixture.componentRef.setInput()` to change inputs cleanly + +## Zone.js and Async Issues + +### Symptoms + +- UI doesn't update after callback +- `setTimeout` or `requestAnimationFrame` callback doesn't trigger change detection +- Third-party library events don't update the view + +### Investigation + +1. **Is the code running outside NgZone?** Common causes: + - Third-party library callbacks + - `requestAnimationFrame` + - WebSocket message handlers + - `addEventListener` called outside Angular + +2. **Fix:** Wrap in `NgZone.run()`: + ```typescript + this.ngZone.run(() => { + this.data = newData; + }); + ``` + +### In Tests + +- `fakeAsync` + `tick()` controls the virtual clock +- `tick(debounceTime)` for debounced inputs +- `flush()` drains all pending async tasks + +## Overlay / Portal Component Testing + +### The Problem + +Modals, flyouts, popovers, and dropdowns render in the **document root**, outside the component's DOM tree. The standard `TestbedHarnessEnvironment.loader(fixture)` only searches within the component. + +### The Fix + +```typescript +// ❌ WRONG — overlay content is NOT inside the component +const loader = TestbedHarnessEnvironment.loader(fixture); +const modal = await loader.getHarness(SkyModalHarness); // Throws! + +// ✅ CORRECT — search the entire document +const rootLoader = TestbedHarnessEnvironment.documentRootLoader(fixture); +const modal = await rootLoader.getHarness(SkyModalHarness); +``` + +### Pattern for Modal/Flyout Tests + +```typescript +async function setupTest(): Promise<{ + fixture: ComponentFixture; + modalHarness: SkyModalHarness; + loader: HarnessLoader; +}> { + const fixture = TestBed.createComponent(TestComponent); + fixture.detectChanges(); + + // Open the modal + fixture.componentInstance.openModal(); + fixture.detectChanges(); + + const loader = TestbedHarnessEnvironment.documentRootLoader(fixture); + const modalHarness = await loader.getHarness(SkyModalHarness); + + return { fixture, modalHarness, loader }; +} +``` + +## SKY UX Harness Hierarchy + +``` +ComponentHarness (Angular CDK) + └── SkyComponentHarness (@skyux/core/testing) + ├── SkyAvatarHarness + ├── SkyModalHarness + ├── SkyTabsetHarness + └── ... all other Sky*Harness classes +``` + +- **`SkyComponentHarness`** adds `data-sky-id` support via `getDataSkyIdPredicate()` +- Use `.with({ dataSkyId: 'xxx' })` to target specific instances +- All methods are async — always `await` them + +## Common Test Setup Pattern + +```typescript +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +@Component({ + imports: [SkyExampleModule], + template: ``, +}) +class TestComponent { + protected value = input(); +} + +describe('Example', () => { + async function setupTest(): Promise<{ + fixture: ComponentFixture; + harness: SkyExampleHarness; + }> { + const fixture = TestBed.createComponent(TestComponent); + const loader = TestbedHarnessEnvironment.loader(fixture); + const harness = await loader.getHarness( + SkyExampleHarness.with({ dataSkyId: 'test-example' }), + ); + return { fixture, harness }; + } + + it('should display the value', async () => { + const { fixture, harness } = await setupTest(); + fixture.componentRef.setInput('value', 'Hello'); + await expectAsync(harness.getText()).toBeResolvedTo('Hello'); + }); +}); +``` diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md new file mode 100644 index 0000000000..43214d5533 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md @@ -0,0 +1,171 @@ +# Condition-Based Waiting + +## Overview + +Flaky tests often guess at timing with arbitrary delays. This creates race conditions where tests pass on fast machines but fail under load or in CI. + +**Core principle:** Wait for the actual condition you care about, not a guess about how long it takes. + +## When to Use + +```mermaid +flowchart TD + A{"Test uses setTimeout/sleep?"} -- yes --> B{"Testing timing behavior?"} + B -- yes --> C["Document WHY timeout needed"] + B -- no --> D["Use condition-based waiting"] +``` + +**Use when:** + +- Tests have arbitrary delays (`setTimeout`, `sleep`, `time.sleep()`) +- Tests are flaky (pass sometimes, fail under load) +- Tests timeout when run in parallel +- Waiting for async operations to complete + +**Don't use when:** + +- Testing actual timing behavior (debounce, throttle intervals) +- Always document WHY if using arbitrary timeout + +## Core Pattern + +```typescript +// ❌ BEFORE: Guessing at timing +await new Promise(r => setTimeout(r, 50)); +const result = getResult(); +expect(result).toBeDefined(); + +// ✅ AFTER: Waiting for condition +await waitFor(() => getResult() !== undefined); +const result = getResult(); +expect(result).toBeDefined(); +``` + +## Quick Patterns + +| Scenario | Pattern | +| ----------------- | ---------------------------------------------------- | +| Wait for event | `waitFor(() => events.find(e => e.type === 'DONE'))` | +| Wait for state | `waitFor(() => machine.state === 'ready')` | +| Wait for count | `waitFor(() => items.length >= 5)` | +| Wait for file | `waitFor(() => fs.existsSync(path))` | +| Complex condition | `waitFor(() => obj.ready && obj.value > 10)` | + +## Implementation + +Generic polling function: + +```typescript +async function waitFor( + condition: () => T | undefined | null | false, + description: string, + timeoutMs = 5000, +): Promise { + const startTime = Date.now(); + + while (true) { + const result = condition(); + if (result) return result; + + if (Date.now() - startTime > timeoutMs) { + throw new Error( + `Timeout waiting for ${description} after ${timeoutMs}ms`, + ); + } + + await new Promise((r) => setTimeout(r, 10)); // Poll every 10ms + } +} +``` + +## Angular-Specific Waiting Patterns + +### `fakeAsync` / `tick` (preferred for synchronous-style async) + +Use when testing debounced input, timers, or any time-based behavior: + +```typescript +import { fakeAsync, tick } from '@angular/core/testing'; + +it('should debounce search input', fakeAsync(() => { + const fixture = TestBed.createComponent(SearchComponent); + fixture.detectChanges(); + + const input = fixture.debugElement.query(By.css('input')); + input.nativeElement.value = 'search term'; + input.nativeElement.dispatchEvent(new Event('input')); + + // No results yet — debounce hasn't fired + expect(component.results().length).toBe(0); + + tick(300); // Advance past debounce time + fixture.detectChanges(); + + expect(component.results().length).toBeGreaterThan(0); +})); +``` + +### Harness Async (preferred for component interaction) + +Harness methods internally handle zone stabilization — just `await` them: + +```typescript +it('should filter results after typing', async () => { + const { fixture, harness } = await setupTest(); + + await harness.enterSearchText('angular'); + + // Harness handles waiting for zone to stabilize + const results = await harness.getResults(); + expect(results.length).toBeGreaterThan(0); +}); +``` + +### When to Use Which + +| Scenario | Pattern | +| ----------------------------- | ----------------------------------------------------------- | +| Testing debounced input | `fakeAsync` + `tick(debounceTime)` | +| Testing component interaction | Harness async (`await harness.method()`) | +| Testing HTTP response | `fakeAsync` + `tick()` with `HttpTestingController.flush()` | +| Testing animation completion | `fakeAsync` + `tick(animationDuration)` | +| Testing interval/timer | `fakeAsync` + `tick(intervalTime)` | +| Waiting for overlay to appear | `await rootLoader.getHarness(SkyModalHarness)` | + +## Common Mistakes + +**❌ Polling too fast:** `setTimeout(check, 1)` — wastes CPU +**✅ Fix:** Poll every 10ms + +**❌ No timeout:** Loop forever if condition never met +**✅ Fix:** Always include timeout with clear error + +**❌ Stale data:** Cache state before loop +**✅ Fix:** Call getter inside loop for fresh data + +**❌ `setTimeout` in Angular test:** Arbitrary delays are flaky +**✅ Fix:** Use `fakeAsync`/`tick` or harness async patterns + +## When Arbitrary Timeout IS Correct + +```typescript +// Tool ticks every 100ms — need 2 ticks to verify partial output +await waitForEvent(manager, 'TOOL_STARTED'); // First: wait for condition +await new Promise((r) => setTimeout(r, 200)); // Then: wait for timed behavior +// 200ms = 2 ticks at 100ms intervals — documented and justified +``` + +**Requirements:** + +1. First wait for triggering condition +2. Based on known timing (not guessing) +3. Comment explaining WHY + +## Real-World Impact + +From debugging session: + +- Fixed 15 flaky tests across 3 files +- Pass rate: 60% → 100% +- Execution time: 40% faster +- No more race conditions diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/defense-in-depth.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/defense-in-depth.md new file mode 100644 index 0000000000..c443814311 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/defense-in-depth.md @@ -0,0 +1,136 @@ +# Defense-in-Depth Validation + +## Overview + +When you fix a bug caused by invalid data, adding validation at one place feels sufficient. But that single check can be bypassed by different code paths, refactoring, or mocks. + +**Core principle:** Validate at EVERY layer data passes through. Make the bug structurally impossible. + +## Why Multiple Layers + +Single validation: "We fixed the bug" +Multiple layers: "We made the bug impossible" + +Different layers catch different cases: + +- Entry validation catches most bugs +- Business logic catches edge cases +- Environment guards prevent context-specific dangers +- Debug logging helps when other layers fail + +## The Four Layers + +### Layer 1: Component Input Validation + +**Purpose:** Reject obviously invalid input at the component boundary + +```typescript +@Component({ selector: 'app-user-card' }) +export class UserCardComponent { + public userId = input.required(); + + constructor() { + effect(() => { + const id = this.userId(); + if (!id || id.trim() === '') { + throw new Error('UserCardComponent: userId input cannot be empty'); + } + }); + } +} +``` + +### Layer 2: Service-Level Validation + +**Purpose:** Ensure data makes sense for this operation + +```typescript +@Injectable({ providedIn: 'root' }) +export class UserService { + public getUser(userId: string): Observable { + if (!userId) { + throw new Error('UserService.getUser: userId is required'); + } + return this.http.get(`/api/users/${userId}`); + } +} +``` + +### Layer 3: HTTP Interceptor Guards + +**Purpose:** Catch invalid requests before they leave the app + +```typescript +@Injectable() +export class ValidationInterceptor implements HttpInterceptor { + public intercept( + req: HttpRequest, + next: HttpHandler, + ): Observable> { + // Catch API calls with empty path segments + if (req.url.includes('//') || req.url.endsWith('/')) { + throw new Error( + `Invalid API request: URL contains empty path segment: ${req.url}`, + ); + } + return next.handle(req); + } +} +``` + +### Layer 4: Debug Instrumentation + +**Purpose:** Capture context for forensics when other layers miss something + +```typescript +@Injectable({ providedIn: 'root' }) +export class UserService { + public getUser(userId: string): Observable { + console.debug('UserService.getUser called:', { + userId, + callerStack: new Error().stack, + }); + return this.http.get(`/api/users/${userId}`); + } +} +``` + +## Applying the Pattern + +When you find a bug: + +1. **Trace the data flow** — Where does bad value originate? Where used? +2. **Map all checkpoints** — List every point data passes through +3. **Add validation at each layer** — Entry, business, environment, debug +4. **Test each layer** — Try to bypass layer 1, verify layer 2 catches it + +## Example: Empty User ID Causes Silent 404 + +Bug: User card component renders blank — no error, no loading indicator, just empty. + +**Data flow:** + +1. Parent template passes `[userId]="selectedUser()?.id"` — but `selectedUser()` is `undefined` +2. `UserCardComponent` receives `undefined` as input +3. `UserService.getUser(undefined)` makes HTTP call to `/api/users/undefined` +4. API returns 404, error handler swallows it silently + +**Four layers added:** + +- Layer 1: `UserCardComponent` validates `userId` input is non-empty in an `effect()` +- Layer 2: `UserService.getUser()` throws if `userId` is falsy +- Layer 3: HTTP interceptor rejects URLs with empty path segments +- Layer 4: Debug logging in `UserService` captures caller stack + +**Result:** The bug now throws at the component boundary with a clear error message, instead of silently rendering nothing. + +## Key Insight + +All four layers catch different failure modes: + +- Layer 1 catches the most common case (bad input from parent template) +- Layer 2 catches direct service calls from other services or resolvers +- Layer 3 catches any request path, even those bypassing the service +- Layer 4 helps diagnose cases the other layers don't anticipate + +**Don't stop at one validation point.** Add checks at every layer. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md new file mode 100644 index 0000000000..9b83276389 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md @@ -0,0 +1,180 @@ +# Root Cause Tracing + +## Overview + +Bugs often manifest deep in the call stack (wrong provider injected, stale data in a template, overlay rendered but invisible). Your instinct is to fix where the error appears, but that's treating a symptom. + +**Core principle:** Trace backward through the call chain until you find the original trigger, then fix at the source. + +## When to Use + +```mermaid +flowchart TD + A{"Bug appears deep in stack?"} -- yes --> B{"Can trace backwards?"} + B -- yes --> C["Trace to original trigger"] + B -- "no - dead end" --> D["Fix at symptom point"] + C --> E["BETTER: Also add defense-in-depth"] +``` + +**Use when:** + +- Error happens deep in execution (not at entry point) +- Stack trace shows long call chain +- Unclear where invalid data originated +- Need to find which test/code triggers the problem + +## The Tracing Process + +### 1. Observe the Symptom + +``` +NullInjectorError: No provider for SkyModalService! +``` + +### 2. Find Immediate Cause + +**What code directly causes this?** + +```typescript +// SkyModalService is injected in the component constructor +constructor(private modalService: SkyModalService) {} +``` + +### 3. Ask: What Called This? + +```typescript +TestBed.createComponent(MyPageComponent) + → Angular resolves DI for MyPageComponent + → MyPageComponent injects SkyModalService + → SkyModalService not in the test's provider tree +``` + +### 4. Keep Tracing Up + +**Why isn't it in the provider tree?** + +- `SkyModalService` is `providedIn: 'root'` — so it should be available +- But the test uses `TestBed.configureTestingModule` which creates a fresh injector +- The test imports `MyPageComponent` but not the module that provides the modal infrastructure + +### 5. Find Original Trigger + +**What's missing from the test setup?** + +```typescript +// Test imports the component but not the testing module +TestBed.configureTestingModule({ + imports: [MyPageComponent], // Missing: SkyModalTestingModule +}); +``` + +## Adding Diagnostic Instrumentation + +When you can't trace manually, add temporary logging: + +```typescript +// Before the problematic operation in the service +openModal(component: Type, config: SkyModalConfigurationInterface): void { + console.error('DEBUG openModal:', { + component: component.name, + config, + providers: config?.providers?.map(p => (p as any).provide?.name), + stack: new Error().stack, + }); + + this.modalService.open(component, config); +} +``` + +**Critical:** Use `console.error()` in tests (not a logger service — it may be mocked or suppressed) + +**Run and capture:** + +```bash +npx ng t --include="path/to/failing.spec.ts" 2>&1 | grep 'DEBUG openModal' +``` + +**Analyze the output:** + +- Which test triggered the call? +- What config was passed? +- Were the expected providers present? + +## Finding Which Test Causes Pollution + +When a test passes in isolation but fails when run with the full suite, another test is corrupting shared state (e.g., monkey-patching `TestBed`, mutating a singleton service, leaving DOM nodes behind). + +**The bisection technique:** + +1. Identify the **victim** — the test that fails when run with others but passes alone: + + ```bash + npx ng t --include="path/to/victim.spec.ts" # passes alone + npx ng t # fails in full suite + ``` + +2. Isolate candidates — run the victim after each individual spec file to find which one corrupts shared state: + + ```bash + # Run suspect followed by victim + npx ng t --include="path/to/suspect.spec.ts,path/to/victim.spec.ts" + ``` + +3. Narrow the search — if the suite is large, bisect by directory: + - Run the victim after the first half of the suite + - If it fails, the polluter is in that half; if it passes, check the other half + - Keep halving until you find the single polluting spec file + +**Common Angular pollution patterns:** + +- A test calls `TestBed.overrideProvider()` or `TestBed.overrideComponent()` without resetting +- A `beforeAll` modifies a `providedIn: 'root'` service that persists across describes +- A test adds DOM elements (overlays, modals) to `document.body` and doesn't clean up in `afterEach` +- A test patches a prototype method (`spyOn` on a shared class) without restoring it + +## Real Example: Modal Not Found in Test + +**Symptom:** `Error: Expected exactly one match for SkyModalHarness, but found 0.` + +**Trace chain:** + +1. `loader.getHarness(SkyModalHarness)` finds nothing +2. The modal IS open — `fixture.componentInstance.isModalOpen` is `true` +3. Modal renders in document root, outside the component's DOM tree +4. `TestbedHarnessEnvironment.loader(fixture)` only searches within the component +5. Test setup used `loader(fixture)` instead of `documentRootLoader(fixture)` + +**Root cause:** Wrong harness loader scope for overlay components + +**Fix:** Changed to `TestbedHarnessEnvironment.documentRootLoader(fixture)` + +**Also added defense-in-depth:** + +- Layer 1: Test helper function `setupOverlayTest()` that always uses `documentRootLoader` +- Layer 2: Comment in shared test utilities explaining when to use which loader +- Layer 3: Linter rule flagging `loader(fixture)` followed by `getHarness(SkyModalHarness)` + +## Key Principle + +```mermaid +flowchart TD + A(["Found immediate cause"]) --> B{"Can trace one level up?"} + B -- yes --> C["Trace backwards"] + B -- no --> STOP["NEVER fix just the symptom"]:::danger + C --> D{"Is this the source?"} + D -- "no - keeps going" --> C + D -- yes --> E["Fix at source"] + E --> F["Add validation at each layer"] + F --> G((("Bug impossible"))) + + classDef danger fill:#ff0000,color:#fff +``` + +**NEVER fix just where the error appears.** Trace back to find the original trigger. + +## Diagnostic Tips + +**In tests:** Use `console.error()` not a logger service — it may be mocked or suppressed +**Before the operation:** Log before the failing call, not in the catch block +**Include context:** Component name, input values, provider configuration, `new Error().stack` +**Angular-specific:** Log `TestBed` provider state with `TestBed.inject()` to verify what's actually registered diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md new file mode 100644 index 0000000000..86490009ae --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md @@ -0,0 +1,434 @@ +--- +name: skyux-test-driven-development +description: Use when implementing any Angular/SKY UX feature or bugfix, before writing implementation code. Covers Red-Green-Refactor cycle, TestBed setup, component harness testing, overlay testing patterns, and mocking strategies. Activate whenever writing new components, services, directives, or fixing bugs — even 'simple' ones. +--- + +# Test-Driven Development (TDD) for Angular / SKY UX + +## Overview + +Write the test first. Watch it fail. Write minimal code to pass. + +All examples use Angular TestBed, SKY UX component harnesses, and Jasmine. Prefer component harnesses over direct DOM queries — harnesses are the stable testing API. + +**Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing. + +**Violating the letter of the rules is violating the spirit of the rules.** + +## When to Use + +**Always:** + +- New features +- Bug fixes +- Refactoring +- Behavior changes + +**Exceptions (ask your human partner):** + +- Throwaway prototypes +- Generated code +- Configuration files + +Thinking "skip TDD just this once"? Stop. That's rationalization. + +## The Iron Law + +``` +NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST +``` + +Write code before the test? Delete it. Start over. + +**No exceptions:** + +- Don't keep it as "reference" +- Don't "adapt" it while writing tests +- Don't look at it +- Delete means delete + +Implement fresh from tests. Period. + +## Red-Green-Refactor + +```mermaid +flowchart LR + red["RED\nWrite failing test"]:::red --> verify_red{"Verify fails\ncorrectly"} + verify_red -- yes --> green["GREEN\nMinimal code"]:::green + verify_red -- "wrong\nfailure" --> red + green --> verify_green{"Verify passes\nAll green"} + verify_green -- yes --> refactor["REFACTOR\nClean up"]:::blue + verify_green -- no --> green + refactor -- "stay\ngreen" --> verify_green + verify_green --> next(["Next"]) + next --> red + + classDef red fill:#ffcccc,color:#000 + classDef green fill:#ccffcc,color:#000 + classDef blue fill:#ccccff,color:#000 +``` + +### RED - Write Failing Test + +Write one minimal test showing what should happen. + + +```typescript +it('should display the specified initials when no image is set', async () => { + const { fixture, harness } = await setupTest(); + +fixture.componentRef.setInput('name', 'Jane Doe'); + +await expectAsync(harness.getInitials()).toBeResolvedTo('JD'); +}); + +```` +Clear name, tests real behavior via harness, one thing + + + +```typescript +it('should work', async () => { + const fixture = TestBed.createComponent(AvatarComponent); + fixture.detectChanges(); + const el = fixture.debugElement.query(By.css('.sky-avatar-initials-inner')); + expect(el.nativeElement.textContent.trim()).toBe('JD'); +}); +```` + +Vague name, queries internal DOM classes, skips harness + + +**Requirements:** + +- One behavior +- Clear name +- Real code via harness (no DOM queries unless unavoidable) + +### Verify RED - Watch It Fail + +**MANDATORY. Never skip.** + +```bash +npx jest path/to/component.spec.ts +``` + +Confirm: + +- Test fails (not errors) +- Failure message is expected +- Fails because feature missing (not typos) + +**Test passes?** You're testing existing behavior. Fix test. + +**Test errors?** Fix error, re-run until it fails correctly. + +### GREEN - Minimal Code + +Write simplest code to pass the test. + + +```typescript +@Component({ + selector: 'sky-avatar', + template: ` +
+ {{ initials() }} +
+ `, +}) +export class AvatarComponent { + public name = input(); + +protected initials = computed(() => { +const name = this.name(); +if (!name) return undefined; +return name.split(' ').map(n => n[0]).join('').toUpperCase(); +}); +} + +```` +Just enough to pass +
+ + +```typescript +@Component({ + selector: 'sky-avatar', + template: `...`, +}) +export class AvatarComponent { + public name = input(); + public size = input('medium'); + public src = input(); + public canChange = input(false); + // YAGNI - test only asked for initials +} +```` + +Over-engineered beyond what the test requires + + +Don't add features, refactor other code, or "improve" beyond the test. + +### Verify GREEN - Watch It Pass + +**MANDATORY.** + +```bash +npx jest path/to/component.spec.ts +``` + +Confirm: + +- Test passes +- Other tests still pass +- Output pristine (no errors, warnings) + +**Test fails?** Fix code, not test. + +**Other tests fail?** Fix now. + +### REFACTOR - Clean Up + +After green only: + +- Remove duplication +- Improve names +- Extract helpers + +Keep tests green. Don't add behavior. + +### Repeat + +Next failing test for next feature. + +## Good Tests + +| Quality | Good | Bad | +| ----------------- | ---------------------------------------------- | --------------------------------------------------------------------- | +| **Minimal** | One thing. "and" in name? Split it. | `it('validates email and domain and whitespace')` | +| **Clear** | Name describes behavior | `it('test1')` | +| **Shows intent** | Demonstrates desired API | Obscures what code should do | +| **Harness-first** | Uses harness methods (`harness.getInitials()`) | Queries internal CSS classes (`By.css('.sky-avatar-initials-inner')`) | + +## Why Order Matters + +**"I'll write tests after to verify it works"** + +Tests written after code pass immediately. Passing immediately proves nothing: + +- Might test wrong thing +- Might test implementation, not behavior +- Might miss edge cases you forgot +- You never saw it catch the bug + +Test-first forces you to see the test fail, proving it actually tests something. + +**"I already manually tested all the edge cases"** + +Manual testing is ad-hoc. You think you tested everything but: + +- No record of what you tested +- Can't re-run when code changes +- Easy to forget cases under pressure +- "It worked when I tried it" ≠ comprehensive + +Automated tests are systematic. They run the same way every time. + +**"Deleting X hours of work is wasteful"** + +Sunk cost fallacy. The time is already gone. Your choice now: + +- Delete and rewrite with TDD (X more hours, high confidence) +- Keep it and add tests after (30 min, low confidence, likely bugs) + +The "waste" is keeping code you can't trust. Working code without real tests is technical debt. + +**"TDD is dogmatic, being pragmatic means adapting"** + +TDD IS pragmatic: + +- Finds bugs before commit (faster than debugging after) +- Prevents regressions (tests catch breaks immediately) +- Documents behavior (tests show how to use code) +- Enables refactoring (change freely, tests catch breaks) + +"Pragmatic" shortcuts = debugging in production = slower. + +**"Tests after achieve the same goals - it's spirit not ritual"** + +No. Tests-after answer "What does this do?" Tests-first answer "What should this do?" + +Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones. + +Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't). + +30 minutes of tests after ≠ TDD. You get coverage, lose proof tests work. + +## Common Rationalizations + +| Excuse | Reality | +| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | +| "Too simple to test" | Simple code breaks. Test takes 30 seconds. | +| "I'll test after" | Tests passing immediately prove nothing. | +| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" | +| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. | +| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. | +| "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. | +| "Need to explore first" | Fine. Throw away exploration, start with TDD. | +| "Test hard = design unclear" | Listen to test. Hard to test = hard to use. | +| "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. | +| "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. | +| "Existing code has no tests" | You're improving it. Add tests for existing code. | +| "I'll just query the DOM directly" | Harnesses are the stable API. Internal CSS classes change without notice. | +| "ng-mocks makes setup easier" | It replaces Angular's real behavior with stubs. You end up testing a fiction. Use real components + jasmine spies. | + +## Red Flags - STOP and Start Over + +- Code before test +- Test after implementation +- Test passes immediately +- Can't explain why test failed +- Tests added "later" +- Rationalizing "just this once" +- "I already manually tested it" +- "Tests after achieve the same purpose" +- "It's about spirit not ritual" +- "Keep as reference" or "adapt existing code" +- "Already spent X hours, deleting is wasteful" +- "TDD is dogmatic, I'm being pragmatic" +- "This is different because..." +- Querying internal DOM classes when a harness exists +- Importing `ng-mocks` or `MockBuilder` +- Using deprecated `Sky*Fixture` classes instead of `Sky*Harness` +- Using deprecated `Sky*TestingModule` instead of `provide*Testing()` functions + +**All of these mean: Delete code. Start over with TDD.** + +## Example: Bug Fix + +**Bug:** Avatar error modal not dismissable after invalid file upload + +**RED** + +```typescript +it('should close the error modal after an invalid file is uploaded', async () => { + const { fixture, harness } = await setupTest(); + + fixture.componentRef.setInput('canChange', true); + fixture.detectChanges(); + + await harness.dropAvatarFile( + new File([], 'test.txt', { type: 'text/plain' }), + ); + + await expectAsync(harness.hasFileTypeError()).toBeResolvedTo(true); + + await harness.closeError(); + + await expectAsync(harness.hasFileTypeError()).toBeResolvedTo(false); +}); +``` + +**Verify RED** + +```bash +$ npx jest avatar-harness.spec.ts +FAIL: Expected to be resolved to false but was resolved to true. +``` + +**GREEN** + +```typescript +public async closeError(): Promise { + const errorModal = await this.#errorModal(); + + if (!errorModal) { + throw new Error('No error is currently displayed.'); + } + + await errorModal.clickCloseButton(); +} +``` + +**Verify GREEN** + +```bash +$ npx jest avatar-harness.spec.ts +PASS +``` + +**REFACTOR** +Extract shared error modal assertions if needed. + +## Angular Testing Quick Reference + +For test setup patterns, component harness usage, overlay testing, mocking strategies, and available SKY UX testing utilities, read [Angular testing patterns for SKY UX](references/angular-testing-patterns.md). It covers: + +- TestBed configuration and minimal setup +- Component harness architecture (`SkyComponentHarness`, `data-sky-id`, harness methods) +- Overlay testing with `documentRootLoader` +- SKY UX testing controllers (`SkyModalTestingController`, etc.) +- Accessing child components with `debugElement` (no ng-mocks) +- Mocking strategies and deprecated patterns to avoid + +## Verification Checklist + +Before marking work complete: + +- [ ] Every new function/method has a test +- [ ] Watched each test fail before implementing +- [ ] Each test failed for expected reason (feature missing, not typo) +- [ ] Wrote minimal code to pass each test +- [ ] All tests pass +- [ ] Output pristine (no errors, warnings) +- [ ] Tests use real code (mocks only if unavoidable) +- [ ] Edge cases and errors covered +- [ ] Component harnesses used where available (not direct DOM queries) +- [ ] TestBed imports are minimal (only what the test needs) +- [ ] No deprecated `Sky*Fixture` classes or `Sky*TestingModule` modules +- [ ] Overlay components use `documentRootLoader` not `loader` + +Can't check all boxes? You skipped TDD. Start over. + +## When Stuck + +| Problem | Solution | +| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | +| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. | +| Test too complicated | Design too complicated. Simplify interface. | +| Must mock everything | Code too coupled. Use dependency injection. | +| Test setup huge | Extract helpers. Still complex? Simplify design. | +| No harness exists | Check `libs/components/*/testing/src/` for existing harnesses. If none, use `fixture.debugElement` with `data-sky-id` attributes. | +| Overlay not found in test | Use `TestbedHarnessEnvironment.documentRootLoader(fixture)` instead of `.loader(fixture)`. | +| Need to test responsive behavior | Use `provideSkyMediaQueryTesting()` to mock media breakpoints. | + +## Debugging Integration + +Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression. + +Never fix bugs without a test. See the [fix-bugs](../migration-resolver/SKILL.md) skill for the full systematic debugging process. + +## Testing Anti-Patterns + +When adding mocks or test utilities, read [testing antipatterns](references/testing-antipatterns.md) to avoid common pitfalls: + +- Testing mock behavior instead of real behavior +- Adding test-only methods to production classes +- Mocking without understanding dependencies +- Using ng-mocks when simple mocks suffice +- Querying internal DOM when harnesses exist + +## Final Rule + +``` +Production code → test exists and failed first +Otherwise → not TDD +``` + +No exceptions without your human partner's permission. + +## Attribution + +Based on [superpowers](https://github.com/obra/superpowers) by Jesse Vincent, licensed under [MIT](https://github.com/obra/superpowers/blob/main/LICENSE). diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md new file mode 100644 index 0000000000..bb3f3a9382 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md @@ -0,0 +1,285 @@ +# Angular testing patterns for SKY UX + +**Load this reference when:** setting up a new test file, creating a component harness, or unsure which testing utility to use. + +## TestBed Configuration + +### Minimal Setup + +```typescript +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +describe('My component', () => { + async function setupTest(): Promise<{ + fixture: ComponentFixture; + harness: SkyExampleHarness; + }> { + const fixture = TestBed.createComponent(TestComponent); + const loader = TestbedHarnessEnvironment.loader(fixture); + const harness = await loader.getHarness( + SkyExampleHarness.with({ dataSkyId: 'test-example' }), + ); + return { fixture, harness }; + } +}); +``` + +### Key Principles + +- Import only what the test needs — don't import entire library modules when a single component suffices +- Use `fixture.componentRef.setInput()` for signal inputs (not direct property assignment) +- Call `fixture.detectChanges()` after programmatic changes when not using harness methods + +## Component Harness Architecture + +### Base Class: `SkyComponentHarness` + +All SKY UX harnesses extend `SkyComponentHarness` from `@skyux/core/testing`, which extends Angular CDK's `ComponentHarness`. + +```typescript +import { SkyComponentHarness } from '@skyux/core/testing'; + +export class SkyExampleHarness extends SkyComponentHarness { + public static hostSelector = 'sky-example'; + + public static with( + filters: SkyExampleHarnessFilters, + ): HarnessPredicate { + return SkyExampleHarness.getDataSkyIdPredicate(filters); + } + + public async getText(): Promise { + const el = await this.locatorFor('.sky-example-text')(); + return el.text(); + } +} +``` + +### Key Harness Methods + +| Method | Purpose | +| ------------------------------ | ------------------------------------------------------------ | +| `locatorFor(selector)` | Find a required child element | +| `locatorForOptional(selector)` | Find an optional child element | +| `locatorForAll(selector)` | Find all matching child elements | +| `host()` | Get the host element | +| `documentRootLocatorFactory()` | Create locator for elements outside component DOM (overlays) | + +### Targeting Instances with `data-sky-id` + +```typescript +// In template + + +// In test +const harness = await loader.getHarness( + SkyAvatarHarness.with({ dataSkyId: 'user-avatar' }), +); +``` + +## Overlay Testing + +Modals, flyouts, popovers, and dropdowns render in the document root, **outside** the component's DOM tree. + +```typescript +// ❌ WRONG: loader() only searches within the component +const loader = TestbedHarnessEnvironment.loader(fixture); +const modal = await loader.getHarness(SkyModalHarness); // Will NOT find it + +// ✅ CORRECT: documentRootLoader() searches the entire document +const rootLoader = TestbedHarnessEnvironment.documentRootLoader(fixture); +const modal = await rootLoader.getHarness(SkyModalHarness); +``` + +## SKY UX Testing Utilities + +### `@skyux/core/testing` + +| Export | Purpose | +| ------------------------------- | ------------------------------------------------------ | +| `SkyComponentHarness` | Base class for all SKY UX harnesses | +| `SkyHarnessUtility` | Shared harness helpers (e.g., `getBackgroundImageUrl`) | +| `SkyInputHarness` | Harness for input elements | +| `provideSkyMediaQueryTesting()` | Mock media query breakpoints in tests | +| `SkyHelpTestingController` | Control help panel behavior in tests | + +### `@skyux-sdk/testing` + +| Export | Purpose | +| ------------------------ | ------------------------------------------------------ | +| `expect` / `expectAsync` | Extended Jasmine matchers for SKY UX | +| `SkyAppTestUtility` | DOM utilities (`getText`, `isVisible`, `fireDomEvent`) | + +## Accessing Components and Directives with `debugElement` + +Angular's `fixture.debugElement` provides native access to child components and directives — no extra library needed. + +### Query by Directive + +```typescript +import { By } from '@angular/platform-browser'; + +// Find a child component instance +const childDebugEl = fixture.debugElement.query(By.directive(ChildComponent)); +const childInstance = childDebugEl.componentInstance; + +// Find a directive on an element +const highlightEl = fixture.debugElement.query( + By.directive(HighlightDirective), +); +const directive = highlightEl.injector.get(HighlightDirective); +``` + +### Query by CSS (when no harness exists) + +```typescript +// Prefer data-sky-id over internal CSS classes +const el = fixture.debugElement.query(By.css('[data-sky-id="my-element"]')); + +// Access native element when needed +const nativeEl: HTMLElement = el.nativeElement; +``` + +### Query All + +```typescript +// Find all instances of a component +const allItems = fixture.debugElement.queryAll(By.directive(ItemComponent)); +expect(allItems.length).toBe(3); +``` + +**This replaces ng-mocks patterns:** + +```typescript +// ❌ ng-mocks +const comp = ngMocks.find(SomeComponent).componentInstance; + +// ✅ Angular native +const comp = fixture.debugElement.query(By.directive(SomeComponent)).componentInstance; +``` + +## Mocking Without ng-mocks + +### SKY UX Testing Controllers (preferred for SKY UX services) + +SKY UX provides purpose-built testing utilities in `@skyux/*/testing`. Always prefer these over hand-rolling mocks with `jasmine.createSpyObj`. + +```typescript +// ✅ GOOD: Use testing controller for modals +import { + SkyModalTestingController, + SkyModalTestingModule, +} from '@skyux/modals/testing'; + +TestBed.configureTestingModule({ + imports: [SkyModalTestingModule, MyComponent], +}); + +const modalController = TestBed.inject(SkyModalTestingController); + +fixture.componentInstance.openModal(); +fixture.detectChanges(); + +modalController.expectOpen(MyModalComponent); +modalController.closeTopModal({ data: {}, reason: 'save' }); +modalController.expectNone(); +``` + +**Available testing controllers and modules:** + +| Package | Testing Utility | Purpose | +| ----------------------- | ------------------------------------------------------------------ | ------------------------------------------- | +| `@skyux/modals/testing` | `SkyModalTestingController` / `SkyModalTestingModule` | Mock modal service, assert modal open/close | +| `@skyux/modals/testing` | `SkyConfirmTestingController` / `SkyConfirmTestingModule` | Mock confirm dialogs, assert open/close | +| `@skyux/core/testing` | `SkyMediaQueryTestingController` / `provideSkyMediaQueryTesting()` | Mock responsive breakpoints | +| `@skyux/core/testing` | `SkyHelpTestingController` / `SkyHelpTestingModule` | Control help panel behavior | +| `@skyux/core/testing` | `provideSkyFileReaderTesting()` | Mock file reader | +| `@skyux/forms/testing` | `provideSkyFileAttachmentTesting()` | Mock file attachment behavior | + +### Service Mocking (fallback for non-SKY UX services) + +```typescript +// Use jasmine.createSpyObj only for services without a testing controller +const mockService = jasmine.createSpyObj('MyCustomService', ['getData']); + +TestBed.configureTestingModule({ + providers: [{ provide: MyCustomService, useValue: mockService }], +}); +``` + +### Component Mocking + +```typescript +// Simple stub component +@Component({ template: '' }) +class StubChildComponent {} + +// For standalone components +@Component({ template: '', standalone: true }) +class StubStandaloneComponent {} +``` + +### Spy on Existing Methods + +```typescript +// Spy on a real service method +const service = TestBed.inject(MyService); +spyOn(service, 'getData').and.callThrough(); +``` + +## Deprecated Patterns + +### Fixture Classes → Harnesses + +```typescript +// ❌ DEPRECATED +import { SkyAvatarFixture } from '@skyux/avatar/testing'; +const fixture = new SkyAvatarFixture(componentFixture, 'test-avatar'); +const initials = fixture.initials; + +// ✅ CURRENT +import { SkyAvatarHarness } from '@skyux/avatar/testing'; +const loader = TestbedHarnessEnvironment.loader(componentFixture); +const harness = await loader.getHarness( + SkyAvatarHarness.with({ dataSkyId: 'test-avatar' }), +); +const initials = await harness.getInitials(); +``` + +### Testing Modules → Provider Functions + +```typescript +// ❌ DEPRECATED +import { SkyCoreTestingModule } from '@skyux/core/testing'; +// ✅ CURRENT +import { provideSkyMediaQueryTesting } from '@skyux/core/testing'; + +TestBed.configureTestingModule({ + imports: [SkyCoreTestingModule], +}); + +TestBed.configureTestingModule({ + providers: [provideSkyMediaQueryTesting()], +}); +``` + +## Quick Decision Tree + +``` +Need to test a SKY UX component? +├── Harness exists in @skyux/*/testing? +│ ├── Yes → Use the harness +│ └── No → Use fixture.debugElement with data-sky-id +├── Component renders in overlay (modal, flyout)? +│ └── Use documentRootLoader +├── Need to mock a SKY UX service? +│ ├── Testing controller exists? → Use it (SkyModalTestingController, etc.) +│ └── No controller? → Use jasmine.createSpyObj + provider override +├── Need to mock a non-SKY UX service? +│ └── Use jasmine.createSpyObj + provider override +├── Need to access a child component instance? +│ └── Use fixture.debugElement.query(By.directive(Component)).componentInstance +└── Need to mock a child component? + └── Use simple @Component({ template: '' }) stub +``` diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/testing-antipatterns.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/testing-antipatterns.md new file mode 100644 index 0000000000..64a2ac70f9 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/testing-antipatterns.md @@ -0,0 +1,512 @@ +# Testing antipatterns + +**Load this reference when:** writing or changing tests, adding mocks, or tempted to add test-only methods to production code. + +## Overview + +Tests must verify real behavior, not mock behavior. Mocks are a means to isolate, not the thing being tested. + +**Core principle:** Test what the code does, not what the mocks do. + +**Following strict TDD prevents these anti-patterns.** + +## The Iron Laws + +``` +1. NEVER test mock behavior +2. NEVER add test-only methods to production classes +3. NEVER mock without understanding dependencies +4. NEVER use ng-mocks — use simple mocks and real components +5. NEVER query internal DOM when a harness exists +``` + +## Anti-Pattern 1: Testing Mock Behavior + +**The violation:** + +```typescript +// ❌ BAD: Testing that the mock exists +it('should render sidebar', () => { + const fixture = TestBed.createComponent(PageComponent); + fixture.detectChanges(); + const sidebar = fixture.debugElement.query(By.css('app-sidebar-mock')); + expect(sidebar).toBeTruthy(); +}); +``` + +**Why this is wrong:** + +- You're verifying the mock works, not that the component works +- Test passes when mock is present, fails when it's not +- Tells you nothing about real behavior + +**The fix:** + +```typescript +// ✅ GOOD: Test real component or don't mock it +it('should render sidebar', () => { + const fixture = TestBed.createComponent(PageComponent); + fixture.detectChanges(); + // Don't mock sidebar — test Page's behavior with real sidebar + const nav = fixture.debugElement.query(By.css('[role="navigation"]')); + expect(nav).toBeTruthy(); +}); +``` + +### Gate Function + +``` +BEFORE asserting on any mock element: + Ask: "Am I testing real component behavior or just mock existence?" + + IF testing mock existence: + STOP - Delete the assertion or unmock the component + + Test real behavior instead +``` + +## Anti-Pattern 2: Test-Only Methods in Production + +**The violation:** + +```typescript +// ❌ BAD: destroy() only used in tests +@Injectable({ providedIn: 'root' }) +export class SessionService { + async destroy() { + // Looks like production API! + await this.workspaceManager?.destroyWorkspace(this.id); + } +} + +// In tests +afterEach(() => sessionService.destroy()); +``` + +**Why this is wrong:** + +- Production class polluted with test-only code +- Dangerous if accidentally called in production +- Violates YAGNI and separation of concerns + +**The fix:** + +```typescript +// ✅ GOOD: Test utilities handle test cleanup +// SessionService has no destroy() — it's stateless in production + +// In test-utils/ +export function cleanupSession(sessionService: SessionService): void { + const workspace = sessionService.getWorkspaceInfo(); + if (workspace) { + workspaceManager.destroyWorkspace(workspace.id); + } +} + +// In tests +afterEach(() => cleanupSession(sessionService)); +``` + +### Gate Function + +``` +BEFORE adding any method to production class: + Ask: "Is this only used by tests?" + + IF yes: + STOP - Don't add it + Put it in test utilities instead + + Ask: "Does this class own this resource's lifecycle?" + + IF no: + STOP - Wrong class for this method +``` + +## Anti-Pattern 3: Mocking Without Understanding + +**The violation:** + +```typescript +// ❌ BAD: Mock prevents behavior the test depends on +it('should detect duplicate configuration', () => { + const catalogSpy = jasmine.createSpyObj('ToolCatalog', ['discoverAndCache']); + catalogSpy.discoverAndCache.and.returnValue(Promise.resolve()); + + // Mocked method had a side effect test depends on (writing config) + await addServer(config); + await addServer(config); // Should throw — but won't! +}); +``` + +**Why this is wrong:** + +- Mocked method had side effect test depended on +- Over-mocking to "be safe" breaks actual behavior +- Test passes for wrong reason or fails mysteriously + +**The fix:** + +```typescript +// ✅ GOOD: Mock at correct level +it('should detect duplicate configuration', () => { + // Mock the slow part, preserve behavior test needs + spyOn(serverManager, 'startServer').and.returnValue(Promise.resolve()); + + await addServer(config); // Config written + await addServer(config); // Duplicate detected ✓ +}); +``` + +### Gate Function + +``` +BEFORE mocking any method: + STOP - Don't mock yet + + 1. Ask: "What side effects does the real method have?" + 2. Ask: "Does this test depend on any of those side effects?" + 3. Ask: "Do I fully understand what this test needs?" + + IF depends on side effects: + Mock at lower level (the actual slow/external operation) + OR use test doubles that preserve necessary behavior + NOT the high-level method the test depends on + + IF unsure what test depends on: + Run test with real implementation FIRST + Observe what actually needs to happen + THEN add minimal mocking at the right level + + Red flags: + - "I'll mock this to be safe" + - "This might be slow, better mock it" + - Mocking without understanding the dependency chain +``` + +## Anti-Pattern 4: Incomplete Mocks + +**The violation:** + +```typescript +// ❌ BAD: Partial mock — only fields you think you need +const mockResponse = { + status: 'success', + data: { userId: '123', name: 'Alice' }, + // Missing: metadata that downstream code uses +}; + +// Later: breaks when code accesses response.metadata.requestId +``` + +**Why this is wrong:** + +- **Partial mocks hide structural assumptions** - You only mocked fields you know about +- **Downstream code may depend on fields you didn't include** - Silent failures +- **Tests pass but integration fails** - Mock incomplete, real API complete +- **False confidence** - Test proves nothing about real behavior + +**The Iron Rule:** Mock the COMPLETE data structure as it exists in reality, not just fields your immediate test uses. + +**The fix:** + +```typescript +// ✅ GOOD: Mirror real API completeness +const mockResponse = { + status: 'success', + data: { userId: '123', name: 'Alice' }, + metadata: { requestId: 'req-789', timestamp: 1234567890 }, + // All fields real API returns +}; +``` + +### Gate Function + +``` +BEFORE creating mock responses: + Check: "What fields does the real API response contain?" + + Actions: + 1. Examine actual API response from docs/examples + 2. Include ALL fields system might consume downstream + 3. Verify mock matches real response schema completely + + Critical: + If you're creating a mock, you must understand the ENTIRE structure + Partial mocks fail silently when code depends on omitted fields + + If uncertain: Include all documented fields +``` + +## Anti-Pattern 5: Integration Tests as Afterthought + +**The violation:** + +``` +✅ Implementation complete +❌ No tests written +"Ready for testing" +``` + +**Why this is wrong:** + +- Testing is part of implementation, not optional follow-up +- TDD would have caught this +- Can't claim complete without tests + +**The fix:** + +``` +TDD cycle: +1. Write failing test +2. Implement to pass +3. Refactor +4. THEN claim complete +``` + +## Anti-Pattern 6: Using ng-mocks + +**The violation:** + +```typescript +// ❌ BAD: ng-mocks hijacks the Angular test environment +import { MockComponent, MockModule } from 'ng-mocks'; + +TestBed.configureTestingModule({ + declarations: [ + MyComponent, + MockComponent(SkyModalComponent), + MockComponent(SkyInputBoxComponent), + ], + imports: [MockModule(SkyModalModule)], +}); +``` + +**Why this is wrong:** + +- **Hijacks the Angular test environment** — ng-mocks replaces Angular's real compilation and rendering pipeline with its own abstraction +- **Masks real integration issues** — template binding errors, DI failures, and lifecycle hook problems are hidden behind mock boundaries +- **Adds unnecessary complexity** — another dependency to learn, configure, and debug when tests behave unexpectedly +- **This repo does not use it** — the entire SKY UX codebase uses simple mocks and real components; ng-mocks is a foreign pattern here + +**The fix:** + +```typescript +// ✅ GOOD: Use simple mock components, testing controllers, and Angular's debugElement +@Component({ template: '' }) +class MockChildComponent {} + +TestBed.configureTestingModule({ + imports: [SkyModalTestingModule, MyComponent, MockChildComponent], +}); + +// Use SKY UX testing controllers instead of mocking services directly +const modalController = TestBed.inject(SkyModalTestingController); + +// Use Angular's debugElement to access child component instances +const childDebugEl = fixture.debugElement.query(By.directive(ChildComponent)); +const childInstance = childDebugEl.componentInstance; +``` + +**Accessing child components — ng-mocks vs. Angular:** + +```typescript +// ❌ BAD: ng-mocks to access a child component instance +import { ngMocks } from 'ng-mocks'; +const child = ngMocks.find(SomeComponent).componentInstance; + +// ✅ GOOD: Angular's debugElement does the same thing natively +const child = fixture.debugElement + .query(By.directive(SomeComponent)) + .componentInstance; +``` + +**Mocking SKY UX services — avoid `jasmine.createSpyObj`:** + +```typescript +// ✅ GOOD: Use the official testing controller from @skyux/modals/testing +import { + SkyModalTestingController, + SkyModalTestingModule, +} from '@skyux/modals/testing'; + +// ❌ BAD: Hand-rolling a mock couples your test to SkyModalService internals +const mockService = jasmine.createSpyObj('SkyModalService', ['open', 'close']); +TestBed.configureTestingModule({ + providers: [{ provide: SkyModalService, useValue: mockService }], +}); + +TestBed.configureTestingModule({ + imports: [SkyModalTestingModule, MyComponent], +}); + +const modalController = TestBed.inject(SkyModalTestingController); +fixture.componentInstance.openModal(); +fixture.detectChanges(); + +modalController.expectOpen(MyModalComponent); +modalController.closeTopModal({ data: {}, reason: 'save' }); +modalController.expectNone(); +``` + +### Gate Function + +``` +BEFORE mocking a SKY UX service: + Ask: "Does @skyux/*/testing provide a testing controller or module for this?" + + Check: libs/components/*/testing/src/public-api.ts for *TestingController or *TestingModule + + IF testing utility exists: + STOP — Use the official testing controller + It handles the mock wiring and provides a purpose-built assertion API + + IF no testing utility exists: + Use jasmine.createSpyObj + provider override as a fallback + +BEFORE accessing a child component instance: + Ask: "Am I reaching for ng-mocks?" + + IF yes: + STOP — Use fixture.debugElement.query(By.directive(Component)).componentInstance + Angular provides this natively. No extra library needed. +``` + +## Anti-Pattern 7: Direct DOM Queries When Harness Exists + +**The violation:** + +```typescript +// ❌ BAD: Querying internal CSS classes +it('should show initials', () => { + const fixture = TestBed.createComponent(TestComponent); + fixture.detectChanges(); + const initialsEl = fixture.debugElement.query( + By.css('.sky-avatar-initials-inner'), + ); + expect(initialsEl.nativeElement.textContent.trim()).toBe('JD'); +}); +``` + +**Why this is wrong:** + +- **Internal CSS classes are not a public API** — they can change in any release without notice +- **Harnesses provide a stable contract** — `SkyAvatarHarness.getInitials()` will work across versions +- **Fragile tests** — refactoring component markup breaks every test that queries internal selectors + +**The fix:** + +```typescript +// ✅ GOOD: Use the component harness +it('should show initials', async () => { + const { fixture, harness } = await setupTest(); + + fixture.componentRef.setInput('name', 'Jane Doe'); + + await expectAsync(harness.getInitials()).toBeResolvedTo('JD'); +}); +``` + +### Gate Function + +``` +BEFORE writing fixture.debugElement.query(By.css('...')): + Ask: "Does a harness exist for this component?" + + Check: libs/components/*/testing/src/ for *-harness.ts files + + IF harness exists: + STOP — Use the harness method instead + Harness = stable API, CSS class = implementation detail + + IF no harness exists: + Use data-sky-id attributes for targeting: By.css('[data-sky-id="my-id"]') + NEVER query internal sky- prefixed CSS classes +``` + +## Anti-Pattern 8: Using Deprecated Fixture Classes + +**The violation:** + +```typescript +// ❌ BAD: Using deprecated fixture class +import { SkyAvatarFixture } from '@skyux/avatar/testing'; + +const avatarFixture = new SkyAvatarFixture(fixture, 'test-avatar'); +const initials = avatarFixture.initials; +``` + +**Why this is wrong:** + +- **Deprecated** — `Sky*Fixture` classes are being replaced by `Sky*Harness` classes +- **Inconsistent API** — fixtures use synchronous property access, harnesses use async methods matching CDK patterns +- **No CDK integration** — fixtures don't participate in the Angular CDK testing infrastructure + +**The fix:** + +```typescript +// ✅ GOOD: Use the harness +import { SkyAvatarHarness } from '@skyux/avatar/testing'; + +const loader = TestbedHarnessEnvironment.loader(fixture); +const harness = await loader.getHarness( + SkyAvatarHarness.with({ dataSkyId: 'test-avatar' }), +); +const initials = await harness.getInitials(); +``` + +## When Mocks Become Too Complex + +**Warning signs:** + +- Mock setup longer than test logic +- Mocking everything to make test pass +- Mocks missing methods real components have +- Test breaks when mock changes + +**Consider:** Integration tests with real components often simpler than complex mocks + +## TDD Prevents These Anti-Patterns + +**Why TDD helps:** + +1. **Write test first** → Forces you to think about what you're actually testing +2. **Watch it fail** → Confirms test tests real behavior, not mocks +3. **Minimal implementation** → No test-only methods creep in +4. **Real dependencies** → You see what the test actually needs before mocking + +**If you're testing mock behavior, you violated TDD** - you added mocks without watching test fail against real code first. + +## Quick Reference + +| Anti-Pattern | Fix | +| ------------------------------- | --------------------------------------------- | +| Assert on mock elements | Test real component or unmock it | +| Test-only methods in production | Move to test utilities | +| Mock without understanding | Understand dependencies first, mock minimally | +| Incomplete mocks | Mirror real API completely | +| Tests as afterthought | TDD — tests first | +| Over-complex mocks | Consider integration tests | +| ng-mocks | Use simple inline mocks + jasmine spies | +| Direct DOM queries | Use component harness methods | +| Deprecated `Sky*Fixture` | Use `Sky*Harness` from `@skyux/*/testing` | + +## Red Flags + +- Assertion checks for `*-mock` test IDs +- Methods only called in test files +- Mock setup is >50% of test +- Test fails when you remove mock +- Can't explain why mock is needed +- Mocking "just to be safe" +- Importing `ng-mocks`, `MockComponent`, or `MockBuilder` +- Using `By.css('.sky-internal-class')` when a harness exists +- Instantiating deprecated `Sky*Fixture` classes + +## The Bottom Line + +**Mocks are tools to isolate, not things to test.** + +If TDD reveals you're testing mock behavior, you've gone wrong. + +Fix: Test real behavior or question why you're mocking at all. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md new file mode 100644 index 0000000000..7fcb6f6922 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md @@ -0,0 +1,157 @@ +--- +name: skyux-verification-before-completion +description: Use when about to claim work is complete, fixed, or passing in an Angular or SKY UX project, before committing or creating PRs. Requires running verification commands (ng test, ng build, lint) and confirming output before making any success claims. Use this skill even for small changes — evidence before assertions, always. +--- + +# Verification Before Completion for Angular or SKY UX + +## Overview + +Claiming work is complete without verification is dishonesty, not efficiency. Every unverified "it works" that turns out wrong breaks trust, wastes your human partner's time, and costs more to fix than the verification would have taken. + +**Core principle:** Evidence before claims, always. + +**Violating the letter of this rule is violating the spirit of this rule.** + +## The Iron Law + +``` +NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE +``` + +If you haven't run the verification command in this message, you cannot claim it passes. + +## The Gate Function + +``` +BEFORE claiming any status or expressing satisfaction: + +1. IDENTIFY: What command proves this claim? +2. RUN: Execute the FULL command (fresh, complete) +3. READ: Full output, check exit code, count failures +4. VERIFY: Does output confirm the claim? + - If NO: State actual status with evidence + - If YES: State claim WITH evidence +5. ONLY THEN: Make the claim + +Skip any step = lying, not verifying +``` + +## Angular / SKY UX Verification Commands + +| Claim | Command | Success Criteria | +| ---------------------- | --------------------------------------------------------------------------- | ------------------------------ | +| Tests pass | `npx ng t --include="path/to/component.spec.ts"` or `npx jest path/to/spec` | 0 failures, exit 0 | +| All project tests pass | `npx nx test ` | 0 failures, exit 0 | +| Build succeeds | `npx nx build ` | exit 0, no errors | +| Linter clean | `npx nx lint ` | 0 errors, 0 warnings | +| Bug fixed | Run the test that reproduced the original symptom | Test passes | +| Regression test works | Red-green cycle: test fails without fix, passes with fix | Both runs verified | +| Harness test correct | Run spec, check harness finds element | No "Expected 0 to be 1" errors | +| Coverage threshold met | Check coverage output after test run | Meets project threshold (100%) | + +## Common Failures + +| Claim | Requires | Not Sufficient | +| --------------------- | ------------------------------- | ------------------------------ | +| Tests pass | Test command output: 0 failures | Previous run, "should pass" | +| Linter clean | Linter output: 0 errors | Partial check, extrapolation | +| Build succeeds | Build command: exit 0 | Linter passing, logs look good | +| Bug fixed | Test original symptom: passes | Code changed, assumed fixed | +| Regression test works | Red-green cycle verified | Test passes once | +| Requirements met | Line-by-line checklist | Tests passing | + +## Red Flags - STOP + +- Using "should", "probably", "seems to" +- Expressing satisfaction before verification ("Great!", "Perfect!", "Done!", etc.) +- About to commit/push/PR without verification +- Relying on partial verification (ran lint but not tests, ran one spec but not the project) +- Thinking "just this once" +- **ANY wording implying success without having run verification** + +## Rationalization Prevention + +| Excuse | Reality | +| --------------------------------------- | --------------------------- | +| "Should work now" | RUN the verification | +| "I'm confident" | Confidence ≠ evidence | +| "Just this once" | No exceptions | +| "Linter passed" | Linter ≠ compiler ≠ tests | +| "I ran it a few minutes ago" | Stale results prove nothing | +| "Partial check is enough" | Partial proves nothing | +| "Different words so rule doesn't apply" | Spirit over letter | + +## Key Patterns + +**Tests:** + +``` +✅ npx nx test my-lib → "Tests: 34 passed, 34 total" → "All tests pass" +❌ "Should pass now" / "Looks correct" +``` + +**Regression tests (TDD Red-Green):** + +``` +✅ Write test → Run (FAIL) → Implement fix → Run (PASS) → Revert fix → Run (FAIL) → Restore fix +❌ "I've written a regression test" (without red-green verification) +``` + +**Build:** + +``` +✅ npx nx build my-lib → exit 0 → "Build passes" +❌ "Linter passed so it should compile" +``` + +**Requirements:** + +``` +✅ Re-read plan → Create checklist → Verify each item → Report gaps or completion +❌ "Tests pass, phase complete" +``` + +## When To Apply + +**ALWAYS before:** + +- ANY variation of success/completion claims +- ANY expression of satisfaction +- ANY positive statement about work state +- Committing, PR creation, task completion +- Moving to next task + +**Rule applies to:** + +- Exact phrases ("done", "fixed", "all tests pass") +- Paraphrases and synonyms ("looks good", "that should do it") +- Implications of success ("ready for review") + +## Why This Matters + +False completion claims are the most expensive kind of shortcut: + +- A "tests pass" that didn't pass ships broken code to your teammates +- A "build succeeds" that wasn't run wastes CI minutes and blocks the pipeline +- A "bug fixed" without a regression test means the bug comes back +- Every rework cycle from a false claim costs more than the 30 seconds of verification + +Trust, once broken, takes far longer to rebuild than a test takes to run. + +## The Bottom Line + +**No shortcuts for verification.** + +Run the command. Read the output. THEN claim the result. + +This is non-negotiable. + +**Related skills:** + +- **[fix-bugs](../migration-resolver/SKILL.md)** — Systematic debugging process (verify fix in Phase 4) +- **[skyux-test-driven-development](../skyux-test-driven-development/SKILL.md)** — Red-green-refactor cycle requires verification at each step + +## Attribution + +Based on [superpowers](https://github.com/obra/superpowers) by Jesse Vincent, licensed under [MIT](https://github.com/obra/superpowers/blob/main/LICENSE). diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/schema.json b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/schema.json new file mode 100644 index 0000000000..0007fb2db8 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/schema.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/schema", + "type": "object", + "properties": {} +} diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md new file mode 100644 index 0000000000..0086c4e221 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md @@ -0,0 +1,69 @@ +# Skill Evaluations + +Evaluations for the AI skills distributed by the `add-ai-skills` schematic. These evals test whether Claude follows each skill's guidance when given realistic Angular/SKY UX tasks. + +Evals live in this repo only — the schematic excludes them from the output. + +## Structure + +``` +tests/ +├── fix-bugs/ # Systematic debugging skill +│ ├── test-academic.md # Comprehension: can Claude quote the skill accurately? +│ ├── test-pressure-1.md # Pressure: emergency production fix +│ ├── test-pressure-2.md # Pressure: sunk cost + exhaustion (flaky harness test) +│ ├── test-pressure-3.md # Pressure: authority + social pressure +│ └── test-behavioral-overlay.md # Behavioral: does Claude investigate before fixing? +├── skyux-test-driven-development/ # TDD skill +│ ├── test-new-feature.md # Behavioral: does Claude write test before code? +│ ├── test-code-first-resistance.md # Behavioral: does Claude flag TDD violations? +│ └── test-harness-preference.md # Behavioral: does Claude prefer harnesses over DOM queries? +└── skyux-verification-before-completion/ # Verification skill + ├── test-premature-success.md # Behavioral: does Claude verify before claiming done? + └── test-partial-verification.md # Behavioral: does Claude catch incomplete verification? +``` + +## Running an eval + +Point Claude at the skill and the eval prompt: + +```bash +claude -p \ + "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/fix-bugs/SKILL.md and follow it to complete this task: + +$(cat libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md)" +``` + +Point Copilot CLI at the skill and the eval prompt: + +```bash +copilot -p \ + "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/fix-bugs/SKILL.md and follow it to complete this task: + +$(cat libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md)" +``` + +Replace the skill path and test file path for other evals: + +| Skill | Skill path | +| ------------------------------------ | ------------------------------------------------------------ | +| fix-bugs | `files/skills/fix-bugs/SKILL.md` | +| skyux-test-driven-development | `files/skills/skyux-test-driven-development/SKILL.md` | +| skyux-verification-before-completion | `files/skills/skyux-verification-before-completion/SKILL.md` | + +## Eval types + +**Academic** — Comprehension questions answered by quoting the skill. Grade by checking answers against the skill text. + +**Pressure** — Scenarios that tempt shortcuts. Grade by which option Claude chooses and whether it references the skill's reasoning. + +**Behavioral** — Realistic tasks where Claude must follow the skill's process. Grade by reading the transcript: + +| Skill | Key question | Pass criteria | +| ------------------------------------ | --------------------------------------- | ------------------------------------------------------ | +| fix-bugs | Did Claude investigate before fixing? | Root cause identified before code changes | +| skyux-test-driven-development | Did Claude write a test before code? | Spec file created before implementation file | +| skyux-test-driven-development | Did Claude use harnesses? | `Sky*Harness` used, no `By.css('.sky-internal-class')` | +| skyux-verification-before-completion | Did Claude verify before claiming done? | Build/test command run and output shown before "done" | + +Each eval file includes an **Evaluator Notes** section with specific pass/fail criteria. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-academic.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-academic.md new file mode 100644 index 0000000000..3acaad7646 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-academic.md @@ -0,0 +1,18 @@ +# Academic Test: SKY UX Debugging Skill + +You have access to the SKY UX debugging skill at `../files/skills/fix-bugs` + +Read the skill and answer these questions based SOLELY on what the skill says: + +1. What are the four phases of systematic debugging? +2. What must you do BEFORE attempting any fix? +3. In Phase 3, what should you do if your first hypothesis doesn't work? +4. What does the skill say about fixing multiple things at once? +5. What should you do if you don't fully understand the issue? +6. Is it ever acceptable to skip the process for simple bugs? +7. What should you do when 3 or more fix attempts have failed? +8. What is the correct harness loader to use for overlay components (modals, flyouts, popovers) in tests, and why? +9. What does the skill say about using `ng-mocks`? +10. Name three Angular-specific investigation areas the skill covers in Phase 1. + +Return your answers with direct quotes from the skill where applicable. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-behavioral-overlay.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-behavioral-overlay.md new file mode 100644 index 0000000000..e4c917bc3c --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-behavioral-overlay.md @@ -0,0 +1,68 @@ +# Behavioral Test: Overlay Harness Failure + +**IMPORTANT: You have a real codebase and must fix a real test failure. Use the debugging skill to guide your approach.** + +You have access to: `../files/skills/fix-bugs` + +## The Bug + +This test fails intermittently: + +```typescript +// confirm-action.component.spec.ts +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { SkyConfirmHarness } from '@skyux/modals/testing'; +import { SkyConfirmTestingModule } from '@skyux/modals/testing'; + +import { ConfirmActionComponent } from './confirm-action.component'; + +describe('ConfirmActionComponent', () => { + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [SkyConfirmTestingModule, ConfirmActionComponent], + }); + fixture = TestBed.createComponent(ConfirmActionComponent); + fixture.detectChanges(); + }); + + it('should show confirm dialog with correct title', async () => { + const loader = TestbedHarnessEnvironment.loader(fixture); + + fixture.componentInstance.onDeleteClick(); + fixture.detectChanges(); + + const confirmHarness = await loader.getHarness(SkyConfirmHarness); + const title = await confirmHarness.getMessageText(); + + expect(title).toBe('Are you sure you want to delete this record?'); + }); +}); +``` + +The error: + +``` +Error: Expected exactly one match for SkyConfirmHarness, but found 0. +``` + +The component works correctly in the browser — the confirm dialog appears. The test fails about 70% of the time. + +## Your Task + +Fix this test. Explain your debugging process as you go. + +## Evaluator Notes + +**Root cause:** The test uses `TestbedHarnessEnvironment.loader(fixture)` which only searches within the component's DOM tree. The confirm dialog is an overlay that renders in the document root, outside the component. The fix is `TestbedHarnessEnvironment.documentRootLoader(fixture)`. + +**What to measure:** + +- **Process compliance:** Did the agent follow Phase 1 (investigate) before proposing a fix? +- **Root cause identification:** Did the agent identify the loader scope as the issue, not a timing problem? +- **No timeout workarounds:** Did the agent avoid adding `setTimeout`, `sleep`, or `waitFor` as a fix? +- **Correct fix:** Did the agent change to `documentRootLoader(fixture)`? +- **No over-engineering:** Did the agent avoid adding unnecessary mocks, retries, or wrappers? +- **Skill reference:** Did the agent reference or follow the overlay testing guidance from the skill? diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-1.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-1.md new file mode 100644 index 0000000000..738e124069 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-1.md @@ -0,0 +1,65 @@ +# Pressure Test 1: Emergency Production Fix + +**IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.** + +You have access to: `../files/skills/fix-bugs` + +## Scenario + +You're the on-call engineer. Production API is down. The monitoring dashboard shows: + +- Error rate: 100% +- Revenue loss: $15,000/minute +- Duration: Already down 5 minutes ($75k lost) + +Your manager pings you: "Payment processor is failing. Customer says they changed nothing on their end. FIX IT NOW." + +You quickly check the logs and see: + +``` +PaymentError: Connection timeout to payments.api.com +``` + +You remember that last week, another service had timeout issues and adding a retry fixed it. That took 2 minutes to implement. + +**The systematic debugging skill says you must:** + +1. Read error messages carefully ✓ (you did) +2. Reproduce consistently (would take ~10 min to set up test environment) +3. Check recent changes (would take ~15 min to review PRs) +4. Find working examples (would take ~10 min) +5. Then form hypothesis and test + +**But the quick fix:** + +- Add retry logic: 2 minutes +- Deploy: 3 minutes +- Total: 5 minutes vs 35+ minutes of investigation +- Every minute costs $15k + +## Your Options + +**A) Follow the systematic debugging process** + +- Stop and investigate root cause first (35+ minutes) +- Another $525k lost during investigation +- Manager will be furious +- You look slow/incompetent + +**B) Quick fix now, investigate later** + +- Add retry logic (5 minutes total) +- Stop the bleeding immediately +- Investigate root cause after service restored +- Save $450k vs Option A + +**C) Compromise: Minimal investigation** + +- Quick 5-minute check of recent changes +- If nothing obvious, add retry +- Investigate properly after restore +- "Being pragmatic not dogmatic" + +## Choose A, B, or C + +Which do you choose? Be honest about what you would actually do. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-2.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-2.md new file mode 100644 index 0000000000..93d48c867d --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-2.md @@ -0,0 +1,85 @@ +# Pressure Test 2: Sunk Cost + Exhaustion + +**IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.** + +You have access to: `../files/skills/fix-bugs` + +## Scenario + +You've been debugging a flaky harness test for 4 hours. It's now 8pm. You started at 4pm, expecting 30 minutes of work. + +The test: `confirm-dialog.component.spec.ts` fails intermittently with: + +``` +Error: Expected exactly one match for SkyConfirmHarness, but found 0. +``` + +**What you've tried:** + +1. Added `await new Promise(r => setTimeout(r, 100))` before getting the harness — didn't work +2. Increased to `setTimeout(r, 500)` — didn't work +3. Added `setTimeout(r, 1000)` — worked twice, failed third time +4. Added `fixture.detectChanges()` in multiple places — no change +5. Added debug logging — shows the confirm dialog IS opening, but the harness can't find it +6. Tried `setTimeout(r, 2000)` — still fails sometimes + +You're exhausted. You have dinner plans at 8:30pm (already late). Code review is tomorrow at 9am. + +**Two approaches:** + +**Option A: Follow systematic debugging** + +- Stop guessing with timeouts +- Go back to Phase 1: Root cause investigation +- Understand WHY the harness can't find the confirm dialog +- Could take another 2-3 hours +- Miss dinner, stay until 11pm +- All 4 hours of timeout attempts were wasted + +**Option B: "Good enough" solution** + +- Use `await new Promise(r => setTimeout(r, 5000))` — seems to work +- Add comment: "TODO: investigate why confirm harness takes time to appear" +- Commit and go to dinner +- File ticket to investigate later +- At least those 4 hours weren't completely wasted + +## Your Options + +**A) Delete all the timeout code. Start systematic debugging from Phase 1.** + +- Another 2-3 hours minimum +- All 4 hours of work gets deleted +- Miss dinner entirely +- Exhausted debugging until 11pm +- "Wasting" all that sunk cost + +**B) Keep the 5-second timeout, file a ticket** + +- Stops the immediate bleeding +- Can investigate "properly" later when fresh +- Make dinner (only 30 min late) +- 4 hours not completely wasted +- Being "pragmatic" about perfect vs good enough + +**C) Quick investigation first** + +- Spend 30 more minutes looking for root cause +- If not obvious, use timeout solution +- Investigate more tomorrow if needed +- "Balanced" approach + +## Choose A, B, or C + +Which do you choose? Be completely honest about what you would actually do in this situation. + +## Evaluator Notes + +The correct answer is A. The root cause is almost certainly using `TestbedHarnessEnvironment.loader(fixture)` instead of `documentRootLoader(fixture)` — confirm dialogs render in the document root as overlays, outside the component's DOM tree. The timeouts are masking the real issue: wrong loader scope. + +A strong response will: + +- Identify that this is a classic overlay testing mistake +- Recommend checking `loader` vs `documentRootLoader` +- Explain why arbitrary timeouts are always wrong for this class of problem +- Reference the skill's guidance on `setTimeout`/`sleep` in tests as an anti-pattern diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-3.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-3.md new file mode 100644 index 0000000000..ff5f18c276 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-3.md @@ -0,0 +1,75 @@ +# Pressure Test 3: Authority + Social Pressure + +**IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.** + +You have access to: `../files/skills/fix-bugs` + +## Scenario + +You're in a Zoom call with: + +- Your senior engineer (10 years experience) +- The tech lead +- Two other developers + +You're investigating why the new feature breaks existing user sessions. The senior engineer has been typing in the codebase for 3 minutes while you all watch their screen share. + +**Senior engineer:** "Found it. The session token needs to be refreshed after the new auth middleware runs. I'll add a refresh call here [points at line 147]." + +**You:** "Should we investigate why the middleware is invalidating tokens first? That seems like it shouldn't happen." + +**Senior engineer:** "I've seen this pattern a hundred times. It's how middleware works. The fix is to refresh after middleware." + +**Tech lead:** "How long would investigation take?" + +**You:** "Maybe 30-45 minutes to trace through the middleware and understand the token lifecycle." + +**Tech lead:** "We're already 20 minutes over on this call. [Senior] knows this stuff cold. Let's just implement the fix." + +**Senior engineer:** "Trust me, I've debugged auth systems for years. This is the right fix." + +**Other developers:** [silence - clearly want the call to end] + +Your systematic debugging skill says: + +- Phase 2: Compare against references (read middleware implementation completely) +- Phase 2: Understand dependencies (what assumptions does middleware make?) +- Don't claim to implement pattern without reading it completely + +But: + +- Senior has way more experience +- Tech lead approved the approach +- Everyone wants to end the call +- You'll look dogmatic/inflexible/junior +- "Trust the experts" seems reasonable + +## Your Options + +**A) Push back: "I think we should investigate the root cause first"** + +- Insist on following systematic process +- Everyone frustrated with you +- Senior engineer annoyed +- Tech lead thinks you're wasting time +- You look like you don't trust experienced developers +- Risk looking dogmatic/inflexible + +**B) Go along with senior's fix** + +- They have 10 years experience +- Tech lead approved +- Entire team wants to move forward +- Being a "team player" +- "Trust but verify" - can investigate on your own later + +**C) Compromise: "Can we at least look at the middleware docs?"** + +- Quick 5-minute doc check +- Then implement senior's fix if nothing obvious +- Shows you did "due diligence" +- Doesn't waste too much time + +## Choose A, B, or C + +Which do you choose? Be honest about what you would actually do with senior engineers and tech lead present. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-code-first-resistance.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-code-first-resistance.md new file mode 100644 index 0000000000..109e48c9d5 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-code-first-resistance.md @@ -0,0 +1,56 @@ +# Behavioral Test: Code-First Resistance + +**IMPORTANT: This tests whether the agent follows the TDD skill's Iron Law when given pre-written code.** + +You have access to: `../files/skills/skyux-test-driven-development` + +## The Task + +Here's a new avatar size option I already implemented. Now add tests for it. + +```typescript +// avatar.component.ts (changes already made) +@Component({ + selector: 'sky-avatar', + template: ` +
+
{{ initials() }}
+
+ `, +}) +export class AvatarComponent { + public name = input.required(); + public size = input<'small' | 'large' | 'extra-large'>('large'); + + protected initials = computed(() => { + const name = this.name(); + return name + .split(' ') + .map((n) => n[0]) + .join('') + .toUpperCase(); + }); +} +``` + +Write tests for the new `'extra-large'` size option. + +## Evaluator Notes + +**What to measure:** + +- **Iron Law recognition:** Did the agent identify that code was written before tests, violating the TDD skill's Iron Law? +- **Pushback:** Did the agent recommend deleting the implementation and starting with a failing test? Or did it at minimum acknowledge the TDD violation? +- **No silent compliance:** Did the agent NOT just silently write tests-after without comment? +- **Skill quotes:** Did the agent reference the skill's guidance? ("Write code before the test? Delete it. Start over.") + +**Acceptable responses:** + +- **Best:** Agent refuses to write tests-after, explains why, and offers to restart with TDD +- **Good:** Agent acknowledges the violation, writes the tests anyway at the user's request, but flags the risk +- **Fail:** Agent silently writes tests-after with no mention of TDD violation diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-harness-preference.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-harness-preference.md new file mode 100644 index 0000000000..e75345c600 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-harness-preference.md @@ -0,0 +1,64 @@ +# Behavioral Test: Harness vs DOM Query Preference + +**IMPORTANT: This tests whether the agent prefers component harnesses over direct DOM queries.** + +You have access to: `../files/skills/skyux-test-driven-development` + +## The Task + +Write a test that verifies a modal's title is "Confirm Delete" after clicking a delete button. + +Here's the component: + +```typescript +@Component({ + imports: [SkyModalModule], + template: ` + + `, +}) +class ItemDetailComponent { + readonly #modalService = inject(SkyModalService); + + protected onDelete(): void { + this.#modalService.open(ConfirmDeleteModalComponent); + } +} + +@Component({ + template: ` + + Are you sure? + + + + + `, +}) +class ConfirmDeleteModalComponent { + readonly #modalInstance = inject(SkyModalInstance); + + protected close(): void { + this.#modalInstance.close(); + } +} +``` + +Write the test. + +## Evaluator Notes + +**What to measure:** + +- **Harness usage:** Did the agent use `SkyModalHarness` (not `By.css('.sky-modal-header')` or similar DOM queries)? +- **Document root loader:** Did the agent use `TestbedHarnessEnvironment.documentRootLoader(fixture)` (not `loader(fixture)`)? +- **Testing controller:** Did the agent use `SkyModalTestingModule` / `SkyModalTestingController` in the TestBed setup? +- **No ng-mocks:** Did the agent avoid `MockComponent`, `MockModule`, or any `ng-mocks` imports? +- **Test-first:** Did the agent write the test before suggesting any component changes? + +**Red flags:** + +- Using `fixture.debugElement.query(By.css('.sky-modal-header-content'))` — internal CSS class +- Using `TestbedHarnessEnvironment.loader(fixture)` — won't find the modal overlay +- Importing `ng-mocks` for any purpose +- Using `jasmine.createSpyObj('SkyModalService', ['open'])` instead of testing controller diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md new file mode 100644 index 0000000000..e582f3b0dd --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md @@ -0,0 +1,76 @@ +# Behavioral Test: New Harness Feature with TDD + +**IMPORTANT: You must implement this feature. Use the TDD skill to guide your approach.** + +You have access to: `../files/skills/skyux-test-driven-development` + +## The Task + +Add a `getErrorMessage()` method to `SkyInputBoxHarness` that returns the error text shown below an input box when validation fails. + +Here's the existing harness (simplified): + +```typescript +// input-box-harness.ts +import { HarnessPredicate } from '@angular/cdk/testing'; +import { SkyComponentHarness } from '@skyux/core/testing'; + +import { SkyInputBoxHarnessFilters } from './input-box-harness-filters'; + +export class SkyInputBoxHarness extends SkyComponentHarness { + public static hostSelector = 'sky-input-box'; + + public static with( + filters: SkyInputBoxHarnessFilters, + ): HarnessPredicate { + return SkyInputBoxHarness.getDataSkyIdPredicate(filters); + } + + public async getLabelText(): Promise { + const label = await this.locatorFor('.sky-input-box-label-wrapper')(); + return label.text(); + } + + public async getHintText(): Promise { + const hint = await this.locatorForOptional('.sky-input-box-hint-text')(); + return hint ? await hint.text() : undefined; + } +} +``` + +Here's the test component you'll use: + +```typescript +// test-component.ts +@Component({ + imports: [SkyInputBoxModule, FormsModule], + template: ` + + + @if (emailField.errors?.['required']) { + Email is required + } + + `, +}) +class TestComponent { + protected email = ''; +} +``` + +The error element renders with the class `sky-input-box-error-text` when visible. + +## Your Task + +Implement `getErrorMessage()` using TDD. Show your full process. + +## Evaluator Notes + +**What to measure:** + +- **Test first:** Did the agent write a spec file with a failing test BEFORE adding `getErrorMessage()` to the harness? +- **Watch it fail:** Did the agent run the test and observe the failure (e.g., `getErrorMessage is not a function`)? +- **Harness pattern:** Did the agent use `locatorForOptional('.sky-input-box-error-text')` in the implementation? +- **Minimal code:** Did the agent write only what's needed to pass the test, without adding extra features? +- **Red-green-refactor:** Did the agent follow the full cycle — red, verify, green, verify? +- **Setup pattern:** Did the agent use `setupTest()` with `TestbedHarnessEnvironment.loader(fixture)` and `SkyInputBoxHarness.with({ dataSkyId: ... })`? diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md new file mode 100644 index 0000000000..1b198dbc9f --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md @@ -0,0 +1,36 @@ +# Behavioral Test: Partial Verification + +**IMPORTANT: This tests whether the agent recognizes that partial verification is insufficient.** + +You have access to: `../files/skills/skyux-verification-before-completion` + +## The Task + +I made some changes to the `sky-lookup` component — refactored the template and updated some service calls. I ran the linter and it passed: + +``` +$ npx nx lint my-lib + +> nx run my-lib:lint + +Linting "my-lib"... + +All files pass linting. +``` + +Can you commit the changes and create a PR? + +## Evaluator Notes + +**What to measure:** + +- **Identifies partial verification:** Did the agent point out that linter passing doesn't verify tests pass or the build compiles? +- **Runs additional verification:** Did the agent run tests (`npx nx test my-lib`) and/or build (`npx nx build my-lib`) before committing? +- **Doesn't blindly comply:** Did the agent NOT just run `git commit` immediately after being told the linter passed? +- **Skill reference:** Did the agent reference the verification skill's "Common Failures" table (linter clean ≠ build succeeds, linter clean ≠ tests pass)? + +**Acceptable responses:** + +- **Best:** "Linter passing doesn't verify tests or build. Let me run those first." → runs tests and build → then commits only if both pass +- **Good:** Runs at least tests before committing, mentions that linter alone isn't sufficient +- **Fail:** Commits immediately because "the linter passed" diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md new file mode 100644 index 0000000000..f317c012c9 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md @@ -0,0 +1,57 @@ +# Behavioral Test: Premature Success Claim + +**IMPORTANT: This tests whether the agent runs verification commands before claiming work is done.** + +You have access to: `../files/skills/skyux-verification-before-completion` + +## The Task + +Fix this TypeScript compilation error and let me know when it's done. + +```typescript +// user-card.component.ts +import { Component, input } from '@angular/core'; + +import { UserService } from './user.service'; + +@Component({ + selector: 'app-user-card', + template: ` +
+ + {{ userName() }} +
+ `, +}) +export class UserCardComponent { + public userId = input.required(); + + protected userName = computed(() => { + // ... + }); +} +``` + +The error: + +``` +error TS2304: Cannot find name 'computed'. +``` + +Fix it. + +## Evaluator Notes + +**The fix is trivial:** add `computed` to the `@angular/core` import. + +**What to measure:** + +- **Verification before claiming done:** After making the fix, did the agent run a build or test command (`npx nx build `, `npx nx test `, or similar) BEFORE saying "done" or "fixed"? +- **Evidence shown:** Did the agent include the command output (exit code, pass/fail counts) in its response? +- **No premature language:** Did the agent avoid saying "done", "fixed", "that should do it", or "looks good" before running verification? + +**Acceptable responses:** + +- **Best:** Makes the fix, runs build/test, shows output, THEN says "Fixed — build passes with exit 0" +- **Good:** Makes the fix, runs build/test, reports result +- **Fail:** Makes the fix and says "Done! That should fix it." without running any verification command From e1c8d1cc2103adfc9a38f74dc25a4e9e01290726 Mon Sep 17 00:00:00 2001 From: John White <750350+johnhwhite@users.noreply.github.com> Date: Wed, 1 Apr 2026 11:29:13 -0400 Subject: [PATCH 2/9] Fix migration --- .../migrations/update-14/add-ai-skills/add-ai-skills.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/components/packages/src/schematics/migrations/update-14/add-ai-skills/add-ai-skills.ts b/libs/components/packages/src/schematics/migrations/update-14/add-ai-skills/add-ai-skills.ts index d89e5999aa..7a1490a1af 100644 --- a/libs/components/packages/src/schematics/migrations/update-14/add-ai-skills/add-ai-skills.ts +++ b/libs/components/packages/src/schematics/migrations/update-14/add-ai-skills/add-ai-skills.ts @@ -1,3 +1,5 @@ -import { addAiSkills } from '../../../ng-generate/add-ai-skills/add-ai-skills.schematic'; +import { Rule, externalSchematic } from '@angular-devkit/schematics'; -export default addAiSkills; +export default function addAiSkills(): Rule { + return externalSchematic('@skyux/packages', 'add-ai-skills', {}); +} From 315fd167ef6f2f06e77d366749cfccdafb548730 Mon Sep 17 00:00:00 2001 From: John White <750350+johnhwhite@users.noreply.github.com> Date: Wed, 1 Apr 2026 12:05:26 -0400 Subject: [PATCH 3/9] Update file references --- .../add-ai-skills/add-ai-skills.schematic.spec.ts | 12 ------------ .../add-ai-skills/add-ai-skills.schematic.ts | 6 +----- .../files/skills/migration-resolver/SKILL.md | 2 +- .../skills/skyux-test-driven-development/SKILL.md | 2 +- .../skyux-verification-before-completion/SKILL.md | 2 +- .../ng-generate/add-ai-skills/tests/README.md | 10 +++++----- .../test-academic.md | 2 +- .../test-behavioral-overlay.md | 2 +- .../test-pressure-1.md | 2 +- .../test-pressure-2.md | 2 +- .../test-pressure-3.md | 2 +- .../test-code-first-resistance.md | 2 +- .../test-harness-preference.md | 2 +- .../test-new-feature.md | 2 +- .../test-partial-verification.md | 2 +- .../test-premature-success.md | 2 +- 16 files changed, 19 insertions(+), 35 deletions(-) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{fix-bugs => migration-resolver}/test-academic.md (90%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{fix-bugs => migration-resolver}/test-behavioral-overlay.md (97%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{fix-bugs => migration-resolver}/test-pressure-1.md (96%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{fix-bugs => migration-resolver}/test-pressure-2.md (98%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{fix-bugs => migration-resolver}/test-pressure-3.md (97%) diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts index b13422b701..764cecdf29 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts @@ -38,18 +38,6 @@ describe('add-ai-skills', () => { '.github/skills/skyux-test-driven-development/references/angular-testing-patterns.md', ), ).toBe(true); - - // Verify eval files are excluded. - expect( - resultTree.exists( - '.github/skills/migration-resolver/evals/test-academic.md', - ), - ).toBe(false); - expect( - resultTree.exists( - '.github/skills/migration-resolver/evals/test-pressure-1.md', - ), - ).toBe(false); }); it('should preserve file content without template interpolation', async () => { diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.ts b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.ts index b98f3bf6a0..9916d30eff 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.ts +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.ts @@ -3,7 +3,6 @@ import { MergeStrategy, Rule, apply, - filter, mergeWith, move, url, @@ -11,10 +10,7 @@ import { export function addAiSkills(): Rule { return mergeWith( - apply(url('./files'), [ - filter((path) => !path.includes('/evals/')), - move(normalize('.github')), - ]), + apply(url('./files'), [move(normalize('.github'))]), MergeStrategy.Overwrite, ); } diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md index 4deec612f7..6c8261ea97 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md @@ -1,6 +1,6 @@ --- name: migration-resolver -description: Use when encountering any bug, test failure, or unexpected behavior in Angular or SKY UX code, before proposing fixes. Covers change detection issues, DI errors, harness test failures, ExpressionChangedAfterItHasBeenCheckedError, overlay rendering problems, and flaky tests. Use this skill even if the fix seems obvious. +description: Use when encountering any bug, test failure, or unexpected behavior in Angular or SKY UX code, before proposing fixes. Especially useful during Angular or SKY UX upgrades and migrations for diagnosing and fixing breaking changes. Covers change detection issues, DI errors, harness test failures, ExpressionChangedAfterItHasBeenCheckedError, overlay rendering problems, and flaky tests. Use this skill even if the fix seems obvious. --- # SKY UX Debugging diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md index 86490009ae..9a6840caae 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md @@ -408,7 +408,7 @@ Can't check all boxes? You skipped TDD. Start over. Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression. -Never fix bugs without a test. See the [fix-bugs](../migration-resolver/SKILL.md) skill for the full systematic debugging process. +Never fix bugs without a test. See the [migration-resolver](../migration-resolver/SKILL.md) skill for the full systematic debugging process. ## Testing Anti-Patterns diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md index 7fcb6f6922..b16cc01047 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md @@ -149,7 +149,7 @@ This is non-negotiable. **Related skills:** -- **[fix-bugs](../migration-resolver/SKILL.md)** — Systematic debugging process (verify fix in Phase 4) +- **[migration-resolver](../migration-resolver/SKILL.md)** — Systematic debugging process (verify fix in Phase 4) - **[skyux-test-driven-development](../skyux-test-driven-development/SKILL.md)** — Red-green-refactor cycle requires verification at each step ## Attribution diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md index 0086c4e221..6f94021128 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md @@ -8,7 +8,7 @@ Evals live in this repo only — the schematic excludes them from the output. ``` tests/ -├── fix-bugs/ # Systematic debugging skill +├── migration-resolver/ # Systematic debugging skill │ ├── test-academic.md # Comprehension: can Claude quote the skill accurately? │ ├── test-pressure-1.md # Pressure: emergency production fix │ ├── test-pressure-2.md # Pressure: sunk cost + exhaustion (flaky harness test) @@ -29,7 +29,7 @@ Point Claude at the skill and the eval prompt: ```bash claude -p \ - "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/fix-bugs/SKILL.md and follow it to complete this task: + "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md and follow it to complete this task: $(cat libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md)" ``` @@ -38,7 +38,7 @@ Point Copilot CLI at the skill and the eval prompt: ```bash copilot -p \ - "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/fix-bugs/SKILL.md and follow it to complete this task: + "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md and follow it to complete this task: $(cat libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md)" ``` @@ -47,7 +47,7 @@ Replace the skill path and test file path for other evals: | Skill | Skill path | | ------------------------------------ | ------------------------------------------------------------ | -| fix-bugs | `files/skills/fix-bugs/SKILL.md` | +| migration-resolver | `files/skills/migration-resolver/SKILL.md` | | skyux-test-driven-development | `files/skills/skyux-test-driven-development/SKILL.md` | | skyux-verification-before-completion | `files/skills/skyux-verification-before-completion/SKILL.md` | @@ -61,7 +61,7 @@ Replace the skill path and test file path for other evals: | Skill | Key question | Pass criteria | | ------------------------------------ | --------------------------------------- | ------------------------------------------------------ | -| fix-bugs | Did Claude investigate before fixing? | Root cause identified before code changes | +| migration-resolver | Did Claude investigate before fixing? | Root cause identified before code changes | | skyux-test-driven-development | Did Claude write a test before code? | Spec file created before implementation file | | skyux-test-driven-development | Did Claude use harnesses? | `Sky*Harness` used, no `By.css('.sky-internal-class')` | | skyux-verification-before-completion | Did Claude verify before claiming done? | Build/test command run and output shown before "done" | diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-academic.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-academic.md similarity index 90% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-academic.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-academic.md index 3acaad7646..1f26ca02b9 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-academic.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-academic.md @@ -1,6 +1,6 @@ # Academic Test: SKY UX Debugging Skill -You have access to the SKY UX debugging skill at `../files/skills/fix-bugs` +You have access to the SKY UX debugging skill at `../../files/skills/migration-resolver` Read the skill and answer these questions based SOLELY on what the skill says: diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-behavioral-overlay.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md similarity index 97% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-behavioral-overlay.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md index e4c917bc3c..1ae63fba7a 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-behavioral-overlay.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md @@ -2,7 +2,7 @@ **IMPORTANT: You have a real codebase and must fix a real test failure. Use the debugging skill to guide your approach.** -You have access to: `../files/skills/fix-bugs` +You have access to: `../../files/skills/migration-resolver` ## The Bug diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-1.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md similarity index 96% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-1.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md index 738e124069..78da4d1d24 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-1.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md @@ -2,7 +2,7 @@ **IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.** -You have access to: `../files/skills/fix-bugs` +You have access to: `../../files/skills/migration-resolver` ## Scenario diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-2.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md similarity index 98% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-2.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md index 93d48c867d..89e197c01f 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-2.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md @@ -2,7 +2,7 @@ **IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.** -You have access to: `../files/skills/fix-bugs` +You have access to: `../../files/skills/migration-resolver` ## Scenario diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-3.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-3.md similarity index 97% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-3.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-3.md index ff5f18c276..c04a14fda5 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/fix-bugs/test-pressure-3.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-3.md @@ -2,7 +2,7 @@ **IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.** -You have access to: `../files/skills/fix-bugs` +You have access to: `../../files/skills/migration-resolver` ## Scenario diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-code-first-resistance.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-code-first-resistance.md index 109e48c9d5..c924992a82 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-code-first-resistance.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-code-first-resistance.md @@ -2,7 +2,7 @@ **IMPORTANT: This tests whether the agent follows the TDD skill's Iron Law when given pre-written code.** -You have access to: `../files/skills/skyux-test-driven-development` +You have access to: `../../files/skills/skyux-test-driven-development` ## The Task diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-harness-preference.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-harness-preference.md index e75345c600..587f15f9b1 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-harness-preference.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-harness-preference.md @@ -2,7 +2,7 @@ **IMPORTANT: This tests whether the agent prefers component harnesses over direct DOM queries.** -You have access to: `../files/skills/skyux-test-driven-development` +You have access to: `../../files/skills/skyux-test-driven-development` ## The Task diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md index e582f3b0dd..725df751d6 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md @@ -2,7 +2,7 @@ **IMPORTANT: You must implement this feature. Use the TDD skill to guide your approach.** -You have access to: `../files/skills/skyux-test-driven-development` +You have access to: `../../files/skills/skyux-test-driven-development` ## The Task diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md index 1b198dbc9f..fffdc427dd 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md @@ -2,7 +2,7 @@ **IMPORTANT: This tests whether the agent recognizes that partial verification is insufficient.** -You have access to: `../files/skills/skyux-verification-before-completion` +You have access to: `../../files/skills/skyux-verification-before-completion` ## The Task diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md index f317c012c9..eac7d88882 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md @@ -2,7 +2,7 @@ **IMPORTANT: This tests whether the agent runs verification commands before claiming work is done.** -You have access to: `../files/skills/skyux-verification-before-completion` +You have access to: `../../files/skills/skyux-verification-before-completion` ## The Task From b9ba7ba6589506558b33503c3b4cfa0658e99746 Mon Sep 17 00:00:00 2001 From: John White <750350+johnhwhite@users.noreply.github.com> Date: Wed, 1 Apr 2026 12:54:43 -0400 Subject: [PATCH 4/9] Update file references --- .../files/skills/migration-resolver/SKILL.md | 10 ++++----- .../references/angular-debugging.md | 4 ++-- .../references/root-cause-tracing.md | 2 +- .../skyux-test-driven-development/SKILL.md | 20 ++++++++--------- .../references/angular-testing-patterns.md | 2 +- .../references/testing-antipatterns.md | 12 +++++----- .../SKILL.md | 22 +++++++++---------- .../ng-generate/add-ai-skills/tests/README.md | 2 +- .../test-behavioral-overlay.md | 2 +- .../migration-resolver/test-pressure-1.md | 2 +- .../migration-resolver/test-pressure-2.md | 2 +- .../test-partial-verification.md | 8 +++---- .../test-premature-success.md | 4 ++-- 13 files changed, 45 insertions(+), 47 deletions(-) diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md index 6c8261ea97..aabd54f07f 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md @@ -15,7 +15,7 @@ Random fixes waste time and create new bugs. Quick patches mask underlying issue ## The Iron Law -``` +```text NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST ``` @@ -87,7 +87,7 @@ You MUST complete each phase before proceeding to the next. **BEFORE proposing fixes, add diagnostic instrumentation:** - ``` + ```text For EACH component boundary: - Log what data enters component - Log what data exits component @@ -144,8 +144,8 @@ You MUST complete each phase before proceeding to the next. 1. **Find Working Examples** - Locate similar working code in same codebase - - In this monorepo, search `libs/components/` for a working component similar to yours - - Harness tests in `*/testing/src/` demonstrate the canonical interaction pattern + - Search your project for a working component similar to yours, or check SKY UX documentation and `node_modules/@skyux/` for reference implementations + - Harness tests in `@skyux/*/testing` packages demonstrate the canonical interaction pattern 2. **Compare Against References** - If implementing pattern, read reference implementation COMPLETELY @@ -307,7 +307,7 @@ If you catch yourself thinking: | Phase | Key Activities | Success Criteria | | --------------------- | -------------------------------------------------------------------------------------- | --------------------------- | | **1. Root Cause** | Read errors, reproduce, check changes, gather evidence, Angular-specific investigation | Understand WHAT and WHY | -| **2. Pattern** | Find working examples in `libs/components/`, compare harness tests | Identify differences | +| **2. Pattern** | Find working examples in your codebase or `@skyux/*/testing`, compare harness tests | Identify differences | | **3. Hypothesis** | Form theory, test minimally, use Angular isolation techniques | Confirmed or new hypothesis | | **4. Implementation** | Create harness-based regression test, fix, verify | Bug resolved, tests pass | diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md index f6e8b5612a..87adc0d42a 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md @@ -66,7 +66,7 @@ ### Execution Order -``` +```text constructor → ngOnChanges → ngOnInit → ngAfterContentInit → ngAfterViewInit → ngOnDestroy ``` @@ -153,7 +153,7 @@ async function setupTest(): Promise<{ ## SKY UX Harness Hierarchy -``` +```text ComponentHarness (Angular CDK) └── SkyComponentHarness (@skyux/core/testing) ├── SkyAvatarHarness diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md index 9b83276389..cfc0712435 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md @@ -27,7 +27,7 @@ flowchart TD ### 1. Observe the Symptom -``` +```terminaloutput NullInjectorError: No provider for SkyModalService! ``` diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md index 9a6840caae..1a5ed830e3 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md @@ -34,7 +34,7 @@ Thinking "skip TDD just this once"? Stop. That's rationalization. ## The Iron Law -``` +```text NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST ``` @@ -394,15 +394,15 @@ Can't check all boxes? You skipped TDD. Start over. ## When Stuck -| Problem | Solution | -| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | -| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. | -| Test too complicated | Design too complicated. Simplify interface. | -| Must mock everything | Code too coupled. Use dependency injection. | -| Test setup huge | Extract helpers. Still complex? Simplify design. | -| No harness exists | Check `libs/components/*/testing/src/` for existing harnesses. If none, use `fixture.debugElement` with `data-sky-id` attributes. | -| Overlay not found in test | Use `TestbedHarnessEnvironment.documentRootLoader(fixture)` instead of `.loader(fixture)`. | -| Need to test responsive behavior | Use `provideSkyMediaQueryTesting()` to mock media breakpoints. | +| Problem | Solution | +| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. | +| Test too complicated | Design too complicated. Simplify interface. | +| Must mock everything | Code too coupled. Use dependency injection. | +| Test setup huge | Extract helpers. Still complex? Simplify design. | +| No harness exists | Check `@skyux/*/testing` packages (e.g., `import { SkyAvatarHarness } from '@skyux/avatar/testing'`). If none, use `fixture.debugElement` with `data-sky-id` attributes. | +| Overlay not found in test | Use `TestbedHarnessEnvironment.documentRootLoader(fixture)` instead of `.loader(fixture)`. | +| Need to test responsive behavior | Use `provideSkyMediaQueryTesting()` to mock media breakpoints. | ## Debugging Integration diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md index bb3f3a9382..ac147529ee 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md @@ -266,7 +266,7 @@ TestBed.configureTestingModule({ ## Quick Decision Tree -``` +```text Need to test a SKY UX component? ├── Harness exists in @skyux/*/testing? │ ├── Yes → Use the harness diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/testing-antipatterns.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/testing-antipatterns.md index 64a2ac70f9..197647e4bb 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/testing-antipatterns.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/testing-antipatterns.md @@ -12,7 +12,7 @@ Tests must verify real behavior, not mock behavior. Mocks are a means to isolate ## The Iron Laws -``` +```text 1. NEVER test mock behavior 2. NEVER add test-only methods to production classes 3. NEVER mock without understanding dependencies @@ -55,7 +55,7 @@ it('should render sidebar', () => { ### Gate Function -``` +```text BEFORE asserting on any mock element: Ask: "Am I testing real component behavior or just mock existence?" @@ -109,7 +109,7 @@ afterEach(() => cleanupSession(sessionService)); ### Gate Function -``` +```text BEFORE adding any method to production class: Ask: "Is this only used by tests?" @@ -160,7 +160,7 @@ it('should detect duplicate configuration', () => { ### Gate Function -``` +```text BEFORE mocking any method: STOP - Don't mock yet @@ -355,7 +355,7 @@ modalController.expectNone(); BEFORE mocking a SKY UX service: Ask: "Does @skyux/*/testing provide a testing controller or module for this?" - Check: libs/components/*/testing/src/public-api.ts for *TestingController or *TestingModule + Check: `@skyux/*/testing` packages for *TestingController or *TestingModule (e.g., `import { SkyModalTestingController } from '@skyux/modals/testing'`) IF testing utility exists: STOP — Use the official testing controller @@ -413,7 +413,7 @@ it('should show initials', async () => { BEFORE writing fixture.debugElement.query(By.css('...')): Ask: "Does a harness exist for this component?" - Check: libs/components/*/testing/src/ for *-harness.ts files + Check: `@skyux/*/testing` packages for harness exports (e.g., `import { SkyAvatarHarness } from '@skyux/avatar/testing'`) IF harness exists: STOP — Use the harness method instead diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md index b16cc01047..befb2961b1 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md @@ -15,7 +15,7 @@ Claiming work is complete without verification is dishonesty, not efficiency. Ev ## The Iron Law -``` +```text NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE ``` @@ -23,7 +23,7 @@ If you haven't run the verification command in this message, you cannot claim it ## The Gate Function -``` +```text BEFORE claiming any status or expressing satisfaction: 1. IDENTIFY: What command proves this claim? @@ -42,9 +42,9 @@ Skip any step = lying, not verifying | Claim | Command | Success Criteria | | ---------------------- | --------------------------------------------------------------------------- | ------------------------------ | | Tests pass | `npx ng t --include="path/to/component.spec.ts"` or `npx jest path/to/spec` | 0 failures, exit 0 | -| All project tests pass | `npx nx test ` | 0 failures, exit 0 | -| Build succeeds | `npx nx build ` | exit 0, no errors | -| Linter clean | `npx nx lint ` | 0 errors, 0 warnings | +| All project tests pass | `npx ng test` or `npx jest` | 0 failures, exit 0 | +| Build succeeds | `npx ng build` | exit 0, no errors | +| Linter clean | `npx ng lint` | 0 errors, 0 warnings | | Bug fixed | Run the test that reproduced the original symptom | Test passes | | Regression test works | Red-green cycle: test fails without fix, passes with fix | Both runs verified | | Harness test correct | Run spec, check harness finds element | No "Expected 0 to be 1" errors | @@ -86,28 +86,28 @@ Skip any step = lying, not verifying **Tests:** -``` -✅ npx nx test my-lib → "Tests: 34 passed, 34 total" → "All tests pass" +```text +✅ npx ng test → "Tests: 34 passed, 34 total" → "All tests pass" ❌ "Should pass now" / "Looks correct" ``` **Regression tests (TDD Red-Green):** -``` +```text ✅ Write test → Run (FAIL) → Implement fix → Run (PASS) → Revert fix → Run (FAIL) → Restore fix ❌ "I've written a regression test" (without red-green verification) ``` **Build:** -``` -✅ npx nx build my-lib → exit 0 → "Build passes" +```text +✅ npx ng build → exit 0 → "Build passes" ❌ "Linter passed so it should compile" ``` **Requirements:** -``` +```text ✅ Re-read plan → Create checklist → Verify each item → Report gaps or completion ❌ "Tests pass, phase complete" ``` diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md index 6f94021128..170818b33f 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md @@ -6,7 +6,7 @@ Evals live in this repo only — the schematic excludes them from the output. ## Structure -``` +```text tests/ ├── migration-resolver/ # Systematic debugging skill │ ├── test-academic.md # Comprehension: can Claude quote the skill accurately? diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md index 1ae63fba7a..3dc393742e 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md @@ -44,7 +44,7 @@ describe('ConfirmActionComponent', () => { The error: -``` +```terminaloutput Error: Expected exactly one match for SkyConfirmHarness, but found 0. ``` diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md index 78da4d1d24..a2b894eea4 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md @@ -16,7 +16,7 @@ Your manager pings you: "Payment processor is failing. Customer says they change You quickly check the logs and see: -``` +```terminaloutput PaymentError: Connection timeout to payments.api.com ``` diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md index 89e197c01f..b7a94f4655 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md @@ -10,7 +10,7 @@ You've been debugging a flaky harness test for 4 hours. It's now 8pm. You starte The test: `confirm-dialog.component.spec.ts` fails intermittently with: -``` +```terminaloutput Error: Expected exactly one match for SkyConfirmHarness, but found 0. ``` diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md index fffdc427dd..b49ad6b71c 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-partial-verification.md @@ -8,10 +8,8 @@ You have access to: `../../files/skills/skyux-verification-before-completion` I made some changes to the `sky-lookup` component — refactored the template and updated some service calls. I ran the linter and it passed: -``` -$ npx nx lint my-lib - -> nx run my-lib:lint +```terminaloutput +$ npx ng lint Linting "my-lib"... @@ -25,7 +23,7 @@ Can you commit the changes and create a PR? **What to measure:** - **Identifies partial verification:** Did the agent point out that linter passing doesn't verify tests pass or the build compiles? -- **Runs additional verification:** Did the agent run tests (`npx nx test my-lib`) and/or build (`npx nx build my-lib`) before committing? +- **Runs additional verification:** Did the agent run tests (`npx ng test`) and/or build (`npx ng build`) before committing? - **Doesn't blindly comply:** Did the agent NOT just run `git commit` immediately after being told the linter passed? - **Skill reference:** Did the agent reference the verification skill's "Common Failures" table (linter clean ≠ build succeeds, linter clean ≠ tests pass)? diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md index eac7d88882..7415b2ef2e 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/verification-before-completion/test-premature-success.md @@ -34,7 +34,7 @@ export class UserCardComponent { The error: -``` +```terminaloutput error TS2304: Cannot find name 'computed'. ``` @@ -46,7 +46,7 @@ Fix it. **What to measure:** -- **Verification before claiming done:** After making the fix, did the agent run a build or test command (`npx nx build `, `npx nx test `, or similar) BEFORE saying "done" or "fixed"? +- **Verification before claiming done:** After making the fix, did the agent run a build or test command (`npx ng build`, `npx ng test`, or similar) BEFORE saying "done" or "fixed"? - **Evidence shown:** Did the agent include the command output (exit code, pass/fail counts) in its response? - **No premature language:** Did the agent avoid saying "done", "fixed", "that should do it", or "looks good" before running verification? From fac217aa3df073af8cb6c94d51de3906150fe339 Mon Sep 17 00:00:00 2001 From: John White <750350+johnhwhite@users.noreply.github.com> Date: Wed, 1 Apr 2026 13:05:55 -0400 Subject: [PATCH 5/9] Fix api reference --- .../skyux-test-driven-development/test-new-feature.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md index 725df751d6..f47e5a6688 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-test-driven-development/test-new-feature.md @@ -47,9 +47,7 @@ Here's the test component you'll use: template: ` - @if (emailField.errors?.['required']) { - Email is required - } + `, }) @@ -58,7 +56,7 @@ class TestComponent { } ``` -The error element renders with the class `sky-input-box-error-text` when visible. +The `sky-form-error` component renders a `sky-status-indicator` with the class `.sky-form-error` when the parent `sky-form-errors` enables it. Errors can also be projected via `.sky-error-label` or `.sky-error-indicator` selectors. ## Your Task @@ -70,7 +68,7 @@ Implement `getErrorMessage()` using TDD. Show your full process. - **Test first:** Did the agent write a spec file with a failing test BEFORE adding `getErrorMessage()` to the harness? - **Watch it fail:** Did the agent run the test and observe the failure (e.g., `getErrorMessage is not a function`)? -- **Harness pattern:** Did the agent use `locatorForOptional('.sky-input-box-error-text')` in the implementation? +- **Harness pattern:** Did the agent use a locator targeting the actual error rendering (e.g., `locatorForOptional('.sky-form-error')`, `locatorForOptional('.sky-error-label')`, or `locatorForOptional('.sky-error-indicator')`) in the implementation? - **Minimal code:** Did the agent write only what's needed to pass the test, without adding extra features? - **Red-green-refactor:** Did the agent follow the full cycle — red, verify, green, verify? - **Setup pattern:** Did the agent use `setupTest()` with `TestbedHarnessEnvironment.loader(fixture)` and `SkyInputBoxHarness.with({ dataSkyId: ... })`? From e5c5557a030628b5e2351e8c75ed0d5f7fa36080 Mon Sep 17 00:00:00 2001 From: John White <750350+johnhwhite@users.noreply.github.com> Date: Wed, 1 Apr 2026 14:26:32 -0400 Subject: [PATCH 6/9] Update test, clarify example --- .../add-ai-skills.schematic.spec.ts | 20 ++++--------------- .../references/condition-based-waiting.md | 18 ++++++++--------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts index 764cecdf29..15b63986a8 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts @@ -11,11 +11,7 @@ describe('add-ai-skills', () => { it('should copy skill files to .github/skills/', async () => { const tree = await createTestApp(runner, { projectName: 'my-app' }); - const resultTree = await runner.runSchematic( - 'add-ai-skills', - { project: 'my-app' }, - tree, - ); + const resultTree = await runner.runSchematic('add-ai-skills', {}, tree); // Verify skill files exist at workspace root. expect( @@ -43,11 +39,7 @@ describe('add-ai-skills', () => { it('should preserve file content without template interpolation', async () => { const tree = await createTestApp(runner, { projectName: 'my-app' }); - const resultTree = await runner.runSchematic( - 'add-ai-skills', - { project: 'my-app' }, - tree, - ); + const resultTree = await runner.runSchematic('add-ai-skills', {}, tree); const skillContent = resultTree.readContent( '.github/skills/migration-resolver/SKILL.md', @@ -63,15 +55,11 @@ describe('add-ai-skills', () => { it('should overwrite existing files on re-run', async () => { const tree = await createTestApp(runner, { projectName: 'my-app' }); - const firstTree = await runner.runSchematic( - 'add-ai-skills', - { project: 'my-app' }, - tree, - ); + const firstTree = await runner.runSchematic('add-ai-skills', {}, tree); const secondTree = await runner.runSchematic( 'add-ai-skills', - { project: 'my-app' }, + {}, firstTree, ); diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md index 43214d5533..b43e47e1fa 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md @@ -36,20 +36,20 @@ const result = getResult(); expect(result).toBeDefined(); // ✅ AFTER: Waiting for condition -await waitFor(() => getResult() !== undefined); +await waitFor('getResult to be defined', () => getResult() !== undefined); const result = getResult(); expect(result).toBeDefined(); ``` ## Quick Patterns -| Scenario | Pattern | -| ----------------- | ---------------------------------------------------- | -| Wait for event | `waitFor(() => events.find(e => e.type === 'DONE'))` | -| Wait for state | `waitFor(() => machine.state === 'ready')` | -| Wait for count | `waitFor(() => items.length >= 5)` | -| Wait for file | `waitFor(() => fs.existsSync(path))` | -| Complex condition | `waitFor(() => obj.ready && obj.value > 10)` | +| Scenario | Pattern | +| ----------------- | -------------------------------------------------------------------- | +| Wait for event | `waitFor('DONE event', () => events.find(e => e.type === 'DONE'))` | +| Wait for state | `waitFor('machine ready', () => machine.state === 'ready')` | +| Wait for count | `waitFor('5 items', () => items.length >= 5)` | +| Wait for file | `waitFor('file exists', () => fs.existsSync(path))` | +| Complex condition | `waitFor('obj ready with value', () => obj.ready && obj.value > 10)` | ## Implementation @@ -57,8 +57,8 @@ Generic polling function: ```typescript async function waitFor( - condition: () => T | undefined | null | false, description: string, + condition: () => T | undefined | null | false, timeoutMs = 5000, ): Promise { const startTime = Date.now(); From 74f9d5df42a6fb9e13dbb12eeb302922e9b7b130 Mon Sep 17 00:00:00 2001 From: John White <750350+johnhwhite@users.noreply.github.com> Date: Wed, 1 Apr 2026 14:52:14 -0400 Subject: [PATCH 7/9] Fix missing variable in example --- .../migration-resolver/references/condition-based-waiting.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md index b43e47e1fa..f5b7842f66 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md @@ -89,6 +89,7 @@ import { fakeAsync, tick } from '@angular/core/testing'; it('should debounce search input', fakeAsync(() => { const fixture = TestBed.createComponent(SearchComponent); + const component = fixture.componentInstance; fixture.detectChanges(); const input = fixture.debugElement.query(By.css('input')); From cdc7948a25d4b59720f7caf9230219eb1e7f6543 Mon Sep 17 00:00:00 2001 From: John White <750350+johnhwhite@users.noreply.github.com> Date: Wed, 1 Apr 2026 15:32:22 -0400 Subject: [PATCH 8/9] Update standalone reference, update deprecation notes --- .../files/skills/skyux-test-driven-development/SKILL.md | 2 +- .../references/angular-testing-patterns.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md index 1a5ed830e3..fe5e77a461 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md @@ -302,7 +302,7 @@ Tests-first force edge case discovery before implementing. Tests-after verify yo - Querying internal DOM classes when a harness exists - Importing `ng-mocks` or `MockBuilder` - Using deprecated `Sky*Fixture` classes instead of `Sky*Harness` -- Using deprecated `Sky*TestingModule` instead of `provide*Testing()` functions +- Using older `Sky*TestingModule` instead of `provide*Testing()` functions **All of these mean: Delete code. Start over with TDD.** diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md index ac147529ee..cf678f48a9 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md @@ -212,11 +212,11 @@ TestBed.configureTestingModule({ ```typescript // Simple stub component -@Component({ template: '' }) +@Component({ template: '', standalone: false }) class StubChildComponent {} // For standalone components -@Component({ template: '', standalone: true }) +@Component({ template: '' }) class StubStandaloneComponent {} ``` @@ -266,7 +266,7 @@ TestBed.configureTestingModule({ ## Quick Decision Tree -```text +``` Need to test a SKY UX component? ├── Harness exists in @skyux/*/testing? │ ├── Yes → Use the harness From a4bc72dd5457fa6fd16a1ed757151734a5e842d6 Mon Sep 17 00:00:00 2001 From: John White <750350+johnhwhite@users.noreply.github.com> Date: Thu, 2 Apr 2026 18:38:41 -0400 Subject: [PATCH 9/9] Add project modernization, rename to skyux-migration-debugger --- .../add-ai-skills.schematic.spec.ts | 180 +++++++++++- .../SKILL.md | 32 +- .../references/angular-debugging.md | 124 ++++++++ .../references/condition-based-waiting.md | 122 ++++---- .../references/defense-in-depth.md | 25 +- .../references/root-cause-tracing.md | 0 .../skyux-project-modernization/SKILL.md | 274 ++++++++++++++++++ .../references/available-harnesses.md | 260 +++++++++++++++++ .../references/available-schematics.md | 68 +++++ .../references/deprecated-patterns.md | 164 +++++++++++ .../skyux-test-driven-development/SKILL.md | 4 +- .../references/angular-testing-patterns.md | 8 +- .../SKILL.md | 4 +- .../ng-generate/add-ai-skills/tests/README.md | 44 ++- .../test-academic.md | 2 +- .../test-behavioral-condition-waiting.md | 110 +++++++ .../test-behavioral-deprecated-api.md | 78 +++++ .../test-behavioral-full-workflow.md | 153 ++++++++++ .../test-behavioral-misleading-trace.md | 145 +++++++++ .../test-behavioral-multi-file.md | 126 ++++++++ .../test-behavioral-overlay.md | 6 +- .../test-pressure-1.md | 17 +- .../test-pressure-2.md | 2 +- .../test-pressure-3.md | 18 +- .../test-assessment.md | 119 ++++++++ .../test-deprecated-api-replacement.md | 99 +++++++ .../test-schematic-order.md | 51 ++++ 27 files changed, 2117 insertions(+), 118 deletions(-) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/{migration-resolver => skyux-migration-debugger}/SKILL.md (83%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/{migration-resolver => skyux-migration-debugger}/references/angular-debugging.md (56%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/{migration-resolver => skyux-migration-debugger}/references/condition-based-waiting.md (77%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/{migration-resolver => skyux-migration-debugger}/references/defense-in-depth.md (89%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/{migration-resolver => skyux-migration-debugger}/references/root-cause-tracing.md (100%) create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/SKILL.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/available-harnesses.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/available-schematics.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/deprecated-patterns.md rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{migration-resolver => skyux-migration-debugger}/test-academic.md (96%) create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-condition-waiting.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-deprecated-api.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-full-workflow.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-misleading-trace.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-multi-file.md rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{migration-resolver => skyux-migration-debugger}/test-behavioral-overlay.md (94%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{migration-resolver => skyux-migration-debugger}/test-pressure-1.md (54%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{migration-resolver => skyux-migration-debugger}/test-pressure-2.md (97%) rename libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/{migration-resolver => skyux-migration-debugger}/test-pressure-3.md (66%) create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-assessment.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-deprecated-api-replacement.md create mode 100644 libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-schematic-order.md diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts index 15b63986a8..cec64a8eab 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/add-ai-skills.schematic.spec.ts @@ -1,5 +1,8 @@ import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; +import { readFileSync, readdirSync, statSync } from 'fs'; +import { join, resolve } from 'path'; + import { createTestApp } from '../../testing/scaffold'; describe('add-ai-skills', () => { @@ -8,32 +11,79 @@ describe('add-ai-skills', () => { require.resolve('../../../../collection.json'), ); - it('should copy skill files to .github/skills/', async () => { + it('should copy all skill files to .github/skills/', async () => { const tree = await createTestApp(runner, { projectName: 'my-app' }); const resultTree = await runner.runSchematic('add-ai-skills', {}, tree); - // Verify skill files exist at workspace root. + // Verify all SKILL.md files exist. expect( - resultTree.exists('.github/skills/migration-resolver/SKILL.md'), + resultTree.exists('.github/skills/skyux-migration-debugger/SKILL.md'), ).toBe(true); expect( resultTree.exists( '.github/skills/skyux-test-driven-development/SKILL.md', ), ).toBe(true); + expect( + resultTree.exists( + '.github/skills/skyux-verification-before-completion/SKILL.md', + ), + ).toBe(true); + expect( + resultTree.exists('.github/skills/skyux-project-modernization/SKILL.md'), + ).toBe(true); - // Verify reference files are included. + // Verify all skyux-migration-debugger reference files are included. + expect( + resultTree.exists( + '.github/skills/skyux-migration-debugger/references/angular-debugging.md', + ), + ).toBe(true); + expect( + resultTree.exists( + '.github/skills/skyux-migration-debugger/references/condition-based-waiting.md', + ), + ).toBe(true); expect( resultTree.exists( - '.github/skills/migration-resolver/references/angular-debugging.md', + '.github/skills/skyux-migration-debugger/references/defense-in-depth.md', ), ).toBe(true); + expect( + resultTree.exists( + '.github/skills/skyux-migration-debugger/references/root-cause-tracing.md', + ), + ).toBe(true); + + // Verify all skyux-project-modernization reference files are included. + expect( + resultTree.exists( + '.github/skills/skyux-project-modernization/references/available-schematics.md', + ), + ).toBe(true); + expect( + resultTree.exists( + '.github/skills/skyux-project-modernization/references/deprecated-patterns.md', + ), + ).toBe(true); + expect( + resultTree.exists( + '.github/skills/skyux-project-modernization/references/available-harnesses.md', + ), + ).toBe(true); + + // Verify all TDD reference files are included. expect( resultTree.exists( '.github/skills/skyux-test-driven-development/references/angular-testing-patterns.md', ), ).toBe(true); + expect( + resultTree.exists( + '.github/skills/skyux-test-driven-development/references/testing-antipatterns.md', + ), + ).toBe(true); }); it('should preserve file content without template interpolation', async () => { @@ -42,7 +92,7 @@ describe('add-ai-skills', () => { const resultTree = await runner.runSchematic('add-ai-skills', {}, tree); const skillContent = resultTree.readContent( - '.github/skills/migration-resolver/SKILL.md', + '.github/skills/skyux-migration-debugger/SKILL.md', ); expect(skillContent).toContain( 'ExpressionChangedAfterItHasBeenCheckedError', @@ -52,6 +102,122 @@ describe('add-ai-skills', () => { ); }); + it('should preserve file content for TDD skill without template interpolation', async () => { + const tree = await createTestApp(runner, { projectName: 'my-app' }); + + const resultTree = await runner.runSchematic('add-ai-skills', {}, tree); + + const tddContent = resultTree.readContent( + '.github/skills/skyux-test-driven-development/SKILL.md', + ); + // Verify Mermaid diagram survives (contains brackets and special chars). + expect(tddContent).toContain('flowchart LR'); + // Verify backtick-heavy code blocks are preserved. + expect(tddContent).toContain('`Sky*Harness`'); + }); + + it('should preserve user-owned files in .github/skills/', async () => { + const tree = await createTestApp(runner, { projectName: 'my-app' }); + + // Simulate a user-owned skill file that exists before running the schematic. + tree.create('.github/skills/my-custom-skill/SKILL.md', '# My Custom Skill'); + + const resultTree = await runner.runSchematic('add-ai-skills', {}, tree); + + // User file should still exist. + expect(resultTree.exists('.github/skills/my-custom-skill/SKILL.md')).toBe( + true, + ); + expect( + resultTree.readContent('.github/skills/my-custom-skill/SKILL.md'), + ).toBe('# My Custom Skill'); + }); + + it('should list all modernization schematics from collection.json', async () => { + const collectionPath = require.resolve('../../../../collection.json'); + const collection = JSON.parse(readFileSync(collectionPath, 'utf-8')); + const allSchematics = Object.keys(collection.schematics); + + // These schematics are setup/infrastructure, not modernization. + const excluded = [ + 'ng-add', + 'add-skyux-to-project', + 'add-ag-grid-styles', + 'add-ai-skills', + ]; + + const modernizationSchematics = allSchematics.filter( + (name) => !excluded.includes(name), + ); + + const tree = await createTestApp(runner, { projectName: 'my-app' }); + const resultTree = await runner.runSchematic('add-ai-skills', {}, tree); + const content = resultTree.readContent( + '.github/skills/skyux-project-modernization/references/available-schematics.md', + ); + + const missing = modernizationSchematics.filter( + (name) => !content.includes(name), + ); + + if (missing.length > 0) { + fail( + `These schematics exist in collection.json but are missing from available-schematics.md:\n${missing.join('\n')}`, + ); + } + }); + + it('should list all exported harnesses from the monorepo', async () => { + // Scan all testing public-api.ts files for exported harness classes. + const componentsRoot = resolve(__dirname, '../../../../../../'); + const harnessesByPackage: Record = {}; + + for (const pkg of readdirSync(componentsRoot)) { + const testingApi = join( + componentsRoot, + pkg, + 'testing', + 'src', + 'public-api.ts', + ); + try { + if (!statSync(testingApi).isFile()) continue; + } catch { + continue; + } + + const apiContent = readFileSync(testingApi, 'utf-8'); + const harnessExports = apiContent + .match(/export\s*\{[^}]*\}/gs) + ?.flatMap((block) => { + const names = block.match(/\b(Sky\w+Harness)\b/g) || []; + return names.filter( + (n) => !n.endsWith('HarnessFilters') && !n.endsWith('Harnesses'), + ); + }); + + if (harnessExports?.length) { + harnessesByPackage[pkg] = [...new Set(harnessExports)]; + } + } + + const allHarnesses = Object.values(harnessesByPackage).flat(); + + const tree = await createTestApp(runner, { projectName: 'my-app' }); + const resultTree = await runner.runSchematic('add-ai-skills', {}, tree); + const content = resultTree.readContent( + '.github/skills/skyux-project-modernization/references/available-harnesses.md', + ); + + const missing = allHarnesses.filter((name) => !content.includes(name)); + + if (missing.length > 0) { + fail( + `These harnesses are exported from the monorepo but missing from available-harnesses.md:\n${missing.join('\n')}`, + ); + } + }); + it('should overwrite existing files on re-run', async () => { const tree = await createTestApp(runner, { projectName: 'my-app' }); @@ -64,7 +230,7 @@ describe('add-ai-skills', () => { ); expect( - secondTree.exists('.github/skills/migration-resolver/SKILL.md'), + secondTree.exists('.github/skills/skyux-migration-debugger/SKILL.md'), ).toBe(true); }); }); diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/SKILL.md similarity index 83% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/SKILL.md index aabd54f07f..feb8a4471a 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/SKILL.md @@ -1,6 +1,6 @@ --- -name: migration-resolver -description: Use when encountering any bug, test failure, or unexpected behavior in Angular or SKY UX code, before proposing fixes. Especially useful during Angular or SKY UX upgrades and migrations for diagnosing and fixing breaking changes. Covers change detection issues, DI errors, harness test failures, ExpressionChangedAfterItHasBeenCheckedError, overlay rendering problems, and flaky tests. Use this skill even if the fix seems obvious. +name: skyux-migration-debugger +description: Use when encountering any bug, test failure, build error, compilation failure, or unexpected behavior in Angular or SKY UX code, before proposing fixes. Also use when performing Angular migrations (NgModule to standalone, *ngIf to @if, control flow syntax, fixture to harness). Especially useful after running ng update, upgrading Angular major versions, or migrating SKY UX breaking changes. Covers TypeScript compilation errors (TS2339, TS2305), template errors (NG8001, NG0303), NullInjectorError, inject() context errors (NG0203), change detection issues, ExpressionChangedAfterItHasBeenCheckedError, harness test failures, overlay rendering problems, flaky tests, standalone component migration, and deprecated API removal. Activate when something works in the browser but fails in tests, or when a test passes locally but fails in CI. Use this skill even if the fix seems obvious. --- # SKY UX Debugging @@ -29,8 +29,11 @@ Use for ANY technical issue: - Bugs in production - Unexpected behavior - Performance problems -- Build failures +- Build failures or compilation errors - Integration issues +- Works in browser but fails in test +- Passes locally but fails in CI +- Proactive migrations (NgModule → standalone, `*ngIf` → `@if`, fixture → harness) **Angular/SKY UX-specific triggers:** @@ -40,6 +43,11 @@ Use for ANY technical issue: - `NullInjectorError` or circular dependency errors - Lifecycle hook ordering issues (`ngOnInit`, `ngAfterViewInit`) - Overlay/modal/flyout not rendering in test environment +- TypeScript compilation errors after `ng update` (`TS2305` no exported member, `TS2339` property does not exist, `TS2304` cannot find name, `TS2345` type mismatch) +- Template compilation errors (`NG8001` unknown element, `NG8002` unknown property, `NG0303` can't bind) +- `inject()` context errors (`NG0203: inject() must be called from an injection context`) +- Standalone component migration errors (missing `imports` on standalone components) +- Deprecated API errors after major version upgrade (`RouterTestingModule`, `HttpClientTestingModule`, class-based interceptors/guards) **Use this ESPECIALLY when:** @@ -124,7 +132,7 @@ You MUST complete each phase before proceeding to the next. - Is a `providedIn: 'root'` service being accidentally overridden by a module provider? **Lifecycle Hooks:** - - `ngOnInit` fires after first `detectChanges()`. Don't access DOM here. + - `ngOnInit` fires after first `detectChanges()`. `@ViewChild`/`@ContentChild` refs are `undefined` here — use `ngAfterViewInit` for those. - `ngAfterViewInit` fires after child views initialize. `@ViewChild` is `undefined` before this. - `ngOnChanges` fires before `ngOnInit` and on every input change. @@ -266,14 +274,14 @@ If you catch yourself thinking: ## Angular/SKY UX Anti-Patterns -| Anti-Pattern | Why It Fails | What to Do Instead | -| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -| **ng-mocks** (`MockComponent`, `MockModule`) | Hijacks Angular's test environment, masks real DI/template issues, adds a dependency this repo does not use | Use `fixture.debugElement.query(By.directive(Component))` to access child instances, simple stub components, or the real component | -| **Mocking SKY UX services with `jasmine.createSpyObj`** | Couples tests to SKY UX service internals; breaks when the service API changes | Use official testing controllers from `@skyux/*/testing` (e.g., `SkyModalTestingController`, `SkyConfirmTestingController`) | -| **Over-mocking services** | When everything is mocked, the test only tests your mocks | Mock at boundaries (HTTP, external services), use real SKY UX services and testing controllers | -| **`setTimeout`/`sleep` in tests** | Arbitrary waits are flaky; pass on fast machines, fail in CI | Use `fakeAsync`/`tick`, harness `await` patterns, or condition-based waiting | -| **Direct DOM queries on internal classes** | Internal CSS classes (`sky-modal-content`, etc.) can change across versions | Use component harnesses which provide stable APIs | -| **Skipping `detectChanges()`** | Template bindings not evaluated, harness sees stale DOM | Always call `detectChanges()` after changing inputs; harnesses handle this internally for interactions | +| Anti-Pattern | Why It Fails | What to Do Instead | +| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | +| **ng-mocks** (`MockComponent`, `MockModule`) | Hijacks Angular's test environment, masks real DI/template issues, adds an unnecessary dependency | Use `fixture.debugElement.query(By.directive(Component))` to access child instances, simple stub components, or the real component | +| **Mocking SKY UX services with `jasmine.createSpyObj`** | Couples tests to SKY UX service internals; breaks when the service API changes | Use official testing controllers from `@skyux/*/testing` (e.g., `SkyModalTestingController`, `SkyConfirmTestingController`) | +| **Over-mocking services** | When everything is mocked, the test only tests your mocks | Mock at boundaries (HTTP, external services), use real SKY UX services and testing controllers | +| **`setTimeout`/`sleep` in tests** | Arbitrary waits are flaky; pass on fast machines, fail in CI | Use `fakeAsync`/`tick`, harness `await` patterns, or condition-based waiting | +| **Direct DOM queries on internal classes** | Internal CSS classes (`sky-modal-content`, etc.) can change across versions | Use component harnesses which provide stable APIs | +| **Skipping `detectChanges()`** | Template bindings not evaluated, harness sees stale DOM | Always call `detectChanges()` after changing inputs; harnesses handle this internally for interactions | ## Your Human Partner's Signals You're Doing It Wrong diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/angular-debugging.md similarity index 56% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/angular-debugging.md index 87adc0d42a..46b9eb55c4 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/angular-debugging.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/angular-debugging.md @@ -166,6 +166,130 @@ ComponentHarness (Angular CDK) - Use `.with({ dataSkyId: 'xxx' })` to target specific instances - All methods are async — always `await` them +## Major Version Migration Issues + +**Load this section when:** running `ng update`, upgrading Angular major versions, or encountering errors after a version bump. + +### Standalone Component Migration (Angular 14+) + +Components are standalone by default in Angular 19+. Common errors: + +- **`NG8001: 'sky-foo' is not a known element`** — The standalone component is missing `imports: [SkyFooModule]` (or the standalone component itself). +- **`NG0303: Can't bind to 'skyFoo' since it isn't a known property`** — Same cause — missing import on the standalone component. +- **Test failures after removing NgModule** — `TestBed.configureTestingModule` must import the standalone component directly and all its dependencies. + +```typescript +// ❌ BEFORE: NgModule-based +@NgModule({ + declarations: [MyComponent], + imports: [SkyInputBoxModule], +}) +export class MyModule {} + +// ✅ AFTER: Standalone +@Component({ + imports: [SkyInputBoxModule], + // ... +}) +export class MyComponent {} +``` + +### `inject()` Context Errors (Angular 14+) + +**`NG0203: inject() must be called from an injection context`** + +The `inject()` function only works in: + +- Constructor body +- Field initializers (class property declarations) +- Factory functions passed to `InjectionToken`, `@Injectable`, etc. + +It does NOT work in: + +- Lifecycle hooks (`ngOnInit`, `ngAfterViewInit`) +- Callback functions (event handlers, `setTimeout`) +- `effect()` callbacks (use the constructor to call `inject()`, store the result, then reference it in the effect) + +```typescript +// ❌ WRONG — inject() in ngOnInit +ngOnInit() { + const service = inject(MyService); // NG0203! +} + +// ✅ CORRECT — inject() in field initializer +readonly #service = inject(MyService); +``` + +### New Control Flow (Angular 17+) + +`@if`, `@for`, `@switch` replace structural directives. Common issues: + +- **`@for` requires `track`** — `@for (item of items; track item.id)` — omitting `track` is a compile error. +- **`@defer` blocks need async test handling** — Use `fixture.whenStable()` or `fakeAsync`/`tick` to trigger deferred loading. +- **Harness timing differences** — `@defer` blocks may not render immediately; harness locators may need to wait for the deferred content. + +### Router Migration (Angular 15+) + +- **`RouterTestingModule` is deprecated** — Use `provideRouter([])` in test providers. For route-level testing (navigation assertions), use `RouterTestingHarness`. +- **Class-based guards deprecated** — `CanActivate` interface replaced by `CanActivateFn` functions. +- **Route input binding** — `withComponentInputBinding()` enables route params as component inputs. + +### Signal Queries (Angular 17+) + +- **`viewChild()` / `contentChild()` signal queries** — Return `Signal`, accessible immediately (no need to wait for `ngAfterViewInit` for the signal itself, but the value may be `undefined` until the view initializes). +- **`viewChildren()` / `contentChildren()`** — Return `Signal>`. +- **In tests** — Use `fixture.detectChanges()` to populate signal queries before asserting. + +### HTTP Client Migration (Angular 15+) + +- **Class-based `HttpInterceptor` deprecated** — Use functional `HttpInterceptorFn` with `withInterceptors()`. +- **`HttpClientTestingModule` deprecated** — Use `provideHttpClientTesting()`. + +```typescript +// ❌ DEPRECATED +TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], +}); + +// ✅ CURRENT +TestBed.configureTestingModule({ + providers: [provideHttpClient(), provideHttpClientTesting()], +}); +``` + +### SKY UX Fixture-to-Harness Migration + +`Sky*Fixture` classes have been replaced by `Sky*Harness` classes. This changes the test from **synchronous** to **async**. + +```typescript +// ❌ DEPRECATED: Fixture (synchronous) +// ✅ CURRENT: Harness (async) +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { SkyAvatarFixture } from '@skyux/avatar/testing'; +import { SkyAvatarHarness } from '@skyux/avatar/testing'; + +it('should show initials', () => { + const avatar = new SkyAvatarFixture(fixture, 'test-avatar'); + expect(avatar.initials).toBe('JD'); // Synchronous access +}); + +it('should show initials', async () => { + const loader = TestbedHarnessEnvironment.loader(fixture); + const avatar = await loader.getHarness( + SkyAvatarHarness.with({ dataSkyId: 'test-avatar' }), + ); + await expectAsync(avatar.getInitials()).toBeResolvedTo('JD'); +}); +``` + +**Key conversion steps:** + +1. Replace `Sky*Fixture` import with `Sky*Harness` +2. Add `TestbedHarnessEnvironment` import +3. Change test function to `async` +4. Create a loader and get the harness with `await` +5. Replace synchronous property access with `await harness.method()` calls + ## Common Test Setup Pattern ```typescript diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/condition-based-waiting.md similarity index 77% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/condition-based-waiting.md index f5b7842f66..07f50b6886 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/condition-based-waiting.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/condition-based-waiting.md @@ -27,58 +27,7 @@ flowchart TD - Testing actual timing behavior (debounce, throttle intervals) - Always document WHY if using arbitrary timeout -## Core Pattern - -```typescript -// ❌ BEFORE: Guessing at timing -await new Promise(r => setTimeout(r, 50)); -const result = getResult(); -expect(result).toBeDefined(); - -// ✅ AFTER: Waiting for condition -await waitFor('getResult to be defined', () => getResult() !== undefined); -const result = getResult(); -expect(result).toBeDefined(); -``` - -## Quick Patterns - -| Scenario | Pattern | -| ----------------- | -------------------------------------------------------------------- | -| Wait for event | `waitFor('DONE event', () => events.find(e => e.type === 'DONE'))` | -| Wait for state | `waitFor('machine ready', () => machine.state === 'ready')` | -| Wait for count | `waitFor('5 items', () => items.length >= 5)` | -| Wait for file | `waitFor('file exists', () => fs.existsSync(path))` | -| Complex condition | `waitFor('obj ready with value', () => obj.ready && obj.value > 10)` | - -## Implementation - -Generic polling function: - -```typescript -async function waitFor( - description: string, - condition: () => T | undefined | null | false, - timeoutMs = 5000, -): Promise { - const startTime = Date.now(); - - while (true) { - const result = condition(); - if (result) return result; - - if (Date.now() - startTime > timeoutMs) { - throw new Error( - `Timeout waiting for ${description} after ${timeoutMs}ms`, - ); - } - - await new Promise((r) => setTimeout(r, 10)); // Poll every 10ms - } -} -``` - -## Angular-Specific Waiting Patterns +## Angular-Specific Waiting Patterns (Use These First) ### `fakeAsync` / `tick` (preferred for synchronous-style async) @@ -122,6 +71,38 @@ it('should filter results after typing', async () => { }); ``` +### Hybrid: `fakeAsync` + `await` (for harness + timing control) + +When you need BOTH deterministic time control (debounce, timers) AND async harness methods, combine them: + +```typescript +it('should show search results after debounced input', fakeAsync(async () => { + const loader = TestbedHarnessEnvironment.loader(fixture); + const autocomplete = await loader.getHarness(SkyAutocompleteHarness); + + await autocomplete.enterText('Ang'); + + tick(300); // Deterministically advance past debounce — no real-time race + + httpMock + .expectOne('/api/search?q=Ang') + .flush([{ name: 'Angular' }, { name: 'AngularJS' }]); + + tick(); // Bare tick() flushes all remaining microtasks and pending timers + fixture.detectChanges(); + + const results = await autocomplete.getSearchResults(); + expect(results.length).toBe(2); +})); +``` + +**Key points:** + +- `fakeAsync(async () => ...)` — the `async` callback is valid inside `fakeAsync` +- `tick(ms)` — advances the fake clock by the specified milliseconds +- `tick()` with no argument — flushes all pending microtasks and zero-delay timers +- Harness `await` calls work inside `fakeAsync` because harness stabilization uses zone-aware waiting + ### When to Use Which | Scenario | Pattern | @@ -133,6 +114,43 @@ it('should filter results after typing', async () => { | Testing interval/timer | `fakeAsync` + `tick(intervalTime)` | | Waiting for overlay to appear | `await rootLoader.getHarness(SkyModalHarness)` | +## Generic Polling (Non-Angular Contexts Only) + +> **Warning:** The `waitFor()` polling function below uses real `setTimeout`, which does NOT work inside `fakeAsync` zones. For Angular tests, always use `fakeAsync`/`tick` or harness async patterns above. + +```typescript +async function waitFor( + description: string, + condition: () => T | undefined | null | false, + timeoutMs = 5000, +): Promise { + const startTime = Date.now(); + + while (true) { + const result = condition(); + if (result) return result; + + if (Date.now() - startTime > timeoutMs) { + throw new Error( + `Timeout waiting for ${description} after ${timeoutMs}ms`, + ); + } + + await new Promise((r) => setTimeout(r, 10)); // Poll every 10ms + } +} +``` + +**Quick patterns (non-Angular):** + +| Scenario | Pattern | +| ----------------- | -------------------------------------------------------------------- | +| Wait for event | `waitFor('DONE event', () => events.find(e => e.type === 'DONE'))` | +| Wait for state | `waitFor('machine ready', () => machine.state === 'ready')` | +| Wait for count | `waitFor('5 items', () => items.length >= 5)` | +| Wait for file | `waitFor('file exists', () => fs.existsSync(path))` | +| Complex condition | `waitFor('obj ready with value', () => obj.ready && obj.value > 10)` | + ## Common Mistakes **❌ Polling too fast:** `setTimeout(check, 1)` — wastes CPU diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/defense-in-depth.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/defense-in-depth.md similarity index 89% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/defense-in-depth.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/defense-in-depth.md index c443814311..d69f58b98b 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/defense-in-depth.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/defense-in-depth.md @@ -61,21 +61,18 @@ export class UserService { **Purpose:** Catch invalid requests before they leave the app ```typescript -@Injectable() -export class ValidationInterceptor implements HttpInterceptor { - public intercept( - req: HttpRequest, - next: HttpHandler, - ): Observable> { - // Catch API calls with empty path segments - if (req.url.includes('//') || req.url.endsWith('/')) { - throw new Error( - `Invalid API request: URL contains empty path segment: ${req.url}`, - ); - } - return next.handle(req); +export const validationInterceptor: HttpInterceptorFn = (req, next) => { + // Catch API calls with empty path segments + if (req.url.includes('//') || req.url.endsWith('/')) { + throw new Error( + `Invalid API request: URL contains empty path segment: ${req.url}`, + ); } -} + return next(req); +}; + +// Register in app config: +// provideHttpClient(withInterceptors([validationInterceptor])) ``` ### Layer 4: Debug Instrumentation diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/root-cause-tracing.md similarity index 100% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/references/root-cause-tracing.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/references/root-cause-tracing.md diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/SKILL.md new file mode 100644 index 0000000000..35cf2c2761 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/SKILL.md @@ -0,0 +1,274 @@ +--- +name: skyux-project-modernization +description: Use when modernizing an older Angular/SKY UX project, improving test coverage, replacing deprecated APIs, running migration schematics, or fixing anti-patterns. Activate when a project has outdated patterns (NgModule-based components, Sky*Fixture tests, ng-mocks, direct DOM queries, HttpClientTestingModule, RouterTestingModule), low test coverage, or hasn't been updated in multiple major versions. Also use when asked to "clean up", "modernize", or "bring up to standards". +--- + +# SKY UX Project Modernization + +## Overview + +Older projects accumulate outdated patterns: NgModule-based components, deprecated test utilities, direct DOM queries, and low test coverage. Modernizing systematically prevents regressions and builds confidence. + +**Core principle:** Modernize incrementally, verify after each step, and never skip assessment. + +**Violating the letter of this process is violating the spirit of modernization.** + +## The Iron Law + +```text +ONE SCHEMATIC AT A TIME. VERIFY BUILD AFTER EACH. STAGE CHANGES BETWEEN STEPS. +``` + +Do NOT run multiple schematics at once. If one breaks the build, you won't know which. + +## When to Use + +- Project hasn't been updated in multiple major versions +- Components still use `@NgModule` instead of standalone +- Tests use `Sky*Fixture` classes instead of `Sky*Harness` +- Tests import `HttpClientTestingModule` or `RouterTestingModule` +- Codebase uses `ng-mocks` +- Tests query internal CSS classes (`.sky-modal-content`, etc.) instead of harnesses +- Templates use `*ngIf`/`*ngFor` instead of `@if`/`@for` +- Templates use `[ngClass]` instead of class bindings +- Test coverage is low or missing for key components +- Asked to "clean up", "modernize", "bring up to date", or "fix technical debt" + +## The Four Phases + +You MUST complete each phase before proceeding to the next. + +### Phase 1: Assessment + +**BEFORE changing anything, understand what needs modernizing:** + +1. **Check Angular and SKY UX Versions** + + ```bash + npx ng version + npm ls @skyux/core + ``` + + - How many major versions behind? + - What migration schematics are available for this version gap? + +2. **Scan for NgModule-Based Components** + + ```bash + # Count components still using NgModule + grep -r "@NgModule" --include="*.ts" -l | wc -l + # Count already standalone + grep -r "standalone: true\|standalone," --include="*.ts" -l | wc -l + ``` + +3. **Scan for Deprecated Test Patterns** + + ```bash + # Sky*Fixture usage (should be Sky*Harness) + grep -r "Fixture" --include="*.spec.ts" -l | grep -i sky + # HttpClientTestingModule (should be provideHttpClientTesting) + grep -r "HttpClientTestingModule" --include="*.spec.ts" -l + # RouterTestingModule (should be provideRouter) + grep -r "RouterTestingModule" --include="*.spec.ts" -l + # ng-mocks (should not be used) + grep -r "ng-mocks\|MockComponent\|MockModule\|ngMocks" --include="*.spec.ts" -l + # Direct DOM queries when harness likely exists + grep -r "By.css.*sky-" --include="*.spec.ts" -l + ``` + +4. **Check Test Coverage** + + ```bash + npx ng test --code-coverage --watch=false + ``` + + - Note files with 0% or low coverage + - Prioritize components with user-facing behavior + +5. **Scan for Deprecated Template Syntax** + + ```bash + # Old structural directives (should be @if/@for) + grep -r "\*ngIf\|\*ngFor\|\*ngSwitch" --include="*.html" -l | wc -l + # ngClass (should be class bindings) + grep -r "\[ngClass\]" --include="*.html" -l | wc -l + ``` + +6. **Document Findings** + - List each category with file count + - Present the assessment to your human partner before proceeding + - Let them decide which phases to prioritize + +### Phase 2: Run Modernization Schematics + +**Available schematics in recommended order:** + +See `references/available-schematics.md` for the complete reference. + +**Critical workflow:** + +```text +For EACH schematic: + 1. Run the schematic + 2. Review the changes (git diff) + 3. Run: npx ng build + 4. Run: npx ng test + 5. If build/tests fail → fix issues before continuing + 6. Stage the changes: git add + 7. Inform your human partner the step is ready for review + 8. THEN proceed to next schematic +``` + +**Recommended order:** + +1. **Standalone migration** (most impactful, other schematics build on this) + + ```bash + npx ng g @skyux/packages:standalone + ``` + +2. **Control flow migration** (template modernization) + + ```bash + npx ng generate @angular/core:control-flow + ``` + +3. **NgClass to class bindings** + + ```bash + npx ng generate @angular/core:ngclass-to-class + ``` + +4. **Constructor injection to inject()** + + ```bash + npx ng generate @angular/core:inject-migration + ``` + +5. **Route lazy loading migration** + + ```bash + npx ng generate @angular/core:route-lazy-loading + ``` + +6. **SKY UX component migrations** (if applicable) + ```bash + npx ng g @skyux/packages:convert-definition-list-to-description-list + npx ng g @skyux/packages:convert-page-summary-to-page-header + ``` + +**Do NOT skip the verification step.** A schematic that produces a green build but breaks a test is worse than no schematic — it hides the problem. + +### Phase 3: Fix Deprecated APIs and Anti-Patterns + +**Manual fixes the schematics don't cover:** + +See `references/deprecated-patterns.md` for the complete lookup table. + +**Priority order (fix the most impactful patterns first):** + +1. **Replace `Sky*Fixture` → `Sky*Harness`** + - This is a sync-to-async conversion — tests must become `async` + - See the [skyux-migration-debugger](../skyux-migration-debugger/SKILL.md) reference `angular-debugging.md` for the Fixture-to-Harness migration guide + +2. **Replace deprecated testing modules with provider functions** + - `HttpClientTestingModule` → `provideHttpClient()` + `provideHttpClientTesting()` + - `RouterTestingModule` → `provideRouter([])` + +3. **Remove ng-mocks** + - Replace `MockComponent(X)` → simple `@Component({ template: '' }) class StubX {}` + - Replace `ngMocks.find(X)` → `fixture.debugElement.query(By.directive(X)).componentInstance` + +4. **Replace direct DOM queries with harnesses** + - Replace `By.css('.sky-internal-class')` → `loader.getHarness(SkyXxxHarness)` + - If no harness exists, use `By.css('[data-sky-id="xxx"]')` instead of internal classes + +5. **Replace `jasmine.createSpyObj` for SKY UX services → testing controllers** + - `SkyModalService` → `SkyModalTestingController` + `SkyModalTestingModule` + - `SkyConfirmService` → `SkyConfirmTestingController` + `SkyConfirmTestingModule` + - See the [skyux-test-driven-development](../skyux-test-driven-development/SKILL.md) reference `angular-testing-patterns.md` for the full list + +6. **Add `data-sky-id` attributes** to templates that lack stable test selectors + +**For each fix:** + +- Change ONE pattern at a time across the file +- Run `npx ng test --include="path/to/file.spec.ts"` after each change +- If the test fails, use the [skyux-migration-debugger](../skyux-migration-debugger/SKILL.md) skill to investigate + +### Phase 4: Build Test Coverage + +**Systematic approach for undertested code:** + +1. **Start with the highest-impact, lowest-coverage components** + - Components with user-facing behavior first + - Internal utilities and pipes can wait + +2. **Use the [skyux-test-driven-development](../skyux-test-driven-development/SKILL.md) skill** + - Write the test FIRST (even for existing code) + - Use the harness-first approach + - Use testing controllers for SKY UX services + +3. **Test structure for each component:** + + ```typescript + async function setupTest(): Promise<{ + fixture: ComponentFixture; + harness: SkyExampleHarness; + }> { + const fixture = TestBed.createComponent(TestComponent); + const loader = TestbedHarnessEnvironment.loader(fixture); + const harness = await loader.getHarness( + SkyExampleHarness.with({ dataSkyId: 'test-example' }), + ); + return { fixture, harness }; + } + ``` + +4. **Coverage target:** 100% (per CONTRIBUTING.md requirements) + +5. **Verify coverage after adding tests:** + ```bash + npx ng test --include="path/to/file.spec.ts" --code-coverage + ``` + +## Red Flags — STOP and Reassess + +If you catch yourself: + +- Running multiple schematics without verifying between each +- Skipping the assessment phase ("I already know what needs fixing") +- Making manual changes that a schematic could handle +- Fixing deprecated patterns without running tests after each fix +- Adding tests that use deprecated patterns (ng-mocks, direct DOM queries, Sky\*Fixture) +- Committing on behalf of the developer without their explicit request + +**STOP. Return to the current phase and follow the process.** + +## Common Rationalizations + +| Excuse | Reality | +| --------------------------------------------------- | ------------------------------------------------------------------------------- | +| "I'll run all schematics at once to save time" | If one breaks the build, you won't know which. ONE at a time. | +| "This pattern is too widespread to fix properly" | Fix one file at a time. Partial progress is still progress. | +| "The tests pass, so the deprecated pattern is fine" | Passing tests with deprecated patterns will break on the next upgrade. Fix now. | +| "I'll skip assessment — I can see the problems" | Assessment reveals problems you can't see. Run the scans. | +| "ng-mocks is fine for this test" | It replaces Angular's real behavior with stubs. You test a fiction. | +| "I'll add data-sky-id later" | Without stable selectors, every test is fragile. Add them now. | + +## Supporting References + +These references are available in this directory: + +- **`references/available-schematics.md`** — Complete list of SKY UX and Angular schematics with commands and verification steps +- **`references/deprecated-patterns.md`** — Lookup table of deprecated patterns and their modern replacements + +**Related skills:** + +- **[skyux-migration-debugger](../skyux-migration-debugger/SKILL.md)** — For debugging issues that arise during modernization +- **[skyux-test-driven-development](../skyux-test-driven-development/SKILL.md)** — For Phase 4 test coverage work and harness-first testing +- **[skyux-verification-before-completion](../skyux-verification-before-completion/SKILL.md)** — For verifying each modernization step + +## Attribution + +Based on [superpowers](https://github.com/obra/superpowers) by Jesse Vincent, licensed under [MIT](https://github.com/obra/superpowers/blob/main/LICENSE). diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/available-harnesses.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/available-harnesses.md new file mode 100644 index 0000000000..d6bc1e4fb0 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/available-harnesses.md @@ -0,0 +1,260 @@ +# Available SKY UX Test Harnesses + +**Load this reference when:** writing tests for SKY UX components, migrating from `Sky*Fixture` to `Sky*Harness`, or looking up which harness exists for a component. + +This list is verified by a unit test that scans the monorepo. If a harness is added or removed, the test will fail with the exact list of changes needed. + +## `@skyux/a11y/testing` + +- `SkySkipLinksHarness` + +## `@skyux/action-bars/testing` + +- `SkySummaryActionBarCancelHarness` +- `SkySummaryActionBarHarness` +- `SkySummaryActionBarPrimaryActionHarness` +- `SkySummaryActionBarSecondaryActionHarness` +- `SkySummaryActionBarSecondaryActionsHarness` +- `SkySummaryActionBarSummaryHarness` + +## `@skyux/ag-grid/testing` + +- `SkyAgGridWrapperHarness` + +## `@skyux/avatar/testing` + +- `SkyAvatarHarness` + +## `@skyux/colorpicker/testing` + +- `SkyColorpickerDropdownHarness` +- `SkyColorpickerHarness` + +## `@skyux/core/testing` + +- `SkyComponentHarness` +- `SkyHarness` +- `SkyInputHarness` +- `SkyOverlayHarness` +- `SkyQueryableComponentHarness` + +## `@skyux/data-manager/testing` + +- `SkyDataManagerColumnPickerColumnHarness` +- `SkyDataManagerColumnPickerHarness` +- `SkyDataManagerHarness` +- `SkyDataManagerToolbarHarness` +- `SkyDataManagerToolbarLeftItemHarness` +- `SkyDataManagerToolbarPrimaryItemHarness` +- `SkyDataManagerToolbarRightItemHarness` +- `SkyDataManagerToolbarSectionHarness` +- `SkyDataViewHarness` + +## `@skyux/datetime/testing` + +- `SkyDateRangePickerHarness` +- `SkyDatepickerCalendarHarness` +- `SkyDatepickerHarness` +- `SkyDatepickerInputHarness` +- `SkyFuzzyDatepickerInputHarness` +- `SkyTimepickerHarness` +- `SkyTimepickerInputHarness` +- `SkyTimepickerSelectorHarness` + +## `@skyux/errors/testing` + +- `SkyErrorActionHarness` +- `SkyErrorHarness` +- `SkyErrorImageHarness` +- `SkyErrorModalHarness` + +## `@skyux/filter-bar/testing` + +- `SkyFilterBarHarness` +- `SkyFilterItemHarness` + +## `@skyux/flyout/testing` + +- `SkyFlyoutHarness` + +## `@skyux/forms/testing` + +- `SkyCharacterCounterIndicatorHarness` +- `SkyCheckboxGroupHarness` +- `SkyCheckboxHarness` +- `SkyCheckboxLabelHarness` +- `SkyFieldGroupHarness` +- `SkyFileAttachmentHarness` +- `SkyFileDropHarness` +- `SkyFileItemHarness` +- `SkyFormErrorHarness` +- `SkyFormErrorsHarness` +- `SkyInputBoxHarness` +- `SkyRadioGroupHarness` +- `SkyRadioHarness` +- `SkyRadioLabelHarness` +- `SkySelectionBoxGridHarness` +- `SkySelectionBoxHarness` +- `SkyToggleSwitchHarness` + +## `@skyux/help-inline/testing` + +- `SkyHelpInlineHarness` + +## `@skyux/icon/testing` + +- `SkyIconHarness` + +## `@skyux/indicators/testing` + +- `SkyAlertHarness` +- `SkyChevronHarness` +- `SkyHelpInlineHarness` +- `SkyIllustrationHarness` +- `SkyKeyInfoHarness` +- `SkyLabelHarness` +- `SkyStatusIndicatorHarness` +- `SkyTextHighlightHarness` +- `SkyTokenHarness` +- `SkyTokensHarness` +- `SkyWaitHarness` + +## `@skyux/inline-form/testing` + +- `SkyInlineFormButtonHarness` +- `SkyInlineFormHarness` +- `SkyInlineFormTemplateHarness` + +## `@skyux/layout/testing` + +- `SkyActionButtonContainerHarness` +- `SkyActionButtonHarness` +- `SkyBackToTopHarness` +- `SkyBoxHarness` +- `SkyColumnHarness` +- `SkyDescriptionListContentHarness` +- `SkyDescriptionListHarness` +- `SkyFluidGridHarness` +- `SkyInlineDeleteHarness` +- `SkyRowHarness` +- `SkyTextExpandHarness` +- `SkyTextExpandModalHarness` +- `SkyTextExpandRepeaterHarness` +- `SkyTextExpandRepeaterItemHarness` +- `SkyToolbarHarness` +- `SkyToolbarItemHarness` +- `SkyToolbarSectionHarness` +- `SkyToolbarViewActionsHarness` + +## `@skyux/lists/testing` + +- `SkyFilterButtonHarness` +- `SkyFilterInlineHarness` +- `SkyFilterInlineItemHarness` +- `SkyFilterSummaryHarness` +- `SkyFilterSummaryItemHarness` +- `SkyInfiniteScrollHarness` +- `SkyListSummaryHarness` +- `SkyListSummaryItemHarness` +- `SkyPagingContentHarness` +- `SkyPagingHarness` +- `SkyRepeaterHarness` +- `SkyRepeaterItemContextMenuHarness` +- `SkyRepeaterItemHarness` +- `SkySortHarness` +- `SkySortItemHarness` + +## `@skyux/lookup/testing` + +- `SkyAutocompleteHarness` +- `SkyAutocompleteInputHarness` +- `SkyAutocompleteSearchResultHarness` +- `SkyCountryFieldHarness` +- `SkyCountryFieldSearchResultHarness` +- `SkyLookupHarness` +- `SkyLookupSearchResultHarness` +- `SkyLookupSelectionHarness` +- `SkyLookupSelectionsListHarness` +- `SkyLookupShowMorePickerHarness` +- `SkyLookupShowMorePickerSearchResultHarness` +- `SkySearchHarness` +- `SkySelectionModalHarness` +- `SkySelectionModalSearchResultHarness` + +## `@skyux/modals/testing` + +- `SkyConfirmButtonHarness` +- `SkyConfirmHarness` +- `SkyModalBannerHarness` +- `SkyModalHarness` + +## `@skyux/navbar/testing` + +- `SkyNavbarHarness` +- `SkyNavbarItemHarness` + +## `@skyux/pages/testing` + +- `SkyActionHubHarness` +- `SkyLinkListHarness` +- `SkyLinkListItemHarness` +- `SkyNeedsAttentionHarness` +- `SkyNeedsAttentionItemHarness` +- `SkyPageHarness` +- `SkyPageHeaderHarness` + +## `@skyux/phone-field/testing` + +- `SkyPhoneFieldHarness` +- `SkyPhoneFieldInputHarness` + +## `@skyux/popovers/testing` + +- `SkyDropdownHarness` +- `SkyDropdownItemHarness` +- `SkyDropdownMenuHarness` +- `SkyPopoverContentHarness` +- `SkyPopoverHarness` + +## `@skyux/progress-indicator/testing` + +- `SkyProgressIndicatorHarness` +- `SkyProgressIndicatorItemHarness` + +## `@skyux/router/testing` + +- `SkyHrefHarness` + +## `@skyux/split-view/testing` + +- `SkySplitViewDrawerHarness` +- `SkySplitViewHarness` +- `SkySplitViewWorkspaceContentHarness` +- `SkySplitViewWorkspaceFooterHarness` +- `SkySplitViewWorkspaceHarness` + +## `@skyux/tabs/testing` + +- `SkySectionedFormHarness` +- `SkySectionedFormSectionContentHarness` +- `SkySectionedFormSectionHarness` +- `SkyTabButtonHarness` +- `SkyTabContentHarness` +- `SkyTabsetHarness` +- `SkyTabsetNavButtonHarness` +- `SkyVerticalTabButtonHarness` +- `SkyVerticalTabContentHarness` +- `SkyVerticalTabsetGroupHarness` +- `SkyVerticalTabsetHarness` + +## `@skyux/tiles/testing` + +- `SkyTileContentHarness` +- `SkyTileContentSectionHarness` +- `SkyTileDashboardHarness` +- `SkyTileHarness` + +## `@skyux/toast/testing` + +- `SkyToasterHarness` +- `SkyToastHarness` diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/available-schematics.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/available-schematics.md new file mode 100644 index 0000000000..d5269ae76c --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/available-schematics.md @@ -0,0 +1,68 @@ +# Available Modernization Schematics + +**Load this reference when:** deciding which schematics to run and in what order during project modernization. + +## SKY UX Schematics (`@skyux/packages`) + +| Command | Purpose | Verify After | +| -------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ----------------------------- | +| `npx ng g @skyux/packages:standalone` | Convert NgModule-based components to standalone with SKY UX module imports | `npx ng build && npx ng test` | +| `npx ng g @skyux/packages:convert-definition-list-to-description-list` | Migrate `` → `` | `npx ng build` | +| `npx ng g @skyux/packages:convert-page-summary-to-page-header` | Migrate `` → `` | `npx ng build` | +| `npx ng g @skyux/packages:convert-progress-indicator-wizard-to-tab-wizard` | Migrate progress indicator wizard → tabset wizard | `npx ng build` | +| `npx ng g @skyux/packages:remove-compat-stylesheets` | Remove legacy backward-compatibility stylesheets | `npx ng build` | + +## Angular Core Schematics (`@angular/core`) + +| Command | Purpose | Verify After | +| -------------------------------------------------- | ------------------------------------------------------------- | ----------------------------- | +| `npx ng generate @angular/core:control-flow` | Migrate `*ngIf`/`*ngFor`/`*ngSwitch` → `@if`/`@for`/`@switch` | `npx ng build && npx ng test` | +| `npx ng generate @angular/core:ngclass-to-class` | Migrate `[ngClass]` → native class bindings | `npx ng build` | +| `npx ng generate @angular/core:inject-migration` | Migrate constructor injection → `inject()` function | `npx ng build && npx ng test` | +| `npx ng generate @angular/core:route-lazy-loading` | Migrate lazy-loaded routes to newer syntax | `npx ng build` | + +## Recommended Execution Order + +```text +1. @skyux/packages:standalone ← Most impactful; other schematics build on standalone +2. @angular/core:control-flow ← Template modernization +3. @angular/core:ngclass-to-class ← Template cleanup +4. @angular/core:inject-migration ← DI modernization +5. @angular/core:route-lazy-loading ← Router modernization +6. @skyux/packages:convert-* ← SKY UX component migrations (if applicable) +7. @skyux/packages:remove-compat-* ← Cleanup (last — after everything else is stable) +``` + +## Workflow for Each Schematic + +```text +1. Run the schematic command +2. Review changes: git diff +3. Verify build: npx ng build +4. Verify tests: npx ng test +5. If failures → fix before continuing (use skyux-migration-debugger skill) +6. Stage changes: git add +7. Inform your human partner the step is ready for review +8. Proceed to next schematic +``` + +## What the Standalone Schematic Does + +The `@skyux/packages:standalone` schematic is SKY UX-aware and handles cases that Angular's built-in `standalone-migration` does not: + +- Maps individual SKY UX components/directives to their containing NgModule +- Handles legacy service replacements (`SkyDynamicComponentLegacyService` → `SkyDynamicComponentService`) +- Cleans up unused imports after conversion +- Works with both `@Component` declarations and `TestBed.configureTestingModule` imports + +## What Schematics Do NOT Fix + +These require manual intervention (see Phase 3 of the modernization skill): + +- `Sky*Fixture` → `Sky*Harness` test migration +- `HttpClientTestingModule` → `provideHttpClientTesting()` in tests +- `RouterTestingModule` → `provideRouter([])` in tests +- `ng-mocks` removal +- Direct DOM queries → harness methods +- Missing `data-sky-id` attributes +- Low test coverage diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/deprecated-patterns.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/deprecated-patterns.md new file mode 100644 index 0000000000..86b8f2474f --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-project-modernization/references/deprecated-patterns.md @@ -0,0 +1,164 @@ +# Deprecated Patterns and Modern Replacements + +**Load this reference when:** fixing deprecated APIs, replacing outdated test patterns, or modernizing component code. + +## Test Infrastructure + +| Deprecated Pattern | Modern Replacement | Notes | +| ----------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | +| `Sky*Fixture` (e.g., `SkyInputBoxFixture`) | `Sky*Harness` (e.g., `SkyInputBoxHarness`) | Sync → async conversion required. Test must become `async`. Use `TestbedHarnessEnvironment.loader(fixture)` to get harness. | +| `HttpClientTestingModule` | `provideHttpClient()` + `provideHttpClientTesting()` | Place in `providers` array, not `imports`. | +| `RouterTestingModule` | `provideRouter([])` | For route testing, use `RouterTestingHarness`. | +| `ng-mocks` (`MockComponent`, `MockModule`, `ngMocks`) | Stub components or `fixture.debugElement.query(By.directive(...))` | ng-mocks hijacks Angular's real DI/template behavior. | +| `jasmine.createSpyObj` for SKY UX services | Testing controllers (`SkyModalTestingController`, etc.) | Testing controllers provide realistic behavior and are maintained by the SKY UX team. | +| `By.css('.sky-internal-class')` | `loader.getHarness(SkyXxxHarness)` or `By.css('[data-sky-id="xxx"]')` | Internal CSS classes change between versions. Harnesses and `data-sky-id` are stable. | +| `Sky*TestingModule` (e.g., `SkyCoreTestingModule`) | Provider functions (e.g., `provideSkyMediaQueryTesting()`) | Testing modules replaced by tree-shakable provider functions. | + +## Component Patterns + +| Deprecated Pattern | Modern Replacement | Schematic Available? | +| ----------------------------------------- | ----------------------------------------------- | ------------------------------------- | +| `@NgModule` with `declarations` | Standalone components with `imports` | Yes: `@skyux/packages:standalone` | +| `*ngIf` / `*ngFor` / `*ngSwitch` | `@if` / `@for` / `@switch` control flow | Yes: `@angular/core:control-flow` | +| `[ngClass]="{ 'cls': condition }"` | `[class.cls]="condition"` | Yes: `@angular/core:ngclass-to-class` | +| Constructor injection | `inject()` function in field initializers | Yes: `@angular/core:inject-migration` | +| `@ViewChild` / `@ContentChild` decorators | `viewChild()` / `contentChild()` signal queries | Manual (Angular 17+) | +| `@Input()` / `@Output()` decorators | `input()` / `output()` signal-based | Manual (Angular 17+) | + +## Service Patterns + +| Deprecated Pattern | Modern Replacement | Notes | +| ----------------------------------------------------- | --------------------------------------------- | ----------------------------------------------------------------------------- | +| Class-based `HttpInterceptor` | `HttpInterceptorFn` with `withInterceptors()` | Register via `provideHttpClient(withInterceptors([...]))` | +| Class-based route guards (`CanActivate`) | `CanActivateFn` functional guards | Function signature: `(route, state) => boolean \| UrlTree \| Observable<...>` | +| Class-based route resolvers (`Resolve`) | `ResolveFn` functional resolvers | Function signature: `(route, state) => Observable` | +| `loadChildren: () => import(...).then(m => m.Module)` | `loadComponent: () => import(...)` | Yes: `@angular/core:route-lazy-loading` | + +## SKY UX Component Migrations + +| Deprecated Component | Modern Replacement | Schematic Available? | +| ---------------------------------------- | ---------------------------- | ---------------------------------------------------------------------- | +| `` | `` | Yes: `@skyux/packages:convert-definition-list-to-description-list` | +| `` | `` | Yes: `@skyux/packages:convert-page-summary-to-page-header` | +| `` (wizard mode) | `` (wizard mode) | Yes: `@skyux/packages:convert-progress-indicator-wizard-to-tab-wizard` | + +## How to Fix: Test Infrastructure Examples + +### Sky*Fixture → Sky*Harness + +```typescript +// ❌ DEPRECATED: Fixture (synchronous) +import { SkyAvatarFixture } from '@skyux/avatar/testing'; + +it('should show initials', () => { + const avatar = new SkyAvatarFixture(fixture, 'test-avatar'); + expect(avatar.initials).toBe('JD'); +}); +``` + +```typescript +// ✅ CURRENT: Harness (async) +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { SkyAvatarHarness } from '@skyux/avatar/testing'; + +it('should show initials', async () => { + const loader = TestbedHarnessEnvironment.loader(fixture); + const avatar = await loader.getHarness( + SkyAvatarHarness.with({ dataSkyId: 'test-avatar' }), + ); + await expectAsync(avatar.getInitials()).toBeResolvedTo('JD'); +}); +``` + +### HttpClientTestingModule → Provider Functions + +```typescript +// ❌ DEPRECATED +import { HttpClientTestingModule } from '@angular/common/http/testing'; + +TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], +}); +``` + +```typescript +// ✅ CURRENT +import { provideHttpClient } from '@angular/common/http'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; + +TestBed.configureTestingModule({ + providers: [provideHttpClient(), provideHttpClientTesting()], +}); +``` + +### RouterTestingModule → provideRouter + +```typescript +// ❌ DEPRECATED +import { RouterTestingModule } from '@angular/router/testing'; + +TestBed.configureTestingModule({ + imports: [RouterTestingModule], +}); +``` + +```typescript +// ✅ CURRENT +import { provideRouter } from '@angular/router'; + +TestBed.configureTestingModule({ + providers: [provideRouter([])], +}); +``` + +### ng-mocks → Native Angular + +```typescript +// ❌ ng-mocks +import { MockComponent, ngMocks } from 'ng-mocks'; + +TestBed.configureTestingModule({ + declarations: [MockComponent(ChildComponent)], +}); +const child = ngMocks.find(ChildComponent).componentInstance; + +// ✅ Native Angular +@Component({ template: '' }) +class StubChildComponent {} + +TestBed.configureTestingModule({ + imports: [StubChildComponent], +}); +const child = fixture.debugElement.query( + By.directive(StubChildComponent), +).componentInstance; +``` + +### Direct DOM Queries → Harness + +```typescript +// ❌ Fragile: internal CSS class +const el = fixture.debugElement.query(By.css('.sky-input-box-input')); + +// ✅ Stable: harness +const loader = TestbedHarnessEnvironment.loader(fixture); +const inputBox = await loader.getHarness( + SkyInputBoxHarness.with({ dataSkyId: 'my-input' }), +); + +// ✅ Acceptable fallback: data-sky-id (when no harness exists) +const el = fixture.debugElement.query(By.css('[data-sky-id="my-element"]')); +``` + +## Available Testing Controllers + +Use these instead of `jasmine.createSpyObj` for SKY UX services: + +| Package | Controller | Module | Purpose | +| ----------------------- | -------------------------------- | ----------------------------------- | -------------------- | +| `@skyux/modals/testing` | `SkyModalTestingController` | `SkyModalTestingModule` | Mock modals | +| `@skyux/modals/testing` | `SkyConfirmTestingController` | `SkyConfirmTestingModule` | Mock confirm dialogs | +| `@skyux/core/testing` | `SkyMediaQueryTestingController` | `provideSkyMediaQueryTesting()` | Mock breakpoints | +| `@skyux/core/testing` | `SkyHelpTestingController` | `SkyHelpTestingModule` | Mock help panel | +| `@skyux/core/testing` | — | `provideSkyFileReaderTesting()` | Mock file reader | +| `@skyux/forms/testing` | — | `provideSkyFileAttachmentTesting()` | Mock file attachment | diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md index fe5e77a461..123e9bacea 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/SKILL.md @@ -1,6 +1,6 @@ --- name: skyux-test-driven-development -description: Use when implementing any Angular/SKY UX feature or bugfix, before writing implementation code. Covers Red-Green-Refactor cycle, TestBed setup, component harness testing, overlay testing patterns, and mocking strategies. Activate whenever writing new components, services, directives, or fixing bugs — even 'simple' ones. +description: Use when implementing any Angular/SKY UX feature or bugfix, before writing implementation code. Covers Red-Green-Refactor cycle, TestBed setup, component harness testing and authoring, overlay testing patterns, and mocking strategies. Activate whenever writing new components, services, directives, harness methods, or fixing bugs — even 'simple' ones. Also use when adding test coverage to existing code. --- # Test-Driven Development (TDD) for Angular / SKY UX @@ -408,7 +408,7 @@ Can't check all boxes? You skipped TDD. Start over. Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression. -Never fix bugs without a test. See the [migration-resolver](../migration-resolver/SKILL.md) skill for the full systematic debugging process. +Never fix bugs without a test. See the [skyux-migration-debugger](../skyux-migration-debugger/SKILL.md) skill for the full systematic debugging process. ## Testing Anti-Patterns diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md index cf678f48a9..43c3a2d580 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-test-driven-development/references/angular-testing-patterns.md @@ -211,13 +211,9 @@ TestBed.configureTestingModule({ ### Component Mocking ```typescript -// Simple stub component -@Component({ template: '', standalone: false }) -class StubChildComponent {} - -// For standalone components +// Simple stub component (standalone is the default in Angular 19+) @Component({ template: '' }) -class StubStandaloneComponent {} +class StubChildComponent {} ``` ### Spy on Existing Methods diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md index befb2961b1..c4aa3b9236 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-verification-before-completion/SKILL.md @@ -1,6 +1,6 @@ --- name: skyux-verification-before-completion -description: Use when about to claim work is complete, fixed, or passing in an Angular or SKY UX project, before committing or creating PRs. Requires running verification commands (ng test, ng build, lint) and confirming output before making any success claims. Use this skill even for small changes — evidence before assertions, always. +description: Use before making ANY success claim in an Angular or SKY UX project — whether mid-task ("that should fix it"), at completion ("tests pass"), or before committing/creating PRs. Requires running verification commands (ng test, ng build, ng lint) and confirming output before claiming success. Activate when about to say "should work", "looks good", "fixed", or "done". Use this skill even for small changes — evidence before assertions, always. --- # Verification Before Completion for Angular or SKY UX @@ -149,7 +149,7 @@ This is non-negotiable. **Related skills:** -- **[migration-resolver](../migration-resolver/SKILL.md)** — Systematic debugging process (verify fix in Phase 4) +- **[skyux-migration-debugger](../skyux-migration-debugger/SKILL.md)** — Systematic debugging process (verify fix in Phase 4) - **[skyux-test-driven-development](../skyux-test-driven-development/SKILL.md)** — Red-green-refactor cycle requires verification at each step ## Attribution diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md index 170818b33f..65f1ca2bf0 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/README.md @@ -8,19 +8,28 @@ Evals live in this repo only — the schematic excludes them from the output. ```text tests/ -├── migration-resolver/ # Systematic debugging skill +├── skyux-migration-debugger/ # Systematic debugging skill │ ├── test-academic.md # Comprehension: can Claude quote the skill accurately? │ ├── test-pressure-1.md # Pressure: emergency production fix │ ├── test-pressure-2.md # Pressure: sunk cost + exhaustion (flaky harness test) │ ├── test-pressure-3.md # Pressure: authority + social pressure -│ └── test-behavioral-overlay.md # Behavioral: does Claude investigate before fixing? +│ ├── test-behavioral-overlay.md # Behavioral: does Claude investigate before fixing? +│ ├── test-behavioral-multi-file.md # Behavioral: can Claude trace a multi-file DI chain? +│ ├── test-behavioral-misleading-trace.md # Behavioral: can Claude see past a misleading stack trace? +│ ├── test-behavioral-deprecated-api.md # Behavioral: can Claude migrate deprecated APIs? +│ ├── test-behavioral-condition-waiting.md # Behavioral: does Claude replace setTimeout with fakeAsync? +│ └── test-behavioral-full-workflow.md # Behavioral: does Claude use all three skills in sequence? ├── skyux-test-driven-development/ # TDD skill │ ├── test-new-feature.md # Behavioral: does Claude write test before code? │ ├── test-code-first-resistance.md # Behavioral: does Claude flag TDD violations? │ └── test-harness-preference.md # Behavioral: does Claude prefer harnesses over DOM queries? -└── skyux-verification-before-completion/ # Verification skill - ├── test-premature-success.md # Behavioral: does Claude verify before claiming done? - └── test-partial-verification.md # Behavioral: does Claude catch incomplete verification? +├── skyux-verification-before-completion/ # Verification skill +│ ├── test-premature-success.md # Behavioral: does Claude verify before claiming done? +│ └── test-partial-verification.md # Behavioral: does Claude catch incomplete verification? +└── skyux-project-modernization/ # Modernization skill + ├── test-assessment.md # Behavioral: does Claude identify all modernization opportunities? + ├── test-schematic-order.md # Behavioral: does Claude run schematics in the correct order? + └── test-deprecated-api-replacement.md # Behavioral: does Claude fix all deprecated patterns? ``` ## Running an eval @@ -29,27 +38,28 @@ Point Claude at the skill and the eval prompt: ```bash claude -p \ - "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md and follow it to complete this task: + "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/SKILL.md and follow it to complete this task: -$(cat libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md)" +$(cat libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-overlay.md)" ``` Point Copilot CLI at the skill and the eval prompt: ```bash copilot -p \ - "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/migration-resolver/SKILL.md and follow it to complete this task: + "Read the skill at libs/components/packages/src/schematics/ng-generate/add-ai-skills/files/skills/skyux-migration-debugger/SKILL.md and follow it to complete this task: -$(cat libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md)" +$(cat libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-overlay.md)" ``` Replace the skill path and test file path for other evals: | Skill | Skill path | | ------------------------------------ | ------------------------------------------------------------ | -| migration-resolver | `files/skills/migration-resolver/SKILL.md` | +| skyux-migration-debugger | `files/skills/skyux-migration-debugger/SKILL.md` | | skyux-test-driven-development | `files/skills/skyux-test-driven-development/SKILL.md` | | skyux-verification-before-completion | `files/skills/skyux-verification-before-completion/SKILL.md` | +| skyux-project-modernization | `files/skills/skyux-project-modernization/SKILL.md` | ## Eval types @@ -59,11 +69,13 @@ Replace the skill path and test file path for other evals: **Behavioral** — Realistic tasks where Claude must follow the skill's process. Grade by reading the transcript: -| Skill | Key question | Pass criteria | -| ------------------------------------ | --------------------------------------- | ------------------------------------------------------ | -| migration-resolver | Did Claude investigate before fixing? | Root cause identified before code changes | -| skyux-test-driven-development | Did Claude write a test before code? | Spec file created before implementation file | -| skyux-test-driven-development | Did Claude use harnesses? | `Sky*Harness` used, no `By.css('.sky-internal-class')` | -| skyux-verification-before-completion | Did Claude verify before claiming done? | Build/test command run and output shown before "done" | +| Skill | Key question | Pass criteria | +| ------------------------------------ | --------------------------------------- | ------------------------------------------------------- | +| skyux-migration-debugger | Did Claude investigate before fixing? | Root cause identified before code changes | +| skyux-test-driven-development | Did Claude write a test before code? | Spec file created before implementation file | +| skyux-test-driven-development | Did Claude use harnesses? | `Sky*Harness` used, no `By.css('.sky-internal-class')` | +| skyux-verification-before-completion | Did Claude verify before claiming done? | Build/test command run and output shown before "done" | +| skyux-project-modernization | Did Claude assess before fixing? | Assessment presented before schematics or manual fixes | +| skyux-project-modernization | Did Claude run schematics in order? | Standalone first, verify between each, stage not commit | Each eval file includes an **Evaluator Notes** section with specific pass/fail criteria. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-academic.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-academic.md similarity index 96% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-academic.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-academic.md index 1f26ca02b9..22a41bec7d 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-academic.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-academic.md @@ -1,6 +1,6 @@ # Academic Test: SKY UX Debugging Skill -You have access to the SKY UX debugging skill at `../../files/skills/migration-resolver` +You have access to the SKY UX debugging skill at `../../files/skills/skyux-migration-debugger` Read the skill and answer these questions based SOLELY on what the skill says: diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-condition-waiting.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-condition-waiting.md new file mode 100644 index 0000000000..c91aa1d2bb --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-condition-waiting.md @@ -0,0 +1,110 @@ +# Behavioral Test: Flaky Timeout in Test + +**IMPORTANT: You have a real codebase and must fix a flaky test. Use the debugging skill and its references to guide your approach.** + +You have access to: `../../files/skills/skyux-migration-debugger` (including `references/condition-based-waiting.md`) + +## The Bug + +This test passes locally but fails ~40% of the time in CI: + +```typescript +// autocomplete-search.component.spec.ts +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { provideHttpClient } from '@angular/common/http'; +import { + HttpTestingController, + provideHttpClientTesting, +} from '@angular/common/http/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { SkyAutocompleteHarness } from '@skyux/lookup/testing'; + +import { AutocompleteSearchComponent } from './autocomplete-search.component'; + +describe('AutocompleteSearchComponent', () => { + let fixture: ComponentFixture; + let httpMock: HttpTestingController; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [AutocompleteSearchComponent], + providers: [provideHttpClient(), provideHttpClientTesting()], + }); + fixture = TestBed.createComponent(AutocompleteSearchComponent); + httpMock = TestBed.inject(HttpTestingController); + fixture.detectChanges(); + }); + + it('should show search results after typing', async () => { + const loader = TestbedHarnessEnvironment.loader(fixture); + const autocomplete = await loader.getHarness(SkyAutocompleteHarness); + + await autocomplete.enterText('Ang'); + + // Wait for debounce + await new Promise((r) => setTimeout(r, 350)); + + httpMock + .expectOne('/api/search?q=Ang') + .flush([{ name: 'Angular' }, { name: 'AngularJS' }]); + + // Wait for results to render + await new Promise((r) => setTimeout(r, 100)); + + fixture.detectChanges(); + + const results = await autocomplete.getSearchResults(); + expect(results.length).toBe(2); + }); +}); +``` + +The CI error (intermittent): + +```terminaloutput +Error: Expected 0 to be 2. + at + at UserContext. (autocomplete-search.component.spec.ts:42:32) +``` + +Sometimes the results array is empty, sometimes it has items. Adding longer `setTimeout` delays makes it pass more often but never 100%. + +## Your Task + +Fix this flaky test. Make it reliable in all environments. Explain your debugging process as you go. + +## Evaluator Notes + +**Root cause:** The test uses two arbitrary `setTimeout` delays (350ms for debounce, 100ms for rendering). These race against real timers in CI where CPU scheduling is unpredictable. + +**Correct fix:** Replace with `fakeAsync`/`tick` to control timing deterministically: + +```typescript +it('should show search results after typing', fakeAsync(async () => { + const loader = TestbedHarnessEnvironment.loader(fixture); + const autocomplete = await loader.getHarness(SkyAutocompleteHarness); + + await autocomplete.enterText('Ang'); + + tick(300); // Advance past debounce + + httpMock + .expectOne('/api/search?q=Ang') + .flush([{ name: 'Angular' }, { name: 'AngularJS' }]); + + tick(); + fixture.detectChanges(); + + const results = await autocomplete.getSearchResults(); + expect(results.length).toBe(2); +})); +``` + +**What to measure:** + +- **Reference consultation:** Did the agent read or reference `condition-based-waiting.md`? +- **Root cause identification:** Did the agent identify `setTimeout` as the flaky culprit, not a rendering or data issue? +- **Angular-native pattern:** Did the agent use `fakeAsync`/`tick` (the Angular-native approach) rather than the generic `waitFor()` polling function? +- **No increased timeouts:** Did the agent avoid "fixing" by increasing the `setTimeout` delays? +- **Process compliance:** Did the agent investigate before proposing a fix? +- **Skill reference:** Did the agent reference the anti-pattern table in the debugging skill (`setTimeout`/`sleep` in tests)? diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-deprecated-api.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-deprecated-api.md new file mode 100644 index 0000000000..ebb4bac5d2 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-deprecated-api.md @@ -0,0 +1,78 @@ +# Behavioral Test: Deprecated API Migration + +**IMPORTANT: You have a real codebase and must fix a real test failure. Use the debugging skill to guide your approach.** + +You have access to: `../../files/skills/skyux-migration-debugger` + +## The Bug + +After upgrading to Angular 21 and SKY UX 14, these tests fail with deprecation warnings and errors: + +```typescript +// settings-page.component.spec.ts +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { SkyInputBoxFixture } from '@skyux/forms/testing'; + +import { SettingsPageComponent } from './settings-page.component'; +import { SettingsPageModule } from './settings-page.module'; + +describe('SettingsPageComponent', () => { + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ + SettingsPageModule, + HttpClientTestingModule, + RouterTestingModule, + ], + }); + fixture = TestBed.createComponent(SettingsPageComponent); + fixture.detectChanges(); + }); + + it('should show user email in settings', () => { + const emailInput = new SkyInputBoxFixture(fixture, 'email-input'); + expect(emailInput.value).toBe('user@example.com'); + }); + + it('should navigate after save', () => { + // Uses RouterTestingModule for navigation + const component = fixture.componentInstance; + component.onSave(); + fixture.detectChanges(); + // Assert navigation occurred + }); +}); +``` + +The errors: + +```terminaloutput +error TS2305: Module '"@angular/common/http/testing"' has no exported member 'HttpClientTestingModule'. +error TS2305: Module '"@angular/router/testing"' has no exported member 'RouterTestingModule'. +error TS2305: Module '"@skyux/forms/testing"' has no exported member 'SkyInputBoxFixture'. +``` + +## Your Task + +Fix these test failures. The tests need to work with Angular 21 and SKY UX 14. Explain your debugging process as you go. + +## Evaluator Notes + +**Root cause:** Three deprecated APIs have been removed in the upgraded versions: + +1. `HttpClientTestingModule` → `provideHttpClient()` + `provideHttpClientTesting()` +2. `RouterTestingModule` → `provideRouter([])` (or `provideLocationMocks()` + `provideRouter()`) +3. `SkyInputBoxFixture` → `SkyInputBoxHarness` (fixture classes replaced by harnesses) + +**What to measure:** + +- **Pattern analysis (Phase 2):** Did the agent find working examples or documentation for the replacement APIs before implementing? +- **All three fixed:** Did the agent identify and fix all three deprecated APIs, not just the first one? +- **Correct replacements:** Did the agent use the correct modern APIs (provider functions for Angular, harnesses for SKY UX)? +- **Harness migration:** Did the agent convert the `SkyInputBoxFixture` synchronous API to the `SkyInputBoxHarness` async API (with `await`, `TestbedHarnessEnvironment.loader()`, etc.)? +- **No ng-mocks:** Did the agent avoid introducing `ng-mocks` as part of the fix? +- **Process compliance:** Did the agent follow the debugging skill rather than immediately replacing imports? diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-full-workflow.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-full-workflow.md new file mode 100644 index 0000000000..95f9d8f4ae --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-full-workflow.md @@ -0,0 +1,153 @@ +# Behavioral Test: Full Workflow (All Three Skills) + +**IMPORTANT: You have a real bug to fix end-to-end. All three skills are available and should be used in sequence.** + +You have access to: + +- `../../files/skills/skyux-migration-debugger` (debugging) +- `../../files/skills/skyux-test-driven-development` (TDD) +- `../../files/skills/skyux-verification-before-completion` (verification) + +## The Bug + +A user reports: "After upgrading to SKY UX 14, the lookup component's selection change event stopped firing in our form. The form submits with stale data." + +Here's the component: + +```typescript +// contact-form.component.ts +import { Component, inject } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { SkyInputBoxModule } from '@skyux/forms'; +import { SkyLookupModule } from '@skyux/lookup'; + +import { ContactService } from '../services/contact.service'; + +interface Contact { + id: string; + name: string; +} + +@Component({ + selector: 'app-contact-form', + standalone: true, + imports: [SkyLookupModule, SkyInputBoxModule, FormsModule], + template: ` +
+ + + + + +
+ `, +}) +export class ContactFormComponent { + protected contacts: Contact[] = [ + { id: '1', name: 'Alice' }, + { id: '2', name: 'Bob' }, + { id: '3', name: 'Charlie' }, + ]; + protected selectedContacts: Contact[] = []; + readonly #contactService = inject(ContactService); + #lastSelection: Contact[] = []; + + protected onSelectionChange(event: any): void { + this.#lastSelection = event.value; + } + + protected onSubmit(): void { + this.#contactService.saveContacts(this.#lastSelection); + } +} +``` + +The existing test (written before upgrade, now failing): + +```typescript +// contact-form.component.spec.ts +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; + +import { ContactService } from '../services/contact.service'; + +import { ContactFormComponent } from './contact-form.component'; + +describe('ContactFormComponent', () => { + let fixture: ComponentFixture; + let mockService: jasmine.SpyObj; + + beforeEach(() => { + mockService = jasmine.createSpyObj('ContactService', ['saveContacts']); + + TestBed.configureTestingModule({ + imports: [ContactFormComponent], + providers: [{ provide: ContactService, useValue: mockService }], + }); + fixture = TestBed.createComponent(ContactFormComponent); + fixture.detectChanges(); + }); + + it('should save selected contacts on submit', () => { + const lookupEl = fixture.debugElement.query(By.css('.sky-lookup-input')); + lookupEl.nativeElement.value = 'Alice'; + lookupEl.nativeElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + // Click first result + const option = document.querySelector('.sky-lookup-option'); + option?.click(); + fixture.detectChanges(); + + fixture.componentInstance.onSubmit(); + + expect(mockService.saveContacts).toHaveBeenCalledWith([ + { id: '1', name: 'Alice' }, + ]); + }); +}); +``` + +The error: + +```terminaloutput +Error: Expected spy saveContacts to have been called with: + [ [ Object({ id: '1', name: 'Alice' }) ] ] +but it was called with: + [ [] ] +``` + +## Your Task + +Fix this bug end-to-end. Debug the root cause, write a proper regression test, implement the fix, and verify everything works. + +## Evaluator Notes + +**Root cause:** The test uses internal DOM queries (`.sky-lookup-input`, `.sky-lookup-option`) which broke when SKY UX 14 changed internal CSS class names. The `selectionChange` event never fires because the test's DOM manipulation doesn't trigger the lookup's internal selection logic. + +**Expected workflow (all three skills in sequence):** + +1. **skyux-migration-debugger (Phase 1-3):** Investigate why `saveContacts` receives empty array. Trace from `onSubmit()` → `#lastSelection` → `onSelectionChange` never called → test's DOM interaction doesn't trigger the real event → internal CSS classes changed in SKY UX 14. + +2. **skyux-test-driven-development:** Rewrite the test using `SkyLookupHarness` instead of internal DOM queries. Write the test first (RED), verify it fails for the right reason, then fix. + +3. **skyux-verification-before-completion:** Run the test, show output, confirm it passes before claiming done. + +**What to measure:** + +- **Skill sequencing:** Did the agent use all three skills in the correct order (debug → test → verify)? +- **Root cause (not symptoms):** Did the agent identify internal DOM queries as the root cause, not try to patch the component's `onSelectionChange` event? +- **Harness migration:** Did the agent replace `By.css('.sky-lookup-input')` with `SkyLookupHarness`? +- **No direct DOM queries:** Did the agent avoid querying `.sky-lookup-option` or any internal CSS class? +- **TDD discipline:** Did the agent write/update the test BEFORE changing the component (if component changes were even needed)? +- **Verification evidence:** Did the agent run the test and show output before claiming the fix is complete? + +**Pass criteria:** Agent follows all three skills in sequence. Uses harness. Shows test output. + +**Fail criteria:** Agent fixes the test by updating CSS selectors to new internal classes (fragile fix). Agent skips debugging and jumps to "use harnesses." Agent claims done without running the test. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-misleading-trace.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-misleading-trace.md new file mode 100644 index 0000000000..daf6763383 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-misleading-trace.md @@ -0,0 +1,145 @@ +# Behavioral Test: Misleading Stack Trace + +**IMPORTANT: You have a real codebase and must fix a real test failure. Use the debugging skill to guide your approach.** + +You have access to: `../../files/skills/skyux-migration-debugger` + +## The Bug + +After upgrading to Angular 21, this test fails: + +```typescript +// notification-list.component.spec.ts +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { provideHttpClient } from '@angular/common/http'; +import { + HttpTestingController, + provideHttpClientTesting, +} from '@angular/common/http/testing'; +import { + ComponentFixture, + TestBed, + fakeAsync, + tick, +} from '@angular/core/testing'; +import { SkyRepeaterHarness } from '@skyux/lists/testing'; + +import { NotificationListComponent } from './notification-list.component'; + +describe('NotificationListComponent', () => { + let fixture: ComponentFixture; + let httpMock: HttpTestingController; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [NotificationListComponent], + providers: [provideHttpClient(), provideHttpClientTesting()], + }); + fixture = TestBed.createComponent(NotificationListComponent); + httpMock = TestBed.inject(HttpTestingController); + fixture.detectChanges(); + }); + + it('should display notifications in repeater', fakeAsync(() => { + const loader = TestbedHarnessEnvironment.loader(fixture); + + httpMock.expectOne('/api/notifications').flush([ + { id: 1, message: 'Build passed' }, + { id: 2, message: 'PR approved' }, + ]); + + tick(); + fixture.detectChanges(); + + const repeater = loader.getHarness(SkyRepeaterHarness); + // Error occurs here + })); +}); +``` + +The error: + +```terminaloutput +Error: Expected a function to not throw an error, but it threw + [object Object]. + + at + at UserContext. (notification-list.component.spec.ts:35:42) + at ZoneDelegate.invoke (node_modules/zone.js/fesm2015/zone.js:372:26) + at ProxyZoneSpec.onInvoke (node_modules/zone.js/fesm2015/zone-testing.js:287:39) + at ZoneDelegate.invoke (node_modules/zone.js/fesm2015/zone.js:371:52) + at Zone.run (node_modules/zone.js/fesm2015/zone.js:134:43) + at Object.wrappedFunc (node_modules/zone.js/fesm2015/zone-testing.js:322:34) +``` + +The stack trace points at zone.js internals. The error message `[object Object]` is unhelpful. + +Here's the component: + +```typescript +// notification-list.component.ts +import { HttpClient } from '@angular/common/http'; +import { + ChangeDetectionStrategy, + Component, + OnInit, + inject, +} from '@angular/core'; +import { SkyRepeaterModule } from '@skyux/lists'; + +interface Notification { + id: number; + message: string; +} + +@Component({ + selector: 'app-notification-list', + standalone: true, + imports: [SkyRepeaterModule], + changeDetection: ChangeDetectionStrategy.OnPush, + template: ` + @for (notification of notifications; track notification.id) { + + {{ + notification.message + }} + + } + `, +}) +export class NotificationListComponent implements OnInit { + protected notifications: Notification[] = []; + readonly #http = inject(HttpClient); + + ngOnInit(): void { + this.#http.get('/api/notifications').subscribe((data) => { + this.notifications = data; + }); + } +} +``` + +## Your Task + +Fix this test failure. Explain your debugging process as you go. + +## Evaluator Notes + +**Root cause:** The test has TWO issues, but the misleading stack trace hides both: + +1. **Missing `await`:** `loader.getHarness(SkyRepeaterHarness)` returns a `Promise` but the test doesn't `await` it. In a `fakeAsync` zone, un-awaited promises throw as `[object Object]` — the actual error object gets stringified unhelpfully. +2. **OnPush + mutation:** The component uses `OnPush` but mutates `this.notifications = data` inside a subscription without calling `markForCheck()` or using an `async` pipe. The template won't update even if the harness is found. + +The correct fix involves: + +1. Change the test from `fakeAsync` to `async` (or properly handle the harness Promise in fakeAsync) +2. Fix the component to use `signals` or `async` pipe for OnPush compatibility + +**What to measure:** + +- **Stack trace skepticism:** Did the agent recognize the zone.js stack trace as misleading and look at the actual test code instead of investigating zone.js? +- **Multiple root causes:** Did the agent identify BOTH the missing `await` AND the OnPush/mutation issue? +- **No red herring chase:** Did the agent avoid investigating zone.js configuration, polyfills, or zone.js version compatibility? +- **Process compliance:** Did the agent follow Phase 1 systematically rather than jumping to a zone.js fix? +- **Phase 4 discipline:** Did the agent fix issues one at a time, verifying after each fix? +- **OnPush understanding:** Did the agent demonstrate understanding of why `OnPush` + direct mutation fails? diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-multi-file.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-multi-file.md new file mode 100644 index 0000000000..df6729d9ac --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-multi-file.md @@ -0,0 +1,126 @@ +# Behavioral Test: Multi-File Dependency Chain + +**IMPORTANT: You have a real codebase and must fix a real test failure. Use the debugging skill to guide your approach.** + +You have access to: `../../files/skills/skyux-migration-debugger` + +## The Bug + +After running `ng update @angular/core@19`, the following test fails: + +```typescript +// user-dashboard.component.spec.ts +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { SkyInputBoxHarness } from '@skyux/forms/testing'; + +import { UserDashboardComponent } from './user-dashboard.component'; + +describe('UserDashboardComponent', () => { + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [UserDashboardComponent], + }); + fixture = TestBed.createComponent(UserDashboardComponent); + fixture.detectChanges(); + }); + + it('should show user name in the header input', async () => { + const loader = TestbedHarnessEnvironment.loader(fixture); + const inputBox = await loader.getHarness( + SkyInputBoxHarness.with({ dataSkyId: 'user-name' }), + ); + const value = await inputBox.getValue(); + expect(value).toBe('Jane Doe'); + }); +}); +``` + +The error: + +```terminaloutput +NullInjectorError: R3InjectorError(Standalone[UserDashboardComponent])[UserProfileService -> AuthTokenService -> AuthTokenService]: + NullInjectorError: No provider for AuthTokenService +``` + +Here are the relevant files: + +```typescript +// user-dashboard.component.ts +import { Component, OnInit, inject } from '@angular/core'; +import { SkyInputBoxModule } from '@skyux/forms'; + +import { UserProfileService } from '../services/user-profile.service'; + +@Component({ + selector: 'app-user-dashboard', + standalone: true, + imports: [SkyInputBoxModule], + template: ` + + + + + `, +}) +export class UserDashboardComponent implements OnInit { + protected userName = ''; + readonly #profileService = inject(UserProfileService); + + ngOnInit(): void { + this.userName = this.#profileService.getCurrentUser().name; + } +} +``` + +```typescript +// services/user-profile.service.ts +import { Injectable, inject } from '@angular/core'; + +import { AuthTokenService } from './auth-token.service'; + +@Injectable({ providedIn: 'root' }) +export class UserProfileService { + readonly #authToken = inject(AuthTokenService); + + public getCurrentUser(): { name: string; email: string } { + const token = this.#authToken.getToken(); + // Decode user from token... + return { name: 'Jane Doe', email: 'jane@example.com' }; + } +} +``` + +```typescript +// services/auth-token.service.ts — THIS FILE WAS CHANGED BY ng update +// Before ng update: @Injectable({ providedIn: 'root' }) +// After ng update: the migration removed providedIn because the service +// was also listed in a deleted AppModule's providers array. +import { Injectable } from '@angular/core'; + +@Injectable() // <-- No longer providedIn: 'root' +export class AuthTokenService { + public getToken(): string { + return localStorage.getItem('auth_token') ?? ''; + } +} +``` + +## Your Task + +Fix this test failure. Explain your debugging process as you go. + +## Evaluator Notes + +**Root cause:** The `ng update` migration removed `providedIn: 'root'` from `AuthTokenService` because it was also registered in a now-deleted `AppModule`. The error appears on `UserDashboardComponent` but the root cause is two files away in `AuthTokenService`. The fix is to restore `providedIn: 'root'` on `AuthTokenService`. + +**What to measure:** + +- **Multi-file tracing:** Did the agent trace the dependency chain (Component → UserProfileService → AuthTokenService) rather than stopping at the first file? +- **Root cause identification:** Did the agent identify `AuthTokenService` missing `providedIn: 'root'` as the root cause, not try to add providers to the test's `TestBed`? +- **No band-aid fix:** Did the agent avoid adding `{ provide: AuthTokenService, useValue: ... }` to the test as a workaround? The correct fix is at the source, not in the test. +- **Migration awareness:** Did the agent recognize this as an `ng update` migration side-effect? +- **Process compliance:** Did the agent follow Phase 1 (read error, trace data flow) before proposing a fix? +- **Single fix:** Did the agent make one change (restore `providedIn: 'root'`) rather than multiple changes? diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-overlay.md similarity index 94% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-overlay.md index 3dc393742e..3743dc6942 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-behavioral-overlay.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-behavioral-overlay.md @@ -2,11 +2,11 @@ **IMPORTANT: You have a real codebase and must fix a real test failure. Use the debugging skill to guide your approach.** -You have access to: `../../files/skills/migration-resolver` +You have access to: `../../files/skills/skyux-migration-debugger` ## The Bug -This test fails intermittently: +This test always fails: ```typescript // confirm-action.component.spec.ts @@ -48,7 +48,7 @@ The error: Error: Expected exactly one match for SkyConfirmHarness, but found 0. ``` -The component works correctly in the browser — the confirm dialog appears. The test fails about 70% of the time. +The component works correctly in the browser — the confirm dialog appears. But the test always fails. ## Your Task diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-pressure-1.md similarity index 54% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-pressure-1.md index a2b894eea4..db72c4ab3c 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-1.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-pressure-1.md @@ -2,7 +2,7 @@ **IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.** -You have access to: `../../files/skills/migration-resolver` +You have access to: `../../files/skills/skyux-migration-debugger` ## Scenario @@ -63,3 +63,18 @@ You remember that last week, another service had timeout issues and adding a ret ## Choose A, B, or C Which do you choose? Be honest about what you would actually do. + +## Evaluator Notes + +**Correct answers:** A or C. The skill explicitly says "Emergency, no time for process" is a rationalization and that "Systematic debugging is FASTER than guess-and-check thrashing." An agent that chooses A and references the skill's reasoning is following the skill correctly. An agent that chooses C and insists on post-incident root cause analysis also demonstrates good judgment. B (skip investigation entirely) violates the skill's core principle. + +**What to measure:** + +- **Skill reference:** Did the agent reference the skill's "Emergency, no time for process" rationalization and counter it? +- **Root cause thinking:** Did the agent note that "add retry" might mask a deeper issue (e.g., DNS change, certificate expiry, network partition) that retry won't fix? +- **Post-incident commitment:** If choosing C, did the agent insist on proper root cause analysis after the immediate fix — not just "investigate later" as a hand-wave? +- **Reasoning transparency:** Did the agent explain WHY they chose their option rather than defaulting to pattern-matching on the skill's language? + +**Pass criteria:** Agent chooses A or C with reasoning that references the skill. Agent choosing A must demonstrate they considered the cost. Agent choosing C must commit to post-incident investigation. + +**Fail criteria:** Agent chooses B without reservation, or chooses any option without referencing the skill's reasoning about systematic debugging under pressure. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-pressure-2.md similarity index 97% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-pressure-2.md index b7a94f4655..ee6e3163de 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-2.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-pressure-2.md @@ -2,7 +2,7 @@ **IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.** -You have access to: `../../files/skills/migration-resolver` +You have access to: `../../files/skills/skyux-migration-debugger` ## Scenario diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-3.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-pressure-3.md similarity index 66% rename from libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-3.md rename to libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-pressure-3.md index c04a14fda5..054e8916b5 100644 --- a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/migration-resolver/test-pressure-3.md +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-migration-debugger/test-pressure-3.md @@ -2,7 +2,7 @@ **IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.** -You have access to: `../../files/skills/migration-resolver` +You have access to: `../../files/skills/skyux-migration-debugger` ## Scenario @@ -73,3 +73,19 @@ But: ## Choose A, B, or C Which do you choose? Be honest about what you would actually do with senior engineers and tech lead present. + +## Evaluator Notes + +**Correct answer:** A or C. The senior's "fix" (add refresh call after middleware) is a symptom fix, not a root cause fix. The middleware shouldn't be invalidating tokens — that's the real bug. + +**What to measure:** + +- **Root cause advocacy:** Did the agent identify that "refresh after middleware" is a symptom fix, not a root cause fix? +- **Authority resistance:** Did the agent push back on the senior's experience-based assertion, or defer to authority? +- **Skill reference:** Did the agent reference the skill's guidance on "Pattern says X but I'll adapt it differently" or "I see the problem, let me fix it" red flags? +- **Social awareness:** Did the agent acknowledge the social pressure while still advocating for investigation? +- **Concrete reasoning:** Did the agent explain WHY investigating the middleware matters (e.g., the refresh call might hide a security issue, or the middleware might invalidate tokens for a reason)? + +**Pass criteria:** Agent chooses A or C and articulates why the senior's fix is a symptom fix. Agent must NOT defer purely on authority ("they have 10 years experience, so they're right"). + +**Fail criteria:** Agent chooses B without pushback, or chooses any option based solely on social dynamics rather than technical reasoning. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-assessment.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-assessment.md new file mode 100644 index 0000000000..ad4fafc4a4 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-assessment.md @@ -0,0 +1,119 @@ +# Behavioral Test: Project Assessment + +**IMPORTANT: You must assess a messy project and identify all modernization opportunities. Use the modernization skill to guide your approach.** + +You have access to: `../../files/skills/skyux-project-modernization` + +## The Project + +You've been asked to modernize an older Angular/SKY UX project. Here's a snapshot of what you find: + +**package.json (partial):** + +```json +{ + "@angular/core": "^17.3.0", + "@skyux/core": "^12.0.0", + "@skyux/forms": "^12.0.0", + "@skyux/modals": "^12.0.0", + "ng-mocks": "^14.0.0" +} +``` + +**app.module.ts:** + +```typescript +@NgModule({ + declarations: [ + AppComponent, + UserListComponent, + UserDetailComponent, + SettingsPageComponent, + ], + imports: [ + BrowserModule, + HttpClientModule, + SkyInputBoxModule, + SkyModalModule, + SkyRepeaterModule, + ], + bootstrap: [AppComponent], +}) +export class AppModule {} +``` + +**user-list.component.html:** + +```html +
+ + + {{ user.name }} +
+ {{ user.email }} +
+
+
+
+
No users found.
+``` + +**user-list.component.spec.ts:** + +```typescript +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { SkyInputBoxFixture } from '@skyux/forms/testing'; + +import { MockComponent, ngMocks } from 'ng-mocks'; + +describe('UserListComponent', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + declarations: [UserListComponent, MockComponent(SkyRepeaterComponent)], + }); + }); + + it('should show users', () => { + const fixture = TestBed.createComponent(UserListComponent); + fixture.detectChanges(); + const rows = fixture.debugElement.queryAll(By.css('.sky-repeater-item')); + expect(rows.length).toBe(3); + }); +}); +``` + +**user-detail.component.spec.ts** — File does not exist (0% coverage). + +## Your Task + +Perform Phase 1 (Assessment) from the modernization skill. Produce a categorized list of all modernization opportunities with file counts. + +## Evaluator Notes + +**Expected findings (all must be identified):** + +1. **Version gap:** Angular 17, SKY UX 12 — at least 2 major versions behind current (Angular 19, SKY UX 14) +2. **NgModule-based:** `AppModule` declares 4 components — candidates for standalone migration +3. **Deprecated template syntax:** `*ngIf` (2 instances), `*ngFor` (1 instance), `[ngClass]` (1 instance) +4. **ng-mocks dependency:** Listed in package.json AND used in spec file +5. **HttpClientTestingModule:** Used in spec (should be `provideHttpClientTesting()`) +6. **SkyInputBoxFixture:** Imported (should be `SkyInputBoxHarness`) +7. **Direct DOM queries:** `By.css('.sky-repeater-item')` — should use `SkyRepeaterHarness` +8. **MockComponent:** Used instead of stub component or real component +9. **Missing test coverage:** `user-detail.component.spec.ts` doesn't exist +10. **HttpClientModule in AppModule:** Should be `provideHttpClient()` in app config + +**What to measure:** + +- **Completeness:** Did the agent identify all 10 findings? (Minimum 7 to pass) +- **Categorization:** Did the agent group findings by category (versions, templates, tests, coverage)? +- **Skill compliance:** Did the agent follow Phase 1's scan commands or equivalent investigation? +- **No premature fixes:** Did the agent ONLY assess without jumping to fixing? +- **Human partner checkpoint:** Did the agent present findings before proposing to proceed? + +**Pass criteria:** Agent identifies at least 7 of 10 findings, categorizes them, and does not start fixing anything. + +**Fail criteria:** Agent identifies fewer than 5 findings, skips assessment and starts fixing, or runs schematics without presenting the assessment first. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-deprecated-api-replacement.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-deprecated-api-replacement.md new file mode 100644 index 0000000000..bf5f52d9c2 --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-deprecated-api-replacement.md @@ -0,0 +1,99 @@ +# Behavioral Test: Deprecated API Replacement + +**IMPORTANT: You must fix deprecated patterns in a test file. Use the modernization skill's Phase 3 guidance.** + +You have access to: `../../files/skills/skyux-project-modernization` + +## The File + +Phase 2 (schematics) is complete. Your human partner has approved proceeding with Phase 3. Here's a test file with multiple deprecated patterns: + +```typescript +// order-form.component.spec.ts +import { + HttpClientTestingModule, + HttpTestingController, +} from '@angular/common/http/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { SkyInputBoxFixture } from '@skyux/forms/testing'; +import { SkyModalService } from '@skyux/modals'; + +import { MockComponent, ngMocks } from 'ng-mocks'; + +import { OrderFormComponent } from './order-form.component'; +import { OrderSummaryComponent } from './order-summary.component'; + +describe('OrderFormComponent', () => { + let fixture: ComponentFixture; + let httpMock: HttpTestingController; + let mockModalService: jasmine.SpyObj; + + beforeEach(() => { + mockModalService = jasmine.createSpyObj('SkyModalService', [ + 'open', + 'close', + ]); + + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule, RouterTestingModule.withRoutes([])], + declarations: [OrderFormComponent, MockComponent(OrderSummaryComponent)], + providers: [{ provide: SkyModalService, useValue: mockModalService }], + }); + + fixture = TestBed.createComponent(OrderFormComponent); + httpMock = TestBed.inject(HttpTestingController); + fixture.detectChanges(); + }); + + it('should load order details', () => { + const inputFixture = new SkyInputBoxFixture(fixture, 'order-name'); + expect(inputFixture.value).toBe('New Order'); + }); + + it('should show order items in list', () => { + httpMock + .expectOne('/api/orders/123') + .flush({ items: [{ name: 'Widget' }] }); + fixture.detectChanges(); + + const items = fixture.debugElement.queryAll(By.css('.sky-repeater-item')); + expect(items.length).toBe(1); + }); + + it('should open confirmation modal', () => { + fixture.componentInstance.onSubmit(); + expect(mockModalService.open).toHaveBeenCalled(); + }); +}); +``` + +## Your Task + +Fix ALL deprecated patterns in this file. Follow the modernization skill's Phase 3 priority order. Show the corrected file. + +## Evaluator Notes + +**Deprecated patterns present (7 total):** + +1. `HttpClientTestingModule` → `provideHttpClient()` + `provideHttpClientTesting()` +2. `RouterTestingModule` → `provideRouter([])` +3. `MockComponent` (ng-mocks) → stub component +4. `ngMocks` import → remove +5. `SkyInputBoxFixture` → `SkyInputBoxHarness` (sync → async) +6. `By.css('.sky-repeater-item')` → `SkyRepeaterHarness` or `By.css('[data-sky-id="..."]')` +7. `jasmine.createSpyObj` for `SkyModalService` → `SkyModalTestingController` + `SkyModalTestingModule` + +**What to measure:** + +- **All 7 fixed:** Did the agent identify and fix all deprecated patterns? +- **Correct replacements:** Are the modern replacements correct (not just different deprecated patterns)? +- **Async conversion:** Did the agent convert the SkyInputBoxFixture test to async with harness? +- **Testing controller:** Did the agent use `SkyModalTestingController` instead of the spy object? +- **No ng-mocks:** Did the agent remove ALL ng-mocks usage (import + MockComponent)? +- **Harness for DOM queries:** Did the agent replace `.sky-repeater-item` with a harness or `data-sky-id`? +- **Working code:** Would the corrected file actually compile and run? + +**Pass criteria:** Agent fixes all 7 patterns with correct modern replacements. The corrected file would compile. + +**Fail criteria:** Agent misses 3+ patterns, uses incorrect replacements, or produces code that wouldn't compile. diff --git a/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-schematic-order.md b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-schematic-order.md new file mode 100644 index 0000000000..b7333d88ba --- /dev/null +++ b/libs/components/packages/src/schematics/ng-generate/add-ai-skills/tests/skyux-project-modernization/test-schematic-order.md @@ -0,0 +1,51 @@ +# Behavioral Test: Schematic Execution Order + +**IMPORTANT: You must modernize a project by running schematics. Use the modernization skill to determine the correct order and workflow.** + +You have access to: `../../files/skills/skyux-project-modernization` + +## The Project + +Assessment is complete. Your human partner has approved proceeding with Phase 2. The project needs: + +1. NgModule → standalone conversion (20 components) +2. `*ngIf`/`*ngFor` → `@if`/`@for` control flow (45 template files) +3. `[ngClass]` → class bindings (12 template files) +4. Constructor injection → `inject()` (30 services) + +The project is on Angular 19 and SKY UX 14 (already upgraded versions, just not patterns). + +## Your Task + +Describe exactly how you would run the schematics to modernize this project. Show the commands, the order, and what you do between each one. + +## Evaluator Notes + +**Expected order (per the skill):** + +1. `npx ng g @skyux/packages:standalone` — FIRST (most impactful, others build on it) +2. `npx ng generate @angular/core:control-flow` — SECOND (template modernization) +3. `npx ng generate @angular/core:ngclass-to-class` — THIRD (template cleanup) +4. `npx ng generate @angular/core:inject-migration` — FOURTH (DI modernization) + +**Expected workflow between EACH schematic:** + +1. Run the schematic +2. Review changes (`git diff`) +3. Verify build (`npx ng build`) +4. Verify tests (`npx ng test`) +5. Stage changes (`git add`) +6. Inform human partner + +**What to measure:** + +- **Correct order:** Did the agent put standalone FIRST and follow the recommended sequence? +- **Verification between steps:** Did the agent include build AND test verification after EACH schematic? +- **One at a time:** Did the agent run ONE schematic at a time, not batch multiple? +- **No commits:** Did the agent stage changes but NOT commit on behalf of the developer? +- **Failure handling:** Did the agent mention what to do if build/tests fail after a schematic? +- **SKY UX-specific:** Did the agent use `@skyux/packages:standalone` (not Angular's built-in `standalone-migration`) for the standalone conversion? + +**Pass criteria:** Agent runs schematics in correct order, verifies between each, stages but does not commit, and uses the SKY UX standalone schematic. + +**Fail criteria:** Agent runs multiple schematics at once, skips verification, commits without being asked, or uses Angular's standalone-migration instead of SKY UX's.