Better looking testing dashboard. Still needs work though. It does not scroll correctly.

This commit is contained in:
Scott Idem
2026-01-15 17:28:26 -05:00
parent 52f5d0bab6
commit 96adf1fa26

View File

@@ -2,213 +2,316 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { api } from '$lib/api/api'; import { api } from '$lib/api/api';
import { ae_loc, ae_sess, ae_api, slct, slct_trigger } from '$lib/stores/ae_stores'; import { ae_loc, ae_sess, ae_api, slct } from '$lib/stores/ae_stores';
import { get_object } from '$lib/ae_api/api_get_object'; import { get_object } from '$lib/ae_api/api_get_object';
import { post_object } from '$lib/ae_api/api_post_object'; import { post_object } from '$lib/ae_api/api_post_object';
import {
Database,
Server,
User,
Users,
MapPin,
Contact,
ShieldCheck,
Globe,
RefreshCcw,
Trash2,
Bug,
Zap
} from 'lucide-svelte';
type key_val = { // Core Module Imports
[key: string]: any; import { load_ae_obj_li__account } from '$lib/ae_core/ae_core__account';
}; import { load_ae_obj_li__site, lookup_site_domain_v3 } from '$lib/ae_core/ae_core__site';
import { load_ae_obj_li__person } from '$lib/ae_core/ae_core__person';
import { load_ae_obj_li__address } from '$lib/ae_core/ae_core__address';
import { load_ae_obj_li__contact } from '$lib/ae_core/ae_core__contact';
import { load_ae_obj_li__user } from '$lib/ae_core/ae_core__user';
import { db_core } from '$lib/ae_core/db_core';
let v3_test_result: any = $state(null); let test_result: any = $state(null);
let test_fqdn = $state(''); let test_fqdn = $state('');
let db_counts: Record<string, number> = $state({});
onMount(() => { onMount(async () => {
console.log('Testing: +page.svelte'); console.log('Testing Dashboard: +page.svelte');
await update_db_counts();
});
async function update_db_counts() {
try {
db_counts = {
user: await db_core.user.count(),
person: await db_core.person.count(),
account: await db_core.account.count(),
address: await db_core.address.count(),
contact: await db_core.contact.count(),
site: await db_core.site.count()
};
} catch (e) {
console.error('Failed to get DB counts:', e);
}
}
async function run_test(name: string, test_fn: () => Promise<any>) {
test_result = 'loading...';
try {
const result = await test_fn();
test_result = { test: name, timestamp: new Date().toISOString(), result };
await update_db_counts();
} catch (error: any) {
test_result = { test: name, error: error.message, details: error };
}
}
/**
* SYSTEM & INFRASTRUCTURE TESTS
*/
const test_site_domain_lookup = () => run_test('Site Domain Lookup', async () => {
const fqdn = test_fqdn || window.location.host;
return await lookup_site_domain_v3({ api_cfg: $ae_api, fqdn, log_lvl: 1 });
});
const test_bootstrap_bypass = () => run_test('Bootstrap Paradox Bypass', async () => {
const stripped_api_cfg = { base_url: $ae_api.base_url, headers: {} };
const fqdn = test_fqdn || window.location.host;
return await post_object({
api_cfg: stripped_api_cfg,
endpoint: '/v3/crud/site_domain/search',
headers: { 'x-no-account-id': 'System Test' },
data: { q: fqdn },
log_lvl: 1
});
}); });
/** /**
* CORE HELPER TESTS * CORE MODULE TESTS (V3)
*/ */
async function test_core_get_object() { const test_load_accounts = () => run_test('Load Accounts', async () => {
console.log('*** test_core_get_object() ***'); return await load_ae_obj_li__account({ api_cfg: $ae_api, enabled: 'all', log_lvl: 1 });
v3_test_result = 'loading...'; });
// Direct call to get_object with minimal params const test_load_people = () => run_test('Load People (Account)', async () => {
const result = await get_object({ return await load_ae_obj_li__person({
api_cfg: $ae_api,
endpoint: '/crud/account/list',
params: { limit: 1 },
log_lvl: 2
});
v3_test_result = {
helper: 'get_object',
result: result
};
}
async function test_core_post_object_v3_search() {
console.log('*** test_core_post_object_v3_search() ***');
v3_test_result = 'loading...';
// Direct call to post_object for V3 search
const result = await post_object({
api_cfg: $ae_api,
endpoint: '/v3/crud/event/search',
data: { q: 'Aether' },
params: { limit: 1 },
log_lvl: 2
});
v3_test_result = {
helper: 'post_object',
result: result
};
}
async function test_bootstrap_paradox_bypass() {
console.log('*** test_bootstrap_paradox_bypass() ***');
v3_test_result = 'loading...';
// CRITICAL TEST: Simulate unauthenticated first visit
// We create a STRIPPED api_cfg that has no JWT and no account_id
const stripped_api_cfg = {
base_url: $ae_api.base_url,
headers: {} // NO DEFAULT HEADERS
};
const fqdn = test_fqdn || window.location.host;
const result = await post_object({
api_cfg: stripped_api_cfg,
endpoint: '/v3/crud/site_domain/search',
headers: { 'x-no-account-id': null }, // Trigger the bypass!
data: { q: fqdn },
log_lvl: 2
});
v3_test_result = {
test: 'Bootstrap Paradox Bypass',
api_cfg_used: 'STRIPPED (No default headers)',
fqdn_tested: fqdn,
result: result
};
}
/**
* V3 WRAPPER TESTS
*/
async function test_v3_get_id() {
v3_test_result = 'loading...';
const result = await api.get_ae_obj_v3({
api_cfg: $ae_api,
obj_type: 'event',
obj_id: '9dv-IV-iz-LY',
view: 'base',
log_lvl: 1
});
v3_test_result = result;
}
async function test_v3_get_nested_id() {
v3_test_result = 'loading...';
const result = await api.get_nested_ae_obj_v3({
api_cfg: $ae_api,
parent_type: 'event',
parent_id: '9dv-IV-iz-LY',
child_type: 'event_badge',
child_id: 'XHTX-23-20-42',
view: 'base',
log_lvl: 1
});
v3_test_result = result;
}
/**
* DATA LOADING MODULE TESTS
*/
import { load_ae_obj_li__account, load_ae_obj_id__account } from '$lib/ae_core/ae_core__account';
import { load_ae_obj_li__site, load_ae_obj_id__site, lookup_site_domain_v3 } from '$lib/ae_core/ae_core__site';
async function test_site_domain_load_v3() {
v3_test_result = 'loading...';
const fqdn = test_fqdn || window.location.host;
const result = await lookup_site_domain_v3({
api_cfg: $ae_api,
fqdn,
log_lvl: 2
});
v3_test_result = result;
}
async function test_account_v3_load() {
v3_test_result = 'loading...';
const account_li = await load_ae_obj_li__account({
api_cfg: $ae_api, api_cfg: $ae_api,
for_obj_id: $ae_loc.account_id,
enabled: 'all', enabled: 'all',
hidden: 'all', log_lvl: 1
log_lvl: 2
}); });
v3_test_result = account_li; });
}
const test_load_addresses = () => run_test('Load Addresses', async () => {
return await load_ae_obj_li__address({
api_cfg: $ae_api,
for_obj_id: $ae_loc.account_id,
enabled: 'all',
log_lvl: 1
});
});
const test_load_contacts = () => run_test('Load Contacts', async () => {
return await load_ae_obj_li__contact({
api_cfg: $ae_api,
for_obj_id: $ae_loc.account_id,
enabled: 'all',
log_lvl: 1
});
});
/**
* USER MANAGEMENT & SCOPING TESTS
*/
const test_load_users_account = () => run_test('Load Users (Account Only)', async () => {
return await load_ae_obj_li__user({
api_cfg: $ae_api,
for_obj_id: $ae_loc.account_id,
include_global: false,
log_lvl: 1
});
});
const test_load_users_global = () => run_test('Load Users (Global Only)', async () => {
return await load_ae_obj_li__user({
api_cfg: $ae_api,
for_obj_id: null,
include_global: true,
log_lvl: 1
});
});
const test_load_users_all = () => run_test('Load Users (All)', async () => {
return await load_ae_obj_li__user({
api_cfg: $ae_api,
for_obj_id: $ae_loc.account_id,
include_global: true,
log_lvl: 1
});
});
/**
* LOCAL DATABASE (DEXIE) TESTS
*/
const clear_local_cache = () => run_test('Clear Local Cache', async () => {
await Promise.all([
db_core.user.clear(),
db_core.person.clear(),
db_core.account.clear(),
db_core.address.clear(),
db_core.contact.clear(),
db_core.site.clear()
]);
return 'Local cache cleared successfully';
});
</script> </script>
<div class="container h-full mx-auto p-4 gap-8 flex flex-col"> <div class="container mx-auto p-4 space-y-8">
<header class="text-center space-y-4"> <header class="flex justify-between items-center bg-surface-50-900-token p-6 rounded-container shadow-xl">
<h1 class="h1">Aether - System Testing Dashboard</h1> <div class="space-y-1">
<p class="opacity-50">Comprehensive validation for API V3 and Core Helpers</p> <h1 class="h1 flex items-center gap-3">
<Bug class="text-error-500" /> System Testing
</h1>
<p class="opacity-60">Validation dashboard for Aether Platform V3</p>
</div>
<div class="flex gap-4">
<div class="card p-2 variant-soft-secondary flex items-center gap-4 text-sm">
<div class="flex flex-col items-center px-2">
<span class="font-bold">{db_counts.user ?? 0}</span>
<span class="text-[10px] uppercase">Users</span>
</div>
<div class="divider-vertical h-8" />
<div class="flex flex-col items-center px-2">
<span class="font-bold">{db_counts.person ?? 0}</span>
<span class="text-[10px] uppercase">People</span>
</div>
<div class="divider-vertical h-8" />
<button class="btn-icon btn-icon-sm" onclick={update_db_counts} title="Refresh Counts">
<RefreshCcw size={14} />
</button>
</div>
</div>
</header> </header>
<div class="grid grid-cols-1 md:grid-cols-2 gap-8"> <div class="grid grid-cols-1 xl:grid-cols-[1fr_400px] gap-8">
<!-- Control Panel --> <!-- Control Panel -->
<section class="space-y-6"> <main class="space-y-6">
<div class="card p-4 space-y-4"> <!-- Global Config -->
<h3 class="h3">Global Parameters</h3> <div class="card p-4 variant-soft-surface space-y-4">
<label class="label"> <header class="flex items-center gap-2 border-b border-surface-500/30 pb-2">
<span>Target FQDN</span> <Globe size={18} />
<input type="text" class="input" placeholder="e.g. localhost:5173" bind:value={test_fqdn} /> <h3 class="h3">Environment Config</h3>
</label> </header>
</div> <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<label class="label">
<div class="card p-4 space-y-4"> <span>Current Account ID</span>
<h3 class="h3">Core Helper Verification</h3> <input type="text" class="input" readonly value={$ae_loc.account_id || 'Not Set'} />
<div class="flex flex-wrap gap-2"> </label>
<button class="btn variant-filled-primary" onclick={test_core_get_object}>get_object</button> <label class="label">
<button class="btn variant-filled-primary" onclick={test_core_post_object_v3_search}>post_object (Search)</button> <span>Override FQDN (for Domain Lookup)</span>
<button class="btn variant-filled-error" onclick={test_bootstrap_paradox_bypass}>Bootstrap Paradox Bypass</button> <input type="text" class="input" placeholder={window.location.host} bind:value={test_fqdn} />
</label>
</div> </div>
</div> </div>
<div class="card p-4 space-y-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<h3 class="h3">V3 Wrapper Tests</h3> <!-- Infra Tests -->
<div class="flex flex-wrap gap-2"> <div class="card p-4 space-y-4 shadow-lg">
<button class="btn variant-filled-secondary" onclick={test_v3_get_id}>Get Event</button> <header class="flex items-center gap-2 text-primary-500">
<button class="btn variant-filled-secondary" onclick={test_v3_get_nested_id}>Get Nested Badge</button> <Server size={18} />
<h4 class="h4 font-bold">Infrastructure</h4>
</header>
<div class="flex flex-col gap-2">
<button class="btn variant-filled-primary justify-start" onclick={test_site_domain_lookup}>
<Zap size={14} class="mr-2" /> Lookup Site Domain
</button>
<button class="btn variant-ghost-error justify-start" onclick={test_bootstrap_bypass}>
<ShieldCheck size={14} class="mr-2" /> Bootstrap Bypass Test
</button>
</div>
</div>
<!-- Core Module Tests -->
<div class="card p-4 space-y-4 shadow-lg">
<header class="flex items-center gap-2 text-secondary-500">
<Database size={18} />
<h4 class="h4 font-bold">Core Modules (V3)</h4>
</header>
<div class="grid grid-cols-2 gap-2">
<button class="btn variant-soft-secondary btn-sm" onclick={test_load_accounts}>Accounts</button>
<button class="btn variant-soft-secondary btn-sm" onclick={test_load_people}>People</button>
<button class="btn variant-soft-secondary btn-sm" onclick={test_load_addresses}>Addresses</button>
<button class="btn variant-soft-secondary btn-sm" onclick={test_load_contacts}>Contacts</button>
</div>
</div>
<!-- User Scoping -->
<div class="card p-4 space-y-4 shadow-lg md:col-span-2">
<header class="flex items-center gap-2 text-tertiary-500">
<Users size={18} />
<h4 class="h4 font-bold">User Management Scoping</h4>
</header>
<div class="flex flex-wrap gap-2">
<button class="btn variant-filled-tertiary" onclick={test_load_users_account}>
<ShieldCheck size={14} class="mr-2" /> Current Account Only
</button>
<button class="btn variant-filled-tertiary" onclick={test_load_users_global}>
<Globe size={14} class="mr-2" /> Global Only
</button>
<button class="btn variant-filled-tertiary" onclick={test_load_users_all}>
<RefreshCcw size={14} class="mr-2" /> All (Inclusive)
</button>
</div>
</div> </div>
</div> </div>
<div class="card p-4 space-y-4"> <!-- Maintenance -->
<h3 class="h3">Module Loader Tests</h3> <div class="card p-4 variant-soft-error flex justify-between items-center">
<div class="flex flex-wrap gap-2"> <div class="flex items-center gap-3">
<button class="btn variant-filled-tertiary" onclick={test_account_v3_load}>Load Accounts</button> <Trash2 class="text-error-500" />
<button class="btn variant-filled-tertiary" onclick={test_site_domain_load_v3}>Lookup Site Domain</button> <div>
<p class="font-bold text-error-500">Local Cache Management</p>
<p class="text-xs opacity-60">Wipe local IndexedDB tables for core objects</p>
</div>
</div> </div>
<button class="btn variant-filled-error" onclick={clear_local_cache}>Clear Local IDB</button>
</div> </div>
</section> </main>
<!-- Result View --> <!-- Result View -->
<section class="space-y-4"> <aside class="space-y-4">
<div class="card p-4 h-full bg-surface-100-800-token overflow-hidden flex flex-col"> <div class="card p-4 h-full bg-surface-100-800-token overflow-hidden flex flex-col sticky top-4 max-h-[calc(100vh-2rem)] shadow-2xl">
<div class="flex justify-between items-center mb-4"> <div class="flex justify-between items-center mb-4">
<h3 class="h3">Result View</h3> <h3 class="h3">Output</h3>
{#if v3_test_result === 'loading...'} {#if test_result === 'loading...'}
<span class="badge variant-filled-warning animate-pulse">Processing...</span> <span class="badge variant-filled-warning animate-pulse">Running...</span>
{:else if v3_test_result} {:else if test_result?.error}
<span class="badge variant-filled-error">Failed</span>
{:else if test_result}
<span class="badge variant-filled-success">Success</span> <span class="badge variant-filled-success">Success</span>
{/if} {/if}
</div> </div>
<div class="flex-1 overflow-auto bg-black/10 rounded p-2"> <div class="flex-1 overflow-auto bg-black/20 rounded-container p-4 font-mono text-xs">
{#if v3_test_result} {#if test_result === 'loading...'}
<pre class="text-xs">{JSON.stringify(v3_test_result, null, 2)}</pre> <div class="placeholder animate-pulse space-y-4">
<div class="placeholder-circle w-12" />
<div class="placeholder-line w-full" />
<div class="placeholder-line w-3/4" />
</div>
{:else if test_result}
<pre>{JSON.stringify(test_result, null, 2)}</pre>
{:else} {:else}
<p class="text-center opacity-50 py-20">Execute a test to see results</p> <div class="flex flex-col items-center justify-center h-full opacity-30 py-20 text-center">
<Zap size={48} class="mb-4" />
<p>Select a validation test<br/>to begin audit</p>
</div>
{/if} {/if}
</div> </div>
</div> </div>
</section> </aside>
</div> </div>
</div> </div>