mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-06 21:46:40 +02:00
feat: hook eval-store sync, use shared utils, add 30 lib tests
- eval-store.ts: import shared getGitInfo/getVersion, add pushEvalRun() hook in finalize() (non-blocking, non-fatal) - session-runner.ts: import shared atomicWriteSync/sanitizeForFilename - eval-store.test.ts: fix pre-existing bug in double-finalize test (was counting _partial file) - 30 new tests for lib/util, lib/sync-config, lib/sync Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -114,7 +114,8 @@ describe('EvalCollector', () => {
|
||||
|
||||
expect(filepath1).toBeTruthy();
|
||||
expect(filepath2).toBe(''); // second call returns empty
|
||||
expect(fs.readdirSync(tmpDir).filter(f => f.endsWith('.json'))).toHaveLength(1);
|
||||
// Exclude _partial files — savePartial writes _partial-e2e.json alongside the final
|
||||
expect(fs.readdirSync(tmpDir).filter(f => f.endsWith('.json') && !f.startsWith('_partial'))).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('empty collector writes valid file', async () => {
|
||||
|
||||
+11
-17
@@ -12,6 +12,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { spawnSync } from 'child_process';
|
||||
import { getGitInfo as getGitInfoShared, getVersion as getVersionShared } from '../../lib/util';
|
||||
|
||||
const SCHEMA_VERSION = 1;
|
||||
const DEFAULT_EVAL_DIR = path.join(os.homedir(), '.gstack-dev', 'evals');
|
||||
@@ -345,26 +346,11 @@ export function formatComparison(c: ComparisonResult): string {
|
||||
// --- EvalCollector ---
|
||||
|
||||
function getGitInfo(): { branch: string; sha: string } {
|
||||
try {
|
||||
const branch = spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { stdio: 'pipe', timeout: 5000 });
|
||||
const sha = spawnSync('git', ['rev-parse', '--short', 'HEAD'], { stdio: 'pipe', timeout: 5000 });
|
||||
return {
|
||||
branch: branch.stdout?.toString().trim() || 'unknown',
|
||||
sha: sha.stdout?.toString().trim() || 'unknown',
|
||||
};
|
||||
} catch {
|
||||
return { branch: 'unknown', sha: 'unknown' };
|
||||
}
|
||||
return getGitInfoShared();
|
||||
}
|
||||
|
||||
function getVersion(): string {
|
||||
try {
|
||||
const pkgPath = path.resolve(__dirname, '..', '..', 'package.json');
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
||||
return pkg.version || 'unknown';
|
||||
} catch {
|
||||
return 'unknown';
|
||||
}
|
||||
return getVersionShared();
|
||||
}
|
||||
|
||||
export class EvalCollector {
|
||||
@@ -469,6 +455,14 @@ export class EvalCollector {
|
||||
process.stderr.write(`\nCompare error: ${err.message}\n`);
|
||||
}
|
||||
|
||||
// Team sync: push eval result (non-fatal, non-blocking)
|
||||
try {
|
||||
const { pushEvalRun } = await import('../../lib/sync');
|
||||
pushEvalRun(result as unknown as Record<string, unknown>).then(ok => {
|
||||
if (ok) process.stderr.write('Synced eval to team store ✓\n');
|
||||
}).catch(() => { /* queued for retry */ });
|
||||
} catch { /* sync module not available — skip */ }
|
||||
|
||||
return filepath;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,20 +9,13 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { atomicWriteSync, sanitizeForFilename, GSTACK_DEV_DIR } from '../../lib/util';
|
||||
|
||||
const GSTACK_DEV_DIR = path.join(os.homedir(), '.gstack-dev');
|
||||
const HEARTBEAT_PATH = path.join(GSTACK_DEV_DIR, 'e2e-live.json');
|
||||
|
||||
/** Sanitize test name for use as filename: strip leading slashes, replace / with - */
|
||||
export function sanitizeTestName(name: string): string {
|
||||
return name.replace(/^\/+/, '').replace(/\//g, '-');
|
||||
}
|
||||
|
||||
/** Atomic write: write to .tmp then rename. Non-fatal on error. */
|
||||
function atomicWriteSync(filePath: string, data: string): void {
|
||||
const tmp = filePath + '.tmp';
|
||||
fs.writeFileSync(tmp, data);
|
||||
fs.renameSync(tmp, filePath);
|
||||
return sanitizeForFilename(name);
|
||||
}
|
||||
|
||||
export interface CostEstimate {
|
||||
|
||||
Reference in New Issue
Block a user