mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-03-30 13:43:26 +08:00
feat: deliver v1.8.0 harness reliability and parity updates
This commit is contained in:
@@ -21,7 +21,12 @@ const {
|
||||
buildPrompt,
|
||||
askClaude,
|
||||
isValidSessionName,
|
||||
handleClear
|
||||
handleClear,
|
||||
getSessionMetrics,
|
||||
searchSessions,
|
||||
branchSession,
|
||||
exportSession,
|
||||
compactSession
|
||||
} = require(path.join(__dirname, '..', '..', 'scripts', 'claw.js'));
|
||||
|
||||
// Test helper — matches ECC's custom test pattern
|
||||
@@ -229,6 +234,92 @@ function runTests() {
|
||||
assert.strictEqual(isValidSessionName(undefined), false);
|
||||
})) passed++; else failed++;
|
||||
|
||||
console.log('\nNanoClaw v2:');
|
||||
|
||||
if (test('getSessionMetrics returns non-zero token estimate for populated history', () => {
|
||||
const tmpDir = makeTmpDir();
|
||||
const filePath = path.join(tmpDir, 'metrics.md');
|
||||
try {
|
||||
appendTurn(filePath, 'User', 'Implement auth');
|
||||
appendTurn(filePath, 'Assistant', 'Working on it');
|
||||
const metrics = getSessionMetrics(filePath);
|
||||
assert.strictEqual(metrics.turns, 2);
|
||||
assert.ok(metrics.tokenEstimate > 0);
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('searchSessions finds query in saved session', () => {
|
||||
const tmpDir = makeTmpDir();
|
||||
const originalHome = process.env.HOME;
|
||||
process.env.HOME = tmpDir;
|
||||
try {
|
||||
const sessionPath = path.join(tmpDir, '.claude', 'claw', 'alpha.md');
|
||||
fs.mkdirSync(path.dirname(sessionPath), { recursive: true });
|
||||
appendTurn(sessionPath, 'User', 'Need oauth migration');
|
||||
const results = searchSessions('oauth');
|
||||
assert.strictEqual(results.length, 1);
|
||||
assert.strictEqual(results[0].session, 'alpha');
|
||||
} finally {
|
||||
process.env.HOME = originalHome;
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('branchSession copies history into new branch session', () => {
|
||||
const tmpDir = makeTmpDir();
|
||||
const originalHome = process.env.HOME;
|
||||
process.env.HOME = tmpDir;
|
||||
try {
|
||||
const source = path.join(tmpDir, '.claude', 'claw', 'base.md');
|
||||
fs.mkdirSync(path.dirname(source), { recursive: true });
|
||||
appendTurn(source, 'User', 'base content');
|
||||
const result = branchSession(source, 'feature-branch');
|
||||
assert.strictEqual(result.ok, true);
|
||||
const branched = fs.readFileSync(result.path, 'utf8');
|
||||
assert.ok(branched.includes('base content'));
|
||||
} finally {
|
||||
process.env.HOME = originalHome;
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('exportSession writes JSON export', () => {
|
||||
const tmpDir = makeTmpDir();
|
||||
const filePath = path.join(tmpDir, 'export.md');
|
||||
const outPath = path.join(tmpDir, 'export.json');
|
||||
try {
|
||||
appendTurn(filePath, 'User', 'hello');
|
||||
appendTurn(filePath, 'Assistant', 'world');
|
||||
const result = exportSession(filePath, 'json', outPath);
|
||||
assert.strictEqual(result.ok, true);
|
||||
const exported = JSON.parse(fs.readFileSync(outPath, 'utf8'));
|
||||
assert.strictEqual(Array.isArray(exported.turns), true);
|
||||
assert.strictEqual(exported.turns.length, 2);
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('compactSession reduces long histories', () => {
|
||||
const tmpDir = makeTmpDir();
|
||||
const filePath = path.join(tmpDir, 'compact.md');
|
||||
try {
|
||||
for (let i = 0; i < 30; i++) {
|
||||
appendTurn(filePath, i % 2 ? 'Assistant' : 'User', `turn-${i}`);
|
||||
}
|
||||
const changed = compactSession(filePath, 10);
|
||||
assert.strictEqual(changed, true);
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
assert.ok(content.includes('NanoClaw Compaction'));
|
||||
assert.ok(!content.includes('turn-0'));
|
||||
assert.ok(content.includes('turn-29'));
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Summary ───────────────────────────────────────────────────────────
|
||||
|
||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||
|
||||
Reference in New Issue
Block a user