testchimp-runner-core 0.0.25 → 0.0.28
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/CREDIT_CALLBACK_ARCHITECTURE.md +253 -0
- package/INTEGRATION_COMPLETE.md +322 -0
- package/RELEASE_0.0.26.md +165 -0
- package/RELEASE_0.0.27.md +236 -0
- package/RELEASE_0.0.28.md +286 -0
- package/dist/credit-usage-service.d.ts +28 -2
- package/dist/credit-usage-service.d.ts.map +1 -1
- package/dist/credit-usage-service.js +60 -24
- package/dist/credit-usage-service.js.map +1 -1
- package/dist/env-loader.d.ts +0 -5
- package/dist/env-loader.d.ts.map +1 -1
- package/dist/env-loader.js +0 -21
- package/dist/env-loader.js.map +1 -1
- package/dist/execution-service.d.ts.map +1 -1
- package/dist/execution-service.js +134 -10
- package/dist/execution-service.js.map +1 -1
- package/dist/index.d.ts +14 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -7
- package/dist/index.js.map +1 -1
- package/dist/progress-reporter.d.ts +30 -0
- package/dist/progress-reporter.d.ts.map +1 -1
- package/dist/prompts.js +4 -4
- package/dist/scenario-service.d.ts +1 -1
- package/dist/scenario-service.d.ts.map +1 -1
- package/dist/scenario-service.js +7 -4
- package/dist/scenario-service.js.map +1 -1
- package/dist/scenario-worker-class.d.ts +2 -10
- package/dist/scenario-worker-class.d.ts.map +1 -1
- package/dist/scenario-worker-class.js +88 -26
- package/dist/scenario-worker-class.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/credit-usage-service.ts +81 -26
- package/src/env-loader.ts +0 -22
- package/src/execution-service.ts +158 -11
- package/src/index.ts +54 -10
- package/src/progress-reporter.ts +35 -0
- package/src/prompts.ts +4 -4
- package/src/scenario-service.ts +16 -4
- package/src/scenario-worker-class.ts +102 -28
- package/src/types.ts +16 -0
- package/testchimp-runner-core-0.0.27.tgz +0 -0
- package/RELEASE_0.0.23.md +0 -120
- package/RELEASE_0.0.24.md +0 -161
|
@@ -97,8 +97,6 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
97
97
|
* Initialize orchestrator mode with tools
|
|
98
98
|
*/
|
|
99
99
|
private initializeOrchestrator(): void {
|
|
100
|
-
this.log('🤖 Initializing Orchestrator Mode');
|
|
101
|
-
|
|
102
100
|
// Create tool registry
|
|
103
101
|
this.toolRegistry = new ToolRegistry();
|
|
104
102
|
|
|
@@ -135,12 +133,12 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
135
133
|
this.debugMode // Pass debug mode
|
|
136
134
|
);
|
|
137
135
|
|
|
138
|
-
|
|
136
|
+
// Minimal initialization logging - internal details not needed by consumer
|
|
139
137
|
}
|
|
140
138
|
|
|
141
139
|
private log(message: string): void {
|
|
142
|
-
|
|
143
|
-
const formattedMessage = `[
|
|
140
|
+
// Let consumer add timestamps - just report the raw message
|
|
141
|
+
const formattedMessage = `[ScenarioWorker] ${message}`;
|
|
144
142
|
// Always log to console for debug visibility
|
|
145
143
|
console.log(formattedMessage);
|
|
146
144
|
// Also route to outputChannel if provided
|
|
@@ -150,8 +148,8 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
private logError(message: string): void {
|
|
153
|
-
|
|
154
|
-
const formattedMessage = `[
|
|
151
|
+
// Let consumer add timestamps - just report the raw message
|
|
152
|
+
const formattedMessage = `[ScenarioWorker] ERROR: ${message}`;
|
|
155
153
|
// Always log to console for debug visibility
|
|
156
154
|
console.error(formattedMessage);
|
|
157
155
|
// Also route to outputChannel if provided
|
|
@@ -246,21 +244,16 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
246
244
|
|
|
247
245
|
async initialize(): Promise<void> {
|
|
248
246
|
try {
|
|
249
|
-
const RUNNER_CORE_VERSION = "v1.5.0-vision-preserve-values";
|
|
250
|
-
this.log('═══════════════════════════════════════════════════════');
|
|
251
|
-
this.log(`🚀 RUNNER-CORE VERSION: ${RUNNER_CORE_VERSION}`);
|
|
252
|
-
this.log('═══════════════════════════════════════════════════════');
|
|
253
|
-
this.log('Initializing Scenario worker...');
|
|
254
247
|
this.sessionId = `scenario_worker_${Date.now()}`;
|
|
255
248
|
this.initialized = true;
|
|
256
|
-
|
|
249
|
+
// Minimal initialization - consumer doesn't need to see internal details
|
|
257
250
|
} catch (error) {
|
|
258
251
|
this.logError(`Scenario worker initialization error: ${error}`);
|
|
259
252
|
throw error;
|
|
260
253
|
}
|
|
261
254
|
}
|
|
262
255
|
|
|
263
|
-
async processScenarioJob(job:
|
|
256
|
+
async processScenarioJob(job: ScenarioRunJob): Promise<ScenarioResponse> {
|
|
264
257
|
if (!this.initialized) {
|
|
265
258
|
throw new Error('Scenario worker not initialized');
|
|
266
259
|
}
|
|
@@ -268,9 +261,9 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
268
261
|
// Set current job ID for progress reporting
|
|
269
262
|
this.currentJobId = job.id;
|
|
270
263
|
|
|
271
|
-
//
|
|
272
|
-
const
|
|
273
|
-
this.log(
|
|
264
|
+
// Log library version once (read from package.json)
|
|
265
|
+
const packageJson = require('../package.json');
|
|
266
|
+
this.log(`testchimp-runner-core v${packageJson.version}`);
|
|
274
267
|
this.log(`📋 Processing scenario: ${job.scenario}`);
|
|
275
268
|
|
|
276
269
|
const startTime = Date.now();
|
|
@@ -310,16 +303,30 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
310
303
|
}
|
|
311
304
|
this.emit('log', job.id, `\n## Execution Progress\n\n`);
|
|
312
305
|
|
|
313
|
-
// 2. Start a new browser session
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
306
|
+
// 2. Start a new browser session or use existing one
|
|
307
|
+
if (job.existingBrowser && job.existingContext && job.existingPage) {
|
|
308
|
+
// Use existing browser provided by caller (e.g., scriptservice)
|
|
309
|
+
this.log('Using existing browser/page provided by caller');
|
|
310
|
+
browser = job.existingBrowser;
|
|
311
|
+
context = job.existingContext;
|
|
312
|
+
page = job.existingPage;
|
|
313
|
+
} else {
|
|
314
|
+
// Create new browser (default behavior for local clients)
|
|
315
|
+
// Default to headed mode (headless: false) for better debugging
|
|
316
|
+
// Create logger function from outputChannel for browser initialization
|
|
317
|
+
const logger = this.outputChannel ? (message: string, level?: 'log' | 'error' | 'warn') => {
|
|
318
|
+
this.outputChannel!.appendLine(`[Browser] ${message}`);
|
|
319
|
+
} : undefined;
|
|
320
|
+
const browserInstance = await initializeBrowser(job.playwrightConfig, false, undefined, logger);
|
|
321
|
+
browser = browserInstance.browser;
|
|
322
|
+
context = browserInstance.context;
|
|
323
|
+
page = browserInstance.page;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// LIFECYCLE: Call beforeStartTest if provided
|
|
327
|
+
if (this.progressReporter?.beforeStartTest) {
|
|
328
|
+
await this.progressReporter.beforeStartTest(page, browser, context);
|
|
329
|
+
}
|
|
323
330
|
|
|
324
331
|
// Set reasonable timeout for most operations
|
|
325
332
|
// 5 seconds for element interactions (fast feedback on wrong selectors)
|
|
@@ -367,6 +374,17 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
367
374
|
step.stepNumber = i + 1;
|
|
368
375
|
|
|
369
376
|
try {
|
|
377
|
+
// LIFECYCLE: Call beforeStepStart if provided
|
|
378
|
+
if (this.progressReporter?.beforeStepStart) {
|
|
379
|
+
await this.progressReporter.beforeStepStart(
|
|
380
|
+
{
|
|
381
|
+
stepNumber: step.stepNumber,
|
|
382
|
+
description: step.description
|
|
383
|
+
},
|
|
384
|
+
page
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
370
388
|
// Use orchestrator to execute this step
|
|
371
389
|
const result = await this.orchestratorAgent.executeStep(
|
|
372
390
|
page,
|
|
@@ -405,6 +423,18 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
405
423
|
}
|
|
406
424
|
}
|
|
407
425
|
|
|
426
|
+
// REPORT FINAL STEP RESULT (after orchestrator completes all iterations)
|
|
427
|
+
// This gives the complete accumulated commands, not just one iteration
|
|
428
|
+
await this.reportStepProgress({
|
|
429
|
+
jobId: job.id,
|
|
430
|
+
stepNumber: step.stepNumber,
|
|
431
|
+
description: step.description,
|
|
432
|
+
code: step.playwrightCommands?.join('\n') || '', // All accumulated commands
|
|
433
|
+
status: step.success ? StepExecutionStatus.SUCCESS : StepExecutionStatus.FAILURE,
|
|
434
|
+
error: step.error,
|
|
435
|
+
agentIteration: result.iterations
|
|
436
|
+
});
|
|
437
|
+
|
|
408
438
|
} catch (error: any) {
|
|
409
439
|
this.logError(`Orchestrator execution failed for step ${step.stepNumber}: ${error.message}`);
|
|
410
440
|
step.success = false;
|
|
@@ -858,7 +888,17 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
858
888
|
}
|
|
859
889
|
|
|
860
890
|
// Generate clean script with TestChimp comment and code
|
|
891
|
+
this.log(`[ScenarioWorker] Generating script from ${steps.length} steps`);
|
|
892
|
+
steps.forEach((s, i) => {
|
|
893
|
+
this.log(`[ScenarioWorker] Step ${i+1}: ${s.description}`);
|
|
894
|
+
this.log(`[ScenarioWorker] Commands: ${s.playwrightCommands?.length || 0}`);
|
|
895
|
+
if (s.playwrightCommands && s.playwrightCommands.length > 0) {
|
|
896
|
+
this.log(`[ScenarioWorker] First command: ${s.playwrightCommands[0]}`);
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
|
|
861
900
|
generatedScript = generateTestScript(testName, steps, undefined, hashtags);
|
|
901
|
+
this.log(`[ScenarioWorker] Generated script length: ${generatedScript.length}`);
|
|
862
902
|
|
|
863
903
|
// Perform final cleanup pass to remove redundancies and make minor adjustments
|
|
864
904
|
this.log(`[ScenarioWorker] Performing final script cleanup...`);
|
|
@@ -931,6 +971,15 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
931
971
|
|
|
932
972
|
const executionLog = logLines.join('\n');
|
|
933
973
|
|
|
974
|
+
// Report job completion
|
|
975
|
+
await this.reportJobProgress({
|
|
976
|
+
jobId: job.id,
|
|
977
|
+
status: overallSuccess ? 'completed' : 'failed',
|
|
978
|
+
testName,
|
|
979
|
+
script: generatedScript,
|
|
980
|
+
error: overallSuccess ? undefined : 'Some steps failed during execution'
|
|
981
|
+
});
|
|
982
|
+
|
|
934
983
|
return {
|
|
935
984
|
success: overallSuccess,
|
|
936
985
|
steps,
|
|
@@ -944,6 +993,16 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
944
993
|
} catch (error: any) {
|
|
945
994
|
overallSuccess = false;
|
|
946
995
|
this.logError(`Overall scenario processing error: ${error}`);
|
|
996
|
+
|
|
997
|
+
// Report job failure
|
|
998
|
+
await this.reportJobProgress({
|
|
999
|
+
jobId: job.id,
|
|
1000
|
+
status: 'failed',
|
|
1001
|
+
testName: job.testName || 'test',
|
|
1002
|
+
script: generatedScript,
|
|
1003
|
+
error: error instanceof Error ? error.message : 'Unknown error during scenario processing'
|
|
1004
|
+
});
|
|
1005
|
+
|
|
947
1006
|
return {
|
|
948
1007
|
success: false,
|
|
949
1008
|
steps,
|
|
@@ -955,7 +1014,22 @@ export class ScenarioWorker extends EventEmitter {
|
|
|
955
1014
|
error: error instanceof Error ? error.message : 'Unknown error during scenario processing'
|
|
956
1015
|
};
|
|
957
1016
|
} finally {
|
|
958
|
-
if
|
|
1017
|
+
// LIFECYCLE: Call afterEndTest if provided
|
|
1018
|
+
if (browser && this.progressReporter?.afterEndTest) {
|
|
1019
|
+
try {
|
|
1020
|
+
await this.progressReporter.afterEndTest(
|
|
1021
|
+
overallSuccess ? 'passed' : 'failed',
|
|
1022
|
+
overallSuccess ? undefined : 'Test execution had failures',
|
|
1023
|
+
page
|
|
1024
|
+
);
|
|
1025
|
+
} catch (callbackError) {
|
|
1026
|
+
this.log(`afterEndTest callback failed: ${callbackError}`);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// Only close browser if we created it (not provided by caller)
|
|
1031
|
+
const usingExternalBrowser = !!(job.existingBrowser && job.existingContext && job.existingPage);
|
|
1032
|
+
if (browser && !usingExternalBrowser) {
|
|
959
1033
|
await browser.close();
|
|
960
1034
|
}
|
|
961
1035
|
}
|
package/src/types.ts
CHANGED
|
@@ -83,6 +83,11 @@ export interface ScenarioRunJob {
|
|
|
83
83
|
playwrightConfig?: PlaywrightConfig;
|
|
84
84
|
model?: string;
|
|
85
85
|
scenarioFileName?: string;
|
|
86
|
+
|
|
87
|
+
// Optional: Provide existing browser/page/context (for server-side usage)
|
|
88
|
+
existingBrowser?: any;
|
|
89
|
+
existingContext?: any;
|
|
90
|
+
existingPage?: any;
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
/**
|
|
@@ -139,6 +144,11 @@ export interface ScenarioJob {
|
|
|
139
144
|
config?: PlaywrightConfig;
|
|
140
145
|
resolve: (result: ScenarioResponse) => void;
|
|
141
146
|
reject: (error: Error) => void;
|
|
147
|
+
|
|
148
|
+
// Optional: Provide existing browser/page/context (for server-side usage)
|
|
149
|
+
existingBrowser?: any;
|
|
150
|
+
existingContext?: any;
|
|
151
|
+
existingPage?: any;
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
// ============================================================================
|
|
@@ -166,6 +176,12 @@ export interface ScriptExecutionRequest {
|
|
|
166
176
|
model?: string;
|
|
167
177
|
headless?: boolean; // defaults to false (headed)
|
|
168
178
|
deflake_run_count?: number; // defaults to 1
|
|
179
|
+
|
|
180
|
+
// Optional: Provide existing browser/page/context (for server-side usage)
|
|
181
|
+
// If not provided, runner-core will create its own
|
|
182
|
+
existingBrowser?: any; // Browser instance
|
|
183
|
+
existingContext?: any; // BrowserContext instance
|
|
184
|
+
existingPage?: any; // Page instance
|
|
169
185
|
}
|
|
170
186
|
|
|
171
187
|
/**
|
|
Binary file
|
package/RELEASE_0.0.23.md
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
# Release 0.0.23 - Published to npm
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
Published `testchimp-runner-core@0.0.23` to npm registry and updated `testchimp-vs-extension` to use the published package instead of local file references.
|
|
5
|
-
|
|
6
|
-
## Changes in 0.0.23
|
|
7
|
-
|
|
8
|
-
### New Features
|
|
9
|
-
1. **Script Cleanup Feature** - Final LLM-based cleanup pass to remove redundancies
|
|
10
|
-
2. **Semantic Selector Preference** - Prioritize getByRole, getByLabel, etc. over auto-generated IDs
|
|
11
|
-
3. **Playwright Expect Assertions** - Use expect() for verifications instead of manual checks
|
|
12
|
-
4. **Focused Step Execution** - Only execute what's explicitly asked in each step
|
|
13
|
-
|
|
14
|
-
### Improvements
|
|
15
|
-
1. Enhanced selector generation priority in page-info-utils
|
|
16
|
-
2. Improved orchestrator prompts for better code quality
|
|
17
|
-
3. Fixed comment placement in generated scripts
|
|
18
|
-
4. Made expect() available in command execution context
|
|
19
|
-
5. Added comprehensive guidance to avoid extra assertions
|
|
20
|
-
|
|
21
|
-
### Bug Fixes
|
|
22
|
-
1. Fixed duplicate/orphaned comments in generated scripts
|
|
23
|
-
2. Removed self-dependency from package.json
|
|
24
|
-
3. Fixed comment ordering (now always appears before code)
|
|
25
|
-
|
|
26
|
-
## Publishing Details
|
|
27
|
-
|
|
28
|
-
### Version Update
|
|
29
|
-
- **Previous:** 0.0.22 (local tarball)
|
|
30
|
-
- **Current:** 0.0.23 (npm published)
|
|
31
|
-
- **Registry:** https://registry.npmjs.org/
|
|
32
|
-
- **Package Size:** 14.0 MB
|
|
33
|
-
- **Unpacked Size:** 14.8 MB
|
|
34
|
-
- **Files:** 166
|
|
35
|
-
|
|
36
|
-
### Package Changes
|
|
37
|
-
**runner-core/package.json:**
|
|
38
|
-
- Updated version from 0.0.22 → 0.0.23
|
|
39
|
-
- Removed self-dependency on testchimp-runner-core
|
|
40
|
-
|
|
41
|
-
**vs-ext/package.json:**
|
|
42
|
-
- Changed from: `"testchimp-runner-core": "file:testchimp-runner-core-0.0.22.tgz"`
|
|
43
|
-
- Changed to: `"testchimp-runner-core": "^0.0.23"`
|
|
44
|
-
|
|
45
|
-
### Cleanup Performed
|
|
46
|
-
- Removed all local .tgz tarball files
|
|
47
|
-
- Removed testchimp-runner-core@0.0.22 directory from vs-ext
|
|
48
|
-
- Clean installation from npm registry
|
|
49
|
-
|
|
50
|
-
## Verification
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
$ npm list testchimp-runner-core
|
|
54
|
-
testchimp-vs-extension@0.0.8
|
|
55
|
-
└── testchimp-runner-core@0.0.23
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
✅ **vs-ext successfully using published npm package**
|
|
59
|
-
|
|
60
|
-
## Build Status
|
|
61
|
-
|
|
62
|
-
✅ **runner-core**
|
|
63
|
-
- Clean build successful
|
|
64
|
-
- TypeScript compilation: ✓
|
|
65
|
-
- Published to npm: ✓
|
|
66
|
-
|
|
67
|
-
✅ **vs-ext**
|
|
68
|
-
- Dependencies installed from npm: ✓
|
|
69
|
-
- Webpack production build: ✓ (492 KiB)
|
|
70
|
-
- Extension bundle: Ready
|
|
71
|
-
|
|
72
|
-
## Benefits of npm Publishing
|
|
73
|
-
|
|
74
|
-
### For Development
|
|
75
|
-
1. **Version Control** - Clear versioning in package.json
|
|
76
|
-
2. **Dependency Management** - Standard npm workflow
|
|
77
|
-
3. **Faster Installs** - No need to rebuild tarball
|
|
78
|
-
4. **Better CI/CD** - Can reference specific versions
|
|
79
|
-
|
|
80
|
-
### For Distribution
|
|
81
|
-
1. **Public Access** - Anyone can install via npm
|
|
82
|
-
2. **Version History** - All versions tracked on npm
|
|
83
|
-
3. **Automatic Updates** - Use semver ranges (^0.0.23)
|
|
84
|
-
4. **No Local Files** - Cleaner repository
|
|
85
|
-
|
|
86
|
-
## Next Steps
|
|
87
|
-
|
|
88
|
-
### For Future Releases
|
|
89
|
-
1. Update version in runner-core/package.json
|
|
90
|
-
2. Build: `npm run build`
|
|
91
|
-
3. Publish: `npm publish`
|
|
92
|
-
4. Update vs-ext dependency to new version
|
|
93
|
-
5. Install and rebuild vs-ext
|
|
94
|
-
|
|
95
|
-
### Deployment
|
|
96
|
-
The vs-ext can now be:
|
|
97
|
-
- Packaged as .vsix with the npm-installed dependency
|
|
98
|
-
- Distributed without including runner-core tarball
|
|
99
|
-
- Updated independently by bumping the version range
|
|
100
|
-
|
|
101
|
-
## Documentation
|
|
102
|
-
|
|
103
|
-
All features are documented in:
|
|
104
|
-
- `plandocs/SELECTOR_IMPROVEMENTS.md` - Selector preference strategy
|
|
105
|
-
- `plandocs/SCRIPT_CLEANUP_FEATURE.md` - Cleanup feature details
|
|
106
|
-
- This file - Release notes
|
|
107
|
-
|
|
108
|
-
## Breaking Changes
|
|
109
|
-
|
|
110
|
-
None. All changes are backward compatible.
|
|
111
|
-
|
|
112
|
-
## Migration Notes
|
|
113
|
-
|
|
114
|
-
For anyone using testchimp-runner-core@0.0.22:
|
|
115
|
-
1. Update package.json to: `"testchimp-runner-core": "^0.0.23"`
|
|
116
|
-
2. Run: `npm install`
|
|
117
|
-
3. Rebuild your project
|
|
118
|
-
|
|
119
|
-
No code changes required - all improvements are in the core library.
|
|
120
|
-
|
package/RELEASE_0.0.24.md
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
# Release 0.0.24 - Suppress Token Usage Logs in Staging/Production
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
Token usage logs are now suppressed in staging and production environments to reduce noise in production logs. Detailed token usage information is only shown in development mode (localhost).
|
|
5
|
-
|
|
6
|
-
## Changes in 0.0.24
|
|
7
|
-
|
|
8
|
-
### Environment-Aware Logging
|
|
9
|
-
Added intelligent environment detection to suppress verbose logs in production environments:
|
|
10
|
-
|
|
11
|
-
1. **New Function: `isDevelopmentMode()`** (`env-loader.ts`)
|
|
12
|
-
- Detects if running in development mode based on:
|
|
13
|
-
- Backend URL contains `localhost` or `127.0.0.1`
|
|
14
|
-
- `NODE_ENV` is explicitly set to `'development'`
|
|
15
|
-
- Returns `false` for staging/production (safe default)
|
|
16
|
-
|
|
17
|
-
2. **Suppressed Logs in Production**
|
|
18
|
-
- Token usage logs: `💰 Reporting token usage: X + Y`
|
|
19
|
-
- Missing usage data warnings: `⚠ No usage data in LLM response`
|
|
20
|
-
- These logs still appear when running locally for debugging
|
|
21
|
-
|
|
22
|
-
### Implementation Details
|
|
23
|
-
|
|
24
|
-
**env-loader.ts:**
|
|
25
|
-
```typescript
|
|
26
|
-
export function isDevelopmentMode(): boolean {
|
|
27
|
-
try {
|
|
28
|
-
const config = loadEnvConfig();
|
|
29
|
-
const backendUrl = config.TESTCHIMP_BACKEND_URL || '';
|
|
30
|
-
|
|
31
|
-
// Development mode if:
|
|
32
|
-
// 1. Backend URL contains localhost or 127.0.0.1
|
|
33
|
-
// 2. NODE_ENV is explicitly set to 'development'
|
|
34
|
-
const isLocalhost = backendUrl.includes('localhost') || backendUrl.includes('127.0.0.1');
|
|
35
|
-
const isDevEnv = process.env.NODE_ENV === 'development';
|
|
36
|
-
|
|
37
|
-
return isLocalhost || isDevEnv;
|
|
38
|
-
} catch (error) {
|
|
39
|
-
// If we can't determine, assume production (suppress logs)
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
**orchestrator-agent.ts:**
|
|
46
|
-
```typescript
|
|
47
|
-
// Only log token usage in development mode
|
|
48
|
-
if (isDevelopmentMode()) {
|
|
49
|
-
this.logger?.(`[Orchestrator] 💰 Reporting token usage: ${tokenUsage.inputTokens} + ${tokenUsage.outputTokens}`, 'log');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Only log missing usage data in development mode
|
|
53
|
-
else if (!response.usage && isDevelopmentMode()) {
|
|
54
|
-
this.logger?.(`[Orchestrator] ⚠ No usage data in LLM response`, 'warn');
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
## Environment Detection Logic
|
|
59
|
-
|
|
60
|
-
### Development Mode (logs shown)
|
|
61
|
-
- Backend URL: `http://localhost:*` or `http://127.0.0.1:*`
|
|
62
|
-
- OR `NODE_ENV=development`
|
|
63
|
-
|
|
64
|
-
### Staging/Production (logs suppressed)
|
|
65
|
-
- env.staging: `https://featureservice-staging.testchimp.io`
|
|
66
|
-
- env.prod: `https://featureservice.testchimp.io`
|
|
67
|
-
|
|
68
|
-
## Benefits
|
|
69
|
-
|
|
70
|
-
1. **Cleaner Production Logs** - No verbose token usage logs in staging/prod
|
|
71
|
-
2. **Better User Experience** - Users don't see internal debugging information
|
|
72
|
-
3. **Still Debug-Friendly** - Developers still see all logs when running locally
|
|
73
|
-
4. **Safe Defaults** - If environment can't be determined, assume production (suppress logs)
|
|
74
|
-
5. **Token Tracking Still Works** - `progressReporter.onTokensUsed()` is still called regardless of logging
|
|
75
|
-
|
|
76
|
-
## What Still Happens in Production
|
|
77
|
-
|
|
78
|
-
Even though logs are suppressed, the following still works:
|
|
79
|
-
- ✅ Token usage is tracked via `progressReporter.onTokensUsed()`
|
|
80
|
-
- ✅ Token metrics are sent to backend
|
|
81
|
-
- ✅ All functionality remains unchanged
|
|
82
|
-
- ✅ Error logs and warnings (non-token-related) still appear
|
|
83
|
-
|
|
84
|
-
## What's Suppressed in Production
|
|
85
|
-
|
|
86
|
-
Only these specific verbose logs are hidden:
|
|
87
|
-
- ❌ `💰 Reporting token usage: X + Y`
|
|
88
|
-
- ❌ `⚠ No usage data in LLM response`
|
|
89
|
-
|
|
90
|
-
## Testing
|
|
91
|
-
|
|
92
|
-
### Local Development
|
|
93
|
-
```bash
|
|
94
|
-
# Backend URL will be localhost
|
|
95
|
-
# OR NODE_ENV=development
|
|
96
|
-
# Result: Token usage logs VISIBLE
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Staging
|
|
100
|
-
```bash
|
|
101
|
-
# env.staging: https://featureservice-staging.testchimp.io
|
|
102
|
-
# Result: Token usage logs HIDDEN
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Production
|
|
106
|
-
```bash
|
|
107
|
-
# env.prod: https://featureservice.testchimp.io
|
|
108
|
-
# Result: Token usage logs HIDDEN
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Migration
|
|
112
|
-
|
|
113
|
-
No code changes required. Simply update to `^0.0.24`:
|
|
114
|
-
|
|
115
|
-
```json
|
|
116
|
-
{
|
|
117
|
-
"dependencies": {
|
|
118
|
-
"testchimp-runner-core": "^0.0.24"
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Files Modified
|
|
124
|
-
|
|
125
|
-
1. `/src/env-loader.ts` - Added `isDevelopmentMode()` function
|
|
126
|
-
2. `/src/orchestrator/orchestrator-agent.ts` - Added environment checks to token usage logs
|
|
127
|
-
|
|
128
|
-
## Backward Compatibility
|
|
129
|
-
|
|
130
|
-
✅ Fully backward compatible - no breaking changes
|
|
131
|
-
✅ All functionality preserved
|
|
132
|
-
✅ Only logging behavior changed
|
|
133
|
-
|
|
134
|
-
## Version History
|
|
135
|
-
|
|
136
|
-
- **0.0.24** - Environment-aware token usage logging
|
|
137
|
-
- **0.0.23** - Script cleanup feature, semantic selectors, expect() assertions
|
|
138
|
-
- **0.0.22** - Previous version (local tarball)
|
|
139
|
-
|
|
140
|
-
## Published to npm
|
|
141
|
-
|
|
142
|
-
```
|
|
143
|
-
✅ Published: testchimp-runner-core@0.0.24
|
|
144
|
-
📦 Package Size: 243.4 kB (significantly smaller!)
|
|
145
|
-
📋 Registry: https://registry.npmjs.org/
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
## Next Steps
|
|
149
|
-
|
|
150
|
-
For future releases, any verbose development logs should use:
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
import { isDevelopmentMode } from '../env-loader';
|
|
154
|
-
|
|
155
|
-
if (isDevelopmentMode()) {
|
|
156
|
-
this.logger?.('Detailed debug information', 'log');
|
|
157
|
-
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
This ensures production logs stay clean while maintaining full debugging capabilities for local development.
|
|
161
|
-
|