@rigour-labs/core 2.22.0 → 3.0.1

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.
Files changed (117) hide show
  1. package/README.md +58 -0
  2. package/dist/context.test.js +2 -3
  3. package/dist/environment.test.js +2 -1
  4. package/dist/gates/agent-team.d.ts +2 -1
  5. package/dist/gates/agent-team.js +1 -0
  6. package/dist/gates/base.d.ts +3 -1
  7. package/dist/gates/base.js +3 -0
  8. package/dist/gates/checkpoint.d.ts +2 -1
  9. package/dist/gates/checkpoint.js +3 -2
  10. package/dist/gates/context-window-artifacts.d.ts +2 -1
  11. package/dist/gates/context-window-artifacts.js +6 -3
  12. package/dist/gates/context.d.ts +2 -1
  13. package/dist/gates/context.js +1 -0
  14. package/dist/gates/coverage.js +3 -1
  15. package/dist/gates/dependency.js +5 -5
  16. package/dist/gates/duplication-drift.d.ts +2 -1
  17. package/dist/gates/duplication-drift.js +4 -1
  18. package/dist/gates/environment.js +4 -4
  19. package/dist/gates/hallucinated-imports.d.ts +21 -2
  20. package/dist/gates/hallucinated-imports.js +116 -2
  21. package/dist/gates/inconsistent-error-handling.d.ts +2 -1
  22. package/dist/gates/inconsistent-error-handling.js +21 -7
  23. package/dist/gates/promise-safety.d.ts +68 -0
  24. package/dist/gates/promise-safety.js +509 -0
  25. package/dist/gates/retry-loop-breaker.d.ts +2 -1
  26. package/dist/gates/retry-loop-breaker.js +2 -1
  27. package/dist/gates/runner.js +34 -1
  28. package/dist/gates/safety.d.ts +2 -1
  29. package/dist/gates/safety.js +2 -1
  30. package/dist/gates/security-patterns-owasp.test.d.ts +1 -0
  31. package/dist/gates/security-patterns-owasp.test.js +171 -0
  32. package/dist/gates/security-patterns.d.ts +6 -1
  33. package/dist/gates/security-patterns.js +101 -0
  34. package/dist/gates/structure.js +1 -1
  35. package/dist/hooks/checker.d.ts +23 -0
  36. package/dist/hooks/checker.js +222 -0
  37. package/dist/hooks/checker.test.d.ts +1 -0
  38. package/dist/hooks/checker.test.js +132 -0
  39. package/dist/hooks/index.d.ts +9 -0
  40. package/dist/hooks/index.js +8 -0
  41. package/dist/hooks/standalone-checker.d.ts +15 -0
  42. package/dist/hooks/standalone-checker.js +106 -0
  43. package/dist/hooks/templates.d.ts +22 -0
  44. package/dist/hooks/templates.js +232 -0
  45. package/dist/hooks/types.d.ts +34 -0
  46. package/dist/hooks/types.js +21 -0
  47. package/dist/index.d.ts +2 -0
  48. package/dist/index.js +2 -0
  49. package/dist/services/fix-packet-service.d.ts +0 -1
  50. package/dist/services/fix-packet-service.js +9 -14
  51. package/dist/services/score-history.d.ts +54 -0
  52. package/dist/services/score-history.js +122 -0
  53. package/dist/templates/index.js +176 -0
  54. package/dist/types/fix-packet.d.ts +5 -5
  55. package/dist/types/fix-packet.js +1 -1
  56. package/dist/types/index.d.ts +207 -0
  57. package/dist/types/index.js +32 -0
  58. package/package.json +21 -1
  59. package/src/context.test.ts +0 -256
  60. package/src/discovery.test.ts +0 -88
  61. package/src/discovery.ts +0 -112
  62. package/src/environment.test.ts +0 -115
  63. package/src/gates/agent-team.test.ts +0 -134
  64. package/src/gates/agent-team.ts +0 -210
  65. package/src/gates/ast-handlers/base.ts +0 -13
  66. package/src/gates/ast-handlers/python.ts +0 -145
  67. package/src/gates/ast-handlers/python_parser.py +0 -181
  68. package/src/gates/ast-handlers/typescript.ts +0 -264
  69. package/src/gates/ast-handlers/universal.ts +0 -184
  70. package/src/gates/ast.ts +0 -54
  71. package/src/gates/base.ts +0 -28
  72. package/src/gates/checkpoint.test.ts +0 -135
  73. package/src/gates/checkpoint.ts +0 -311
  74. package/src/gates/content.ts +0 -51
  75. package/src/gates/context-window-artifacts.ts +0 -277
  76. package/src/gates/context.ts +0 -270
  77. package/src/gates/coverage.ts +0 -74
  78. package/src/gates/dependency.ts +0 -108
  79. package/src/gates/duplication-drift.ts +0 -231
  80. package/src/gates/environment.ts +0 -94
  81. package/src/gates/file.ts +0 -46
  82. package/src/gates/hallucinated-imports.ts +0 -361
  83. package/src/gates/inconsistent-error-handling.ts +0 -254
  84. package/src/gates/retry-loop-breaker.ts +0 -151
  85. package/src/gates/runner.ts +0 -188
  86. package/src/gates/safety.ts +0 -56
  87. package/src/gates/security-patterns.test.ts +0 -162
  88. package/src/gates/security-patterns.ts +0 -306
  89. package/src/gates/structure.ts +0 -36
  90. package/src/index.ts +0 -13
  91. package/src/pattern-index/embeddings.ts +0 -84
  92. package/src/pattern-index/index.ts +0 -59
  93. package/src/pattern-index/indexer.test.ts +0 -276
  94. package/src/pattern-index/indexer.ts +0 -1023
  95. package/src/pattern-index/matcher.test.ts +0 -293
  96. package/src/pattern-index/matcher.ts +0 -493
  97. package/src/pattern-index/overrides.ts +0 -235
  98. package/src/pattern-index/security.ts +0 -151
  99. package/src/pattern-index/staleness.test.ts +0 -313
  100. package/src/pattern-index/staleness.ts +0 -568
  101. package/src/pattern-index/types.ts +0 -339
  102. package/src/safety.test.ts +0 -53
  103. package/src/services/adaptive-thresholds.test.ts +0 -189
  104. package/src/services/adaptive-thresholds.ts +0 -275
  105. package/src/services/context-engine.ts +0 -104
  106. package/src/services/fix-packet-service.ts +0 -42
  107. package/src/services/state-service.ts +0 -138
  108. package/src/smoke.test.ts +0 -18
  109. package/src/templates/index.ts +0 -338
  110. package/src/types/fix-packet.ts +0 -32
  111. package/src/types/index.ts +0 -200
  112. package/src/utils/logger.ts +0 -43
  113. package/src/utils/scanner.test.ts +0 -37
  114. package/src/utils/scanner.ts +0 -43
  115. package/tsconfig.json +0 -10
  116. package/vitest.config.ts +0 -7
  117. package/vitest.setup.ts +0 -30
