Skip to content

feat: Add exec skill guidance for non-exportable function testing #300

Closed

Description

@admarble

Problem

When the exec agent encounters a private (non-exported) function that needs testing, it falls back to writing "documentation-style" tests — local variable assertions that mirror the logic but never call the real function. This produces tests that always pass but catch zero regressions.

Issue #267's executePhaseWithRetry was private, so the exec agent wrote tests like:

const mcpEnabled = true;
const phaseFailed = true;
expect(mcpEnabled && phaseFailed).toBe(true);

The fix was to export the function with @internal JSDoc and use dependency injection (executePhaseFn parameter) so tests could mock the inner dependency and call the real function.

Root cause

The exec skill has no guidance for this scenario. When a function can't be imported, the agent improvises — and the path of least resistance is tautological tests that make the test count look right.

Proposed Solution

Add guidance to the exec skill for handling non-exportable functions:

Decision tree for the exec agent

Function needs tests but is not exported?
├── Can it be exported with @internal tag? → Export it, test directly
├── Can a dependency be injected for mocking? → Add optional param, test with mock
├── Can the behavior be tested via a public caller? → Write integration test through the public API
└── None of the above? → Document why tests are limited, do NOT write tautological tests

Explicit anti-pattern warning

Add to exec skill:

NEVER write tests that only assert on local variables. If a test block does not call any imported function, it is tautological and provides no regression protection. If you cannot test a function directly, escalate to integration testing or export with @internal — do not fake the test.

Pattern library

Provide examples of each approach:

  1. Export with @internal:
/** @internal Exported for testing */
export function privateHelper(...) { ... }
  1. Dependency injection:
export function retry(
  ...,
  executeFn = executePhase,  // injectable for tests
) { ... }
  1. Integration test through public API:
it("retries on cold-start failure", async () => {
  // Test via runCommand() which internally calls executePhaseWithRetry
  const result = await runCommand({ ... });
  expect(result.exitCode).toBe(0);
});

Acceptance Criteria

  • AC-1: Exec skill includes decision tree for testing non-exported functions
  • AC-2: Exec skill explicitly warns against tautological tests (local-variable-only assertions)
  • AC-3: Exec skill provides code examples for @internal export, dependency injection, and integration testing patterns
  • AC-4: If exec agent cannot test a function directly, it must document the limitation rather than writing fake tests

Context

