forked from github/copilot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract-transcript-regression.js
More file actions
92 lines (79 loc) · 2.6 KB
/
extract-transcript-regression.js
File metadata and controls
92 lines (79 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const {
DEFAULT_FIXTURE_DIR,
buildFixtureSkeleton,
sanitizeFixtureName,
upsertFixtureBundleEntry
} = require(path.join(__dirname, 'transcript-regression-fixtures.js'));
function getArgValue(flagName) {
const index = process.argv.indexOf(flagName);
if (index >= 0 && index + 1 < process.argv.length) {
return process.argv[index + 1];
}
return null;
}
function hasFlag(flagName) {
return process.argv.includes(flagName);
}
function readTranscriptInput() {
const transcriptFile = getArgValue('--transcript-file');
if (transcriptFile) {
return {
transcript: fs.readFileSync(transcriptFile, 'utf8'),
sourceTracePath: transcriptFile
};
}
if (!process.stdin.isTTY) {
return {
transcript: fs.readFileSync(0, 'utf8'),
sourceTracePath: null
};
}
throw new Error('Provide --transcript-file <path> or pipe transcript text via stdin.');
}
function resolveOutputFile(fixtureName) {
const explicit = getArgValue('--output-file');
if (explicit) return explicit;
return path.join(DEFAULT_FIXTURE_DIR, `${sanitizeFixtureName(fixtureName || 'runtime-transcript')}.json`);
}
function main() {
const { transcript, sourceTracePath } = readTranscriptInput();
const description = getArgValue('--description') || null;
const capturedAt = getArgValue('--captured-at') || null;
const requestedName = getArgValue('--fixture-name') || null;
const skeleton = buildFixtureSkeleton({
fixtureName: requestedName,
description,
transcript,
sourceTracePath: getArgValue('--source-trace-path') || sourceTracePath,
capturedAt
});
const outputFile = resolveOutputFile(skeleton.fixtureName);
const shouldWrite = !hasFlag('--stdout-only');
if (shouldWrite) {
const stored = upsertFixtureBundleEntry(outputFile, skeleton.fixtureName, skeleton.entry, {
overwrite: hasFlag('--overwrite')
});
console.log(`Saved transcript regression fixture: ${stored.filePath}`);
}
console.log(`Fixture: ${skeleton.fixtureName}`);
console.log(`Prompts: ${skeleton.entry.prompts.length}`);
console.log(`Assistant turns: ${skeleton.entry.assistantTurns.length}`);
console.log(`Observed providers: ${(skeleton.entry.observedHeaders.providers || []).join(', ') || 'none'}`);
console.log('');
console.log(JSON.stringify({ [skeleton.fixtureName]: skeleton.entry }, null, 2));
}
if (require.main === module) {
try {
main();
} catch (error) {
console.error(error.stack || error.message);
process.exit(1);
}
}
module.exports = {
readTranscriptInput,
resolveOutputFile
};