@7n/test 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.7.0] - 2026-06-27
4
+
5
+ ### Added
6
+
7
+ - Bootstrap-режим: якщо тестів нема взагалі (`files=[]`, `failingTests=[]`), `@7n/test` тепер сканує джерельні файли, оцінює потребу через LLM і генерує початкові тести — замість зупинки з попередженням. Прибрано бінарний аліас `test` із bin-поля — залишено лише `7n-test`, що усуває конфлікт з shell built-in при `npx @7n/test`.
8
+
3
9
  ## [0.6.0] - 2026-06-27
4
10
 
5
11
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@7n/test",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "CLI-утиліта @7n/test",
5
5
  "keywords": [
6
6
  "7n",
@@ -18,8 +18,7 @@
18
18
  "url": "git+https://github.com/nitra/7n-test.git"
19
19
  },
20
20
  "bin": {
21
- "7n-test": "bin/7n-test.js",
22
- "test": "bin/7n-test.js"
21
+ "7n-test": "bin/7n-test.js"
23
22
  },
24
23
  "files": [
25
24
  "bin",
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { spawnSync } from 'node:child_process'
8
8
  import { existsSync, readFileSync } from 'node:fs'
9
- import { mkdtemp, rm } from 'node:fs/promises'
9
+ import { mkdtemp, readdir, rm } from 'node:fs/promises'
10
10
  import { tmpdir } from 'node:os'
11
11
  import { createRequire } from 'node:module'
12
12
  import { join, relative, dirname } from 'node:path'
@@ -133,3 +133,41 @@ export async function measureCoveragePerFile(dir) {
133
133
  export function getUncoveredFiles(files, threshold = 80) {
134
134
  return files.filter(f => f.pct < threshold)
135
135
  }
136
+
137
+ const SOURCE_EXT_RE = /\.(mjs|js|ts|vue|py)$/
138
+ const IGNORE_DIRS = new Set([
139
+ 'node_modules', 'dist', 'build', 'out', '.git', '__pycache__',
140
+ 'coverage', '.cursor', '.claude', '.pi', 'docs', 'bin', 'reports'
141
+ ])
142
+
143
+ /**
144
+ * Recursively finds source code files in a directory, excluding tests and
145
+ * ignored directories. Used for bootstrap when no coverage data exists.
146
+ *
147
+ * @param {string} dir project root
148
+ * @returns {Promise<string[]>} relative paths to source files
149
+ */
150
+ export async function findSourceFiles(dir) {
151
+ const results = []
152
+
153
+ async function walk(current, relBase) {
154
+ let entries
155
+ try {
156
+ entries = await readdir(current, { withFileTypes: true })
157
+ } catch {
158
+ return
159
+ }
160
+ for (const entry of entries) {
161
+ if (entry.name.startsWith('.')) continue
162
+ const rel = relBase ? `${relBase}/${entry.name}` : entry.name
163
+ if (entry.isDirectory()) {
164
+ if (!IGNORE_DIRS.has(entry.name)) await walk(join(current, entry.name), rel)
165
+ } else if (entry.isFile() && SOURCE_EXT_RE.test(entry.name) && !TEST_FILE_RE.test(rel)) {
166
+ results.push(rel)
167
+ }
168
+ }
169
+ }
170
+
171
+ await walk(dir, '')
172
+ return results
173
+ }
package/src/run.mjs CHANGED
@@ -11,7 +11,7 @@
11
11
  * 5. Mutation testing via existing coverage providers (requires .n-cursor.json#rules).
12
12
  * 6. Auto-fix survived mutants via pi agent.
13
13
  */
14
- import { measureCoveragePerFile, getUncoveredFiles } from './coverage-per-file.mjs'
14
+ import { measureCoveragePerFile, getUncoveredFiles, findSourceFiles } from './coverage-per-file.mjs'
15
15
  import { assessNeed } from './assess-need.mjs'
16
16
  import { generateTests } from './gen-tests.mjs'
17
17
  import { fixFailingTests } from './fix-tests.mjs'
@@ -43,8 +43,28 @@ export async function runAutoTest(dir, opts = {}) {
43
43
  }
44
44
 
45
45
  if (allFiles.length === 0) {
46
- console.log('⚠ Vitest coverage не повернула даних — перевір налаштування vitest.')
47
- break
46
+ if (failingTests.length > 0) {
47
+ console.log('⚠ Тести падають, але coverage все одно порожня — зупиняю цикл.')
48
+ break
49
+ }
50
+ // Bootstrap: no tests at all — scan source files and generate initial tests
51
+ const sourceFiles = await findSourceFiles(dir)
52
+ if (sourceFiles.length === 0) {
53
+ console.log('⚠ Vitest coverage не повернула даних — перевір налаштування vitest.')
54
+ break
55
+ }
56
+ console.log(`\n── Bootstrap: ${sourceFiles.length} файлів без тестів — оцінюю потребу ──\n`)
57
+ const bootstrapFiles = sourceFiles.map(f => ({ file: f, pct: 0 }))
58
+ const assessed = await assessNeed(bootstrapFiles, dir)
59
+ const needsTests = assessed.filter(f => f.needsTests)
60
+ if (needsTests.length === 0) {
61
+ console.log('✓ LLM вирішила: жоден файл не потребує unit-тестів.')
62
+ break
63
+ }
64
+ console.log(`\n→ Bootstrap-тести для (${needsTests.length}):`)
65
+ for (const f of needsTests) console.log(` • ${f.file} — ${f.reason}`)
66
+ await generateTests(needsTests, dir)
67
+ continue
48
68
  }
49
69
 
50
70
  const uncovered = getUncoveredFiles(allFiles, COVERAGE_THRESHOLD)