feat: v2.12.0 - UI/UX Refinement (Model Sync & Premium Tooltips)

This commit is contained in:
Wonseok Jung
2026-04-30 00:19:06 +09:00
parent f8a57cfbb0
commit 326672cb93
25 changed files with 5606 additions and 363 deletions
+68
View File
@@ -0,0 +1,68 @@
/// <reference types="jest" />
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { TransactionManager } from '../src/core/transaction';
describe('TransactionManager', () => {
let tm: TransactionManager;
let testDir: string;
beforeEach(() => {
tm = new TransactionManager();
testDir = path.join(os.tmpdir(), `g1-test-${Date.now()}`);
if (!fs.existsSync(testDir)) {
fs.mkdirSync(testDir, { recursive: true });
}
});
afterEach(() => {
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true });
}
});
test('should record and rollback file creation', () => {
const testFile = path.join(testDir, 'test.txt');
tm.begin();
tm.record(testFile);
fs.writeFileSync(testFile, 'hello world');
expect(fs.existsSync(testFile)).toBe(true);
tm.rollback();
expect(fs.existsSync(testFile)).toBe(false);
});
test('should record and rollback file modification', () => {
const testFile = path.join(testDir, 'edit.txt');
fs.writeFileSync(testFile, 'original');
tm.begin();
tm.record(testFile);
fs.writeFileSync(testFile, 'modified');
expect(fs.readFileSync(testFile, 'utf8')).toBe('modified');
tm.rollback();
expect(fs.readFileSync(testFile, 'utf8')).toBe('original');
});
test('should delete backup files after commit', () => {
const testFile = path.join(testDir, 'commit.txt');
fs.writeFileSync(testFile, 'data');
tm.begin();
tm.record(testFile);
fs.writeFileSync(testFile, 'new data');
tm.commit();
expect(fs.readFileSync(testFile, 'utf8')).toBe('new data');
// Backups are in ~/.g1nation-backups (hardcoded in TM, but let's assume it cleans up internal state)
expect(tm.isActive()).toBe(false);
});
});
+60
View File
@@ -0,0 +1,60 @@
/// <reference types="jest" />
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { AsyncLockManager } from '../src/core/lock';
import { TransactionManager } from '../src/core/transaction';
describe('System Vulnerability Tests', () => {
let testDir: string;
beforeEach(() => {
testDir = path.join(os.tmpdir(), `g1-vulnerability-test-${Date.now()}`);
if (!fs.existsSync(testDir)) {
fs.mkdirSync(testDir, { recursive: true });
}
});
afterEach(() => {
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true });
}
});
test('AsyncLockManager should prevent race conditions on the same file', async () => {
const lockManager = new AsyncLockManager();
const testFile = path.join(testDir, 'race_condition.txt');
fs.writeFileSync(testFile, '0');
// Simulate 10 concurrent increments
const tasks = Array.from({ length: 10 }).map(async (_, i) => {
const release = await lockManager.acquire(testFile);
try {
const current = parseInt(fs.readFileSync(testFile, 'utf-8'));
// Artificial delay to increase race condition probability
await new Promise(r => setTimeout(r, 10));
fs.writeFileSync(testFile, (current + 1).toString());
} finally {
release();
}
});
await Promise.all(tasks);
const finalValue = fs.readFileSync(testFile, 'utf-8');
expect(finalValue).toBe('10'); // If race condition occurs, it will be < 10
});
test('TransactionManager should support external verification hooks', () => {
const tm = new TransactionManager();
tm.begin();
tm.recordExternalAction('DB_COMMIT', true);
tm.recordExternalAction('API_PUSH', true);
expect(tm.isFullyVerified()).toBe(true);
tm.recordExternalAction('WIKI_SYNC', false);
expect(tm.isFullyVerified()).toBe(false);
});
});