test-install.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #!/usr/bin/env bun
  2. /**
  3. * Test script for context installer
  4. * Tests against real GitHub repository
  5. */
  6. import { existsSync } from 'fs'
  7. import { join } from 'path'
  8. import { fetchRegistry, filterContextByProfile } from './utils/registry-fetcher'
  9. import { installContext } from './install-context'
  10. const colors = {
  11. reset: '\x1b[0m',
  12. red: '\x1b[31m',
  13. green: '\x1b[32m',
  14. yellow: '\x1b[33m',
  15. blue: '\x1b[34m',
  16. cyan: '\x1b[36m',
  17. bold: '\x1b[1m',
  18. }
  19. function printHeader(msg: string): void {
  20. console.log(`\n${colors.bold}${colors.cyan}${msg}${colors.reset}\n`)
  21. }
  22. function printSuccess(msg: string): void {
  23. console.log(`${colors.green}✓${colors.reset} ${msg}`)
  24. }
  25. function printError(msg: string): void {
  26. console.log(`${colors.red}✗${colors.reset} ${msg}`)
  27. }
  28. function printInfo(msg: string): void {
  29. console.log(`${colors.blue}ℹ${colors.reset} ${msg}`)
  30. }
  31. async function runTests(): Promise<void> {
  32. let passed = 0
  33. let failed = 0
  34. printHeader('Testing Context Installer')
  35. printInfo('Testing against real GitHub repository')
  36. console.log('')
  37. // Test 1: Fetch Registry
  38. printHeader('Test 1: Fetch Registry')
  39. try {
  40. const registry = await fetchRegistry({ source: 'github' })
  41. printSuccess(`Fetched from: https://raw.githubusercontent.com/darrenhinde/OpenAgentsControl/main/registry.json`)
  42. printSuccess(`Registry version: ${registry.version}`)
  43. printSuccess(`Context components found: ${registry.components.contexts?.length || 0}`)
  44. passed++
  45. } catch (error) {
  46. printError(`Failed to fetch registry: ${error}`)
  47. failed++
  48. }
  49. console.log('')
  50. // Test 2: Filter by Profile
  51. printHeader('Test 2: Filter by Profile')
  52. try {
  53. const registry = await fetchRegistry({ source: 'github' })
  54. const essential = filterContextByProfile(registry, 'essential')
  55. printSuccess(`Essential profile: ${essential.length} components`)
  56. for (const component of essential.slice(0, 5)) {
  57. console.log(` - ${component.id}: ${component.path}`)
  58. }
  59. if (essential.length > 5) {
  60. console.log(` ... and ${essential.length - 5} more`)
  61. }
  62. passed++
  63. } catch (error) {
  64. printError(`Failed to filter by profile: ${error}`)
  65. failed++
  66. }
  67. console.log('')
  68. // Test 3: Dry Run Installation
  69. printHeader('Test 3: Dry Run Installation')
  70. try {
  71. const result = await installContext({
  72. profile: 'essential',
  73. dryRun: true,
  74. verbose: false,
  75. })
  76. if (result.success) {
  77. printSuccess('Dry run completed successfully')
  78. printSuccess(`Would install ${result.manifest.context.length} components`)
  79. printSuccess(`Profile: ${result.manifest.profile}`)
  80. passed++
  81. } else {
  82. printError('Dry run failed')
  83. if (result.errors) {
  84. for (const error of result.errors) {
  85. printError(` ${error}`)
  86. }
  87. }
  88. failed++
  89. }
  90. } catch (error) {
  91. printError(`Dry run error: ${error}`)
  92. failed++
  93. }
  94. console.log('')
  95. // Test 4: Actual Installation (optional - commented out by default)
  96. // Uncomment to test actual installation
  97. /*
  98. printHeader('Test 4: Install Essential Profile')
  99. try {
  100. const result = await installContext({
  101. profile: 'essential',
  102. dryRun: false,
  103. force: true,
  104. verbose: true,
  105. })
  106. if (result.success) {
  107. printSuccess('Installation complete')
  108. printSuccess(`Installed ${result.manifest.context.length} components`)
  109. printSuccess(`Commit: ${result.manifest.source.commit}`)
  110. // Verify files exist
  111. let filesExist = 0
  112. let filesMissing = 0
  113. for (const component of result.manifest.context) {
  114. if (existsSync(component.local_path)) {
  115. filesExist++
  116. } else {
  117. filesMissing++
  118. printError(`Missing: ${component.id}`)
  119. }
  120. }
  121. printSuccess(`Files verified: ${filesExist}/${result.manifest.context.length}`)
  122. if (filesMissing === 0) {
  123. passed++
  124. } else {
  125. printError(`${filesMissing} files missing`)
  126. failed++
  127. }
  128. } else {
  129. printError('Installation failed')
  130. if (result.errors) {
  131. for (const error of result.errors) {
  132. printError(` ${error}`)
  133. }
  134. }
  135. failed++
  136. }
  137. } catch (error) {
  138. printError(`Installation error: ${error}`)
  139. failed++
  140. }
  141. console.log('')
  142. */
  143. // Summary
  144. printHeader('Test Summary')
  145. console.log(`Total tests: ${passed + failed}`)
  146. printSuccess(`Passed: ${passed}`)
  147. if (failed > 0) {
  148. printError(`Failed: ${failed}`)
  149. }
  150. console.log('')
  151. if (failed === 0) {
  152. printSuccess('All tests passed! ✓')
  153. } else {
  154. printError('Some tests failed')
  155. process.exit(1)
  156. }
  157. }
  158. // Run tests
  159. runTests().catch((error) => {
  160. console.error('Fatal error:', error)
  161. process.exit(1)
  162. })