principles-disciple 1.32.0 → 1.34.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/openclaw.plugin.json +4 -4
- package/package.json +1 -1
- package/src/core/correction-cue-learner.ts +203 -0
- package/src/core/correction-types.ts +88 -0
- package/src/core/evolution-logger.ts +3 -3
- package/src/core/init.ts +67 -0
- package/src/service/correction-observer-types.ts +58 -0
- package/src/service/correction-observer-workflow-manager.ts +218 -0
- package/src/service/evolution-worker.ts +172 -146
- package/src/service/nocturnal-service.ts +4 -1
- package/src/service/subagent-workflow/index.ts +14 -0
- package/src/service/subagent-workflow/nocturnal-workflow-manager.ts +3 -1
- package/tests/service/evolution-worker.nocturnal.test.ts +14 -1
- package/tests/service/evolution-worker.timeout.test.ts +350 -0
- package/tests/commands/implementation-lifecycle.test.ts +0 -362
- package/tests/core/detection-funnel.test.ts +0 -63
- package/tests/core/evolution-e2e.test.ts +0 -58
- package/tests/core/evolution-engine-gate-integration.test.ts +0 -543
- package/tests/core/evolution-engine.test.ts +0 -562
- package/tests/core/evolution-reducer.test.ts +0 -180
- package/tests/core/evolution-user-stories.e2e.test.ts +0 -249
- package/tests/core/local-worker-routing.test.ts +0 -757
- package/tests/core/rule-host.test.ts +0 -389
- package/tests/core/trajectory-correction-pain.test.ts +0 -180
- package/tests/hooks/gate-edit-verification.test.ts +0 -435
- package/tests/hooks/llm.test.ts +0 -308
- package/tests/hooks/progressive-trust-gate.test.ts +0 -277
- package/tests/hooks/prompt.test.ts +0 -1473
- package/tests/index.integration.test.ts +0 -179
- package/tests/index.shadow-routing.integration.test.ts +0 -140
- package/tests/service/evolution-worker.test.ts +0 -462
- package/tests/service/nocturnal-service.test.ts +0 -577
- package/tests/service/nocturnal-workflow-manager.test.ts +0 -441
- package/tests/tools/critique-prompt.test.ts +0 -260
- package/tests/tools/deep-reflect.test.ts +0 -232
- package/tests/tools/model-index.test.ts +0 -246
- package/tests/ui/app.test.tsx +0 -114
package/tests/hooks/llm.test.ts
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { handleLlmOutput, extractEmpathySignal, isEmpathyAuditPayload } from '../../src/hooks/llm';
|
|
3
|
-
import * as painFlags from '../../src/core/pain';
|
|
4
|
-
import * as sessionTracker from '../../src/core/session-tracker';
|
|
5
|
-
import { ControlUiDatabase } from '../../src/core/control-ui-db';
|
|
6
|
-
import { DetectionService } from '../../src/core/detection-service';
|
|
7
|
-
import { WorkspaceContext } from '../../src/core/workspace-context';
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
import path from 'path';
|
|
10
|
-
|
|
11
|
-
vi.mock('fs');
|
|
12
|
-
vi.mock('../../src/core/pain', () => ({
|
|
13
|
-
writePainFlag: vi.fn(),
|
|
14
|
-
}));
|
|
15
|
-
vi.mock('../../src/core/control-ui-db');
|
|
16
|
-
vi.mock('../../src/core/detection-service');
|
|
17
|
-
vi.mock('../../src/core/workspace-context');
|
|
18
|
-
|
|
19
|
-
describe('LLM Cognitive Distress Hook', () => {
|
|
20
|
-
const workspaceDir = '/mock/workspace';
|
|
21
|
-
const sessionId = 'test-session-auth';
|
|
22
|
-
|
|
23
|
-
const mockConfig = {
|
|
24
|
-
get: vi.fn((key) => {
|
|
25
|
-
if (key === 'thresholds.stuck_loops_trigger') return 3;
|
|
26
|
-
if (key === 'thresholds.cognitive_paralysis_input') return 4000;
|
|
27
|
-
if (key === 'scores.paralysis') return 40;
|
|
28
|
-
if (key === 'thresholds.pain_trigger') return 30;
|
|
29
|
-
if (key === 'scores.default_confusion') return 35;
|
|
30
|
-
if (key === 'empathy_engine.enabled') return true;
|
|
31
|
-
if (key === 'empathy_engine.dedupe_window_ms') return 60000;
|
|
32
|
-
if (key === 'empathy_engine.penalties.mild') return 10;
|
|
33
|
-
if (key === 'empathy_engine.penalties.moderate') return 25;
|
|
34
|
-
if (key === 'empathy_engine.penalties.severe') return 40;
|
|
35
|
-
if (key === 'empathy_engine.rate_limit.max_per_turn') return 40;
|
|
36
|
-
if (key === 'empathy_engine.rate_limit.max_per_hour') return 120;
|
|
37
|
-
if (key === 'empathy_engine.model_calibration') return { 'test/test': 0.5 };
|
|
38
|
-
return undefined;
|
|
39
|
-
})
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const mockEventLog = {
|
|
43
|
-
recordRuleMatch: vi.fn(),
|
|
44
|
-
recordPainSignal: vi.fn(),
|
|
45
|
-
};
|
|
46
|
-
const mockControlUiDb = {
|
|
47
|
-
getRecentThinkingContext: vi.fn().mockReturnValue({
|
|
48
|
-
toolCalls: [{ toolName: 'edit', outcome: 'failure', errorType: 'EACCES' }],
|
|
49
|
-
painEvents: [{ source: 'user_empathy', score: 13 }],
|
|
50
|
-
gateBlocks: [],
|
|
51
|
-
userCorrections: [],
|
|
52
|
-
principleEvents: [],
|
|
53
|
-
}),
|
|
54
|
-
recordThinkingModelEvent: vi.fn(),
|
|
55
|
-
dispose: vi.fn(),
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const mockWctx = {
|
|
59
|
-
workspaceDir,
|
|
60
|
-
stateDir: '/mock/workspace/.state',
|
|
61
|
-
config: mockConfig,
|
|
62
|
-
eventLog: mockEventLog,
|
|
63
|
-
trajectory: {
|
|
64
|
-
recordAssistantTurn: vi.fn().mockReturnValue(101),
|
|
65
|
-
recordPainEvent: vi.fn(),
|
|
66
|
-
},
|
|
67
|
-
resolve: vi.fn().mockImplementation((key) => {
|
|
68
|
-
if (key === 'THINKING_OS_USAGE') return path.join(workspaceDir, '.state', 'thinking_os_usage.json');
|
|
69
|
-
return '';
|
|
70
|
-
}),
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
vi.clearAllMocks();
|
|
75
|
-
sessionTracker.clearSession(sessionId);
|
|
76
|
-
vi.mocked(WorkspaceContext.fromHookContext).mockReturnValue(mockWctx as any);
|
|
77
|
-
vi.mocked(ControlUiDatabase).mockImplementation(function MockControlUiDatabase() {
|
|
78
|
-
return mockControlUiDb as any;
|
|
79
|
-
} as any);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
afterEach(() => {
|
|
83
|
-
vi.useRealTimers();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should detect confusion patterns via detection funnel (L1)', () => {
|
|
87
|
-
const mockFunnel = {
|
|
88
|
-
detect: vi.fn().mockReturnValue({
|
|
89
|
-
detected: true,
|
|
90
|
-
severity: 35,
|
|
91
|
-
ruleId: 'P_CONFUSION_EN',
|
|
92
|
-
source: 'l1_exact'
|
|
93
|
-
})
|
|
94
|
-
};
|
|
95
|
-
vi.mocked(DetectionService.get).mockReturnValue(mockFunnel as any);
|
|
96
|
-
|
|
97
|
-
const mockEvent = {
|
|
98
|
-
runId: 'r1',
|
|
99
|
-
sessionId,
|
|
100
|
-
provider: 'test',
|
|
101
|
-
assistantTexts: ['I am currently struggling to figure out why this test is failing.'],
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
handleLlmOutput(mockEvent as any, { workspaceDir, sessionId } as any);
|
|
105
|
-
|
|
106
|
-
expect(painFlags.writePainFlag).toHaveBeenCalledWith(
|
|
107
|
-
workspaceDir,
|
|
108
|
-
expect.objectContaining({
|
|
109
|
-
source: 'llm_p_confusion_en',
|
|
110
|
-
score: '35',
|
|
111
|
-
reason: expect.stringContaining('P_CONFUSION_EN')
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should track Thinking OS mental model usage when signal is detected', () => {
|
|
117
|
-
const mockFunnel = {
|
|
118
|
-
detect: vi.fn().mockReturnValue({ detected: false, source: 'l3_async_queued' })
|
|
119
|
-
};
|
|
120
|
-
vi.mocked(DetectionService.get).mockReturnValue(mockFunnel as any);
|
|
121
|
-
|
|
122
|
-
const mockEvent = {
|
|
123
|
-
runId: 'r1',
|
|
124
|
-
sessionId,
|
|
125
|
-
provider: 'test',
|
|
126
|
-
model: 'test',
|
|
127
|
-
assistantTexts: ["According to Occam's Razor, the simplest approach is best."],
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const usageLogPath = path.join(workspaceDir, '.state', 'thinking_os_usage.json');
|
|
131
|
-
|
|
132
|
-
vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
133
|
-
const mockWrite = vi.fn();
|
|
134
|
-
vi.mocked(fs.writeFileSync).mockImplementation(mockWrite);
|
|
135
|
-
|
|
136
|
-
handleLlmOutput(mockEvent as any, { workspaceDir, sessionId } as any);
|
|
137
|
-
|
|
138
|
-
expect(mockWrite).toHaveBeenCalledWith(
|
|
139
|
-
usageLogPath,
|
|
140
|
-
expect.stringContaining('"T-06": 1'),
|
|
141
|
-
'utf8'
|
|
142
|
-
);
|
|
143
|
-
expect(mockControlUiDb.recordThinkingModelEvent).toHaveBeenCalledWith(
|
|
144
|
-
expect.objectContaining({
|
|
145
|
-
modelId: 'T-06',
|
|
146
|
-
assistantTurnId: expect.any(Number),
|
|
147
|
-
})
|
|
148
|
-
);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('should parse structured empathy signal', () => {
|
|
152
|
-
const result = extractEmpathySignal('<empathy signal="damage" severity="severe" confidence="0.75" reason="ignored constraints"/>');
|
|
153
|
-
expect(result).toEqual(expect.objectContaining({
|
|
154
|
-
detected: true,
|
|
155
|
-
severity: 'severe',
|
|
156
|
-
confidence: 0.75,
|
|
157
|
-
mode: 'structured'
|
|
158
|
-
}));
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
it('should reject legacy empathy tag when embedded in regular assistant text', () => {
|
|
163
|
-
const result = extractEmpathySignal('User asked me to print [EMOTIONAL_DAMAGE_DETECTED:severe], so I echoed it.');
|
|
164
|
-
expect(result).toEqual(expect.objectContaining({
|
|
165
|
-
detected: false
|
|
166
|
-
}));
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('should NOT produce user_empathy from empathy JSON in main model output (Path 1 disabled)', () => {
|
|
170
|
-
vi.spyOn(sessionTracker, 'trackFriction').mockImplementation(() => ({ currentGfi: 0 } as any));
|
|
171
|
-
const mockFunnel = { detect: vi.fn().mockReturnValue({ detected: false, source: 'l3_async_queued' }) };
|
|
172
|
-
vi.mocked(DetectionService.get).mockReturnValue(mockFunnel as any);
|
|
173
|
-
|
|
174
|
-
const mockEvent = {
|
|
175
|
-
runId: 'r1',
|
|
176
|
-
sessionId,
|
|
177
|
-
provider: 'test',
|
|
178
|
-
model: 'test',
|
|
179
|
-
assistantTexts: ['[EMOTIONAL_DAMAGE_DETECTED:moderate]'],
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
handleLlmOutput(mockEvent as any, { workspaceDir, sessionId } as any);
|
|
183
|
-
|
|
184
|
-
expect(sessionTracker.trackFriction).not.toHaveBeenCalledWith(
|
|
185
|
-
sessionId,
|
|
186
|
-
expect.anything(),
|
|
187
|
-
expect.stringContaining('user_empathy'),
|
|
188
|
-
expect.anything(),
|
|
189
|
-
expect.anything()
|
|
190
|
-
);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should NOT produce user_empathy from structured empathy tag in main model output', () => {
|
|
194
|
-
vi.spyOn(sessionTracker, 'trackFriction').mockImplementation(() => ({ currentGfi: 0 } as any));
|
|
195
|
-
const mockFunnel = { detect: vi.fn().mockReturnValue({ detected: false, source: 'l3_async_queued' }) };
|
|
196
|
-
vi.mocked(DetectionService.get).mockReturnValue(mockFunnel as any);
|
|
197
|
-
|
|
198
|
-
const event = {
|
|
199
|
-
runId: 'same-run',
|
|
200
|
-
sessionId,
|
|
201
|
-
provider: 'test',
|
|
202
|
-
model: 'test',
|
|
203
|
-
assistantTexts: ['<empathy signal="damage" severity="severe" confidence="1" reason="reason-a"/>'],
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
handleLlmOutput(event as any, { workspaceDir, sessionId } as any);
|
|
207
|
-
|
|
208
|
-
expect(sessionTracker.trackFriction).not.toHaveBeenCalledWith(
|
|
209
|
-
sessionId,
|
|
210
|
-
expect.anything(),
|
|
211
|
-
expect.stringContaining('user_empathy'),
|
|
212
|
-
expect.anything(),
|
|
213
|
-
expect.anything()
|
|
214
|
-
);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('should filter empathy audit payloads before detection to prevent rule_match pollution', () => {
|
|
218
|
-
const mockFunnel = {
|
|
219
|
-
detect: vi.fn().mockReturnValue({ detected: false, source: 'l3_async_queued' })
|
|
220
|
-
};
|
|
221
|
-
vi.mocked(DetectionService.get).mockReturnValue(mockFunnel as any);
|
|
222
|
-
|
|
223
|
-
const mockEvent = {
|
|
224
|
-
runId: 'r1',
|
|
225
|
-
sessionId,
|
|
226
|
-
provider: 'test',
|
|
227
|
-
assistantTexts: ['{"damageDetected": true, "severity": "moderate", "confidence": 0.8, "reason": "frustration"}'],
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
handleLlmOutput(mockEvent as any, { workspaceDir, sessionId } as any);
|
|
231
|
-
|
|
232
|
-
expect(mockFunnel.detect).toHaveBeenCalledWith('');
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it('should continue pain processing when trajectory persistence fails', () => {
|
|
236
|
-
const mockFunnel = {
|
|
237
|
-
detect: vi.fn().mockReturnValue({
|
|
238
|
-
detected: true,
|
|
239
|
-
severity: 35,
|
|
240
|
-
ruleId: 'P_CONFUSION_EN',
|
|
241
|
-
source: 'l1_exact'
|
|
242
|
-
})
|
|
243
|
-
};
|
|
244
|
-
vi.mocked(DetectionService.get).mockReturnValue(mockFunnel as any);
|
|
245
|
-
mockWctx.trajectory.recordAssistantTurn.mockImplementation(() => {
|
|
246
|
-
throw new Error('db offline');
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
const logger = {
|
|
250
|
-
warn: vi.fn(),
|
|
251
|
-
info: vi.fn(),
|
|
252
|
-
error: vi.fn(),
|
|
253
|
-
debug: vi.fn(),
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
handleLlmOutput({
|
|
257
|
-
runId: 'r-fail',
|
|
258
|
-
sessionId,
|
|
259
|
-
provider: 'test',
|
|
260
|
-
model: 'test',
|
|
261
|
-
assistantTexts: ['I am currently struggling to figure out why this test is failing.'],
|
|
262
|
-
} as any, { workspaceDir, sessionId, logger } as any);
|
|
263
|
-
|
|
264
|
-
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Failed to persist assistant turn'));
|
|
265
|
-
expect(painFlags.writePainFlag).toHaveBeenCalledWith(
|
|
266
|
-
workspaceDir,
|
|
267
|
-
expect.objectContaining({
|
|
268
|
-
source: 'llm_p_confusion_en',
|
|
269
|
-
score: '35',
|
|
270
|
-
})
|
|
271
|
-
);
|
|
272
|
-
expect(mockEventLog.recordPainSignal).toHaveBeenCalledWith(
|
|
273
|
-
sessionId,
|
|
274
|
-
expect.objectContaining({
|
|
275
|
-
source: 'llm_p_confusion_en',
|
|
276
|
-
score: 35,
|
|
277
|
-
})
|
|
278
|
-
);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it('should rollback only the empathy slice when rollback tag is emitted', () => {
|
|
282
|
-
vi.spyOn(sessionTracker, 'resetFriction').mockImplementation(() => ({ currentGfi: 10 } as any));
|
|
283
|
-
const mockFunnel = { detect: vi.fn().mockReturnValue({ detected: false, source: 'l3_async_queued' }) };
|
|
284
|
-
vi.mocked(DetectionService.get).mockReturnValue(mockFunnel as any);
|
|
285
|
-
(mockEventLog as any).getLastEmpathyEventId = vi.fn().mockReturnValue('emp_rollback_1');
|
|
286
|
-
(mockEventLog as any).rollbackEmpathyEvent = vi.fn().mockReturnValue(13);
|
|
287
|
-
|
|
288
|
-
handleLlmOutput({
|
|
289
|
-
runId: 'r-rollback',
|
|
290
|
-
sessionId,
|
|
291
|
-
provider: 'test',
|
|
292
|
-
model: 'test',
|
|
293
|
-
assistantTexts: ['[EMPATHY_ROLLBACK_REQUEST]'],
|
|
294
|
-
} as any, { workspaceDir, sessionId } as any);
|
|
295
|
-
|
|
296
|
-
expect(mockEventLog.getLastEmpathyEventId).toHaveBeenCalledWith(sessionId);
|
|
297
|
-
expect(mockEventLog.rollbackEmpathyEvent).toHaveBeenCalledWith(
|
|
298
|
-
'emp_rollback_1',
|
|
299
|
-
sessionId,
|
|
300
|
-
'Natural language rollback request detected',
|
|
301
|
-
'natural_language'
|
|
302
|
-
);
|
|
303
|
-
expect(sessionTracker.resetFriction).toHaveBeenCalledWith(sessionId, workspaceDir, {
|
|
304
|
-
source: 'user_empathy',
|
|
305
|
-
amount: 13,
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
});
|
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for Progressive Trust Gate Module (EP-Only Version)
|
|
3
|
-
*
|
|
4
|
-
* 2026-03-29: EP System 是唯一的门控机制
|
|
5
|
-
* - 不再有 Trust Score (30-100) 系统
|
|
6
|
-
* - 不再有 Stage 1-4 分级
|
|
7
|
-
* - 不再有基于行数的限制
|
|
8
|
-
* - EP (Evolution Points) 是唯一的门控机制
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
12
|
-
import type { PluginHookBeforeToolCallEvent } from '../../src/openclaw-sdk.js';
|
|
13
|
-
import {
|
|
14
|
-
checkProgressiveTrustGate,
|
|
15
|
-
buildEvolutionGateReason,
|
|
16
|
-
} from '../../src/hooks/progressive-trust-gate.js';
|
|
17
|
-
import { checkEvolutionGate } from '../../src/core/evolution-engine.js';
|
|
18
|
-
|
|
19
|
-
// Mock dependencies
|
|
20
|
-
vi.mock('../../src/core/workspace-context.js', () => ({
|
|
21
|
-
WorkspaceContext: {
|
|
22
|
-
fromHookContext: vi.fn(() => mockWctx)
|
|
23
|
-
}
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
vi.mock('../../src/utils/io.js', () => ({
|
|
27
|
-
planStatus: vi.fn(() => 'READY'),
|
|
28
|
-
normalizePath: vi.fn((p) => p),
|
|
29
|
-
isRisky: vi.fn(() => false)
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
vi.mock('../../src/utils/glob-match.js', () => ({
|
|
33
|
-
matchesAnyPattern: vi.fn(() => false)
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
vi.mock('../../src/core/risk-calculator.js', () => ({
|
|
37
|
-
assessRiskLevel: vi.fn(() => 'LOW'),
|
|
38
|
-
estimateLineChanges: vi.fn(() => 10)
|
|
39
|
-
}));
|
|
40
|
-
|
|
41
|
-
vi.mock('../../src/core/evolution-engine.js', () => ({
|
|
42
|
-
checkEvolutionGate: vi.fn(() => ({ allowed: true, currentTier: 1 }))
|
|
43
|
-
}));
|
|
44
|
-
|
|
45
|
-
vi.mock('../../src/hooks/gate-block-helper.js', () => ({
|
|
46
|
-
recordGateBlockAndReturn: vi.fn((wctx, params) => ({
|
|
47
|
-
block: true,
|
|
48
|
-
blockReason: params.reason || 'Blocked'
|
|
49
|
-
}))
|
|
50
|
-
}));
|
|
51
|
-
|
|
52
|
-
// Mock workspace context - simplified for EP-only
|
|
53
|
-
const mockWctx = {
|
|
54
|
-
config: {
|
|
55
|
-
get: vi.fn(() => ({}))
|
|
56
|
-
},
|
|
57
|
-
eventLog: {
|
|
58
|
-
recordGateBlock: vi.fn(),
|
|
59
|
-
recordPlanApproval: vi.fn()
|
|
60
|
-
},
|
|
61
|
-
trajectory: {
|
|
62
|
-
recordGateBlock: vi.fn()
|
|
63
|
-
},
|
|
64
|
-
resolve: vi.fn((key) => key)
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
describe('progressive-trust-gate (EP-Only)', () => {
|
|
68
|
-
describe('checkProgressiveTrustGate - EP System', () => {
|
|
69
|
-
let mockEvent: PluginHookBeforeToolCallEvent;
|
|
70
|
-
let mockLogger: any;
|
|
71
|
-
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
mockEvent = {
|
|
74
|
-
toolName: 'edit',
|
|
75
|
-
params: {
|
|
76
|
-
file_path: '/test/file.ts',
|
|
77
|
-
content: 'test content\n'.repeat(10)
|
|
78
|
-
}
|
|
79
|
-
} as any;
|
|
80
|
-
|
|
81
|
-
mockLogger = {
|
|
82
|
-
info: vi.fn(),
|
|
83
|
-
warn: vi.fn(),
|
|
84
|
-
error: vi.fn()
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// Reset EP mock
|
|
88
|
-
vi.mocked(checkEvolutionGate).mockReturnValue({ allowed: true, currentTier: 1 });
|
|
89
|
-
|
|
90
|
-
vi.clearAllMocks();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should allow when EP system allows', () => {
|
|
94
|
-
vi.mocked(checkEvolutionGate).mockReturnValue({ allowed: true, currentTier: 1 });
|
|
95
|
-
|
|
96
|
-
const result = checkProgressiveTrustGate(
|
|
97
|
-
mockEvent,
|
|
98
|
-
mockWctx as any,
|
|
99
|
-
'/test/file.ts',
|
|
100
|
-
false,
|
|
101
|
-
100, // Even large changes are allowed by EP
|
|
102
|
-
mockLogger,
|
|
103
|
-
{ workspaceDir: '/test', sessionId: 'test-session' },
|
|
104
|
-
{}
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
// EP allows, so result should be undefined (allow)
|
|
108
|
-
expect(result).toBeUndefined();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should block when EP system denies', () => {
|
|
112
|
-
vi.mocked(checkEvolutionGate).mockReturnValue({
|
|
113
|
-
allowed: false,
|
|
114
|
-
currentTier: 1,
|
|
115
|
-
reason: 'EP Tier 1 limit: 150 lines max'
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const result = checkProgressiveTrustGate(
|
|
119
|
-
mockEvent,
|
|
120
|
-
mockWctx as any,
|
|
121
|
-
'/test/file.ts',
|
|
122
|
-
false,
|
|
123
|
-
200,
|
|
124
|
-
mockLogger,
|
|
125
|
-
{ workspaceDir: '/test', sessionId: 'test-session' },
|
|
126
|
-
{}
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
expect(result).toBeDefined();
|
|
130
|
-
expect(result?.block).toBe(true);
|
|
131
|
-
expect(result?.blockReason).toContain('EP');
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should log EP decision info', () => {
|
|
135
|
-
vi.mocked(checkEvolutionGate).mockReturnValue({ allowed: true, currentTier: 2 });
|
|
136
|
-
|
|
137
|
-
checkProgressiveTrustGate(
|
|
138
|
-
mockEvent,
|
|
139
|
-
mockWctx as any,
|
|
140
|
-
'/test/file.ts',
|
|
141
|
-
false,
|
|
142
|
-
10,
|
|
143
|
-
mockLogger,
|
|
144
|
-
{ workspaceDir: '/test', sessionId: 'test-session' },
|
|
145
|
-
{}
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
149
|
-
expect.stringContaining('EP Gate:')
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should allow risky path when EP allows', () => {
|
|
154
|
-
vi.mocked(checkEvolutionGate).mockReturnValue({
|
|
155
|
-
allowed: true,
|
|
156
|
-
currentTier: 4, // Tree tier - can access risk paths
|
|
157
|
-
reason: 'Tier 4 unlocked'
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const result = checkProgressiveTrustGate(
|
|
161
|
-
mockEvent,
|
|
162
|
-
mockWctx as any,
|
|
163
|
-
'/test/risk-path',
|
|
164
|
-
true, // risky
|
|
165
|
-
500,
|
|
166
|
-
mockLogger,
|
|
167
|
-
{ workspaceDir: '/test', sessionId: 'test-session' },
|
|
168
|
-
{}
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
expect(result).toBeUndefined();
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('should block risky path when EP denies', () => {
|
|
175
|
-
vi.mocked(checkEvolutionGate).mockReturnValue({
|
|
176
|
-
allowed: false,
|
|
177
|
-
currentTier: 2, // Sprout tier - cannot access risk paths
|
|
178
|
-
reason: 'Risk paths require Tree tier'
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const result = checkProgressiveTrustGate(
|
|
182
|
-
mockEvent,
|
|
183
|
-
mockWctx as any,
|
|
184
|
-
'/test/risk-path',
|
|
185
|
-
true, // risky
|
|
186
|
-
10,
|
|
187
|
-
mockLogger,
|
|
188
|
-
{ workspaceDir: '/test', sessionId: 'test-session' },
|
|
189
|
-
{}
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
expect(result).toBeDefined();
|
|
193
|
-
expect(result?.block).toBe(true);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('should skip check when no workspaceDir', () => {
|
|
197
|
-
const result = checkProgressiveTrustGate(
|
|
198
|
-
mockEvent,
|
|
199
|
-
mockWctx as any,
|
|
200
|
-
'/test/file.ts',
|
|
201
|
-
false,
|
|
202
|
-
10,
|
|
203
|
-
mockLogger,
|
|
204
|
-
{ sessionId: 'test-session' }, // No workspaceDir
|
|
205
|
-
{}
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
expect(result).toBeUndefined();
|
|
209
|
-
expect(mockLogger.warn).toHaveBeenCalledWith(
|
|
210
|
-
expect.stringContaining('No workspaceDir')
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('should pass correct parameters to checkEvolutionGate', () => {
|
|
215
|
-
vi.mocked(checkEvolutionGate).mockReturnValue({ allowed: true, currentTier: 1 });
|
|
216
|
-
|
|
217
|
-
checkProgressiveTrustGate(
|
|
218
|
-
mockEvent,
|
|
219
|
-
mockWctx as any,
|
|
220
|
-
'/test/file.ts',
|
|
221
|
-
true, // isRiskPath
|
|
222
|
-
100,
|
|
223
|
-
mockLogger,
|
|
224
|
-
{ workspaceDir: '/test', sessionId: 'test-session' },
|
|
225
|
-
{}
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
expect(checkEvolutionGate).toHaveBeenCalledWith('/test', {
|
|
229
|
-
toolName: 'edit',
|
|
230
|
-
isRiskPath: true,
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
describe('buildEvolutionGateReason', () => {
|
|
236
|
-
it('should build EP gate rejection reason with tier info', () => {
|
|
237
|
-
const reason = buildEvolutionGateReason(2, 'Sprout', 'Max 50 lines');
|
|
238
|
-
|
|
239
|
-
expect(reason).toContain('EP Gate');
|
|
240
|
-
expect(reason).toContain('Tier 2');
|
|
241
|
-
expect(reason).toContain('Sprout');
|
|
242
|
-
expect(reason).toContain('Max 50 lines');
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it('should handle unknown tier name', () => {
|
|
246
|
-
const reason = buildEvolutionGateReason(99, 'Unknown', 'Some restriction');
|
|
247
|
-
|
|
248
|
-
expect(reason).toContain('EP Gate');
|
|
249
|
-
expect(reason).toContain('Tier 99');
|
|
250
|
-
expect(reason).toContain('Unknown');
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
describe('EP Tier Names', () => {
|
|
255
|
-
it('should pass correct tier info to checkEvolutionGate', () => {
|
|
256
|
-
vi.mocked(checkEvolutionGate).mockReturnValue({ allowed: true, currentTier: 1 });
|
|
257
|
-
const event = { toolName: 'edit', params: { file_path: '/test.ts', content: '' } } as any;
|
|
258
|
-
const logger = { info: vi.fn() };
|
|
259
|
-
|
|
260
|
-
checkProgressiveTrustGate(
|
|
261
|
-
event,
|
|
262
|
-
mockWctx as any,
|
|
263
|
-
'/test.ts',
|
|
264
|
-
false,
|
|
265
|
-
10,
|
|
266
|
-
logger,
|
|
267
|
-
{ workspaceDir: '/test' },
|
|
268
|
-
{}
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
expect(checkEvolutionGate).toHaveBeenCalledWith('/test', {
|
|
272
|
-
toolName: 'edit',
|
|
273
|
-
isRiskPath: false,
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
});
|