mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-06 12:51:54 +00:00
refactor(lock): Consolidate utilities and fix circular dependencies
Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
244dbe1511
commit
e7b858d84a
330 files changed
+34090
-3976
No files matched your search
@@ -0,0 +1,78 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Prepare logging directory
|
||||
const logDir = 'test_logs';
|
||||
if (!fs.existsSync(logDir)) {
|
||||
fs.mkdirSync(logDir);
|
||||
}
|
||||
const logFile = path.join(logDir, 'playwright_console.log');
|
||||
// Clear previous log
|
||||
fs.writeFileSync(logFile, '');
|
||||
|
||||
test.use({
|
||||
extraHTTPHeaders: {
|
||||
// base64('admin:password') = 'YWRtaW46cGFzc3dvcmQ='
|
||||
'Authorization': 'Basic YWRtaW46cGFzc3dvcmQ='
|
||||
}
|
||||
});
|
||||
|
||||
test.describe.serial('TORCH Dashboard', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
page.on('console', msg => {
|
||||
const logLine = `[${msg.type()}] ${msg.text()}\n`;
|
||||
fs.appendFileSync(logFile, logLine);
|
||||
// Also log to stdout so it appears in the runner output
|
||||
// console.log(`[Browser Console] ${msg.text()}`);
|
||||
});
|
||||
});
|
||||
|
||||
test('should load the dashboard and verify title', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
// Check for title "TORCH Dashboard" or similar. Checking regex /TORCH/ is safer.
|
||||
await expect(page).toHaveTitle(/TORCH/);
|
||||
|
||||
// Check for some basic element presence to ensure rendering happened
|
||||
// Assuming there is a header or main content
|
||||
// We can inspect dashboard/index.html to be sure
|
||||
// But generic check for body visibility is a start
|
||||
await expect(page.locator('body')).toBeVisible();
|
||||
|
||||
// Verify console log capture
|
||||
await page.evaluate(() => console.log('Test log from browser'));
|
||||
});
|
||||
|
||||
test('should fail authentication with wrong credentials', async ({ browser }) => {
|
||||
const context = await browser.newContext({
|
||||
extraHTTPHeaders: {
|
||||
'Authorization': 'Basic YWRtaW46d3Jvbmc=' // admin:wrong
|
||||
}
|
||||
});
|
||||
const page = await context.newPage();
|
||||
const response = await page.goto('/');
|
||||
expect(response.status()).toBe(401);
|
||||
await context.close();
|
||||
});
|
||||
|
||||
test('should serve public config correctly', async ({ request }) => {
|
||||
const response = await request.get('/torch-config.json');
|
||||
expect(response.ok()).toBeTruthy();
|
||||
const config = await response.json();
|
||||
expect(config.nostrLock.namespace).toBe('test-torch');
|
||||
// Security check: Auth should be stripped
|
||||
expect(config.dashboard.auth).toBeUndefined();
|
||||
});
|
||||
|
||||
test('should shutdown gracefully to save coverage', async ({ request }) => {
|
||||
// Attempt to shutdown. It might fail if already down (unlikely in serial).
|
||||
try {
|
||||
// We don't expect a response because the server dies
|
||||
await request.get('/shutdown', { timeout: 1000 }).catch(() => {});
|
||||
} catch (_) {
|
||||
// Ignore
|
||||
}
|
||||
// Wait a bit for file write
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"nostrLock": {
|
||||
"namespace": "test-torch",
|
||||
"relays": ["wss://relay.damus.io"],
|
||||
"relayFallbacks": [],
|
||||
"ttlSeconds": 60,
|
||||
"queryTimeoutMs": 5000,
|
||||
"publishTimeoutMs": 5000,
|
||||
"minSuccessfulRelayPublishes": 1,
|
||||
"minActiveRelayPool": 1
|
||||
},
|
||||
"dashboard": {
|
||||
"auth": "admin:password",
|
||||
"defaultCadenceView": "daily",
|
||||
"defaultStatusView": "active",
|
||||
"relays": ["wss://relay.damus.io"],
|
||||
"namespace": "test-torch",
|
||||
"hashtag": "test-torch-lock"
|
||||
},
|
||||
"scheduler": {
|
||||
"firstPromptByCadence": {
|
||||
"daily": "src/prompts/daily/agent.md",
|
||||
"weekly": "src/prompts/weekly/agent.md"
|
||||
},
|
||||
"paused": {
|
||||
"daily": [],
|
||||
"weekly": []
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user