pumuki 6.3.179 → 6.3.180

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/VERSION CHANGED
@@ -1 +1 @@
1
- v6.3.179
1
+ v6.3.180
@@ -8,6 +8,7 @@ import {
8
8
  findKotlinPresentationSrpMatch,
9
9
  hasKotlinGlobalScopeUsage,
10
10
  hasKotlinLiveDataStateExposureUsage,
11
+ hasKotlinManualCoroutineScopeInViewModelUsage,
11
12
  hasKotlinRunBlockingUsage,
12
13
  hasKotlinThreadSleepCall,
13
14
  } from './android';
@@ -114,6 +115,32 @@ class OrdersViewModel : ViewModel() {
114
115
  assert.equal(hasKotlinLiveDataStateExposureUsage(source), false);
115
116
  });
116
117
 
118
+ test('hasKotlinManualCoroutineScopeInViewModelUsage detecta CoroutineScope manual dentro de ViewModel', () => {
119
+ const source = `
120
+ class OrdersViewModel : ViewModel() {
121
+ private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
122
+ }
123
+ `;
124
+ assert.equal(hasKotlinManualCoroutineScopeInViewModelUsage(source), true);
125
+ });
126
+
127
+ test('hasKotlinManualCoroutineScopeInViewModelUsage ignora imports, comentarios y uso fuera de ViewModel', () => {
128
+ const source = `
129
+ import kotlinx.coroutines.CoroutineScope
130
+ // private val scope = CoroutineScope(SupervisorJob())
131
+ val sample = "CoroutineScope(SupervisorJob())"
132
+ class OrdersWorker {
133
+ private val scope = CoroutineScope(SupervisorJob())
134
+ }
135
+ class OrdersViewModel : ViewModel() {
136
+ fun load() {
137
+ viewModelScope.launch { }
138
+ }
139
+ }
140
+ `;
141
+ assert.equal(hasKotlinManualCoroutineScopeInViewModelUsage(source), false);
142
+ });
143
+
117
144
  test('findKotlinPresentationSrpMatch devuelve payload semantico para SRP-Android en presentation', () => {
118
145
  const source = `
119
146
  import android.content.SharedPreferences
@@ -299,6 +299,38 @@ export const hasKotlinLiveDataStateExposureUsage = (source: string): boolean =>
299
299
  ).length > 0;
300
300
  };
301
301
 
302
+ export const hasKotlinManualCoroutineScopeInViewModelUsage = (source: string): boolean => {
303
+ const lines = source.split(/\r?\n/);
304
+ let insideViewModel = false;
305
+ let braceDepth = 0;
306
+
307
+ for (const rawLine of lines) {
308
+ const sanitized = stripKotlinLineForSemanticScan(rawLine);
309
+ if (sanitized.trimStart().startsWith('import ')) {
310
+ continue;
311
+ }
312
+
313
+ if (!insideViewModel && /\bclass\s+\w*ViewModel\b/.test(sanitized)) {
314
+ insideViewModel = true;
315
+ braceDepth =
316
+ countTokenOccurrences(sanitized, '{') - countTokenOccurrences(sanitized, '}');
317
+ } else if (insideViewModel) {
318
+ braceDepth += countTokenOccurrences(sanitized, '{');
319
+ braceDepth -= countTokenOccurrences(sanitized, '}');
320
+ }
321
+
322
+ if (insideViewModel && /\bCoroutineScope\s*\(/.test(sanitized)) {
323
+ return true;
324
+ }
325
+
326
+ if (insideViewModel && braceDepth <= 0 && sanitized.includes('}')) {
327
+ insideViewModel = false;
328
+ }
329
+ }
330
+
331
+ return false;
332
+ };
333
+
302
334
  export const findKotlinPresentationSrpMatch = (
303
335
  source: string
304
336
  ): KotlinPresentationSrpMatch | undefined => {
@@ -638,6 +638,7 @@ const textDetectorRegistry: ReadonlyArray<TextDetectorRegistryEntry> = [
638
638
  { platform: 'android', pathCheck: isAndroidKotlinPath, excludePaths: [isKotlinTestPath], detect: TextAndroid.hasKotlinGlobalScopeUsage, ruleId: 'heuristics.android.globalscope.ast', code: 'HEURISTICS_ANDROID_GLOBAL_SCOPE_AST', message: 'AST heuristic detected GlobalScope coroutine usage in production Kotlin code.' },
639
639
  { platform: 'android', pathCheck: isAndroidKotlinPath, excludePaths: [isKotlinTestPath], detect: TextAndroid.hasKotlinRunBlockingUsage, ruleId: 'heuristics.android.run-blocking.ast', code: 'HEURISTICS_ANDROID_RUN_BLOCKING_AST', message: 'AST heuristic detected runBlocking usage in production Kotlin code.' },
640
640
  { platform: 'android', pathCheck: isAndroidPresentationPath, excludePaths: [isKotlinTestPath], detect: TextAndroid.hasKotlinLiveDataStateExposureUsage, ruleId: 'heuristics.android.flow.livedata-state-exposure.ast', code: 'HEURISTICS_ANDROID_FLOW_LIVEDATA_STATE_EXPOSURE_AST', message: 'AST heuristic detected LiveData state exposure in Android presentation code where StateFlow or SharedFlow should be preferred.' },
641
+ { platform: 'android', pathCheck: isAndroidPresentationPath, excludePaths: [isKotlinTestPath], detect: TextAndroid.hasKotlinManualCoroutineScopeInViewModelUsage, ruleId: 'heuristics.android.coroutines.manual-scope-in-viewmodel.ast', code: 'HEURISTICS_ANDROID_COROUTINES_MANUAL_SCOPE_IN_VIEWMODEL_AST', message: 'AST heuristic detected manual CoroutineScope inside an Android ViewModel where viewModelScope should be preferred.' },
641
642
  ];
642
643
 
643
644
  const extractWorkflowHeuristicFacts = (
@@ -3,7 +3,7 @@ import test from 'node:test';
3
3
  import { androidRules } from './android';
4
4
 
5
5
  test('androidRules define reglas heurísticas locked para plataforma android', () => {
6
- assert.equal(androidRules.length, 9);
6
+ assert.equal(androidRules.length, 10);
7
7
 
8
8
  const ids = androidRules.map((rule) => rule.id);
9
9
  assert.deepEqual(ids, [
@@ -11,6 +11,7 @@ test('androidRules define reglas heurísticas locked para plataforma android', (
11
11
  'heuristics.android.globalscope.ast',
12
12
  'heuristics.android.run-blocking.ast',
13
13
  'heuristics.android.flow.livedata-state-exposure.ast',
14
+ 'heuristics.android.coroutines.manual-scope-in-viewmodel.ast',
14
15
  'heuristics.android.solid.srp.presentation-mixed-responsibilities.ast',
15
16
  'heuristics.android.solid.ocp.discriminator-branching.ast',
16
17
  'heuristics.android.solid.dip.concrete-framework-dependency.ast',
@@ -45,6 +46,10 @@ test('androidRules define reglas heurísticas locked para plataforma android', (
45
46
  byId.get('heuristics.android.flow.livedata-state-exposure.ast')?.then.code,
46
47
  'HEURISTICS_ANDROID_FLOW_LIVEDATA_STATE_EXPOSURE_AST'
47
48
  );
49
+ assert.equal(
50
+ byId.get('heuristics.android.coroutines.manual-scope-in-viewmodel.ast')?.then.code,
51
+ 'HEURISTICS_ANDROID_COROUTINES_MANUAL_SCOPE_IN_VIEWMODEL_AST'
52
+ );
48
53
  assert.equal(
49
54
  byId.get('heuristics.android.solid.srp.presentation-mixed-responsibilities.ast')?.then.code,
50
55
  'HEURISTICS_ANDROID_SOLID_SRP_PRESENTATION_MIXED_RESPONSIBILITIES_AST'
@@ -75,6 +75,26 @@ export const androidRules: RuleSet = [
75
75
  code: 'HEURISTICS_ANDROID_FLOW_LIVEDATA_STATE_EXPOSURE_AST',
76
76
  },
77
77
  },
78
+ {
79
+ id: 'heuristics.android.coroutines.manual-scope-in-viewmodel.ast',
80
+ description:
81
+ 'Detects manual CoroutineScope construction inside Android ViewModel classes where viewModelScope should be preferred.',
82
+ severity: 'WARN',
83
+ platform: 'android',
84
+ locked: true,
85
+ when: {
86
+ kind: 'Heuristic',
87
+ where: {
88
+ ruleId: 'heuristics.android.coroutines.manual-scope-in-viewmodel.ast',
89
+ },
90
+ },
91
+ then: {
92
+ kind: 'Finding',
93
+ message:
94
+ 'AST heuristic detected manual CoroutineScope inside an Android ViewModel.',
95
+ code: 'HEURISTICS_ANDROID_COROUTINES_MANUAL_SCOPE_IN_VIEWMODEL_AST',
96
+ },
97
+ },
78
98
  {
79
99
  id: 'heuristics.android.solid.srp.presentation-mixed-responsibilities.ast',
80
100
  description:
@@ -124,7 +124,8 @@ app/
124
124
 
125
125
  ### Enforcement AST inicial de coroutines Android
126
126
  ✅ `skills.android.guideline.android.coroutines-async-await-no-callbacks` debe mapear a señales ejecutables existentes de uso inseguro de coroutines, empezando por `GlobalScope` y `runBlocking`.
127
- El baseline inicial de coroutines es parcial: cubre APIs bloqueantes o scopes no estructurados, pero no declara todavía cobertura completa de `Flow`, `viewModelScope`, `supervisorScope`, dispatchers ni cancelación cooperativa.
127
+ `skills.android.guideline.android.viewmodelscope-scope-de-viewmodel-cancelado-automa-ticamente` debe mapear a señales ejecutables de scopes manuales dentro de `ViewModel`, empezando por `CoroutineScope(...)` construido en presentation.
128
+ ✅ El baseline inicial de coroutines es parcial: cubre APIs bloqueantes, scopes no estructurados y scopes manuales en `ViewModel`, pero no declara todavía cobertura completa de `Flow`, `supervisorScope`, dispatchers ni cancelación cooperativa.
128
129
  ✅ Si se amplía esta cobertura, cada nueva regla debe aterrizar como detector AST/textual semántico con test dirigido antes de declararse cubierta en el registry.
129
130
 
130
131
  ### Enforcement AST inicial de Flow/StateFlow Android
@@ -220,6 +220,10 @@ const registryByRuleId: Record<string, SkillsDetectorBinding> = {
220
220
  'heuristics.android.run-blocking.ast',
221
221
  ]
222
222
  ),
223
+ 'skills.android.guideline.android.viewmodelscope-scope-de-viewmodel-cancelado-automa-ticamente': heuristicDetector(
224
+ 'android.coroutines.viewmodel-scope',
225
+ ['heuristics.android.coroutines.manual-scope-in-viewmodel.ast']
226
+ ),
223
227
  'skills.android.guideline.android.stateflow-estado-mutable-observable': heuristicDetector(
224
228
  'android.flow.state-exposure',
225
229
  ['heuristics.android.flow.livedata-state-exposure.ast']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pumuki",
3
- "version": "6.3.179",
3
+ "version": "6.3.180",
4
4
  "description": "Enterprise-grade AST Intelligence System with multi-platform support (iOS, Android, Backend, Frontend) and Feature-First + DDD + Clean Architecture enforcement. Includes dynamic violations API for intelligent querying.",
5
5
  "main": "index.js",
6
6
  "bin": {