docs: enterprise refactor plan with ralph specs
This commit is contained in:
30
src/plugins/collectors/DOMSnapshotCollector.ts
Normal file
30
src/plugins/collectors/DOMSnapshotCollector.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* DOMSnapshotCollector — writes the DOM snapshot at anomaly moment to disk.
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { IAnomaly, IAnomalyEvidence } from '../../core/interfaces';
|
||||
import { ICollector, IInteractionAgent } from '../interfaces';
|
||||
|
||||
interface HasCaptureState {
|
||||
captureState(): Promise<{ domSnapshot: string }>;
|
||||
}
|
||||
|
||||
export class DOMSnapshotCollector implements ICollector {
|
||||
readonly name = 'DOMSnapshotCollector';
|
||||
|
||||
constructor(private readonly outputDir: string = './reports') {}
|
||||
|
||||
async collect(anomaly: IAnomaly, agent: IInteractionAgent): Promise<IAnomalyEvidence> {
|
||||
const state = await (agent as HasCaptureState).captureState();
|
||||
|
||||
const dir = path.join(this.outputDir, anomaly.id);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
|
||||
const domPath = path.join(dir, 'dom.html');
|
||||
fs.writeFileSync(domPath, state.domSnapshot, 'utf8');
|
||||
|
||||
return { domSnapshotPath: path.relative(this.outputDir, domPath) };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user