@@ -1,276 +0,0 @@
1
- /**
2
- * Pattern Indexer Tests
3
- *
4
- * Comprehensive tests for the pattern indexer.
5
- */
6
-
7
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
8
- import * as fs from 'fs/promises';
9
- import * as path from 'path';
10
- import * as os from 'os';
11
- import { PatternIndexer, savePatternIndex, loadPatternIndex } from './indexer.js';
12
-
13
- describe('PatternIndexer', () => {
14
- let testDir: string;
15
-
16
- beforeEach(async () => {
17
- // Create a temporary test directory
18
- testDir = await fs.mkdtemp(path.join(os.tmpdir(), 'rigour-test-'));
19
- await fs.mkdir(path.join(testDir, 'src'), { recursive: true });
20
- });
21
-
22
- afterEach(async () => {
23
- // Clean up
24
- await fs.rm(testDir, { recursive: true, force: true });
25
- });
26
-
27
- describe('buildIndex', () => {
28
- it('should index function declarations', async () => {
29
- await fs.writeFile(
30
- path.join(testDir, 'src', 'utils.ts'),
31
- `
32
- /**
33
- * Format a date to a readable string.
34
- */
35
- export function formatDate(date: Date): string {
36
- return date.toISOString();
37
- }
38
- `
39
- );
40
-
41
- const indexer = new PatternIndexer(testDir);
42
- const index = await indexer.buildIndex();
43
-
44
- expect(index.patterns).toHaveLength(1);
45
- expect(index.patterns[0].name).toBe('formatDate');
46
- expect(index.patterns[0].type).toBe('function');
47
- expect(index.patterns[0].exported).toBe(true);
48
- expect(index.patterns[0].signature).toContain('date: Date');
49
- expect(index.patterns[0].description).toContain('Format a date');
50
- });
51
-
52
- it('should index arrow functions', async () => {
53
- await fs.writeFile(
54
- path.join(testDir, 'src', 'helpers.ts'),
55
- `
56
- export const slugify = (text: string): string => {
57
- return text.toLowerCase().replace(/\\s+/g, '-');
58
- };
59
- `
60
- );
61
-
62
- const indexer = new PatternIndexer(testDir);
63
- const index = await indexer.buildIndex();
64
-
65
- expect(index.patterns).toHaveLength(1);
66
- expect(index.patterns[0].name).toBe('slugify');
67
- expect(index.patterns[0].type).toBe('function');
68
- });
69
-
70
- it('should detect React hooks', async () => {
71
- await fs.writeFile(
72
- path.join(testDir, 'src', 'hooks.ts'),
73
- `
74
- export const useAuth = () => {
75
- return { user: null, login: () => {} };
76
- };
77
- `
78
- );
79
-
80
- const indexer = new PatternIndexer(testDir);
81
- const index = await indexer.buildIndex();
82
-
83
- expect(index.patterns).toHaveLength(1);
84
- expect(index.patterns[0].name).toBe('useAuth');
85
- expect(index.patterns[0].type).toBe('hook');
86
- });
87
-
88
- it('should index classes', async () => {
89
- await fs.writeFile(
90
- path.join(testDir, 'src', 'services.ts'),
91
- `
92
- export class UserService {
93
- getUser(id: string) {
94
- return { id };
95
- }
96
- }
97
- `
98
- );
99
-
100
- const indexer = new PatternIndexer(testDir);
101
- const index = await indexer.buildIndex();
102
-
103
- expect(index.patterns.some(p => p.name === 'UserService')).toBe(true);
104
- expect(index.patterns.find(p => p.name === 'UserService')?.type).toBe('class');
105
- });
106
-
107
- it('should detect error classes', async () => {
108
- await fs.writeFile(
109
- path.join(testDir, 'src', 'errors.ts'),
110
- `
111
- export class ValidationError extends Error {
112
- constructor(message: string) {
113
- super(message);
114
- }
115
- }
116
- `
117
- );
118
-
119
- const indexer = new PatternIndexer(testDir);
120
- const index = await indexer.buildIndex();
121
-
122
- expect(index.patterns[0].type).toBe('error');
123
- });
124
-
125
- it('should index interfaces', async () => {
126
- await fs.writeFile(
127
- path.join(testDir, 'src', 'types.ts'),
128
- `
129
- export interface User {
130
- id: string;
131
- name: string;
132
- email: string;
133
- }
134
- `
135
- );
136
-
137
- const indexer = new PatternIndexer(testDir);
138
- const index = await indexer.buildIndex();
139
-
140
- expect(index.patterns).toHaveLength(1);
141
- expect(index.patterns[0].name).toBe('User');
142
- expect(index.patterns[0].type).toBe('interface');
143
- });
144
-
145
- it('should index type aliases', async () => {
146
- await fs.writeFile(
147
- path.join(testDir, 'src', 'types.ts'),
148
- `
149
- export type UserId = string;
150
- `
151
- );
152
-
153
- const indexer = new PatternIndexer(testDir);
154
- const index = await indexer.buildIndex();
155
-
156
- expect(index.patterns).toHaveLength(1);
157
- expect(index.patterns[0].type).toBe('type');
158
- });
159
-
160
- it('should index enums', async () => {
161
- await fs.writeFile(
162
- path.join(testDir, 'src', 'constants.ts'),
163
- `
164
- export enum Status {
165
- Active = 'active',
166
- Inactive = 'inactive'
167
- }
168
- `
169
- );
170
-
171
- const indexer = new PatternIndexer(testDir);
172
- const index = await indexer.buildIndex();
173
-
174
- expect(index.patterns).toHaveLength(1);
175
- expect(index.patterns[0].name).toBe('Status');
176
- expect(index.patterns[0].type).toBe('enum');
177
- });
178
-
179
- it('should index constants (all caps)', async () => {
180
- await fs.writeFile(
181
- path.join(testDir, 'src', 'config.ts'),
182
- `
183
- export const API_URL = 'https://api.example.com';
184
- export const MAX_RETRIES = 3;
185
- `
186
- );
187
-
188
- const indexer = new PatternIndexer(testDir);
189
- const index = await indexer.buildIndex();
190
-
191
- const constants = index.patterns.filter(p => p.type === 'constant');
192
- expect(constants.length).toBeGreaterThanOrEqual(1);
193
- expect(constants.some(c => c.name === 'API_URL')).toBe(true);
194
- });
195
-
196
- it('should track index statistics', async () => {
197
- await fs.writeFile(
198
- path.join(testDir, 'src', 'utils.ts'),
199
- `
200
- export function foo() {}
201
- export function bar() {}
202
- export interface Baz {}
203
- `
204
- );
205
-
206
- const indexer = new PatternIndexer(testDir);
207
- const index = await indexer.buildIndex();
208
-
209
- expect(index.stats.totalPatterns).toBe(3);
210
- expect(index.stats.totalFiles).toBe(1);
211
- expect(index.stats.indexDurationMs).toBeGreaterThan(0);
212
- });
213
-
214
- it('should exclude test files by default', async () => {
215
- await fs.writeFile(path.join(testDir, 'src', 'utils.ts'), 'export function main() {}');
216
- await fs.writeFile(path.join(testDir, 'src', 'utils.test.ts'), 'export function testMain() {}');
217
-
218
- const indexer = new PatternIndexer(testDir);
219
- const index = await indexer.buildIndex();
220
-
221
- expect(index.patterns.every(p => !p.file.includes('.test.'))).toBe(true);
222
- });
223
- });
224
-
225
- describe('updateIndex (incremental)', () => {
226
- it('should only reindex changed files', async () => {
227
- // Initial index
228
- await fs.writeFile(
229
- path.join(testDir, 'src', 'a.ts'),
230
- 'export function funcA() {}'
231
- );
232
- await fs.writeFile(
233
- path.join(testDir, 'src', 'b.ts'),
234
- 'export function funcB() {}'
235
- );
236
-
237
- const indexer = new PatternIndexer(testDir);
238
- const initialIndex = await indexer.buildIndex();
239
- expect(initialIndex.patterns).toHaveLength(2);
240
-
241
- // Modify only one file
242
- await fs.writeFile(
243
- path.join(testDir, 'src', 'a.ts'),
244
- 'export function funcA() {} export function funcA2() {}'
245
- );
246
-
247
- const updatedIndex = await indexer.updateIndex(initialIndex);
248
- expect(updatedIndex.patterns).toHaveLength(3);
249
- });
250
- });
251
-
252
- describe('savePatternIndex / loadPatternIndex', () => {
253
- it('should save and load index correctly', async () => {
254
- await fs.writeFile(
255
- path.join(testDir, 'src', 'utils.ts'),
256
- 'export function myFunc() {}'
257
- );
258
-
259
- const indexer = new PatternIndexer(testDir);
260
- const index = await indexer.buildIndex();
261
-
262
- const indexPath = path.join(testDir, '.rigour', 'patterns.json');
263
- await savePatternIndex(index, indexPath);
264
-
265
- const loaded = await loadPatternIndex(indexPath);
266
- expect(loaded).not.toBeNull();
267
- expect(loaded!.patterns).toHaveLength(index.patterns.length);
268
- expect(loaded!.version).toBe(index.version);
269
- });
270
-
271
- it('should return null for non-existent index', async () => {
272
- const loaded = await loadPatternIndex('/non/existent/path.json');
273
- expect(loaded).toBeNull();
274
- });
275
- });
276
- });