Activity

  1. added
    enhancement
    spec
    on Feb 19, 2026
  2. admarble commented on Feb 20, 2026

    @admarble
    ContributorAuthor

    📋 Spec Plan for Issue #300

    AC Quality Check

    ✅ All 4 acceptance criteria are clear and testable.


    Scope Assessment

    Metric Value Status
    Feature count 1 ✅
    AC items 4 ✅
    Directory spread 1 ✅

    Verdict: ⚠️ SCOPE_WARNING - Non-Goals section missing. Quality loop auto-enabled.

    Suggested Non-Goals:


    Acceptance Criteria with Verification

    AC Description Verification Method
    AC-1 Decision tree for testing non-exported functions Manual Test: Verify ASCII/markdown diagram with 4 paths
    AC-2 Warning against tautological tests Manual Test: Verify bold warning block present
    AC-3 Code examples for @internal, DI, integration patterns Manual Test: Verify 3 TypeScript examples
    AC-4 Document limitation rather than fake tests Manual Test: Verify documentation fallback guidance

    Implementation Plan

    File to modify: .claude/skills/exec/skill.md

    Phase 1: Add New Section

    1. Add ### 3e. Testing Non-Exported Functions (REQUIRED) after section 3d (Lint Check)

    Phase 2: Content
    2. Decision tree (AC-1):

    Function needs tests but is not exported?
    ├── Can export with @internal? → Export it, test directly
    ├── Can inject dependency? → Add optional param, test with mock
    ├── Can test via public caller? → Write integration test
    └── None of the above? → Document limitation, do NOT write fake tests
    
    1. Anti-pattern warning (AC-2): Bold callout with example from fix: sequant run fails on first execution, succeeds on retry (cold-start race) #267

    2. Pattern library (AC-3): Three TypeScript examples

      • @internal export
      • Dependency injection with default parameter
      • Integration test via public API
    3. Documentation fallback (AC-4): Template for limitation docs

    Phase 3: Integration
    6. Cross-reference from existing test sections
    7. Verify lint passes


    Recommended Workflow

    Phases: exec → qa
    Quality Loop: enabled (auto-enabled due to scope warning)


    Assumptions to Validate

    • Section 3e numbering is appropriate (after 3d Lint Check)
    • Code examples should use TypeScript (consistent with codebase)
    • No need to update other skills (QA, spec) as part of this issue

    Implementation Readiness

    Status: ✅ READY

    • Clear AC with testable verification criteria
    • Single file change (.claude/skills/exec/skill.md)
    • No dependencies on other issues
    • No blockers identified

    Worktree: Already created at feature/300-feat-add-exec-skill-guidance-for-non-exportable-fu

  3. added
    planned
    on Feb 20, 2026
  4. added a commit that references this issue on Feb 20, 2026
  5. admarble commented on Feb 20, 2026

    @admarble
    ContributorAuthor

    🚀 Exec Phase Complete

    AC Coverage Summary

    AC Description Status Evidence
    AC-1 Decision tree for testing non-exported functions ✅ Implemented Section 3e with ASCII decision tree showing 4 paths
    AC-2 Warning against tautological tests ✅ Implemented Bold callout with bad example from #267
    AC-3 Code examples for @internal, DI, integration patterns ✅ Implemented 3 TypeScript examples with tests
    AC-4 Document limitation rather than fake tests ✅ Implemented Pattern 4 with 4 requirements checklist

    Files Changed

    • .claude/skills/exec/SKILL.md - Added section 3e "Testing Non-Exported Functions (REQUIRED)" (+146 lines)

    Quality Checks

    Check Status
    npm run build ✅ Passed
    npm run lint ✅ Passed
    npm test ✅ 1334 tests passed

    Quality Plan Alignment

    N/A - No quality plan in issue (no /spec quality planning section found)

    Test Coverage Analysis

    Changed File Tier Has Tests?
    .claude/skills/exec/SKILL.md Optional - (docs only)

    Coverage: Documentation-only change; no code tests needed.

    PR Status

    ✅ Created: #312

    Next Steps

    • QA review via /qa to verify all AC are satisfied
    • Documentation change only - no runtime tests required
  6. admarble commented on Feb 20, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #300

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original Decision tree for testing non-exported functions ✅ MET ASCII decision tree with 4 paths present (lines 1078-1092)
    AC-2 Original Warning against tautological tests ✅ MET Bold warning block with bad example from #267 (lines 1094-1108)
    AC-3 Original Code examples for @internal, DI, integration patterns ✅ MET 4 TypeScript patterns with tests (Patterns 1-4, lines 1110-1216)
    AC-4 Original Document limitation rather than fake tests ✅ MET Pattern 4 with 4-item checklist for documentation requirements (lines 1212-1216)

    Coverage: 4/4 AC items fully met


    Quality Plan Verification

    N/A - No quality plan found in issue comments


    CI Status

    Check State Bucket Impact
    build (18.x) IN_PROGRESS pending ⏳ PENDING
    build (20.x) IN_PROGRESS pending ⏳ PENDING
    build (22.x) IN_PROGRESS pending ⏳ PENDING
    validate-skills SUCCESS pass ✅ MET
    typecheck SUCCESS pass ✅ MET
    validate-plugin SUCCESS pass ✅ MET

    CI Summary: 3 passed, 3 pending, 0 failed
    CI-related AC items: None (no CI-specific AC items in this issue)


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 ✅ OK
    Deleted tests 0 ✅ OK
    Files changed 1 ✅ OK
    Lines added +146 -
    Lines deleted -0 -

    Code Review

    Strengths:

    • Well-structured decision tree with 4 clear paths matching the issue spec exactly
    • Prominent anti-pattern warning with concrete bad example from fix: sequant run fails on first execution, succeeds on retry (cold-start race) #267 (the origin case)
    • Comprehensive TypeScript examples for each pattern (export with @internal, DI, integration test, document limitation)
    • Clear "MUST" requirements for documentation fallback preventing fake tests
    • Section properly numbered (3e) and placed after lint checks (3d)

    Issues:

    • None identified

    Test Coverage Analysis

    Changed File Tier Has Tests?
    .claude/skills/exec/SKILL.md Optional - (docs only)

    Coverage: Documentation-only change; no code tests needed


    Skill Command Verification

    Skill files changed: 1 (.claude/skills/exec/SKILL.md)

    File Commands Found Verification Status
    .claude/skills/exec/SKILL.md 0 ✅ Not Required

    Note: The new section contains only instructional content and TypeScript code examples. No new CLI commands were added.


    Self-Evaluation

    • Verified working: Yes - All 4 AC items have corresponding implementations verified against the diff
    • Test efficacy: N/A - Documentation change with no runtime behavior
    • Likely failure mode: Agent ignores the guidance and writes tautological tests anyway (mitigated by prominent warning and concrete bad example)
    • Verdict confidence: High - Clear AC requirements mapped to clear implementations

    Verdict: NEEDS_VERIFICATION

    All 4 acceptance criteria are fully met. The implementation is clean, well-structured, and matches the issue specification exactly. However, 3 CI checks (build matrix 18.x, 20.x, 22.x) are still in progress. The verdict will upgrade to READY_FOR_MERGE once CI completes.

    Next Steps

    1. Wait for CI build matrix (18.x, 20.x, 22.x) to complete
    2. Re-run /qa 300 after CI passes to confirm READY_FOR_MERGE
    3. Merge PR feat(#300): add exec skill guidance for testing non-exported functions #312

    QA completed: All AC met, awaiting CI completion

  7. admarble commented on Feb 22, 2026

    @admarble
    ContributorAuthor

    Merged via feat(#300). Non-exportable function testing guidance added to exec skill.

  8. added 3 commits that reference this issue on Feb 22, 2026
  9. admarble commented on Feb 22, 2026

    @admarble
    ContributorAuthor

    Documentation Review Complete

    This issue contains documentation-only changes. No additional documentation generation required.

    Files Modified:

    • .claude/skills/exec/SKILL.md — Added section 3e: Testing Non-Exported Functions (decision tree, anti-pattern warning, 4 patterns with code examples)

    Status:

    ✅ Documentation changes are ready for review and merge.


    Ready to merge!

  10. added a commit that references this issue on Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementplannedspec

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions