|
| 1 | +# API Export Verification Tests |
| 2 | + |
| 3 | +This test verifies that the CLPrompter API is properly exported and accessible to external extensions. |
| 4 | + |
| 5 | +## What is Being Tested |
| 6 | + |
| 7 | +The test verifies that: |
| 8 | + |
| 9 | +1. ✅ The `activate()` function in `extension.ts` imports `CLPrompter` and `CLPrompterCallback` |
| 10 | +2. ✅ The `activate()` function returns `{ CLPrompter, CLPrompterCallback }` |
| 11 | +3. ✅ External extensions can access the API using `vscode.extensions.getExtension()` |
| 12 | + |
| 13 | +## Why This Matters |
| 14 | + |
| 15 | +After Alan's feedback on issue #6, we discovered that the `activate()` function wasn't returning the exports. This meant external extensions couldn't access the API. |
| 16 | + |
| 17 | +**The Fix:** |
| 18 | +```typescript |
| 19 | +// In extension.ts activate() function |
| 20 | +return { |
| 21 | + CLPrompter, |
| 22 | + CLPrompterCallback |
| 23 | +}; |
| 24 | +``` |
| 25 | + |
| 26 | +## Running the Tests |
| 27 | + |
| 28 | +Run the verification test to check the source code: |
| 29 | + |
| 30 | +```bash |
| 31 | +npm run test:api |
| 32 | +``` |
| 33 | + |
| 34 | +This will: |
| 35 | +1. Compile the test file |
| 36 | +2. Check the source code for proper imports and return statement |
| 37 | +3. Verify the API export structure |
| 38 | + |
| 39 | +## Expected Output |
| 40 | + |
| 41 | +If everything is working correctly, you should see: |
| 42 | + |
| 43 | +``` |
| 44 | +╔════════════════════════════════════════════════════════╗ |
| 45 | +║ CLPrompter API Export Verification Test ║ |
| 46 | +╚════════════════════════════════════════════════════════╝ |
| 47 | +
|
| 48 | +Checking that activate() returns the API exports... |
| 49 | +
|
| 50 | +Step 1: Checking for CLPrompter import... |
| 51 | + ✓ CLPrompter imported from clPrompter module |
| 52 | +
|
| 53 | +Step 2: Checking for CLPrompterCallback import... |
| 54 | + ✓ CLPrompterCallback imported from clPrompter module |
| 55 | +
|
| 56 | +Step 3: Checking activate() function return statement... |
| 57 | + ✓ activate() returns { CLPrompter, CLPrompterCallback } |
| 58 | +
|
| 59 | +============================================================ |
| 60 | +✅ SUCCESS! API is properly exported |
| 61 | +============================================================ |
| 62 | +
|
| 63 | +The activate() function correctly returns: |
| 64 | + return { CLPrompter, CLPrompterCallback }; |
| 65 | +
|
| 66 | +External extensions can access the API using: |
| 67 | +
|
| 68 | + const ext = vscode.extensions.getExtension('CozziResearch.clprompter'); |
| 69 | + if (!ext.isActive) await ext.activate(); |
| 70 | + const { CLPrompter } = ext.exports; |
| 71 | + const result = await CLPrompter(command); |
| 72 | +``` |
| 73 | + |
| 74 | +## What External Extensions Need to Do |
| 75 | + |
| 76 | +With the API properly exported, external extensions can use either pattern: |
| 77 | + |
| 78 | +### Pattern 1: Optional Enhancement (Recommended) |
| 79 | + |
| 80 | +```typescript |
| 81 | +const clPrompterExt = vscode.extensions.getExtension('CozziResearch.clprompter'); |
| 82 | + |
| 83 | +if (clPrompterExt) { |
| 84 | + if (!clPrompterExt.isActive) { |
| 85 | + await clPrompterExt.activate(); |
| 86 | + } |
| 87 | + |
| 88 | + if (clPrompterExt.exports?.CLPrompter) { |
| 89 | + const result = await clPrompterExt.exports.CLPrompter(command); |
| 90 | + // Use result... |
| 91 | + } |
| 92 | +} else { |
| 93 | + // Fallback to simple input box |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +### Pattern 2: Required Dependency |
| 98 | + |
| 99 | +Add to `package.json`: |
| 100 | +```json |
| 101 | +{ |
| 102 | + "extensionDependencies": ["CozziResearch.clprompter"] |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +Then use directly: |
| 107 | +```typescript |
| 108 | +const clPrompterExt = vscode.extensions.getExtension('CozziResearch.clprompter')!; |
| 109 | +await clPrompterExt.activate(); |
| 110 | +const { CLPrompter } = clPrompterExt.exports; |
| 111 | +const result = await CLPrompter(command); |
| 112 | +``` |
| 113 | + |
| 114 | +## Test Files |
| 115 | + |
| 116 | +- `src/testAPICall.ts` - Main verification test (checks source code) |
| 117 | + |
| 118 | +The old mock-based test files have been removed as they were overly complex and had multiple issues. The simple source code verification is sufficient and reliable. |
| 119 | + |
| 120 | +## Troubleshooting |
| 121 | + |
| 122 | +### Test Fails: "return statement NOT found" |
| 123 | + |
| 124 | +The `activate()` function in `extension.ts` is missing the return statement. Add this at the end of the function: |
| 125 | + |
| 126 | +```typescript |
| 127 | +return { |
| 128 | + CLPrompter, |
| 129 | + CLPrompterCallback |
| 130 | +}; |
| 131 | +``` |
| 132 | + |
| 133 | +### Test Fails: "Could not find extension.ts" |
| 134 | + |
| 135 | +The test looks for the source file at `src/extension.ts`. Make sure you're running the test from the project root directory. |
| 136 | + |
| 137 | +## References |
| 138 | + |
| 139 | +- Issue #6: https://github.com/bobcozzi/clPrompter/issues/6 |
| 140 | +- API Documentation: [CLPROMPTER_API.md](CLPROMPTER_API.md) |
0 commit comments