@evolith/smart-cli 0.0.2-beta → 0.0.3-beta
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/dist/app.module.js +0 -2
- package/dist/app.module.js.map +1 -1
- package/dist/app.module.spec.d.ts +1 -0
- package/dist/app.module.spec.js +305 -0
- package/dist/app.module.spec.js.map +1 -0
- package/dist/commands/adr/adr.command.spec.d.ts +1 -0
- package/dist/commands/adr/adr.command.spec.js +409 -0
- package/dist/commands/adr/adr.command.spec.js.map +1 -0
- package/dist/commands/architecture/scaffold.command.spec.d.ts +1 -0
- package/dist/commands/architecture/scaffold.command.spec.js +207 -0
- package/dist/commands/architecture/scaffold.command.spec.js.map +1 -0
- package/dist/commands/completion/completion.command.spec.d.ts +1 -0
- package/dist/commands/completion/completion.command.spec.js +240 -0
- package/dist/commands/completion/completion.command.spec.js.map +1 -0
- package/dist/commands/docs/docs.command.spec.d.ts +1 -0
- package/dist/commands/docs/docs.command.spec.js +87 -0
- package/dist/commands/docs/docs.command.spec.js.map +1 -0
- package/dist/commands/drift/drift.command.spec.d.ts +1 -0
- package/dist/commands/drift/drift.command.spec.js +327 -0
- package/dist/commands/drift/drift.command.spec.js.map +1 -0
- package/dist/commands/history/history.command.spec.d.ts +1 -0
- package/dist/commands/history/history.command.spec.js +392 -0
- package/dist/commands/history/history.command.spec.js.map +1 -0
- package/dist/commands/init/agents.command.spec.js +398 -0
- package/dist/commands/init/agents.command.spec.js.map +1 -1
- package/dist/commands/init/init.command.spec.d.ts +1 -0
- package/dist/commands/init/init.command.spec.js +272 -0
- package/dist/commands/init/init.command.spec.js.map +1 -0
- package/dist/commands/init/upgrade.command.spec.d.ts +1 -0
- package/dist/commands/init/upgrade.command.spec.js +378 -0
- package/dist/commands/init/upgrade.command.spec.js.map +1 -0
- package/dist/commands/mcp/mcp-serve.command.spec.d.ts +1 -0
- package/dist/commands/mcp/mcp-serve.command.spec.js +58 -0
- package/dist/commands/mcp/mcp-serve.command.spec.js.map +1 -0
- package/dist/commands/sdlc/generate-domain.command.spec.d.ts +1 -0
- package/dist/commands/sdlc/generate-domain.command.spec.js +47 -0
- package/dist/commands/sdlc/generate-domain.command.spec.js.map +1 -0
- package/dist/commands/sdlc/handoff.command.spec.d.ts +1 -0
- package/dist/commands/sdlc/handoff.command.spec.js +395 -0
- package/dist/commands/sdlc/handoff.command.spec.js.map +1 -0
- package/dist/commands/sdlc/sdlc.command.spec.d.ts +1 -0
- package/dist/commands/sdlc/sdlc.command.spec.js +45 -0
- package/dist/commands/sdlc/sdlc.command.spec.js.map +1 -0
- package/dist/commands/standards/standards.command.spec.d.ts +1 -0
- package/dist/commands/standards/standards.command.spec.js +311 -0
- package/dist/commands/standards/standards.command.spec.js.map +1 -0
- package/dist/commands/validate/validate.command.spec.d.ts +1 -0
- package/dist/commands/validate/validate.command.spec.js +368 -0
- package/dist/commands/validate/validate.command.spec.js.map +1 -0
- package/dist/core/abstractions/providers/logger.provider.spec.d.ts +1 -0
- package/dist/core/abstractions/providers/logger.provider.spec.js +212 -0
- package/dist/core/abstractions/providers/logger.provider.spec.js.map +1 -0
- package/dist/core/di/container.spec.js +164 -0
- package/dist/core/di/container.spec.js.map +1 -1
- package/dist/core/mcp/metrics.service.spec.d.ts +1 -0
- package/dist/core/mcp/metrics.service.spec.js +159 -0
- package/dist/core/mcp/metrics.service.spec.js.map +1 -0
- package/dist/core/mcp/prompts/index.js +36 -0
- package/dist/core/mcp/prompts/index.js.map +1 -1
- package/dist/core/mcp/prompts/index.spec.d.ts +1 -0
- package/dist/core/mcp/prompts/index.spec.js +150 -0
- package/dist/core/mcp/prompts/index.spec.js.map +1 -0
- package/dist/core/mcp/resources/index.js +16 -0
- package/dist/core/mcp/resources/index.js.map +1 -1
- package/dist/core/mcp/resources/index.spec.d.ts +1 -0
- package/dist/core/mcp/resources/index.spec.js +212 -0
- package/dist/core/mcp/resources/index.spec.js.map +1 -0
- package/dist/core/mcp/server.d.ts +2 -1
- package/dist/core/mcp/server.js +256 -5
- package/dist/core/mcp/server.js.map +1 -1
- package/dist/core/mcp/server.spec.d.ts +1 -0
- package/dist/core/mcp/server.spec.js +563 -0
- package/dist/core/mcp/server.spec.js.map +1 -0
- package/dist/core/mcp/tools/agent.spec.d.ts +1 -0
- package/dist/core/mcp/tools/agent.spec.js +171 -0
- package/dist/core/mcp/tools/agent.spec.js.map +1 -0
- package/dist/core/mcp/tools/architecture.d.ts +2 -0
- package/dist/core/mcp/tools/architecture.js +68 -0
- package/dist/core/mcp/tools/architecture.js.map +1 -1
- package/dist/core/mcp/tools/architecture.spec.d.ts +1 -0
- package/dist/core/mcp/tools/architecture.spec.js +145 -0
- package/dist/core/mcp/tools/architecture.spec.js.map +1 -0
- package/dist/core/mcp/tools/moscow.d.ts +30 -0
- package/dist/core/mcp/tools/moscow.js +113 -0
- package/dist/core/mcp/tools/moscow.js.map +1 -0
- package/dist/core/mcp/tools/moscow.spec.d.ts +1 -0
- package/dist/core/mcp/tools/moscow.spec.js +209 -0
- package/dist/core/mcp/tools/moscow.spec.js.map +1 -0
- package/dist/core/mcp/tools/sdlc.js +2 -1
- package/dist/core/mcp/tools/sdlc.js.map +1 -1
- package/dist/core/mcp/tools/sdlc.spec.d.ts +1 -0
- package/dist/core/mcp/tools/sdlc.spec.js +170 -0
- package/dist/core/mcp/tools/sdlc.spec.js.map +1 -0
- package/dist/core/mcp/tools/validate.spec.d.ts +1 -0
- package/dist/core/mcp/tools/validate.spec.js +130 -0
- package/dist/core/mcp/tools/validate.spec.js.map +1 -0
- package/dist/core/mcp/watcher.service.spec.js +109 -8
- package/dist/core/mcp/watcher.service.spec.js.map +1 -1
- package/dist/core/observability/error-reporter.spec.d.ts +1 -0
- package/dist/core/observability/error-reporter.spec.js +291 -0
- package/dist/core/observability/error-reporter.spec.js.map +1 -0
- package/dist/core/observability/structured-logger.spec.d.ts +1 -0
- package/dist/core/observability/structured-logger.spec.js +197 -0
- package/dist/core/observability/structured-logger.spec.js.map +1 -0
- package/dist/core/observability/timing.spec.d.ts +1 -0
- package/dist/core/observability/timing.spec.js +216 -0
- package/dist/core/observability/timing.spec.js.map +1 -0
- package/dist/core/upgrade/satellite-upgrade.service.spec.js +121 -101
- package/dist/core/upgrade/satellite-upgrade.service.spec.js.map +1 -1
- package/dist/core/validators/deep-architecture-analyzer.d.ts +58 -0
- package/dist/core/validators/deep-architecture-analyzer.js +333 -0
- package/dist/core/validators/deep-architecture-analyzer.js.map +1 -0
- package/dist/core/validators/deep-architecture-analyzer.spec.d.ts +1 -0
- package/dist/core/validators/deep-architecture-analyzer.spec.js +216 -0
- package/dist/core/validators/deep-architecture-analyzer.spec.js.map +1 -0
- package/dist/core/validators/phase-gate-validator.service.js +3 -1
- package/dist/core/validators/phase-gate-validator.service.js.map +1 -1
- package/dist/core/validators/ruleset-validator-architecture.spec.js +2 -2
- package/dist/core/validators/ruleset-validator-architecture.spec.js.map +1 -1
- package/dist/core/validators/ruleset-validator.service.js +7 -7
- package/dist/core/validators/ruleset-validator.service.js.map +1 -1
- package/dist/core/validators/ruleset-validator.service.spec.js +347 -0
- package/dist/core/validators/ruleset-validator.service.spec.js.map +1 -1
- package/dist/domain/services/index.d.ts +1 -0
- package/dist/domain/services/index.js +3 -1
- package/dist/domain/services/index.js.map +1 -1
- package/dist/domain/services/moscow-prioritization.service.d.ts +44 -0
- package/dist/domain/services/moscow-prioritization.service.js +213 -0
- package/dist/domain/services/moscow-prioritization.service.js.map +1 -0
- package/dist/domain/services/moscow-prioritization.service.spec.d.ts +1 -0
- package/dist/domain/services/moscow-prioritization.service.spec.js +285 -0
- package/dist/domain/services/moscow-prioritization.service.spec.js.map +1 -0
- package/dist/domain/services/standards.service.spec.js +461 -1
- package/dist/domain/services/standards.service.spec.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const structured_logger_1 = require("./structured-logger");
|
|
4
|
+
describe('StructuredLogger', () => {
|
|
5
|
+
let logger;
|
|
6
|
+
let infoSpy;
|
|
7
|
+
let errorSpy;
|
|
8
|
+
let warnSpy;
|
|
9
|
+
let debugSpy;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
logger = new structured_logger_1.StructuredLogger({ level: structured_logger_1.LogLevel.DEBUG });
|
|
12
|
+
infoSpy = jest.spyOn(console, 'info').mockImplementation(() => { });
|
|
13
|
+
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
14
|
+
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
15
|
+
debugSpy = jest.spyOn(console, 'debug').mockImplementation(() => { });
|
|
16
|
+
});
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
infoSpy.mockRestore();
|
|
19
|
+
errorSpy.mockRestore();
|
|
20
|
+
warnSpy.mockRestore();
|
|
21
|
+
debugSpy.mockRestore();
|
|
22
|
+
});
|
|
23
|
+
describe('log levels', () => {
|
|
24
|
+
it('should log debug messages', () => {
|
|
25
|
+
logger.debug('debug message');
|
|
26
|
+
expect(debugSpy).toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
it('should log info messages', () => {
|
|
29
|
+
logger.info('info message');
|
|
30
|
+
expect(infoSpy).toHaveBeenCalled();
|
|
31
|
+
});
|
|
32
|
+
it('should log warn messages', () => {
|
|
33
|
+
logger.warn('warn message');
|
|
34
|
+
expect(warnSpy).toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
it('should log error messages', () => {
|
|
37
|
+
logger.error('error message');
|
|
38
|
+
expect(errorSpy).toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
it('should log fatal messages', () => {
|
|
41
|
+
logger.fatal('fatal message');
|
|
42
|
+
expect(errorSpy).toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
it('should respect log level filter', () => {
|
|
45
|
+
const warnLogger = new structured_logger_1.StructuredLogger({ level: structured_logger_1.LogLevel.WARN });
|
|
46
|
+
warnLogger.debug('should not appear');
|
|
47
|
+
warnLogger.info('should not appear');
|
|
48
|
+
expect(debugSpy).not.toHaveBeenCalled();
|
|
49
|
+
expect(infoSpy).not.toHaveBeenCalled();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('log formatting', () => {
|
|
53
|
+
it('should include timestamp in log output', () => {
|
|
54
|
+
logger.info('timestamp test');
|
|
55
|
+
expect(infoSpy).toHaveBeenCalledWith(expect.stringMatching(/\[\d{4}-\d{2}-\d{2}T/));
|
|
56
|
+
});
|
|
57
|
+
it('should include level name in log output', () => {
|
|
58
|
+
logger.info('level test');
|
|
59
|
+
expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('[INFO ]'));
|
|
60
|
+
});
|
|
61
|
+
it('should include operation name when set', () => {
|
|
62
|
+
logger.startOperation('test-op');
|
|
63
|
+
expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('{test-op}'));
|
|
64
|
+
});
|
|
65
|
+
it('should format context as JSON when enabled', () => {
|
|
66
|
+
logger.info('context test', { key: 'value' });
|
|
67
|
+
expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('{"key":"value"}'));
|
|
68
|
+
});
|
|
69
|
+
it('should not format context when disabled', () => {
|
|
70
|
+
const noContextLogger = new structured_logger_1.StructuredLogger({ enableContext: false });
|
|
71
|
+
noContextLogger.info('no context', { key: 'value' });
|
|
72
|
+
expect(infoSpy).not.toHaveBeenCalledWith(expect.stringContaining('{"key":"value"}'));
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe('operation tracking', () => {
|
|
76
|
+
it('should start operation', () => {
|
|
77
|
+
logger.startOperation('my-operation');
|
|
78
|
+
expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('Started: my-operation'));
|
|
79
|
+
});
|
|
80
|
+
it('should end operation with duration', () => {
|
|
81
|
+
logger.startOperation('timed-op');
|
|
82
|
+
logger.endOperation('timed-op', 100);
|
|
83
|
+
expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('Completed: timed-op'));
|
|
84
|
+
});
|
|
85
|
+
it('should handle nested operations', () => {
|
|
86
|
+
logger.startOperation('outer');
|
|
87
|
+
logger.startOperation('inner');
|
|
88
|
+
logger.info('nested test');
|
|
89
|
+
const calls = infoSpy.mock.calls;
|
|
90
|
+
const lastCall = calls[calls.length - 1][0];
|
|
91
|
+
expect(lastCall).toContain('{inner}');
|
|
92
|
+
});
|
|
93
|
+
it('should pop operation from stack when ended', () => {
|
|
94
|
+
logger.startOperation('outer');
|
|
95
|
+
logger.startOperation('inner');
|
|
96
|
+
logger.endOperation('inner', 50);
|
|
97
|
+
logger.info('after inner');
|
|
98
|
+
const calls = infoSpy.mock.calls;
|
|
99
|
+
const lastCall = calls[calls.length - 1][0];
|
|
100
|
+
expect(lastCall).toContain('{outer}');
|
|
101
|
+
});
|
|
102
|
+
it('should warn on operation mismatch', () => {
|
|
103
|
+
logger.startOperation('expected-op');
|
|
104
|
+
logger.endOperation('different-op', 50);
|
|
105
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Operation mismatch'));
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe('getBuffer', () => {
|
|
109
|
+
it('should return all log entries', () => {
|
|
110
|
+
logger.info('entry 1');
|
|
111
|
+
logger.warn('entry 2');
|
|
112
|
+
const buffer = logger.getBuffer();
|
|
113
|
+
expect(buffer).toHaveLength(2);
|
|
114
|
+
});
|
|
115
|
+
it('should return a copy of buffer', () => {
|
|
116
|
+
logger.info('entry 1');
|
|
117
|
+
const buffer = logger.getBuffer();
|
|
118
|
+
buffer.length = 0;
|
|
119
|
+
expect(logger.getBuffer()).toHaveLength(1);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
describe('clearBuffer', () => {
|
|
123
|
+
it('should clear all log entries', () => {
|
|
124
|
+
logger.info('entry 1');
|
|
125
|
+
logger.info('entry 2');
|
|
126
|
+
logger.clearBuffer();
|
|
127
|
+
expect(logger.getBuffer()).toHaveLength(0);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('setLevel', () => {
|
|
131
|
+
it('should update log level', () => {
|
|
132
|
+
logger.setLevel(structured_logger_1.LogLevel.ERROR);
|
|
133
|
+
logger.debug('should not appear');
|
|
134
|
+
logger.info('should not appear');
|
|
135
|
+
logger.error('should appear');
|
|
136
|
+
expect(debugSpy).not.toHaveBeenCalled();
|
|
137
|
+
expect(infoSpy).not.toHaveBeenCalled();
|
|
138
|
+
expect(errorSpy).toHaveBeenCalled();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe('getLastError', () => {
|
|
142
|
+
it('should return undefined when no error objects logged', () => {
|
|
143
|
+
logger.error('first error');
|
|
144
|
+
logger.error('second error');
|
|
145
|
+
const lastError = logger.getLastError();
|
|
146
|
+
expect(lastError).toBeUndefined();
|
|
147
|
+
});
|
|
148
|
+
it('should return undefined when no errors', () => {
|
|
149
|
+
logger.info('info message');
|
|
150
|
+
expect(logger.getLastError()).toBeUndefined();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe('getErrorCount', () => {
|
|
154
|
+
it('should count errors', () => {
|
|
155
|
+
logger.error('error 1');
|
|
156
|
+
logger.fatal('fatal 1');
|
|
157
|
+
logger.info('info 1');
|
|
158
|
+
expect(logger.getErrorCount()).toBe(2);
|
|
159
|
+
});
|
|
160
|
+
it('should return zero when no errors', () => {
|
|
161
|
+
logger.info('info 1');
|
|
162
|
+
logger.debug('debug 1');
|
|
163
|
+
expect(logger.getErrorCount()).toBe(0);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
describe('getWarningCount', () => {
|
|
167
|
+
it('should count warnings', () => {
|
|
168
|
+
logger.warn('warn 1');
|
|
169
|
+
logger.warn('warn 2');
|
|
170
|
+
logger.error('error 1');
|
|
171
|
+
expect(logger.getWarningCount()).toBe(2);
|
|
172
|
+
});
|
|
173
|
+
it('should return zero when no warnings', () => {
|
|
174
|
+
logger.info('info 1');
|
|
175
|
+
expect(logger.getWarningCount()).toBe(0);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe('custom config', () => {
|
|
179
|
+
it('should use custom log level', () => {
|
|
180
|
+
const customLogger = new structured_logger_1.StructuredLogger({ level: structured_logger_1.LogLevel.FATAL });
|
|
181
|
+
customLogger.error('should not appear');
|
|
182
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
183
|
+
});
|
|
184
|
+
it('should disable timestamp when configured', () => {
|
|
185
|
+
const noTimeLogger = new structured_logger_1.StructuredLogger({ enableTimestamp: false });
|
|
186
|
+
noTimeLogger.info('no time test');
|
|
187
|
+
const call = infoSpy.mock.calls[0][0];
|
|
188
|
+
expect(call).not.toMatch(/^\[\d{4}-/);
|
|
189
|
+
});
|
|
190
|
+
it('should use default config when no options', () => {
|
|
191
|
+
const defaultLogger = new structured_logger_1.StructuredLogger();
|
|
192
|
+
defaultLogger.info('default test');
|
|
193
|
+
expect(infoSpy).toHaveBeenCalled();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=structured-logger.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-logger.spec.js","sourceRoot":"","sources":["../../../src/core/observability/structured-logger.spec.ts"],"names":[],"mappings":";;AAAA,2DAAiE;AAEjE,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,MAAwB,CAAC;IAC7B,IAAI,OAAyB,CAAC;IAC9B,IAAI,QAA0B,CAAC;IAC/B,IAAI,OAAyB,CAAC;IAC9B,IAAI,QAA0B,CAAC;IAE/B,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,GAAG,IAAI,oCAAgB,CAAC,EAAE,KAAK,EAAE,4BAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;QACzD,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,G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AK,CAAC,mBAAmB,CAAC,CAAC;YAExC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAClD,MAAM,YAAY,GAAG,IAAI,oCAAgB,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;YAEtE,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAElC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;YACnD,MAAM,aAAa,GAAG,IAAI,oCAAgB,EAAE,CAAC;YAE7C,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAEnC,MAAM,CAAC,OAAO,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const timing_1 = require("./timing");
|
|
13
|
+
jest.mock('./structured-logger', () => ({
|
|
14
|
+
logger: {
|
|
15
|
+
startOperation: jest.fn(),
|
|
16
|
+
endOperation: jest.fn(),
|
|
17
|
+
error: jest.fn(),
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
const structured_logger_1 = require("./structured-logger");
|
|
21
|
+
describe('Timing utilities', () => {
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
jest.clearAllMocks();
|
|
24
|
+
});
|
|
25
|
+
describe('Timed decorator', () => {
|
|
26
|
+
it('should wrap async method and log timing', async () => {
|
|
27
|
+
class TestClass {
|
|
28
|
+
async testMethod() {
|
|
29
|
+
return 'result';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, timing_1.Timed)('test-operation'),
|
|
34
|
+
__metadata("design:type", Function),
|
|
35
|
+
__metadata("design:paramtypes", []),
|
|
36
|
+
__metadata("design:returntype", Promise)
|
|
37
|
+
], TestClass.prototype, "testMethod", null);
|
|
38
|
+
const instance = new TestClass();
|
|
39
|
+
const result = await instance.testMethod();
|
|
40
|
+
expect(result).toBe('result');
|
|
41
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('test-operation');
|
|
42
|
+
expect(structured_logger_1.logger.endOperation).toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
it('should use default operation name when not provided', async () => {
|
|
45
|
+
class TestClass {
|
|
46
|
+
async myMethod() {
|
|
47
|
+
return 42;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, timing_1.Timed)(),
|
|
52
|
+
__metadata("design:type", Function),
|
|
53
|
+
__metadata("design:paramtypes", []),
|
|
54
|
+
__metadata("design:returntype", Promise)
|
|
55
|
+
], TestClass.prototype, "myMethod", null);
|
|
56
|
+
const instance = new TestClass();
|
|
57
|
+
await instance.myMethod();
|
|
58
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('TestClass.myMethod');
|
|
59
|
+
});
|
|
60
|
+
it('should handle errors and log them', async () => {
|
|
61
|
+
class TestClass {
|
|
62
|
+
async failingMethod() {
|
|
63
|
+
throw new Error('Test error');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
__decorate([
|
|
67
|
+
(0, timing_1.Timed)('failing-operation'),
|
|
68
|
+
__metadata("design:type", Function),
|
|
69
|
+
__metadata("design:paramtypes", []),
|
|
70
|
+
__metadata("design:returntype", Promise)
|
|
71
|
+
], TestClass.prototype, "failingMethod", null);
|
|
72
|
+
const instance = new TestClass();
|
|
73
|
+
await expect(instance.failingMethod()).rejects.toThrow('Test error');
|
|
74
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('failing-operation');
|
|
75
|
+
expect(structured_logger_1.logger.error).toHaveBeenCalled();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('TimedSync decorator', () => {
|
|
79
|
+
it('should wrap sync method and log timing', () => {
|
|
80
|
+
class TestClass {
|
|
81
|
+
syncMethod() {
|
|
82
|
+
return 'sync-result';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, timing_1.TimedSync)('sync-operation'),
|
|
87
|
+
__metadata("design:type", Function),
|
|
88
|
+
__metadata("design:paramtypes", []),
|
|
89
|
+
__metadata("design:returntype", String)
|
|
90
|
+
], TestClass.prototype, "syncMethod", null);
|
|
91
|
+
const instance = new TestClass();
|
|
92
|
+
const result = instance.syncMethod();
|
|
93
|
+
expect(result).toBe('sync-result');
|
|
94
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('sync-operation');
|
|
95
|
+
expect(structured_logger_1.logger.endOperation).toHaveBeenCalled();
|
|
96
|
+
});
|
|
97
|
+
it('should use default operation name for sync methods', () => {
|
|
98
|
+
class TestClass {
|
|
99
|
+
anotherSyncMethod() {
|
|
100
|
+
return 100;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
__decorate([
|
|
104
|
+
(0, timing_1.TimedSync)(),
|
|
105
|
+
__metadata("design:type", Function),
|
|
106
|
+
__metadata("design:paramtypes", []),
|
|
107
|
+
__metadata("design:returntype", Number)
|
|
108
|
+
], TestClass.prototype, "anotherSyncMethod", null);
|
|
109
|
+
const instance = new TestClass();
|
|
110
|
+
instance.anotherSyncMethod();
|
|
111
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('TestClass.anotherSyncMethod');
|
|
112
|
+
});
|
|
113
|
+
it('should handle sync errors and log them', () => {
|
|
114
|
+
class TestClass {
|
|
115
|
+
syncFailingMethod() {
|
|
116
|
+
throw new Error('Sync error');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
__decorate([
|
|
120
|
+
(0, timing_1.TimedSync)('sync-failing'),
|
|
121
|
+
__metadata("design:type", Function),
|
|
122
|
+
__metadata("design:paramtypes", []),
|
|
123
|
+
__metadata("design:returntype", void 0)
|
|
124
|
+
], TestClass.prototype, "syncFailingMethod", null);
|
|
125
|
+
const instance = new TestClass();
|
|
126
|
+
expect(() => instance.syncFailingMethod()).toThrow('Sync error');
|
|
127
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('sync-failing');
|
|
128
|
+
expect(structured_logger_1.logger.error).toHaveBeenCalled();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
describe('measureTime', () => {
|
|
132
|
+
it('should measure async operation duration', async () => {
|
|
133
|
+
const operation = async () => 'test-result';
|
|
134
|
+
const { result, duration } = await (0, timing_1.measureTime)(operation, 'measure-test');
|
|
135
|
+
expect(result).toBe('test-result');
|
|
136
|
+
expect(duration).toBeGreaterThanOrEqual(0);
|
|
137
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('measure-test');
|
|
138
|
+
expect(structured_logger_1.logger.endOperation).toHaveBeenCalled();
|
|
139
|
+
});
|
|
140
|
+
it('should use default name for anonymous operations', async () => {
|
|
141
|
+
const operation = async () => 42;
|
|
142
|
+
await (0, timing_1.measureTime)(operation);
|
|
143
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('anonymous-operation');
|
|
144
|
+
});
|
|
145
|
+
it('should handle errors in measured operations', async () => {
|
|
146
|
+
const operation = async () => {
|
|
147
|
+
throw new Error('Measured error');
|
|
148
|
+
};
|
|
149
|
+
await expect((0, timing_1.measureTime)(operation, 'error-measure')).rejects.toThrow('Measured error');
|
|
150
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('error-measure');
|
|
151
|
+
expect(structured_logger_1.logger.error).toHaveBeenCalled();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe('measureTimeSync', () => {
|
|
155
|
+
it('should measure sync operation duration', () => {
|
|
156
|
+
const operation = () => 'sync-result';
|
|
157
|
+
const { result, duration } = (0, timing_1.measureTimeSync)(operation, 'sync-measure');
|
|
158
|
+
expect(result).toBe('sync-result');
|
|
159
|
+
expect(duration).toBeGreaterThanOrEqual(0);
|
|
160
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('sync-measure');
|
|
161
|
+
expect(structured_logger_1.logger.endOperation).toHaveBeenCalled();
|
|
162
|
+
});
|
|
163
|
+
it('should handle errors in sync operations', () => {
|
|
164
|
+
const operation = () => {
|
|
165
|
+
throw new Error('Sync measure error');
|
|
166
|
+
};
|
|
167
|
+
expect(() => (0, timing_1.measureTimeSync)(operation, 'sync-error')).toThrow('Sync measure error');
|
|
168
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('sync-error');
|
|
169
|
+
expect(structured_logger_1.logger.error).toHaveBeenCalled();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
describe('OperationTimer', () => {
|
|
173
|
+
it('should start and end timing', () => {
|
|
174
|
+
const timer = new timing_1.OperationTimer();
|
|
175
|
+
timer.start('timer-test');
|
|
176
|
+
const duration = timer.end();
|
|
177
|
+
expect(duration).toBeGreaterThanOrEqual(0);
|
|
178
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('timer-test');
|
|
179
|
+
expect(structured_logger_1.logger.endOperation).toHaveBeenCalled();
|
|
180
|
+
});
|
|
181
|
+
it('should get current duration', () => {
|
|
182
|
+
const timer = new timing_1.OperationTimer();
|
|
183
|
+
timer.start('duration-test');
|
|
184
|
+
const duration = timer.getDuration();
|
|
185
|
+
expect(duration).toBeGreaterThanOrEqual(0);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
describe('profile', () => {
|
|
189
|
+
it('should wrap async function with timing', async () => {
|
|
190
|
+
const asyncFn = async () => 'profiled-result';
|
|
191
|
+
const profiledFn = (0, timing_1.profile)(asyncFn, 'profile-test');
|
|
192
|
+
const result = await profiledFn();
|
|
193
|
+
expect(result).toBe('profiled-result');
|
|
194
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('profile-test');
|
|
195
|
+
expect(structured_logger_1.logger.endOperation).toHaveBeenCalled();
|
|
196
|
+
});
|
|
197
|
+
it('should use function name when operation name not provided', async () => {
|
|
198
|
+
async function namedFn() {
|
|
199
|
+
return 42;
|
|
200
|
+
}
|
|
201
|
+
const profiledFn = (0, timing_1.profile)(namedFn);
|
|
202
|
+
await profiledFn();
|
|
203
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('namedFn');
|
|
204
|
+
});
|
|
205
|
+
it('should handle errors in profiled functions', async () => {
|
|
206
|
+
const asyncFn = async () => {
|
|
207
|
+
throw new Error('Profile error');
|
|
208
|
+
};
|
|
209
|
+
const profiledFn = (0, timing_1.profile)(asyncFn, 'profile-error');
|
|
210
|
+
await expect(profiledFn()).rejects.toThrow('Profile error');
|
|
211
|
+
expect(structured_logger_1.logger.startOperation).toHaveBeenCalledWith('profile-error');
|
|
212
|
+
expect(structured_logger_1.logger.endOperation).toHaveBeenCalled();
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
//# sourceMappingURL=timing.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.spec.js","sourceRoot":"","sources":["../../../src/core/observability/timing.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAAmG;AAEnG,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;IACtC,MAAM,EAAE;QACN,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;QACzB,YAAY,EAAE,IAAI,CAAC,EAAE,EAAE;QACvB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;KACjB;CACF,CAAC,CAAC,CAAC;AAEJ,2DAA6C;AAE7C,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;QAC/B,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;YACvD,MAAM,SAAS;gBAEP,AAAN,KAAK,CAAC,UAAU;oBACd,OAAO,QAAQ,CAAC;gBAClB,CAAC;aACF;YAHO;gBADL,IAAA,cAAK,EAAC,gBAAgB,CAAC;;;;uDAGvB;YAGH,MAAM,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAC;YACjC,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;YAE3C,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC9B,MAAM,CAAC,0BAAM,CAAC,cAAc,CAAC,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;YACrE,MAAM,CAAC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